Skip to content

Commit 48319ee

Browse files
committed
refactor(core): stop exporting NIP-01 types from client.ts or relay.ts
1 parent 8e143d8 commit 48319ee

11 files changed

+25
-34
lines changed

client.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import type {
1010
RelayUrl,
1111
SubscriptionFilter,
1212
SubscriptionId,
13-
} from "./core/types.ts";
13+
} from "./core/nips/01.ts";
1414
import { NostrNode, NostrNodeConfig } from "./core/nodes.ts";
1515
import { NonExclusiveWritableStream } from "./core/streams.ts";
1616
import { LazyWebSocket } from "./core/websockets.ts";
1717
import { Lock } from "./core/x/async.ts";
1818

19-
export * from "./core/nips/01.ts";
20-
2119
/**
2220
* A class that represents a remote Nostr Relay.
2321
*/
@@ -152,7 +150,7 @@ export class Relay extends NostrNode<ClientToRelayMessage> {
152150
if (!accepted) {
153151
throw new Error(`Event rejected: ${body}`, { cause: event });
154152
}
155-
this.config.logger?.info?.("OK", this.config.name, body);
153+
this.config.logger?.debug?.("OK", this.config.name, body);
156154
}
157155

158156
async close() {

core/nodes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Logger, NostrMessage } from "./types.ts";
1+
import type { NostrMessage } from "./nips/01.ts";
2+
import type { Logger } from "./types.ts";
23
import { WebSocketLike, WebSocketReadyState } from "./websockets.ts";
34
import { NonExclusiveWritableStream } from "./streams.ts";
45

core/types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export type Optional<T, K extends keyof T> = Expand<
1818
& Partial<Pick<T, K>>
1919
>;
2020

21-
// NIPs
22-
export * from "./nips/01.ts";
23-
2421
// Logger
2522
export interface Logger {
2623
debug?: (...args: unknown[]) => void;

lib/env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "https://deno.land/std@0.203.0/dotenv/load.ts";
2-
import { PrivateKey, PublicKey } from "../core/types.ts";
2+
import { PrivateKey, PublicKey } from "../core/nips/01.ts";
33

44
class Env {
55
#nsec?: PrivateKey;

lib/events.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type {
55
PrivateKey,
66
Stringified,
77
Tag,
8-
} from "../core/types.ts";
8+
} from "../core/nips/01.ts";
99
import type { RelayLike } from "../client.ts";
1010

11-
export { EventKind } from "../core/types.ts";
11+
export { EventKind } from "../core/nips/01.ts";
1212

1313
export interface EventInit<K extends EventKind = EventKind> {
1414
kind: K;

lib/notes.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventKind, NostrEvent, RelayUrl } from "../core/types.ts";
1+
import { TagName, EventKind, NostrEvent, RelayUrl } from "../core/nips/01.ts";
22
import type { Optional } from "../core/types.ts";
33
import { EventInit } from "./events.ts";
44

@@ -17,16 +17,16 @@ export class TextNoteComposer extends TransformStream<TextNoteInit, TextNote> {
1717
compose(
1818
init: TextNoteInit,
1919
opts?: {
20-
reply_to?: NostrEvent;
21-
relay_recommend?: RelayUrl;
20+
replyTo?: NostrEvent;
21+
relayRecommend?: RelayUrl;
2222
},
2323
): TextNote {
24-
const relay_recommend = opts?.relay_recommend ?? this.opts.relay_recommend;
24+
const relayRecommend = opts?.relayRecommend ?? this.opts.relay_recommend;
2525

2626
// deno-fmt-ignore
27-
const tags = (init.tags ?? []).concat(opts?.reply_to ? [
28-
["e", opts.reply_to.id, relay_recommend ?? ""],
29-
["p", opts.reply_to.pubkey, relay_recommend ?? ""],
27+
const tags = (init.tags ?? []).concat(opts?.replyTo ? [
28+
["e" as TagName, opts.replyTo.id, relayRecommend ?? ""],
29+
["p" as TagName, opts.replyTo.pubkey, relayRecommend ?? ""],
3030
] : []);
3131

3232
return { ...init, kind: EventKind.TextNote, tags };

lib/pools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type {
22
ClientToRelayMessage,
33
EventKind,
44
SubscriptionFilter,
5-
} from "../core/types.ts";
5+
RelayUrl,
6+
} from "../core/nips/01.ts";
67
import {
78
Relay,
89
RelayInit,
910
RelayLike,
10-
RelayUrl,
1111
SubscriptionOptions,
1212
} from "../client.ts";
1313
import { NonExclusiveWritableStream } from "../core/streams.ts";

lib/signs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import type { Brand } from "../core/types.ts";
12
import type {
2-
Brand,
33
EventContent,
44
EventId,
55
EventKind,
66
EventSerializePrecursor,
77
NostrEvent,
88
Signature,
99
Stringified,
10-
} from "../core/types.ts";
10+
} from "../core/nips/01.ts";
1111
import type { EventInit } from "./events.ts";
1212
import { Timestamp } from "./times.ts";
1313
import { bytesToHex, schnorr, sha256 } from "./x/noble.ts";

relay.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import type {
33
NostrEvent,
44
RelayToClientMessage,
55
SubscriptionFilter,
6-
} from "./core/types.ts";
7-
import { SubscriptionId } from "./core/types.ts";
6+
SubscriptionId,
7+
} from "./core/nips/01.ts";
88
import { NostrNode, NostrNodeConfig } from "./core/nodes.ts";
99

10-
export * from "./core/types.ts";
11-
1210
/**
1311
* A class that represents a remote Nostr client.
1412
*/

tests/client_test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { NostrEvent, Relay } from "../client.ts";
1+
import { NostrEvent } from "../core/nips/01.ts";
2+
import { Relay } from "../client.ts";
23
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
34
import { assert, assertEquals, assertObjectMatch } from "../lib/std/assert.ts";
45
import { MockWebSocket } from "../lib/testing.ts";

tests/relay_test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
Client,
3-
NostrEvent,
4-
RelayToClientMessage,
5-
SubscriptionId,
6-
} from "../relay.ts";
1+
import { EventMessage, NostrEvent, SubscriptionId } from "../core/nips/01.ts";
2+
import { Client } from "../relay.ts";
73
import { afterAll, beforeAll, describe, it } from "../lib/std/testing.ts";
84
import { assert, assertEquals } from "../lib/std/assert.ts";
95
import { MockWebSocket } from "../lib/testing.ts";
@@ -73,7 +69,7 @@ describe("Client", () => {
7369
});
7470
it("should be able to deliver an event to a subscription", async () => {
7571
const msg = { kind: 0 };
76-
const received = new Promise<RelayToClientMessage>((resolve) => {
72+
const received = new Promise<EventMessage>((resolve) => {
7773
ws.remote.addEventListener("message", (ev: MessageEvent<string>) => {
7874
resolve(JSON.parse(ev.data));
7975
});

0 commit comments

Comments
 (0)