@qntx/nostr 0.6.0 → 0.8.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/{abort-Ba8tDrOI.mjs → abort-DBq2STPj.mjs} +13 -6
- package/dist/abort-DBq2STPj.mjs.map +1 -0
- package/dist/{builder-sSflu6nB.d.mts → builder-CTwkB2zM.d.mts} +14 -15
- package/dist/{builder-9tjI6WQ3.mjs → builder-aNU2gGFP.mjs} +11 -17
- package/dist/builder-aNU2gGFP.mjs.map +1 -0
- package/dist/{client-CadO5fAX.mjs → client-Cj2lUaVh.mjs} +141 -353
- package/dist/client-Cj2lUaVh.mjs.map +1 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.mjs +2 -2
- package/dist/collections-DtwMc1NU.mjs +33 -0
- package/dist/collections-DtwMc1NU.mjs.map +1 -0
- package/dist/core.d.mts +9 -8
- package/dist/core.mjs +7 -7
- package/dist/emitter-DkCY6NkU.mjs +32 -0
- package/dist/emitter-DkCY6NkU.mjs.map +1 -0
- package/dist/{error-BW7re1UN.d.mts → error-BD_0QFKT.d.mts} +2 -2
- package/dist/{error-DrEIM7FO.mjs → error-BILMe3Gr.mjs} +2 -2
- package/dist/{error-DrEIM7FO.mjs.map → error-BILMe3Gr.mjs.map} +1 -1
- package/dist/{error-CR8Urc84.d.mts → error-BquXDmIN.d.mts} +4 -4
- package/dist/{error-B__OMBRY.mjs → error-DlhGW4mJ.mjs} +2 -2
- package/dist/{error-B__OMBRY.mjs.map → error-DlhGW4mJ.mjs.map} +1 -1
- package/dist/{event-D8Nfoh4K.mjs → event-CHf47dPM.mjs} +16 -10
- package/dist/event-CHf47dPM.mjs.map +1 -0
- package/dist/{event-fU3Y01PR.d.mts → event-DJeb_DIL.d.mts} +4 -2
- package/dist/{filter-C0IMByE3.d.mts → filter-jI_9htF7.d.mts} +2 -2
- package/dist/{gossip-oloDMWEj.mjs → gossip-DFxIBlsr.mjs} +23 -33
- package/dist/gossip-DFxIBlsr.mjs.map +1 -0
- package/dist/{gossip-DpIvkBuj.d.mts → gossip-OOeeFzG5.d.mts} +37 -28
- package/dist/gossip.d.mts +1 -1
- package/dist/gossip.mjs +1 -1
- package/dist/{index-D1bqFHKB.d.mts → index-BxCBX-8R.d.mts} +18 -18
- package/dist/{index-lvXeER5t.d.mts → index-CPVEyzNX.d.mts} +32 -50
- package/dist/{index-MxC28S4P.d.mts → index-C_w2WfVz.d.mts} +27 -29
- package/dist/{index-CNl2q67H.d.mts → index-Cl_1XdYP.d.mts} +111 -180
- package/dist/{index-CvkvqB16.d.mts → index-DU9tRFTZ.d.mts} +7 -20
- package/dist/{index-q4MDce_r.d.mts → index-DyKwQnbt.d.mts} +6 -8
- package/dist/index.d.mts +23 -21
- package/dist/index.mjs +21 -19
- package/dist/{instance-DQE8BoWt.mjs → instance-C62w3cEt.mjs} +26 -27
- package/dist/instance-C62w3cEt.mjs.map +1 -0
- package/dist/{instance-CIca-ynn.d.mts → instance-DjsL8h84.d.mts} +5 -5
- package/dist/{key-Cv4_pN3x.d.mts → key-D_5OgGT7.d.mts} +11 -7
- package/dist/{key-Bps-LqX7.mjs → key-DnVpchl6.mjs} +13 -9
- package/dist/key-DnVpchl6.mjs.map +1 -0
- package/dist/{loaders-o6YXB_Ri.mjs → loaders-BmPkQfzI.mjs} +73 -82
- package/dist/loaders-BmPkQfzI.mjs.map +1 -0
- package/dist/loaders.d.mts +3 -3
- package/dist/loaders.mjs +2 -2
- package/dist/{memory-C2EVx0_O.mjs → memory-CdJ07kub.mjs} +2 -2
- package/dist/memory-CdJ07kub.mjs.map +1 -0
- package/dist/{memory-index-Do1mz0WF.mjs → memory-index-Cbc83vOZ.mjs} +30 -247
- package/dist/memory-index-Cbc83vOZ.mjs.map +1 -0
- package/dist/message-oNr7t0SJ.mjs +194 -0
- package/dist/message-oNr7t0SJ.mjs.map +1 -0
- package/dist/{message-iGPIqnn0.d.mts → message-tclYCVNc.d.mts} +6 -6
- package/dist/{nip17-CKIufV98.d.mts → nip17-B5WgW4C4.d.mts} +6 -7
- package/dist/{nip19-BevCJZsp.d.mts → nip19-DpPN17bY.d.mts} +25 -31
- package/dist/{nip46-DDV4dC56.d.mts → nip46-BHaxC9TZ.d.mts} +19 -21
- package/dist/nip51-CR0Q8eym.d.mts +87 -0
- package/dist/{nip59-zQgdLcEr.d.mts → nip59-C-RWFQIv.d.mts} +11 -5
- package/dist/nip65-D1fbmhOg.d.mts +23 -0
- package/dist/{nip77-DH4RhS5r.d.mts → nip77-DzUwUxHq.d.mts} +8 -9
- package/dist/nips/blossom.d.mts +17 -13
- package/dist/nips/blossom.mjs +30 -9
- package/dist/nips/blossom.mjs.map +1 -1
- package/dist/nips/nip04.mjs +17 -7
- package/dist/nips/nip04.mjs.map +1 -1
- package/dist/nips/nip05.d.mts +9 -10
- package/dist/nips/nip05.mjs +1 -4
- package/dist/nips/nip05.mjs.map +1 -1
- package/dist/nips/nip10.d.mts +8 -8
- package/dist/nips/nip10.mjs +34 -32
- package/dist/nips/nip10.mjs.map +1 -1
- package/dist/nips/nip11.d.mts +28 -28
- package/dist/nips/nip11.mjs +4 -4
- package/dist/nips/nip11.mjs.map +1 -1
- package/dist/nips/nip13.d.mts +7 -7
- package/dist/nips/nip13.mjs +32 -10
- package/dist/nips/nip13.mjs.map +1 -1
- package/dist/nips/nip17.d.mts +1 -1
- package/dist/nips/nip17.mjs +16 -34
- package/dist/nips/nip17.mjs.map +1 -1
- package/dist/nips/nip19.d.mts +2 -2
- package/dist/nips/nip19.mjs +16 -28
- package/dist/nips/nip19.mjs.map +1 -1
- package/dist/nips/nip21.d.mts +9 -4
- package/dist/nips/nip21.mjs +15 -5
- package/dist/nips/nip21.mjs.map +1 -1
- package/dist/nips/nip27.d.mts +22 -22
- package/dist/nips/nip27.mjs +2 -2
- package/dist/nips/nip27.mjs.map +1 -1
- package/dist/nips/nip42.d.mts +1 -1
- package/dist/nips/nip42.mjs +2 -1
- package/dist/nips/nip42.mjs.map +1 -1
- package/dist/nips/nip44.mjs +2 -2
- package/dist/nips/nip44.mjs.map +1 -1
- package/dist/nips/nip46.d.mts +2 -2
- package/dist/nips/nip46.mjs +15 -19
- package/dist/nips/nip46.mjs.map +1 -1
- package/dist/nips/nip49.d.mts +9 -9
- package/dist/nips/nip49.mjs +4 -4
- package/dist/nips/nip49.mjs.map +1 -1
- package/dist/nips/nip51.d.mts +2 -86
- package/dist/nips/nip51.mjs +7 -23
- package/dist/nips/nip51.mjs.map +1 -1
- package/dist/nips/nip57.d.mts +25 -23
- package/dist/nips/nip57.mjs +12 -17
- package/dist/nips/nip57.mjs.map +1 -1
- package/dist/nips/nip59.d.mts +1 -1
- package/dist/nips/nip59.mjs +27 -19
- package/dist/nips/nip59.mjs.map +1 -1
- package/dist/nips/nip65.d.mts +2 -2
- package/dist/nips/nip65.mjs +14 -37
- package/dist/nips/nip65.mjs.map +1 -1
- package/dist/nips/nip77.d.mts +1 -1
- package/dist/nips/nip77.mjs +33 -32
- package/dist/nips/nip77.mjs.map +1 -1
- package/dist/nips/nip98.d.mts +5 -5
- package/dist/nips/nip98.mjs +8 -8
- package/dist/nips/nip98.mjs.map +1 -1
- package/dist/{pool-DBIYMtwy.d.mts → pool-CqQvUnsq.d.mts} +132 -108
- package/dist/pool-vlw74C4t.mjs +606 -0
- package/dist/pool-vlw74C4t.mjs.map +1 -0
- package/dist/put-w13ci3sC.mjs +187 -0
- package/dist/put-w13ci3sC.mjs.map +1 -0
- package/dist/{reactive-BfhPp9a3.mjs → reactive-Tz0otDIP.mjs} +125 -88
- package/dist/reactive-Tz0otDIP.mjs.map +1 -0
- package/dist/{reactive-7aqeip4A.d.mts → reactive-gGqUrzW8.d.mts} +20 -26
- package/dist/relay-quCs7MHD.mjs +1811 -0
- package/dist/relay-quCs7MHD.mjs.map +1 -0
- package/dist/relay.d.mts +4 -4
- package/dist/relay.mjs +3 -2
- package/dist/serial-Bzpw-xz3.mjs +21 -0
- package/dist/serial-Bzpw-xz3.mjs.map +1 -0
- package/dist/{signer-CYQutDzD.mjs → signer-poTGe6Er.mjs} +12 -14
- package/dist/signer-poTGe6Er.mjs.map +1 -0
- package/dist/signer.d.mts +2 -2
- package/dist/signer.mjs +2 -2
- package/dist/{storage-Dky3wuoH.mjs → storage-B5IXTVuS.mjs} +28 -51
- package/dist/storage-B5IXTVuS.mjs.map +1 -0
- package/dist/storage.d.mts +3 -3
- package/dist/storage.mjs +4 -4
- package/dist/store.d.mts +2 -2
- package/dist/store.mjs +1 -1
- package/dist/testing.d.mts +19 -19
- package/dist/testing.mjs +9 -9
- package/dist/testing.mjs.map +1 -1
- package/dist/{types-2pCUprRU.d.mts → types-BacwnDtU.d.mts} +10 -10
- package/dist/{types-CRQEk0Oi.d.mts → types-DNmiscfd.d.mts} +2 -2
- package/dist/{util-LfQirgDk.mjs → util-DMF9AIO0.mjs} +33 -7
- package/dist/util-DMF9AIO0.mjs.map +1 -0
- package/dist/{verifier-t5WoWbtY.mjs → verifier-B51Wkt5H.mjs} +3 -3
- package/dist/verifier-B51Wkt5H.mjs.map +1 -0
- package/dist/verifier-CgTFpgsC.d.mts +22 -0
- package/dist/wasm.browser.d.mts +3 -3
- package/dist/wasm.browser.mjs +3 -3
- package/dist/wasm.d.mts +3 -3
- package/dist/wasm.mjs +3 -3
- package/dist/wasm.mjs.map +1 -1
- package/package.json +5 -9
- package/dist/abort-Ba8tDrOI.mjs.map +0 -1
- package/dist/builder-9tjI6WQ3.mjs.map +0 -1
- package/dist/client-CadO5fAX.mjs.map +0 -1
- package/dist/event-D8Nfoh4K.mjs.map +0 -1
- package/dist/gossip-oloDMWEj.mjs.map +0 -1
- package/dist/instance-DQE8BoWt.mjs.map +0 -1
- package/dist/key-Bps-LqX7.mjs.map +0 -1
- package/dist/loaders-o6YXB_Ri.mjs.map +0 -1
- package/dist/memory-C2EVx0_O.mjs.map +0 -1
- package/dist/memory-index-Do1mz0WF.mjs.map +0 -1
- package/dist/message-DcY6Fi9o.mjs +0 -193
- package/dist/message-DcY6Fi9o.mjs.map +0 -1
- package/dist/nip65-CjgmdpPB.d.mts +0 -26
- package/dist/nips/nip96.d.mts +0 -40
- package/dist/nips/nip96.mjs +0 -118
- package/dist/nips/nip96.mjs.map +0 -1
- package/dist/pool-As20OGxB.mjs +0 -2166
- package/dist/pool-As20OGxB.mjs.map +0 -1
- package/dist/reactive-BfhPp9a3.mjs.map +0 -1
- package/dist/signer-CYQutDzD.mjs.map +0 -1
- package/dist/storage-Dky3wuoH.mjs.map +0 -1
- package/dist/util-LfQirgDk.mjs.map +0 -1
- package/dist/verifier-t5WoWbtY.mjs.map +0 -1
|
@@ -1,222 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as toError, u as normalizeURL, v as NostrError, x as errorMessage } from "./util-DMF9AIO0.mjs";
|
|
2
2
|
import { t as Kind } from "./kind-Cxwhhkx8.mjs";
|
|
3
|
-
import { f as sortedEvents, o as itemCompare } from "./event-
|
|
4
|
-
import { t as EventBuilder } from "./builder-
|
|
3
|
+
import { f as sortedEvents, o as itemCompare } from "./event-CHf47dPM.mjs";
|
|
4
|
+
import { t as EventBuilder } from "./builder-aNU2gGFP.mjs";
|
|
5
5
|
import { n as canonicalizeFilters, o as matchFilters, t as canonicalizeFilter } from "./filter-BQl3GlHt.mjs";
|
|
6
|
-
import { t as NoSignerError } from "./error-
|
|
7
|
-
import { t as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { t as NoSignerError } from "./error-DlhGW4mJ.mjs";
|
|
7
|
+
import { n as fanIn, r as fetchRouted, t as Pool } from "./pool-vlw74C4t.mjs";
|
|
8
|
+
import { i as throwIfAborted, n as onAbort } from "./abort-DBq2STPj.mjs";
|
|
9
|
+
import { t as Emitter } from "./emitter-DkCY6NkU.mjs";
|
|
10
10
|
import { storageFromItems } from "./nips/nip77.mjs";
|
|
11
11
|
import { isGiftWrapKind, requireNip59Crypto, unwrap } from "./nips/nip59.mjs";
|
|
12
12
|
import { Nip17Error, buildChatMessageRumor, dmRelayListEventBuilder, normalizeRecipients, requireDmRelays, wrapDirectMessage } from "./nips/nip17.mjs";
|
|
13
|
-
import { t as Gossip } from "./gossip-
|
|
14
|
-
import {
|
|
15
|
-
import { n as toStorageError } from "./error-
|
|
16
|
-
import { t as MemoryIndex } from "./memory-index-
|
|
17
|
-
import { t as MemoryEventStore } from "./memory-
|
|
18
|
-
import { t as ReactiveEventStore } from "./reactive-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Fluent constructor for {@link Client}. The constructor is supplied by {@link Client.builder} so
|
|
22
|
-
* this module never imports the `Client` value, keeping the client/builder dependency
|
|
23
|
-
* one-directional.
|
|
24
|
-
*/
|
|
25
|
-
var ClientBuilder = class {
|
|
26
|
-
#opts = {};
|
|
27
|
-
#newClient;
|
|
28
|
-
constructor(newClient) {
|
|
29
|
-
this.#newClient = newClient;
|
|
30
|
-
}
|
|
31
|
-
signer(signer) {
|
|
32
|
-
this.#opts = {
|
|
33
|
-
...this.#opts,
|
|
34
|
-
signer
|
|
35
|
-
};
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
relays(urls) {
|
|
39
|
-
this.#opts = {
|
|
40
|
-
...this.#opts,
|
|
41
|
-
relays: [...urls]
|
|
42
|
-
};
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
addRelay(url) {
|
|
46
|
-
this.#opts = {
|
|
47
|
-
...this.#opts,
|
|
48
|
-
relays: [...this.#opts.relays ?? [], url]
|
|
49
|
-
};
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
websocketImplementation(impl) {
|
|
53
|
-
this.#opts = {
|
|
54
|
-
...this.#opts,
|
|
55
|
-
websocketImplementation: impl
|
|
56
|
-
};
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
verifyEvent(fn) {
|
|
60
|
-
this.#opts = {
|
|
61
|
-
...this.#opts,
|
|
62
|
-
verifyEvent: fn
|
|
63
|
-
};
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
connectTimeoutMs(ms) {
|
|
67
|
-
this.#opts = {
|
|
68
|
-
...this.#opts,
|
|
69
|
-
connectTimeoutMs: ms
|
|
70
|
-
};
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
publishTimeoutMs(ms) {
|
|
74
|
-
this.#opts = {
|
|
75
|
-
...this.#opts,
|
|
76
|
-
publishTimeoutMs: ms
|
|
77
|
-
};
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
automaticAuth(enabled) {
|
|
81
|
-
this.#opts = {
|
|
82
|
-
...this.#opts,
|
|
83
|
-
automaticAuth: enabled
|
|
84
|
-
};
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
/** Allow `ws://` relays. Default false. */
|
|
88
|
-
allowInsecure(allow) {
|
|
89
|
-
this.#opts = {
|
|
90
|
-
...this.#opts,
|
|
91
|
-
allowInsecure: allow
|
|
92
|
-
};
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
/** `ws://` URLs allowed despite `allowInsecure` being off. */
|
|
96
|
-
trustedInsecureUrls(urls) {
|
|
97
|
-
this.#opts = {
|
|
98
|
-
...this.#opts,
|
|
99
|
-
trustedInsecureUrls: urls
|
|
100
|
-
};
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
/** Close idle relays after this many ms. Unset = disabled. */
|
|
104
|
-
idleTimeoutMs(ms) {
|
|
105
|
-
this.#opts = {
|
|
106
|
-
...this.#opts,
|
|
107
|
-
idleTimeoutMs: ms
|
|
108
|
-
};
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
/** Soft cap on connected non-pinned relays. */
|
|
112
|
-
maxRelays(n) {
|
|
113
|
-
this.#opts = {
|
|
114
|
-
...this.#opts,
|
|
115
|
-
maxRelays: n
|
|
116
|
-
};
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
/** Relays never closed by idle cleanup or `maxRelays` eviction. */
|
|
120
|
-
pinnedUrls(urls) {
|
|
121
|
-
this.#opts = {
|
|
122
|
-
...this.#opts,
|
|
123
|
-
pinnedUrls: urls
|
|
124
|
-
};
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
/** Forwarded to the pool: suspend a relay delivering too many invalid events. */
|
|
128
|
-
invalidEventPolicy(policy) {
|
|
129
|
-
this.#opts = {
|
|
130
|
-
...this.#opts,
|
|
131
|
-
invalidEventPolicy: policy
|
|
132
|
-
};
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
/** Forwarded to the pool: fired once when a relay is suspended, with the lift time. */
|
|
136
|
-
onRelaySuspended(cb) {
|
|
137
|
-
this.#opts = {
|
|
138
|
-
...this.#opts,
|
|
139
|
-
onRelaySuspended: cb
|
|
140
|
-
};
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
enableReconnect(enabled) {
|
|
144
|
-
this.#opts = {
|
|
145
|
-
...this.#opts,
|
|
146
|
-
enableReconnect: enabled
|
|
147
|
-
};
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
enablePing(enabled) {
|
|
151
|
-
this.#opts = {
|
|
152
|
-
...this.#opts,
|
|
153
|
-
enablePing: enabled
|
|
154
|
-
};
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
pingIntervalMs(ms) {
|
|
158
|
-
this.#opts = {
|
|
159
|
-
...this.#opts,
|
|
160
|
-
pingIntervalMs: ms
|
|
161
|
-
};
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
pingTimeoutMs(ms) {
|
|
165
|
-
this.#opts = {
|
|
166
|
-
...this.#opts,
|
|
167
|
-
pingTimeoutMs: ms
|
|
168
|
-
};
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Local event store. Defaults to {@link MemoryEventStore}. Browser apps that want persistence must
|
|
173
|
-
* pass {@link IndexedDbEventStore} and `await open()`.
|
|
174
|
-
*/
|
|
175
|
-
storage(store) {
|
|
176
|
-
this.#opts = {
|
|
177
|
-
...this.#opts,
|
|
178
|
-
storage: store
|
|
179
|
-
};
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Synchronous reactive index mirroring ingested events. Defaults to a new
|
|
184
|
-
* {@link ReactiveEventStore}.
|
|
185
|
-
*/
|
|
186
|
-
index(index) {
|
|
187
|
-
this.#opts = {
|
|
188
|
-
...this.#opts,
|
|
189
|
-
index
|
|
190
|
-
};
|
|
191
|
-
return this;
|
|
192
|
-
}
|
|
193
|
-
/** When false, Client will not auto-write events to storage. Default true. */
|
|
194
|
-
persistEvents(enabled) {
|
|
195
|
-
this.#opts = {
|
|
196
|
-
...this.#opts,
|
|
197
|
-
persistEvents: enabled
|
|
198
|
-
};
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
gossip(gossip) {
|
|
202
|
-
this.#opts = {
|
|
203
|
-
...this.#opts,
|
|
204
|
-
gossip
|
|
205
|
-
};
|
|
206
|
-
return this;
|
|
207
|
-
}
|
|
208
|
-
onstorageerror(fn) {
|
|
209
|
-
this.#opts = {
|
|
210
|
-
...this.#opts,
|
|
211
|
-
onstorageerror: fn
|
|
212
|
-
};
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
build() {
|
|
216
|
-
return this.#newClient(this.#opts);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
//#endregion
|
|
13
|
+
import { t as Gossip } from "./gossip-DFxIBlsr.mjs";
|
|
14
|
+
import { r as OutboxFeed, t as createLoaders } from "./loaders-BmPkQfzI.mjs";
|
|
15
|
+
import { n as toStorageError } from "./error-BILMe3Gr.mjs";
|
|
16
|
+
import { t as MemoryIndex } from "./memory-index-Cbc83vOZ.mjs";
|
|
17
|
+
import { t as MemoryEventStore } from "./memory-CdJ07kub.mjs";
|
|
18
|
+
import { t as ReactiveEventStore } from "./reactive-Tz0otDIP.mjs";
|
|
19
|
+
import { t as SerialQueue } from "./serial-Bzpw-xz3.mjs";
|
|
220
20
|
//#region src/client/dm.ts
|
|
221
21
|
function giftWrapRelays(gossip, event) {
|
|
222
22
|
const targets = [];
|
|
@@ -248,13 +48,16 @@ async function sendPrivateMessage(deps, recipients, content, opts) {
|
|
|
248
48
|
subject: opts?.subject,
|
|
249
49
|
replyTo: opts?.replyTo
|
|
250
50
|
});
|
|
251
|
-
const wraps = await wrapDirectMessage(crypto, list, rumor
|
|
51
|
+
const wraps = await wrapDirectMessage(crypto, list, rumor, {
|
|
52
|
+
expiration: opts?.expiration,
|
|
53
|
+
ephemeral: opts?.ephemeral
|
|
54
|
+
});
|
|
252
55
|
return {
|
|
253
56
|
rumor,
|
|
254
57
|
wraps: await Promise.all(wraps.map(async ({ recipient, wrap }) => {
|
|
255
58
|
const relays = requireDmRelays(recipient, deps.gossip.dmRelays(recipient));
|
|
256
59
|
const results = await deps.pool.publish(relays, wrap, { timeoutMs: opts?.timeoutMs });
|
|
257
|
-
if (results.some((r) => r.
|
|
60
|
+
if (results.some((r) => r.status === "ok") && opts?.observe !== false) deps.ingest(wrap);
|
|
258
61
|
return {
|
|
259
62
|
recipient,
|
|
260
63
|
wrap,
|
|
@@ -267,9 +70,9 @@ async function fetchPrivateMessages(deps, opts) {
|
|
|
267
70
|
deps.assertAlive();
|
|
268
71
|
const crypto = deps.requireNip59Crypto();
|
|
269
72
|
const self = await crypto.getPublicKey();
|
|
270
|
-
|
|
73
|
+
throwIfAborted(opts?.signal);
|
|
271
74
|
await deps.hydrateGossip([self]);
|
|
272
|
-
|
|
75
|
+
throwIfAborted(opts?.signal);
|
|
273
76
|
const relays = requireDmRelays(self, deps.gossip.dmRelays(self));
|
|
274
77
|
const urls = /* @__PURE__ */ new Map();
|
|
275
78
|
const events = await deps.pool.fetch(relays, [{
|
|
@@ -291,7 +94,7 @@ async function fetchPrivateMessages(deps, opts) {
|
|
|
291
94
|
const rumor = await unwrap(crypto, wrap);
|
|
292
95
|
const wrapUrls = urls.get(wrap.id);
|
|
293
96
|
const firstUrl = wrapUrls?.values().next().value;
|
|
294
|
-
if (
|
|
97
|
+
if (opts?.observe !== false) {
|
|
295
98
|
deps.ingest(wrap, firstUrl);
|
|
296
99
|
if (wrapUrls) {
|
|
297
100
|
for (const url of wrapUrls) if (url !== firstUrl) deps.markSeen(wrap.id, url);
|
|
@@ -309,9 +112,9 @@ async function subscribePrivateMessages(deps, opts) {
|
|
|
309
112
|
deps.assertAlive();
|
|
310
113
|
const crypto = deps.requireNip59Crypto();
|
|
311
114
|
const self = await crypto.getPublicKey();
|
|
312
|
-
|
|
115
|
+
throwIfAborted(opts?.signal);
|
|
313
116
|
await deps.hydrateGossip([self]);
|
|
314
|
-
|
|
117
|
+
throwIfAborted(opts?.signal);
|
|
315
118
|
const relays = requireDmRelays(self, deps.gossip.dmRelays(self));
|
|
316
119
|
const seen = /* @__PURE__ */ new Set();
|
|
317
120
|
const processed = /* @__PURE__ */ new Set();
|
|
@@ -323,13 +126,15 @@ async function subscribePrivateMessages(deps, opts) {
|
|
|
323
126
|
pendingUrls.delete(wrapId);
|
|
324
127
|
for (const url of extra) deps.markSeen(wrapId, url);
|
|
325
128
|
};
|
|
326
|
-
|
|
129
|
+
const queue = new SerialQueue();
|
|
327
130
|
let closed = false;
|
|
131
|
+
let disposeAbort;
|
|
328
132
|
const markClosed = () => {
|
|
329
133
|
closed = true;
|
|
134
|
+
disposeAbort?.();
|
|
330
135
|
};
|
|
331
136
|
if (opts?.signal?.aborted === true) markClosed();
|
|
332
|
-
else opts?.signal
|
|
137
|
+
else disposeAbort = onAbort(opts?.signal, markClosed);
|
|
333
138
|
const inner = deps.pool.subscribe(relays, [{
|
|
334
139
|
kinds: [Kind.GiftWrap, Kind.GiftWrapEphemeral],
|
|
335
140
|
"#p": [self],
|
|
@@ -354,13 +159,7 @@ async function subscribePrivateMessages(deps, opts) {
|
|
|
354
159
|
},
|
|
355
160
|
onevent: (wrap, relayUrl) => {
|
|
356
161
|
if (closed) return;
|
|
357
|
-
|
|
358
|
-
let release;
|
|
359
|
-
tail = new Promise((resolve) => {
|
|
360
|
-
release = resolve;
|
|
361
|
-
});
|
|
362
|
-
(async () => {
|
|
363
|
-
await prev;
|
|
162
|
+
queue.run(async () => {
|
|
364
163
|
try {
|
|
365
164
|
if (closed) return;
|
|
366
165
|
const rumor = await unwrap(crypto, wrap);
|
|
@@ -370,17 +169,15 @@ async function subscribePrivateMessages(deps, opts) {
|
|
|
370
169
|
return;
|
|
371
170
|
}
|
|
372
171
|
seen.add(rumor.id);
|
|
373
|
-
if (
|
|
172
|
+
if (opts?.observe !== false) deps.ingest(wrap, relayUrl);
|
|
374
173
|
flushSeen(wrap.id);
|
|
375
174
|
opts?.onevent?.({
|
|
376
175
|
wrap,
|
|
377
176
|
rumor,
|
|
378
177
|
relayUrl
|
|
379
178
|
});
|
|
380
|
-
} catch {}
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
})();
|
|
179
|
+
} catch {}
|
|
180
|
+
});
|
|
384
181
|
}
|
|
385
182
|
});
|
|
386
183
|
return { close: (reason) => {
|
|
@@ -479,7 +276,7 @@ function mergeSyncSummary(into, other) {
|
|
|
479
276
|
*/
|
|
480
277
|
async function syncToRelay(deps, url, filter, opts) {
|
|
481
278
|
deps.assertAlive();
|
|
482
|
-
|
|
279
|
+
throwIfAborted(opts?.signal);
|
|
483
280
|
const direction = opts?.direction ?? SyncDirection.Down;
|
|
484
281
|
const canon = canonicalizeFilter(filter);
|
|
485
282
|
const items = await deps.storage.negentropyItems(canon);
|
|
@@ -488,37 +285,44 @@ async function syncToRelay(deps, url, filter, opts) {
|
|
|
488
285
|
timeoutMs: opts?.timeoutMs,
|
|
489
286
|
signal: opts?.signal
|
|
490
287
|
});
|
|
288
|
+
const sent = [];
|
|
289
|
+
const received = [];
|
|
290
|
+
const sendFailures = {};
|
|
291
|
+
const persistFailures = {};
|
|
491
292
|
const summary = {
|
|
492
293
|
local: have,
|
|
493
294
|
remote: need,
|
|
494
|
-
sent
|
|
495
|
-
received
|
|
496
|
-
sendFailures
|
|
497
|
-
persistFailures
|
|
295
|
+
sent,
|
|
296
|
+
received,
|
|
297
|
+
sendFailures,
|
|
298
|
+
persistFailures
|
|
498
299
|
};
|
|
499
300
|
if (opts?.dryRun === true) return summary;
|
|
500
301
|
if ((direction === SyncDirection.Up || direction === SyncDirection.Both) && have.length > 0) {
|
|
501
302
|
const found = await deps.storage.query([{ ids: have }]);
|
|
502
303
|
const foundById = new Map(found.map((event) => [event.id, event]));
|
|
503
|
-
for (const id of have) if (!foundById.has(id))
|
|
304
|
+
for (const id of have) if (!foundById.has(id)) sendFailures[id] = "event not found in local store";
|
|
504
305
|
for (let i = 0; i < found.length; i += SYNC_UPLOAD_CONCURRENCY) {
|
|
505
306
|
const chunk = found.slice(i, i + SYNC_UPLOAD_CONCURRENCY);
|
|
506
307
|
await Promise.all(chunk.map(async (event) => {
|
|
507
308
|
try {
|
|
508
309
|
const results = await deps.pool.publish([url], event, { timeoutMs: opts?.timeoutMs });
|
|
509
|
-
if (results.some((r) => r.
|
|
510
|
-
else
|
|
310
|
+
if (results.some((r) => r.status === "ok")) sent.push(event.id);
|
|
311
|
+
else {
|
|
312
|
+
const [first] = results;
|
|
313
|
+
sendFailures[event.id] = first === void 0 ? "publish failed" : first.status === "failed" ? errorMessage(first.error) : first.message;
|
|
314
|
+
}
|
|
511
315
|
} catch (error) {
|
|
512
|
-
|
|
316
|
+
sendFailures[event.id] = errorMessage(error);
|
|
513
317
|
}
|
|
514
318
|
}));
|
|
515
319
|
}
|
|
516
320
|
}
|
|
517
321
|
if ((direction === SyncDirection.Down || direction === SyncDirection.Both) && need.length > 0) {
|
|
518
|
-
const shouldObserve =
|
|
322
|
+
const shouldObserve = opts?.observe !== false;
|
|
519
323
|
for (let i = 0; i < need.length; i += SYNC_ID_BATCH) {
|
|
520
324
|
const batch = need.slice(i, i + SYNC_ID_BATCH);
|
|
521
|
-
|
|
325
|
+
throwIfAborted(opts?.signal);
|
|
522
326
|
const urlsById = /* @__PURE__ */ new Map();
|
|
523
327
|
const events = await deps.pool.fetch([url], [{ ids: batch }], {
|
|
524
328
|
timeoutMs: opts?.timeoutMs,
|
|
@@ -530,7 +334,7 @@ async function syncToRelay(deps, url, filter, opts) {
|
|
|
530
334
|
} : void 0
|
|
531
335
|
});
|
|
532
336
|
if (!shouldObserve) {
|
|
533
|
-
for (const event of events)
|
|
337
|
+
for (const event of events) received.push(event.id);
|
|
534
338
|
continue;
|
|
535
339
|
}
|
|
536
340
|
const ingestAll = (event) => {
|
|
@@ -541,7 +345,7 @@ async function syncToRelay(deps, url, filter, opts) {
|
|
|
541
345
|
if (!deps.persistEvents) {
|
|
542
346
|
for (const event of events) {
|
|
543
347
|
ingestAll(event);
|
|
544
|
-
|
|
348
|
+
received.push(event.id);
|
|
545
349
|
}
|
|
546
350
|
continue;
|
|
547
351
|
}
|
|
@@ -549,14 +353,14 @@ async function syncToRelay(deps, url, filter, opts) {
|
|
|
549
353
|
try {
|
|
550
354
|
results = await deps.storage.putMany(events);
|
|
551
355
|
} catch (error) {
|
|
552
|
-
const
|
|
553
|
-
for (const event of events)
|
|
356
|
+
const thrown = toError(error);
|
|
357
|
+
for (const event of events) persistFailures[event.id] = thrown;
|
|
554
358
|
break;
|
|
555
359
|
}
|
|
556
360
|
for (const [j, event] of events.entries()) {
|
|
557
361
|
if (results[j] === "rejected" || results[j] === "invalid") continue;
|
|
558
362
|
ingestAll(event);
|
|
559
|
-
|
|
363
|
+
received.push(event.id);
|
|
560
364
|
}
|
|
561
365
|
}
|
|
562
366
|
}
|
|
@@ -569,7 +373,7 @@ async function syncToRelay(deps, url, filter, opts) {
|
|
|
569
373
|
*/
|
|
570
374
|
async function sync(deps, filter, opts) {
|
|
571
375
|
deps.assertAlive();
|
|
572
|
-
const urls = deps.defaultRelays(opts?.relays
|
|
376
|
+
const urls = deps.defaultRelays(opts?.relays);
|
|
573
377
|
const results = await Promise.allSettled(urls.map(async (url) => syncToRelay(deps, url, filter, opts)));
|
|
574
378
|
let merged = emptySummary();
|
|
575
379
|
let fulfilled = 0;
|
|
@@ -583,49 +387,44 @@ async function sync(deps, filter, opts) {
|
|
|
583
387
|
}
|
|
584
388
|
//#endregion
|
|
585
389
|
//#region src/client/client.ts
|
|
390
|
+
function isFilterList(filter) {
|
|
391
|
+
return Array.isArray(filter);
|
|
392
|
+
}
|
|
393
|
+
function toFilterList(filter) {
|
|
394
|
+
return canonicalizeFilters(isFilterList(filter) ? filter : [filter]);
|
|
395
|
+
}
|
|
586
396
|
/** Layer-5 facade: signer + default relays + pool + loaders + gossip + event store. */
|
|
587
|
-
var Client = class
|
|
397
|
+
var Client = class {
|
|
588
398
|
pool;
|
|
589
399
|
loaders;
|
|
590
400
|
gossip;
|
|
591
401
|
storage;
|
|
592
402
|
index;
|
|
593
|
-
onstorageerror;
|
|
594
403
|
#signer;
|
|
595
404
|
#relays;
|
|
596
405
|
#shutdown = false;
|
|
597
406
|
#persistEvents;
|
|
598
407
|
#persistQueue = [];
|
|
599
408
|
#flushing;
|
|
409
|
+
#events = new Emitter();
|
|
410
|
+
#dmDeps;
|
|
411
|
+
#syncDeps;
|
|
600
412
|
constructor(opts = {}) {
|
|
601
|
-
|
|
413
|
+
const { signer, relays, automaticAuth, gossip, storage, index, persistEvents, ...poolOptions } = opts;
|
|
414
|
+
this.#signer = signer;
|
|
602
415
|
this.#relays = [];
|
|
603
|
-
for (const raw of
|
|
416
|
+
for (const raw of relays ?? []) {
|
|
604
417
|
const url = normalizeURL(raw);
|
|
605
418
|
if (!this.#relays.includes(url)) this.#relays.push(url);
|
|
606
419
|
}
|
|
607
|
-
this.gossip =
|
|
608
|
-
this.storage =
|
|
609
|
-
this.index =
|
|
610
|
-
this.#persistEvents =
|
|
611
|
-
this.onstorageerror = opts.onstorageerror;
|
|
420
|
+
this.gossip = gossip ?? new Gossip();
|
|
421
|
+
this.storage = storage ?? new MemoryEventStore();
|
|
422
|
+
this.index = index ?? new ReactiveEventStore();
|
|
423
|
+
this.#persistEvents = persistEvents ?? true;
|
|
612
424
|
this.pool = new Pool({
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
pingIntervalMs: opts.pingIntervalMs,
|
|
617
|
-
pingTimeoutMs: opts.pingTimeoutMs,
|
|
618
|
-
connectTimeoutMs: opts.connectTimeoutMs,
|
|
619
|
-
publishTimeoutMs: opts.publishTimeoutMs,
|
|
620
|
-
enableReconnect: opts.enableReconnect ?? true,
|
|
621
|
-
allowInsecure: opts.allowInsecure,
|
|
622
|
-
trustedInsecureUrls: opts.trustedInsecureUrls,
|
|
623
|
-
idleTimeoutMs: opts.idleTimeoutMs,
|
|
624
|
-
maxRelays: opts.maxRelays,
|
|
625
|
-
pinnedUrls: opts.pinnedUrls,
|
|
626
|
-
invalidEventPolicy: opts.invalidEventPolicy,
|
|
627
|
-
onRelaySuspended: opts.onRelaySuspended,
|
|
628
|
-
automaticallyAuth: opts.automaticAuth ?? true ? () => async (template) => {
|
|
425
|
+
...poolOptions,
|
|
426
|
+
enableReconnect: poolOptions.enableReconnect ?? true,
|
|
427
|
+
automaticallyAuth: automaticAuth ?? true ? () => async (template) => {
|
|
629
428
|
const signer = this.#signer;
|
|
630
429
|
if (!signer) throw new NoSignerError("no signer configured for AUTH");
|
|
631
430
|
const pk = await signer.getPublicKey();
|
|
@@ -641,9 +440,29 @@ var Client = class Client {
|
|
|
641
440
|
index: this.index,
|
|
642
441
|
ingest: (event, relayUrl) => this.#ingest(event, relayUrl)
|
|
643
442
|
});
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
443
|
+
this.#dmDeps = {
|
|
444
|
+
pool: this.pool,
|
|
445
|
+
gossip: this.gossip,
|
|
446
|
+
hydrateGossip: async (pubkeys) => this.hydrateGossip(pubkeys),
|
|
447
|
+
ingest: (event, relayUrl) => this.#ingest(event, relayUrl),
|
|
448
|
+
markSeen: (id, relayUrl) => {
|
|
449
|
+
this.index.markSeen(id, relayUrl);
|
|
450
|
+
},
|
|
451
|
+
assertAlive: () => this.#assertAlive(),
|
|
452
|
+
requireNip59Crypto: () => this.#requireNip59Crypto(),
|
|
453
|
+
publish: async (eventOrBuilder, opts) => this.publish(eventOrBuilder, opts)
|
|
454
|
+
};
|
|
455
|
+
this.#syncDeps = {
|
|
456
|
+
pool: this.pool,
|
|
457
|
+
storage: this.storage,
|
|
458
|
+
persistEvents: this.#persistEvents,
|
|
459
|
+
assertAlive: () => this.#assertAlive(),
|
|
460
|
+
ingest: (event, relayUrl, opts) => this.#ingest(event, relayUrl, opts),
|
|
461
|
+
markSeen: (id, relayUrl) => {
|
|
462
|
+
this.index.markSeen(id, relayUrl);
|
|
463
|
+
},
|
|
464
|
+
defaultRelays: (urls) => this.#defaultRelays(urls)
|
|
465
|
+
};
|
|
647
466
|
}
|
|
648
467
|
get signer() {
|
|
649
468
|
return this.#signer;
|
|
@@ -669,7 +488,7 @@ var Client = class Client {
|
|
|
669
488
|
const normalized = normalizeURL(url);
|
|
670
489
|
this.#relays = this.#relays.filter((r) => r !== normalized);
|
|
671
490
|
this.loaders.removeRelay(normalized);
|
|
672
|
-
this.pool.
|
|
491
|
+
this.pool.closeRelays([normalized]);
|
|
673
492
|
}
|
|
674
493
|
/** Connect all configured relays (best-effort; failures are ignored). */
|
|
675
494
|
async connect(opts) {
|
|
@@ -681,6 +500,14 @@ var Client = class Client {
|
|
|
681
500
|
while (this.#flushing !== void 0) await this.#flushing;
|
|
682
501
|
this.pool.close();
|
|
683
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* Listen for a client event. Multiple listeners per type are allowed and fire in registration
|
|
505
|
+
* order; a throwing listener is reported and does not break the dispatch. Returns an unsubscribe
|
|
506
|
+
* function.
|
|
507
|
+
*/
|
|
508
|
+
on(type, listener) {
|
|
509
|
+
return this.#events.on(type, listener);
|
|
510
|
+
}
|
|
684
511
|
#assertAlive() {
|
|
685
512
|
if (this.#shutdown) throw new ClientError("client is shut down");
|
|
686
513
|
}
|
|
@@ -689,9 +516,6 @@ var Client = class Client {
|
|
|
689
516
|
if (list.length === 0) throw new ClientError("no relays configured");
|
|
690
517
|
return list;
|
|
691
518
|
}
|
|
692
|
-
#wantObserve(flag) {
|
|
693
|
-
return flag !== false;
|
|
694
|
-
}
|
|
695
519
|
/** Ingest one inbound event: index (with relay URL) → meta → persistence. */
|
|
696
520
|
observe(event, relayUrl) {
|
|
697
521
|
this.#ingest(event, relayUrl);
|
|
@@ -713,18 +537,11 @@ var Client = class Client {
|
|
|
713
537
|
*/
|
|
714
538
|
#ingest(event, relayUrl, opts) {
|
|
715
539
|
this.index.add(event, relayUrl);
|
|
716
|
-
if (opts?.meta !== false) this
|
|
540
|
+
if (opts?.meta !== false) this.gossip.ingest(event);
|
|
717
541
|
if (opts?.persist === false || !this.#persistEvents) return;
|
|
718
542
|
this.#persistQueue.push(event);
|
|
719
543
|
this.#armFlush();
|
|
720
544
|
}
|
|
721
|
-
/** Record a relay sighting for an id already in the index. */
|
|
722
|
-
#markSeen(id, relayUrl) {
|
|
723
|
-
this.index.markSeen(id, relayUrl);
|
|
724
|
-
}
|
|
725
|
-
#ingestMeta(event) {
|
|
726
|
-
this.gossip.ingest(event);
|
|
727
|
-
}
|
|
728
545
|
#armFlush() {
|
|
729
546
|
if (this.#flushing) return;
|
|
730
547
|
this.#flushing = this.#flushLoop();
|
|
@@ -739,7 +556,7 @@ var Client = class Client {
|
|
|
739
556
|
try {
|
|
740
557
|
await this.storage.putMany(batch);
|
|
741
558
|
} catch (error) {
|
|
742
|
-
|
|
559
|
+
this.#events.emit("storageerror", toStorageError(error));
|
|
743
560
|
}
|
|
744
561
|
}
|
|
745
562
|
} finally {
|
|
@@ -772,7 +589,7 @@ var Client = class Client {
|
|
|
772
589
|
*/
|
|
773
590
|
outbox(opts) {
|
|
774
591
|
this.#assertAlive();
|
|
775
|
-
return
|
|
592
|
+
return new OutboxFeed({
|
|
776
593
|
pool: this.pool,
|
|
777
594
|
gossip: this.gossip,
|
|
778
595
|
storage: this.storage,
|
|
@@ -804,22 +621,24 @@ var Client = class Client {
|
|
|
804
621
|
hydrate: async (pubkeys) => this.hydrateGossip(pubkeys)
|
|
805
622
|
});
|
|
806
623
|
}
|
|
624
|
+
#requireSigner() {
|
|
625
|
+
const signer = this.#signer;
|
|
626
|
+
if (!signer) throw new ClientError("no signer configured");
|
|
627
|
+
return signer;
|
|
628
|
+
}
|
|
807
629
|
async getPublicKey() {
|
|
808
|
-
|
|
809
|
-
return this.#signer.getPublicKey();
|
|
630
|
+
return this.#requireSigner().getPublicKey();
|
|
810
631
|
}
|
|
811
632
|
async signEvent(unsigned) {
|
|
812
|
-
|
|
813
|
-
return this.#signer.signEvent(unsigned);
|
|
633
|
+
return this.#requireSigner().signEvent(unsigned);
|
|
814
634
|
}
|
|
815
635
|
async signEventBuilder(builder) {
|
|
816
|
-
|
|
817
|
-
return builder.sign(this.#signer);
|
|
636
|
+
return builder.sign(this.#requireSigner());
|
|
818
637
|
}
|
|
819
638
|
async signTemplate(template) {
|
|
820
|
-
|
|
821
|
-
const pubkey = await
|
|
822
|
-
return
|
|
639
|
+
const signer = this.#requireSigner();
|
|
640
|
+
const pubkey = await signer.getPublicKey();
|
|
641
|
+
return signer.signEvent({
|
|
823
642
|
...template,
|
|
824
643
|
pubkey
|
|
825
644
|
});
|
|
@@ -856,7 +675,7 @@ var Client = class Client {
|
|
|
856
675
|
if (urls.length > 0) relays = urls;
|
|
857
676
|
}
|
|
858
677
|
const results = await this.pool.publish(this.#defaultRelays(relays), event, { timeoutMs: opts?.timeoutMs });
|
|
859
|
-
if (results.some((r) => r.
|
|
678
|
+
if (results.some((r) => r.status === "ok") && opts?.observe !== false) this.observe(event);
|
|
860
679
|
return results;
|
|
861
680
|
}
|
|
862
681
|
/**
|
|
@@ -865,8 +684,8 @@ var Client = class Client {
|
|
|
865
684
|
*/
|
|
866
685
|
async fetchEvents(filter, opts) {
|
|
867
686
|
this.#assertAlive();
|
|
868
|
-
const filters =
|
|
869
|
-
const shouldObserve =
|
|
687
|
+
const filters = toFilterList(filter);
|
|
688
|
+
const shouldObserve = opts?.observe !== false;
|
|
870
689
|
const candidates = [];
|
|
871
690
|
if (opts?.localFirst === true) try {
|
|
872
691
|
const local = await this.storage.query(filters);
|
|
@@ -878,7 +697,7 @@ var Client = class Client {
|
|
|
878
697
|
});
|
|
879
698
|
}
|
|
880
699
|
} catch (error) {
|
|
881
|
-
|
|
700
|
+
this.#events.emit("storageerror", toStorageError(error));
|
|
882
701
|
}
|
|
883
702
|
const onevent = (event, relayUrl) => {
|
|
884
703
|
if (shouldObserve) this.#ingest(event, relayUrl, {
|
|
@@ -914,12 +733,12 @@ var Client = class Client {
|
|
|
914
733
|
*/
|
|
915
734
|
async fetchEach(filter, opts) {
|
|
916
735
|
this.#assertAlive();
|
|
917
|
-
const filters =
|
|
736
|
+
const filters = toFilterList(filter);
|
|
918
737
|
const results = await this.pool.fetchEach(this.#defaultRelays(opts?.relays), filters, {
|
|
919
738
|
timeoutMs: opts?.timeoutMs,
|
|
920
739
|
signal: opts?.signal
|
|
921
740
|
});
|
|
922
|
-
if (
|
|
741
|
+
if (opts?.observe !== false) {
|
|
923
742
|
const unique = [];
|
|
924
743
|
const seen = /* @__PURE__ */ new Set();
|
|
925
744
|
for (const result of results) for (const event of result.events) {
|
|
@@ -939,19 +758,19 @@ var Client = class Client {
|
|
|
939
758
|
/** Query local storage only (no network). */
|
|
940
759
|
async queryLocal(filter) {
|
|
941
760
|
this.#assertAlive();
|
|
942
|
-
const filters =
|
|
761
|
+
const filters = toFilterList(filter);
|
|
943
762
|
return this.storage.query(filters);
|
|
944
763
|
}
|
|
945
764
|
subscribe(filter, opts) {
|
|
946
765
|
this.#assertAlive();
|
|
947
|
-
const filters =
|
|
948
|
-
const shouldObserve =
|
|
766
|
+
const filters = toFilterList(filter);
|
|
767
|
+
const shouldObserve = opts?.observe !== false;
|
|
949
768
|
const wrapEvent = (event, relayUrl) => {
|
|
950
769
|
if (shouldObserve) this.observe(event, relayUrl);
|
|
951
770
|
opts?.onevent?.(event, relayUrl);
|
|
952
771
|
};
|
|
953
772
|
const wrapReceived = (id, relayUrl) => {
|
|
954
|
-
if (shouldObserve) this
|
|
773
|
+
if (shouldObserve) this.index.markSeen(id, relayUrl);
|
|
955
774
|
opts?.receivedEvent?.(id, relayUrl);
|
|
956
775
|
};
|
|
957
776
|
if (opts?.gossip !== true || opts.relays !== void 0) return this.pool.subscribe(this.#defaultRelays(opts?.relays), filters, {
|
|
@@ -973,51 +792,20 @@ var Client = class Client {
|
|
|
973
792
|
});
|
|
974
793
|
}
|
|
975
794
|
#requireNip59Crypto() {
|
|
976
|
-
|
|
977
|
-
return requireNip59Crypto(this.#signer);
|
|
978
|
-
}
|
|
979
|
-
#throwIfAborted(signal) {
|
|
980
|
-
throwIfAborted(signal);
|
|
981
|
-
}
|
|
982
|
-
#dmDeps() {
|
|
983
|
-
return {
|
|
984
|
-
pool: this.pool,
|
|
985
|
-
gossip: this.gossip,
|
|
986
|
-
hydrateGossip: async (pubkeys) => this.hydrateGossip(pubkeys),
|
|
987
|
-
ingest: (event, relayUrl) => this.#ingest(event, relayUrl),
|
|
988
|
-
markSeen: (id, relayUrl) => this.#markSeen(id, relayUrl),
|
|
989
|
-
assertAlive: () => this.#assertAlive(),
|
|
990
|
-
requireNip59Crypto: () => this.#requireNip59Crypto(),
|
|
991
|
-
throwIfAborted: (signal) => this.#throwIfAborted(signal),
|
|
992
|
-
wantObserve: (flag) => this.#wantObserve(flag),
|
|
993
|
-
publish: async (eventOrBuilder, opts) => this.publish(eventOrBuilder, opts)
|
|
994
|
-
};
|
|
995
|
-
}
|
|
996
|
-
#syncDeps() {
|
|
997
|
-
return {
|
|
998
|
-
pool: this.pool,
|
|
999
|
-
storage: this.storage,
|
|
1000
|
-
persistEvents: this.#persistEvents,
|
|
1001
|
-
assertAlive: () => this.#assertAlive(),
|
|
1002
|
-
throwIfAborted: (signal) => this.#throwIfAborted(signal),
|
|
1003
|
-
wantObserve: (flag) => this.#wantObserve(flag),
|
|
1004
|
-
ingest: (event, relayUrl, opts) => this.#ingest(event, relayUrl, opts),
|
|
1005
|
-
markSeen: (id, relayUrl) => this.#markSeen(id, relayUrl),
|
|
1006
|
-
defaultRelays: (urls) => this.#defaultRelays(urls)
|
|
1007
|
-
};
|
|
795
|
+
return requireNip59Crypto(this.#requireSigner());
|
|
1008
796
|
}
|
|
1009
797
|
/** Publish a kind:10050 NIP-17 DM relay list (`relay` tags). Not kind 10002. */
|
|
1010
798
|
async setDmRelays(relays, opts) {
|
|
1011
|
-
return setDmRelays(this.#dmDeps
|
|
799
|
+
return setDmRelays(this.#dmDeps, relays, opts);
|
|
1012
800
|
}
|
|
1013
801
|
async sendPrivateMessage(recipients, content, opts) {
|
|
1014
|
-
return sendPrivateMessage(this.#dmDeps
|
|
802
|
+
return sendPrivateMessage(this.#dmDeps, recipients, content, opts);
|
|
1015
803
|
}
|
|
1016
804
|
async fetchPrivateMessages(opts) {
|
|
1017
|
-
return fetchPrivateMessages(this.#dmDeps
|
|
805
|
+
return fetchPrivateMessages(this.#dmDeps, opts);
|
|
1018
806
|
}
|
|
1019
807
|
async subscribePrivateMessages(opts) {
|
|
1020
|
-
return subscribePrivateMessages(this.#dmDeps
|
|
808
|
+
return subscribePrivateMessages(this.#dmDeps, opts);
|
|
1021
809
|
}
|
|
1022
810
|
/**
|
|
1023
811
|
* NIP-77 sync against one relay: reconcile, then optionally upload local-only events and/or
|
|
@@ -1025,7 +813,7 @@ var Client = class Client {
|
|
|
1025
813
|
* listed. `persistEvents: false` skips putMany, still ingests when observe is on.
|
|
1026
814
|
*/
|
|
1027
815
|
async syncToRelay(url, filter, opts) {
|
|
1028
|
-
return syncToRelay(this.#syncDeps
|
|
816
|
+
return syncToRelay(this.#syncDeps, url, filter, opts);
|
|
1029
817
|
}
|
|
1030
818
|
/**
|
|
1031
819
|
* NIP-77 sync against the given relays (or Client default relays). Independent sessions run in
|
|
@@ -1033,10 +821,10 @@ var Client = class Client {
|
|
|
1033
821
|
* URL order.
|
|
1034
822
|
*/
|
|
1035
823
|
async sync(filter, opts) {
|
|
1036
|
-
return sync(this.#syncDeps
|
|
824
|
+
return sync(this.#syncDeps, filter, opts);
|
|
1037
825
|
}
|
|
1038
826
|
};
|
|
1039
827
|
//#endregion
|
|
1040
|
-
export {
|
|
828
|
+
export { ClientError as n, SyncDirection as r, Client as t };
|
|
1041
829
|
|
|
1042
|
-
//# sourceMappingURL=client-
|
|
830
|
+
//# sourceMappingURL=client-Cj2lUaVh.mjs.map
|