@mmstack/mesh 21.15.0 → 21.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/mesh",
3
- "version": "21.15.0",
3
+ "version": "21.15.2",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "@angular/core": ">=21 <22",
23
23
  "@mmstack/primitives": ">=21.25 <22",
24
- "@mmstack/mesh-protocol": ">=0.15 <1"
24
+ "@mmstack/mesh-protocol": ">=0.15.2 <1"
25
25
  },
26
26
  "sideEffects": false,
27
27
  "module": "fesm2022/mmstack-mesh.mjs",
@@ -1,7 +1,25 @@
1
- import { StoreOp, ClientMsg, ServerMsg, Relay, PrincipalCtx, IceServer, ClientSignalMsg, PresenceState, OpPolicy } from '@mmstack/mesh-protocol';
2
- import { OpEnvelope, OpSync, MergePolicyEntry, DiffOpsOptions, AsyncStore, ForkStoreOptions, SyncedFork, WritableSignalStore, StoreOp as StoreOp$1, toStoreOptions } from '@mmstack/primitives/core';
3
1
  import { Signal, Injector, WritableSignal } from '@angular/core';
2
+ import { StoreOp, GenerationReason, TailPolicy, Hlc, ClientMsg, ServerMsg, Relay, PrincipalCtx, IceServer, ClientSignalMsg, PresenceState, OpPolicy } from '@mmstack/mesh-protocol';
3
+ import { OpEnvelope, OpSync, MergePolicyEntry, DiffOpsOptions, AsyncStore, ForkStoreOptions, SyncedFork, WritableSignalStore, StoreOp as StoreOp$1, toStoreOptions } from '@mmstack/primitives/core';
4
4
 
5
+ /**
6
+ * The client half of a room generation: the record fields a snapshot welcome carries, the admission
7
+ * evidence the client keeps for its pre-check, and the pure decisions the session takes on them
8
+ * (which welcome to install, what a new generation does with the pending tail, whether a replayed
9
+ * envelope may be sent, when a member is ready for a consensus cut). Nothing here touches a socket,
10
+ * a store or a timer, so a harness can drive the same decisions the session does.
11
+ */
12
+ /** The immutable fields of the installed generation, as the client keeps them in its record. */
13
+ type InstalledGeneration = {
14
+ readonly instance: string;
15
+ readonly index: number;
16
+ readonly reason: GenerationReason;
17
+ readonly policy: TailPolicy;
18
+ readonly extent: Readonly<Record<string, Readonly<Record<string, Hlc>>>>;
19
+ readonly preCutMax: Readonly<Record<string, Hlc>>;
20
+ /** The seq of the snapshot welcome that installed it (or a later one of the same generation). */
21
+ readonly seq: number;
22
+ };
5
23
  /**
6
24
  * The authored intent of an envelope: its raw op list and one bump flag, what a re-author rebuilds
7
25
  * from. The raws are the stamped ops without their expansion clears (a diffed write never emits a
@@ -31,15 +49,30 @@ type MeshTransportFactory = () => MeshTransport;
31
49
  * flushed on open; malformed inbound frames are dropped.
32
50
  */
33
51
  declare function webSocketTransport(url: string, protocols?: string | string[]): MeshTransportFactory;
52
+ type DirectTransportOptions = {
53
+ /**
54
+ * Hand the relay's messages to this peer BY REFERENCE instead of through a JSON hop. A snapshot
55
+ * welcome then costs the peer no copy of the room's registers: its stores hold the relay's own
56
+ * sibling objects, the same ones every other such peer holds. The peer must therefore treat
57
+ * everything it receives as the relay's memory and never mutate it — a write in place would
58
+ * corrupt the room for everyone. The peer's own messages still cross as JSON, so what it writes
59
+ * reaches the relay exactly as a socket peer's would. Off by default; opt in only for a process
60
+ * whose readers are known not to mutate what a seat materializes.
61
+ */
62
+ readonly byReference?: boolean;
63
+ };
34
64
  /**
35
65
  * Connects directly to an in-process `createRelay` — no network. The backbone of full-loop
36
66
  * tests, and handy for single-process demos or an SSR-side room.
37
67
  *
38
68
  * Messages cross as JSON in both directions, as they would over a socket, so a direct peer holds
39
69
  * exactly what a socket peer would. Handed over by reference, an `undefined` an emitter wrote
40
- * would reach relay memory where a socket peer's would have been dropped.
70
+ * would reach relay memory where a socket peer's would have been dropped. The relay's own
71
+ * messages may skip the hop ({@link DirectTransportOptions.byReference}): they never hold an
72
+ * `undefined` (every value in a room arrived as JSON), so the two peers read the same state and
73
+ * differ only in who owns the objects.
41
74
  */
42
- declare function directTransport(relay: Relay, ctx: PrincipalCtx): MeshTransportFactory;
75
+ declare function directTransport(relay: Relay, ctx: PrincipalCtx, options?: DirectTransportOptions): MeshTransportFactory;
43
76
 
44
77
  /**
45
78
  * Why a write is a conflict: its replay into a new generation cites something the generation does
@@ -71,6 +104,8 @@ type CompactionState = {
71
104
  /** Origins of the members currently declared ready for a consensus cut. */
