Skip to content

Commit b887f8e

Browse files
authored
build: migrate to JSR (#31)
1 parent 74812dd commit b887f8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+304
-305
lines changed

core/clients.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
NostrEvent,
44
RelayToClientMessage,
55
SubscriptionId,
6-
} from "./protocol.d.ts";
6+
} from "./protocol.ts";
77
import {
88
NostrNode,
99
NostrNodeBase,
@@ -36,10 +36,10 @@ export class Client extends NostrNodeBase<
3636
/**
3737
* Writable interface for the subscriptions.
3838
*/
39-
readonly subscriptions = new Map<
39+
readonly subscriptions: Map<
4040
SubscriptionId,
4141
WritableStream<NostrEvent>
42-
>();
42+
> = new Map();
4343

4444
constructor(ws: WebSocket, opts?: ClientOptions) {
4545
super(ws, opts);

core/clients_test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Client } from "./clients.ts";
2-
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
3-
import { assert } from "../lib/std/assert.ts";
1+
import { assert } from "@std/assert";
2+
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
43
import { MockWebSocket } from "../lib/testing.ts";
4+
import { Client } from "./clients.ts";
55

66
describe("Client", () => {
77
let ws: MockWebSocket;

core/deno.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@lophus/core",
3+
"version": "0.0.14",
4+
"exports": "./mod.ts",
5+
6+
"publish": {
7+
"exclude": [
8+
"deno.json",
9+
"*_test.ts"
10+
]
11+
}
12+
}

core/mod.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./protocol.ts";
2+
export * from "./relays.ts";
3+
export * from "./clients.ts";

core/nodes.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NostrMessage } from "./protocol.d.ts";
1+
import type { NostrMessage } from "./protocol.ts";
22
import { WebSocketLike } from "./websockets.ts";
33

44
export interface NostrNodeConfig<
@@ -89,15 +89,15 @@ export class NostrNodeBase<
8989
this.config.modules.forEach((m) => this.install(m));
9090
}
9191

