applesauce-relay 3.1.0 → 4.1.0
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/README.md +2 -3
- package/dist/group.d.ts +37 -7
- package/dist/group.js +54 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/negentropy.d.ts +2 -2
- package/dist/liveness.d.ts +123 -0
- package/dist/liveness.js +327 -0
- package/dist/negentropy.d.ts +22 -6
- package/dist/negentropy.js +10 -3
- package/dist/operators/index.d.ts +1 -0
- package/dist/operators/index.js +1 -0
- package/dist/operators/liveness.d.ts +17 -0
- package/dist/operators/liveness.js +47 -0
- package/dist/pool.d.ts +19 -7
- package/dist/pool.js +35 -4
- package/dist/relay.d.ts +31 -2
- package/dist/relay.js +139 -19
- package/dist/types.d.ts +52 -9
- package/package.json +9 -10
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { EventTemplate, Filter, NostrEvent } from "nostr-tools";
|
|
2
|
+
import type { RelayInformation } from "nostr-tools/nip11";
|
|
3
|
+
import type { Observable, repeat, retry } from "rxjs";
|
|
4
|
+
import type { WebSocketSubject } from "rxjs/webSocket";
|
|
5
|
+
import type { NegentropySyncOptions, ReconcileFunction } from "./negentropy.js";
|
|
6
|
+
import type { IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core";
|
|
7
|
+
import type { SyncDirection } from "./relay.js";
|
|
8
|
+
import type { GroupNegentropySyncOptions, GroupRequestOptions, GroupSubscriptionOptions } from "./group.js";
|
|
4
9
|
export type SubscriptionResponse = NostrEvent | "EOSE";
|
|
5
10
|
export type PublishResponse = {
|
|
6
11
|
ok: boolean;
|
|
7
12
|
message?: string;
|
|
8
13
|
from: string;
|
|
9
14
|
};
|
|
15
|
+
export type CountResponse = {
|
|
16
|
+
count: number;
|
|
17
|
+
};
|
|
10
18
|
export type MultiplexWebSocket<T = any> = Pick<WebSocketSubject<T>, "multiplex">;
|
|
11
19
|
/** Options for the publish method on the pool and relay */
|
|
12
20
|
export type PublishOptions = {
|
|
@@ -21,6 +29,8 @@ export type PublishOptions = {
|
|
|
21
29
|
* @see https://rxjs.dev/api/index/function/retry
|
|
22
30
|
*/
|
|
23
31
|
reconnect?: boolean | number | Parameters<typeof retry>[0];
|
|
32
|
+
/** Timeout for publish in milliseconds (default 30 seconds) */
|
|
33
|
+
timeout?: number | boolean;
|
|
24
34
|
};
|
|
25
35
|
/** Options for the request method on the pool and relay */
|
|
26
36
|
export type RequestOptions = SubscriptionOptions;
|
|
@@ -58,6 +68,10 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
58
68
|
challenge$: Observable<string | null>;
|
|
59
69
|
authenticated$: Observable<boolean>;
|
|
60
70
|
notices$: Observable<string[]>;
|
|
71
|
+
open$: Observable<Event>;
|
|
72
|
+
close$: Observable<CloseEvent>;
|
|
73
|
+
closing$: Observable<void>;
|
|
74
|
+
error$: Observable<Error | null>;
|
|
61
75
|
readonly connected: boolean;
|
|
62
76
|
readonly authenticated: boolean;
|
|
63
77
|
readonly challenge: string | null;
|
|
@@ -66,10 +80,14 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
66
80
|
close(): void;
|
|
67
81
|
/** Send a REQ message */
|
|
68
82
|
req(filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
83
|
+
/** Send a COUNT message */
|
|
84
|
+
count(filters: Filter | Filter[], id?: string): Observable<CountResponse>;
|
|
69
85
|
/** Send an EVENT message */
|
|
70
86
|
event(event: NostrEvent): Observable<PublishResponse>;
|
|
71
87
|
/** Send an AUTH message */
|
|
72
88
|
auth(event: NostrEvent): Promise<PublishResponse>;
|
|
89
|
+
/** Negentropy sync event ids with the relay and an event store */
|
|
90
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
73
91
|
/** Authenticate with the relay using a signer */
|
|
74
92
|
authenticate(signer: AuthSigner): Promise<PublishResponse>;
|
|
75
93
|
/** Send an EVENT message with retries */
|
|
@@ -78,20 +96,39 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
78
96
|
request(filters: FilterInput, opts?: RequestOptions): Observable<NostrEvent>;
|
|
79
97
|
/** Open a subscription with retries */
|
|
80
98
|
subscription(filters: FilterInput, opts?: SubscriptionOptions): Observable<SubscriptionResponse>;
|
|
99
|
+
/** Negentropy sync events with the relay and an event store */
|
|
100
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
101
|
+
/** Get the NIP-11 information document for the relay */
|
|
102
|
+
getInformation(): Promise<RelayInformation | null>;
|
|
103
|
+
/** Get the limitations for the relay */
|
|
104
|
+
getLimitations(): Promise<RelayInformation["limitation"] | null>;
|
|
105
|
+
/** Get the supported NIPs for the relay */
|
|
106
|
+
getSupported(): Promise<number[] | null>;
|
|
81
107
|
}
|
|
82
108
|
export interface IGroup {
|
|
83
109
|
/** Send a REQ message */
|
|
84
110
|
req(filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
85
111
|
/** Send an EVENT message */
|
|
86
112
|
event(event: NostrEvent): Observable<PublishResponse>;
|
|
113
|
+
/** Negentropy sync event ids with the relays and an event store */
|
|
114
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
87
115
|
/** Send an EVENT message with retries */
|
|
88
116
|
publish(event: NostrEvent, opts?: PublishOptions): Promise<PublishResponse[]>;
|
|
89
117
|
/** Send a REQ message with retries */
|
|
90
|
-
request(filters: FilterInput, opts?:
|
|
118
|
+
request(filters: FilterInput, opts?: GroupRequestOptions): Observable<NostrEvent>;
|
|
91
119
|
/** Open a subscription with retries */
|
|
92
|
-
subscription(filters: FilterInput, opts?:
|
|
120
|
+
subscription(filters: FilterInput, opts?: GroupSubscriptionOptions): Observable<SubscriptionResponse>;
|
|
121
|
+
/** Count events on the relays and an event store */
|
|
122
|
+
count(filters: Filter | Filter[], id?: string): Observable<Record<string, CountResponse>>;
|
|
123
|
+
/** Negentropy sync events with the relay and an event store */
|
|
124
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
125
|
+
}
|
|
126
|
+
/** Signals emitted by the pool */
|
|
127
|
+
export interface IPoolSignals {
|
|
128
|
+
add$: Observable<IRelay>;
|
|
129
|
+
remove$: Observable<IRelay>;
|
|
93
130
|
}
|
|
94
|
-
export interface IPool {
|
|
131
|
+
export interface IPool extends IPoolSignals {
|
|
95
132
|
/** Get or create a relay */
|
|
96
133
|
relay(url: string): IRelay;
|
|
97
134
|
/** Create a relay group */
|
|
@@ -102,10 +139,16 @@ export interface IPool {
|
|
|
102
139
|
req(relays: string[], filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
103
140
|
/** Send an EVENT message */
|
|
104
141
|
event(relays: string[], event: NostrEvent): Observable<PublishResponse>;
|
|
142
|
+
/** Negentropy sync event ids with the relays and an event store */
|
|
143
|
+
negentropy(relays: string[], store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, reconcile: ReconcileFunction, opts?: GroupNegentropySyncOptions): Promise<boolean>;
|
|
105
144
|
/** Send an EVENT message to relays with retries */
|
|
106
|
-
publish(relays: string[], event:
|
|
145
|
+
publish(relays: string[], event: Parameters<IGroup["publish"]>[0], opts?: Parameters<IGroup["publish"]>[1]): Promise<PublishResponse[]>;
|
|
107
146
|
/** Send a REQ message to relays with retries */
|
|
108
|
-
request(relays: string[], filters:
|
|
147
|
+
request(relays: string[], filters: Parameters<IGroup["request"]>[0], opts?: Parameters<IGroup["request"]>[1]): Observable<NostrEvent>;
|
|
109
148
|
/** Open a subscription to relays with retries */
|
|
110
|
-
subscription(relays: string[], filters:
|
|
149
|
+
subscription(relays: string[], filters: Parameters<IGroup["subscription"]>[0], opts?: Parameters<IGroup["subscription"]>[1]): Observable<SubscriptionResponse>;
|
|
150
|
+
/** Count events on the relays and an event store */
|
|
151
|
+
count(relays: string[], filters: Filter | Filter[], id?: string): Observable<Record<string, CountResponse>>;
|
|
152
|
+
/** Negentropy sync events with the relay and an event store */
|
|
153
|
+
sync(relays: string[], store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
111
154
|
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-relay",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "nostr relay communication framework built on rxjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"keywords": [
|
|
9
|
-
"nostr"
|
|
10
|
-
"applesauce"
|
|
9
|
+
"nostr"
|
|
11
10
|
],
|
|
12
11
|
"author": "hzrd149",
|
|
13
12
|
"license": "MIT",
|
|
14
13
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"applesauce"
|
|
14
|
+
"dist"
|
|
17
15
|
],
|
|
18
16
|
"exports": {
|
|
19
17
|
".": {
|
|
@@ -54,17 +52,17 @@
|
|
|
54
52
|
},
|
|
55
53
|
"dependencies": {
|
|
56
54
|
"@noble/hashes": "^1.7.1",
|
|
57
|
-
"applesauce-core": "^
|
|
55
|
+
"applesauce-core": "^4.1.0",
|
|
58
56
|
"nanoid": "^5.0.9",
|
|
59
|
-
"nostr-tools": "~2.
|
|
57
|
+
"nostr-tools": "~2.17",
|
|
60
58
|
"rxjs": "^7.8.1"
|
|
61
59
|
},
|
|
62
60
|
"devDependencies": {
|
|
63
61
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
64
|
-
"applesauce-signers": "^
|
|
65
|
-
"
|
|
62
|
+
"applesauce-signers": "^4.1.0",
|
|
63
|
+
"rimraf": "^6.0.1",
|
|
66
64
|
"typescript": "^5.7.3",
|
|
67
|
-
"vitest": "^3.2.
|
|
65
|
+
"vitest": "^3.2.4",
|
|
68
66
|
"vitest-websocket-mock": "^0.5.0"
|
|
69
67
|
},
|
|
70
68
|
"funding": {
|
|
@@ -72,6 +70,7 @@
|
|
|
72
70
|
"url": "lightning:nostrudel@geyser.fund"
|
|
73
71
|
},
|
|
74
72
|
"scripts": {
|
|
73
|
+
"prebuild": "rimraf dist",
|
|
75
74
|
"build": "tsc",
|
|
76
75
|
"watch:build": "tsc --watch > /dev/null",
|
|
77
76
|
"test": "vitest run --passWithNoTests",
|