foldkit-sync 0.12.3 → 0.13.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/README.md +76 -24
- package/dist/diagnostics.d.ts +71 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +67 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/{do.d.mts → do.d.ts} +12 -2
- package/dist/do.d.ts.map +1 -0
- package/dist/{do.mjs → do.js} +15 -9
- package/dist/do.js.map +1 -0
- package/dist/{entity.d.mts → entity.d.ts} +1 -1
- package/dist/entity.d.ts.map +1 -0
- package/dist/{entity.mjs → entity.js} +1 -1
- package/dist/entity.js.map +1 -0
- package/dist/errors.d.ts +91 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +75 -0
- package/dist/errors.js.map +1 -0
- package/dist/ids.d.ts +30 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +28 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/indexedDb.d.ts +62 -0
- package/dist/indexedDb.d.ts.map +1 -0
- package/dist/indexedDb.js +128 -0
- package/dist/indexedDb.js.map +1 -0
- package/dist/{journal.d.mts → journal.d.ts} +29 -5
- package/dist/journal.d.ts.map +1 -0
- package/dist/{journal-D5h-jqXE.mjs → journal.js} +43 -32
- package/dist/journal.js.map +1 -0
- package/dist/lww.d.ts +76 -0
- package/dist/lww.d.ts.map +1 -0
- package/dist/lww.js +121 -0
- package/dist/lww.js.map +1 -0
- package/dist/make.d.ts +162 -0
- package/dist/make.d.ts.map +1 -0
- package/dist/make.js +153 -0
- package/dist/make.js.map +1 -0
- package/dist/mount.d.ts +138 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +344 -0
- package/dist/mount.js.map +1 -0
- package/dist/presence.d.ts +116 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +277 -0
- package/dist/presence.js.map +1 -0
- package/dist/{remote.d.mts → remote.d.ts} +2 -2
- package/dist/remote.d.ts.map +1 -0
- package/dist/{remote.mjs → remote.js} +1 -1
- package/dist/remote.js.map +1 -0
- package/dist/revalidate.d.ts +6 -0
- package/dist/revalidate.d.ts.map +1 -0
- package/dist/revalidate.js +10 -0
- package/dist/revalidate.js.map +1 -0
- package/dist/sync.d.ts +276 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +512 -0
- package/dist/sync.js.map +1 -0
- package/dist/transport.d.ts +151 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/{transport-BZ6utYmB.mjs → transport.js} +20 -30
- package/dist/transport.js.map +1 -0
- package/package.json +24 -24
- package/dist/do.d.mts.map +0 -1
- package/dist/do.mjs.map +0 -1
- package/dist/entity.d.mts.map +0 -1
- package/dist/entity.mjs.map +0 -1
- package/dist/index.d.mts +0 -397
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -1613
- package/dist/index.mjs.map +0 -1
- package/dist/journal-D5h-jqXE.mjs.map +0 -1
- package/dist/journal.d.mts.map +0 -1
- package/dist/journal.mjs +0 -1
- package/dist/make-DJ0Q1SSc.d.mts +0 -702
- package/dist/make-DJ0Q1SSc.d.mts.map +0 -1
- package/dist/remote.d.mts.map +0 -1
- package/dist/remote.mjs.map +0 -1
- package/dist/transport-BZ6utYmB.mjs.map +0 -1
package/dist/mount.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { Effect, Exit, Option, Schema, Stream } from "effect";
|
|
2
|
+
import { absurd } from "effect/Function";
|
|
3
|
+
import * as Navigation from "foldkit/navigation";
|
|
4
|
+
import * as Port from "foldkit/port";
|
|
5
|
+
import * as Runtime from "foldkit/runtime";
|
|
6
|
+
import * as Subscription from "foldkit/subscription";
|
|
7
|
+
import * as Url from "foldkit/url";
|
|
8
|
+
// src/mount.ts
|
|
9
|
+
/**
|
|
10
|
+
* `Sync.mount`: runs a Foldkit application over a replica with one reducer.
|
|
11
|
+
*
|
|
12
|
+
* A durable Message is a state-only, deterministic transition of the shared
|
|
13
|
+
* projection (the derived replay enforces it), so the application's own `update`
|
|
14
|
+
* is applied at once and the Message is persisted afterwards in a Command. The
|
|
15
|
+
* shared slice is re-installed from the replica when an exchange changes it or
|
|
16
|
+
* a persist fails, through one private Message the application never sees.
|
|
17
|
+
*/
|
|
18
|
+
const REFRESH = "foldkit-sync/Refresh";
|
|
19
|
+
const PERSISTED = "foldkit-sync/Persisted";
|
|
20
|
+
const FAILED = "foldkit-sync/PersistenceFailed";
|
|
21
|
+
const NAVIGATE = "foldkit-sync/Navigate";
|
|
22
|
+
const NAVIGATED = "foldkit-sync/Navigated";
|
|
23
|
+
const DISPATCHED = "foldkit-sync/Dispatched";
|
|
24
|
+
const PRIVATE = {
|
|
25
|
+
[REFRESH]: true,
|
|
26
|
+
[PERSISTED]: true,
|
|
27
|
+
[FAILED]: true,
|
|
28
|
+
[NAVIGATE]: true,
|
|
29
|
+
[NAVIGATED]: true,
|
|
30
|
+
[DISPATCHED]: true
|
|
31
|
+
};
|
|
32
|
+
const isPrivate = (message) => Object.hasOwn(PRIVATE, message._tag);
|
|
33
|
+
const FACT = Symbol.for("foldkit-sync/fact");
|
|
34
|
+
/**
|
|
35
|
+
* A Command that dispatches `message` as the next transition, which under `Sync.mount`
|
|
36
|
+
* means within this one: the mount applies it straight after the `update` that returned
|
|
37
|
+
* it, and persists it if it is durable, before any other Message is processed. This is
|
|
38
|
+
* how a local intent turns into a durable fact that needs something only the intent's
|
|
39
|
+
* transition knows, such as an id minted from local state, without a later Message
|
|
40
|
+
* seeing the Model before the fact. Elsewhere, or once a parent has mapped the Command,
|
|
41
|
+
* it is an ordinary Command that yields `message`, and so is one a durable Message's
|
|
42
|
+
* update returns: replay would not apply it, and with derived replay the durable Message's
|
|
43
|
+
* persist fails with `ReplayError` as for any Command.
|
|
44
|
+
*/
|
|
45
|
+
const fact = (message) => Object.defineProperty({
|
|
46
|
+
name: "foldkit-sync/fact",
|
|
47
|
+
effect: Effect.succeed(message)
|
|
48
|
+
}, FACT, {
|
|
49
|
+
value: message,
|
|
50
|
+
enumerable: false
|
|
51
|
+
});
|
|
52
|
+
const factOf = (command) => typeof command === "object" && command !== null && FACT in command ? { message: command[FACT] } : void 0;
|
|
53
|
+
/**
|
|
54
|
+
* Commits, rejections and acknowledgments change what the replica holds; a
|
|
55
|
+
* submit only echoes a local edit. An acknowledgment that does not return the
|
|
56
|
+
* operation moves no cursor, but it still drops the edit from the outbox.
|
|
57
|
+
*/
|
|
58
|
+
const sharedChanged = (previous, next) => previous === void 0 || previous.cursor !== next.cursor || next.pending < previous.pending || previous.rejected.length !== next.rejected.length || previous.rejected.some((rejection, index) => rejection.opId !== next.rejected[index]?.opId);
|
|
59
|
+
/**
|
|
60
|
+
* The edits a replica whose next local sequence is `next` does not hold yet.
|
|
61
|
+
* Submits run one at a time, so the one in flight is in the replica exactly
|
|
62
|
+
* when its submit has moved the sequence past `started`.
|
|
63
|
+
*/
|
|
64
|
+
const unconfirmedEdits = (edits, next) => edits.filter((edit) => edit.started === void 0 || next <= edit.started).map((edit) => edit.message);
|
|
65
|
+
const mount = (app, sync, options) => {
|
|
66
|
+
if (options.container.id === "") throw new Error("Sync.mount: the container needs an id (`container.id = \"app\"`)");
|
|
67
|
+
const { replica } = options;
|
|
68
|
+
const durable = new Set(sync.contract.messages);
|
|
69
|
+
const edits = [];
|
|
70
|
+
const holdUnload = (event) => event.preventDefault();
|
|
71
|
+
const unloadGuarded = (guarded) => {
|
|
72
|
+
if (typeof window === "undefined") return;
|
|
73
|
+
if (guarded) window.addEventListener("beforeunload", holdUnload);
|
|
74
|
+
else window.removeEventListener("beforeunload", holdUnload);
|
|
75
|
+
};
|
|
76
|
+
let tail = Promise.resolve();
|
|
77
|
+
let installedFrom;
|
|
78
|
+
let editedSinceInstall = false;
|
|
79
|
+
const install = (model) => {
|
|
80
|
+
const snapshot = Effect.runSync(replica.snapshot);
|
|
81
|
+
installedFrom = snapshot.shared;
|
|
82
|
+
const unconfirmed = unconfirmedEdits(edits, snapshot.nextLocalSequence);
|
|
83
|
+
editedSinceInstall = unconfirmed.length > 0;
|
|
84
|
+
const shared = unconfirmed.reduce((value, message) => {
|
|
85
|
+
try {
|
|
86
|
+
return sync.replay(value, message);
|
|
87
|
+
} catch {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
}, snapshot.shared);
|
|
91
|
+
return sync.projection.set(model, shared);
|
|
92
|
+
};
|
|
93
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
94
|
+
let dispatchesOwed = 0;
|
|
95
|
+
let persistsOwed = 0;
|
|
96
|
+
let applied;
|
|
97
|
+
let disposed = false;
|
|
98
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
99
|
+
const quiet = () => dispatchesOwed === 0 && persistsOwed === 0 && !sharedChanged(applied, Effect.runSync(replica.status));
|
|
100
|
+
const notifySettled = () => {
|
|
101
|
+
if (!quiet()) return;
|
|
102
|
+
for (const waiter of [...waiters]) {
|
|
103
|
+
waiters.delete(waiter);
|
|
104
|
+
waiter.resolve();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* A private transition that leaves the Model as it was: the runtime sends
|
|
109
|
+
* no Subscription the change, so `settled` is told here, once it returns.
|
|
110
|
+
*/
|
|
111
|
+
const unchanged = (model) => {
|
|
112
|
+
queueMicrotask(notifySettled);
|
|
113
|
+
return { model };
|
|
114
|
+
};
|
|
115
|
+
let latest = install(app.initial);
|
|
116
|
+
const modelListeners = /* @__PURE__ */ new Set();
|
|
117
|
+
const committedListeners = /* @__PURE__ */ new Set();
|
|
118
|
+
const messageListeners = /* @__PURE__ */ new Set();
|
|
119
|
+
const notifyEach = (listeners, value) => {
|
|
120
|
+
for (const listener of [...listeners]) try {
|
|
121
|
+
listener(value);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
queueMicrotask(() => {
|
|
124
|
+
throw error;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const notifyCommitted = () => notifyEach(committedListeners, void 0);
|
|
129
|
+
const updatePrivate = (model, message) => {
|
|
130
|
+
switch (message._tag) {
|
|
131
|
+
case REFRESH: {
|
|
132
|
+
const reset = applied !== void 0 && Option.isSome(applied.epoch) && Option.isSome(message.status.epoch) && applied.epoch.value !== message.status.epoch.value;
|
|
133
|
+
applied = message.status;
|
|
134
|
+
if (!message.changed || !editedSinceInstall && Effect.runSync(replica.snapshot).shared === installedFrom) return unchanged(model);
|
|
135
|
+
return reinstalled(install(model), model, { reset });
|
|
136
|
+
}
|
|
137
|
+
case PERSISTED:
|
|
138
|
+
persistsOwed--;
|
|
139
|
+
return unchanged(model);
|
|
140
|
+
case FAILED: {
|
|
141
|
+
persistsOwed--;
|
|
142
|
+
const { error } = message;
|
|
143
|
+
const reverted = install(model);
|
|
144
|
+
return reinstalled(options.onPersistenceFailure?.(reverted, error) ?? reverted, model, { reset: false });
|
|
145
|
+
}
|
|
146
|
+
case NAVIGATE: {
|
|
147
|
+
const { request } = message;
|
|
148
|
+
return {
|
|
149
|
+
model,
|
|
150
|
+
commands: [{
|
|
151
|
+
name: "foldkit-sync/navigate",
|
|
152
|
+
effect: (request._tag === "Internal" ? Navigation.pushUrl(Url.toString(request.url)) : Navigation.load(request.href)).pipe(Effect.as({ _tag: NAVIGATED }))
|
|
153
|
+
}]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case NAVIGATED: return { model };
|
|
157
|
+
case DISPATCHED:
|
|
158
|
+
dispatchesOwed--;
|
|
159
|
+
return transition(model, message.message);
|
|
160
|
+
default: return absurd(message);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const update = (model, message) => {
|
|
164
|
+
const result = isPrivate(message) ? updatePrivate(model, message) : transition(model, message);
|
|
165
|
+
if (options.afterUpdate === void 0) return result;
|
|
166
|
+
const after = applyFacts(options.afterUpdate(result.model));
|
|
167
|
+
return after.model === result.model && (after.commands ?? []).length === 0 ? result : {
|
|
168
|
+
model: after.model,
|
|
169
|
+
commands: [...result.commands ?? [], ...after.commands ?? []]
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
const reinstalled = (next, previous, change) => options.onReinstall === void 0 ? { model: next } : applyFacts(options.onReinstall(next, previous, change));
|
|
173
|
+
/** The application's transition for one of its Messages, with the persist a durable one needs. */
|
|
174
|
+
const step = (model, message) => {
|
|
175
|
+
notifyEach(messageListeners, message);
|
|
176
|
+
const result = app.update(model, message);
|
|
177
|
+
if (!durable.has(message._tag)) return result;
|
|
178
|
+
editedSinceInstall = true;
|
|
179
|
+
persistsOwed++;
|
|
180
|
+
const edit = {
|
|
181
|
+
message,
|
|
182
|
+
started: void 0
|
|
183
|
+
};
|
|
184
|
+
edits.push(edit);
|
|
185
|
+
if (edits.length === 1) unloadGuarded(true);
|
|
186
|
+
const previous = tail;
|
|
187
|
+
let settle;
|
|
188
|
+
const done = new Promise((resolve) => {
|
|
189
|
+
settle = resolve;
|
|
190
|
+
});
|
|
191
|
+
tail = done;
|
|
192
|
+
const release = () => {
|
|
193
|
+
const index = edits.indexOf(edit);
|
|
194
|
+
if (index !== -1) edits.splice(index, 1);
|
|
195
|
+
if (edits.length === 0) unloadGuarded(false);
|
|
196
|
+
inFlight.delete(done);
|
|
197
|
+
settle();
|
|
198
|
+
};
|
|
199
|
+
const persist = {
|
|
200
|
+
name: "foldkit-sync/persist",
|
|
201
|
+
effect: Effect.gen(function* () {
|
|
202
|
+
inFlight.add(done);
|
|
203
|
+
yield* Effect.promise(() => previous);
|
|
204
|
+
edit.started = (yield* replica.snapshot).nextLocalSequence;
|
|
205
|
+
const outcome = yield* Effect.result(replica.submit(edit.message));
|
|
206
|
+
return outcome._tag === "Success" ? { _tag: PERSISTED } : {
|
|
207
|
+
_tag: FAILED,
|
|
208
|
+
error: outcome.failure
|
|
209
|
+
};
|
|
210
|
+
}).pipe(Effect.ensuring(Effect.sync(release)))
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
model: result.model,
|
|
214
|
+
commands: [...result.commands ?? [], persist]
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* A Message's transition, with the facts it returned applied after it. A durable
|
|
219
|
+
* Message's are not: replay would not apply them, so they stay ordinary Commands.
|
|
220
|
+
*/
|
|
221
|
+
const transition = (model, message) => {
|
|
222
|
+
const result = step(model, message);
|
|
223
|
+
return durable.has(message._tag) ? result : applyFacts(result);
|
|
224
|
+
};
|
|
225
|
+
/** Applies the facts a transition returned, in order, each as the transition after it. */
|
|
226
|
+
const applyFacts = (result) => {
|
|
227
|
+
let model = result.model;
|
|
228
|
+
const kept = [];
|
|
229
|
+
for (const command of result.commands ?? []) {
|
|
230
|
+
const found = factOf(command);
|
|
231
|
+
if (found === void 0) {
|
|
232
|
+
kept.push(command);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const next = transition(model, found.message);
|
|
236
|
+
model = next.model;
|
|
237
|
+
kept.push(...next.commands ?? []);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
model,
|
|
241
|
+
commands: kept
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
const ports = { inbound: { message: Port.inbound(app.Message) } };
|
|
245
|
+
const own = Subscription.make()(() => ({
|
|
246
|
+
message: Port.subscriptionEntry(ports.inbound.message, (message) => ({
|
|
247
|
+
_tag: DISPATCHED,
|
|
248
|
+
message
|
|
249
|
+
})),
|
|
250
|
+
refresh: Subscription.persistentEntry(replica.statusChanges.pipe(Stream.tap(() => Effect.sync(notifyCommitted)), Stream.mapAccum(() => void 0, (previous, status) => [status, [{
|
|
251
|
+
_tag: REFRESH,
|
|
252
|
+
status,
|
|
253
|
+
changed: sharedChanged(previous, status)
|
|
254
|
+
}]]))),
|
|
255
|
+
latest: {
|
|
256
|
+
dependenciesSchema: Schema.Struct({}),
|
|
257
|
+
modelToDependencies: (model) => {
|
|
258
|
+
latest = model;
|
|
259
|
+
notifyEach(modelListeners, void 0);
|
|
260
|
+
notifySettled();
|
|
261
|
+
return {};
|
|
262
|
+
},
|
|
263
|
+
dependenciesToStream: () => Stream.never
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
const subscriptions = options.subscriptions === void 0 ? own : Subscription.aggregate()(options.subscriptions, own);
|
|
267
|
+
const view = (model, h) => options.view(model, h);
|
|
268
|
+
const common = {
|
|
269
|
+
Model: app.Model,
|
|
270
|
+
container: options.container,
|
|
271
|
+
ports,
|
|
272
|
+
update,
|
|
273
|
+
subscriptions,
|
|
274
|
+
...options.resources === void 0 ? {} : { resources: options.resources },
|
|
275
|
+
view
|
|
276
|
+
};
|
|
277
|
+
const url = options.url;
|
|
278
|
+
const program = url === void 0 ? Runtime.makeApplication({
|
|
279
|
+
...common,
|
|
280
|
+
init: () => ({ model: latest })
|
|
281
|
+
}) : Runtime.makeApplication({
|
|
282
|
+
...common,
|
|
283
|
+
routing: {
|
|
284
|
+
onUrlChange: (at) => url.onUrlChange(at),
|
|
285
|
+
onUrlRequest: (request) => url.onUrlRequest === void 0 ? {
|
|
286
|
+
_tag: NAVIGATE,
|
|
287
|
+
request
|
|
288
|
+
} : url.onUrlRequest(request)
|
|
289
|
+
},
|
|
290
|
+
init: (at) => {
|
|
291
|
+
latest = url.init === void 0 ? latest : url.init(latest, at);
|
|
292
|
+
return { model: latest };
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
const handle = Runtime.embed(program);
|
|
296
|
+
const encodeMessage = Schema.encodeExit(app.Message);
|
|
297
|
+
return {
|
|
298
|
+
dispatch: (message) => Exit.match(encodeMessage(message), {
|
|
299
|
+
onSuccess: (encoded) => {
|
|
300
|
+
dispatchesOwed++;
|
|
301
|
+
const sent = handle.ports.message.send(encoded);
|
|
302
|
+
if (Exit.isFailure(sent)) dispatchesOwed--;
|
|
303
|
+
return sent;
|
|
304
|
+
},
|
|
305
|
+
onFailure: (cause) => Exit.failCause(cause)
|
|
306
|
+
}),
|
|
307
|
+
model: () => latest,
|
|
308
|
+
subscribe: (listener) => {
|
|
309
|
+
modelListeners.add(listener);
|
|
310
|
+
return () => modelListeners.delete(listener);
|
|
311
|
+
},
|
|
312
|
+
observe: (listener) => {
|
|
313
|
+
messageListeners.add(listener);
|
|
314
|
+
return () => messageListeners.delete(listener);
|
|
315
|
+
},
|
|
316
|
+
committed: {
|
|
317
|
+
get: () => Effect.runSync(replica.committed),
|
|
318
|
+
subscribe: (listener) => {
|
|
319
|
+
committedListeners.add(listener);
|
|
320
|
+
return () => committedListeners.delete(listener);
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
settled: () => {
|
|
324
|
+
if (disposed) return Promise.reject(/* @__PURE__ */ new Error("Sync.mount: settled() after dispose"));
|
|
325
|
+
if (quiet()) return Promise.resolve();
|
|
326
|
+
return new Promise((resolve, reject) => waiters.add({
|
|
327
|
+
resolve,
|
|
328
|
+
reject
|
|
329
|
+
}));
|
|
330
|
+
},
|
|
331
|
+
dispose: async () => {
|
|
332
|
+
disposed = true;
|
|
333
|
+
for (const waiter of [...waiters]) {
|
|
334
|
+
waiters.delete(waiter);
|
|
335
|
+
waiter.reject(/* @__PURE__ */ new Error("Sync.mount: disposed before it settled"));
|
|
336
|
+
}
|
|
337
|
+
await Promise.all([...inFlight]);
|
|
338
|
+
handle.dispose();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
export { fact, mount, unconfirmedEdits };
|
|
343
|
+
|
|
344
|
+
//# sourceMappingURL=mount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","names":[],"sources":["../src/mount.ts"],"sourcesContent":["/**\n * `Sync.mount`: runs a Foldkit application over a replica with one reducer.\n *\n * A durable Message is a state-only, deterministic transition of the shared\n * projection (the derived replay enforces it), so the application's own `update`\n * is applied at once and the Message is persisted afterwards in a Command. The\n * shared slice is re-installed from the replica when an exchange changes it or\n * a persist fails, through one private Message the application never sees.\n */\nimport { Effect, Exit, Layer, Option, Schema, Stream } from 'effect'\nimport { absurd } from 'effect/Function'\nimport type { Document, HtmlBuilder } from 'foldkit/html'\nimport * as Navigation from 'foldkit/navigation'\nimport type { UrlRequest } from 'foldkit/navigation'\nimport * as Port from 'foldkit/port'\nimport * as Runtime from 'foldkit/runtime'\nimport * as Subscription from 'foldkit/subscription'\nimport type { Subscriptions } from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport * as Url from 'foldkit/url'\nimport type { RunnableApplication } from 'foldkit-surface'\nimport type { ReplicaError } from './errors.js'\nimport type { DefinedSync } from './make.js'\nimport type { Replica, ReplicaStatus } from './sync.js'\n\nconst REFRESH = 'foldkit-sync/Refresh'\nconst PERSISTED = 'foldkit-sync/Persisted'\nconst FAILED = 'foldkit-sync/PersistenceFailed'\nconst NAVIGATE = 'foldkit-sync/Navigate'\nconst NAVIGATED = 'foldkit-sync/Navigated'\nconst DISPATCHED = 'foldkit-sync/Dispatched'\n\ntype Private =\n // Every replica status, applied in order, so `settled` counts one seen only once `update` has it.\n | { readonly _tag: typeof REFRESH; readonly status: ReplicaStatus; readonly changed: boolean }\n | { readonly _tag: typeof PERSISTED }\n | { readonly _tag: typeof FAILED; readonly error: ReplicaError }\n | { readonly _tag: typeof NAVIGATE; readonly request: UrlRequest }\n | { readonly _tag: typeof NAVIGATED }\n // An application Message sent through `dispatch`, so `settled` counts it in.\n | { readonly _tag: typeof DISPATCHED; readonly message: unknown }\n\n// A key per private tag, so a variant added to `Private` must be added here too.\nconst PRIVATE: Readonly<Record<Private['_tag'], true>> = {\n [REFRESH]: true,\n [PERSISTED]: true,\n [FAILED]: true,\n [NAVIGATE]: true,\n [NAVIGATED]: true,\n [DISPATCHED]: true,\n}\n\nconst isPrivate = (message: { readonly _tag: string }): message is Private =>\n Object.hasOwn(PRIVATE, message._tag)\n\n// A registered symbol, so two copies of this package in one bundle recognize each other's.\nconst FACT = Symbol.for('foldkit-sync/fact')\n\n/**\n * A Command that dispatches `message` as the next transition, which under `Sync.mount`\n * means within this one: the mount applies it straight after the `update` that returned\n * it, and persists it if it is durable, before any other Message is processed. This is\n * how a local intent turns into a durable fact that needs something only the intent's\n * transition knows, such as an id minted from local state, without a later Message\n * seeing the Model before the fact. Elsewhere, or once a parent has mapped the Command,\n * it is an ordinary Command that yields `message`, and so is one a durable Message's\n * update returns: replay would not apply it, and with derived replay the durable Message's\n * persist fails with `ReplayError` as for any Command.\n */\nexport const fact = <Message>(\n message: Message,\n): { readonly name: string; readonly effect: Effect.Effect<Message> } =>\n // Not enumerable, so the spread a mapping Command is copied with drops the marker, and a\n // mapped fact is the ordinary Command it now is rather than the unmapped Message.\n Object.defineProperty({ name: 'foldkit-sync/fact', effect: Effect.succeed(message) }, FACT, {\n value: message,\n enumerable: false,\n })\n\nconst factOf = (command: unknown): { readonly message: unknown } | undefined =>\n typeof command === 'object' && command !== null && FACT in command\n ? { message: (command as { readonly [FACT]: unknown })[FACT] }\n : undefined\n\n/**\n * The URL as part of the application: `onUrlChange` names the Message the\n * runtime sends for the current URL at start and on every navigation (so a\n * `foldkit-mirror` URL mirror reads back in), `init` reduces the URL into the\n * Model before the first render, and `onUrlRequest` names the Message for a\n * link click; omitted, the mount follows the link itself (an internal one is\n * pushed, an external one loaded).\n */\nexport interface MountUrl<Model, Message> {\n readonly init?: ((model: Model, url: Url.Url) => Model) | undefined\n readonly onUrlChange: (url: Url.Url) => Message\n readonly onUrlRequest?: ((request: UrlRequest) => Message) | undefined\n}\n\nexport interface MountOptions<Model, Message, Shared, Resources> {\n /** An open replica of this contract; `mount` does not close it. */\n readonly replica: Replica<Message, Shared>\n /** The element the application renders into; Foldkit requires it to have an `id`. */\n readonly container: HTMLElement\n readonly view: (model: Model, h: HtmlBuilder<Message>) => Document\n readonly subscriptions?: Subscriptions<Model, Message, Resources> | undefined\n readonly resources?: Layer.Layer<Resources> | undefined\n /** Route the URL through the application; without it the mount ignores the URL. */\n readonly url?: MountUrl<Model, Message> | undefined\n /**\n * Reflects a refused or failed persist in the Model, after the durable edit\n * has been reverted. Omitted, the edit is reverted silently.\n */\n readonly onPersistenceFailure?: ((model: Model, error: ReplicaError) => Model) | undefined\n /**\n * Runs when the mount replaces the shared slice outside `update`: an exchange committed,\n * acknowledged or rejected something, or a persist failed and its edit was reverted.\n * `previous` is the Model before; what it returns is the transition, so an application\n * can carry local state across the change (a selection held by what it points at) or\n * return Commands (a DOM the change has to reach). Omitted, the Model is `next`. It is\n * not called for a status that changes nothing the Model shows, such as the first.\n */\n readonly onReinstall?:\n | ((\n next: Model,\n previous: Model,\n change: Reinstall,\n ) => Update.Return<Model, Message, Resources>)\n | undefined\n /**\n * Runs on the Model after every update of the mounted application, a durable\n * Message's and a reinstall's included, and never in replay: for local state\n * derived from the shared slice, which a durable transition may not write\n * (the overlays `foldkit-sync/remote` keeps in Remote). With nothing to\n * change it returns the Model it was given.\n */\n readonly afterUpdate?: ((model: Model) => Update.Return<Model, Message, Resources>) | undefined\n}\n\n/**\n * What a reinstall came from. `reset` is a server reset: the replica's\n * committed history is a new one, so anything an application derived from\n * the old one (reads cached by commit sequence, say) is to be read again.\n */\nexport interface Reinstall {\n readonly reset: boolean\n}\n\n/**\n * The shared slice as the server has confirmed it, outside the Model. It is a\n * source for waiting consumers, the shape `Agent.when({ source })` reads, and\n * not a Projection: it does not render and is not derived from the Model.\n */\nexport interface CommittedView<Shared> {\n readonly get: () => Shared\n /** Told after every exchange, including one that moves no cursor (a checkpoint). */\n readonly subscribe: (listener: () => void) => () => void\n}\n\nexport interface Mounted<Model, Message, Shared = unknown> {\n /** Sends an application Message through the runtime; the `Exit` reports a decode failure. */\n readonly dispatch: (message: Message) => Exit.Exit<void, unknown>\n /** The Model after the last transition. */\n readonly model: () => Model\n /** Notified after every transition; with `model` and `dispatch`, the host an agent binds to. */\n readonly subscribe: (listener: () => void) => () => void\n /**\n * Every application Message the runtime applies, from any origin, so an\n * agent contract that declares a `completion` can see the Message that\n * finishes its work. The mount's private Messages are not reported.\n */\n readonly observe: (listener: (message: Message) => void) => () => void\n /**\n * The shared slice without pending local edits, for an agent that must not\n * report an optimistic edit as done: `Agent.when({ source: mounted.committed, … })`.\n */\n readonly committed: CommittedView<Shared>\n /**\n * Resolves once the Model has caught up with the replica: no persist in\n * flight or unanswered, every replica status the mount was told of seen,\n * and every reinstall it asked for applied. It observes and never does the\n * work. Frames are not its to wait for (`Frames.track` in\n * `foldkit-mixins/testing` is), nor I/O a Command started. Rejects after\n * `dispose`.\n */\n readonly settled: () => Promise<void>\n /** Waits for in-flight persists, then disposes the runtime. The replica stays open. */\n readonly dispose: () => Promise<void>\n}\n\n/**\n * Commits, rejections and acknowledgments change what the replica holds; a\n * submit only echoes a local edit. An acknowledgment that does not return the\n * operation moves no cursor, but it still drops the edit from the outbox.\n */\nconst sharedChanged = (previous: ReplicaStatus | undefined, next: ReplicaStatus): boolean =>\n previous === undefined ||\n previous.cursor !== next.cursor ||\n next.pending < previous.pending ||\n previous.rejected.length !== next.rejected.length ||\n previous.rejected.some((rejection, index) => rejection.opId !== next.rejected[index]?.opId)\n\n/**\n * A durable edit the Model already shows. `started` is the replica's next local\n * sequence when its submit began, `undefined` while it waits for its turn.\n */\nexport interface LocalEdit<Message> {\n readonly message: Message\n started: number | undefined\n}\n\n/**\n * The edits a replica whose next local sequence is `next` does not hold yet.\n * Submits run one at a time, so the one in flight is in the replica exactly\n * when its submit has moved the sequence past `started`.\n */\nexport const unconfirmedEdits = <Message>(\n edits: ReadonlyArray<LocalEdit<Message>>,\n next: number,\n): ReadonlyArray<Message> =>\n edits.filter(edit => edit.started === undefined || next <= edit.started).map(edit => edit.message)\n\n/** The application's Message union, as `Surface.application` types it. */\ntype MessageOf<App> =\n App extends RunnableApplication<any, any, any, any> ? Schema.Schema.Type<App['Message']> : never\n\nexport const mount = <\n Model,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Fields extends Schema.Struct.Fields,\n Ms extends readonly unknown[],\n Resources = never,\n Principal = unknown,\n>(\n app: RunnableApplication<Model, F, Cases, Resources>,\n sync: DefinedSync<\n Model,\n Fields,\n MessageOf<RunnableApplication<Model, F, Cases, Resources>>,\n Ms,\n Principal\n >,\n options: MountOptions<\n Model,\n MessageOf<RunnableApplication<Model, F, Cases, Resources>>,\n Schema.Struct.Type<Fields>,\n Resources\n >,\n): Mounted<\n Model,\n MessageOf<RunnableApplication<Model, F, Cases, Resources>>,\n Schema.Struct.Type<Fields>\n> => {\n // Foldkit reports a missing id only inside the runtime fiber, where nothing\n // renders and nothing is thrown; fail here instead.\n if (options.container.id === '')\n throw new Error('Sync.mount: the container needs an id (`container.id = \"app\"`)')\n type Message = MessageOf<RunnableApplication<Model, F, Cases, Resources>>\n // The application's Messages are tagged structs; the generic cannot say so.\n type Tagged = { readonly _tag: string }\n type RuntimeMessage = (Message & Tagged) | Private\n type Shared = Schema.Struct.Type<Fields>\n const { replica } = options\n const durable = new Set(sync.contract.messages)\n\n // Durable edits whose submit has not settled, in dispatch order.\n const edits: Array<LocalEdit<Message>> = []\n // An edit shows before it is stored, so a reload while one waits would lose\n // what the reader saw: the browser asks first, from the first such edit\n // until the last is stored.\n const holdUnload = (event: Event): void => event.preventDefault()\n const unloadGuarded = (guarded: boolean): void => {\n if (typeof window === 'undefined') return\n if (guarded) window.addEventListener('beforeunload', holdUnload)\n else window.removeEventListener('beforeunload', holdUnload)\n }\n // Settles when the latest edit's submit does; the next submit waits for it.\n let tail: Promise<void> = Promise.resolve()\n\n // The replica's `shared` holds every settled edit, and the one in flight once\n // its submit lands; the rest are replayed on top. Read from one snapshot, so\n // a refresh neither hides an edit still waiting for the replica nor applies\n // one the replica already holds.\n // The replica's shared value the Model was last installed from, and whether a durable\n // edit has changed the Model's copy since. The replica keeps one object per state, so\n // the same object with no edit since is the shared slice the Model already shows.\n let installedFrom: Shared | undefined\n let editedSinceInstall = false\n const install = (model: Model): Model => {\n const snapshot = Effect.runSync(replica.snapshot)\n installedFrom = snapshot.shared\n const unconfirmed = unconfirmedEdits(edits, snapshot.nextLocalSequence)\n // Edits replayed on top leave the Model's copy apart from `installedFrom`.\n editedSinceInstall = unconfirmed.length > 0\n const shared = unconfirmed.reduce<Shared>((value, message) => {\n try {\n return sync.replay(value, message)\n } catch {\n // The replica refuses it too; its FAILED re-installs without it.\n return value\n }\n }, snapshot.shared)\n return sync.projection.set(model, shared)\n }\n\n const inFlight = new Set<Promise<void>>()\n // What `settled` waits on: dispatches and persists not yet answered in\n // `update`, and the last replica status `update` applied.\n let dispatchesOwed = 0\n let persistsOwed = 0\n let applied: ReplicaStatus | undefined\n let disposed = false\n const waiters = new Set<{\n readonly resolve: () => void\n readonly reject: (error: Error) => void\n }>()\n const quiet = (): boolean =>\n dispatchesOwed === 0 &&\n persistsOwed === 0 &&\n !sharedChanged(applied, Effect.runSync(replica.status))\n const notifySettled = (): void => {\n if (!quiet()) return\n for (const waiter of [...waiters]) {\n waiters.delete(waiter)\n waiter.resolve()\n }\n }\n /**\n * A private transition that leaves the Model as it was: the runtime sends\n * no Subscription the change, so `settled` is told here, once it returns.\n */\n const unchanged = (model: Model): Update.Return<Model, RuntimeMessage, Resources> => {\n queueMicrotask(notifySettled)\n return { model }\n }\n let latest: Model = install(app.initial)\n const modelListeners = new Set<() => void>()\n const committedListeners = new Set<() => void>()\n const messageListeners = new Set<(message: Message) => void>()\n // Listeners run inside `update`, a Subscription, and the refresh stream. A\n // throwing one must not break those or skip the listeners after it, so its\n // error is reported asynchronously, as an event listener's would be.\n const notifyEach = <A>(listeners: ReadonlySet<(value: A) => void>, value: A): void => {\n for (const listener of [...listeners]) {\n try {\n listener(value)\n } catch (error) {\n queueMicrotask(() => {\n throw error\n })\n }\n }\n }\n const notifyCommitted = (): void => notifyEach(committedListeners, undefined)\n\n const updatePrivate = (\n model: Model,\n message: Private,\n ): Update.Return<Model, RuntimeMessage, Resources> => {\n switch (message._tag) {\n // Installs at once: edits still waiting for the replica are replayed on\n // top, so nothing is deferred behind them.\n case REFRESH: {\n // The server's history changed under the replica: a reset.\n const reset =\n applied !== undefined &&\n Option.isSome(applied.epoch) &&\n Option.isSome(message.status.epoch) &&\n applied.epoch.value !== message.status.epoch.value\n applied = message.status\n // The first status, and any other that changed nothing the Model shows, reinstall\n // nothing, so `onReinstall` hears only of a real change.\n if (\n !message.changed ||\n (!editedSinceInstall && Effect.runSync(replica.snapshot).shared === installedFrom)\n ) {\n return unchanged(model)\n }\n return reinstalled(install(model), model, { reset })\n }\n case PERSISTED:\n persistsOwed--\n return unchanged(model)\n case FAILED: {\n persistsOwed--\n const { error } = message\n const reverted = install(model)\n return reinstalled(options.onPersistenceFailure?.(reverted, error) ?? reverted, model, {\n reset: false,\n })\n }\n case NAVIGATE: {\n // A link the application did not claim: follow it. The runtime then\n // reports the new URL through `onUrlChange`.\n const { request } = message\n const follow =\n request._tag === 'Internal'\n ? Navigation.pushUrl(Url.toString(request.url))\n : Navigation.load(request.href)\n return {\n model,\n commands: [\n {\n name: 'foldkit-sync/navigate',\n effect: follow.pipe(Effect.as({ _tag: NAVIGATED } as RuntimeMessage)),\n },\n ],\n }\n }\n case NAVIGATED:\n return { model }\n case DISPATCHED:\n dispatchesOwed--\n return transition(model, message.message as Message & Tagged)\n default:\n return absurd(message)\n }\n }\n\n const update = (\n model: Model,\n message: RuntimeMessage,\n ): Update.Return<Model, RuntimeMessage, Resources> => {\n const result = isPrivate(message)\n ? updatePrivate(model, message)\n : transition(model, message as Message & Tagged)\n if (options.afterUpdate === undefined) return result\n const after = applyFacts(\n options.afterUpdate(result.model) as Update.Return<Model, RuntimeMessage, Resources>,\n )\n return after.model === result.model && (after.commands ?? []).length === 0\n ? result\n : { model: after.model, commands: [...(result.commands ?? []), ...(after.commands ?? [])] }\n }\n\n const reinstalled = (\n next: Model,\n previous: Model,\n change: Reinstall,\n ): Update.Return<Model, RuntimeMessage, Resources> =>\n options.onReinstall === undefined\n ? { model: next }\n : applyFacts(\n options.onReinstall(next, previous, change) as Update.Return<\n Model,\n RuntimeMessage,\n Resources\n >,\n )\n\n /** The application's transition for one of its Messages, with the persist a durable one needs. */\n const step = (\n model: Model,\n message: Message & Tagged,\n ): Update.Return<Model, RuntimeMessage, Resources> => {\n notifyEach(messageListeners, message)\n const result = app.update(model, message) as Update.Return<Model, RuntimeMessage, Resources>\n if (!durable.has(message._tag)) return result\n editedSinceInstall = true\n persistsOwed++\n const edit: LocalEdit<Message> = { message, started: undefined }\n edits.push(edit)\n if (edits.length === 1) unloadGuarded(true)\n const previous = tail\n let settle!: () => void\n const done = new Promise<void>(resolve => {\n settle = resolve\n })\n tail = done\n const release = (): void => {\n const index = edits.indexOf(edit)\n if (index !== -1) edits.splice(index, 1)\n if (edits.length === 0) unloadGuarded(false)\n inFlight.delete(done)\n settle()\n }\n const persist = {\n name: 'foldkit-sync/persist',\n effect: Effect.gen(function* () {\n // Tracked so `dispose` can wait instead of interrupting a persist.\n inFlight.add(done)\n // One submit at a time, in dispatch order, so `started` is the\n // sequence this edit takes if its submit succeeds.\n yield* Effect.promise(() => previous)\n edit.started = (yield* replica.snapshot).nextLocalSequence\n const outcome = yield* Effect.result(replica.submit(edit.message))\n return outcome._tag === 'Success'\n ? ({ _tag: PERSISTED } as RuntimeMessage)\n : ({ _tag: FAILED, error: outcome.failure } as RuntimeMessage)\n }).pipe(\n // `ensuring`, so a defect in storage still releases the next submit and `dispose`.\n Effect.ensuring(Effect.sync(release)),\n ),\n }\n return { model: result.model, commands: [...(result.commands ?? []), persist] }\n }\n\n /**\n * A Message's transition, with the facts it returned applied after it. A durable\n * Message's are not: replay would not apply them, so they stay ordinary Commands.\n */\n const transition = (\n model: Model,\n message: Message & Tagged,\n ): Update.Return<Model, RuntimeMessage, Resources> => {\n const result = step(model, message)\n return durable.has(message._tag) ? result : applyFacts(result)\n }\n\n /** Applies the facts a transition returned, in order, each as the transition after it. */\n const applyFacts = (\n result: Update.Return<Model, RuntimeMessage, Resources>,\n ): Update.Return<Model, RuntimeMessage, Resources> => {\n let model = result.model\n const kept: Array<Update.Commands<RuntimeMessage, Resources>[number]> = []\n for (const command of result.commands ?? []) {\n const found = factOf(command)\n if (found === undefined) {\n kept.push(command)\n continue\n }\n const next = transition(model, found.message as Message & Tagged)\n model = next.model\n kept.push(...(next.commands ?? []))\n }\n return { model, commands: kept }\n }\n\n const ports = {\n inbound: { message: Port.inbound(app.Message as unknown as Schema.Codec<Message, unknown>) },\n }\n const own = Subscription.make<Model, RuntimeMessage, Resources>()(() => ({\n message: Port.subscriptionEntry(ports.inbound.message, (message): RuntimeMessage => ({\n _tag: DISPATCHED,\n message,\n })),\n // The replica's status carries the cursor and rejections, which is exactly\n // when the shared slice held locally can differ from the replica's.\n refresh: Subscription.persistentEntry<RuntimeMessage, Resources>(\n replica.statusChanges.pipe(\n // Every status, not only a changed cursor: a checkpoint at the same\n // cursor still replaces the committed state a waiter reads.\n Stream.tap(() => Effect.sync(notifyCommitted)),\n Stream.mapAccum(\n (): ReplicaStatus | undefined => undefined,\n (previous, status): readonly [ReplicaStatus, ReadonlyArray<RuntimeMessage>] => [\n status,\n [{ _tag: REFRESH, status, changed: sharedChanged(previous, status) }],\n ],\n ),\n ),\n ),\n // `modelToDependencies` runs on every transition, so it doubles as the Model\n // getter the runtime does not expose.\n latest: {\n dependenciesSchema: Schema.Struct({}),\n modelToDependencies: (model: Model) => {\n latest = model\n notifyEach(modelListeners, undefined)\n // After every transition, so `settled` resolves once `model()` has it.\n notifySettled()\n return {}\n },\n dependenciesToStream: () => Stream.never,\n },\n }))\n const subscriptions =\n options.subscriptions === undefined\n ? own\n : Subscription.aggregate<Model, RuntimeMessage, Resources>()(\n options.subscriptions as Subscriptions<Model, RuntimeMessage, Resources>,\n own,\n )\n\n const view = (model: Model, h: HtmlBuilder<RuntimeMessage>): Document =>\n // Sound: the view constructs only application Messages, a subset of the\n // runtime's union.\n options.view(model, h as unknown as HtmlBuilder<Message>)\n const common = {\n Model: app.Model as unknown as Schema.Codec<Model, any, unknown, unknown>,\n container: options.container,\n ports,\n update,\n subscriptions,\n ...(options.resources === undefined ? {} : { resources: options.resources }),\n view,\n }\n const url = options.url\n const program =\n url === undefined\n ? Runtime.makeApplication({ ...common, init: () => ({ model: latest }) })\n : Runtime.makeApplication({\n ...common,\n routing: {\n onUrlChange: (at: Url.Url) => url.onUrlChange(at) as RuntimeMessage,\n onUrlRequest: (request: UrlRequest): RuntimeMessage =>\n url.onUrlRequest === undefined\n ? { _tag: NAVIGATE, request }\n : (url.onUrlRequest(request) as RuntimeMessage),\n },\n init: (at: Url.Url) => {\n latest = url.init === undefined ? latest : url.init(latest, at)\n return { model: latest }\n },\n })\n const handle = Runtime.embed(program)\n const encodeMessage = Schema.encodeExit(app.Message as unknown as Schema.Codec<Message, unknown>)\n\n return {\n // The port decodes what it is sent, so it takes the Message encoded: a\n // Message is sent as its type is, Option fields and all.\n dispatch: message =>\n Exit.match(encodeMessage(message), {\n onSuccess: encoded => {\n // Counted before the send, in case the port delivers within it.\n dispatchesOwed++\n const sent = handle.ports.message.send(encoded)\n if (Exit.isFailure(sent)) dispatchesOwed--\n return sent\n },\n onFailure: cause => Exit.failCause(cause),\n }),\n model: () => latest,\n subscribe: listener => {\n modelListeners.add(listener)\n return () => modelListeners.delete(listener)\n },\n observe: listener => {\n messageListeners.add(listener)\n return () => messageListeners.delete(listener)\n },\n committed: {\n get: () => Effect.runSync(replica.committed),\n subscribe: listener => {\n committedListeners.add(listener)\n return () => committedListeners.delete(listener)\n },\n },\n settled: () => {\n if (disposed) return Promise.reject(new Error('Sync.mount: settled() after dispose'))\n if (quiet()) return Promise.resolve()\n return new Promise<void>((resolve, reject) => waiters.add({ resolve, reject }))\n },\n dispose: async () => {\n disposed = true\n for (const waiter of [...waiters]) {\n waiters.delete(waiter)\n waiter.reject(new Error('Sync.mount: disposed before it settled'))\n }\n await Promise.all([...inFlight])\n handle.dispose()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,UA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ACb,YAAW,aAAY;GACrB,eAAe,IAAI,QAAQ;GAC3B,aAAa,eAAe,OAAO,QAAQ;EAC7C;EACA,UAAS,aAAY;GACnB,iBAAiB,IAAI,QAAQ;GAC7B,aAAa,iBAAiB,OAAO,QAAQ;EAC/C;EACA,WAAW;GACT,WAAW,OAAO,QAAQ,QAAQ,SAAS;GAC3C,YAAW,aAAY;IACrB,mBAAmB,IAAI,QAAQ;IAC/B,aAAa,mBAAmB,OAAO,QAAQ;GACjD;EACF;EACA,eAAe;GACb,IAAI,UAAU,OAAO,QAAQ,uBAAO,IAAI,MAAM,qCAAqC,CAAC;GACpF,IAAI,MAAM,GAAG,OAAO,QAAQ,QAAQ;GACpC,OAAO,IAAI,SAAe,SAAS,WAAW,QAAQ,IAAI;IAAE;IAAS;GAAO,CAAC,CAAC;EAChF;EACA,SAAS,YAAY;GACnB,WAAW;GACX,KAAK,MAAM,UAAU,CAAC,GAAG,OAAO,GAAG;IACjC,QAAQ,OAAO,MAAM;IACrB,OAAO,uBAAO,IAAI,MAAM,wCAAwC,CAAC;GACnE;GACA,MAAM,QAAQ,IAAI,CAAC,GAAG,QAAQ,CAAC;GAC/B,OAAO,QAAQ;EACjB;CACF;AACF"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Duration, Effect, PubSub, Scope, Stream } from "effect";
|
|
2
|
+
import { SocketLike } from "./transport.js";
|
|
3
|
+
/** One peer's presence. A `null` value means the peer left. */
|
|
4
|
+
export interface PresenceUpdate<Update> {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly value: Update | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The ephemeral channel presence travels on.
|
|
10
|
+
*
|
|
11
|
+
* `updates` is the inbound bus a peer consumes; `publish` sends one to the bus.
|
|
12
|
+
* Splitting them keeps an inbound update from being echoed straight back out.
|
|
13
|
+
* This is deliberately not the durable transport: presence is broadcast, never
|
|
14
|
+
* journaled, so a dropped or duplicated update is harmless.
|
|
15
|
+
*/
|
|
16
|
+
export interface PresenceChannel<Update> {
|
|
17
|
+
readonly updates: PubSub.PubSub<PresenceUpdate<Update>>;
|
|
18
|
+
readonly publish: (update: PresenceUpdate<Update>) => Effect.Effect<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface PresenceOptions<Update> {
|
|
21
|
+
/** This peer's identity on the channel. */
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/** How long a peer may go without refreshing before it is dropped. */
|
|
24
|
+
readonly ttl: Duration.Input;
|
|
25
|
+
/**
|
|
26
|
+
* Validates the untrusted value a peer sends before it is stored. Presence
|
|
27
|
+
* crosses a wire, so this is required rather than trusting the type
|
|
28
|
+
* parameter; a value it rejects is dropped.
|
|
29
|
+
*/
|
|
30
|
+
readonly decodeValue: (value: unknown) => Update;
|
|
31
|
+
readonly channel?: PresenceChannel<Update> | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The least time between two values sent on the channel. `set` still takes effect here at
|
|
34
|
+
* once; a value set sooner waits, and only the latest one waiting is sent when the time is
|
|
35
|
+
* up. A departure is never held back. Absent, every `set` is sent at once.
|
|
36
|
+
*/
|
|
37
|
+
readonly throttle?: Duration.Input | undefined;
|
|
38
|
+
}
|
|
39
|
+
export interface PresencePeer<Update> {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly value: Update;
|
|
42
|
+
readonly updatedAt: number;
|
|
43
|
+
}
|
|
44
|
+
export interface Presence<Update> {
|
|
45
|
+
/** Sets this peer's value and broadcasts it, no sooner than `throttle` allows. */
|
|
46
|
+
readonly set: (value: Update) => Effect.Effect<void>;
|
|
47
|
+
/** Removes this peer and broadcasts the departure. */
|
|
48
|
+
readonly leave: Effect.Effect<void>;
|
|
49
|
+
/** Live peers, self included, with stale ones excluded. */
|
|
50
|
+
readonly peers: Effect.Effect<ReadonlyArray<PresencePeer<Update>>>;
|
|
51
|
+
/** Drops expired peers; notifies if any went. */
|
|
52
|
+
readonly prune: Effect.Effect<void>;
|
|
53
|
+
/** Notified when the peer set changes. */
|
|
54
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
55
|
+
/**
|
|
56
|
+
* The live peers, re-emitted whenever the set changes. The `Stream` form of
|
|
57
|
+
* `subscribe`, for a consumer that composes with Effect.
|
|
58
|
+
*/
|
|
59
|
+
readonly changes: Stream.Stream<ReadonlyArray<PresencePeer<Update>>>;
|
|
60
|
+
/** Stops consuming the channel; the enclosing scope also does this on exit. */
|
|
61
|
+
readonly close: Effect.Effect<void>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Tracks ephemeral peers with a time-to-live.
|
|
65
|
+
*
|
|
66
|
+
* Nothing here touches the durable log: presence is state a peer refreshes, and
|
|
67
|
+
* a peer that stops refreshing is dropped, not replayed. Time comes from the
|
|
68
|
+
* `Clock`, so a `TestClock` drives the TTL deterministically.
|
|
69
|
+
*/
|
|
70
|
+
export declare const createPresence: <Update>(options: PresenceOptions<Update>) => Effect.Effect<{
|
|
71
|
+
set: (value: Update) => Effect.Effect<void, never, never>;
|
|
72
|
+
leave: Effect.Effect<void, never, never>;
|
|
73
|
+
peers: Effect.Effect<{
|
|
74
|
+
id: string;
|
|
75
|
+
value: Update;
|
|
76
|
+
updatedAt: number;
|
|
77
|
+
}[], never, never>;
|
|
78
|
+
prune: Effect.Effect<void, never, never>;
|
|
79
|
+
subscribe: (listener: () => void) => () => boolean;
|
|
80
|
+
changes: Stream.Stream<{
|
|
81
|
+
id: string;
|
|
82
|
+
value: Update;
|
|
83
|
+
updatedAt: number;
|
|
84
|
+
}[], never, never>;
|
|
85
|
+
close: Effect.Effect<void, never, never>;
|
|
86
|
+
}, never, Scope.Scope>;
|
|
87
|
+
/** An in-process channel, for tests and single-process demos. */
|
|
88
|
+
export declare const loopbackPresenceChannel: <Update>() => Effect.Effect<{
|
|
89
|
+
updates: PubSub.PubSub<PresenceUpdate<Update>>;
|
|
90
|
+
publish: (update: PresenceUpdate<Update>) => Effect.Effect<boolean, never, never>;
|
|
91
|
+
}, never, never>;
|
|
92
|
+
/** Broadcasts presence updates among connected peers. */
|
|
93
|
+
export interface PresenceHub<Update> {
|
|
94
|
+
/** Registers a peer's send; returns a leave function. */
|
|
95
|
+
join(send: (update: PresenceUpdate<Update>) => void): () => void;
|
|
96
|
+
/** Fans an update out to every joined peer. */
|
|
97
|
+
publish(update: PresenceUpdate<Update>): void;
|
|
98
|
+
}
|
|
99
|
+
export declare const createPresenceHub: <Update>() => PresenceHub<Update>;
|
|
100
|
+
/**
|
|
101
|
+
* A presence channel fed by stamped frames from the server, sent back without an
|
|
102
|
+
* id: the server owns peer identity, so a client cannot assert another's.
|
|
103
|
+
*/
|
|
104
|
+
export declare const socketPresenceChannel: <Update>(socket: SocketLike) => Effect.Effect<PresenceChannel<Update>, never, Scope.Scope>;
|
|
105
|
+
/**
|
|
106
|
+
* Serves presence frames on an accepted socket, stamping the connection's
|
|
107
|
+
* identity, until the socket closes or the returned function is called.
|
|
108
|
+
* With `opens`, the connection joins only once it answers that it may open
|
|
109
|
+
* the document the presence accompanies: until then, and for good when it
|
|
110
|
+
* is refused or fails, nothing reaches it and nothing it sends is relayed.
|
|
111
|
+
*/
|
|
112
|
+
export declare const servePresence: <Update>(socket: SocketLike, hub: PresenceHub<Update>, options: {
|
|
113
|
+
readonly peerId: string;
|
|
114
|
+
readonly opens?: Effect.Effect<boolean, unknown> | undefined;
|
|
115
|
+
}) => (() => void);
|
|
116
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","names":[],"sources":["../src/presence.ts"],"mappings":";;;iBAgBiB,eAAe;WACrB;WACA,OAAO;;;;;;;;;;iBAWD,gBAAgB;WACtB,SAAS,OAAO,OAAO,eAAe;WACtC,UAAU,QAAQ,eAAe,YAAY,OAAO;;iBAG9C,gBAAgB;;WAEtB;;WAEA,KAAK,SAAS;;;;;;WAMd,cAAc,mBAAmB;WACjC,UAAU,gBAAgB;;;;;;WAM1B,WAAW,SAAS;;iBAGd,aAAa;WACnB;WACA,OAAO;WACP;;iBAGM,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;;;iBAK3B,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"}
|