92-
send(msg: W) {
92+
send(msg: W): void | Promise<void> {
9393
return this.ws.send(JSON.stringify(msg));
9494
}
9595

96-
get status() {
96+
get status(): WebSocket["readyState"] {
9797
return this.ws.readyState;
9898
}
9999

100-
async close() {
100+
async close(): Promise<void> {
101101
try {
102102
await this.writable.close();
103103
} catch (err) {
@@ -107,8 +107,8 @@ export class NostrNodeBase<
107107
}
108108
}
109109

110-
install(mod: NostrNodeModule<W, R>) {
111-
return mod.install(this);
110+
install(mod: NostrNodeModule<W, R>): void {
111+
mod.install(this);
112112
}
113113

114114
declare addEventListener: NostrNode<W, R>["addEventListener"];

core/nodes_test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { NostrNode, NostrNodeBase } from "./nodes.ts";
2-
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
3-
import { assertEquals } from "../lib/std/assert.ts";
1+
import { assertEquals } from "@std/assert";
2+
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
43
import { MockWebSocket } from "../lib/testing.ts";
4+
import { NostrNode, NostrNodeBase } from "./nodes.ts";
55

66
describe("NostrNodeBase", () => {
77
let node: NostrNode;

core/protocol.d.ts core/protocol.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @module
1010
*/
1111

12-
import type { AlphabetLetter, Brand, Stringified } from "./types.ts";
12+
import type { AlphabetLetter, Brand, Stringified } from "../lib/types.ts";
1313

1414
// ----------------------
1515
// Extendable interfaces

core/relays.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Stringified } from "./types.ts";
1+
import type { Stringified } from "../lib/types.ts";
22
import type {
33
ClientToRelayMessage,
44
EventId,
@@ -9,7 +9,7 @@ import type {
99
RelayUrl,
1010
SubscriptionFilter,
1111
SubscriptionId,
12-
} from "./protocol.d.ts";
12+
} from "./protocol.ts";
1313
import { LazyWebSocket } from "./websockets.ts";
1414
import { NostrNodeBase, NostrNodeConfig, NostrNodeModule } from "./nodes.ts";
1515

@@ -52,7 +52,7 @@ export class Relay extends NostrNodeBase<
5252
RelayEventTypeRecord
5353
> {
5454
declare ws: LazyWebSocket;
55-
readonly config: Readonly<RelayConfig>;
55+
declare config: RelayConfig;
5656

5757
constructor(
5858
init: RelayUrl | RelayInit,

core/relays_test.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { assert, assertEquals, assertObjectMatch } from "@std/assert";
2+
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
13
import { Relay } from "./relays.ts";
2-
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
3-
import { assert, assertEquals, assertObjectMatch } from "../lib/std/assert.ts";
44

55
const url = "wss://localhost:8080";
66

@@ -11,24 +11,28 @@ describe("Relay", () => {
1111
beforeAll(() => {
1212
relay = new Relay(url);
1313
});
14-
afterAll(() => {
15-
relay.close();
16-
});
14+
15+
afterAll(() => relay.close());
16+
1717
it("should be constructable", () => {
1818
assert(relay instanceof Relay);
1919
});
20+
2021
it("should have a url", () => {
2122
assertEquals(relay.config.url, url);
2223
});
24+
2325
it("should have a name", () => {
2426
assertEquals(relay.config.name, "localhost");
2527
});
28+
2629
it("should have default options", () => {
2730
assertObjectMatch(relay.config, {
2831
read: true,
2932
write: true,
3033
});
3134
});
35+
3236
it("should not be connected initially", () => {
3337
assertEquals(relay.status, WebSocket.CLOSED);
3438
});
@@ -43,12 +47,15 @@ describe("Relay", () => {
4347
nbuffer: 20,
4448
});
4549
});
50+
4651
afterAll(() => {
4752
relay.close();
4853
});
54+
4955
it("should be constructable", () => {
5056
assert(relay instanceof Relay);
5157
});
58+
5259
it("should have the given options", () => {
5360
assertObjectMatch(relay.config, {
5461
name: "test",

core/types.ts

-34
This file was deleted.

core/websockets_test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
2-
import { assert, assertEquals } from "../lib/std/assert.ts";
3-
import { LazyWebSocket } from "./websockets.ts";
1+
import { assert, assertEquals } from "@std/assert";
2+
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
43
import { MockWebSocket } from "../lib/testing.ts";
4+
import { LazyWebSocket } from "./websockets.ts";
55

66
describe("LazyWebSocket", () => {
77
let lazy: LazyWebSocket;

deno.json

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
{
2+
"exclude": [
3+
"dist/"
4+
],
5+
"imports": {
6+
"@noble/curves": "npm:@noble/curves@^1.3.0",
7+
"@noble/hashes": "npm:@noble/hashes@^1.3.3",
8+
"@std/assert": "jsr:@std/assert@^0.219.1",
9+
"@std/dotenv": "jsr:@std/dotenv@^0.219.1",
10+
"@std/streams": "jsr:@std/streams@^0.219.1",
11+
"@std/testing": "jsr:@std/testing@^0.219.1"
12+
},
213
"tasks": {
14+
"build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts",
315
"cache": "deno cache ./**/*.ts --lock",
4-
"lock": "deno task cache --lock-write && git add deno.lock",
516
"check": "deno check ./**/*.ts",
6-
"test": "deno test -A --no-check --parallel",
7-
"build": "mkdir -p ./dist && deno run -A ./bin/bundle.ts",
8-
"dev": "deno fmt && deno lint && deno task -q check && deno task -q lock && deno task -q test",
9-
"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",
10-
"update:commit": "deno task -q update --commit --pre-commit=dev --prefix 'build(deps):'"
17+
"lock": "deno task cache --lock-write && git add deno.lock",
18+
"pre-commit": "deno fmt && deno lint && deno task -q check && deno task -q lock && deno task -q test",
19+
"test": "deno test -A --no-check",
20+
"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",
21+
"update:commit": "deno task -q update --commit --prefix 'build(deps):' --prefix-lock 'build(lock):'"
1122
},
12-
"exclude": [
13-
"dist/",
14-
"CHANGELOG.md"
23+
"workspaces": [
24+
"./core"
1525
]
1626
}

0 commit comments

Comments
 (0)