applesauce-relay 4.2.0 → 4.4.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/dist/group.d.ts +5 -4
- package/dist/negentropy.d.ts +4 -4
- package/dist/negentropy.js +1 -1
- package/dist/pool.d.ts +4 -4
- package/dist/pool.js +1 -1
- package/dist/relay.d.ts +5 -4
- package/dist/types.d.ts +14 -13
- package/package.json +2 -2
package/dist/group.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type NostrEvent } from "nostr-tools";
|
|
2
2
|
import { BehaviorSubject, MonoTypeOperatorFunction, Observable } from "rxjs";
|
|
3
3
|
import { IAsyncEventStoreActions, IAsyncEventStoreRead, IEventStoreActions, IEventStoreRead } from "applesauce-core";
|
|
4
|
+
import { type FilterWithAnd } from "applesauce-core/helpers";
|
|
4
5
|
import { NegentropySyncOptions, type ReconcileFunction } from "./negentropy.js";
|
|
5
6
|
import { SyncDirection } from "./relay.js";
|
|
6
7
|
import { CountResponse, FilterInput, IGroup, IGroupRelayInput, IRelay, PublishOptions, PublishResponse, RequestOptions, SubscriptionOptions, SubscriptionResponse } from "./types.js";
|
|
@@ -46,7 +47,7 @@ export declare class RelayGroup implements IGroup {
|
|
|
46
47
|
/** Send an event to all relays */
|
|
47
48
|
event(event: NostrEvent): Observable<PublishResponse>;
|
|
48
49
|
/** Negentropy sync events with the relays and an event store */
|
|
49
|
-
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
50
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: GroupNegentropySyncOptions): Promise<boolean>;
|
|
50
51
|
/** Publish an event to all relays with retries ( default 3 retries ) */
|
|
51
52
|
publish(event: NostrEvent, opts?: PublishOptions): Promise<PublishResponse[]>;
|
|
52
53
|
/** Request events from all relays and complete on EOSE */
|
|
@@ -54,7 +55,7 @@ export declare class RelayGroup implements IGroup {
|
|
|
54
55
|
/** Open a subscription to all relays with retries ( default 3 retries ) */
|
|
55
56
|
subscription(filters: FilterInput, opts?: GroupSubscriptionOptions): Observable<SubscriptionResponse>;
|
|
56
57
|
/** Count events on all relays in the group */
|
|
57
|
-
count(filters:
|
|
58
|
+
count(filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<Record<string, CountResponse>>;
|
|
58
59
|
/** Negentropy sync events with the relays and an event store */
|
|
59
|
-
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
60
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
60
61
|
}
|
package/dist/negentropy.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core";
|
|
2
|
-
import {
|
|
3
|
-
import { MultiplexWebSocket } from "./types.js";
|
|
2
|
+
import { type FilterWithAnd } from "applesauce-core/helpers";
|
|
4
3
|
import { NegentropyStorageVector } from "./lib/negentropy.js";
|
|
4
|
+
import { MultiplexWebSocket } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* A function that reconciles the storage vectors with a remote relay
|
|
7
7
|
* @param have - The ids that the local storage has
|
|
@@ -15,7 +15,7 @@ export type NegentropySyncOptions = {
|
|
|
15
15
|
signal?: AbortSignal;
|
|
16
16
|
};
|
|
17
17
|
/** Creates a NegentropyStorageVector from an event store and filter */
|
|
18
|
-
export declare function buildStorageFromFilter(store: IEventStoreRead | IAsyncEventStoreRead, filter:
|
|
18
|
+
export declare function buildStorageFromFilter(store: IEventStoreRead | IAsyncEventStoreRead, filter: FilterWithAnd): Promise<NegentropyStorageVector>;
|
|
19
19
|
/** Creates a NegentropyStorageVector from an array of items */
|
|
20
20
|
export declare function buildStorageVector(items: {
|
|
21
21
|
id: string;
|
|
@@ -28,4 +28,4 @@ export declare function buildStorageVector(items: {
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function negentropySync(storage: NegentropyStorageVector, socket: MultiplexWebSocket & {
|
|
30
30
|
next: (msg: any) => void;
|
|
31
|
-
}, filter:
|
|
31
|
+
}, filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
package/dist/negentropy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
|
-
import { map, share, firstValueFrom, race, Observable } from "rxjs";
|
|
3
2
|
import { nanoid } from "nanoid";
|
|
3
|
+
import { firstValueFrom, map, Observable, race, share } from "rxjs";
|
|
4
4
|
import { Negentropy, NegentropyStorageVector } from "./lib/negentropy.js";
|
|
5
5
|
const log = logger.extend("negentropy");
|
|
6
6
|
/** Creates a NegentropyStorageVector from an event store and filter */
|
package/dist/pool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core";
|
|
2
|
-
import { FilterMap, OutboxMap } from "applesauce-core/helpers";
|
|
2
|
+
import { FilterMap, OutboxMap, type FilterWithAnd } from "applesauce-core/helpers";
|
|
3
3
|
import { Filter, type NostrEvent } from "nostr-tools";
|
|
4
4
|
import { BehaviorSubject, Observable, Subject } from "rxjs";
|
|
5
5
|
import { RelayGroup } from "./group.js";
|
|
@@ -26,7 +26,7 @@ export declare class RelayPool implements IPool {
|
|
|
26
26
|
/** Send an EVENT message to multiple relays */
|
|
27
27
|
event(relays: IPoolRelayInput, event: NostrEvent): Observable<PublishResponse>;
|
|
28
28
|
/** Negentropy sync event ids with the relays and an event store */
|
|
29
|
-
negentropy(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
29
|
+
negentropy(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
30
30
|
/** Publish an event to multiple relays */
|
|
31
31
|
publish(relays: IPoolRelayInput, event: Parameters<RelayGroup["publish"]>[0], opts?: Parameters<RelayGroup["publish"]>[1]): Promise<PublishResponse[]>;
|
|
32
32
|
/** Request events from multiple relays */
|
|
@@ -38,7 +38,7 @@ export declare class RelayPool implements IPool {
|
|
|
38
38
|
/** Open a subscription for an {@link OutboxMap} and filter */
|
|
39
39
|
outboxSubscription(outboxes: OutboxMap | Observable<OutboxMap>, filter: Omit<Filter, "authors">, options?: Parameters<RelayGroup["subscription"]>[1]): Observable<SubscriptionResponse>;
|
|
40
40
|
/** Count events on multiple relays */
|
|
41
|
-
count(relays: IPoolRelayInput, filters:
|
|
41
|
+
count(relays: IPoolRelayInput, filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<Record<string, CountResponse>>;
|
|
42
42
|
/** Negentropy sync events with the relays and an event store */
|
|
43
|
-
sync(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
43
|
+
sync(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
44
44
|
}
|
package/dist/pool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFilterMap, isFilterEqual, normalizeURL } from "applesauce-core/helpers";
|
|
1
|
+
import { createFilterMap, isFilterEqual, normalizeURL, } from "applesauce-core/helpers";
|
|
2
2
|
import { BehaviorSubject, distinctUntilChanged, isObservable, map, of, Subject } from "rxjs";
|
|
3
3
|
import { RelayGroup } from "./group.js";
|
|
4
4
|
import { Relay } from "./relay.js";
|
package/dist/relay.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IAsyncEventStoreRead, IEventStoreRead, logger } from "applesauce-core";
|
|
2
|
-
import { type
|
|
2
|
+
import { type FilterWithAnd } from "applesauce-core/helpers";
|
|
3
|
+
import { type NostrEvent } from "nostr-tools";
|
|
3
4
|
import { RelayInformation } from "nostr-tools/nip11";
|
|
4
5
|
import { BehaviorSubject, MonoTypeOperatorFunction, Observable, RepeatConfig, RetryConfig, Subject } from "rxjs";
|
|
5
6
|
import { WebSocketSubject, WebSocketSubjectConfig } from "rxjs/webSocket";
|
|
@@ -105,13 +106,13 @@ export declare class Relay implements IRelay {
|
|
|
105
106
|
/** Create a REQ observable that emits events or "EOSE" or errors */
|
|
106
107
|
req(filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
107
108
|
/** Create a COUNT observable that emits a single count response */
|
|
108
|
-
count(filters:
|
|
109
|
+
count(filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<CountResponse>;
|
|
109
110
|
/** Send an EVENT or AUTH message and return an observable of PublishResponse that completes or errors */
|
|
110
111
|
event(event: NostrEvent, verb?: "EVENT" | "AUTH"): Observable<PublishResponse>;
|
|
111
112
|
/** send and AUTH message */
|
|
112
113
|
auth(event: NostrEvent): Promise<PublishResponse>;
|
|
113
114
|
/** Negentropy sync event ids with the relay and an event store */
|
|
114
|
-
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
115
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
115
116
|
/** Authenticate with the relay using a signer */
|
|
116
117
|
authenticate(signer: AuthSigner): Promise<PublishResponse>;
|
|
117
118
|
/** Internal operator for creating the retry() operator */
|
|
@@ -129,7 +130,7 @@ export declare class Relay implements IRelay {
|
|
|
129
130
|
/** Publishes an event to the relay and retries when relay errors or responds with auth-required ( default 3 retries ) */
|
|
130
131
|
publish(event: NostrEvent, opts?: PublishOptions): Promise<PublishResponse>;
|
|
131
132
|
/** Negentropy sync events with the relay and an event store */
|
|
132
|
-
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
133
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
133
134
|
/** Force close the connection */
|
|
134
135
|
close(): void;
|
|
135
136
|
/** An async method that returns the NIP-11 information document for the relay */
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core";
|
|
2
|
+
import type { FilterWithAnd } from "applesauce-core/helpers";
|
|
3
|
+
import type { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
4
|
import type { RelayInformation } from "nostr-tools/nip11";
|
|
3
5
|
import type { Observable, repeat, retry } from "rxjs";
|
|
4
6
|
import type { WebSocketSubject } from "rxjs/webSocket";
|
|
7
|
+
import type { GroupNegentropySyncOptions, GroupRequestOptions, GroupSubscriptionOptions } from "./group.js";
|
|
5
8
|
import type { NegentropySyncOptions, ReconcileFunction } from "./negentropy.js";
|
|
6
|
-
import type { IAsyncEventStoreRead, IEventStoreRead } from "applesauce-core";
|
|
7
9
|
import type { SyncDirection } from "./relay.js";
|
|
8
|
-
import type { GroupNegentropySyncOptions, GroupRequestOptions, GroupSubscriptionOptions } from "./group.js";
|
|
9
10
|
export type SubscriptionResponse = NostrEvent | "EOSE";
|
|
10
11
|
export type PublishResponse = {
|
|
11
12
|
ok: boolean;
|
|
@@ -59,7 +60,7 @@ export type AuthSigner = {
|
|
|
59
60
|
signEvent: (event: EventTemplate) => NostrEvent | Promise<NostrEvent>;
|
|
60
61
|
};
|
|
61
62
|
/** Filters that can be passed to request methods on the pool or relay */
|
|
62
|
-
export type FilterInput =
|
|
63
|
+
export type FilterInput = FilterWithAnd | FilterWithAnd[] | Observable<FilterWithAnd | FilterWithAnd[]> | ((relay: IRelay) => FilterWithAnd | FilterWithAnd[] | Observable<FilterWithAnd | FilterWithAnd[]>);
|
|
63
64
|
export interface IRelay extends MultiplexWebSocket {
|
|
64
65
|
url: string;
|
|
65
66
|
message$: Observable<any>;
|
|
@@ -81,13 +82,13 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
81
82
|
/** Send a REQ message */
|
|
82
83
|
req(filters: FilterInput, id?: string): Observable<SubscriptionResponse>;
|
|
83
84
|
/** Send a COUNT message */
|
|
84
|
-
count(filters:
|
|
85
|
+
count(filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<CountResponse>;
|
|
85
86
|
/** Send an EVENT message */
|
|
86
87
|
event(event: NostrEvent): Observable<PublishResponse>;
|
|
87
88
|
/** Send an AUTH message */
|
|
88
89
|
auth(event: NostrEvent): Promise<PublishResponse>;
|
|
89
90
|
/** Negentropy sync event ids with the relay and an event store */
|
|
90
|
-
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
91
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
91
92
|
/** Authenticate with the relay using a signer */
|
|
92
93
|
authenticate(signer: AuthSigner): Promise<PublishResponse>;
|
|
93
94
|
/** Send an EVENT message with retries */
|
|
@@ -97,7 +98,7 @@ export interface IRelay extends MultiplexWebSocket {
|
|
|
97
98
|
/** Open a subscription with retries */
|
|
98
99
|
subscription(filters: FilterInput, opts?: SubscriptionOptions): Observable<SubscriptionResponse>;
|
|
99
100
|
/** Negentropy sync events with the relay and an event store */
|
|
100
|
-
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
101
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
101
102
|
/** Get the NIP-11 information document for the relay */
|
|
102
103
|
getInformation(): Promise<RelayInformation | null>;
|
|
103
104
|
/** Get the limitations for the relay */
|
|
@@ -112,7 +113,7 @@ export interface IGroup {
|
|
|
112
113
|
/** Send an EVENT message */
|
|
113
114
|
event(event: Parameters<IRelay["event"]>[0]): Observable<PublishResponse>;
|
|
114
115
|
/** Negentropy sync event ids with the relays and an event store */
|
|
115
|
-
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
116
|
+
negentropy(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: NegentropySyncOptions): Promise<boolean>;
|
|
116
117
|
/** Add a relay to the group */
|
|
117
118
|
add(relay: IRelay): void;
|
|
118
119
|
/** Remove a relay from the group */
|
|
@@ -126,9 +127,9 @@ export interface IGroup {
|
|
|
126
127
|
/** Open a subscription with retries */
|
|
127
128
|
subscription(filters: Parameters<IRelay["subscription"]>[0], opts?: GroupSubscriptionOptions): Observable<SubscriptionResponse>;
|
|
128
129
|
/** Count events on the relays and an event store */
|
|
129
|
-
count(filters:
|
|
130
|
+
count(filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<Record<string, CountResponse>>;
|
|
130
131
|
/** Negentropy sync events with the relay and an event store */
|
|
131
|
-
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
132
|
+
sync(store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
132
133
|
}
|
|
133
134
|
/** Signals emitted by the pool */
|
|
134
135
|
export interface IPoolSignals {
|
|
@@ -148,7 +149,7 @@ export interface IPool extends IPoolSignals {
|
|
|
148
149
|
/** Send an EVENT message */
|
|
149
150
|
event(relays: IPoolRelayInput, event: NostrEvent): Observable<PublishResponse>;
|
|
150
151
|
/** Negentropy sync event ids with the relays and an event store */
|
|
151
|
-
negentropy(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
152
|
+
negentropy(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, reconcile: ReconcileFunction, opts?: GroupNegentropySyncOptions): Promise<boolean>;
|
|
152
153
|
/** Send an EVENT message to relays with retries */
|
|
153
154
|
publish(relays: IPoolRelayInput, event: Parameters<IGroup["publish"]>[0], opts?: Parameters<IGroup["publish"]>[1]): Promise<PublishResponse[]>;
|
|
154
155
|
/** Send a REQ message to relays with retries */
|
|
@@ -156,7 +157,7 @@ export interface IPool extends IPoolSignals {
|
|
|
156
157
|
/** Open a subscription to relays with retries */
|
|
157
158
|
subscription(relays: IPoolRelayInput, filters: Parameters<IGroup["subscription"]>[0], opts?: Parameters<IGroup["subscription"]>[1]): Observable<SubscriptionResponse>;
|
|
158
159
|
/** Count events on the relays and an event store */
|
|
159
|
-
count(relays: IPoolRelayInput, filters:
|
|
160
|
+
count(relays: IPoolRelayInput, filters: FilterWithAnd | FilterWithAnd[], id?: string): Observable<Record<string, CountResponse>>;
|
|
160
161
|
/** Negentropy sync events with the relay and an event store */
|
|
161
|
-
sync(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter:
|
|
162
|
+
sync(relays: IPoolRelayInput, store: IEventStoreRead | IAsyncEventStoreRead | NostrEvent[], filter: FilterWithAnd, direction?: SyncDirection): Observable<NostrEvent>;
|
|
162
163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-relay",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "nostr relay communication framework built on rxjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@noble/hashes": "^1.7.1",
|
|
55
|
-
"applesauce-core": "^4.
|
|
55
|
+
"applesauce-core": "^4.4.0",
|
|
56
56
|
"nanoid": "^5.0.9",
|
|
57
57
|
"nostr-tools": "~2.17",
|
|
58
58
|
"rxjs": "^7.8.1"
|