foldkit-sync 0.10.2 → 0.11.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/README.md CHANGED
@@ -380,7 +380,10 @@ The three milestones each have a reader.
380
380
 
381
381
  **Visible** is the Model. Nothing to do.
382
382
 
383
- **Saved** is the persist. `onPersistenceFailure` runs when it fails, after the
383
+ **Saved** is the persist. Between the edit showing and the persist finishing,
384
+ a reload would lose what the user saw, so the browser asks before the page
385
+ unloads (`beforeunload`) until every shown edit is stored; it usually takes
386
+ milliseconds. `onPersistenceFailure` runs when it fails, after the
384
387
  edit has been reverted; the Model it returns is what the user sees next. The
385
388
  error names why: `ReplayError` for a Message that cannot be durable,
386
389
  `StorageError` for IndexedDB.
@@ -667,6 +670,8 @@ application come first.
667
670
  grows; the loop retries. Nothing to handle.
668
671
  - **The server rejects an edit.** Dropped from `pending`, the rest replayed,
669
672
  the Model re-installed. Explain it from `status.rejected`.
673
+ - **The page unloads before the persist finishes.** The browser asks first;
674
+ leaving anyway loses the edits not yet stored.
670
675
  - **The persist fails.** The edit is reverted and `onPersistenceFailure` runs.
671
676
  The user has to redo it.
672
677
  - **Local storage was evicted.** The replica starts at cursor 0 and catches up
package/dist/do.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as AuthorizeDecision, v as Operation, w as Sync } from "./make-h5yD8STj.mjs";
1
+ import { n as AuthorizeDecision, v as Operation, w as Sync } from "./make-CFOcLcQ1.mjs";
2
2
  import { Effect } from "effect";
3
3
  import { Journal } from "foldkit-durable/core";
4
4
  //#region src/do.d.ts
package/dist/do.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"do.d.mts","names":[],"sources":["../src/do.ts"],"mappings":";;;;;iBAiCiB;WACN;;;iBAIM,mBAAmB,SAAS,QAAQ,WAAW;;WAErD,MAAM,KAAK,SAAS;;;;;;;;WAQpB,cACP,KAAK,qBACL,KAAK,QACF,QAAQ,QAAQ,WAAW,QAA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Ms extends ReadonlyArray<Memb
113
113
  };
114
114
  /** Edits to an Entity's members, kept per cell in a replicated slice and laid over its rows. */
115
115
  export declare const EditableEntity: {
116
- make: <E extends EntityFields, const Ms extends ReadonlyArray<Member<E>>>(entity: E, options: {
117
- readonly members: Ms;
118
- }) => {
119
- /** Carried so `foldkit-sync/remote` can name the rows it overlays by the Entity's own name. */
120
- entity: E;
121
- members: Ms;
122
- /** The members, as a schema: what names a cell. */
123
- Member: Schema.Literals<Ms>;
124
- /** One cell's change, on the wire: its member's value, by that member's schema. */
125
- Change: Schema.Codec<Change<E, Ms[number]>, unknown, never, never>;
126
- /** One cell's edit as the slice keeps it; `null` on the wire where it has no `at` or `by`. */
127
- Edit: Schema.Codec<CellEdit<E, Ms[number]>, unknown, never, never>;
128
- /** The durable Message that edits cells: its fields, for the application's own tag. */
129
- edited: {
130
- changes: Schema.$Array<Schema.Codec<Change<E, Ms[number]>, unknown, never, never>>;
131
- /** The journal's: absent on what a replica sends, stamped at commit. */
132
- at: Schema.optionalKey<Schema.Number>;
133
- by: Schema.optionalKey<Schema.Struct<{
134
- readonly actor: Schema.String;
135
- readonly replica: Schema.String;
136
- }>>;
137
- };
138
- /** The server's durable Message: the table holds every edit committed through `through`. */
139
- absorbed: {
140
- through: Schema.Number;
141
- };
142
- /** What the stamp writes into an edit: the sequence and the author. */
143
- stamped: (commit: {
144
- readonly sequence: number;
145
- readonly actorId: string;
146
- readonly replicaId: string;
147
- }) => {
148
- at: number;
149
- by: {
150
- actor: string;
151
- replica: string;
152
- };
153
- };
154
- /** The edits with `changes` laid over them, each cell's latest kept. */
155
- merge: (edits: ReadonlyArray<CellEdit<E, Ms[number]>>, changes: ReadonlyArray<Change<E, Ms[number]>>, at: Option.Option<number>, by: Option.Option<Author>) => ReadonlyArray<CellEdit<E, Ms[number]>>;
156
- /** The edits less those committed through `through`; the same array when none was. */
157
- absorb: (edits: ReadonlyArray<CellEdit<E, Ms[number]>>, through: number) => ReadonlyArray<CellEdit<E, Ms[number]>>;
158
- /** Whether any edit is committed through `through`: whether an absorb would drop one. */
159
- holdsThrough: (edits: ReadonlyArray<CellEdit<E, Ms[number]>>, through: number) => boolean;
160
- /**
161
- * What the slice replaced that `replica` had written: each cell whose
162
- * edit was its own, and now holds another replica's commit with another
163
- * value, though it be the same person's in another tab.
164
- */
165
- replaced: (previous: ReadonlyArray<CellEdit<E, Ms[number]>>, next: ReadonlyArray<CellEdit<E, Ms[number]>>, replica: string) => ReadonlyArray<Replaced<CellEdit<E, Ms[number]>>>;
166
- /** The cells a set of changes names: what a refusal of them undid. */
167
- cellsOf: (changes: ReadonlyArray<Change<E, Ms[number]>>) => ReadonlyArray<{
168
- readonly id: IdOf<E>;
169
- readonly member: Ms[number];
170
- }>;
171
- /**
172
- * What a row holds in one member, as the change that would set it: the
173
- * value an undo puts back.
174
- */
175
- changeAt: (row: RowOf<E, Ms[number]>, member: Ms[number]) => Change<E, Ms[number]>;
176
- /** The edit of one cell, if the edits hold one. */
177
- editOf: (edits: ReadonlyArray<CellEdit<E, Ms[number]>>, row: IdOf<E>, member: Ms[number]) => Option.Option<CellEdit<E, Ms[number]>>;
178
- mine: (edit: CellEdit<E, Ms[number]>, replica: string) => boolean;
179
- };
116
+ make: typeof make;
180
117
  };
