foldkit-sync 0.3.0 → 0.4.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 +246 -137
- package/dist/index.d.mts +307 -183
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +308 -245
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ids.ts","../src/errors.ts","../src/indexedDb.ts","../src/transport.ts","../src/sync.ts","../src/make.ts","../src/mount.ts","../src/presence.ts","../src/lww.ts","../src/index.ts"],"mappings":";;;;;;;;qBAGa,YAAU,SAAA,MAAA,SAAA;YACX,oBAAoB,WAAW;;qBAG9B,WAAS,SAAA,MAAA,SAAA;YACV,mBAAmB,UAAU;;qBAG5B,MAAI,SAAA,MAAA,SAAA;YACL,cAAc,KAAK;;;;;qBAMlB,UAAQ,SAAA,MAAA,SAAA;YAKT,kBAAkB,SAAS;;qBAG1B,eAAa,SAAA,MAAA,SAAA;YAKd,uBAAuB,cAAc;;;;;;qBAOpC,aAAc,kBAAgB;qBAC9B,YAAa,kBAAgB;qBAC7B,OAAQ,kBAAgB;qBACxB,WAAY,kBAAgB;qBAC5B,gBAAiB,kBAAgB;;;;;;;;qBCvCjC,qBAAqB;;;;;;qBAMrB,qCAAqC;;;;;;;qBASrC,iCAAiC;;;;;;qBAUjC,mCAAmC;;;;;;qBASnC,6BAA6B;;;;;qBAS7B,2BAA2B;;;;;;;qBAQ3B,kCAAkC;;;;;;;qBAUlC,4BAA4B;;;;;;qBAU5B,8BAA8B;;;;;;;;;;qBAa9B,oCAAoC;;;;;qBASpC,2BAA2B;;;;;;;qBAQ3B,uCAAuC;;;;;;;;;qBAavC,oBAAoB;KAKrB,eACR,eACA,cACA,2BACA,6BACA,uBACA,iCACA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;UAuJpB,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;;;;;qBA6C5C,wBAAyB,QACpC,QAAQ,eACP,OAAO,OAAO,gBAAgB,gBAAgB,MAAM;;qBAsB1C,gBAAiB,QAC5B,QAAQ,YACR,KAAK,YAAY,SACjB;WAAoB;;;;;cCnRhB,OAAK,SAAA;;;;cAYL,YAAU,SAAA;;;;;;KAOJ,uBAAuB,WAAW;UAE7B;;EAEf,OAAO,6BAA6B,OAAO,cAAc,MAAM,MAAM;;EAErE,OAAO,OAAO;;;;;;;;;;qBAuCH,eAAY;WAEA,YAAA;WACD,WAAA;WACF,SAAA;;;;;;;GAgErB,eAAA;;;;;;qBAOY,cAAe,OAAO,SAAS,IAAI,IAC9C,OAAO,SAAO,MAAM,OAAO,SAAS,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YC1G9B,KAAK,SAAS,UAAU,OAAa,SAAS;;qBAG7C"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Clock, Context, Duration, Effect, Exit, Fiber, Layer, Metric, PubSub, Queue, Ref, Schedule, Schema, Stream, SynchronizedRef } from "effect";
|
|
2
|
+
import { MessageSet, Projection, Surface } from "foldkit-surface";
|
|
2
3
|
import * as Navigation from "foldkit/navigation";
|
|
3
4
|
import * as Port from "foldkit/port";
|
|
4
5
|
import * as Runtime from "foldkit/runtime";
|
|
5
6
|
import * as Subscription from "foldkit/subscription";
|
|
6
7
|
import * as Url from "foldkit/url";
|
|
7
|
-
import { MessageSet, Projection, Surface } from "foldkit-surface";
|
|
8
8
|
//#region src/errors.ts
|
|
9
9
|
/** The persisted storage could not be read or written. */
|
|
10
10
|
var StorageError = class extends Schema.TaggedError()("StorageError", {
|
|
@@ -130,142 +130,6 @@ const indexedDb = Effect.fn("Storage.indexedDb")(function* (name, factory = glob
|
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
//#endregion
|
|
133
|
-
//#region src/mount.ts
|
|
134
|
-
/**
|
|
135
|
-
* `Sync.mount`: runs a Foldkit application over a replica with one reducer.
|
|
136
|
-
*
|
|
137
|
-
* A durable Message is a state-only, deterministic transition of the shared
|
|
138
|
-
* projection (the derived replay enforces it), so the application's own `update`
|
|
139
|
-
* is applied at once and the Message is persisted afterwards in a Command. The
|
|
140
|
-
* shared slice is re-installed from the replica when an exchange changes it or
|
|
141
|
-
* a persist fails, through one private Message the application never sees.
|
|
142
|
-
*/
|
|
143
|
-
const REFRESH = "foldkit-sync/Refresh";
|
|
144
|
-
const PERSISTED = "foldkit-sync/Persisted";
|
|
145
|
-
const FAILED = "foldkit-sync/PersistenceFailed";
|
|
146
|
-
const NAVIGATE = "foldkit-sync/Navigate";
|
|
147
|
-
const NAVIGATED = "foldkit-sync/Navigated";
|
|
148
|
-
/** Exchanges and rejections change what the replica holds; a submit only echoes a local edit. */
|
|
149
|
-
const sharedChanged = (previous, next) => previous === void 0 || previous.cursor !== next.cursor || previous.rejected.length !== next.rejected.length || previous.rejected.some((id, index) => id !== next.rejected[index]);
|
|
150
|
-
const mount = (app, sync, options) => {
|
|
151
|
-
if (options.container.id === "") throw new Error("Sync.mount: the container needs an id (`container.id = \"app\"`)");
|
|
152
|
-
const { replica } = options;
|
|
153
|
-
const durable = new Set(sync.contract.messages);
|
|
154
|
-
const install = (model) => sync.projection.set(model, Effect.runSync(replica.shared));
|
|
155
|
-
const inFlight = /* @__PURE__ */ new Set();
|
|
156
|
-
let latest = install(app.initial);
|
|
157
|
-
const modelListeners = /* @__PURE__ */ new Set();
|
|
158
|
-
const messageListeners = /* @__PURE__ */ new Set();
|
|
159
|
-
const update = (model, message) => {
|
|
160
|
-
switch (message._tag) {
|
|
161
|
-
case REFRESH: return { model: install(model) };
|
|
162
|
-
case PERSISTED: return { model };
|
|
163
|
-
case FAILED: {
|
|
164
|
-
const { error } = message;
|
|
165
|
-
const reverted = install(model);
|
|
166
|
-
return { model: options.onPersistenceFailure?.(reverted, error) ?? reverted };
|
|
167
|
-
}
|
|
168
|
-
case NAVIGATE: {
|
|
169
|
-
const { request } = message;
|
|
170
|
-
return {
|
|
171
|
-
model,
|
|
172
|
-
commands: [{
|
|
173
|
-
name: "foldkit-sync/navigate",
|
|
174
|
-
effect: (request._tag === "Internal" ? Navigation.pushUrl(Url.toString(request.url)) : Navigation.load(request.href)).pipe(Effect.as({ _tag: NAVIGATED }))
|
|
175
|
-
}]
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
case NAVIGATED: return { model };
|
|
179
|
-
default: {
|
|
180
|
-
for (const listener of messageListeners) listener(message);
|
|
181
|
-
const result = app.update(model, message);
|
|
182
|
-
if (!durable.has(message._tag)) return result;
|
|
183
|
-
const persist = {
|
|
184
|
-
name: "foldkit-sync/persist",
|
|
185
|
-
effect: Effect.gen(function* () {
|
|
186
|
-
let settle;
|
|
187
|
-
const done = new Promise((resolve) => {
|
|
188
|
-
settle = resolve;
|
|
189
|
-
});
|
|
190
|
-
inFlight.add(done);
|
|
191
|
-
const outcome = yield* Effect.result(replica.submit(message));
|
|
192
|
-
inFlight.delete(done);
|
|
193
|
-
settle();
|
|
194
|
-
return outcome._tag === "Success" ? { _tag: PERSISTED } : {
|
|
195
|
-
_tag: FAILED,
|
|
196
|
-
error: outcome.failure
|
|
197
|
-
};
|
|
198
|
-
})
|
|
199
|
-
};
|
|
200
|
-
return {
|
|
201
|
-
model: result.model,
|
|
202
|
-
commands: [...result.commands ?? [], persist]
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
const ports = { inbound: { message: Port.inbound(app.Message) } };
|
|
208
|
-
const own = Subscription.make()(() => ({
|
|
209
|
-
message: Port.subscription(ports.inbound.message, (message) => message),
|
|
210
|
-
refresh: Subscription.persistent(replica.statusChanges.pipe(Stream.mapAccum(() => void 0, (previous, status) => [status, sharedChanged(previous, status) ? [{ _tag: REFRESH }] : []]))),
|
|
211
|
-
latest: {
|
|
212
|
-
dependenciesSchema: Schema.Struct({}),
|
|
213
|
-
modelToDependencies: (model) => {
|
|
214
|
-
latest = model;
|
|
215
|
-
for (const listener of modelListeners) listener();
|
|
216
|
-
return {};
|
|
217
|
-
},
|
|
218
|
-
dependenciesToStream: () => Stream.never
|
|
219
|
-
}
|
|
220
|
-
}));
|
|
221
|
-
const subscriptions = options.subscriptions === void 0 ? own : Subscription.aggregate()(options.subscriptions, own);
|
|
222
|
-
const view = (model, h) => options.view(model, h);
|
|
223
|
-
const common = {
|
|
224
|
-
Model: app.Model,
|
|
225
|
-
container: options.container,
|
|
226
|
-
ports,
|
|
227
|
-
update,
|
|
228
|
-
subscriptions,
|
|
229
|
-
...options.resources === void 0 ? {} : { resources: options.resources },
|
|
230
|
-
view
|
|
231
|
-
};
|
|
232
|
-
const url = options.url;
|
|
233
|
-
const program = url === void 0 ? Runtime.makeApplication({
|
|
234
|
-
...common,
|
|
235
|
-
init: () => ({ model: latest })
|
|
236
|
-
}) : Runtime.makeApplication({
|
|
237
|
-
...common,
|
|
238
|
-
routing: {
|
|
239
|
-
onUrlChange: (at) => url.onUrlChange(at),
|
|
240
|
-
onUrlRequest: (request) => url.onUrlRequest === void 0 ? {
|
|
241
|
-
_tag: NAVIGATE,
|
|
242
|
-
request
|
|
243
|
-
} : url.onUrlRequest(request)
|
|
244
|
-
},
|
|
245
|
-
init: (at) => {
|
|
246
|
-
latest = url.init === void 0 ? latest : url.init(latest, at);
|
|
247
|
-
return { model: latest };
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
const handle = Runtime.embed(program);
|
|
251
|
-
return {
|
|
252
|
-
dispatch: (message) => handle.ports.message.send(message),
|
|
253
|
-
model: () => latest,
|
|
254
|
-
subscribe: (listener) => {
|
|
255
|
-
modelListeners.add(listener);
|
|
256
|
-
return () => modelListeners.delete(listener);
|
|
257
|
-
},
|
|
258
|
-
observe: (listener) => {
|
|
259
|
-
messageListeners.add(listener);
|
|
260
|
-
return () => messageListeners.delete(listener);
|
|
261
|
-
},
|
|
262
|
-
dispose: async () => {
|
|
263
|
-
await Promise.all([...inFlight]);
|
|
264
|
-
handle.dispose();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
//#endregion
|
|
269
133
|
//#region src/ids.ts
|
|
270
134
|
/** Identifies the replicated document a replica or operation belongs to. */
|
|
271
135
|
const DocumentId = Schema.NonEmptyString.pipe(Schema.brand("@foldkit-sync/DocumentId"));
|
|
@@ -280,12 +144,133 @@ const OpId = Schema.NonEmptyString.pipe(Schema.brand("@foldkit-sync/OpId"));
|
|
|
280
144
|
const Sequence = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)).pipe(Schema.brand("@foldkit-sync/Sequence"));
|
|
281
145
|
/** A replica's own operation counter within a document; 1-based. */
|
|
282
146
|
const LocalSequence = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)).pipe(Schema.brand("@foldkit-sync/LocalSequence"));
|
|
147
|
+
/**
|
|
148
|
+
* Decode-and-brand helpers. A branded schema constructs the same value with
|
|
149
|
+
* `DocumentId.make('todos')`, which is the spelling to lead with; these stay
|
|
150
|
+
* for callers that already have them.
|
|
151
|
+
*/
|
|
283
152
|
const documentId = (value) => Schema.decodeUnknownSync(DocumentId)(value);
|
|
284
153
|
const replicaId = (value) => Schema.decodeUnknownSync(ReplicaId)(value);
|
|
285
154
|
const opId = (value) => Schema.decodeUnknownSync(OpId)(value);
|
|
286
155
|
const sequence = (value) => Schema.decodeUnknownSync(Sequence)(value);
|
|
287
156
|
const localSequence = (value) => Schema.decodeUnknownSync(LocalSequence)(value);
|
|
288
157
|
//#endregion
|
|
158
|
+
//#region src/lww.ts
|
|
159
|
+
/** A logical write time; replica ids break concurrent ties using UTF-16 order. */
|
|
160
|
+
const Stamp = Schema.Struct({
|
|
161
|
+
counter: Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)),
|
|
162
|
+
replicaId: ReplicaId
|
|
163
|
+
});
|
|
164
|
+
/** The persisted clock format. A bump must handle the older value explicitly. */
|
|
165
|
+
const CLOCK_SCHEMA_VERSION = 1;
|
|
166
|
+
const ClockState = Schema.Struct({
|
|
167
|
+
schemaVersion: Schema.Literal(CLOCK_SCHEMA_VERSION),
|
|
168
|
+
documentId: DocumentId,
|
|
169
|
+
replicaId: ReplicaId,
|
|
170
|
+
revision: Stamp.fields.counter
|
|
171
|
+
});
|
|
172
|
+
const decodeClock = Schema.decodeUnknownSync(ClockState, { onExcessProperty: "error" });
|
|
173
|
+
const decodeCounter = Schema.decodeUnknownSync(Stamp.fields.counter);
|
|
174
|
+
const clockError = (message, cause) => new StorageError({
|
|
175
|
+
message: `${message}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
176
|
+
cause
|
|
177
|
+
});
|
|
178
|
+
const VersionProbe = Schema.Struct({ schemaVersion: Schema.optional(Schema.Number) });
|
|
179
|
+
/**
|
|
180
|
+
* Tells a version this build does not understand apart from malformed data, so
|
|
181
|
+
* the caller gets an actionable failure and the stored state is preserved.
|
|
182
|
+
*/
|
|
183
|
+
const unsupportedVersion = (input) => {
|
|
184
|
+
let found;
|
|
185
|
+
try {
|
|
186
|
+
found = Schema.decodeUnknownSync(VersionProbe)(input);
|
|
187
|
+
} catch {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (found.schemaVersion === CLOCK_SCHEMA_VERSION) return void 0;
|
|
191
|
+
return new UnsupportedClockVersionError({
|
|
192
|
+
schemaVersion: found.schemaVersion ?? null,
|
|
193
|
+
message: `Stored clock uses schema ${found.schemaVersion ?? "?"}; this build supports ${CLOCK_SCHEMA_VERSION}`
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Opens a durable clock over the caller's storage.
|
|
198
|
+
*
|
|
199
|
+
* Allocations are serialized through a `SynchronizedRef` and each persists before
|
|
200
|
+
* its stamp is returned. A crash after the save may skip a timestamp but never
|
|
201
|
+
* reuse one. Storage is owned by the caller; a failed open closes it so a partial
|
|
202
|
+
* initialization does not leak the connection.
|
|
203
|
+
*/
|
|
204
|
+
const openLwwClock = Effect.fn("Lww.openClock")(function* (options) {
|
|
205
|
+
const { documentId, replicaId, storage } = options;
|
|
206
|
+
yield* Effect.annotateCurrentSpan({
|
|
207
|
+
documentId,
|
|
208
|
+
replicaId
|
|
209
|
+
});
|
|
210
|
+
const initial = decodeClock({
|
|
211
|
+
schemaVersion: CLOCK_SCHEMA_VERSION,
|
|
212
|
+
documentId,
|
|
213
|
+
replicaId,
|
|
214
|
+
revision: 0
|
|
215
|
+
});
|
|
216
|
+
const saved = yield* storage.load();
|
|
217
|
+
const state = yield* Effect.try({
|
|
218
|
+
try: () => saved === void 0 ? initial : decodeClock(saved),
|
|
219
|
+
catch: (cause) => unsupportedVersion(saved) ?? clockError("Stored clock state is invalid", cause)
|
|
220
|
+
});
|
|
221
|
+
if (state.documentId !== documentId || state.replicaId !== replicaId) return yield* new StorageError({ message: "Wrong clock storage" });
|
|
222
|
+
if (saved === void 0) yield* storage.save(state, null);
|
|
223
|
+
const stateRef = yield* SynchronizedRef.make(state);
|
|
224
|
+
const closed = yield* Ref.make(false);
|
|
225
|
+
return {
|
|
226
|
+
next: Effect.fn("Lww.next")(function* (observedCounter = 0) {
|
|
227
|
+
if (yield* Ref.get(closed)) return yield* new StorageError({ message: "Clock is closed" });
|
|
228
|
+
return yield* SynchronizedRef.modifyEffect(stateRef, (current) => Effect.gen(function* () {
|
|
229
|
+
if (yield* Ref.get(closed)) return yield* new StorageError({ message: "Clock is closed" });
|
|
230
|
+
const allocated = yield* Effect.try({
|
|
231
|
+
try: () => decodeClock({
|
|
232
|
+
...current,
|
|
233
|
+
revision: Math.max(current.revision, decodeCounter(observedCounter)) + 1
|
|
234
|
+
}),
|
|
235
|
+
catch: (cause) => clockError("Invalid clock allocation", cause)
|
|
236
|
+
});
|
|
237
|
+
yield* storage.save(allocated, current.revision);
|
|
238
|
+
return [{
|
|
239
|
+
counter: allocated.revision,
|
|
240
|
+
replicaId
|
|
241
|
+
}, allocated];
|
|
242
|
+
}));
|
|
243
|
+
}),
|
|
244
|
+
close: Effect.fn("Lww.close")(function* () {
|
|
245
|
+
if (yield* Ref.modify(closed, (current) => [current, true])) return;
|
|
246
|
+
yield* SynchronizedRef.modifyEffect(stateRef, (current) => Effect.succeed([void 0, current]));
|
|
247
|
+
yield* storage.close;
|
|
248
|
+
})()
|
|
249
|
+
};
|
|
250
|
+
}, (effect, options) => effect.pipe(Effect.onExit((exit) => Exit.isSuccess(exit) ? Effect.void : options.storage.close.pipe(Effect.ignore))));
|
|
251
|
+
/**
|
|
252
|
+
* A schema and reducer helper for a last-writer-wins register.
|
|
253
|
+
* Allocate a unique stamp per write before dispatch, and retain it in the Message.
|
|
254
|
+
* Merge is for decoded values; the application's schema validates wire input.
|
|
255
|
+
*/
|
|
256
|
+
const lwwRegister = (value) => {
|
|
257
|
+
const schema = Schema.Struct({
|
|
258
|
+
stamp: Stamp,
|
|
259
|
+
value
|
|
260
|
+
});
|
|
261
|
+
const equivalent = Schema.toEquivalence(value);
|
|
262
|
+
const merge = (left, right) => {
|
|
263
|
+
if (left.stamp.counter !== right.stamp.counter) return left.stamp.counter > right.stamp.counter ? left : right;
|
|
264
|
+
if (left.stamp.replicaId !== right.stamp.replicaId) return left.stamp.replicaId > right.stamp.replicaId ? left : right;
|
|
265
|
+
if (!equivalent(left.value, right.value)) throw new Error("Conflicting LWW write identity");
|
|
266
|
+
return left;
|
|
267
|
+
};
|
|
268
|
+
return {
|
|
269
|
+
schema,
|
|
270
|
+
merge
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
//#endregion
|
|
289
274
|
//#region src/transport.ts
|
|
290
275
|
/** The wire failure of a transport. A refusal is a result, not an error. */
|
|
291
276
|
var TransportError = class extends Schema.TaggedError()("SyncTransportError", { message: Schema.String }) {};
|
|
@@ -1058,119 +1043,139 @@ const build = (app) => {
|
|
|
1058
1043
|
};
|
|
1059
1044
|
};
|
|
1060
1045
|
//#endregion
|
|
1061
|
-
//#region src/
|
|
1062
|
-
/** A logical write time; replica ids break concurrent ties using UTF-16 order. */
|
|
1063
|
-
const Stamp = Schema.Struct({
|
|
1064
|
-
counter: Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)),
|
|
1065
|
-
replicaId: ReplicaId
|
|
1066
|
-
});
|
|
1067
|
-
/** The persisted clock format. A bump must handle the older value explicitly. */
|
|
1068
|
-
const CLOCK_SCHEMA_VERSION = 1;
|
|
1069
|
-
const ClockState = Schema.Struct({
|
|
1070
|
-
schemaVersion: Schema.Literal(CLOCK_SCHEMA_VERSION),
|
|
1071
|
-
documentId: DocumentId,
|
|
1072
|
-
replicaId: ReplicaId,
|
|
1073
|
-
revision: Stamp.fields.counter
|
|
1074
|
-
});
|
|
1075
|
-
const decodeClock = Schema.decodeUnknownSync(ClockState, { onExcessProperty: "error" });
|
|
1076
|
-
const decodeCounter = Schema.decodeUnknownSync(Stamp.fields.counter);
|
|
1077
|
-
const clockError = (message, cause) => new StorageError({
|
|
1078
|
-
message: `${message}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1079
|
-
cause
|
|
1080
|
-
});
|
|
1081
|
-
const VersionProbe = Schema.Struct({ schemaVersion: Schema.optional(Schema.Number) });
|
|
1082
|
-
/**
|
|
1083
|
-
* Tells a version this build does not understand apart from malformed data, so
|
|
1084
|
-
* the caller gets an actionable failure and the stored state is preserved.
|
|
1085
|
-
*/
|
|
1086
|
-
const unsupportedVersion = (input) => {
|
|
1087
|
-
let found;
|
|
1088
|
-
try {
|
|
1089
|
-
found = Schema.decodeUnknownSync(VersionProbe)(input);
|
|
1090
|
-
} catch {
|
|
1091
|
-
return;
|
|
1092
|
-
}
|
|
1093
|
-
if (found.schemaVersion === CLOCK_SCHEMA_VERSION) return void 0;
|
|
1094
|
-
return new UnsupportedClockVersionError({
|
|
1095
|
-
schemaVersion: found.schemaVersion ?? null,
|
|
1096
|
-
message: `Stored clock uses schema ${found.schemaVersion ?? "?"}; this build supports ${CLOCK_SCHEMA_VERSION}`
|
|
1097
|
-
});
|
|
1098
|
-
};
|
|
1046
|
+
//#region src/mount.ts
|
|
1099
1047
|
/**
|
|
1100
|
-
*
|
|
1048
|
+
* `Sync.mount`: runs a Foldkit application over a replica with one reducer.
|
|
1101
1049
|
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1050
|
+
* A durable Message is a state-only, deterministic transition of the shared
|
|
1051
|
+
* projection (the derived replay enforces it), so the application's own `update`
|
|
1052
|
+
* is applied at once and the Message is persisted afterwards in a Command. The
|
|
1053
|
+
* shared slice is re-installed from the replica when an exchange changes it or
|
|
1054
|
+
* a persist fails, through one private Message the application never sees.
|
|
1106
1055
|
*/
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1056
|
+
const REFRESH = "foldkit-sync/Refresh";
|
|
1057
|
+
const PERSISTED = "foldkit-sync/Persisted";
|
|
1058
|
+
const FAILED = "foldkit-sync/PersistenceFailed";
|
|
1059
|
+
const NAVIGATE = "foldkit-sync/Navigate";
|
|
1060
|
+
const NAVIGATED = "foldkit-sync/Navigated";
|
|
1061
|
+
/** Exchanges and rejections change what the replica holds; a submit only echoes a local edit. */
|
|
1062
|
+
const sharedChanged = (previous, next) => previous === void 0 || previous.cursor !== next.cursor || previous.rejected.length !== next.rejected.length || previous.rejected.some((id, index) => id !== next.rejected[index]);
|
|
1063
|
+
const mount = (app, sync, options) => {
|
|
1064
|
+
if (options.container.id === "") throw new Error("Sync.mount: the container needs an id (`container.id = \"app\"`)");
|
|
1065
|
+
const { replica } = options;
|
|
1066
|
+
const durable = new Set(sync.contract.messages);
|
|
1067
|
+
const install = (model) => sync.projection.set(model, Effect.runSync(replica.shared));
|
|
1068
|
+
const inFlight = /* @__PURE__ */ new Set();
|
|
1069
|
+
let latest = install(app.initial);
|
|
1070
|
+
const modelListeners = /* @__PURE__ */ new Set();
|
|
1071
|
+
const messageListeners = /* @__PURE__ */ new Set();
|
|
1072
|
+
const update = (model, message) => {
|
|
1073
|
+
switch (message._tag) {
|
|
1074
|
+
case REFRESH: return { model: install(model) };
|
|
1075
|
+
case PERSISTED: return { model };
|
|
1076
|
+
case FAILED: {
|
|
1077
|
+
const { error } = message;
|
|
1078
|
+
const reverted = install(model);
|
|
1079
|
+
return { model: options.onPersistenceFailure?.(reverted, error) ?? reverted };
|
|
1080
|
+
}
|
|
1081
|
+
case NAVIGATE: {
|
|
1082
|
+
const { request } = message;
|
|
1083
|
+
return {
|
|
1084
|
+
model,
|
|
1085
|
+
commands: [{
|
|
1086
|
+
name: "foldkit-sync/navigate",
|
|
1087
|
+
effect: (request._tag === "Internal" ? Navigation.pushUrl(Url.toString(request.url)) : Navigation.load(request.href)).pipe(Effect.as({ _tag: NAVIGATED }))
|
|
1088
|
+
}]
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
case NAVIGATED: return { model };
|
|
1092
|
+
default: {
|
|
1093
|
+
for (const listener of messageListeners) listener(message);
|
|
1094
|
+
const result = app.update(model, message);
|
|
1095
|
+
if (!durable.has(message._tag)) return result;
|
|
1096
|
+
const persist = {
|
|
1097
|
+
name: "foldkit-sync/persist",
|
|
1098
|
+
effect: Effect.gen(function* () {
|
|
1099
|
+
let settle;
|
|
1100
|
+
const done = new Promise((resolve) => {
|
|
1101
|
+
settle = resolve;
|
|
1102
|
+
});
|
|
1103
|
+
inFlight.add(done);
|
|
1104
|
+
const outcome = yield* Effect.result(replica.submit(message));
|
|
1105
|
+
inFlight.delete(done);
|
|
1106
|
+
settle();
|
|
1107
|
+
return outcome._tag === "Success" ? { _tag: PERSISTED } : {
|
|
1108
|
+
_tag: FAILED,
|
|
1109
|
+
error: outcome.failure
|
|
1110
|
+
};
|
|
1111
|
+
})
|
|
1112
|
+
};
|
|
1113
|
+
return {
|
|
1114
|
+
model: result.model,
|
|
1115
|
+
commands: [...result.commands ?? [], persist]
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1152
1119
|
};
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1120
|
+
const ports = { inbound: { message: Port.inbound(app.Message) } };
|
|
1121
|
+
const own = Subscription.make()(() => ({
|
|
1122
|
+
message: Port.subscription(ports.inbound.message, (message) => message),
|
|
1123
|
+
refresh: Subscription.persistent(replica.statusChanges.pipe(Stream.mapAccum(() => void 0, (previous, status) => [status, sharedChanged(previous, status) ? [{ _tag: REFRESH }] : []]))),
|
|
1124
|
+
latest: {
|
|
1125
|
+
dependenciesSchema: Schema.Struct({}),
|
|
1126
|
+
modelToDependencies: (model) => {
|
|
1127
|
+
latest = model;
|
|
1128
|
+
for (const listener of modelListeners) listener();
|
|
1129
|
+
return {};
|
|
1130
|
+
},
|
|
1131
|
+
dependenciesToStream: () => Stream.never
|
|
1132
|
+
}
|
|
1133
|
+
}));
|
|
1134
|
+
const subscriptions = options.subscriptions === void 0 ? own : Subscription.aggregate()(options.subscriptions, own);
|
|
1135
|
+
const view = (model, h) => options.view(model, h);
|
|
1136
|
+
const common = {
|
|
1137
|
+
Model: app.Model,
|
|
1138
|
+
container: options.container,
|
|
1139
|
+
ports,
|
|
1140
|
+
update,
|
|
1141
|
+
subscriptions,
|
|
1142
|
+
...options.resources === void 0 ? {} : { resources: options.resources },
|
|
1143
|
+
view
|
|
1170
1144
|
};
|
|
1145
|
+
const url = options.url;
|
|
1146
|
+
const program = url === void 0 ? Runtime.makeApplication({
|
|
1147
|
+
...common,
|
|
1148
|
+
init: () => ({ model: latest })
|
|
1149
|
+
}) : Runtime.makeApplication({
|
|
1150
|
+
...common,
|
|
1151
|
+
routing: {
|
|
1152
|
+
onUrlChange: (at) => url.onUrlChange(at),
|
|
1153
|
+
onUrlRequest: (request) => url.onUrlRequest === void 0 ? {
|
|
1154
|
+
_tag: NAVIGATE,
|
|
1155
|
+
request
|
|
1156
|
+
} : url.onUrlRequest(request)
|
|
1157
|
+
},
|
|
1158
|
+
init: (at) => {
|
|
1159
|
+
latest = url.init === void 0 ? latest : url.init(latest, at);
|
|
1160
|
+
return { model: latest };
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
const handle = Runtime.embed(program);
|
|
1171
1164
|
return {
|
|
1172
|
-
|
|
1173
|
-
|
|
1165
|
+
dispatch: (message) => handle.ports.message.send(message),
|
|
1166
|
+
model: () => latest,
|
|
1167
|
+
subscribe: (listener) => {
|
|
1168
|
+
modelListeners.add(listener);
|
|
1169
|
+
return () => modelListeners.delete(listener);
|
|
1170
|
+
},
|
|
1171
|
+
observe: (listener) => {
|
|
1172
|
+
messageListeners.add(listener);
|
|
1173
|
+
return () => messageListeners.delete(listener);
|
|
1174
|
+
},
|
|
1175
|
+
dispose: async () => {
|
|
1176
|
+
await Promise.all([...inFlight]);
|
|
1177
|
+
handle.dispose();
|
|
1178
|
+
}
|
|
1174
1179
|
};
|
|
1175
1180
|
};
|
|
1176
1181
|
//#endregion
|
|
@@ -1361,6 +1366,64 @@ const servePresence = (socket, hub, options) => {
|
|
|
1361
1366
|
};
|
|
1362
1367
|
};
|
|
1363
1368
|
//#endregion
|
|
1364
|
-
|
|
1369
|
+
//#region src/index.ts
|
|
1370
|
+
/**
|
|
1371
|
+
* `foldkit-sync` — a local-first replica of a shared Foldkit projection.
|
|
1372
|
+
*
|
|
1373
|
+
* The application's Message union and update function stay authoritative: sync
|
|
1374
|
+
* wraps them rather than introducing a second reducer. The replica owns the
|
|
1375
|
+
* local outbox, optimistic projection, and reconciliation; a durable server
|
|
1376
|
+
* journal provides authoritative order.
|
|
1377
|
+
*
|
|
1378
|
+
* `Sync` is the namespace: `Sync.forApplication`, `Sync.mount`,
|
|
1379
|
+
* `Sync.transport.socket`. Ids are branded schemas, so they construct through
|
|
1380
|
+
* `DocumentId.make('todos')`. Every name is also exported on its own.
|
|
1381
|
+
*/
|
|
1382
|
+
/** The package's public surface, grouped. Each entry is the exported function itself. */
|
|
1383
|
+
const Sync = {
|
|
1384
|
+
/** Derives a sync contract from a Foldkit application: `Sync.forApplication(App).make({…})`. */
|
|
1385
|
+
forApplication,
|
|
1386
|
+
/** The protocol primitive, for a client with no Foldkit application to derive from. */
|
|
1387
|
+
define: defineSync,
|
|
1388
|
+
/** Runs a Foldkit application over an open replica with one reducer. */
|
|
1389
|
+
mount,
|
|
1390
|
+
/** Counters and a histogram an application can scrape. */
|
|
1391
|
+
metrics: syncMetrics,
|
|
1392
|
+
/** The only storage adapter: one IndexedDB database per document/replica. */
|
|
1393
|
+
indexedDb,
|
|
1394
|
+
/** The `Transport` service's layers, and the bridges to and from a promise client. */
|
|
1395
|
+
transport: {
|
|
1396
|
+
/** A reconnecting WebSocket client layer. */
|
|
1397
|
+
socket: layerSocket,
|
|
1398
|
+
/** An in-process layer, for tests and single-process demos. */
|
|
1399
|
+
loopback: layerLoopback,
|
|
1400
|
+
/** Wraps the promise-based client the replica already speaks. */
|
|
1401
|
+
fromPromise: layerFromPromise,
|
|
1402
|
+
/** Bridges the service back to that promise client. */
|
|
1403
|
+
toPromise,
|
|
1404
|
+
/** The server side of one accepted socket connection. */
|
|
1405
|
+
serve: serveSocket,
|
|
1406
|
+
/** The default socket factory: the platform `WebSocket`. */
|
|
1407
|
+
nativeSocket
|
|
1408
|
+
},
|
|
1409
|
+
/** An ephemeral, TTL'd peer registry, deliberately outside the durable log. */
|
|
1410
|
+
presence: {
|
|
1411
|
+
make: createPresence,
|
|
1412
|
+
/** Broadcasts presence updates among connected peers, on the server. */
|
|
1413
|
+
hub: createPresenceHub,
|
|
1414
|
+
/** Serves presence frames on an accepted socket, stamping the connection's identity. */
|
|
1415
|
+
serve: servePresence,
|
|
1416
|
+
socketChannel: socketPresenceChannel,
|
|
1417
|
+
loopbackChannel: loopbackPresenceChannel
|
|
1418
|
+
},
|
|
1419
|
+
/** Last-writer-wins registers (experimental): a per-field merge on logical time. */
|
|
1420
|
+
lww: {
|
|
1421
|
+
register: lwwRegister,
|
|
1422
|
+
/** The durable counter a stamp is allocated from, before dispatch. */
|
|
1423
|
+
openClock: openLwwClock
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
//#endregion
|
|
1427
|
+
export { CheckpointRegressionError, CommittedOrderError, DocumentId, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, LocalSequence, OpId, ReplayError, ReplicaClosedError, ReplicaId, Sequence, StorageError, Sync, Transport, TransportError, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError, createPresence, createPresenceHub, defineSync, documentId, forApplication, indexedDb, layerFromPromise, layerLoopback, layerSocket, localSequence, loopbackPresenceChannel, lwwRegister, mount, nativeSocket, opId, openLwwClock, replicaId, sequence, servePresence, serveSocket, socketPresenceChannel, syncMetrics, toPromise };
|
|
1365
1428
|
|
|
1366
1429
|
//# sourceMappingURL=index.mjs.map
|