Sync / foldkit-sync

Storage

interface · packages/sync/src/indexedDb.ts:19

interface Storage {
  load: () => Effect.Effect<unknown, StorageError>
  save: (
    state: unknown,
    expectedRevision: number | null,
  ) => Effect.Effect<void, StorageError>
  append?: (
    entry: OutboxEntry,
    expectedRevision: number,
  ) => Effect.Effect<void, StorageError>
  close: Effect.Effect<void>
}

Persists a replica's state with compare-and-swap on its revision.

In the guides

Members

Storage.load

property · packages/sync/src/indexedDb.ts:24

load: () => Effect.Effect<unknown, StorageError>

The saved state, with every operation appended since in its pending (replacing the one of the same local sequence), and the last one's revision and nextLocalSequence.

Storage.save

property · packages/sync/src/indexedDb.ts:26

save: (state: unknown, expectedRevision: number | null) =>
  Effect.Effect<void, StorageError>

Replaces the whole state, and with it every appended operation.

Storage.append

property · packages/sync/src/indexedDb.ts:32

append?: (
  entry: OutboxEntry,
  expectedRevision: number,
) => Effect.Effect<void, StorageError>

Optional. Records one submitted operation without rewriting the rest of the state, so a submit costs the operation's size rather than the document's. Without it, a submit saves the whole state.

Storage.close

property · packages/sync/src/indexedDb.ts:34

close: Effect.Effect<void>

Idempotent; the caller closes the connection explicitly.