181
118
  export type EditableEntity<E extends EntityFields, Ms extends ReadonlyArray<Member<E>>> = ReturnType<typeof make<E, Ms>>;
182
119
  //#endregion
120
+ export {};
183
121
  //# sourceMappingURL=entity.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.mts","names":[],"sources":["../src/entity.ts"],"mappings":";;;qBAkBa,QAAM,OAAA;;;;YACP,gBAAgB,OAAO;;iBAGlB;WACN;aAAmB;eAAe,QAAQ,OAAO;;;cAC9C;eAA4B,QAAQ,OAAO;;;;;YAK7C,OAAO,UAAU,gBAAgB,cAAc;KACtD,QAAQ,UAAU,cAAc,UAAU,OAAO,MAAM,YAAY;KACnE,KAAK,UAAU,gBAAgB;;YAGxB,OAAO,UAA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B;eAAA;;YACD,eACV,UAAU,cACV,WAAW,cAAc,OAAO,OAC9B,kBAAkB,KAAK,GAAG"}
package/dist/index.d.mts CHANGED
@@ -1,125 +1,11 @@
1
- import { $ as InvalidOutboxError, A as ExchangeReply, B as nativeSocket, C as ReplicaStatus, D as defineSync, E as TransportClient, F as TransportError, G as OutboxEntry, H as serveSocket, I as TransportShape, J as CheckpointRegressionError, K as Storage, L as layerFromPromise, M as SocketLike, N as SocketOptions, O as syncMetrics, P as Transport, Q as InvalidExchangeError, R as layerLoopback, S as ReplicaState, T as SyncDefinition, U as toPromise, V as portSocket, W as workerSocket, X as ForeignAcknowledgementError, Y as CommittedOrderError, Z as ForeignRejectionError, _ as JournalContract, _t as sequence, a as DefinedSync, at as UnsupportedClockVersionError, b as Replica, c as MsgOf, ct as DocumentId, d as SyncFragment, dt as ReplicaId, et as InvalidReplicaHistoryError, f as forApplication, ft as Sequence, g as Exchange, gt as replicaId, h as CommittedOperation, ht as opId, i as AuthorizeRequest, it as StorageError, j as NotifyFrame, k as ExchangeFrame, l as PolicyJournalContract, lt as LocalSequence, m as CommitStamp, mt as localSequence, n as AuthorizeDecision, nt as ReplicaClosedError, o as FragmentMessages, ot as UnsupportedReplicaVersionError, p as Checkpoint, pt as documentId, q as indexedDb, r as AuthorizePolicy, rt as ReplicaError, s as MakeOptions, st as WrongReplicaStorageError, t as ApplicationSync, tt as ReplayError, u as StampPolicy, ut as OpId, v as Operation, w as Sync$1, x as ReplicaSnapshot, y as Rejection, z as layerSocket } from "./make-h5yD8STj.mjs";
2
- import { Duration, Effect, Exit, Layer, PubSub, Schema as Schema$1, Scope, Stream } from "effect";
1
+ import { $ as InvalidOutboxError, A as ExchangeReply, B as nativeSocket, C as ReplicaStatus, D as defineSync, E as TransportClient, F as TransportError, G as OutboxEntry, H as serveSocket, I as TransportShape, J as CheckpointRegressionError, K as Storage, L as layerFromPromise, M as SocketLike, N as SocketOptions, O as syncMetrics, P as Transport, Q as InvalidExchangeError, R as layerLoopback, S as ReplicaState, T as SyncDefinition, U as toPromise, V as portSocket, W as workerSocket, X as ForeignAcknowledgementError, Y as CommittedOrderError, Z as ForeignRejectionError, _ as JournalContract, _t as sequence, a as DefinedSync, at as UnsupportedClockVersionError, b as Replica, c as MsgOf, ct as DocumentId, d as SyncFragment, dt as ReplicaId, et as InvalidReplicaHistoryError, f as forApplication, ft as Sequence, g as Exchange, gt as replicaId, h as CommittedOperation, ht as opId, i as AuthorizeRequest, it as StorageError, j as NotifyFrame, k as ExchangeFrame, l as PolicyJournalContract, lt as LocalSequence, m as CommitStamp, mt as localSequence, n as AuthorizeDecision, nt as ReplicaClosedError, o as FragmentMessages, ot as UnsupportedReplicaVersionError, p as Checkpoint, pt as documentId, q as indexedDb, r as AuthorizePolicy, rt as ReplicaError, s as MakeOptions, st as WrongReplicaStorageError, t as ApplicationSync, tt as ReplayError, u as StampPolicy, ut as OpId, v as Operation, w as Sync$1, x as ReplicaSnapshot, y as Rejection, z as layerSocket } from "./make-CFOcLcQ1.mjs";
2
+ import { Duration, Effect, Exit, Layer, PubSub, Schema, Scope, Stream } from "effect";
3
3
  import { RunnableApplication } from "foldkit-surface";
