Skip to content

Commit

Permalink
improve dependency handling
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme committed Mar 6, 2024
1 parent aa0fd2b commit 2abfca2
Show file tree
Hide file tree
Showing 44 changed files with 55 additions and 80 deletions.
2 changes: 1 addition & 1 deletion bin/conformanceServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { AuthenticationResult, Context, Topic } from "../server/mod.ts";
import { DenoServer } from "../deno/server.ts";
import { logger, LogLevel } from "../utils/utils.ts";
import { logger, LogLevel } from "../utils/mod.ts";

const utf8Decoder = new TextDecoder();
const userTable = new Map();
Expand Down
2 changes: 1 addition & 1 deletion bin/demoServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthenticationResult, Context, Topic } from "../server/mod.ts";
import { DenoServer } from "../deno/server.ts";
import { logger, LogLevel } from "../utils/utils.ts";
import { logger, LogLevel } from "../utils/mod.ts";

const utf8Decoder = new TextDecoder();
const userTable = new Map();
Expand Down
2 changes: 1 addition & 1 deletion bin/mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseArgs } from "../utils/deps.ts";
import { parseArgs } from "../utils/mod.ts";
import { DenoClient as Client } from "../deno/client.ts";
import { DEFAULT_URL, logger } from "../client/mod.ts";

