@mmstack/mesh 21.14.1 → 21.15.1

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.14.1",
3
+ "version": "21.15.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -20,8 +20,8 @@
20
20
  "homepage": "https://github.com/mihajm/mmstack/blob/master/packages/mesh/client",
21
21
  "peerDependencies": {
22
22
  "@angular/core": ">=21 <22",
23
- "@mmstack/primitives": ">=21.24 <22",
24
- "@mmstack/mesh-protocol": ">=0.14 <1"
23
+ "@mmstack/primitives": ">=21.25 <22",
24
+ "@mmstack/mesh-protocol": ">=0.15.1 <1"
25
25
  },
26
26
  "sideEffects": false,
27
27
  "module": "fesm2022/mmstack-mesh.mjs",
@@ -1,6 +1,36 @@
1
- import { ClientMsg, ServerMsg, Relay, PrincipalCtx, IceServer, ClientSignalMsg, PresenceState, OpPolicy } from '@mmstack/mesh-protocol';
2
- import { OpSync, MergePolicyEntry, DiffOpsOptions, OpEnvelope, AsyncStore, ForkStoreOptions, SyncedFork, WritableSignalStore, StoreOp, 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
+
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
+ };
23
+ /**
24
+ * The authored intent of an envelope: its raw op list and one bump flag, what a re-author rebuilds
25
+ * from. The raws are the stamped ops without their expansion clears (a diffed write never emits a
26
+ * `clear` of its own, so every `clear` is one) and without cites and epoch. The envelope bumped when
27
+ * an op's epoch rises above the register baseline at its path as the client held it before the
28
+ * envelope (the relay's own test for a bump).
29
+ */
30
+ type Intent = {
31
+ readonly raws: readonly StoreOp[];
32
+ readonly bump: boolean;
33
+ };
4
34
 
5
35
  /**
6
36
  * One live connection to a relay. `meshSync` calls the factory per (re)connect; a transport
@@ -29,6 +59,38 @@ declare function webSocketTransport(url: string, protocols?: string | string[]):
29
59
  */
30
60
  declare function directTransport(relay: Relay, ctx: PrincipalCtx): MeshTransportFactory;
31
61
 
62
+ /**
63
+ * Why a write is a conflict: its replay into a new generation cites something the generation does
64
+ * not hold (`'uncovered'`, never sent), or the relay refused it — a cite it does not cover
65
+ * (`'citation'`) or an epoch raised without the authority to (`'epoch-bump'`).
66
+ */
67
+ type ConflictCause = 'uncovered' | 'citation' | 'epoch-bump';
68
+ /**
69
+ * A write that will never be admitted as it stands. Its local effect is retracted (a replay that
70
+ * failed its pre-check is never applied; a refused write is dropped by the snapshot that follows).
71
+ * The two verbs are the whole surface: `discard()` lets it go, `reauthor()` writes its raw ops again
72
+ * as a new write citing the current state. Neither can submit the original envelope.
73
+ */
74
+ type MeshConflict = {
75
+ /** The envelope as it was authored (its values, cites and epoch). */
76
+ readonly env: OpEnvelope;
77
+ readonly intent: Intent;
78
+ readonly cause: ConflictCause;
79
+ discard(): void;
80
+ /** Write the raw ops again as a new write; false when the shell cannot write (no `reauthor`). */
81
+ reauthor(): boolean;
82
+ };
83
+ /** The room's compaction state, as the relay last announced it. */
84
+ type CompactionState = {
85
+ /** Droppable tombstones counted against the budget. */
86
+ readonly count: number;
87
+ /** The hard budget, 0 when the room arms none. */
88
+ readonly budget: number;
89
+ /** Origins of the members currently declared ready for a consensus cut. */
90
+ readonly ready: readonly string[];
91
+ };
92
+ /** The room generation the client installed, as its snapshot welcome named it. */
93
+ type GenerationState = Pick<InstalledGeneration, 'instance' | 'index' | 'reason' | 'policy'>;
32
94
  type MeshStatus = 'connecting'
33
95
  /** Queued behind another tab that owns this key's durable outbox (`crossTab: 'queue'`). */
34
96
  | 'waiting' | 'live' | 'reconnecting' | 'ejected' | 'closed';