72
105
  readonly ready: readonly string[];
73
106
  };
107
+ /** The room generation the client installed, as its snapshot welcome named it. */
108
+ type GenerationState = Pick<InstalledGeneration, 'instance' | 'index' | 'reason' | 'policy'>;
74
109
  type MeshStatus = 'connecting'
75
110
  /** Queued behind another tab that owns this key's durable outbox (`crossTab: 'queue'`). */
76
111
  | 'waiting' | 'live' | 'reconnecting' | 'ejected' | 'closed';
@@ -325,7 +360,7 @@ type MeshSyncOptions = {
325
360
  /** The connection dropped and a reconnect is scheduled; `code` is the close code (1009 = message too big, 1006 = dropped). */
326
361
  readonly onDisconnect?: (code: number, reason: string) => void;
327
362
  /** A write the relay refused (see `MeshSessionHooks.onRefused`); the envelope carries its values. */
328
- readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order') => void;
363
+ readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
329
364
  /**
330
365
  * Hold the connection until the local base is assembled. `meshSync` awaits this before it connects
331
366
  * (and before it restores an `outbox`), so a store hydrated from another source first (a worker
@@ -432,6 +467,12 @@ type MeshSyncRef<T extends object = Record<string, unknown>> = {
432
467
  readonly conflicts: Signal<readonly MeshConflict[]>;
433
468
  /** The room's compaction state as the relay last announced it; undefined before any notice. */
434
469
  readonly compaction: Signal<CompactionState | undefined>;
470
+ /**
471
+ * The room generation this client installed: set by every snapshot welcome of a new generation
472
+ * (a cut's welcome flips it), untouched by one of the installed generation. Undefined until the
473
+ * first snapshot welcome and after a room was recreated without its record.
474
+ */
475
+ readonly generation: Signal<GenerationState | undefined>;
435
476
  /**
436
477
  * The member pressed (`true`) or released Compact: the client declares itself ready for a
437
478
  * consensus cut whenever nothing it wrote is outstanding, re-declaring on every change. A
@@ -510,7 +551,7 @@ type AgentSeatOptions = {
510
551
  readonly context?: toStoreOptions;
511
552
  readonly onEject?: (reason: string) => void;
512
553
  /** A write the relay refused; it is not in the room, and the doc was rehydrated. The envelope carries its values. */
513
- readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order') => void;
554
+ readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
514
555
  };
515
556
  type AgentSeat<T extends object> = {
516
557
  /** The live converging replica. Reads exactly like a local signal store. */
@@ -531,6 +572,14 @@ type AgentSeat<T extends object> = {
531
572
  * carry, or a relay refusal), each with `discard()` and `reauthor()`.
532
573
  */
533
574
  conflicts(): readonly MeshConflict[];
575
+ /** The room's compaction state as the relay last announced it; undefined before any notice. */
576
+ readonly compaction: Signal<CompactionState | undefined>;
577
+ /**
578
+ * The seat pressed (`true`) or released Compact: it declares itself ready for a consensus cut
579
+ * whenever it is connected and nothing it wrote is outstanding, re-declaring on every change. A
580
+ * reconnect or a new generation releases it.
581
+ */
582
+ declareReady(pressed: boolean): void;
534
583
  /** Path-addressed write (`'a.b.c'` or segments), emitted immediately. */
535
584
  setAtPath(path: string | readonly (string | number)[], value: unknown): void;
536
585
  /**
@@ -716,4 +765,4 @@ type RtcPresenceRef<T> = {
716
765
  declare function rtcPresence<T>(links: PeerLinks, opt: RtcPresenceOptions): RtcPresenceRef<T>;
717
766
 
718
767
  export { agentSeat, defaultPeerChannels, describeOp, directTransport, meshSync, peerLinks, presenceChannel, rtcPeerConnector, rtcPresence, setAtPath, webRtcMesh, webSocketTransport };
719
- export type { AgentSeat, AgentSeatOptions, DataChannelLike, MeshDirect, MeshPeer, MeshStatus, MeshSyncOptions, MeshSyncRef, MeshTransport, MeshTransportFactory, PeerChannelSpec, PeerConnector, PeerLinks, PeerLinksOptions, PresenceFrame, RtcPresenceOptions, RtcPresenceRef, SeatChange, SeatEvent, SeatResync, SeatSync, SignalingPort, StableSnapshot, SyncHealth, SyncHealthStatus, WebRtcMeshOptions, WebRtcMeshRef };
768
+ export type { AgentSeat, AgentSeatOptions, DataChannelLike, DirectTransportOptions, MeshDirect, MeshPeer, MeshStatus, MeshSyncOptions, MeshSyncRef, MeshTransport, MeshTransportFactory, PeerChannelSpec, PeerConnector, PeerLinks, PeerLinksOptions, PresenceFrame, RtcPresenceOptions, RtcPresenceRef, SeatChange, SeatEvent, SeatResync, SeatSync, SignalingPort, StableSnapshot, SyncHealth, SyncHealthStatus, WebRtcMeshOptions, WebRtcMeshRef };