4
4
  import { UrlRequest } from "foldkit/navigation";
5
5
  import { Subscriptions } from "foldkit/subscription";
6
6
  import * as Url from "foldkit/url";
7
7
  import { Document, HtmlBuilder } from "foldkit/html";
8
8
  import * as Update from "foldkit/update";
9
- //#region src/mount.d.ts
10
- /**
11
- * A Command that dispatches `message` as the next transition, which under `Sync.mount`
12
- * means within this one: the mount applies it straight after the `update` that returned
13
- * it, and persists it if it is durable, before any other Message is processed. This is
14
- * how a local intent turns into a durable fact that needs something only the intent's
15
- * transition knows, such as an id minted from local state, without a later Message
16
- * seeing the Model before the fact. Elsewhere, or once a parent has mapped the Command,
17
- * it is an ordinary Command that yields `message`, and so is one a durable Message's
18
- * update returns: replay would not apply it, and with derived replay the durable Message's
19
- * persist fails with `ReplayError` as for any Command.
20
- */
21
- export declare const fact: <Message>(message: Message) => {
22
- readonly name: string;
23
- readonly effect: Effect.Effect<Message>;
24
- };
25
- /**
26
- * The URL as part of the application: `onUrlChange` names the Message the
27
- * runtime sends for the current URL at start and on every navigation (so a
28
- * `foldkit-mirror` URL mirror reads back in), `init` reduces the URL into the
29
- * Model before the first render, and `onUrlRequest` names the Message for a
30
- * link click; omitted, the mount follows the link itself (an internal one is
31
- * pushed, an external one loaded).
32
- */
33
- interface MountUrl<Model, Message> {
34
- readonly init?: ((model: Model, url: Url.Url) => Model) | undefined;
35
- readonly onUrlChange: (url: Url.Url) => Message;
36
- readonly onUrlRequest?: ((request: UrlRequest) => Message) | undefined;
37
- }
38
- interface MountOptions<Model, Message, Shared, Resources> {
39
- /** An open replica of this contract; `mount` does not close it. */
40
- readonly replica: Replica<Message, Shared>;
41
- /** The element the application renders into; Foldkit requires it to have an `id`. */
42
- readonly container: HTMLElement;
43
- readonly view: (model: Model, h: HtmlBuilder<Message>) => Document;
44
- readonly subscriptions?: Subscriptions<Model, Message, Resources> | undefined;
45
- readonly resources?: Layer.Layer<Resources> | undefined;
46
- /** Route the URL through the application; without it the mount ignores the URL. */
47
- readonly url?: MountUrl<Model, Message> | undefined;
48
- /**
49
- * Reflects a refused or failed persist in the Model, after the durable edit
50
- * has been reverted. Omitted, the edit is reverted silently.
51
- */
52
- readonly onPersistenceFailure?: ((model: Model, error: ReplicaError) => Model) | undefined;
53
- /**
54
- * Runs when the mount replaces the shared slice outside `update`: an exchange committed,
55
- * acknowledged or rejected something, or a persist failed and its edit was reverted.
56
- * `previous` is the Model before; what it returns is the transition, so an application
57
- * can carry local state across the change (a selection held by what it points at) or
58
- * return Commands (a DOM the change has to reach). Omitted, the Model is `next`. It is
59
- * not called for a status that changes nothing the Model shows, such as the first.
60
- */
61
- readonly onReinstall?: ((next: Model, previous: Model, change: Reinstall) => Update.Return<Model, Message, Resources>) | undefined;
62
- /**
63
- * Runs on the Model after every update of the mounted application, a durable
64
- * Message's and a reinstall's included, and never in replay: for local state
65
- * derived from the shared slice, which a durable transition may not write
66
- * (the overlays `foldkit-sync/remote` keeps in Remote). With nothing to
67
- * change it returns the Model it was given.
68
- */
69
- readonly afterUpdate?: ((model: Model) => Update.Return<Model, Message, Resources>) | undefined;
70
- }
71
- /**
72
- * What a reinstall came from. `reset` is a server reset: the replica's
73
- * committed history is a new one, so anything an application derived from
74
- * the old one (reads cached by commit sequence, say) is to be read again.
75
- */
76
- interface Reinstall {
77
- readonly reset: boolean;
78
- }
79
- /**
80
- * The shared slice as the server has confirmed it, outside the Model. It is a
81
- * source for waiting consumers, the shape `Agent.when({ source })` reads, and
82
- * not a Projection: it does not render and is not derived from the Model.
83
- */
84
- interface CommittedView<Shared> {
85
- readonly get: () => Shared;
86
- /** Told after every exchange, including one that moves no cursor (a checkpoint). */
87
- readonly subscribe: (listener: () => void) => () => void;
88
- }
89
- interface Mounted<Model, Message, Shared = unknown> {
90
- /** Sends an application Message through the runtime; the `Exit` reports a decode failure. */
91
- readonly dispatch: (message: Message) => Exit.Exit<void, unknown>;
92
- /** The Model after the last transition. */
93
- readonly model: () => Model;
94
- /** Notified after every transition; with `model` and `dispatch`, the host an agent binds to. */
95
- readonly subscribe: (listener: () => void) => () => void;
96
- /**
97
- * Every application Message the runtime applies, from any origin, so an
98
- * agent contract that declares a `completion` can see the Message that
99
- * finishes its work. The mount's private Messages are not reported.
100
- */
101
- readonly observe: (listener: (message: Message) => void) => () => void;
102
- /**
103
- * The shared slice without pending local edits, for an agent that must not
104
- * report an optimistic edit as done: `Agent.when({ source: mounted.committed, … })`.
105
- */
106
- readonly committed: CommittedView<Shared>;
107
- /**
108
- * Resolves once the Model has caught up with the replica: no persist in
109
- * flight or unanswered, every replica status the mount was told of seen,
110
- * and every reinstall it asked for applied. It observes and never does the
111
- * work. Frames are not its to wait for (`Frames.track` in
112
- * `foldkit-mixins/testing` is), nor I/O a Command started. Rejects after
113
- * `dispose`.
114
- */
115
- readonly settled: () => Promise<void>;
116
- /** Waits for in-flight persists, then disposes the runtime. The replica stays open. */
117
- readonly dispose: () => Promise<void>;
118
- }
119
- /** The application's Message union, as `Surface.application` types it. */
120
- type MessageOf<App> = App extends RunnableApplication<any, any, any, any> ? Schema$1.Schema.Type<App['Message']> : never;
121
- export declare const mount: <Model, F extends Schema$1.Struct.Fields, Cases extends Record<string, Schema$1.Struct.Fields>, Fields extends Schema$1.Struct.Fields, Ms extends readonly unknown[], Resources = never, Principal = unknown>(app: RunnableApplication<Model, F, Cases, Resources>, sync: DefinedSync<Model, Fields, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Ms, Principal>, options: MountOptions<Model, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Schema$1.Struct.Type<Fields>, Resources>) => Mounted<Model, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Schema$1.Struct.Type<Fields>>;
122
- //#endregion
123
9
  //#region src/presence.d.ts