@@ -283,7 +345,7 @@ type MeshSyncOptions = {
283
345
  /** The connection dropped and a reconnect is scheduled; `code` is the close code (1009 = message too big, 1006 = dropped). */
284
346
  readonly onDisconnect?: (code: number, reason: string) => void;
285
347
  /** A write the relay refused (see `MeshSessionHooks.onRefused`); the envelope carries its values. */
286
- readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order') => void;
348
+ readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
287
349
  /**
288
350
  * Hold the connection until the local base is assembled. `meshSync` awaits this before it connects
289
351
  * (and before it restores an `outbox`), so a store hydrated from another source first (a worker
@@ -382,6 +444,26 @@ type MeshSyncRef<T extends object = Record<string, unknown>> = {
382
444
  fork(opt?: ForkStoreOptions<T & Record<string, any>>): SyncedFork<T & Record<string, any>>;
383
445
  /** Authority surface over the CURRENT op-sync (it is rebuilt on restore); see {@link SeatSync}. */
384
446
  readonly sync: SeatSync<T>;
447
+ /**
448
+ * Writes that will never be admitted as they stand: a write a compaction cut could not replay
449
+ * (it cites something the cut folded away) or one the relay refused. Each offers `discard()` or
450
+ * `reauthor()` (write its values again, citing the current state). Persisted with the outbox.
451
+ */
452
+ readonly conflicts: Signal<readonly MeshConflict[]>;
453
+ /** The room's compaction state as the relay last announced it; undefined before any notice. */
454
+ readonly compaction: Signal<CompactionState | undefined>;
455
+ /**
456
+ * The room generation this client installed: set by every snapshot welcome of a new generation
457
+ * (a cut's welcome flips it), untouched by one of the installed generation. Undefined until the
458
+ * first snapshot welcome and after a room was recreated without its record.
459
+ */
460
+ readonly generation: Signal<GenerationState | undefined>;
461
+ /**
462
+ * The member pressed (`true`) or released Compact: the client declares itself ready for a
463
+ * consensus cut whenever nothing it wrote is outstanding, re-declaring on every change. A
464
+ * reconnect or a new generation releases it.
465
+ */
466
+ declareReady(pressed: boolean): void;
385
467
  close(): void;
386
468
  };
387
469
  /**
@@ -399,7 +481,7 @@ type SeatChange = {
399
481
  /** The relay's total-order stamp. Strictly increasing across `change` events between resyncs. */
400
482
  readonly seq: number;
401
483
  readonly writer: string;
402
- readonly ops: readonly StoreOp[];
484
+ readonly ops: readonly StoreOp$1[];
403
485
  };
404
486
  /**
405
487
  * Seq continuity broke: the seat re-established state from a room snapshot (a reconnect past
@@ -454,7 +536,7 @@ type AgentSeatOptions = {
454
536
  readonly context?: toStoreOptions;
455
537
  readonly onEject?: (reason: string) => void;
456
538
  /** A write the relay refused; it is not in the room, and the doc was rehydrated. The envelope carries its values. */
457
- readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order') => void;
539
+ readonly onRefused?: (env: OpEnvelope, reason: 'generation' | 'schema' | 'order' | 'compacting') => void;
458
540
  };
459
541
  type AgentSeat<T extends object> = {
460
542
  /** The live converging replica. Reads exactly like a local signal store. */
@@ -470,6 +552,19 @@ type AgentSeat<T extends object> = {
470
552
  stableSnapshot(): StableSnapshot<T> | null;
471
553
  /** Run local writes and emit them to the room as one envelope, like any peer's edit. */
472
554
  write(fn: () => void): void;
555
+ /**
556
+ * The seat's writes that will never be admitted as they stand (a replay a compaction cut could not
557
+ * carry, or a relay refusal), each with `discard()` and `reauthor()`.
558
+ */
559
+ conflicts(): readonly MeshConflict[];
560
+ /** The room's compaction state as the relay last announced it; undefined before any notice. */
561
+ readonly compaction: Signal<CompactionState | undefined>;
562
+ /**
563
+ * The seat pressed (`true`) or released Compact: it declares itself ready for a consensus cut
564
+ * whenever it is connected and nothing it wrote is outstanding, re-declaring on every change. A
565
+ * reconnect or a new generation releases it.
566
+ */
567
+ declareReady(pressed: boolean): void;
473
568
  /** Path-addressed write (`'a.b.c'` or segments), emitted immediately. */
474
569
  setAtPath(path: string | readonly (string | number)[], value: unknown): void;
475
570
  /**
@@ -539,7 +634,7 @@ declare function setAtPath(node: unknown, path: string | readonly PathSegment[],
539
634
  * activity feeds and model context. Values render as truncated JSON. Pair with a seat's
540
635
  * `changes` stream: narrating each batch's ops yields an append-only account of the room.
541
636
  */
542
- declare function describeOp(op: StoreOp, writer: string): string;
637
+ declare function describeOp(op: StoreOp$1, writer: string): string;
543
638
 
544
639
  type WebRtcMeshOptions = {
545
640
  readonly room: string;