foldkit-sync 0.6.0 → 0.8.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 +423 -786
- package/dist/index.d.mts +148 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +458 -160
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ import { UrlRequest } from "foldkit/navigation";
|
|
|
4
4
|
import { Subscriptions } from "foldkit/subscription";
|
|
5
5
|
import * as Url from "foldkit/url";
|
|
6
6
|
import { Document, HtmlBuilder } from "foldkit/html";
|
|
7
|
+
import * as Update from "foldkit/update";
|
|
7
8
|
//#region src/ids.d.ts
|
|
8
9
|
/** Identifies the replicated document a replica or operation belongs to. */
|
|
9
10
|
export declare const DocumentId: Schema$1.brand<Schema$1.NonEmptyString, "@foldkit-sync/DocumentId">;
|
|
@@ -125,15 +126,39 @@ export declare class ReplayError extends ReplayError_base {}
|
|
|
125
126
|
type ReplicaError = StorageError | ReplayError | WrongReplicaStorageError | InvalidReplicaHistoryError | InvalidExchangeError | UnsupportedReplicaVersionError | InvalidOutboxError | CheckpointRegressionError | CommittedOrderError | ForeignRejectionError | ForeignAcknowledgementError | ReplicaClosedError;
|
|
126
127
|
//#endregion
|
|
127
128
|
//#region src/indexedDb.d.ts
|
|
129
|
+
/** One submitted operation, as `Storage.append` records it. */
|
|
130
|
+
interface OutboxEntry {
|
|
131
|
+
/** The replica's revision once this operation is in its outbox. */
|
|
132
|
+
readonly revision: number;
|
|
133
|
+
readonly nextLocalSequence: number;
|
|
134
|
+
/**
|
|
135
|
+
* The operation's local sequence. An entry with the sequence of one already in the
|
|
136
|
+
* outbox replaces it: a coalesced submit rewrites the last operation.
|
|
137
|
+
*/
|
|
138
|
+
readonly localSequence: number;
|
|
139
|
+
/** The operation, encoded. */
|
|
140
|
+
readonly operation: unknown;
|
|
141
|
+
}
|
|
128
142
|
/** Persists a replica's state with compare-and-swap on its revision. */
|
|
129
143
|
interface Storage {
|
|
144
|
+
/**
|
|
145
|
+
* The saved state, with every operation appended since in its `pending` (replacing the
|
|
146
|
+
* one of the same local sequence), and the last one's `revision` and `nextLocalSequence`.
|
|
147
|
+
*/
|
|
130
148
|
load: () => Effect.Effect<unknown, StorageError>;
|
|
149
|
+
/** Replaces the whole state, and with it every appended operation. */
|
|
131
150
|
save: (state: unknown, expectedRevision: number | null) => Effect.Effect<void, StorageError>;
|
|
151
|
+
/**
|
|
152
|
+
* Optional. Records one submitted operation without rewriting the rest of the state, so
|
|
153
|
+
* a submit costs the operation's size rather than the document's. Without it, a submit
|
|
154
|
+
* saves the whole state.
|
|
155
|
+
*/
|
|
156
|
+
append?: (entry: OutboxEntry, expectedRevision: number) => Effect.Effect<void, StorageError>;
|
|
132
157
|
/** Idempotent; the caller closes the connection explicitly. */
|
|
133
158
|
close: Effect.Effect<void>;
|
|
134
159
|
}
|
|
135
160
|
/** One database per document/replica; CAS prevents two tabs from sharing a writer identity. */
|
|
136
|
-
export declare const indexedDb: (name: string | Config.Config<string>, factory?: IDBFactory | undefined) => Effect.Effect<Storage
|
|
161
|
+
export declare const indexedDb: (name: string | Config.Config<string>, factory?: IDBFactory | undefined) => Effect.Effect<Required<Storage>, StorageError, import("effect/Scope").Scope>;
|
|
137
162
|
//#endregion
|
|
138
163
|
//#region src/transport.d.ts
|
|
139
164
|
declare const TransportError_base: Schema$1.Class<TransportError, Schema$1.TaggedStruct<"SyncTransportError", {
|
|
@@ -146,14 +171,35 @@ interface ExchangeFrame {
|
|
|
146
171
|
readonly id: string;
|
|
147
172
|
readonly cursor: number;
|
|
148
173
|
readonly pending: ReadonlyArray<Operation>;
|
|
174
|
+
readonly epoch?: string | undefined;
|
|
149
175
|
}
|
|
150
176
|
interface ExchangeReply {
|
|
151
177
|
readonly id: string;
|
|
152
178
|
readonly result?: unknown;
|
|
153
179
|
readonly error?: string;
|
|
154
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Sent by a server, unasked, when the document may have changed. It carries no
|
|
183
|
+
* data: the replica exchanges from its own cursor, so a notice that is lost,
|
|
184
|
+
* late, or one of many is harmless.
|
|
185
|
+
*/
|
|
186
|
+
interface NotifyFrame {
|
|
187
|
+
readonly notify: true;
|
|
188
|
+
}
|
|
155
189
|
interface TransportShape {
|
|
156
|
-
|
|
190
|
+
/** `epoch` is the server history the replica's cursor points into, when it knows one. */
|
|
191
|
+
readonly exchange: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => Effect.Effect<unknown, TransportError>;
|
|
192
|
+
/**
|
|
193
|
+
* Emits when the server may have something new, for a transport that can hear
|
|
194
|
+
* it: `Replica.start` exchanges on each. A wake-up, not data.
|
|
195
|
+
*/
|
|
196
|
+
readonly changes?: Stream.Stream<void> | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* The connection itself, for another protocol to share, such as presence: a send goes to
|
|
199
|
+
* the socket open now and is dropped while none is, and messages from every socket the
|
|
200
|
+
* transport opens arrive here. It is the transport's to close.
|
|
201
|
+
*/
|
|
202
|
+
readonly socket?: SocketLike | undefined;
|
|
157
203
|
}
|
|
158
204
|
declare const Transport_base: Context.ServiceClass<Transport, "foldkit-sync/Transport", TransportShape>;
|
|
159
205
|
/**
|
|
@@ -165,7 +211,7 @@ declare const Transport_base: Context.ServiceClass<Transport, "foldkit-sync/Tran
|
|
|
165
211
|
*/
|
|
166
212
|
export declare class Transport extends Transport_base {}
|
|
167
213
|
/** A transport backed by an in-process handler, for tests and single-process demos. */
|
|
168
|
-
export declare const layerLoopback: (handler: (cursor: number, pending: ReadonlyArray<Operation
|
|
214
|
+
export declare const layerLoopback: (handler: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>) => Layer.Layer<Transport>;
|
|
169
215
|
/** Wraps the promise-based client the replica already speaks. */
|
|
170
216
|
export declare const layerFromPromise: (transport: TransportClient) => Layer.Layer<Transport>;
|
|
171
217
|
/** Bridges the service back to the promise client the replica consumes. */
|
|
@@ -174,11 +220,15 @@ export declare const toPromise: (transport: TransportShape) => TransportClient;
|
|
|
174
220
|
* Serves one accepted socket, answering each exchange frame.
|
|
175
221
|
*
|
|
176
222
|
* The counterpart to `layerSocket`: the handler returns the exchange result, or
|
|
177
|
-
* throws and the failure is written back as an error frame.
|
|
178
|
-
*
|
|
223
|
+
* throws and the failure is written back as an error frame. With `changes`, a
|
|
224
|
+
* subscription to the document's commits, the socket is also sent a
|
|
225
|
+
* `NotifyFrame` after each, so a client hears of others' edits without polling.
|
|
226
|
+
* Returns a function that stops serving.
|
|
179
227
|
*/
|
|
180
228
|
export declare const serveSocket: (socket: SocketLike, options: {
|
|
181
|
-
readonly exchange: (cursor: number, pending: ReadonlyArray<Operation
|
|
229
|
+
readonly exchange: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>;
|
|
230
|
+
/** Subscribes to the document's commits; returns the unsubscribe. */
|
|
231
|
+
readonly changes?: ((listener: () => void) => () => void) | undefined;
|
|
182
232
|
}) => (() => void);
|
|
183
233
|
/** The minimal socket the layer needs; the global `WebSocket` satisfies it. */
|
|
184
234
|
interface SocketLike {
|
|
@@ -196,10 +246,16 @@ interface SocketOptions {
|
|
|
196
246
|
readonly url: string;
|
|
197
247
|
/** Injectable for tests; defaults to the platform `WebSocket`. */
|
|
198
248
|
readonly makeSocket?: ((url: string) => SocketLike) | undefined;
|
|
199
|
-
/**
|
|
249
|
+
/**
|
|
250
|
+
* Consecutive failed connections after which queued work fails and new
|
|
251
|
+
* exchanges fail fast until a connection is healthy again. Reconnecting goes
|
|
252
|
+
* on regardless. Default 5.
|
|
253
|
+
*/
|
|
200
254
|
readonly maxRetries?: number | undefined;
|
|
201
255
|
/** Base delay of the exponential reconnect backoff. Default `50 millis`. */
|
|
202
256
|
readonly retryBase?: Duration.Input | undefined;
|
|
257
|
+
/** Longest wait between reconnect attempts. Default `5 seconds`. */
|
|
258
|
+
readonly maxRetryDelay?: Duration.Input | undefined;
|
|
203
259
|
/** Exchanges queued or in flight before new ones fail. Default 64. */
|
|
204
260
|
readonly maxQueue?: number | undefined;
|
|
205
261
|
}
|
|
@@ -212,9 +268,14 @@ export declare const nativeSocket: (url: string) => SocketLike;
|
|
|
212
268
|
* it closes, the transport reconnects on an exponential, jittered backoff and
|
|
213
269
|
* re-sends every queued and in-flight frame with its original id, so a lost
|
|
214
270
|
* reply is answered rather than dropped and a late reply cannot resolve a newer
|
|
215
|
-
* frame.
|
|
216
|
-
* with a `TransportError
|
|
217
|
-
*
|
|
271
|
+
* frame. It never stops reconnecting: after `maxRetries` consecutive failures
|
|
272
|
+
* queued work fails with a `TransportError`, and exchanges fail fast while no
|
|
273
|
+
* socket is up, until a socket opens. The count resets only when a connection
|
|
274
|
+
* proves healthy, by answering a frame or by staying open for `maxRetryDelay`:
|
|
275
|
+
* a server that accepts a socket and drops it at once is backed off like one
|
|
276
|
+
* that refuses it. A queue over `maxQueue` fails new
|
|
277
|
+
* exchanges with backpressure. The socket is released when the layer's scope
|
|
278
|
+
* ends.
|
|
218
279
|
*/
|
|
219
280
|
export declare const layerSocket: (options: SocketOptions) => Layer.Layer<Transport, TransportError>;
|
|
220
281
|
//#endregion
|
|
@@ -268,6 +329,14 @@ interface Exchange<Shared> {
|
|
|
268
329
|
readonly acknowledged?: ReadonlyArray<OpId> | undefined;
|
|
269
330
|
/** The snapshot a replica predating compaction adopts in place of the log. */
|
|
270
331
|
readonly checkpoint?: Checkpoint<Shared> | undefined;
|
|
332
|
+
/** The server sent only part of what is after the cursor; the replica asks again. */
|
|
333
|
+
readonly more?: boolean | undefined;
|
|
334
|
+
/**
|
|
335
|
+
* The identity of the server's history. The replica sends back the one it last saw; a
|
|
336
|
+
* server that finds another answers from the start of its own history, and the replica,
|
|
337
|
+
* seeing a new epoch, rebuilds its committed state from that answer and keeps its outbox.
|
|
338
|
+
*/
|
|
339
|
+
readonly epoch?: string | undefined;
|
|
271
340
|
}
|
|
272
341
|
interface ReplicaState<Shared> {
|
|
273
342
|
readonly protocolVersion: typeof PROTOCOL_VERSION;
|
|
@@ -280,13 +349,16 @@ interface ReplicaState<Shared> {
|
|
|
280
349
|
readonly committed: Shared;
|
|
281
350
|
readonly committedIds: ReadonlyArray<string>;
|
|
282
351
|
readonly pending: ReadonlyArray<Operation>;
|
|
352
|
+
/** The server history `cursor` points into, once an exchange has named one. */
|
|
353
|
+
readonly epoch?: string;
|
|
283
354
|
}
|
|
284
355
|
/**
|
|
285
356
|
* What the promise-based edge adapter consumes; the Effect `Transport` service
|
|
286
357
|
* is the primary seam.
|
|
287
358
|
*/
|
|
288
359
|
interface TransportClient {
|
|
289
|
-
|
|
360
|
+
/** `epoch` is the server history the replica's cursor points into, when it knows one. */
|
|
361
|
+
exchange(cursor: Sequence, pending: ReadonlyArray<Operation>, epoch?: string | undefined): Promise<unknown>;
|
|
290
362
|
}
|
|
291
363
|
/** A redacted view of a replica's state, for a UI to explain and recover. */
|
|
292
364
|
interface ReplicaStatus {
|
|
@@ -342,10 +414,12 @@ interface Replica<Message, Shared> {
|
|
|
342
414
|
/** Reconciles against the server. The `Transport` service must be provided. */
|
|
343
415
|
readonly synchronize: Effect.Effect<void, ReplicaError | TransportError, Transport>;
|
|
344
416
|
/**
|
|
345
|
-
* The exchange loop: exchanges once, then after every `submit
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
417
|
+
* The exchange loop: exchanges once, then after every `submit` and every
|
|
418
|
+
* notice on the transport's `changes`, until the replica closes or the fiber
|
|
419
|
+
* is interrupted. A failed exchange is recorded
|
|
420
|
+
* in `status.lastError` and retried on a backoff (from 0.5 s, doubling up to
|
|
421
|
+
* 30 s), or at once on the next `submit`, so the fiber never fails. Fork it
|
|
422
|
+
* with `Effect.forkScoped` and provide `Transport`.
|
|
349
423
|
*/
|
|
350
424
|
readonly start: Effect.Effect<void, never, Transport>;
|
|
351
425
|
readonly close: Effect.Effect<void>;
|
|
@@ -357,9 +431,17 @@ interface SyncDefinition<Message, Shared, MessageEncoded, SharedEncoded> {
|
|
|
357
431
|
readonly empty: Shared;
|
|
358
432
|
readonly durable: (message: Message) => boolean;
|
|
359
433
|
readonly replay: (shared: Shared, message: Message) => Shared;
|
|
434
|
+
/**
|
|
435
|
+
* Optional. Merges a durable Message into the one submitted before it, while that one
|
|
436
|
+
* has not been sent: one operation instead of two, for a burst of typing. Replaying the
|
|
437
|
+
* result must equal replaying `last` then `next`. Undefined keeps them apart.
|
|
438
|
+
*/
|
|
439
|
+
readonly coalesce?: ((last: Message, next: Message) => Message | undefined) | undefined;
|
|
360
440
|
}
|
|
361
441
|
interface Sync$1<Message, Shared> {
|
|
362
442
|
readonly documentId: DocumentId;
|
|
443
|
+
/** Whether a Message is one the replica records and replays. */
|
|
444
|
+
readonly durable: (message: Message) => boolean;
|
|
363
445
|
/**
|
|
364
446
|
* Low-level wire codecs for adapters and the transport. Most applications use
|
|
365
447
|
* `journalContract` and `openReplica`; these are exposed for a custom
|
|
@@ -377,6 +459,10 @@ interface Sync$1<Message, Shared> {
|
|
|
377
459
|
}
|
|
378
460
|
/** Structural match for `foldkit-durable`'s journal options; Sync stays independent. */
|
|
379
461
|
interface JournalContract<Operation, Shared> {
|
|
462
|
+
/** The replica each operation came from, which Durable binds to its first committer. */
|
|
463
|
+
readonly replicaId: (operation: Operation) => string;
|
|
464
|
+
/** Sync's operation id includes the replica, even after Durable compacts its payload. */
|
|
465
|
+
readonly legacyReplicaId: (opId: string) => string;
|
|
380
466
|
readonly operation: {
|
|
381
467
|
/** Operations are stored in their encoded form, so this is the identity. */
|
|
382
468
|
readonly encode: (operation: Operation) => Operation;
|
|
@@ -445,6 +531,12 @@ interface BaseOptions<Principal, Fields extends Schema$1.Struct.Fields, Ms exten
|
|
|
445
531
|
readonly replay?: (shared: Schema$1.Struct.Type<NoInfer<Fields>>, message: MsgOf<NoInfer<Ms>>) => Schema$1.Struct.Type<NoInfer<Fields>>;
|
|
446
532
|
/** Authorization the server journal applies before committing; see `AuthorizePolicy`. */
|
|
447
533
|
readonly authorize?: AuthorizePolicy<Principal, NoInfer<Fields>, NoInfer<Ms>>;
|
|
534
|
+
/**
|
|
535
|
+
* Merges a durable Message into the one submitted before it while that one is unsent,
|
|
536
|
+
* so a burst of edits is one operation. Replaying the result must equal replaying
|
|
537
|
+
* `last` then `next`; undefined keeps them apart.
|
|
538
|
+
*/
|
|
539
|
+
readonly coalesce?: (last: MsgOf<NoInfer<Ms>>, next: MsgOf<NoInfer<Ms>>) => MsgOf<NoInfer<Ms>> | undefined;
|
|
448
540
|
}
|
|
449
541
|
interface MakeOptions<AppModel, Fields extends Schema$1.Struct.Fields, Subset, Ms extends readonly MessageConstructor<any>[], Principal = unknown> extends BaseOptions<Principal, Fields, Ms> {
|
|
450
542
|
/** The writable projection of the shared fields. */
|
|
@@ -531,6 +623,21 @@ interface ApplicationSync<AppModel, F extends Schema$1.Struct.Fields, Cases exte
|
|
|
531
623
|
export declare const forApplication: <AppModel, F extends Schema$1.Struct.Fields, Cases extends Record<string, Schema$1.Struct.Fields>>(app: RunnableApplication<AppModel, F, Cases, any>) => ApplicationSync<AppModel, F, Cases>;
|
|
532
624
|
//#endregion
|
|
533
625
|
//#region src/mount.d.ts
|
|
626
|
+
/**
|
|
627
|
+
* A Command that dispatches `message` as the next transition, which under `Sync.mount`
|
|
628
|
+
* means within this one: the mount applies it straight after the `update` that returned
|
|
629
|
+
* it, and persists it if it is durable, before any other Message is processed. This is
|
|
630
|
+
* how a local intent turns into a durable fact that needs something only the intent's
|
|
631
|
+
* transition knows, such as an id minted from local state, without a later Message
|
|
632
|
+
* seeing the Model before the fact. Elsewhere, or once a parent has mapped the Command,
|
|
633
|
+
* it is an ordinary Command that yields `message`, and so is one a durable Message's
|
|
634
|
+
* update returns: replay would not apply it, and with derived replay the durable Message's
|
|
635
|
+
* persist fails with `ReplayError` as for any Command.
|
|
636
|
+
*/
|
|
637
|
+
export declare const fact: <Message>(message: Message) => {
|
|
638
|
+
readonly name: string;
|
|
639
|
+
readonly effect: Effect.Effect<Message>;
|
|
640
|
+
};
|
|
534
641
|
/**
|
|
535
642
|
* The URL as part of the application: `onUrlChange` names the Message the
|
|
536
643
|
* runtime sends for the current URL at start and on every navigation (so a
|
|
@@ -559,6 +666,15 @@ interface MountOptions<Model, Message, Shared, Resources> {
|
|
|
559
666
|
* has been reverted. Omitted, the edit is reverted silently.
|
|
560
667
|
*/
|
|
561
668
|
readonly onPersistenceFailure?: ((model: Model, error: ReplicaError) => Model) | undefined;
|
|
669
|
+
/**
|
|
670
|
+
* Runs when the mount replaces the shared slice outside `update`: an exchange committed,
|
|
671
|
+
* acknowledged or rejected something, or a persist failed and its edit was reverted.
|
|
672
|
+
* `previous` is the Model before; what it returns is the transition, so an application
|
|
673
|
+
* can carry local state across the change (a selection held by what it points at) or
|
|
674
|
+
* return Commands (a DOM the change has to reach). Omitted, the Model is `next`. It is
|
|
675
|
+
* not called for a status that changes nothing the Model shows, such as the first.
|
|
676
|
+
*/
|
|
677
|
+
readonly onReinstall?: ((next: Model, previous: Model) => Update.Return<Model, Message, Resources>) | undefined;
|
|
562
678
|
}
|
|
563
679
|
/**
|
|
564
680
|
* The shared slice as the server has confirmed it, outside the Model. It is a
|
|
@@ -625,6 +741,12 @@ interface PresenceOptions<Update> {
|
|
|
625
741
|
*/
|
|
626
742
|
readonly decodeValue: (value: unknown) => Update;
|
|
627
743
|
readonly channel?: PresenceChannel<Update> | undefined;
|
|
744
|
+
/**
|
|
745
|
+
* The least time between two values sent on the channel. `set` still takes effect here at
|
|
746
|
+
* once; a value set sooner waits, and only the latest one waiting is sent when the time is
|
|
747
|
+
* up. A departure is never held back. Absent, every `set` is sent at once.
|
|
748
|
+
*/
|
|
749
|
+
readonly throttle?: Duration.Input | undefined;
|
|
628
750
|
}
|
|
629
751
|
interface PresencePeer<Update> {
|
|
630
752
|
readonly id: string;
|
|
@@ -632,7 +754,7 @@ interface PresencePeer<Update> {
|
|
|
632
754
|
readonly updatedAt: number;
|
|
633
755
|
}
|
|
634
756
|
interface Presence<Update> {
|
|
635
|
-
/** Sets this peer's value and broadcasts it. */
|
|
757
|
+
/** Sets this peer's value and broadcasts it, no sooner than `throttle` allows. */
|
|
636
758
|
readonly set: (value: Update) => Effect.Effect<void>;
|
|
637
759
|
/** Removes this peer and broadcasts the departure. */
|
|
638
760
|
readonly leave: Effect.Effect<void>;
|
|
@@ -786,6 +908,11 @@ export declare const Sync: {
|
|
|
786
908
|
define: <Message, Shared, MessageEncoded, SharedEncoded>(definition: SyncDefinition<Message, Shared, MessageEncoded, SharedEncoded>) => Sync$1<Message, Shared>;
|
|
787
909
|
/** Runs a Foldkit application over an open replica with one reducer. */
|
|
788
910
|
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>>;
|
|
911
|
+
/** A Command whose Message the mount applies within the transition that returned it. */
|
|
912
|
+
fact: <Message>(message: Message) => {
|
|
913
|
+
readonly name: string;
|
|
914
|
+
readonly effect: import("effect/Effect").Effect<Message>;
|
|
915
|
+
};
|
|
789
916
|
/** Counters and a histogram an application can scrape. */
|
|
790
917
|
metrics: {
|
|
791
918
|
exchanges: import("effect/Metric").Counter<number>;
|
|
@@ -794,20 +921,21 @@ export declare const Sync: {
|
|
|
794
921
|
exchangePending: import("effect/Metric").Histogram<number>;
|
|
795
922
|
};
|
|
796
923
|
/** The only storage adapter: one IndexedDB database per document/replica. */
|
|
797
|
-
indexedDb: (name: string | import("effect/Config").Config<string>, factory?: IDBFactory | undefined) => import("effect/Effect").Effect<Storage
|
|
924
|
+
indexedDb: (name: string | import("effect/Config").Config<string>, factory?: IDBFactory | undefined) => import("effect/Effect").Effect<Required<Storage>, StorageError, import("effect/Scope").Scope>;
|
|
798
925
|
/** The `Transport` service's layers, and the bridges to and from a promise client. */
|
|
799
926
|
transport: {
|
|
800
927
|
/** A reconnecting WebSocket client layer. */
|
|
801
928
|
socket: (options: SocketOptions) => import("effect/Layer").Layer<Transport, TransportError>;
|
|
802
929
|
/** An in-process layer, for tests and single-process demos. */
|
|
803
|
-
loopback: (handler: (cursor: number, pending: ReadonlyArray<Operation
|
|
930
|
+
loopback: (handler: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>) => import("effect/Layer").Layer<Transport>;
|
|
804
931
|
/** Wraps the promise-based client the replica already speaks. */
|
|
805
932
|
fromPromise: (transport: TransportClient) => import("effect/Layer").Layer<Transport>;
|
|
806
933
|
/** Bridges the service back to that promise client. */
|
|
807
934
|
toPromise: (transport: TransportShape) => TransportClient;
|
|
808
935
|
/** The server side of one accepted socket connection. */
|
|
809
936
|
serve: (socket: SocketLike, options: {
|
|
810
|
-
readonly exchange: (cursor: number, pending: ReadonlyArray<Operation
|
|
937
|
+
readonly exchange: (cursor: number, pending: ReadonlyArray<Operation>, epoch?: string | undefined) => unknown | Promise<unknown>;
|
|
938
|
+
readonly changes?: ((listener: () => void) => () => void) | undefined;
|
|
811
939
|
}) => (() => void);
|
|
812
940
|
/** The default socket factory: the platform `WebSocket`. */
|
|
813
941
|
nativeSocket: (url: string) => SocketLike;
|
|
@@ -888,5 +1016,5 @@ export declare const Sync: {
|
|
|
888
1016
|
};
|
|
889
1017
|
};
|
|
890
1018
|
//#endregion
|
|
891
|
-
export type { ApplicationSync, AuthorizePolicy, AuthorizeRequest, Checkpoint, CommittedOperation, CommittedView, DefinedSync, Exchange, ExchangeFrame, ExchangeReply, FragmentMessages, JournalContract, LwwClock, LwwClockState, MakeOptions, MountOptions, MountUrl, Mounted, MsgOf, Operation, PolicyJournalContract, Presence, PresenceChannel, PresenceHub, PresenceOptions, PresencePeer, PresenceUpdate, Replica, ReplicaError, ReplicaSnapshot, ReplicaState, ReplicaStatus, SocketLike, SocketOptions, Storage, SyncDefinition, SyncFragment, TransportClient, TransportShape };
|
|
1019
|
+
export type { ApplicationSync, AuthorizePolicy, AuthorizeRequest, Checkpoint, CommittedOperation, CommittedView, DefinedSync, Exchange, ExchangeFrame, ExchangeReply, FragmentMessages, JournalContract, LwwClock, LwwClockState, MakeOptions, MountOptions, MountUrl, Mounted, MsgOf, NotifyFrame, Operation, OutboxEntry, PolicyJournalContract, Presence, PresenceChannel, PresenceHub, PresenceOptions, PresencePeer, PresenceUpdate, Replica, ReplicaError, ReplicaSnapshot, ReplicaState, ReplicaStatus, SocketLike, SocketOptions, Storage, SyncDefinition, SyncFragment, TransportClient, TransportShape };
|
|
892
1020
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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,MA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