Expand Down
2 changes: 1 addition & 1 deletion client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CLIENTID_PREFIX = "opifex"; // on first connect
export class Client {
protected clientIdPrefix = CLIENTID_PREFIX;
protected numberOfRetries = DEFAULT_RETRIES;
protected url = new URL(DEFAULT_URL);
protected url: URL = new URL(DEFAULT_URL);
protected keepAlive = DEFAULT_KEEPALIVE;
protected autoReconnect = true;
private caCerts?: string[];
Expand Down
2 changes: 1 addition & 1 deletion client/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export {
export { MqttConn } from "../mqttConn/mqttConn.ts";
export type { SockConn } from "../mqttConn/mqttConn.ts";
export { Timer } from "../timer/timer.ts";
export { AsyncQueue, Deferred, logger } from "../utils/utils.ts";
export { AsyncQueue, Deferred, logger } from "../utils/mod.ts";
export { MemoryStore } from "./store/memoryStore.ts";
2 changes: 0 additions & 2 deletions client/dev_deps.ts

This file was deleted.

2 changes: 1 addition & 1 deletion client/store/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export type {
UnsubscribePacket,
} from "../../mqttPacket/mod.ts";

export { assert } from "../../utils/deps.ts";
export { assert } from "../../utils/mod.ts";
2 changes: 1 addition & 1 deletion deno/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DenoServer } from "./server.ts";
import { assertEquals } from "../utils/dev_deps.ts";
import { assertEquals } from "../dev_utils/mod.ts";

Deno.test("testServer", () => {
const server = new DenoServer({ port: 0 }, {});
Expand Down
2 changes: 1 addition & 1 deletion utils/dev_utils.ts → dev_utils/dummyConn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncQueue } from "./utils.ts";
import { AsyncQueue } from "../utils/mod.ts";
import { SockConn } from "../mqttConn/mqttConn.ts";

class Uint8Writer implements WritableStreamDefaultWriter {
Expand Down
2 changes: 2 additions & 0 deletions utils/dev_deps.ts → dev_utils/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export {
assertThrows,
} from "https://deno.land/[email protected]/assert/mod.ts";
export { readerFromIterable } from "https://deno.land/[email protected]/streams/mod.ts";

export { DummyConn, DummyQueueConn } from "./dummyConn.ts";
29 changes: 0 additions & 29 deletions mqttConn/deps.ts

This file was deleted.

2 changes: 0 additions & 2 deletions mqttConn/dev_deps.ts

This file was deleted.

5 changes: 2 additions & 3 deletions mqttConn/mqttConn.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MqttConn, MqttConnError } from "./mqttConn.ts";
import { AnyPacket, encode } from "./deps.ts";
import { assertEquals, DummyConn } from "./dev_deps.ts";
import { PacketType } from "../mqttPacket/types.ts";
import { assertEquals, DummyConn } from "../dev_utils/mod.ts";
import { PacketType, AnyPacket, encode } from "../mqttPacket/mod.ts";

const connectPacket: AnyPacket = {
type: PacketType.connect,
Expand Down
7 changes: 4 additions & 3 deletions mqttConn/mqttConn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
AnyPacket,
assert,
decodePayload,
encode,
getLengthDecoder,
LengthDecoderResult,
} from "./deps.ts";
} from "../mqttPacket/mod.ts";

import { assert } from "../utils/mod.ts"

export type SockConn = {
readable: ReadableStream<Uint8Array>;
Expand Down Expand Up @@ -49,7 +50,7 @@ async function readFull(conn: SockConn, buf: Uint8Array): Promise<void> {
}
}

/** Read MQTT packet from given BufReader
/** Read MQTT packet
* @throws `Error` if packet is invalid
*/
export async function readPacket(
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/connack.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Connack packet", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/connect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { ConnectPacket, decode, encode } from "./mod.ts";

Deno.test("encode Connect with ClientId", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { Decoder } from "./decoder.ts";

const utf8encoder = new TextEncoder();
Expand Down
1 change: 0 additions & 1 deletion mqttPacket/dev_deps.ts

This file was deleted.

2 changes: 1 addition & 1 deletion mqttPacket/disconnect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Disconnect", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/encoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "./dev_deps.ts";
import { assertEquals } from "../dev_utils/mod.ts";
import { Encoder } from "./encoder.ts";

const utf8Encoder = new TextEncoder();
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/length.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decodeLength as decode, encodeLength as encode } from "./length.ts";

Deno.test("encodeLength", function encodeLength() {
Expand Down
3 changes: 3 additions & 0 deletions mqttPacket/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ export function decode(buffer: Uint8Array): AnyPacket {
const end = start + length;
return decodePayload(buffer[0], buffer.subarray(start, end));
}

export { getLengthDecoder } from "../mqttPacket/length.ts";
export type { LengthDecoderResult } from "../mqttPacket/length.ts";
2 changes: 1 addition & 1 deletion mqttPacket/pingreq.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Pingreq", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pingres.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Pingres", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/puback.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Puback", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pubcomp.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Pubcomp", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

// const utf8Decoder = new TextDecoder();
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pubrec.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Pubrec", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/pubrel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Pubrel", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/suback.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals } from "./dev_deps.ts";
import { assertEquals } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Suback", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/subscribe.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Subscribe", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/unsuback.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Puback", () => {
Expand Down
2 changes: 1 addition & 1 deletion mqttPacket/unsubscribe.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PacketType } from "./types.ts";
import { assertEquals, assertThrows } from "./dev_deps.ts";
import { assertEquals, assertThrows } from "../dev_utils/mod.ts";
import { decode, encode } from "./mod.ts";

Deno.test("encode Unsubscribe", () => {
Expand Down
2 changes: 1 addition & 1 deletion persistence/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export type {
} from "../mqttPacket/mod.ts";
export { PacketType } from "../mqttPacket/mod.ts";
export { Trie } from "../trie/trie.ts";
export { logger } from "../utils/utils.ts";
export { logger } from "../utils/mod.ts";
2 changes: 1 addition & 1 deletion persistence/memory/memoryPersistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "./memoryPersistence.ts";

import { PacketType, PublishPacket } from "../deps.ts";
import { assertEquals } from "../../utils/dev_deps.ts";
import { assertEquals } from "../../dev_utils/mod.ts";

const payloadAny = new TextEncoder().encode("any");
const qos = 1;
Expand Down
2 changes: 1 addition & 1 deletion persistence/memory/memoryPersistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { Client, Handler, IPersistence, RetainStore } from "../persistence.ts";
import { IStore, PacketStore, SubscriptionStore } from "../store.ts";
import { assert } from "../../utils/deps.ts";
import { assert } from "../../utils/mod.ts";

const maxPacketId = 0xffff;
// const maxQueueLength = 0xffff;
Expand Down
4 changes: 2 additions & 2 deletions server/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export type {
UnsubscribePacket,
} from "../mqttPacket/mod.ts";

export { AuthenticationResult, PacketType } from "../mqttConn/deps.ts";
export { AuthenticationResult, PacketType } from "../mqttPacket/mod.ts";
export { Timer } from "../timer/timer.ts";
export { logger } from "../utils/utils.ts";
export { logger } from "../utils/mod.ts";
2 changes: 0 additions & 2 deletions server/test/dev_deps.ts

This file was deleted.

4 changes: 2 additions & 2 deletions server/test/handleConnect.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, DummyQueueConn } from "./dev_deps.ts";
import { assertEquals, DummyQueueConn } from "../../dev_utils/mod.ts";
import { handlers } from "./test-handlers.ts";
import {
AnyPacket,
Expand All @@ -7,7 +7,7 @@ import {
} from "../../mqttPacket/mod.ts";
import { MqttServer } from "../mod.ts";
import { MqttConn } from "../deps.ts";
import { AsyncQueue, nextTick } from "../../utils/utils.ts";
import { AsyncQueue, nextTick } from "../../utils/mod.ts";

const txtEncoder = new TextEncoder();
// logger.level(LogLevel.debug);
Expand Down
2 changes: 1 addition & 1 deletion server/test/test-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthenticationResult, Context, Topic } from "../mod.ts";
import { logger } from "../../utils/utils.ts";
import { logger } from "../../utils/mod.ts";

const utf8Decoder = new TextDecoder();
const userTable = new Map();
Expand Down
2 changes: 1 addition & 1 deletion timer/timer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Timer } from "./timer.ts";
import { assertEquals } from "../utils/dev_deps.ts";
import { assertEquals } from "../dev_utils/mod.ts";

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down
2 changes: 1 addition & 1 deletion trie/trie.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trie } from "./trie.ts";
import { assertArrayIncludes, assertEquals } from "../utils/dev_deps.ts";
import { assertArrayIncludes, assertEquals } from "../dev_utils/mod.ts";

type Data = Array<[string, number]>;
type Matches = Array<[string, number[]]>;
Expand Down
10 changes: 8 additions & 2 deletions utils/deps.ts → utils/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export { parse } from "https://deno.land/[email protected]/flags/mod.ts";
export { parseArgs } from "https://deno.land/[email protected]/cli/parse_args.ts";
export { assert } from "https://deno.land/[email protected]/assert/mod.ts";
export { BufReader } from "https://deno.land/[email protected]/io/mod.ts";
export {
AsyncQueue,
Deferred,
Logger,
logger,
LogLevel,
nextTick,
} from "./utils.ts";
2 changes: 1 addition & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export enum LogLevel {
debug = 4,
}

class Logger {
export class Logger {
private defaultError = console.error;
private defaultWarn = console.warn;
private defaultInfo = console.info;
Expand Down

0 comments on commit 2abfca2

Please sign in to comment.