@ultimat3/realtime 31.42.1 → 31.44.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/README.md +8 -0
- package/package.json +5 -5
- package/src/presence.ts +14 -6
- package/src/sync-protocol.ts +22 -1
package/README.md
CHANGED
|
@@ -731,6 +731,9 @@ made it — a key already queued collapses as always, and nothing queued is ever
|
|
|
731
731
|
is never capped — the sweep differences it — and one node per topic runs that sweep, elected
|
|
732
732
|
through the shared store, rather than every node re-reading every room it has ever seen; the
|
|
733
733
|
leader's lease carries its roster, so a takeover announces a dead leader's members.
|
|
734
|
+
- **No presence frame outgrows `FRAME_LIMITS.members` (4,096)**, the most a client reads before it
|
|
735
|
+
refuses the frame whole: `maxMembers` is clamped to it (`total` still names the room), and a
|
|
736
|
+
sweep that finds more expired members than that announces them in several `leave` frames.
|
|
734
737
|
- **Deliveries are serialized per query id, not per node.** A change is fanned out inside that
|
|
735
738
|
query's own FIFO lane, so two changes off the bus cannot interleave: the window one of them
|
|
736
739
|
writes is the window every subscriber's gate reads, and patch frames leave in lsn order. Every
|
|
@@ -986,6 +989,11 @@ client" is the one instruction that cannot help — a rebuilt client spells the
|
|
|
986
989
|
The fix is `x queries list --json`, and the name the client sent is echoed back while the registry
|
|
987
990
|
never is.
|
|
988
991
|
|
|
992
|
+
A throw with no code — a live query's `TypeError`, a driver's error — is `X_INTERNAL` on the ack,
|
|
993
|
+
as `@ultimat3/http` labels it, never `X_PROTOCOL_VERSION`. Its cause is withheld from the socket as
|
|
994
|
+
HTTP withholds an unclassified 5xx's (a DSN, a row, a path); the node's error report holds the text.
|
|
995
|
+
`As of 2026-11`.
|
|
996
|
+
|
|
989
997
|
`As of 2026-07`: tiers 1–2 target v1, tier 3 targets v2.
|
|
990
998
|
|
|
991
999
|
### Error classes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/realtime",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.44.0",
|
|
4
4
|
"description": "Three-tier realtime: channels, live queries, local-first sync — one protocol, one mutator shape",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"test": "bun test"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ultimat3/core": "31.
|
|
56
|
-
"@ultimat3/entity": "31.
|
|
57
|
-
"@ultimat3/policy": "31.
|
|
58
|
-
"@ultimat3/query": "31.
|
|
55
|
+
"@ultimat3/core": "31.44.0",
|
|
56
|
+
"@ultimat3/entity": "31.44.0",
|
|
57
|
+
"@ultimat3/policy": "31.44.0",
|
|
58
|
+
"@ultimat3/query": "31.44.0",
|
|
59
59
|
"nats": "2.29.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/presence.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { presenceEvent } from './channel-presence';
|
|
|
12
12
|
import type { ChannelEventsFrame } from './channel-wire';
|
|
13
13
|
import type { Transport } from './fanout';
|
|
14
14
|
import type { JsonObject } from './json';
|
|
15
|
-
import { PROTOCOL_VERSION, type PresenceMember } from './sync-protocol';
|
|
15
|
+
import { FRAME_LIMITS, PROTOCOL_VERSION, type PresenceMember } from './sync-protocol';
|
|
16
16
|
|
|
17
17
|
export const PRESENCE_KEY_PREFIX = 'presence';
|
|
18
18
|
/** Separate namespace: the sweep lease is one member per *node*, never one per participant. */
|
|
@@ -39,7 +39,10 @@ export interface PresenceOptions {
|
|
|
39
39
|
readonly clock?: Clock;
|
|
40
40
|
/** Member TTL. Clients should heartbeat at ttl/3 so one lost beat is not a false leave. */
|
|
41
41
|
readonly ttlMs?: number;
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Members on a full-set frame. The set itself is never capped — only what is shipped. Clamped to
|
|
44
|
+
* `FRAME_LIMITS.members`: past it a client refuses the frame whole, and `total` already says the rest.
|
|
45
|
+
*/
|
|
43
46
|
readonly maxMembers?: number;
|
|
44
47
|
/**
|
|
45
48
|
* This node's identity in the per-topic sweep election. Defaults to a fresh id per registry,
|
|
@@ -82,9 +85,10 @@ export class PresenceRegistry {
|
|
|
82
85
|
this.#hub = options.hub;
|
|
83
86
|
this.#clock = options.clock ?? systemClock;
|
|
84
87
|
this.#ttlMs = finiteOption('presence', 'ttlMs', options.ttlMs ?? 30_000);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
const maxMembers = options.maxMembers ?? DEFAULT_MAX_PRESENCE_MEMBERS;
|
|
89
|
+
this.#maxMembers = Math.min(
|
|
90
|
+
FRAME_LIMITS.members,
|
|
91
|
+
Math.max(1, finiteOption('presence', 'maxMembers', maxMembers)),
|
|
88
92
|
);
|
|
89
93
|
this.#nodeId = options.nodeId ?? uuidV7();
|
|
90
94
|
}
|
|
@@ -332,7 +336,11 @@ export class PresenceRegistry {
|
|
|
332
336
|
members: readonly PresenceMember[],
|
|
333
337
|
): Promise<void> {
|
|
334
338
|
if (!this.#hub) return;
|
|
335
|
-
|
|
339
|
+
// A client refuses a roster past `FRAME_LIMITS.members` whole, so one oversized leave (a sweep
|
|
340
|
+
// after a node died with its room) would reach every subscriber as nothing at all.
|
|
341
|
+
for (let at = 0; at < members.length; at += FRAME_LIMITS.members) {
|
|
342
|
+
await this.#hub.emit(name, presenceEvent(op, members.slice(at, at + FRAME_LIMITS.members)));
|
|
343
|
+
}
|
|
336
344
|
}
|
|
337
345
|
}
|
|
338
346
|
|
package/src/sync-protocol.ts
CHANGED
|
@@ -323,7 +323,11 @@ export function toWireError(error: unknown): WireError {
|
|
|
323
323
|
// `renderThrowable` keeps an Error's own words without trusting `instanceof` or `.message`, and
|
|
324
324
|
// `stringField` makes the four probes above it as total as the fallback they choose between —
|
|
325
325
|
// `shape?.code` was a raw property read on that same app value.
|
|
326
|
-
|
|
326
|
+
// `X_INTERNAL` for a throwable with no code, as `@ultimat3/http`'s `factsOf` labels it: it was
|
|
327
|
+
// `X_PROTOCOL_VERSION` until round 5, sending the reader to rebuild a client over a server bug.
|
|
328
|
+
// The decoder's refusals are `ProtocolVersionError`s, coded already, so they keep theirs.
|
|
329
|
+
const code = stringField(error, 'code') ?? 'X_INTERNAL';
|
|
330
|
+
if (code === 'X_INTERNAL') return internalWireError(error);
|
|
327
331
|
const cause = stringField(error, 'cause') ?? renderThrowable(error);
|
|
328
332
|
const fix = stringField(error, 'fix') ?? 'x doctor realtime';
|
|
329
333
|
const docs = stringField(error, 'docs');
|
|
@@ -332,6 +336,23 @@ export function toWireError(error: unknown): WireError {
|
|
|
332
336
|
return retryAfterSeconds === undefined ? base : { ...base, retryAfterSeconds };
|
|
333
337
|
}
|
|
334
338
|
|
|
339
|
+
/**
|
|
340
|
+
* An unclassified failure, as a stranger gets it: HTTP's `toProblem` blanks the same cause, because
|
|
341
|
+
* it is a driver's DSN, a rejected row or a path, and nothing in it is the caller's to act on. The
|
|
342
|
+
* real text is the node's: `sync-node.ts` reports it, `live-reauth.ts` counts it. An authored
|
|
343
|
+
* `fix` and `docs` still ride, being instructions rather than evidence.
|
|
344
|
+
*/
|
|
345
|
+
function internalWireError(error: unknown): WireError {
|
|
346
|
+
const fix = stringField(error, 'fix') ?? INTERNAL_FIX;
|
|
347
|
+
const docs = stringField(error, 'docs');
|
|
348
|
+
const base = { code: 'X_INTERNAL', cause: INTERNAL_CAUSE, fix };
|
|
349
|
+
return docs === undefined ? base : { ...base, docs };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const INTERNAL_CAUSE =
|
|
353
|
+
'the sync node failed while handling this frame; the details are in its logs and error reports';
|
|
354
|
+
const INTERNAL_FIX = 'x errors explain X_INTERNAL --json # then fix the throwing call site';
|
|
355
|
+
|
|
335
356
|
/**
|
|
336
357
|
* `meta.retryAfterSeconds`, the field `@ultimat3/http`'s `X_RATE_LIMITED` carries — read as totally
|
|
337
358
|
* as `stringField` reads the rest, because the throwable is app code's and its getters may throw.
|