@mmstack/mesh 21.14.1 → 21.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/mesh",
3
- "version": "21.14.1",
3
+ "version": "21.15.0",
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"
25
25
  },
26
26
  "sideEffects": false,
27
27
  "module": "fesm2022/mmstack-mesh.mjs",
@@ -1,7 +1,19 @@
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';
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
3
  import { Signal, Injector, WritableSignal } from '@angular/core';
4
4
 
5
+ /**
6
+ * The authored intent of an envelope: its raw op list and one bump flag, what a re-author rebuilds
7
+ * from. The raws are the stamped ops without their expansion clears (a diffed write never emits a
8
+ * `clear` of its own, so every `clear` is one) and without cites and epoch. The envelope bumped when
9
+ * an op's epoch rises above the register baseline at its path as the client held it before the
10
+ * envelope (the relay's own test for a bump).
11
+ */
12
+ type Intent = {
13
+ readonly raws: readonly StoreOp[];
14
+ readonly bump: boolean;
15
+ };
16
+
5
17
  /**
6
18
  * One live connection to a relay. `meshSync` calls the factory per (re)connect; a transport
7
19
  * represents a single connection and never reconnects itself.
@@ -29,6 +41,36 @@ declare function webSocketTransport(url: string, protocols?: string | string[]):
29
41
  */
30
42
  declare function directTransport(relay: Relay, ctx: PrincipalCtx): MeshTransportFactory;
31
43
 
44
+ /**
45
+ * Why a write is a conflict: its replay into a new generation cites something the generation does
46
+ * not hold (`'uncovered'`, never sent), or the relay refused it — a cite it does not cover
47
+ * (`'citation'`) or an epoch raised without the authority to (`'epoch-bump'`).
48
+ */
49
+ type ConflictCause = 'uncovered' | 'citation' | 'epoch-bump';
50
+ /**
51
+ * A write that will never be admitted as it stands. Its local effect is retracted (a replay that
52
+ * failed its pre-check is never applied; a refused write is dropped by the snapshot that follows).
53
+ * The two verbs are the whole surface: `discard()` lets it go, `reauthor()` writes its raw ops again
54
+ * as a new write citing the current state. Neither can submit the original envelope.
55
+ */
56
+ type MeshConflict = {
57
+ /** The envelope as it was authored (its values, cites and epoch). */
58
+ readonly env: OpEnvelope;
59
+ readonly intent: Intent;
60
+ readonly cause: ConflictCause;
61
+ discard(): void;
62
+ /** Write the raw ops again as a new write; false when the shell cannot write (no `reauthor`). */
63
+ reauthor(): boolean;
64
+ };
65
+ /** The room's compaction state, as the relay last announced it. */
66
+ type CompactionState = {
67
+ /** Droppable tombstones counted against the budget. */
68
+ readonly count: number;
69
+ /** The hard budget, 0 when the room arms none. */
70
+ readonly budget: number;
71
+ /** Origins of the members currently declared ready for a consensus cut. */
72
+ readonly ready: readonly string[];
73
+ };
32
74
  type MeshStatus = 'connecting'
33
75
  /** Queued behind another tab that owns this key's durable outbox (`crossTab: 'queue'`). */
34
76
  | 'waiting' | 'live' | 'reconnecting' | 'ejected' | 'closed';
@@ -382,6 +424,20 @@ type MeshSyncRef<T extends object = Record<string, unknown>> = {
382
424
  fork(opt?: ForkStoreOptions<T & Record<string, any>>): SyncedFork<T & Record<string, any>>;
383
425
  /** Authority surface over the CURRENT op-sync (it is rebuilt on restore); see {@link SeatSync}. */
384
426
  readonly sync: SeatSync<T>;
427
+ /**
428
+ * Writes that will never be admitted as they stand: a write a compaction cut could not replay
429
+ * (it cites something the cut folded away) or one the relay refused. Each offers `discard()` or
430
+ * `reauthor()` (write its values again, citing the current state). Persisted with the outbox.
431
+ */
432
+ readonly conflicts: Signal<readonly MeshConflict[]>;
433
+ /** The room's compaction state as the relay last announced it; undefined before any notice. */
434
+ readonly compaction: Signal<CompactionState | undefined>;
435
+ /**
436
+ * The member pressed (`true`) or released Compact: the client declares itself ready for a
437
+ * consensus cut whenever nothing it wrote is outstanding, re-declaring on every change. A
438
+ * reconnect or a new generation releases it.
439
+ */
440
+ declareReady(pressed: boolean): void;
385
441
  close(): void;
386
442
  };
387
443
  /**
@@ -399,7 +455,7 @@ type SeatChange = {
399
455
  /** The relay's total-order stamp. Strictly increasing across `change` events between resyncs. */
400
456
  readonly seq: number;
401
457
  readonly writer: string;
402
- readonly ops: readonly StoreOp[];
458
+ readonly ops: readonly StoreOp$1[];
403
459
  };
404
460
  /**
405
461
  * Seq continuity broke: the seat re-established state from a room snapshot (a reconnect past
@@ -470,6 +526,11 @@ type AgentSeat<T extends object> = {
470
526
  stableSnapshot(): StableSnapshot<T> | null;
471
527
  /** Run local writes and emit them to the room as one envelope, like any peer's edit. */
472
528
  write(fn: () => void): void;
529
+ /**
530
+ * The seat's writes that will never be admitted as they stand (a replay a compaction cut could not
531
+ * carry, or a relay refusal), each with `discard()` and `reauthor()`.
532
+ */
533
+ conflicts(): readonly MeshConflict[];
473
534
  /** Path-addressed write (`'a.b.c'` or segments), emitted immediately. */
474
535
  setAtPath(path: string | readonly (string | number)[], value: unknown): void;
475
536
  /**
@@ -539,7 +600,7 @@ declare function setAtPath(node: unknown, path: string | readonly PathSegment[],
539
600
  * activity feeds and model context. Values render as truncated JSON. Pair with a seat's
540
601
  * `changes` stream: narrating each batch's ops yields an append-only account of the room.
541
602
  */
542
- declare function describeOp(op: StoreOp, writer: string): string;
603
+ declare function describeOp(op: StoreOp$1, writer: string): string;
543
604
 
544
605
  type WebRtcMeshOptions = {
545
606
  readonly room: string;