@mmstack/mesh 22.15.0 → 22.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": "22.15.0",
3
+ "version": "22.15.2",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "@angular/core": ">=22 <23",
23
23
  "@mmstack/primitives": ">=22.25 <23",
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,6 +1,6 @@
1
+ import { Injector, Signal, WritableSignal } from "@angular/core";
1
2
  import { ClientMsg, ClientSignalMsg, CoverContext, Dot, GenerationReason, Hlc, IceServer, Key, OpEnvelope, OpPolicy, PolicyViolation, PresenceState, PrincipalCtx, Ranges, Receipts, RegisterStore, Relay, ServerDirectMsg, ServerMsg, StoreOp, TailPolicy, VersionRange } from "@mmstack/mesh-protocol";
2
3
  import { AsyncStore, DiffOpsOptions, ForkStoreOptions, MergePolicyEntry, OpEnvelope as OpEnvelope$1, OpSync, StoreOp as StoreOp$1, SyncedFork, WritableSignalStore, toStoreOptions } from "@mmstack/primitives/core";
3
- import { Injector, Signal, WritableSignal } from "@angular/core";
4
4
  /**
5
5
  * The client half of a room generation: the record fields a snapshot welcome carries, the admission
6
6
  * evidence the client keeps for its pre-check, and the pure decisions the session takes on them
@@ -142,15 +142,30 @@ type MeshTransportFactory = () => MeshTransport;
142
142
  * flushed on open; malformed inbound frames are dropped.
143
143
  */
144
144
  export declare function webSocketTransport(url: string, protocols?: string | string[]): MeshTransportFactory;
145
+ type DirectTransportOptions = {
146
+ /**
147
+ * Hand the relay's messages to this peer BY REFERENCE instead of through a JSON hop. A snapshot
148
+ * welcome then costs the peer no copy of the room's registers: its stores hold the relay's own
149
+ * sibling objects, the same ones every other such peer holds. The peer must therefore treat
150
+ * everything it receives as the relay's memory and never mutate it — a write in place would
151
+ * corrupt the room for everyone. The peer's own messages still cross as JSON, so what it writes
152
+ * reaches the relay exactly as a socket peer's would. Off by default; opt in only for a process
153
+ * whose readers are known not to mutate what a seat materializes.
154
+ */
155
+ readonly byReference?: boolean;
156
+ };
145
157
  /**
146
158
  * Connects directly to an in-process `createRelay` — no network. The backbone of full-loop
147
159
  * tests, and handy for single-process demos or an SSR-side room.
148
160
  *
149
161
  * Messages cross as JSON in both directions, as they would over a socket, so a direct peer holds
150
162
  * exactly what a socket peer would. Handed over by reference, an `undefined` an emitter wrote
151
- * would reach relay memory where a socket peer's would have been dropped.
163
+ * would reach relay memory where a socket peer's would have been dropped. The relay's own
164
+ * messages may skip the hop ({@link DirectTransportOptions.byReference}): they never hold an
165
+ * `undefined` (every value in a room arrived as JSON), so the two peers read the same state and
166
+ * differ only in who owns the objects.
152
167
  */
153
- export declare function directTransport(relay: Relay, ctx: PrincipalCtx): MeshTransportFactory;
168
+ export declare function directTransport(relay: Relay, ctx: PrincipalCtx, options?: DirectTransportOptions): MeshTransportFactory;
154
169
  /**
155
170
  * Why a write is a conflict: its replay into a new generation cites something the generation does
156
171
  * not hold (`'uncovered'`, never sent), or the relay refused it — a cite it does not cover
@@ -181,6 +196,8 @@ type CompactionState = {
181
196
  /** Origins of the members currently declared ready for a consensus cut. */
182
197
  readonly ready: readonly string[];
183
198
  };
199
+ /** The room generation the client installed, as its snapshot welcome named it. */
200
+ type GenerationState = Pick<InstalledGeneration, 'instance' | 'index' | 'reason' | 'policy'>;
184
201
  /**
185
202
  * The session's durable half, persisted as one unit with the outbox: the fields of the generation
186
203
  * the tail was written in and its admission evidence, the intents of the pending writes, unresolved
@@ -279,16 +296,23 @@ type MeshSessionHooks = {
279
296
  * `'generation'` — written in a room generation that a cut with the `discard` policy closed (a
280
297
  * migration or a rollback: the reset is the intent), or in a room recreated without its
281
298
  * generation record; `'schema'` — a data shape older than the room's; `'order'` — a version
282
- * below this origin's admitted maximum that was never admitted (a second tab on one origin). The
283
- * session drops the write locally and hydrates from a fresh snapshot; the envelope carries the
299
+ * below this origin's admitted maximum that was never admitted (a second tab on one origin);
300
+ * `'compacting'` — a host refused a write from a connection declared ready for the current
301
+ * generation (the relay itself never sends it). The session drops the write locally and hydrates from a fresh snapshot; the envelope carries the
284
302
  * values, so the application can offer to write them again. Any `whenAcked` waiter rejects.
285
303
  * A write a compaction cut replays is never refused here: it is resent, or it is a conflict.
286
304
  */