124
10
  /** One peer's presence. A `null` value means the peer left. */
125
11
  interface PresenceUpdate<Update> {
@@ -237,15 +123,15 @@ export declare const servePresence: <Update>(socket: SocketLike, hub: PresenceHu
237
123
  //#endregion
238
124
  //#region src/lww.d.ts
239
125
  /** A logical write time; replica ids break concurrent ties using UTF-16 order. */
240
- declare const Stamp: Schema$1.Struct<{
241
- readonly counter: Schema$1.Number;
242
- readonly replicaId: Schema$1.brand<Schema$1.NonEmptyString, "@foldkit-sync/ReplicaId">;
126
+ declare const Stamp: Schema.Struct<{
127
+ readonly counter: Schema.Number;
128
+ readonly replicaId: Schema.brand<Schema.NonEmptyString, "@foldkit-sync/ReplicaId">;
243
129
  }>;
244
- declare const ClockState: Schema$1.Struct<{
245
- readonly schemaVersion: Schema$1.Literal<1>;
246
- readonly documentId: Schema$1.brand<Schema$1.NonEmptyString, "@foldkit-sync/DocumentId">;
247
- readonly replicaId: Schema$1.brand<Schema$1.NonEmptyString, "@foldkit-sync/ReplicaId">;
248
- readonly revision: Schema$1.Number;
130
+ declare const ClockState: Schema.Struct<{
131
+ readonly schemaVersion: Schema.Literal<1>;
132
+ readonly documentId: Schema.brand<Schema.NonEmptyString, "@foldkit-sync/DocumentId">;
133
+ readonly replicaId: Schema.brand<Schema.NonEmptyString, "@foldkit-sync/ReplicaId">;
134
+ readonly revision: Schema.Number;
249
135
  }>;
250
136
  type LwwClockState = typeof ClockState.Type;
251
137
  interface LwwClock {
@@ -278,13 +164,13 @@ export declare const openLwwClock: (options: {
278
164
  * Allocate a unique stamp per write before dispatch, and retain it in the Message.
279
165
  * Merge is for decoded values; the application's schema validates wire input.
280
166
  */
281
- export declare const lwwRegister: <Value, Encoded, RD, RE>(value: Schema$1.Codec<Value, Encoded, RD, RE>) => {
282
- schema: Schema$1.Struct<{
283
- readonly stamp: Schema$1.Struct<{
284
- readonly counter: Schema$1.Number;
285
- readonly replicaId: Schema$1.brand<Schema$1.NonEmptyString, "@foldkit-sync/ReplicaId">;
167
+ export declare const lwwRegister: <Value, Encoded, RD, RE>(value: Schema.Codec<Value, Encoded, RD, RE>) => {
168
+ schema: Schema.Struct<{
169
+ readonly stamp: Schema.Struct<{
170
+ readonly counter: Schema.Number;
171
+ readonly replicaId: Schema.brand<Schema.NonEmptyString, "@foldkit-sync/ReplicaId">;
286
172
  }>;
287
- readonly value: Schema$1.Codec<Value, Encoded, RD, RE>;
173
+ readonly value: Schema.Codec<Value, Encoded, RD, RE>;
288
174
  }>;
289
175
  merge: (left: {
290
176
  readonly stamp: {
@@ -307,6 +193,120 @@ export declare const lwwRegister: <Value, Encoded, RD, RE>(value: Schema$1.Codec
307
193
  };
308
194
  };
309
195
  //#endregion
196
+ //#region src/mount.d.ts
197
+ /**
198
+ * A Command that dispatches `message` as the next transition, which under `Sync.mount`
199
+ * means within this one: the mount applies it straight after the `update` that returned
200
+ * it, and persists it if it is durable, before any other Message is processed. This is
201
+ * how a local intent turns into a durable fact that needs something only the intent's
202
+ * transition knows, such as an id minted from local state, without a later Message
203
+ * seeing the Model before the fact. Elsewhere, or once a parent has mapped the Command,
204
+ * it is an ordinary Command that yields `message`, and so is one a durable Message's
205
+ * update returns: replay would not apply it, and with derived replay the durable Message's
206
+ * persist fails with `ReplayError` as for any Command.
207
+ */
208
+ export declare const fact: <Message>(message: Message) => {
209
+ readonly name: string;
210
+ readonly effect: Effect.Effect<Message>;
211
+ };
212
+ /**
213
+ * The URL as part of the application: `onUrlChange` names the Message the
214
+ * runtime sends for the current URL at start and on every navigation (so a
215
+ * `foldkit-mirror` URL mirror reads back in), `init` reduces the URL into the
216
+ * Model before the first render, and `onUrlRequest` names the Message for a
217
+ * link click; omitted, the mount follows the link itself (an internal one is
218
+ * pushed, an external one loaded).
219
+ */
220
+ interface MountUrl<Model, Message> {
221
+ readonly init?: ((model: Model, url: Url.Url) => Model) | undefined;
222
+ readonly onUrlChange: (url: Url.Url) => Message;
223
+ readonly onUrlRequest?: ((request: UrlRequest) => Message) | undefined;
224
+ }
225
+ interface MountOptions<Model, Message, Shared, Resources> {
226
+ /** An open replica of this contract; `mount` does not close it. */
227
+ readonly replica: Replica<Message, Shared>;
228
+ /** The element the application renders into; Foldkit requires it to have an `id`. */
229
+ readonly container: HTMLElement;
230
+ readonly view: (model: Model, h: HtmlBuilder<Message>) => Document;
231
+ readonly subscriptions?: Subscriptions<Model, Message, Resources> | undefined;
232
+ readonly resources?: Layer.Layer<Resources> | undefined;
233
+ /** Route the URL through the application; without it the mount ignores the URL. */
234
+ readonly url?: MountUrl<Model, Message> | undefined;
235
+ /**
236
+ * Reflects a refused or failed persist in the Model, after the durable edit
237
+ * has been reverted. Omitted, the edit is reverted silently.
238
+ */
239
+ readonly onPersistenceFailure?: ((model: Model, error: ReplicaError) => Model) | undefined;
240
+ /**
241
+ * Runs when the mount replaces the shared slice outside `update`: an exchange committed,
242
+ * acknowledged or rejected something, or a persist failed and its edit was reverted.
243
+ * `previous` is the Model before; what it returns is the transition, so an application
244
+ * can carry local state across the change (a selection held by what it points at) or
245
+ * return Commands (a DOM the change has to reach). Omitted, the Model is `next`. It is
246
+ * not called for a status that changes nothing the Model shows, such as the first.
247
+ */
248
+ readonly onReinstall?: ((next: Model, previous: Model, change: Reinstall) => Update.Return<Model, Message, Resources>) | undefined;
249
+ /**
250
+ * Runs on the Model after every update of the mounted application, a durable
251
+ * Message's and a reinstall's included, and never in replay: for local state
252
+ * derived from the shared slice, which a durable transition may not write
253
+ * (the overlays `foldkit-sync/remote` keeps in Remote). With nothing to
254
+ * change it returns the Model it was given.
255
+ */
256
+ readonly afterUpdate?: ((model: Model) => Update.Return<Model, Message, Resources>) | undefined;
257
+ }
258
+ /**
259
+ * What a reinstall came from. `reset` is a server reset: the replica's
260
+ * committed history is a new one, so anything an application derived from
261
+ * the old one (reads cached by commit sequence, say) is to be read again.
262
+ */
263
+ interface Reinstall {
264
+ readonly reset: boolean;
265
+ }
266
+ /**
267
+ * The shared slice as the server has confirmed it, outside the Model. It is a
268
+ * source for waiting consumers, the shape `Agent.when({ source })` reads, and
269
+ * not a Projection: it does not render and is not derived from the Model.
270
+ */
271
+ interface CommittedView<Shared> {
272
+ readonly get: () => Shared;
273
+ /** Told after every exchange, including one that moves no cursor (a checkpoint). */
274
+ readonly subscribe: (listener: () => void) => () => void;
275
+ }
276
+ interface Mounted<Model, Message, Shared = unknown> {
277
+ /** Sends an application Message through the runtime; the `Exit` reports a decode failure. */
278
+ readonly dispatch: (message: Message) => Exit.Exit<void, unknown>;
279
+ /** The Model after the last transition. */
280
+ readonly model: () => Model;
281
+ /** Notified after every transition; with `model` and `dispatch`, the host an agent binds to. */
282
+ readonly subscribe: (listener: () => void) => () => void;
283
+ /**
284
+ * Every application Message the runtime applies, from any origin, so an
285
+ * agent contract that declares a `completion` can see the Message that
286
+ * finishes its work. The mount's private Messages are not reported.
287
+ */
288
+ readonly observe: (listener: (message: Message) => void) => () => void;
289
+ /**
290
+ * The shared slice without pending local edits, for an agent that must not
291
+ * report an optimistic edit as done: `Agent.when({ source: mounted.committed, … })`.
292
+ */
293
+ readonly committed: CommittedView<Shared>;
294
+ /**
295
+ * Resolves once the Model has caught up with the replica: no persist in
296
+ * flight or unanswered, every replica status the mount was told of seen,
297
+ * and every reinstall it asked for applied. It observes and never does the
298
+ * work. Frames are not its to wait for (`Frames.track` in
299
+ * `foldkit-mixins/testing` is), nor I/O a Command started. Rejects after
300
+ * `dispose`.
301
+ */
302
+ readonly settled: () => Promise<void>;
303
+ /** Waits for in-flight persists, then disposes the runtime. The replica stays open. */
304
+ readonly dispose: () => Promise<void>;
305
+ }
306
+ /** The application's Message union, as `Surface.application` types it. */
307
+ type MessageOf<App> = App extends RunnableApplication<any, any, any, any> ? Schema.Schema.Type<App['Message']> : never;
308
+ export declare const mount: <Model, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>, Fields extends Schema.Struct.Fields, Ms extends readonly unknown[], Resources = never, Principal = unknown>(app: RunnableApplication<Model, F, Cases, Resources>, sync: DefinedSync<Model, Fields, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Ms, Principal>, options: MountOptions<Model, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Schema.Struct.Type<Fields>, Resources>) => Mounted<Model, MessageOf<RunnableApplication<Model, F, Cases, Resources>>, Schema.Struct.Type<Fields>>;
309
+ //#endregion
310
310
  //#region src/index.d.ts
311
311
  /**
312
312
  * The contract `Sync.define` and `Sync.forApplication(App).make` produce: the
@@ -319,16 +319,13 @@ export type Sync<Message, Shared> = Sync$1<Message, Shared>;
319
319
  /** The package's public surface, grouped. Each entry is the exported function itself. */
320
320
  export declare const Sync: {
321
321
  /** Derives a sync contract from a Foldkit application: `Sync.forApplication(App).make({…})`. */
322
- forApplication: <AppModel, F extends import("effect/Schema").Struct.Fields, Cases extends Record<string, import("effect/Schema").Struct.Fields>>(app: import("foldkit-surface").RunnableApplication<AppModel, F, Cases, any>) => ApplicationSync<AppModel, F, Cases>;
322
+ forApplication: typeof forApplication;
323
323
  /** The protocol primitive, for a client with no Foldkit application to derive from. */
324
- define: <Message, Shared, MessageEncoded, SharedEncoded>(definition: SyncDefinition<Message, Shared, MessageEncoded, SharedEncoded>) => Sync$1<Message, Shared>;
324
+ define: typeof defineSync;
325
325
  /** Runs a Foldkit application over an open replica with one reducer. */
326
- mount: <Model, F extends import("effect/Schema").Struct.Fields, Cases extends Record<string, import("effect/Schema").Struct.Fields>, Fields extends import("effect/Schema").Struct.Fields, Ms extends readonly unknown[], Resources = never, Principal = unknown>(app: import("foldkit-surface").RunnableApplication<Model, F, Cases, Resources>, sync: DefinedSync<Model, Fields, import("effect/Schema").Schema.Type<import("foldkit/message").MessageUnion<Cases>>, Ms, Principal>, options: MountOptions<Model, import("effect/Schema").Schema.Type<import("foldkit/message").MessageUnion<Cases>>, import("effect/Schema").Struct.Type<Fields>, Resources>) => Mounted<Model, import("effect/Schema").Schema.Type<import("foldkit/message").MessageUnion<Cases>>, import("effect/Schema").Struct.Type<Fields>>;
326
+ mount: typeof mount;
327
327
  /** A Command whose Message the mount applies within the transition that returned it. */
328
- fact: <Message>(message: Message) => {
329
- readonly name: string;
330
- readonly effect: import("effect/Effect").Effect<Message>;
331
- };
328
+ fact: typeof fact;
332
329
  /** Counters and a histogram an application can scrape. */
333
330
  metrics: {
334
331
  exchanges: import("effect/Metric").Counter<number>;
@@ -341,26 +338,21 @@ export declare const Sync: {
341
338
  /** The `Transport` service's layers, and the bridges to and from a promise client. */
342
339
  transport: {
343
340
  /** A reconnecting WebSocket client layer. */
344
- socket: (options: SocketOptions) => import("effect/Layer").Layer<Transport, TransportError>;
341
+ socket: typeof layerSocket;
345
342
  /** An in-process layer, for tests and single-process demos. */
346
- loopback: (handler: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>) => import("effect/Layer").Layer<Transport>;
343
+ loopback: typeof layerLoopback;
347
344
  /** Wraps the promise-based client the replica already speaks. */
348
- fromPromise: (transport: TransportClient) => import("effect/Layer").Layer<Transport>;
345
+ fromPromise: typeof layerFromPromise;
349
346
  /** Bridges the service back to that promise client. */
350
- toPromise: (transport: TransportShape) => TransportClient;
347
+ toPromise: typeof toPromise;
351
348
  /** The server side of one accepted socket connection. */
352
- serve: (socket: SocketLike, options: {
353
- readonly exchange: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>;
354
- readonly changes?: ((listener: () => void) => () => void) | undefined;
355
- }) => (() => void);
349
+ serve: typeof serveSocket;
356
350
  /** The accepted end of a Cloudflare `WebSocketPair`, for `serve`. */
357
- workerSocket: (socket: WebSocket) => SocketLike;
351
+ workerSocket: typeof workerSocket;
358
352
  /** The default socket factory: the platform `WebSocket`. */
359
- nativeSocket: (url: string) => SocketLike;
353
+ nativeSocket: typeof nativeSocket;
360
354
  /** A socket over a `MessagePort`, closed by `close()` or an abort signal. */
361
- portSocket: (port: MessagePort, options?: {
362
- readonly signal?: AbortSignal | undefined;
363
- }) => SocketLike;
355
+ portSocket: typeof portSocket;
364
356
  };
365
357
  /** An ephemeral, TTL'd peer registry, deliberately outside the durable log. */
366
358
  presence: {
@@ -382,13 +374,10 @@ export declare const Sync: {
382
374
  close: import("effect/Effect").Effect<void, never, never>;
383
375
  }, never, import("effect/Scope").Scope>;
384
376
  /** Broadcasts presence updates among connected peers, on the server. */
385
- hub: <Update>() => PresenceHub<Update>;
377
+ hub: typeof createPresenceHub;
386
378
  /** Serves presence frames on an accepted socket, stamping the connection's identity. */
387
- serve: <Update>(socket: SocketLike, hub: PresenceHub<Update>, options: {
388
- readonly peerId: string;
389
- readonly opens?: import("effect/Effect").Effect<boolean, unknown> | undefined;
390
- }) => (() => void);
391
- socketChannel: <Update>(socket: SocketLike) => import("effect/Effect").Effect<PresenceChannel<Update>, never, import("effect/Scope").Scope>;
379
+ serve: typeof servePresence;
380
+ socketChannel: typeof socketPresenceChannel;
392
381
  loopbackChannel: <Update>() => import("effect/Effect").Effect<{
393
382
  updates: import("effect/PubSub").PubSub<PresenceUpdate<Update>>;
394
383
  publish: (update: PresenceUpdate<Update>) => import("effect/Effect").Effect<boolean, never, never>;
@@ -396,34 +385,7 @@ export declare const Sync: {
396
385
  };
397
386
  /** Last-writer-wins registers (experimental): a per-field merge on logical time. */
398
387
  lww: {
399
- register: <Value, Encoded, RD, RE>(value: import("effect/Schema").Codec<Value, Encoded, RD, RE>) => {
400
- schema: import("effect/Schema").Struct<{
401
- readonly stamp: import("effect/Schema").Struct<{
402
- readonly counter: import("effect/Schema").Number;
403
- readonly replicaId: import("effect/Schema").brand<import("effect/Schema").NonEmptyString, "@foldkit-sync/ReplicaId">;
404
- }>;
405
- readonly value: import("effect/Schema").Codec<Value, Encoded, RD, RE>;
406
- }>;
407
- merge: (left: {
408
- readonly stamp: {
409
- readonly counter: number;
410
- readonly replicaId: string & import("effect/Brand").Brand<"@foldkit-sync/ReplicaId">;
411
- };
412
- readonly value: Value;
413
- }, right: {
414
- readonly stamp: {
415
- readonly counter: number;
416
- readonly replicaId: string & import("effect/Brand").Brand<"@foldkit-sync/ReplicaId">;
417
- };
418
- readonly value: Value;
419
- }) => {
420
- readonly stamp: {
421
- readonly counter: number;
422
- readonly replicaId: string & import("effect/Brand").Brand<"@foldkit-sync/ReplicaId">;
423
- };
424
- readonly value: Value;
425
- };
426
- };
388
+ register: typeof lwwRegister;
427
389
  /** The durable counter a stamp is allocated from, before dispatch. */
428
390
  openClock: (options: {
429
391
  readonly documentId: DocumentId;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/mount.ts","../src/presence.ts","../src/lww.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;qBAqEa,OAAQ,SACnB,SAAS;WACG;WAAuB,QAAQ,OAAO,OAAO;;;;;;;;;;UAqB1C,SAAS,OAAO;WACtB,SAAS,OAAO,OAAO,KAAK,IAAI,QAAQ;WACxC,cAAc,KAAK,IAAI,QAAQ;WAC/B,iBAAiB,SAAS,eAAe;;UAGnC,aAAa,OAAO,SAAS,QAAQ;;WAE3C,SAAS,QAAQ,SAAS;;WAE1B,WAAW;WACX,OAAO,OAAO,OAAO,GAAG,YAAY,aA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AAC;UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;eAAk7I,gCAAC"}
1
+ {"version":3,"file":"index.d.mts","names":["SyncContract","_$__indexedDb_js0.Storage","_$__errors_js0.StorageError","_$__presence_js0.PresenceOptions","_$__presence_js0.PresenceUpdate","_$__ids_js0.DocumentId","_$__ids_js0.ReplicaId","_$__errors_js0.UnsupportedClockVersionError"],"sources":["../src/presence.ts","../src/lww.ts","../src/mount.ts","../src/index.ts"],"mappings":";;;;;;;;;;UAciB,eAAe;WACrB;WACA,OAAO;;;;;;;;;;UAWD,gBAAgB;WACtB,SAAS,OAAO,OAAO,eAAe;WACtC,UAAU,QAAQ,eAAe,YAAY,OAAO;;UAG9C,gBAAgB;;WAEtB;;WAEA,KAAK,SAAS;;;;;;WAMd,cAAc,mBAAmB;WACjC,UAAU,gBAAgB;;;;;;WAM1B,WAAW,SAAS;;UAGd,aAAa;WACnB;WACA,OAAO;WACP;;UAGM,SAAS;;WAEf,MAAM,OAAO,WAAW,OAAO;;WAE/B,OAAO,OAAO;;WAEd,OAAO,OAAO,OAAO,cAAc,aAAa;;WAEhD,OAAO,OAAO;;WAEd,YAAY;;;;;WAKZ,SAAS,OAAO,OAAO,cAAc,aAAa;;WAElD,OAAO,OAAO;;;;;;;;;qBAUZ,iBAAyD,QAAM,SAAA,gBAAA,YAAA,OAAA;;;;IAhC7D;;IAEO;;;EAuMI,YAAA;;;;;;;UAUxB,MAAA;;qBAGW,0BAA2E,aAAM,OAAA;;EAIxE,UAAA,QAAA,eAAe,YAAO,OAAA;;;UAK3B,YAAY;;EAE3B,KAAK,OAAO,QAAQ,eAAe;;EAEnC,QAAQ,QAAQ,eAAe;;qBAGpB,oBAAqB,aAAW,YAAY;;;;;qBA8C5C,wBAAyB,QAAM,QAClC,eACP,OAAO,OAAO,gBAAgB,gBAAgB,MAAM;;;;;;;;qBA4B1C,gBAAiB,QAAM,QAC1B,YAAU,KACb,YAAY,SAAO;WAEb;WACA,QAAQ,OAAO;;;;;c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QACX,OACA,UAAU,OAAO,OAAO,QACxB,cAAc,eAAe,OAAO,OAAO,SAC3C,eAAe,OAAO,OAAO,QAC7B,+BACA,mBACA,qBAAmB,KAEd,oBAAoB,OAAO,GAAG,OAAO,YAAU,MAC9C,YACJ,OACA,QACA,UAAU,oBAAoB,OAAO,GAAG,OAAO,aAC/C,IACA,YACD,SACQ,aACP,OACA,UAAU,oBAAoB,OAAO,GAAG,OAAO,aAC/C,OAAO,OAAO,KAAK,SACnB,eAED,QACD,OACA,UAAU,oBAAoB,OAAO,GAAG,OAAO,aAC/C,OAAO,OAAO,KAAK;;;;;;;;;;YCjNT,KAAK,SAAS,UAAUA,OAAa,SAAS;;qBAG7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoCT,OAAI,QAAA,SAAAG,gBAAA,oCAAA;;;;;;;;;;;;;;;;;;IAEJ,YAAG;;IAEH,cAAK;IACL,sBAAa;IACb,kBAAe,qCAAA;;;;;;;IAKf,iBAAQ;;IAER,YAAS;2BAFDE"}
package/dist/index.mjs CHANGED
@@ -1010,6 +1010,12 @@ const mount = (app, sync, options) => {
1010
1010
  const { replica } = options;
1011
1011
  const durable = new Set(sync.contract.messages);
1012
1012
  const edits = [];
1013
+ const holdUnload = (event) => event.preventDefault();
1014
+ const unloadGuarded = (guarded) => {
1015
+ if (typeof window === "undefined") return;
1016
+ if (guarded) window.addEventListener("beforeunload", holdUnload);
1017
+ else window.removeEventListener("beforeunload", holdUnload);
1018
+ };
1013
1019
  let tail = Promise.resolve();
1014
1020
  let installedFrom;
1015
1021
  let editedSinceInstall = false;
@@ -1118,6 +1124,7 @@ const mount = (app, sync, options) => {
1118
1124
  started: void 0
1119
1125
  };
1120
1126
  edits.push(edit);
1127
+ if (edits.length === 1) unloadGuarded(true);
1121
1128
  const previous = tail;
1122
1129
  let settle;
1123
1130
  const done = new Promise((resolve) => {
@@ -1127,6 +1134,7 @@ const mount = (app, sync, options) => {
1127
1134
  const release = () => {
1128
1135
  const index = edits.indexOf(edit);
1129
1136
  if (index !== -1) edits.splice(index, 1);
1137
+ if (edits.length === 0) unloadGuarded(false);
1130
1138
  inFlight.delete(done);
1131
1139
  settle();
1132
1140
  };
@@ -1177,11 +1185,11 @@ const mount = (app, sync, options) => {
1177
1185
  };
1178
1186
  const ports = { inbound: { message: Port.inbound(app.Message) } };
1179
1187
  const own = Subscription.make()(() => ({
1180
- message: Port.subscription(ports.inbound.message, (message) => ({
1188
+ message: Port.subscriptionEntry(ports.inbound.message, (message) => ({
1181
1189
  _tag: DISPATCHED,
1182
1190
  message
1183
1191
  })),
1184
- refresh: Subscription.persistent(replica.statusChanges.pipe(Stream.tap(() => Effect.sync(notifyCommitted)), Stream.mapAccum(() => void 0, (previous, status) => [status, [{
1192
+ refresh: Subscription.persistentEntry(replica.statusChanges.pipe(Stream.tap(() => Effect.sync(notifyCommitted)), Stream.mapAccum(() => void 0, (previous, status) => [status, [{
1185
1193
  _tag: REFRESH,
1186
1194
  status,
1187
1195
  changed: sharedChanged(previous, status)