diff --git a/core/clients.ts b/core/clients.ts index 2548cce..e911611 100644 --- a/core/clients.ts +++ b/core/clients.ts @@ -3,7 +3,7 @@ import type { NostrEvent, RelayToClientMessage, SubscriptionId, -} from "./protocol.d.ts"; +} from "./protocol.ts"; import { NostrNode, NostrNodeBase, @@ -36,10 +36,10 @@ export class Client extends NostrNodeBase< /** * Writable interface for the subscriptions. */ - readonly subscriptions = new Map< + readonly subscriptions: Map< SubscriptionId, WritableStream - >(); + > = new Map(); constructor(ws: WebSocket, opts?: ClientOptions) { super(ws, opts); diff --git a/core/clients_test.ts b/core/clients_test.ts index 768d63c..98b5192 100644 --- a/core/clients_test.ts +++ b/core/clients_test.ts @@ -1,7 +1,7 @@ -import { Client } from "./clients.ts"; -import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assert } from "../lib/std/assert.ts"; +import { assert } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; import { MockWebSocket } from "../lib/testing.ts"; +import { Client } from "./clients.ts"; describe("Client", () => { let ws: MockWebSocket; diff --git a/core/deno.json b/core/deno.json new file mode 100644 index 0000000..405fb8c --- /dev/null +++ b/core/deno.json @@ -0,0 +1,12 @@ +{ + "name": "@lophus/core", + "version": "0.0.14", + "exports": "./mod.ts", + + "publish": { + "exclude": [ + "deno.json", + "*_test.ts" + ] + } +} diff --git a/core/mod.ts b/core/mod.ts new file mode 100644 index 0000000..584b190 --- /dev/null +++ b/core/mod.ts @@ -0,0 +1,3 @@ +export * from "./protocol.ts"; +export * from "./relays.ts"; +export * from "./clients.ts"; diff --git a/core/nodes.ts b/core/nodes.ts index 58c6b1b..48f4655 100644 --- a/core/nodes.ts +++ b/core/nodes.ts @@ -1,4 +1,4 @@ -import type { NostrMessage } from "./protocol.d.ts"; +import type { NostrMessage } from "./protocol.ts"; import { WebSocketLike } from "./websockets.ts"; export interface NostrNodeConfig< @@ -89,15 +89,15 @@ export class NostrNodeBase< this.config.modules.forEach((m) => this.install(m)); } - send(msg: W) { + send(msg: W): void | Promise { return this.ws.send(JSON.stringify(msg)); } - get status() { + get status(): WebSocket["readyState"] { return this.ws.readyState; } - async close() { + async close(): Promise { try { await this.writable.close(); } catch (err) { @@ -107,8 +107,8 @@ export class NostrNodeBase< } } - install(mod: NostrNodeModule) { - return mod.install(this); + install(mod: NostrNodeModule): void { + mod.install(this); } declare addEventListener: NostrNode["addEventListener"]; diff --git a/core/nodes_test.ts b/core/nodes_test.ts index 6818470..8651249 100644 --- a/core/nodes_test.ts +++ b/core/nodes_test.ts @@ -1,7 +1,7 @@ -import { NostrNode, NostrNodeBase } from "./nodes.ts"; -import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assertEquals } from "../lib/std/assert.ts"; +import { assertEquals } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; import { MockWebSocket } from "../lib/testing.ts"; +import { NostrNode, NostrNodeBase } from "./nodes.ts"; describe("NostrNodeBase", () => { let node: NostrNode; diff --git a/core/protocol.d.ts b/core/protocol.ts similarity index 98% rename from core/protocol.d.ts rename to core/protocol.ts index 475ad8a..be01851 100644 --- a/core/protocol.d.ts +++ b/core/protocol.ts @@ -9,7 +9,7 @@ * @module */ -import type { AlphabetLetter, Brand, Stringified } from "./types.ts"; +import type { AlphabetLetter, Brand, Stringified } from "../lib/types.ts"; // ---------------------- // Extendable interfaces diff --git a/core/relays.ts b/core/relays.ts index eaefb79..b9e1e88 100644 --- a/core/relays.ts +++ b/core/relays.ts @@ -1,4 +1,4 @@ -import type { Stringified } from "./types.ts"; +import type { Stringified } from "../lib/types.ts"; import type { ClientToRelayMessage, EventId, @@ -9,7 +9,7 @@ import type { RelayUrl, SubscriptionFilter, SubscriptionId, -} from "./protocol.d.ts"; +} from "./protocol.ts"; import { LazyWebSocket } from "./websockets.ts"; import { NostrNodeBase, NostrNodeConfig, NostrNodeModule } from "./nodes.ts"; @@ -52,7 +52,7 @@ export class Relay extends NostrNodeBase< RelayEventTypeRecord > { declare ws: LazyWebSocket; - readonly config: Readonly; + declare config: RelayConfig; constructor( init: RelayUrl | RelayInit, diff --git a/core/relays_test.ts b/core/relays_test.ts index 5cb9c66..c358940 100644 --- a/core/relays_test.ts +++ b/core/relays_test.ts @@ -1,6 +1,6 @@ +import { assert, assertEquals, assertObjectMatch } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; import { Relay } from "./relays.ts"; -import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assert, assertEquals, assertObjectMatch } from "../lib/std/assert.ts"; const url = "wss://localhost:8080"; @@ -11,24 +11,28 @@ describe("Relay", () => { beforeAll(() => { relay = new Relay(url); }); - afterAll(() => { - relay.close(); - }); + + afterAll(() => relay.close()); + it("should be constructable", () => { assert(relay instanceof Relay); }); + it("should have a url", () => { assertEquals(relay.config.url, url); }); + it("should have a name", () => { assertEquals(relay.config.name, "localhost"); }); + it("should have default options", () => { assertObjectMatch(relay.config, { read: true, write: true, }); }); + it("should not be connected initially", () => { assertEquals(relay.status, WebSocket.CLOSED); }); @@ -43,12 +47,15 @@ describe("Relay", () => { nbuffer: 20, }); }); + afterAll(() => { relay.close(); }); + it("should be constructable", () => { assert(relay instanceof Relay); }); + it("should have the given options", () => { assertObjectMatch(relay.config, { name: "test", diff --git a/core/types.ts b/core/types.ts deleted file mode 100644 index 32d6e30..0000000 --- a/core/types.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Constructor of branded types - */ - -// ---------------------- -// Branded types -// ---------------------- -export type Brand = T & { __brand: B }; - -// ---------------------- -// Promises -// ---------------------- -export type PromiseCallbacks = { - resolve: (value: T | PromiseLike) => void; - reject: (reason?: unknown) => void; -}; - -// ---------------------- -// Strings -// ---------------------- - -export type Url = `https://${string}` | `http://${string}`; -export type Stringified = string & { __content: T }; - -// deno-fmt-ignore -export type AlphabetLetter = - | "a" | "b" | "c" | "d" | "e" | "f" | "g" - | "h" | "i" | "j" | "k" | "l" | "m" | "n" - | "o" | "p" | "q" | "r" | "s" | "t" | "u" - | "v" | "w" | "x" | "y" | "z" - | "A" | "B" | "C" | "D" | "E" | "F" | "G" - | "H" | "I" | "J" | "K" | "L" | "M" | "N" - | "O" | "P" | "Q" | "R" | "S" | "T" | "U" - | "V" | "W" | "X" | "Y" | "Z"; diff --git a/core/websockets_test.ts b/core/websockets_test.ts index b85df3a..b1cd2cb 100644 --- a/core/websockets_test.ts +++ b/core/websockets_test.ts @@ -1,7 +1,7 @@ -import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assert, assertEquals } from "../lib/std/assert.ts"; -import { LazyWebSocket } from "./websockets.ts"; +import { assert, assertEquals } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; import { MockWebSocket } from "../lib/testing.ts"; +import { LazyWebSocket } from "./websockets.ts"; describe("LazyWebSocket", () => { let lazy: LazyWebSocket; diff --git a/deno.json b/deno.json index 6ae0357..7b4d388 100644 --- a/deno.json +++ b/deno.json @@ -1,16 +1,26 @@ { + "exclude": [ + "dist/" + ], + "imports": { + "@noble/curves": "npm:@noble/curves@^1.3.0", + "@noble/hashes": "npm:@noble/hashes@^1.3.3", + "@std/assert": "jsr:@std/assert@^0.219.1", + "@std/dotenv": "jsr:@std/dotenv@^0.219.1", + "@std/streams": "jsr:@std/streams@^0.219.1", + "@std/testing": "jsr:@std/testing@^0.219.1" + }, "tasks": { + "build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts", "cache": "deno cache ./**/*.ts --lock", - "lock": "deno task cache --lock-write && git add deno.lock", "check": "deno check ./**/*.ts", - "test": "deno test -A --no-check --parallel", - "build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts", - "dev": "deno fmt && deno lint && deno task -q check && deno task -q lock && deno task -q test", - "update": "deno run --allow-read --allow-env --allow-write --allow-net=deno.land,registry.npmjs.org --allow-run=deno,git https://deno.land/x/molt@0.14.3/cli.ts ./**/*.ts", - "update:commit": "deno task -q update --commit --pre-commit=dev --prefix 'build(deps):'" + "lock": "deno task cache --lock-write && git add deno.lock", + "pre-commit": "deno fmt && deno lint && deno task -q check && deno task -q lock && deno task -q test", + "test": "deno test -A --no-check", + "update": "deno run --allow-read --allow-env --allow-write --allow-net=registry.npmjs.org,jsr.io --allow-run=deno,git https://deno.land/x/molt@0.17.1/cli.ts deno.json --unstable-lock", + "update:commit": "deno task -q update --commit --prefix 'build(deps):' --prefix-lock 'build(lock):'" }, - "exclude": [ - "dist/", - "CHANGELOG.md" + "workspaces": [ + "./core" ] } diff --git a/deno.lock b/deno.lock index 84ce4bb..7f3d4b3 100644 --- a/deno.lock +++ b/deno.lock @@ -2,9 +2,46 @@ "version": "3", "packages": { "specifiers": { - "npm:@noble/curves@1.3.0": "npm:@noble/curves@1.3.0", - "npm:@noble/hashes@1.3.3": "npm:@noble/hashes@1.3.3", - "npm:mock-socket@9.3.1": "npm:mock-socket@9.3.1" + "jsr:@std/assert@^0.219.1": "jsr:@std/assert@0.219.1", + "jsr:@std/bytes@^0.219.1": "jsr:@std/bytes@0.219.1", + "jsr:@std/dotenv@^0.219.1": "jsr:@std/dotenv@0.219.1", + "jsr:@std/fmt@^0.219.1": "jsr:@std/fmt@0.219.1", + "jsr:@std/io@^0.219.1": "jsr:@std/io@0.219.1", + "jsr:@std/streams@^0.219.1": "jsr:@std/streams@0.219.1", + "jsr:@std/testing@^0.219.1": "jsr:@std/testing@0.219.1", + "npm:@noble/curves@^1.3.0": "npm:@noble/curves@1.3.0", + "npm:@noble/hashes@^1.3.3": "npm:@noble/hashes@1.3.3" + }, + "jsr": { + "@std/assert@0.219.1": { + "integrity": "e76c2a1799a78f0f4db7de04bdc9b908a7a4b821bb65eda0285885297d4fb8af", + "dependencies": [ + "jsr:@std/fmt@^0.219.1" + ] + }, + "@std/bytes@0.219.1": { + "integrity": "693e5f3f7796b33a448fb16c448b75d7d6e62914b55e2f1f715f9a04f77853b4" + }, + "@std/dotenv@0.219.1": { + "integrity": "061a8d284c85ac6f47ce6df7b90f950ae3f89de61e94cf4523cc4a1ba5175050" + }, + "@std/fmt@0.219.1": { + "integrity": "2432152e927df249a207177aa048a6d9465956ea0047653ee6abd4f514db504f" + }, + "@std/io@0.219.1": { + "integrity": "4f5073dd150fb7deff5c57449f4304edaf89a1137e0003602a22c133eb7cf93a" + }, + "@std/streams@0.219.1": { + "integrity": "6f5dac5773a4fafdbe7ee612d0a0d5a2cbe465b9c9e2c85d371877dc8a52d1d3", + "dependencies": [ + "jsr:@std/assert@^0.219.1", + "jsr:@std/bytes@^0.219.1", + "jsr:@std/io@^0.219.1" + ] + }, + "@std/testing@0.219.1": { + "integrity": "a87945273d41853cd5afbdd4d6cea123c6126d005a645c10f487ac35e31da75b" + } }, "npm": { "@noble/curves@1.3.0": { @@ -16,10 +53,6 @@ "@noble/hashes@1.3.3": { "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", "dependencies": {} - }, - "mock-socket@9.3.1": { - "integrity": "sha512-qxBgB7Qa2sEQgHFjj0dSigq7fX4k6Saisd5Nelwp2q8mlbAFh5dHV9JTTlF8viYJLSSWgMCZFUom8PJcMNBoJw==", - "dependencies": {} } } }, @@ -54,62 +87,6 @@ "https://deno.land/std@0.186.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", "https://deno.land/std@0.186.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", "https://deno.land/std@0.186.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", - "https://deno.land/std@0.217.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", - "https://deno.land/std@0.217.0/assert/_diff.ts": "dcc63d94ca289aec80644030cf88ccbf7acaa6fbd7b0f22add93616b36593840", - "https://deno.land/std@0.217.0/assert/_format.ts": "0ba808961bf678437fb486b56405b6fefad2cf87b5809667c781ddee8c32aff4", - "https://deno.land/std@0.217.0/assert/assert.ts": "bec068b2fccdd434c138a555b19a2c2393b71dfaada02b7d568a01541e67cdc5", - "https://deno.land/std@0.217.0/assert/assert_array_includes.ts": "1688d76317fd45b7e93ef9e2765f112fdf2b7c9821016cdfb380b9445374aed1", - "https://deno.land/std@0.217.0/assert/assert_equals.ts": "4497c56fe7d2993b0d447926702802fc0becb44e319079e8eca39b482ee01b4e", - "https://deno.land/std@0.217.0/assert/assert_false.ts": "6f382568e5128c0f855e5f7dbda8624c1ed9af4fcc33ef4a9afeeedcdce99769", - "https://deno.land/std@0.217.0/assert/assert_instance_of.ts": "72dc1faff1e248692d873c89382fa1579dd7b53b56d52f37f9874a75b11ba444", - "https://deno.land/std@0.217.0/assert/assert_is_error.ts": "6596f2b5ba89ba2fe9b074f75e9318cda97a2381e59d476812e30077fbdb6ed2", - "https://deno.land/std@0.217.0/assert/assert_object_match.ts": "e85e5eef62a56ce364c3afdd27978ccab979288a3e772e6855c270a7b118fa49", - "https://deno.land/std@0.217.0/assert/assert_rejects.ts": "e9e0c8d9c3e164c7ac962c37b3be50577c5a2010db107ed272c4c1afb1269f54", - "https://deno.land/std@0.217.0/assert/assert_throws.ts": "edddd86b39606c342164b49ad88dd39a26e72a26655e07545d172f164b617fa7", - "https://deno.land/std@0.217.0/assert/assertion_error.ts": "9f689a101ee586c4ce92f52fa7ddd362e86434ffdf1f848e45987dc7689976b8", - "https://deno.land/std@0.217.0/assert/equal.ts": "fae5e8a52a11d3ac694bbe1a53e13a7969e3f60791262312e91a3e741ae519e2", - "https://deno.land/std@0.217.0/bytes/concat.ts": "9cac3b4376afbef98ff03588eb3cf948e0d1eb6c27cfe81a7651ab6dd3adc54a", - "https://deno.land/std@0.217.0/bytes/copy.ts": "f29c03168853720dfe82eaa57793d0b9e3543ebfe5306684182f0f1e3bfd422a", - "https://deno.land/std@0.217.0/dotenv/load.ts": "587b342f0f6a3df071331fe6ba1c823729ab68f7d53805809475e486dd4161d7", - "https://deno.land/std@0.217.0/dotenv/mod.ts": "0180eaeedaaf88647318811cdaa418cc64dc51fb08354f91f5f480d0a1309f7d", - "https://deno.land/std@0.217.0/dotenv/parse.ts": "a49ed243bd62ec26f38614042cda4e5e3a47b18337c93b0f9f8556a5c918884b", - "https://deno.land/std@0.217.0/dotenv/stringify.ts": "0047ad7068289735d08964046aea267a750c141b494ca0e38831b89be6c020c2", - "https://deno.land/std@0.217.0/fmt/colors.ts": "d239d84620b921ea520125d778947881f62c50e78deef2657073840b8af9559a", - "https://deno.land/std@0.217.0/io/_common.ts": "36705cdb4dfcd338d6131bca1b16e48a4d5bf0d1dada6ce397268e88c17a5835", - "https://deno.land/std@0.217.0/io/_constants.ts": "3c7ad4695832e6e4a32e35f218c70376b62bc78621ef069a4a0a3d55739f8856", - "https://deno.land/std@0.217.0/io/buffer.ts": "4d1f805f350433e418002accec798bc6c33ce18f614afa65f987c202d7b2234e", - "https://deno.land/std@0.217.0/io/iterate_reader.ts": "1e5e4fea22d8965afb7df4ee9ab9adda0a0fc581adbea31bc2f2d25453f8a6e9", - "https://deno.land/std@0.217.0/io/reader_from_stream_reader.ts": "a75bbc93f39df8b0e372cc1fbdc416a7cbf2a39fc4c09ddb057f1241100191c5", - "https://deno.land/std@0.217.0/io/to_readable_stream.ts": "ed03a44a1ec1cc55a85a857acf6cac472035298f6f3b6207ea209f93b4aefb39", - "https://deno.land/std@0.217.0/io/to_writable_stream.ts": "ef422e0425963c8a1e0481674e66c3023da50f0acbe5ef51ec9789efc3c1e2ed", - "https://deno.land/std@0.217.0/io/types.ts": "acecb3074c730b5ff487ba4fe9ce51e67bd982aa07c95e5f5679b7b2f24ad129", - "https://deno.land/std@0.217.0/io/write_all.ts": "24aac2312bb21096ae3ae0b102b22c26164d3249dff96dbac130958aa736f038", - "https://deno.land/std@0.217.0/streams/_common.ts": "4f9f2958d853b9a456be033631dabb7519daa68ee4d02caf53e2ecbffaf5805f", - "https://deno.land/std@0.217.0/streams/buffer.ts": "e012de72a53ad17c56512488e9afb6f4b6ed046b32fc1415ae7a4e6fc0efce38", - "https://deno.land/std@0.217.0/streams/byte_slice_stream.ts": "5bbdcadb118390affa9b3d0a0f73ef8e83754f59bb89df349add669dd9369713", - "https://deno.land/std@0.217.0/streams/delimiter_stream.ts": "45271f9db844e8e501a6df75b946cd2a5e01663de0e9ccf26b92996983e0cdbe", - "https://deno.land/std@0.217.0/streams/early_zip_readable_streams.ts": "21f5cf6dd36381c6a50c31a7727b5bd219f6382bbb7a413418595c3e466c4d14", - "https://deno.land/std@0.217.0/streams/iterate_reader.ts": "a50bed95514736c3c554e4c69ea2d8d2699252e4e74507769999d22c3886c777", - "https://deno.land/std@0.217.0/streams/limited_bytes_transform_stream.ts": "b22a45a337374e863c4eb1867ec6b8ad3e68620a6c52fe837746060ea610e6f1", - "https://deno.land/std@0.217.0/streams/limited_transform_stream.ts": "4c47da5ca38a30fa9f33b0f1a61d4548e7f52a9a58c294b0f430f680e44cc543", - "https://deno.land/std@0.217.0/streams/merge_readable_streams.ts": "9c541012e130d6e36086b6b8c197078a6053f5446367e33f233b71858a2c03cc", - "https://deno.land/std@0.217.0/streams/mod.ts": "d56624832b9649b680c74ab9c77e746e8be81ae1a24756cc04623e25a0d43ce9", - "https://deno.land/std@0.217.0/streams/readable_stream_from_reader.ts": "4289a63836f73901441c1879f2be76eea2a983920f4b10a4a9b8a6d8c29ece56", - "https://deno.land/std@0.217.0/streams/reader_from_iterable.ts": "cf7785e518beaaba1dfb3ff4ae854bb76499bbc1f013910af6402ec7643bf769", - "https://deno.land/std@0.217.0/streams/reader_from_stream_reader.ts": "dda702bd365a133be8bdbc5a1ba96c67b350c3504410632f3a833895bfc7bae3", - "https://deno.land/std@0.217.0/streams/text_delimiter_stream.ts": "ef0d7898cea4a9fff850173ed9f3d2cf9e42ba858d8175bd89fe851c8dfa6a6e", - "https://deno.land/std@0.217.0/streams/text_line_stream.ts": "21f33d3922e019ec1a1676474beb543929cb564ec99b69cd2654e029e0f45bd5", - "https://deno.land/std@0.217.0/streams/to_array_buffer.ts": "1a9c07c4a396ce557ab205c44415815ab13b614fed94a12f62b80f8e650c726d", - "https://deno.land/std@0.217.0/streams/to_blob.ts": "bf5daaae50fa8f57e0c8bfd7474ebac16ac09e130e3d01ef2947ae5153912b4a", - "https://deno.land/std@0.217.0/streams/to_json.ts": "b6a908d0da7cd30956e5fbbfa7460747e50b8f307d1041282ed6fe9070d579ee", - "https://deno.land/std@0.217.0/streams/to_text.ts": "6f93593bdfc2cea5cca39755ea5caf0d4092580c0a713dfe04a1e85c60df331f", - "https://deno.land/std@0.217.0/streams/to_transform_stream.ts": "4c4836455ef89bab9ece55975ee3a819f07d3d8b0e43101ec7f4ed033c8a2b61", - "https://deno.land/std@0.217.0/streams/writable_stream_from_writer.ts": "62f2712d3a7bebd981fca8bd5140192c37450f9c4aa94283f7ca833e46bc7485", - "https://deno.land/std@0.217.0/streams/writer_from_stream_writer.ts": "b0e39ef607dfdc5abdfb627edf61a9672809463e2bb022afcbaf0cd006c40feb", - "https://deno.land/std@0.217.0/streams/zip_readable_streams.ts": "53eb10d7557539b489bd858907aab6dd28247f074b3446573801de3150cb932e", - "https://deno.land/std@0.217.0/testing/_test_suite.ts": "f10a8a6338b60c403f07a76f3f46bdc9f1e1a820c0a1decddeb2949f7a8a0546", - "https://deno.land/std@0.217.0/testing/bdd.ts": "a7a9f691c6531166e4afa9d91bd5750c7418407bb310473b27eda59fd2d1f609", - "https://deno.land/std@0.217.0/testing/types.ts": "36e519e8735884ce60ddd284195a28f6d22f83d3effe5df0ce27bafc17b5655d", "https://deno.land/x/deno_cache@0.7.1/auth_tokens.ts": "3cfe2c5e5f07e1f77020be94de1e1196915ccd77c3dfff8480fa8e4a1d1be7e2", "https://deno.land/x/deno_cache@0.7.1/cache.ts": "5632468ad366153fd33eeb15253935fde8a9c95cdbda9cd9841f8f345f55861d", "https://deno.land/x/deno_cache@0.7.1/deno_dir.ts": "1ea355b8ba11c630d076b222b197cfc937dd81e5a4a260938997da99e8ff93a0", @@ -135,10 +112,20 @@ "https://deno.land/x/emit@0.38.2/emit.generated.js": "5e0846d5faa47952e546415a570563098b93225f35bd80b14eb1da7c5932f6ca", "https://deno.land/x/emit@0.38.2/mod.ts": "2fa64c4d220c13b9d752933803056ce7694722367c3e9cb1ee86fe9f81c587f3", "https://deno.land/x/esbuild@v0.20.1/mod.js": "d50e500b53ce67e31116beba3916b0f9275c0e1cc20bc5cadc0fc1b7a3b06fd9", - "https://deno.land/x/streamtools@v0.5.0/collect.ts": "d421e9dcca5ec7b30b731797305efc9b986aa4cf411bf95aec661dc7b1e1ec11", - "https://deno.land/x/streamtools@v0.5.0/pipe_through_from.ts": "67b0c908e5dcb748ced483e2b31a1ec08d46fc839298b07bcd854ab4b39a4e2a", - "https://deno.land/x/streamtools@v0.5.0/pop.ts": "9ee4bbce7409e902a39bfcc0e49eaaab0008492dfba5f6679db28df6b3867299", "https://deno.land/x/wasmbuild@0.15.1/cache.ts": "9d01b5cb24e7f2a942bbd8d14b093751fa690a6cde8e21709ddc97667e6669ed", "https://deno.land/x/wasmbuild@0.15.1/loader.ts": "8c2fc10e21678e42f84c5135d8ab6ab7dc92424c3f05d2354896a29ccfd02a63" + }, + "workspace": { + "dependencies": [ + "jsr:@std/assert@^0.219.1", + "jsr:@std/dotenv@^0.219.1", + "jsr:@std/streams@^0.219.1", + "jsr:@std/testing@^0.219.1", + "npm:@noble/curves@^1.3.0", + "npm:@noble/hashes@^1.3.3" + ], + "members": { + "@lophus/core": {} + } } } diff --git a/lib/events_test.ts b/lib/events_test.ts deleted file mode 100644 index 708f16f..0000000 --- a/lib/events_test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { afterAll, beforeAll, describe, it } from "./std/testing.ts"; -import { assertEquals, assertInstanceOf } from "./std/assert.ts"; -import { pipeThroughFrom } from "./x/streamtools.ts"; -import type {} from "../core/protocol.d.ts"; -import { Relay } from "../core/relays.ts"; -import { PrivateKey, Signer } from "./signs.ts"; -import { EventInit, EventPublisher } from "./events.ts"; -import { MockWebSocket } from "../lib/testing.ts"; - -describe("EventPublisher", () => { - let relay: Relay; - let signer: Signer; - let publisher: EventPublisher<1>; - - beforeAll(() => { - globalThis.WebSocket = MockWebSocket; - signer = new Signer(PrivateKey.generate()); - }); - afterAll(() => { - relay?.close(); - }); - - it("should be a TransformStream", () => { - publisher = new EventPublisher(signer); - assertInstanceOf(publisher, TransformStream); - }); - - // FIXME: dangling promise - it.ignore("should transform EventInit to ClientToRelayMessage", async () => { - const { readable, writable } = publisher; - const reader = readable.getReader(); - const writer = writable.getWriter(); - const init = { kind: 1, content: "hello" } satisfies EventInit<1>; - await writer.write(init); - const { value } = await reader.read(); - assertEquals(value, ["EVENT", signer.sign(init)]); - await writer.close(); - await reader.cancel(); - }); - - // FIXME: runtime error - it("should be connectable to a relay", async () => { - relay = new Relay("wss://example.com"); - const writable = pipeThroughFrom(relay.writable, publisher); - assertInstanceOf(writable, WritableStream); - await writable.close(); - }); -}); diff --git a/lib/std/assert.ts b/lib/std/assert.ts deleted file mode 100644 index cd38a31..0000000 --- a/lib/std/assert.ts +++ /dev/null @@ -1,8 +0,0 @@ -export { assert } from "https://deno.land/std@0.217.0/assert/assert.ts"; -export { assertArrayIncludes } from "https://deno.land/std@0.217.0/assert/assert_array_includes.ts"; -export { assertEquals } from "https://deno.land/std@0.217.0/assert/assert_equals.ts"; -export { assertFalse } from "https://deno.land/std@0.217.0/assert/assert_false.ts"; -export { assertObjectMatch } from "https://deno.land/std@0.217.0/assert/assert_object_match.ts"; -export { assertThrows } from "https://deno.land/std@0.217.0/assert/assert_throws.ts"; -export { assertRejects } from "https://deno.land/std@0.217.0/assert/assert_rejects.ts"; -export { assertInstanceOf } from "https://deno.land/std@0.217.0/assert/assert_instance_of.ts"; diff --git a/lib/std/streams.ts b/lib/std/streams.ts deleted file mode 100644 index 0656a97..0000000 --- a/lib/std/streams.ts +++ /dev/null @@ -1 +0,0 @@ -export { mergeReadableStreams } from "https://deno.land/std@0.217.0/streams/mod.ts"; diff --git a/lib/std/testing.ts b/lib/std/testing.ts deleted file mode 100644 index e327b4e..0000000 --- a/lib/std/testing.ts +++ /dev/null @@ -1,12 +0,0 @@ -export { - afterAll, - afterEach, - beforeAll, - beforeEach, - describe, - it, -} from "https://deno.land/std@0.217.0/testing/bdd.ts"; -export { - assertType, - type Has, -} from "https://deno.land/std@0.217.0/testing/types.ts"; diff --git a/lib/testing_test.ts b/lib/testing_test.ts index f072990..41029fd 100644 --- a/lib/testing_test.ts +++ b/lib/testing_test.ts @@ -1,11 +1,15 @@ -import { beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assert, assertEquals } from "../lib/std/assert.ts"; -import { MockWebSocket } from "../lib/testing.ts"; +import { beforeAll, describe, it } from "@std/testing/bdd"; +import { assert, assertEquals } from "@std/assert"; +import { MockWebSocket } from "./testing.ts"; describe("MockWebSocket", () => { let ws: MockWebSocket; - describe("new()", () => { + it("should be able to replace globalThis.WebSocket", () => { + globalThis.WebSocket = MockWebSocket; + }); + + describe("new", () => { it("should create an instance without a url", () => { ws = new MockWebSocket(); assert(ws instanceof MockWebSocket); @@ -15,24 +19,28 @@ describe("MockWebSocket", () => { assert(ws instanceof MockWebSocket); }); }); - describe("get instances()", () => { + + describe("instances", () => { it("should return an array of instances", () => { assertEquals(MockWebSocket.instances.length, 2); }); }); - describe("get readyState()", () => { + + describe("readyState", () => { it("should return the WebSocket.OPEN for a valid instance", () => { assertEquals(ws.readyState, WebSocket.OPEN); }); }); - describe("get remote()", () => { + + describe("remote", () => { it("should return a remote instance", () => { assert(ws.remote); assertEquals(ws.remote.url, ws.url); assertEquals(ws.remote.remote, ws); }); }); - describe("send()", () => { + + describe("send", () => { it("should send a message to the remote WebSocket", async () => { const promise = new Promise((resolve) => { ws.remote.addEventListener("message", () => resolve(true)); @@ -41,13 +49,16 @@ describe("MockWebSocket", () => { assert(await promise); }); }); - describe("close()", () => { + + describe("close", () => { let remote_closed: Promise; + beforeAll(() => { remote_closed = new Promise((resolve) => { ws.remote.addEventListener("close", () => resolve(true)); }); }); + it("should close the WebSocket", async () => { const closed = new Promise((resolve) => { ws.addEventListener("close", () => resolve(true)); @@ -56,14 +67,13 @@ describe("MockWebSocket", () => { assert(await closed); assertEquals(ws.readyState, WebSocket.CLOSED); }); + it("should close the remote WebSocket", () => { assertEquals(ws.remote.readyState, WebSocket.CLOSED); }); + it("should trigger the onclose event on the remote WebSocket", async () => { assert(await remote_closed); }); }); - it("should be able to replace globalThis.WebSocket", () => { - globalThis.WebSocket = MockWebSocket; - }); }); diff --git a/lib/types.ts b/lib/types.ts index 6ba3b77..5f6a6fa 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,3 +1,33 @@ +// ---------------------- +// Branded types +// ---------------------- +export type Brand = T & { __brand: B }; + +// ---------------------- +// Promises +// ---------------------- +export type PromiseCallbacks = { + resolve: (value: T | PromiseLike) => void; + reject: (reason?: unknown) => void; +}; + +// ---------------------- +// Strings +// ---------------------- +export type Url = `https://${string}` | `http://${string}`; +export type Stringified = string & { __content: T }; + +// deno-fmt-ignore +export type AlphabetLetter = + | "a" | "b" | "c" | "d" | "e" | "f" | "g" + | "h" | "i" | "j" | "k" | "l" | "m" | "n" + | "o" | "p" | "q" | "r" | "s" | "t" | "u" + | "v" | "w" | "x" | "y" | "z" + | "A" | "B" | "C" | "D" | "E" | "F" | "G" + | "H" | "I" | "J" | "K" | "L" | "M" | "N" + | "O" | "P" | "Q" | "R" | "S" | "T" | "U" + | "V" | "W" | "X" | "Y" | "Z"; + // ---------------------- // Records and maps // ---------------------- diff --git a/lib/x/mock-socket.ts b/lib/x/mock-socket.ts deleted file mode 100644 index 2dd0e37..0000000 --- a/lib/x/mock-socket.ts +++ /dev/null @@ -1 +0,0 @@ -export { Server, WebSocket } from "npm:mock-socket@9.3.1"; diff --git a/lib/x/noble.ts b/lib/x/noble.ts deleted file mode 100644 index 62a4455..0000000 --- a/lib/x/noble.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { schnorr } from "npm:@noble/curves@1.3.0/secp256k1"; -export { sha256 } from "npm:@noble/hashes@1.3.3/sha256"; -export { bytesToHex } from "npm:@noble/hashes@1.3.3/utils"; diff --git a/lib/x/streamtools.ts b/lib/x/streamtools.ts deleted file mode 100644 index f3b47dc..0000000 --- a/lib/x/streamtools.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { collect } from "https://deno.land/x/streamtools@v0.5.0/collect.ts"; -export { pop } from "https://deno.land/x/streamtools@v0.5.0/pop.ts"; -export { pipeThroughFrom } from "https://deno.land/x/streamtools@v0.5.0/pipe_through_from.ts"; diff --git a/mod.ts b/mod.ts deleted file mode 100644 index 654e217..0000000 --- a/mod.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./core/protocol.d.ts"; -export * from "./core/relays.ts"; -export * from "./core/clients.ts"; diff --git a/nips/01/clients.ts b/nips/01/clients.ts index def291c..b3b4cf2 100644 --- a/nips/01/clients.ts +++ b/nips/01/clients.ts @@ -1,4 +1,4 @@ -import type { NostrEvent } from "../../core/protocol.d.ts"; +import type { NostrEvent } from "../../core/protocol.ts"; import { ClientModule } from "../../core/clients.ts"; interface EventValidationContext { diff --git a/nips/01/clients_test.ts b/nips/01/clients_test.ts index 1bf45a4..251cc87 100644 --- a/nips/01/clients_test.ts +++ b/nips/01/clients_test.ts @@ -1,12 +1,12 @@ -import { afterAll, beforeAll, describe, it } from "../../lib/std/testing.ts"; -import { assert, assertEquals } from "../../lib/std/assert.ts"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; +import { assert, assertEquals } from "@std/assert"; import { MockWebSocket } from "../../lib/testing.ts"; import { ClientToRelayMessage, NostrEvent, RelayToClientMessage, SubscriptionId, -} from "../../core/protocol.d.ts"; +} from "../../core/protocol.ts"; import { Client } from "../../core/clients.ts"; import nip_01 from "../01/clients.ts"; diff --git a/nips/01/protocol.d.ts b/nips/01/protocol.ts similarity index 92% rename from nips/01/protocol.d.ts rename to nips/01/protocol.ts index 010c62e..f098b3d 100644 --- a/nips/01/protocol.d.ts +++ b/nips/01/protocol.ts @@ -7,10 +7,10 @@ * @module */ -import "../../core/protocol.d.ts"; -import type { Url } from "../../core/types.ts"; +import "../../core/protocol.ts"; +import type { Url } from "../../lib/types.ts"; -declare module "../../core/protocol.d.ts" { +declare module "../../core/protocol.ts" { interface NipRecord { 1: { ClientToRelayMessage: "EVENT" | "REQ" | "CLOSE"; diff --git a/nips/01/protocol_test.ts b/nips/01/protocol_test.ts index 7d7660b..911bfb6 100644 --- a/nips/01/protocol_test.ts +++ b/nips/01/protocol_test.ts @@ -1,9 +1,13 @@ -import { describe, it } from "../../lib/std/testing.ts"; -import { assertType, Has } from "../../lib/std/testing.ts"; -import type { EventId, PublicKey } from "../../core/protocol.d.ts"; -import { Timestamp } from "../../lib/times.ts"; -import { SubscriptionFilter, Tag } from "../../core/protocol.d.ts"; -import "./protocol.d.ts"; +import { describe, it } from "@std/testing/bdd"; +import { assertType, Has } from "@std/testing/types"; +import type { + EventId, + PublicKey, + SubscriptionFilter, + Tag, +} from "../../core/protocol.ts"; +import { Timestamp } from "../../std/times.ts"; +import "./protocol.ts"; describe("Tag", () => { it("valid event tag", () => { diff --git a/nips/01/relays_test.ts b/nips/01/relays_test.ts index 2772fa3..f6d5c33 100644 --- a/nips/01/relays_test.ts +++ b/nips/01/relays_test.ts @@ -1,10 +1,5 @@ -import "./protocol.d.ts"; -import { afterAll, beforeAll, describe, it } from "../../lib/std/testing.ts"; -import { - assert, - assertEquals, - assertInstanceOf, -} from "../../lib/std/assert.ts"; +import { assert, assertEquals, assertInstanceOf } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; import { MockWebSocket } from "../../lib/testing.ts"; import { ClientToRelayMessage, @@ -12,10 +7,11 @@ import { NostrEvent, RelayToClientMessage, SubscriptionId, -} from "../../core/protocol.d.ts"; +} from "../../core/protocol.ts"; import { ConnectionClosed, EventRejected, Relay } from "../../core/relays.ts"; -import { SubscriptionClosed } from "../../nips/01/relays.ts"; -import nip_01 from "../../nips/01/relays.ts"; +import { SubscriptionClosed } from "./relays.ts"; +import nip_01 from "./relays.ts"; +import "./protocol.ts"; function getRemoteSocket() { return MockWebSocket.instances[0].remote; diff --git a/nips/02/protocol.d.ts b/nips/02/protocol.ts similarity index 73% rename from nips/02/protocol.d.ts rename to nips/02/protocol.ts index 37c9981..50878d7 100644 --- a/nips/02/protocol.d.ts +++ b/nips/02/protocol.ts @@ -1,6 +1,6 @@ -import "../../core/protocol.d.ts"; +import "../../core/protocol.ts"; -declare module "../../core/protocol.d.ts" { +declare module "../../core/protocol.ts" { interface NipRecord { 2: { Tag: "p"; diff --git a/nips/02/protocol_test.ts b/nips/02/protocol_test.ts index fe21193..6329096 100644 --- a/nips/02/protocol_test.ts +++ b/nips/02/protocol_test.ts @@ -1,8 +1,8 @@ -import { describe, it } from "../../lib/std/testing.ts"; -import { assertType, Has } from "../../lib/std/testing.ts"; -import { EventInit } from "../../lib/events.ts"; -import type { EventId, PublicKey } from "../../core/protocol.d.ts"; -import "./protocol.d.ts"; +import { describe, it } from "@std/testing/bdd"; +import { assertType, Has } from "@std/testing/types"; +import { EventInit } from "../../std/events.ts"; +import type { EventId, PublicKey } from "../../core/protocol.ts"; +import "./protocol.ts"; describe("EventInit<3>", () => { it("valid", () => { diff --git a/nips/07/protocol.d.ts b/nips/07/protocol.ts similarity index 90% rename from nips/07/protocol.d.ts rename to nips/07/protocol.ts index 81d451d..3ecd70c 100644 --- a/nips/07/protocol.d.ts +++ b/nips/07/protocol.ts @@ -1,7 +1,7 @@ -import { EventKind, NostrEvent, PublicKey } from "../../core/protocol.d.ts"; +import { EventKind, NostrEvent, PublicKey } from "../../core/protocol.ts"; import type { Optional } from "../../lib/types.ts"; -declare module "../../core/protocol.d.ts" { +declare module "../../core/protocol.ts" { interface NipRecord { 7: Record; } diff --git a/nips/07/signs.ts b/nips/07/signs.ts index 5c29d70..3e8a56a 100644 --- a/nips/07/signs.ts +++ b/nips/07/signs.ts @@ -1,8 +1,8 @@ -import type { Stringified } from "../../core/types.ts"; -import { EventContent, EventKind, NostrEvent } from "../../core/protocol.d.ts"; -import { EventInit } from "../../lib/events.ts"; -import { Timestamp } from "../../lib/times.ts"; -import { UnsignedEvent } from "./protocol.d.ts"; +import type { Stringified } from "../../lib/types.ts"; +import { EventContent, EventKind, NostrEvent } from "../../core/protocol.ts"; +import { EventInit } from "../../std/events.ts"; +import { Timestamp } from "../../std/times.ts"; +import { UnsignedEvent } from "./protocol.ts"; /** * A transform stream that signs events. diff --git a/nips/42/protocol.d.ts b/nips/42/protocol.ts similarity index 88% rename from nips/42/protocol.d.ts rename to nips/42/protocol.ts index 97397f9..38ec14a 100644 --- a/nips/42/protocol.d.ts +++ b/nips/42/protocol.ts @@ -1,7 +1,7 @@ -import "../../core/protocol.d.ts"; +import "../../core/protocol.ts"; import "../../core/relays.ts"; -declare module "../../core/protocol.d.ts" { +declare module "../../core/protocol.ts" { interface NipRecord { 42: { ClientToRelayMessage: "AUTH"; diff --git a/nips/42/protocol_test.ts b/nips/42/protocol_test.ts index a4b7056..be50c37 100644 --- a/nips/42/protocol_test.ts +++ b/nips/42/protocol_test.ts @@ -1,7 +1,7 @@ -import { describe, it } from "../../lib/std/testing.ts"; -import { assertType, Has } from "../../lib/std/testing.ts"; -import { EventInit } from "../../lib/events.ts"; -import "./protocol.d.ts"; +import { describe, it } from "@std/testing/bdd"; +import { assertType, Has } from "@std/testing/types"; +import { EventInit } from "../../std/events.ts"; +import "./protocol.ts"; describe("EventInit<22242>", () => { it("can be valid", () => { diff --git a/nips/42/relays.ts b/nips/42/relays.ts index 39eaa63..fb6590b 100644 --- a/nips/42/relays.ts +++ b/nips/42/relays.ts @@ -1,8 +1,8 @@ -import type { Stringified } from "../../core/types.ts"; +import type { Stringified } from "../../lib/types.ts"; import type { RelayModule } from "../../core/relays.ts"; -import type { EventInit } from "../../lib/events.ts"; -import type { Signer } from "../../lib/signs.ts"; -import "./protocol.d.ts"; +import type { EventInit } from "../../std/events.ts"; +import type { Signer } from "../../std/signs.ts"; +import "./protocol.ts"; declare module "../../core/relays.ts" { interface RelayConfig { diff --git a/lib/env.ts b/std/env.ts similarity index 84% rename from lib/env.ts rename to std/env.ts index 32f9bde..2d0d30d 100644 --- a/lib/env.ts +++ b/std/env.ts @@ -1,5 +1,5 @@ -import "https://deno.land/std@0.217.0/dotenv/load.ts"; -import type { PrivateKey, PublicKey } from "../mod.ts"; +import "@std/dotenv"; +import type { PrivateKey, PublicKey } from "../core/protocol.ts"; class Env { #nsec?: PrivateKey; diff --git a/lib/events.ts b/std/events.ts similarity index 89% rename from lib/events.ts rename to std/events.ts index c9a196e..95b06af 100644 --- a/lib/events.ts +++ b/std/events.ts @@ -3,8 +3,8 @@ import type { EventContent, EventKind, NostrEvent, -} from "../mod.ts"; -import { Stringified } from "../core/types.ts"; +} from "../core/protocol.ts"; +import { Stringified } from "../lib/types.ts"; export interface EventInit { kind: NostrEvent["kind"]; diff --git a/std/events_test.ts b/std/events_test.ts new file mode 100644 index 0000000..eb5244e --- /dev/null +++ b/std/events_test.ts @@ -0,0 +1,51 @@ +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; +import { assertEquals, assertInstanceOf } from "@std/assert"; +import { Relay } from "../core/relays.ts"; +import { PrivateKey, Signer } from "./signs.ts"; +import { EventInit, EventPublisher } from "./events.ts"; +import { MockWebSocket } from "../lib/testing.ts"; + +describe("EventPublisher", () => { + let relay: Relay; + let signer: Signer; + let publisher: EventPublisher<1>; + + beforeAll(() => { + globalThis.WebSocket = MockWebSocket; + signer = new Signer(PrivateKey.generate()); + }); + afterAll(() => { + relay?.close(); + }); + + it("should be a TransformStream", () => { + publisher = new EventPublisher(signer); + assertInstanceOf(publisher, TransformStream); + }); + + // FIXME: dangling promise + // @ts-ignore missing property `ignore` + it.ignore( + "should transform EventInit to ClientToRelayMessage", + async () => { + const { readable, writable } = publisher; + const reader = readable.getReader(); + const writer = writable.getWriter(); + const init = { kind: 1, content: "hello" } satisfies EventInit<1>; + await writer.write(init); + const { value } = await reader.read(); + assertEquals(value, ["EVENT", signer.sign(init)]); + await writer.close(); + await reader.cancel(); + }, + ); + + // FIXME: runtime error + // @ts-ignore missing property `ignore` + it.ignore("should be connectable to a relay", () => { + relay = new Relay("wss://example.com"); + // const writable = pipeThroughFrom(relay.writable, publisher); + // assertInstanceOf(writable, WritableStream); + // await writable.close(); + }); +}); diff --git a/lib/logging.ts b/std/logging.ts similarity index 100% rename from lib/logging.ts rename to std/logging.ts diff --git a/lib/logging_test.ts b/std/logging_test.ts similarity index 78% rename from lib/logging_test.ts rename to std/logging_test.ts index 90724cd..51a6044 100644 --- a/lib/logging_test.ts +++ b/std/logging_test.ts @@ -1,7 +1,6 @@ -import { beforeEach, describe, it } from "../lib/std/testing.ts"; -import { assertEquals } from "../lib/std/assert.ts"; +import { assert, assertEquals } from "@std/assert"; +import { beforeEach, describe, it } from "@std/testing/bdd"; import { ConsoleLogger } from "./logging.ts"; -import { assert } from "../lib/std/assert.ts"; describe("ConsoleLogger", () => { let output = ""; diff --git a/lib/notes.ts b/std/notes.ts similarity index 88% rename from lib/notes.ts rename to std/notes.ts index 4c2f068..d93a2c1 100644 --- a/lib/notes.ts +++ b/std/notes.ts @@ -1,5 +1,5 @@ -import type { NostrEvent, RelayUrl } from "../mod.ts"; -import type { Optional } from "./types.ts"; +import type { Optional } from "../lib/types.ts"; +import type { NostrEvent, RelayUrl } from "../core/protocol.ts"; import { EventInit } from "./events.ts"; export type TextNote = EventInit<1>; diff --git a/lib/relays.ts b/std/relays.ts similarity index 95% rename from lib/relays.ts rename to std/relays.ts index 3e70f86..ac229b9 100644 --- a/lib/relays.ts +++ b/std/relays.ts @@ -3,14 +3,14 @@ import type { EventKind, NostrEvent, SubscriptionFilter, -} from "../core/protocol.d.ts"; +} from "../core/protocol.ts"; import { RelayLike, RelayLikeConfig, RelayLikeOptions, SubscriptionOptions, } from "../core/relays.ts"; -import { Distinctor, merge } from "../lib/streams.ts"; +import { Distinctor, merge } from "../std/streams.ts"; /** * A pool of relays that can be used as a single relay. diff --git a/lib/relays_test.ts b/std/relays_test.ts similarity index 89% rename from lib/relays_test.ts rename to std/relays_test.ts index 9e9df19..c0ac78d 100644 --- a/lib/relays_test.ts +++ b/std/relays_test.ts @@ -1,8 +1,8 @@ -import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts"; -import { assertEquals, assertInstanceOf } from "../lib/std/assert.ts"; -import { NostrEvent } from "../core/protocol.d.ts"; +import { assertEquals, assertInstanceOf } from "@std/assert"; +import { afterAll, beforeAll, describe, it } from "@std/testing/bdd"; +import { NostrEvent } from "../core/protocol.ts"; import { Relay } from "../core/relays.ts"; -import { RelayGroup } from "../lib/relays.ts"; +import { RelayGroup } from "../std/relays.ts"; import { MockWebSocket } from "../lib/testing.ts"; describe("RelayGroup", () => { diff --git a/lib/signs.ts b/std/signs.ts similarity index 88% rename from lib/signs.ts rename to std/signs.ts index ab19e73..3b19742 100644 --- a/lib/signs.ts +++ b/std/signs.ts @@ -1,4 +1,7 @@ -import type { Brand, Stringified } from "../core/types.ts"; +import { sha256 } from "@noble/hashes/sha256"; +import { bytesToHex } from "@noble/hashes/utils"; +import { schnorr } from "@noble/curves/secp256k1"; +import type { Brand, Stringified } from "../lib/types.ts"; import type { EventContent, EventId, @@ -6,13 +9,12 @@ import type { EventSerializePrecursor, NostrEvent, Signature, -} from "../core/protocol.d.ts"; -import type { UnsignedEvent } from "../nips/07/protocol.d.ts"; -import { bytesToHex, schnorr, sha256 } from "./x/noble.ts"; +} from "../core/protocol.ts"; +import type { UnsignedEvent } from "../nips/07/protocol.ts"; import type { EventInit } from "./events.ts"; import { Timestamp } from "./times.ts"; -export type { UnsignedEvent } from "../nips/07/protocol.d.ts"; +export type { UnsignedEvent } from "../nips/07/protocol.ts"; export type PrivateKey = Brand; diff --git a/lib/signs_test.ts b/std/signs_test.ts similarity index 84% rename from lib/signs_test.ts rename to std/signs_test.ts index 7fd4a67..fb3aedd 100644 --- a/lib/signs_test.ts +++ b/std/signs_test.ts @@ -1,8 +1,8 @@ -import { Stringified } from "../core/types.ts"; -import "../nips/01/protocol.d.ts"; -import { describe, it } from "../lib/std/testing.ts"; -import { assert, assertEquals } from "../lib/std/assert.ts"; -import { Timestamp } from "../lib/times.ts"; +import { describe, it } from "@std/testing/bdd"; +import { assert, assertEquals } from "@std/assert"; +import { Stringified } from "../lib/types.ts"; +import "../nips/01/protocol.ts"; +import { Timestamp } from "./times.ts"; import { PrivateKey, PublicKey, diff --git a/lib/streams.ts b/std/streams.ts similarity index 92% rename from lib/streams.ts rename to std/streams.ts index 26f0833..f72f64d 100644 --- a/lib/streams.ts +++ b/std/streams.ts @@ -1,4 +1,4 @@ -export { mergeReadableStreams as merge } from "./std/streams.ts"; +export { mergeReadableStreams as merge } from "@std/streams"; /** * TransformStream which filters out duplicate values from a stream. diff --git a/lib/streams_test.ts b/std/streams_test.ts similarity index 64% rename from lib/streams_test.ts rename to std/streams_test.ts index 3fc718b..e854a8f 100644 --- a/lib/streams_test.ts +++ b/std/streams_test.ts @@ -1,6 +1,5 @@ -import { describe, it } from "../lib/std/testing.ts"; -import { assertArrayIncludes, assertEquals } from "../lib/std/assert.ts"; -import { collect } from "../lib/x/streamtools.ts"; +import { assertArrayIncludes, assertEquals } from "@std/assert"; +import { describe, it } from "@std/testing/bdd"; import { Distinctor } from "./streams.ts"; describe("Distinctor", () => { @@ -14,7 +13,9 @@ describe("Distinctor", () => { controller.close(); }, }); - const values = await collect(stream.pipeThrough(new Distinctor((v) => v))); + const values = await Array.fromAsync( + stream.pipeThrough(new Distinctor((v) => v)), + ); assertEquals(values.length, 3); assertArrayIncludes(values, [1, 2, 3]); }); diff --git a/lib/times.ts b/std/times.ts similarity index 79% rename from lib/times.ts rename to std/times.ts index aa30ae3..b65b7ac 100644 --- a/lib/times.ts +++ b/std/times.ts @@ -1,4 +1,4 @@ -import { Brand } from "../core/types.ts"; +import { Brand } from "../lib/types.ts"; export type Timestamp = Brand;