applesauce-relay 4.4.0 → 4.4.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.js +4 -4
- package/dist/relay.js +18 -17
- package/package.json +1 -1
package/dist/group.js
CHANGED
|
@@ -124,9 +124,7 @@ export class RelayGroup {
|
|
|
124
124
|
upstream.set(relay, observable);
|
|
125
125
|
}
|
|
126
126
|
return merge(...observables);
|
|
127
|
-
})
|
|
128
|
-
// Ensure a single upstream
|
|
129
|
-
share());
|
|
127
|
+
}));
|
|
130
128
|
}
|
|
131
129
|
/**
|
|
132
130
|
* Make a request to all relays
|
|
@@ -137,7 +135,9 @@ export class RelayGroup {
|
|
|
137
135
|
}
|
|
138
136
|
/** Send an event to all relays */
|
|
139
137
|
event(event) {
|
|
140
|
-
return this.internalPublish((relay) => relay.event(event))
|
|
138
|
+
return this.internalPublish((relay) => relay.event(event)).pipe(
|
|
139
|
+
// Ensure a single upstream subscription
|
|
140
|
+
share());
|
|
141
141
|
}
|
|
142
142
|
/** Negentropy sync events with the relays and an event store */
|
|
143
143
|
async negentropy(store, filter, reconcile, opts) {
|
package/dist/relay.js
CHANGED
|
@@ -166,8 +166,15 @@ export class Relay {
|
|
|
166
166
|
this.limitations$ = this.information$.pipe(map((info) => (info ? info.limitation : null)));
|
|
167
167
|
this.supported$ = this.information$.pipe(map((info) => info && Array.isArray(info.supported_nips) ? info.supported_nips.filter((n) => typeof n === "number") : null));
|
|
168
168
|
// Create observables that track if auth is required for REQ or EVENT
|
|
169
|
-
this.authRequiredForRead$ = this.receivedAuthRequiredForReq
|
|
170
|
-
this.authRequiredForPublish$ = this.receivedAuthRequiredForEvent
|
|
169
|
+
this.authRequiredForRead$ = this.receivedAuthRequiredForReq;
|
|
170
|
+
this.authRequiredForPublish$ = this.receivedAuthRequiredForEvent;
|
|
171
|
+
// Log when auth is required
|
|
172
|
+
this.authRequiredForRead$
|
|
173
|
+
.pipe(filter((r) => r === true), take(1))
|
|
174
|
+
.subscribe(() => this.log("Auth required for REQ"));
|
|
175
|
+
this.authRequiredForPublish$
|
|
176
|
+
.pipe(filter((r) => r === true), take(1))
|
|
177
|
+
.subscribe(() => this.log("Auth required for EVENT"));
|
|
171
178
|
// Update the notices state
|
|
172
179
|
const listenForNotice = this.socket.pipe(
|
|
173
180
|
// listen for NOTICE messages
|
|
@@ -320,9 +327,7 @@ export class Relay {
|
|
|
320
327
|
/** Create a COUNT observable that emits a single count response */
|
|
321
328
|
count(filters, id = nanoid()) {
|
|
322
329
|
// Create an observable that filters responses from the relay to just the ones for this COUNT
|
|
323
|
-
const messages = this.socket.pipe(filter((m) => Array.isArray(m) && (m[0] === "COUNT" || m[0] === "CLOSED") && m[1] === id)
|
|
324
|
-
// Singleton (prevents duplicate subscriptions)
|
|
325
|
-
share());
|
|
330
|
+
const messages = this.socket.pipe(filter((m) => Array.isArray(m) && (m[0] === "COUNT" || m[0] === "CLOSED") && m[1] === id));
|
|
326
331
|
// Send the COUNT message and listen for response
|
|
327
332
|
const observable = defer(() => {
|
|
328
333
|
// Send the COUNT message when subscription starts
|
|
@@ -343,11 +348,10 @@ export class Relay {
|
|
|
343
348
|
timeout({
|
|
344
349
|
first: this.eoseTimeout,
|
|
345
350
|
with: () => throwError(() => new Error("COUNT timeout")),
|
|
346
|
-
})
|
|
347
|
-
// Only create one upstream subscription
|
|
348
|
-
share());
|
|
351
|
+
}));
|
|
349
352
|
// Start the watch tower and wait for auth if required
|
|
350
|
-
|
|
353
|
+
// Use share() to prevent multiple subscriptions from creating duplicate COUNT messages
|
|
354
|
+
return this.waitForReady(this.waitForAuth(this.authRequiredForRead$, observable)).pipe(share());
|
|
351
355
|
}
|
|
352
356
|
/** Send an EVENT or AUTH message and return an observable of PublishResponse that completes or errors */
|
|
353
357
|
event(event, verb = "EVENT") {
|
|
@@ -378,14 +382,13 @@ export class Relay {
|
|
|
378
382
|
timeout({
|
|
379
383
|
first: this.eventTimeout,
|
|
380
384
|
with: () => of({ ok: false, from: this.url, message: "Timeout" }),
|
|
381
|
-
})
|
|
382
|
-
// Only create one upstream subscription
|
|
383
|
-
share());
|
|
385
|
+
}));
|
|
384
386
|
// skip wait for auth if verb is AUTH
|
|
387
|
+
// Use share() to prevent multiple subscriptions from creating duplicate EVENT messages
|
|
385
388
|
if (verb === "AUTH")
|
|
386
|
-
return this.waitForReady(observable);
|
|
389
|
+
return this.waitForReady(observable).pipe(share());
|
|
387
390
|
else
|
|
388
|
-
return this.waitForReady(this.waitForAuth(this.authRequiredForPublish$, observable));
|
|
391
|
+
return this.waitForReady(this.waitForAuth(this.authRequiredForPublish$, observable)).pipe(share());
|
|
389
392
|
}
|
|
390
393
|
/** send and AUTH message */
|
|
391
394
|
auth(event) {
|
|
@@ -492,9 +495,7 @@ export class Relay {
|
|
|
492
495
|
// Retry the publish until it succeeds or the number of retries is reached
|
|
493
496
|
this.customRetryOperator(opts?.retries ?? opts?.reconnect ?? true, DEFAULT_RETRY_CONFIG),
|
|
494
497
|
// Add timeout for publishing
|
|
495
|
-
this.customTimeoutOperator(opts?.timeout, this.publishTimeout)
|
|
496
|
-
// Single subscription
|
|
497
|
-
share()));
|
|
498
|
+
this.customTimeoutOperator(opts?.timeout, this.publishTimeout)));
|
|
498
499
|
}
|
|
499
500
|
/** Negentropy sync events with the relay and an event store */
|
|
500
501
|
sync(store, filter, direction = SyncDirection.RECEIVE) {
|