libp2r2p 0.12.11 → 0.12.12
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 +9 -4
- package/package.json +1 -1
- package/private-messenger/index.js +14 -4
package/README.md
CHANGED
|
@@ -364,14 +364,19 @@ await messenger.tell({
|
|
|
364
364
|
`PrivateMessenger` accepts an optional synchronous
|
|
365
365
|
`resolveInboundCoalescing(message, { idempotencyKey })` constructor callback.
|
|
366
366
|
The enriched `message` includes `type` and `channelPubkey`. The callback returns
|
|
367
|
-
`null` or `{ key, keep? }`, where `key` is a lowercase 64-character
|
|
368
|
-
digest
|
|
367
|
+
`null` or `{ key, keep?, sequence? }`, where `key` is a lowercase 64-character
|
|
368
|
+
SHA-256 digest, `keep` is `latest` (default) or `oldest`, and `sequence` is an
|
|
369
|
+
optional non-negative safe integer. Sequence units are resolver-owned and are
|
|
370
|
+
compared only within records sharing the final scoped coalescing key.
|
|
369
371
|
|
|
370
372
|
The resolver runs for ask, reply, tell, yell, message and nym deliveries after
|
|
371
373
|
exact event-ID deduplication. The final coalescing key is scoped by channel,
|
|
372
374
|
sender, type, message code and provenance. `latest` replaces the pending item in
|
|
373
|
-
place;
|
|
374
|
-
|
|
375
|
+
place; when both records carry a sequence, `latest` compares it before envelope
|
|
376
|
+
`created_at`, then falls back to outer/inner timestamps and event ID. `oldest`
|
|
377
|
+
preserves the pending item. While an item is reserved, both policies allow at
|
|
378
|
+
most one successor. Sequences persist in the internal queue metadata and are
|
|
379
|
+
not delivered to the app. Older recovered events do not replace newer requests.
|
|
375
380
|
|
|
376
381
|
For ask, reply, tell and yell, exactly one `["D", key]` tag may serve as an
|
|
377
382
|
automatic fallback when the resolver returns `null`. Its key is non-empty and
|
package/package.json
CHANGED
|
@@ -2237,12 +2237,16 @@ export class PrivateMessenger {
|
|
|
2237
2237
|
|
|
2238
2238
|
let digest = null
|
|
2239
2239
|
let keep = 'latest'
|
|
2240
|
+
let sequence = null
|
|
2240
2241
|
if (resolved != null) {
|
|
2241
2242
|
if (isPlainObject(resolved) && typeof resolved.key === 'string' &&
|
|
2242
2243
|
COALESCING_DIGEST.test(resolved.key) &&
|
|
2243
|
-
(resolved.keep == null || COALESCING_KEEP.has(resolved.keep))
|
|
2244
|
+
(resolved.keep == null || COALESCING_KEEP.has(resolved.keep)) &&
|
|
2245
|
+
(resolved.sequence == null ||
|
|
2246
|
+
(Number.isSafeInteger(resolved.sequence) && resolved.sequence >= 0))) {
|
|
2244
2247
|
digest = resolved.key
|
|
2245
2248
|
keep = resolved.keep || 'latest'
|
|
2249
|
+
sequence = resolved.sequence ?? null
|
|
2246
2250
|
} else {
|
|
2247
2251
|
this.onError?.(coalescingError(new ValidationError('INVALID_INBOUND_COALESCING_RESULT')))
|
|
2248
2252
|
}
|
|
@@ -2266,7 +2270,7 @@ export class PrivateMessenger {
|
|
|
2266
2270
|
digest
|
|
2267
2271
|
]),
|
|
2268
2272
|
coalescingKeep: keep,
|
|
2269
|
-
coalescingOrder: coalescingOrder(message)
|
|
2273
|
+
coalescingOrder: coalescingOrder(message, sequence)
|
|
2270
2274
|
}
|
|
2271
2275
|
}
|
|
2272
2276
|
|
|
@@ -3937,15 +3941,21 @@ function messageCode (message) {
|
|
|
3937
3941
|
: null
|
|
3938
3942
|
}
|
|
3939
3943
|
|
|
3940
|
-
function coalescingOrder (message) {
|
|
3941
|
-
|
|
3944
|
+
function coalescingOrder (message, sequence = null) {
|
|
3945
|
+
const order = {
|
|
3942
3946
|
outer: Number.isSafeInteger(message?.outer?.created_at) ? message.outer.created_at : 0,
|
|
3943
3947
|
inner: Number.isSafeInteger(message?.event?.created_at) ? message.event.created_at : 0,
|
|
3944
3948
|
eventId: message?.event?.id || ''
|
|
3945
3949
|
}
|
|
3950
|
+
if (sequence != null) order.sequence = sequence
|
|
3951
|
+
return order
|
|
3946
3952
|
}
|
|
3947
3953
|
|
|
3948
3954
|
function compareCoalescingOrder (left, right) {
|
|
3955
|
+
if (Number.isSafeInteger(left?.sequence) && Number.isSafeInteger(right?.sequence) &&
|
|
3956
|
+
left.sequence !== right.sequence) {
|
|
3957
|
+
return left.sequence < right.sequence ? -1 : 1
|
|
3958
|
+
}
|
|
3949
3959
|
if ((left?.outer || 0) !== (right?.outer || 0)) return (left?.outer || 0) - (right?.outer || 0)
|
|
3950
3960
|
if ((left?.inner || 0) !== (right?.inner || 0)) return (left?.inner || 0) - (right?.inner || 0)
|
|
3951
3961
|
const leftId = left?.eventId || ''
|