@ultimat3/realtime 31.42.1 → 31.43.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 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/realtime",
3
- "version": "31.42.1",
3
+ "version": "31.43.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.42.1",
56
- "@ultimat3/entity": "31.42.1",
57
- "@ultimat3/policy": "31.42.1",
58
- "@ultimat3/query": "31.42.1",
55
+ "@ultimat3/core": "31.43.0",
56
+ "@ultimat3/entity": "31.43.0",
57
+ "@ultimat3/policy": "31.43.0",
58
+ "@ultimat3/query": "31.43.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
- /** Members on a full-set frame. The set itself is never capped — only what is shipped. */
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
- this.#maxMembers = Math.max(
86
- 1,
87
- finiteOption('presence', 'maxMembers', options.maxMembers ?? DEFAULT_MAX_PRESENCE_MEMBERS),
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
- await this.#hub.emit(name, presenceEvent(op, members));
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