Skip to content

Commit

Permalink
build: migrate to JSR (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue authored Mar 12, 2024
1 parent 74812dd commit b887f8e
Show file tree
Hide file tree
Showing 48 changed files with 304 additions and 305 deletions.
6 changes: 3 additions & 3 deletions core/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
NostrEvent,
RelayToClientMessage,
SubscriptionId,
} from "./protocol.d.ts";
} from "./protocol.ts";
import {
NostrNode,
NostrNodeBase,
Expand Down Expand Up @@ -36,10 +36,10 @@ export class Client extends NostrNodeBase<
/**
* Writable interface for the subscriptions.
*/
readonly subscriptions = new Map<
readonly subscriptions: Map<
SubscriptionId,
WritableStream<NostrEvent>
>();
> = new Map();

constructor(ws: WebSocket, opts?: ClientOptions) {
super(ws, opts);
Expand Down
6 changes: 3 additions & 3 deletions core/clients_test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 12 additions & 0 deletions core/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@lophus/core",
"version": "0.0.14",
"exports": "./mod.ts",

"publish": {
"exclude": [
"deno.json",
"*_test.ts"
]
}
}
3 changes: 3 additions & 0 deletions core/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./protocol.ts";
export * from "./relays.ts";
export * from "./clients.ts";
12 changes: 6 additions & 6 deletions core/nodes.ts
Original file line number Diff line number Diff line change
@@ -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<
Expand Down Expand Up @@ -89,15 +89,15 @@ export class NostrNodeBase<
this.config.modules.forEach((m) => this.install(m));
}

send(msg: W) {
send(msg: W): void | Promise<void> {
return this.ws.send(JSON.stringify(msg));
}

get status() {
get status(): WebSocket["readyState"] {
return this.ws.readyState;
}

async close() {
async close(): Promise<void> {
try {
await this.writable.close();
} catch (err) {
Expand All @@ -107,8 +107,8 @@ export class NostrNodeBase<
}
}

install(mod: NostrNodeModule<W, R>) {
return mod.install(this);
install(mod: NostrNodeModule<W, R>): void {
mod.install(this);
}

declare addEventListener: NostrNode<W, R>["addEventListener"];
Expand Down
6 changes: 3 additions & 3 deletions core/nodes_test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/protocol.d.ts → core/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @module
*/

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

// ----------------------
// Extendable interfaces
Expand Down
6 changes: 3 additions & 3 deletions core/relays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Stringified } from "./types.ts";
import type { Stringified } from "../lib/types.ts";
import type {
ClientToRelayMessage,
EventId,
Expand All @@ -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";

Expand Down Expand Up @@ -52,7 +52,7 @@ export class Relay extends NostrNodeBase<
RelayEventTypeRecord
> {
declare ws: LazyWebSocket;
readonly config: Readonly<RelayConfig>;
declare config: RelayConfig;

constructor(
init: RelayUrl | RelayInit,
Expand Down
17 changes: 12 additions & 5 deletions core/relays_test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
});
Expand All @@ -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",
Expand Down
34 changes: 0 additions & 34 deletions core/types.ts

This file was deleted.

6 changes: 3 additions & 3 deletions core/websockets_test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
28 changes: 19 additions & 9 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
Loading

0 comments on commit b887f8e

Please sign in to comment.