applesauce-relay 5.2.0 → 6.0.2
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/group.d.ts +29 -40
- package/dist/group.js +85 -56
- package/dist/liveness.d.ts +3 -3
- package/dist/operators/complete-on-eose.d.ts +4 -4
- package/dist/operators/complete-when.d.ts +7 -0
- package/dist/operators/complete-when.js +14 -0
- package/dist/operators/index.d.ts +0 -2
- package/dist/operators/index.js +0 -2
- package/dist/operators/only-events.d.ts +2 -2
- package/dist/operators/store-events.d.ts +2 -2
- package/dist/pool.d.ts +16 -16
- package/dist/pool.js +3 -2
- package/dist/relay.d.ts +46 -31
- package/dist/relay.js +266 -102
- package/dist/types.d.ts +104 -131
- package/package.json +3 -3
- package/dist/operators/mark-from-relay.d.ts +0 -4
- package/dist/operators/mark-from-relay.js +0 -9
- package/dist/operators/to-event-store.d.ts +0 -9
- package/dist/operators/to-event-store.js +0 -15
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import type { IAsyncEventStoreActions, IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core/event-store";
|
|
2
|
-
import type { Filter } from "applesauce-core/helpers/filter";
|
|
1
|
+
import type { IAsyncEventStoreActions, IAsyncEventStoreRead, IEventStoreActions, IEventStoreRead } from "applesauce-core/event-store";
|
|
3
2
|
import type { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import type { Filter } from "applesauce-core/helpers/filter";
|
|
4
4
|
import type { RelayInformation as CoreRelayInformation } from "nostr-tools/nip11";
|
|
5
|
-
import type { Observable, repeat, retry } from "rxjs";
|
|
5
|
+
import type { Observable, OperatorFunction, repeat, retry } from "rxjs";
|
|
6
6
|
import type { WebSocketSubject } from "rxjs/webSocket";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { SyncDirection } from "./relay.js";
|
|
10
|
-
export type SubscriptionResponse = NostrEvent | "EOSE";
|
|
11
|
-
export type PublishResponse = {
|
|
12
|
-
ok: boolean;
|
|
13
|
-
message?: string;
|
|
14
|
-
from: string;
|
|
15
|
-
};
|
|
16
|
-
export type CountResponse = {
|
|
17
|
-
count: number;
|
|
18
|
-
};
|
|
7
|
+
import type { NegentropySyncOptions } from "./negentropy.js";
|
|
8
|
+
import type { Relay } from "./relay.js";
|
|
19
9
|
/** Status information for a single relay */
|
|
20
10
|
export interface RelayStatus {
|
|
21
11
|
/** Relay URL */
|
|
@@ -48,28 +38,87 @@ export type PublishOptions = {
|
|
|
48
38
|
/** Timeout for publish in milliseconds (default 30 seconds) */
|
|
49
39
|
timeout?: number | boolean;
|
|
50
40
|
};
|
|
51
|
-
/**
|
|
52
|
-
export type
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
/** The response type when publishing an event to a relay */
|
|
42
|
+
export type PublishResponse = {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
message?: string;
|
|
45
|
+
from: string;
|
|
46
|
+
};
|
|
47
|
+
/** Base options for REQ subscriptions to a relay */
|
|
48
|
+
export type RelayReqOptions = {
|
|
55
49
|
/** Custom REQ id for the subscription */
|
|
56
50
|
id?: string;
|
|
57
51
|
/**
|
|
58
|
-
* Whether to
|
|
52
|
+
* Whether to wait for authentication and retry if auth-required is received. default is true
|
|
53
|
+
*/
|
|
54
|
+
waitForAuth?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether to resubscribe after a clean CLOSED message from the relay. default is false
|
|
59
57
|
* @see https://rxjs.dev/api/index/function/repeat
|
|
60
58
|
*/
|
|
61
59
|
resubscribe?: boolean | number | Parameters<typeof repeat>[0];
|
|
62
60
|
/**
|
|
63
|
-
* Whether to
|
|
61
|
+
* Whether to retry connection errors. default is true (3 retries with linear backoff)
|
|
64
62
|
* @see https://rxjs.dev/api/index/function/retry
|
|
65
63
|
*/
|
|
66
64
|
reconnect?: boolean | number | Parameters<typeof retry>[0];
|
|
67
65
|
};
|
|
66
|
+
/** Internal type emitted when REQ is sent to the relay */
|
|
67
|
+
export type RelayReqOpenMessage = {
|
|
68
|
+
type: "OPEN";
|
|
69
|
+
from: string;
|
|
70
|
+
id: string;
|
|
71
|
+
filters: Filter[];
|
|
72
|
+
};
|
|
73
|
+
/** Internal type emitted when an event is received from the relay */
|
|
74
|
+
export type RelayReqEventMessage = {
|
|
75
|
+
type: "EVENT";
|
|
76
|
+
from: string;
|
|
77
|
+
id: string;
|
|
78
|
+
event: NostrEvent;
|
|
79
|
+
};
|
|
80
|
+
/** Internal type emitted when the relay sends an EOSE message */
|
|
81
|
+
export type RelayReqEoseMessage = {
|
|
82
|
+
type: "EOSE";
|
|
83
|
+
from: string;
|
|
84
|
+
id: string;
|
|
85
|
+
};
|
|
86
|
+
/** Internal type emitted when the relay sends a CLOSED message */
|
|
87
|
+
export type RelayReqClosedMessage = {
|
|
88
|
+
type: "CLOSED";
|
|
89
|
+
from: string;
|
|
90
|
+
id: string;
|
|
91
|
+
reason: string;
|
|
92
|
+
};
|
|
93
|
+
/** Internal type emitted from a REQ subscription to a relay */
|
|
94
|
+
export type RelayReqMessage = RelayReqOpenMessage | RelayReqEventMessage | RelayReqEoseMessage | RelayReqClosedMessage;
|
|
95
|
+
/** Options for the request method on the pool and relay */
|
|
96
|
+
export type RelayRequestOptions = RelayReqOptions & {
|
|
97
|
+
/**
|
|
98
|
+
* Total timeout for the request before request emits a TimeoutError in milliseconds (default 30 seconds)
|
|
99
|
+
* Passed to rjxs timeout() operator */
|
|
100
|
+
timeout?: number;
|
|
101
|
+
/** An operator that determines when the request should complete. */
|
|
102
|
+
complete?: RelayRequestCompleteOperator;
|
|
103
|
+
};
|
|
104
|
+
/** The response type when making a request to a relay */
|
|
105
|
+
export type RelayRequestResponse = NostrEvent;
|
|
106
|
+
/** An operator that determines when a relay request should complete. truthy values are considered complete */
|
|
107
|
+
export type RelayRequestCompleteOperator = OperatorFunction<RelayReqMessage, any>;
|
|
108
|
+
/** Options for the subscription method on the pool and relay */
|
|
109
|
+
export type RelaySubscriptionOptions = RelayReqOptions;
|
|
110
|
+
/** The response type when subscribing to a relay */
|
|
111
|
+
export type RelaySubscriptionResponse = NostrEvent | "EOSE";
|
|
112
|
+
/** The response type when counting events on a relay */
|
|
113
|
+
export type RelayCountResponse = {
|
|
114
|
+
count: number;
|
|
115
|
+
};
|
|
116
|
+
/** A minimal signer interface for authenticating with a relay */
|
|
68
117
|
export type AuthSigner = {
|
|
69
118
|
signEvent: (event: EventTemplate) => NostrEvent | Promise<NostrEvent>;
|
|
70
119
|
};
|
|
71
120
|
/** Filters that can be passed to request methods on the pool or relay */
|
|
72
|
-
export type FilterInput = Filter | Filter[] | Observable<Filter | Filter[]> | ((relay:
|
|
121
|
+
export type FilterInput = Filter | Filter[] | Observable<Filter | Filter[]> | ((relay: Relay) => Filter | Filter[] | Observable<Filter | Filter[]>);
|
|
73
122
|
export type RelayInformation = CoreRelayInformation & {
|
|
74
123
|
/** An array of attributes that describe the relay type/characteristics */
|
|
75
124
|
attributes?: string[];
|
|
@@ -80,112 +129,36 @@ export type NegentropyReadStore = IEventStoreRead | IAsyncEventStoreRead | Nostr
|
|
|
80
129
|
export type NegentropyWriteStore = (IAsyncEventStoreRead & IAsyncEventStoreActions) | (IEventStoreRead & IAsyncEventStoreActions);
|
|
81
130
|
/** An event store that can be used for negentropy sync */
|
|
82
131
|
export type NegentropySyncStore = NegentropyReadStore | NegentropyWriteStore;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/** Authenticate with the relay using a signer */
|
|
117
|
-
authenticate(signer: AuthSigner): Promise<PublishResponse>;
|
|
118
|
-
/** Send an EVENT message with retries */
|
|
119
|
-
publish(event: NostrEvent, opts?: PublishOptions): Promise<PublishResponse>;
|
|
120
|
-
/** Send a REQ message with retries */
|
|
121
|
-
request(filters: FilterInput, opts?: RequestOptions): Observable<NostrEvent>;
|
|
122
|
-
/** Open a subscription with retries */
|
|
123
|
-
subscription(filters: FilterInput, opts?: SubscriptionOptions): Observable<SubscriptionResponse>;
|
|
124
|
-
/** Negentropy sync events with the relay and an event store */
|
|
125
|
-
sync(store: NegentropySyncStore, filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
126
|
-
/** Get the NIP-11 information document for the relay */
|
|
127
|
-
getInformation(): Promise<RelayInformation | null>;
|
|
128
|
-
/** Get the limitations for the relay */
|
|
129
|
-
getLimitations(): Promise<RelayInformation["limitation"] | null>;
|
|
130
|
-
/** Get the supported NIPs for the relay */
|
|
131
|
-
getSupported(): Promise<number[] | null>;
|
|
132
|
-
}
|
|
133
|
-
export type IGroupRelayInput = IRelay[] | Observable<IRelay[]>;
|
|
134
|
-
export interface IGroup {
|
|
135
|
-
/** Observable of relay status for all relays in the group */
|
|
136
|
-
status$: Observable<Record<string, RelayStatus>>;
|
|
137
|
-
/** Send a REQ message */
|
|
138
|
-
req(filters: Parameters<IRelay["req"]>[0], id?: string): Observable<SubscriptionResponse>;
|
|
139
|
-
/** Send an EVENT message */
|
|
140
|
-
event(event: Parameters<IRelay["event"]>[0]): Observable<PublishResponse>;
|
|
141
|
-
/** Negentropy sync event ids with the relays and an event store */
|
|
142
|
-
negentropy(store: NegentropyReadStore, filter: Filter, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
143
|
-
/** Add a relay to the group */
|
|
144
|
-
add(relay: IRelay): void;
|
|
145
|
-
/** Remove a relay from the group */
|
|
146
|
-
remove(relay: IRelay): void;
|
|
147
|
-
/** Check if a relay is in the group */
|
|
148
|
-
has(relay: IRelay | string): boolean;
|
|
149
|
-
/** Send an EVENT message with retries */
|
|
150
|
-
publish(event: Parameters<IRelay["event"]>[0], opts?: PublishOptions): Promise<PublishResponse[]>;
|
|
151
|
-
/** Send a REQ message with retries */
|
|
152
|
-
request(filters: Parameters<IRelay["request"]>[0], opts?: GroupRequestOptions): Observable<NostrEvent>;
|
|
153
|
-
/** Open a subscription with retries */
|
|
154
|
-
subscription(filters: Parameters<IRelay["subscription"]>[0], opts?: GroupSubscriptionOptions): Observable<SubscriptionResponse>;
|
|
155
|
-
/** Count events on the relays and an event store */
|
|
156
|
-
count(filters: Filter | Filter[], id?: string): Observable<Record<string, CountResponse>>;
|
|
157
|
-
/** Negentropy sync events with the relay and an event store */
|
|
158
|
-
sync(store: NegentropySyncStore, filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
159
|
-
}
|
|
160
|
-
/** Signals emitted by the pool */
|
|
161
|
-
export interface IPoolSignals {
|
|
162
|
-
add$: Observable<IRelay>;
|
|
163
|
-
remove$: Observable<IRelay>;
|
|
164
|
-
}
|
|
165
|
-
export type IPoolRelayInput = string[] | Observable<string[]>;
|
|
166
|
-
export interface IPool extends IPoolSignals {
|
|
167
|
-
/** Observable of relay status for all relays in the pool */
|
|
168
|
-
status$: Observable<Record<string, RelayStatus>>;
|
|
169
|
-
/** Get or create a relay */
|
|
170
|
-
relay(url: string): IRelay;
|
|
171
|
-
/** Create a relay group */
|
|
172
|
-
group(relays: IPoolRelayInput): IGroup;
|
|
173
|
-
/** Removes a relay from the pool and defaults to closing the connection */
|
|
174
|
-
remove(relay: string | IRelay, close?: boolean): void;
|
|
175
|
-
/** Send a REQ message */
|
|
176
|
-
req(relays: IPoolRelayInput, filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
177
|
-
/** Send an EVENT message */
|
|
178
|
-
event(relays: IPoolRelayInput, event: NostrEvent): Observable<PublishResponse>;
|
|
179
|
-
/** Negentropy sync event ids with the relays and an event store */
|
|
180
|
-
negentropy(relays: IPoolRelayInput, store: NegentropyReadStore, filter: Filter, reconcile: ReconcileFunction, opts?: GroupNegentropySyncOptions): Promise<boolean>;
|
|
181
|
-
/** Send an EVENT message to relays with retries */
|
|
182
|
-
publish(relays: IPoolRelayInput, event: Parameters<IGroup["publish"]>[0], opts?: Parameters<IGroup["publish"]>[1]): Promise<PublishResponse[]>;
|
|
183
|
-
/** Send a REQ message to relays with retries */
|
|
184
|
-
request(relays: IPoolRelayInput, filters: Parameters<IGroup["request"]>[0], opts?: Parameters<IGroup["request"]>[1]): Observable<NostrEvent>;
|
|
185
|
-
/** Open a subscription to relays with retries */
|
|
186
|
-
subscription(relays: IPoolRelayInput, filters: Parameters<IGroup["subscription"]>[0], opts?: Parameters<IGroup["subscription"]>[1]): Observable<SubscriptionResponse>;
|
|
187
|
-
/** Count events on the relays and an event store */
|
|
188
|
-
count(relays: IPoolRelayInput, filters: Filter | Filter[], id?: string): Observable<Record<string, CountResponse>>;
|
|
189
|
-
/** Negentropy sync events with the relay and an event store */
|
|
190
|
-
sync(relays: IPoolRelayInput, store: NegentropySyncStore, filter: Filter, direction?: SyncDirection): Observable<NostrEvent>;
|
|
191
|
-
}
|
|
132
|
+
/** The input arguments for a relay group */
|
|
133
|
+
export type GroupRelayInput = Relay[] | Observable<Relay[]>;
|
|
134
|
+
/** Options for negentropy sync on a group of relays */
|
|
135
|
+
export type GroupNegentropySyncOptions = NegentropySyncOptions & {
|
|
136
|
+
/** Whether to sync in parallel (default true) */
|
|
137
|
+
parallel?: boolean;
|
|
138
|
+
};
|
|
139
|
+
/** Options for a subscription on a group of relays */
|
|
140
|
+
export type GroupSubscriptionOptions = RelaySubscriptionOptions & {
|
|
141
|
+
/** Deduplicate events with an event store (default is a temporary instance of EventMemory), null will disable deduplication */
|
|
142
|
+
eventStore?: IEventStoreActions | IAsyncEventStoreActions | null;
|
|
143
|
+
};
|
|
144
|
+
/** Options for relay group REQ method */
|
|
145
|
+
export type GroupReqOptions = RelayReqOptions;
|
|
146
|
+
/** Options for a request on a group of relays */
|
|
147
|
+
export type GroupRequestOptions = RelayRequestOptions & {
|
|
148
|
+
/** Deduplicate events with an event store (default is a temporary instance of EventMemory), null will disable deduplication */
|
|
149
|
+
eventStore?: IEventStoreActions | IAsyncEventStoreActions | null;
|
|
150
|
+
/** A custom operator that determines when the request should complete.*/
|
|
151
|
+
complete?: GroupRequestCompleteOperator;
|
|
152
|
+
};
|
|
153
|
+
/** The message that is emitted when the group receives an error message from the relay observable */
|
|
154
|
+
export type GroupReqErrorMessage = {
|
|
155
|
+
type: "ERROR";
|
|
156
|
+
from: string;
|
|
157
|
+
error: unknown;
|
|
158
|
+
};
|
|
159
|
+
/** The response messages from a relay group subscription */
|
|
160
|
+
export type GroupReqMessage = RelayReqMessage | GroupReqErrorMessage;
|
|
161
|
+
/** A operator that determines when a group request should complete. truthy values are considered complete */
|
|
162
|
+
export type GroupRequestCompleteOperator = OperatorFunction<GroupReqMessage, any>;
|
|
163
|
+
/** The input type of relays for pool methods */
|
|
164
|
+
export type PoolRelayInput = string[] | Observable<string[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-relay",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "nostr relay communication framework built on rxjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@noble/hashes": "^1.7.1",
|
|
60
|
-
"applesauce-core": "^
|
|
60
|
+
"applesauce-core": "^6.0.0",
|
|
61
61
|
"nanoid": "^5.0.9",
|
|
62
62
|
"nostr-tools": "~2.19",
|
|
63
63
|
"rxjs": "^7.8.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
67
|
-
"applesauce-signers": "^
|
|
67
|
+
"applesauce-signers": "^6.0.0",
|
|
68
68
|
"rimraf": "^6.0.1",
|
|
69
69
|
"typescript": "^5.7.3",
|
|
70
70
|
"vitest": "^4.0.15",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { tap } from "rxjs";
|
|
2
|
-
import { addSeenRelay } from "applesauce-core/helpers";
|
|
3
|
-
/** Marks all events as from the relay */
|
|
4
|
-
export function markFromRelay(relay) {
|
|
5
|
-
return (source) => source.pipe(tap((message) => {
|
|
6
|
-
if (typeof message !== "string")
|
|
7
|
-
addSeenRelay(message, relay);
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { OperatorFunction } from "rxjs";
|
|
2
|
-
import { IEventStore } from "applesauce-core";
|
|
3
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
4
|
-
import { SubscriptionResponse } from "../types.js";
|
|
5
|
-
/**
|
|
6
|
-
* Adds all events to event store and returns a deduplicated timeline when EOSE is received
|
|
7
|
-
* @deprecated use `mapEventsToStore` and `mapEventsToTimeline` instead
|
|
8
|
-
*/
|
|
9
|
-
export declare function toEventStore(eventStore: IEventStore): OperatorFunction<SubscriptionResponse, NostrEvent[]>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { mapEventsToStore, mapEventsToTimeline } from "applesauce-core/observable";
|
|
2
|
-
import { completeOnEose } from "./complete-on-eose.js";
|
|
3
|
-
/**
|
|
4
|
-
* Adds all events to event store and returns a deduplicated timeline when EOSE is received
|
|
5
|
-
* @deprecated use `mapEventsToStore` and `mapEventsToTimeline` instead
|
|
6
|
-
*/
|
|
7
|
-
export function toEventStore(eventStore) {
|
|
8
|
-
return (source) => source.pipe(
|
|
9
|
-
// Complete when there are not events
|
|
10
|
-
completeOnEose(),
|
|
11
|
-
// Save events to store and remove duplicates
|
|
12
|
-
mapEventsToStore(eventStore, true),
|
|
13
|
-
// Add the events to an array
|
|
14
|
-
mapEventsToTimeline());
|
|
15
|
-
}
|