287
- onRefused?(env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order'): void;
305
+ onRefused?(env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order' | 'compacting'): void;
288
306
  /** The unresolved conflicts changed (a write classified, discarded or re-authored). */
289
307
  onConflicts?(conflicts: readonly MeshConflict[]): void;
290
308
  /** The relay announced the room's compaction state (count, budget, ready members). */
291
309
  onCompaction?(state: CompactionState): void;
310
+ /**
311
+ * A snapshot welcome of a NEW generation installed (a cut's welcome, or the first snapshot of
312
+ * the session); `undefined` when the room was recreated without its record. A welcome of the
313
+ * installed generation never fires it.
314
+ */
315
+ onGeneration?(generation: GenerationState | undefined): void;
292
316
  };
293
317
  type MeshSessionOptions<T extends object> = {
294
318
  readonly room: string;
@@ -615,7 +639,7 @@ type MeshSyncOptions = {
615
639
  /** The connection dropped and a reconnect is scheduled; `code` is the close code (1009 = message too big, 1006 = dropped). */
616
640
  readonly onDisconnect?: (code: number, reason: string) => void;
617
641
  /** A write the relay refused (see `MeshSessionHooks.onRefused`); the envelope carries its values. */
618
- readonly onRefused?: (env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order') => void;
642
+ readonly onRefused?: (env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
619
643
  /**
620
644
  * Hold the connection until the local base is assembled. `meshSync` awaits this before it connects
621
645
  * (and before it restores an `outbox`), so a store hydrated from another source first (a worker
@@ -722,6 +746,12 @@ type MeshSyncRef<T extends object = Record<string, unknown>> = {
722
746
  readonly conflicts: Signal<readonly MeshConflict[]>;
723
747
  /** The room's compaction state as the relay last announced it; undefined before any notice. */
724
748
  readonly compaction: Signal<CompactionState | undefined>;
749
+ /**
750
+ * The room generation this client installed: set by every snapshot welcome of a new generation
751
+ * (a cut's welcome flips it), untouched by one of the installed generation. Undefined until the
752
+ * first snapshot welcome and after a room was recreated without its record.
753
+ */
754
+ readonly generation: Signal<GenerationState | undefined>;
725
755
  /**
726
756
  * The member pressed (`true`) or released Compact: the client declares itself ready for a
727
757
  * consensus cut whenever nothing it wrote is outstanding, re-declaring on every change. A
@@ -799,7 +829,7 @@ type AgentSeatOptions = {
799
829
  readonly context?: toStoreOptions;
800
830
  readonly onEject?: (reason: string) => void;
801
831
  /** A write the relay refused; it is not in the room, and the doc was rehydrated. The envelope carries its values. */
802
- readonly onRefused?: (env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order') => void;
832
+ readonly onRefused?: (env: OpEnvelope$1, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
803
833
  };
804
834
  type AgentSeat<T extends object> = {
805
835
  /** The live converging replica. Reads exactly like a local signal store. */
@@ -820,6 +850,14 @@ type AgentSeat<T extends object> = {
820
850
  * carry, or a relay refusal), each with `discard()` and `reauthor()`.
821
851
  */
822
852
  conflicts(): readonly MeshConflict[];
853
+ /** The room's compaction state as the relay last announced it; undefined before any notice. */
854
+ readonly compaction: Signal<CompactionState | undefined>;
855
+ /**
856
+ * The seat pressed (`true`) or released Compact: it declares itself ready for a consensus cut
857
+ * whenever it is connected and nothing it wrote is outstanding, re-declaring on every change. A
858
+ * reconnect or a new generation releases it.
859
+ */
860
+ declareReady(pressed: boolean): void;
823
861
  /** Path-addressed write (`'a.b.c'` or segments), emitted immediately. */
824
862
  setAtPath(path: string | readonly (string | number)[], value: unknown): void;
825
863
  /**
@@ -1001,4 +1039,4 @@ type RtcPresenceRef<T> = {
1001
1039
  * Values travel as JSON.
1002
1040
  */
1003
1041
  export declare function rtcPresence<T>(links: PeerLinks, opt: RtcPresenceOptions): RtcPresenceRef<T>;
1004
- 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 };
1042
+ 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 };