applesauce-relay 0.0.0-next-20250729145125 → 0.0.0-next-20250808173123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pool.d.ts +3 -1
- package/dist/pool.js +20 -1
- package/dist/relay.d.ts +2 -0
- package/dist/relay.js +4 -0
- package/dist/types.d.ts +4 -0
- package/package.json +3 -3
package/dist/pool.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type NostrEvent } from "nostr-tools";
|
|
|
2
2
|
import { BehaviorSubject, Observable } from "rxjs";
|
|
3
3
|
import { RelayGroup } from "./group.js";
|
|
4
4
|
import { Relay, RelayOptions } from "./relay.js";
|
|
5
|
-
import { IPool, PublishResponse, PublishOptions, RequestOptions, SubscriptionOptions, SubscriptionResponse, FilterInput } from "./types.js";
|
|
5
|
+
import { IPool, PublishResponse, PublishOptions, RequestOptions, SubscriptionOptions, SubscriptionResponse, FilterInput, IRelay } from "./types.js";
|
|
6
6
|
export declare class RelayPool implements IPool {
|
|
7
7
|
options?: RelayOptions | undefined;
|
|
8
8
|
groups$: BehaviorSubject<Map<string, RelayGroup>>;
|
|
@@ -17,6 +17,8 @@ export declare class RelayPool implements IPool {
|
|
|
17
17
|
relay(url: string): Relay;
|
|
18
18
|
/** Create a group of relays */
|
|
19
19
|
group(relays: string[]): RelayGroup;
|
|
20
|
+
/** Removes a relay from the pool and defaults to closing the connection */
|
|
21
|
+
remove(relay: string | IRelay, close?: boolean): void;
|
|
20
22
|
/** Make a REQ to multiple relays that does not deduplicate events */
|
|
21
23
|
req(relays: string[], filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
22
24
|
/** Send an EVENT message to multiple relays */
|
package/dist/pool.js
CHANGED
|
@@ -33,7 +33,8 @@ export class RelayPool {
|
|
|
33
33
|
return relay;
|
|
34
34
|
// Create a new relay
|
|
35
35
|
relay = new Relay(url, this.options);
|
|
36
|
-
this.relays
|
|
36
|
+
this.relays.set(url, relay);
|
|
37
|
+
this.relays$.next(this.relays);
|
|
37
38
|
return relay;
|
|
38
39
|
}
|
|
39
40
|
/** Create a group of relays */
|
|
@@ -50,6 +51,24 @@ export class RelayPool {
|
|
|
50
51
|
this.groups$.next(this.groups.set(key, group));
|
|
51
52
|
return group;
|
|
52
53
|
}
|
|
54
|
+
/** Removes a relay from the pool and defaults to closing the connection */
|
|
55
|
+
remove(relay, close = true) {
|
|
56
|
+
let instance;
|
|
57
|
+
if (typeof relay === "string") {
|
|
58
|
+
instance = this.relays.get(relay);
|
|
59
|
+
if (!instance)
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
else if (Array.from(this.relays.values()).some((r) => r === relay)) {
|
|
63
|
+
instance = relay;
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
return;
|
|
67
|
+
if (close)
|
|
68
|
+
instance?.close();
|
|
69
|
+
this.relays.delete(instance.url);
|
|
70
|
+
this.relays$.next(this.relays);
|
|
71
|
+
}
|
|
53
72
|
/** Make a REQ to multiple relays that does not deduplicate events */
|
|
54
73
|
req(relays, filters, id) {
|
|
55
74
|
return this.group(relays).req(filters, id);
|
package/dist/relay.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ export declare class Relay implements IRelay {
|
|
|
93
93
|
request(filters: Filter | Filter[], opts?: RequestOptions): Observable<NostrEvent>;
|
|
94
94
|
/** Publishes an event to the relay and retries when relay errors or responds with auth-required ( default 3 retries ) */
|
|
95
95
|
publish(event: NostrEvent, opts?: PublishOptions): Promise<PublishResponse>;
|
|
96
|
+
/** Force close the connection */
|
|
97
|
+
close(): void;
|
|
96
98
|
/** Static method to fetch the NIP-11 information document for a relay */
|
|
97
99
|
static fetchInformationDocument(url: string): Observable<RelayInformation | null>;
|
|
98
100
|
/** Static method to create a reconnection method for each relay */
|
package/dist/relay.js
CHANGED
|
@@ -364,6 +364,10 @@ export class Relay {
|
|
|
364
364
|
// Retry the publish until it succeeds or the number of retries is reached
|
|
365
365
|
retry(opts?.retries ?? 3)));
|
|
366
366
|
}
|
|
367
|
+
/** Force close the connection */
|
|
368
|
+
close() {
|
|
369
|
+
this.socket.unsubscribe();
|
|
370
|
+
}
|
|
367
371
|
/** Static method to fetch the NIP-11 information document for a relay */
|
|
368
372
|
static fetchInformationDocument(url) {
|
|
369
373
|
return from(fetch(ensureHttpURL(url), { headers: { Accept: "application/nostr+json" } }).then((res) => res.json())).pipe(
|
package/dist/types.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
36
36
|
readonly authenticated: boolean;
|
|
37
37
|
readonly challenge: string | null;
|
|
38
38
|
readonly notices: string[];
|
|
39
|
+
/** Force close the connection */
|
|
40
|
+
close(): void;
|
|
39
41
|
/** Send a REQ message */
|
|
40
42
|
req(filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
41
43
|
/** Send an EVENT message */
|
|
@@ -84,6 +86,8 @@ export interface IPool {
|
|
|
84
86
|
relay(url: string): IRelay;
|
|
85
87
|
/** Create a relay group */
|
|
86
88
|
group(relays: string[]): IGroup;
|
|
89
|
+
/** Removes a relay from the pool and defaults to closing the connection */
|
|
90
|
+
remove(relay: string | IRelay, close?: boolean): void;
|
|
87
91
|
/** Send a REQ message */
|
|
88
92
|
req(relays: string[], filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
89
93
|
/** Send an EVENT message */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-relay",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250808173123",
|
|
4
4
|
"description": "nostr relay communication framework built on rxjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@noble/hashes": "^1.7.1",
|
|
57
|
-
"applesauce-core": "0.0.0-next-
|
|
57
|
+
"applesauce-core": "0.0.0-next-20250808173123",
|
|
58
58
|
"nanoid": "^5.0.9",
|
|
59
59
|
"nostr-tools": "^2.13",
|
|
60
60
|
"rxjs": "^7.8.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
64
|
-
"applesauce-signers": "0.0.0-next-
|
|
64
|
+
"applesauce-signers": "0.0.0-next-20250808173123",
|
|
65
65
|
"@vitest/expect": "^3.1.1",
|
|
66
66
|
"typescript": "^5.7.3",
|
|
67
67
|
"vitest": "^3.2.3",
|