@net-mesh/browser 0.37.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +517 -0
  2. package/LICENSE-APACHE +190 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +666 -0
  5. package/dist/async-queue.d.ts +26 -0
  6. package/dist/async-queue.js +62 -0
  7. package/dist/credential.d.ts +70 -0
  8. package/dist/credential.js +95 -0
  9. package/dist/errors.d.ts +400 -0
  10. package/dist/errors.js +726 -0
  11. package/dist/events.d.ts +232 -0
  12. package/dist/events.js +298 -0
  13. package/dist/identity.d.ts +40 -0
  14. package/dist/identity.js +78 -0
  15. package/dist/index.bundle.js +2 -0
  16. package/dist/index.d.ts +38 -0
  17. package/dist/index.js +46 -0
  18. package/dist/leader/events.d.ts +111 -0
  19. package/dist/leader/events.js +116 -0
  20. package/dist/leader/index.d.ts +14 -0
  21. package/dist/leader/index.js +11 -0
  22. package/dist/leader/session.d.ts +539 -0
  23. package/dist/leader/session.js +770 -0
  24. package/dist/leader/wasm.d.ts +123 -0
  25. package/dist/leader/wasm.js +39 -0
  26. package/dist/lobby.d.ts +183 -0
  27. package/dist/lobby.js +504 -0
  28. package/dist/local.d.ts +80 -0
  29. package/dist/local.js +160 -0
  30. package/dist/net_leaf.d.ts +1494 -0
  31. package/dist/net_leaf.js +3753 -0
  32. package/dist/net_leaf_bg.wasm +0 -0
  33. package/dist/net_leaf_bg.wasm.d.ts +137 -0
  34. package/dist/netcode/client.d.ts +102 -0
  35. package/dist/netcode/client.js +296 -0
  36. package/dist/netcode/clock.d.ts +45 -0
  37. package/dist/netcode/clock.js +54 -0
  38. package/dist/netcode/host.d.ts +118 -0
  39. package/dist/netcode/host.js +276 -0
  40. package/dist/netcode/index.d.ts +19 -0
  41. package/dist/netcode/index.js +14 -0
  42. package/dist/netcode/interpolate.d.ts +50 -0
  43. package/dist/netcode/interpolate.js +100 -0
  44. package/dist/netcode/wire.d.ts +125 -0
  45. package/dist/netcode/wire.js +117 -0
  46. package/dist/node.d.ts +908 -0
  47. package/dist/node.js +1085 -0
  48. package/dist/org.d.ts +412 -0
  49. package/dist/org.js +567 -0
  50. package/dist/peer-driver.d.ts +117 -0
  51. package/dist/peer-driver.js +224 -0
  52. package/dist/store/assembly.d.ts +176 -0
  53. package/dist/store/assembly.js +325 -0
  54. package/dist/store/chunker.d.ts +83 -0
  55. package/dist/store/chunker.js +190 -0
  56. package/dist/store/core.d.ts +136 -0
  57. package/dist/store/core.js +477 -0
  58. package/dist/store/definition.d.ts +23 -0
  59. package/dist/store/definition.js +83 -0
  60. package/dist/store/errors.d.ts +77 -0
  61. package/dist/store/errors.js +94 -0
  62. package/dist/store/host.d.ts +247 -0
  63. package/dist/store/host.js +675 -0
  64. package/dist/store/index.d.ts +50 -0
  65. package/dist/store/index.js +40 -0
  66. package/dist/store/interest.d.ts +40 -0
  67. package/dist/store/interest.js +77 -0
  68. package/dist/store/inventory.d.ts +81 -0
  69. package/dist/store/inventory.js +140 -0
  70. package/dist/store/join.d.ts +118 -0
  71. package/dist/store/join.js +724 -0
  72. package/dist/store/json.d.ts +50 -0
  73. package/dist/store/json.js +283 -0
  74. package/dist/store/ledger.d.ts +187 -0
  75. package/dist/store/ledger.js +292 -0
  76. package/dist/store/owner.d.ts +616 -0
  77. package/dist/store/owner.js +1711 -0
  78. package/dist/store/patch.d.ts +70 -0
  79. package/dist/store/patch.js +166 -0
  80. package/dist/store/player.d.ts +65 -0
  81. package/dist/store/player.js +261 -0
  82. package/dist/store/replica.d.ts +187 -0
  83. package/dist/store/replica.js +740 -0
  84. package/dist/store/state.d.ts +42 -0
  85. package/dist/store/state.js +165 -0
  86. package/dist/store/types.d.ts +200 -0
  87. package/dist/store/types.js +25 -0
  88. package/dist/store/visibility.d.ts +118 -0
  89. package/dist/store/visibility.js +282 -0
  90. package/dist/store/wire.d.ts +309 -0
  91. package/dist/store/wire.js +834 -0
  92. package/dist/stream.d.ts +174 -0
  93. package/dist/stream.js +238 -0
  94. package/dist/three/index.d.ts +109 -0
  95. package/dist/three/index.js +130 -0
  96. package/dist/udp-probe.d.ts +159 -0
  97. package/dist/udp-probe.js +245 -0
  98. package/dist/wasm.d.ts +642 -0
  99. package/dist/wasm.js +98 -0
  100. package/dist/world/border.d.ts +84 -0
  101. package/dist/world/border.js +99 -0
  102. package/dist/world/handoff.d.ts +187 -0
  103. package/dist/world/handoff.js +222 -0
  104. package/dist/world/index.d.ts +13 -0
  105. package/dist/world/index.js +9 -0
  106. package/dist/world/link.d.ts +179 -0
  107. package/dist/world/link.js +476 -0
  108. package/dist/world/regions.d.ts +154 -0
  109. package/dist/world/regions.js +314 -0
  110. package/package.json +72 -0
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Slice D — the replica: snapshot install, delta apply, resync,
3
+ * generations.
4
+ *
5
+ * ## What this module is
6
+ *
7
+ * The other half of slice C. The owner emits `man` + `snap` chunks and
8
+ * later `delta`s; this decides what a caller is allowed to SEE as a
9
+ * result. It is the production form of the state machine
10
+ * `test/store/lifecycle-model.ts` models abstractly (§1.7a), with the
11
+ * real codec, the real assembler (slice B1) and the real document.
12
+ *
13
+ * ## The three monotone numbers (§1.7a), which are different things
14
+ *
15
+ * - `installed` — the generation whose snapshot is published.
16
+ * - `assembling` — the generation of the open assembly.
17
+ * - `retired` — the highest generation ever **admitted**, installed or
18
+ * not. This is the watermark that makes an abandoned generation
19
+ * inadmissible for ever: `g > installed` would let a delayed manifest
20
+ * reopen a generation that was admitted, abandoned, and never
21
+ * published. Admission tests `g > retired`.
22
+ *
23
+ * Duplicate active manifests fall out of the same rule rather than
24
+ * needing their own: admitting the first set `retired := g`, so the
25
+ * second fails `g > retired` and the open assembly is untouched.
26
+ *
27
+ * ## What an empty slot is not
28
+ *
29
+ * `fenced` exists because an empty correlation slot is not consent. A
30
+ * refused request fences the subscription's view; only `ready` accepts
31
+ * unsolicited owner refreshes, and a `fenced` replica records no skip,
32
+ * so an owner emission cannot lift a fence the caller placed.
33
+ *
34
+ * ## Scope
35
+ *
36
+ * Audience transitions and `resume` are slice F, actions and the ledger
37
+ * are slice E. Both are refused here rather than half-served: this
38
+ * module issues `join` and `resync` and nothing else.
39
+ *
40
+ * Its acceptance gate is reliable transfer (§4 D), exactly as B2′ — a
41
+ * replica that applies deltas in order is not evidence that the
42
+ * transport delivers them in order.
43
+ */
44
+ import { StoreCore } from './core.js';
45
+ import type { Decimal, Hex } from './wire.js';
46
+ import type { ActionSpec, InputSpec, StoreDefinition } from './types.js';
47
+ /** A frame to hand to the transport. */
48
+ export interface Request {
49
+ readonly kind: 'join' | 'resync' | 'aud' | 'resume';
50
+ readonly q: Hex;
51
+ readonly frame: string;
52
+ }
53
+ /** The five states of §1.7a. */
54
+ export type ReplicaState = 'joining' | 'installing' | 'ready' | 'fenced' | 'closed';
55
+ /**
56
+ * How many times an unanswered transition re-asks before the replica
57
+ * gives the caller a terminal answer.
58
+ *
59
+ * Three: enough that a join survives independent losses, few enough
60
+ * that a store nobody is serving stops asking. Each re-ask abandons
61
+ * the subscription the owner may have opened for the previous one;
62
+ * nothing can release it by name, because a replica whose MANIFEST
63
+ * was lost never learned a handle to release — the owner's own idle
64
+ * lease (`owner.ts`'s `HANDLE_LEASE_MS`) is what reclaims it, which
65
+ * is why the ladder is bounded rather than endless.
66
+ */
67
+ export declare const MAX_JOIN_REASKS = 3;
68
+ /** What one arrival produced. */
69
+ export interface Received {
70
+ readonly out: readonly Request[];
71
+ /** A stable, countable reason, when the arrival was not taken. */
72
+ readonly dropped: string | null;
73
+ }
74
+ export interface ReplicaDeps<S extends object, A extends ActionSpec, I extends InputSpec> {
75
+ readonly definition: StoreDefinition<S, A, I>;
76
+ /** The document and its publication — the replica never commits directly. */
77
+ readonly core: StoreCore<S, A, I>;
78
+ /** The transport's current per-event budget. */
79
+ readonly maxEventBytes: number;
80
+ /** A fresh correlation id per request. Its uniqueness is the caller's. */
81
+ readonly newQ: () => Hex;
82
+ readonly now: () => number;
83
+ /**
84
+ * The audience this caller wants at the start.
85
+ *
86
+ * After a `setAudience` the DESIRED one is the replica's own, and it
87
+ * is what every later request states — never the owner's older one.
88
+ */
89
+ readonly audience: readonly string[];
90
+ /**
91
+ * WHICH store of this definition to join — the owner's declared
92
+ * address, carried on the join so the owner it is NOT addressed to
93
+ * can refuse it. See `wire.ts`'s field table.
94
+ */
95
+ readonly store: string;
96
+ /** The opaque join key the owner's policy reads. */
97
+ readonly key: string;
98
+ /** The interest set to join with; absent: every entity. */
99
+ readonly interest?: readonly string[];
100
+ }
101
+ /**
102
+ * A replica of one owner's store.
103
+ *
104
+ * Every method returns the requests it wants sent; nothing here touches
105
+ * a transport, so the state machine is testable without one.
106
+ */
107
+ export declare class StoreReplica<S extends object, A extends ActionSpec, I extends InputSpec> {
108
+ #private;
109
+ private readonly deps;
110
+ constructor(deps: ReplicaDeps<S, A, I>);
111
+ /**
112
+ * The caller's desired interest set, stated by every later `join` and
113
+ * `resume` so a rejoin never falls back to an older one. `null`: none
114
+ * declared, every entity delivered.
115
+ */
116
+ get interest(): readonly string[] | null;
117
+ set interest(keys: readonly string[] | null);
118
+ /** The caller's latest desired audience. */
119
+ get desired(): readonly string[];
120
+ /** Local waiters on the transition in flight. */
121
+ get waiters(): number;
122
+ get state(): ReplicaState;
123
+ /** The learned handle, or null while none has been learned. */
124
+ get handle(): Hex | null;
125
+ /** The installed generation, as a canonical decimal, or null. */
126
+ get installed(): Decimal | null;
127
+ /** The owner's revision for the installed view, or null. */
128
+ get revision(): Decimal | null;
129
+ /** The watermark: the highest generation ever admitted. */
130
+ get retired(): Decimal;
131
+ /** The highest refresh dropped mid-transition, or null. */
132
+ get skipped(): Decimal | null;
133
+ /** Arrivals not taken, by reason. */
134
+ get dropped(): Readonly<Record<string, number>>;
135
+ /**
136
+ * The first request: a `join`.
137
+ *
138
+ * Only `join` creates a handle, so this is the only entry point from
139
+ * a state with none — including after `no {closed}`, which discards
140
+ * the handle and all of its generation state.
141
+ */
142
+ join(): Request;
143
+ /**
144
+ * Change what this caller wants to see (§1.7).
145
+ *
146
+ * Three moments, deliberately separate: local intent is IMMEDIATE —
147
+ * the view is cleared to `empty()` and the status is `syncing`,
148
+ * before the owner has agreed to anything, because continuing to
149
+ * render the old audience is the disclosure this exists to stop.
150
+ * Owner acceptance allocates the generation, and installation
151
+ * publishes it.
152
+ *
153
+ * Equal pending requests share one wire request and one `q`, with a
154
+ * local waiter each: `q` is the transition's identity on the wire,
155
+ * not a waiter's.
156
+ */
157
+ setAudience(names: readonly string[]): readonly Request[];
158
+ /**
159
+ * The session was replaced (§1.6).
160
+ *
161
+ * A reconnect is not an audience change: the last snapshot is
162
+ * RETAINED and marked stale, because what the caller may see has not
163
+ * changed — only whether it is current. The request states the
164
+ * caller's latest desired audience, never the owner's older one.
165
+ */
166
+ reconnect(): readonly Request[];
167
+ /**
168
+ * One local waiter gives up.
169
+ *
170
+ * Cancellation is per waiter; the wire request is not. Cancelling the
171
+ * last one fences the subscription — the view was invalidated at
172
+ * request time and is NOT restored, because the caller asked for a
173
+ * different one.
174
+ */
175
+ cancelWaiter(): void;
176
+ /** One decoded arrival from the owner. */
177
+ receive(frame: string): Received;
178
+ /**
179
+ * The assembly deadline, and the lease the caller keeps by asking.
180
+ *
181
+ * Returns the requests the elapsed time produced — at most one
182
+ * `resync`, because recovery is coalesced.
183
+ */
184
+ tick(): readonly Request[];
185
+ /** The caller gives up this subscription. Fences it; no view. */
186
+ cancel(): void;
187
+ }