Remote / foldkit-remote/persistence

RemotePersistence

namespace · packages/remote/src/persistence.ts:613

const RemotePersistence = {
  dehydrate,
  hydrate,
  snapshotOf,
  mergeStores,
  hydrated,
  emptySnapshot,
  save,
  restore,
}

In the guides

Members

RemotePersistence.dehydrate

function · packages/remote/src/persistence.ts:527

dehydrate(
  snapshot: Snapshot,
  options?: ClockedOptions & {
    readonly maxBytes?: undefined
  },
): string
dehydrate(snapshot: Snapshot, options?: ClockedOptions): string | undefined

The snapshot text, or undefined when it would exceed maxBytes.

RemotePersistence.hydrate

function · packages/remote/src/persistence.ts:560

hydrate(
  raw: string | undefined | null,
  options?: ClockedOptions,
): Option.Option<Snapshot>

What a snapshot text holds, or none when it is refused.

RemotePersistence.snapshotOf

function · packages/remote/src/persistence.ts:123

snapshotOf(
  model: Snapshotted,
  options?: {
    readonly connections?: ReadonlyArray<ConnectionIdentity> | undefined
    readonly maxAge?: number | undefined
  },
): Snapshot

What to keep of a Model, naming the connections that should survive a reload and how long a read lasts. Naming none is the default and is what Remote always did.

RemotePersistence.mergeStores

function · packages/remote/src/store.ts:339

mergeStores(
  current: EntityStore,
  snapshot: EntityStore,
  policy: MergePolicy,
): EntityStore

A snapshot's entities brought into a store by policy.

RemotePersistence.hydrated

function · packages/remote/src/persistence.ts:590

hydrated(
  snapshot: Snapshot,
  options: {
    readonly merge: MergePolicy
    readonly from?: string | undefined
  },
): Extract<
  RemoteMessage,
  {
    readonly _tag: 'Hydrated'
  }
>

The Hydrated Message that brings a snapshot into the Model.

RemotePersistence.emptySnapshot

const · packages/remote/src/persistence.ts:606

emptySnapshot: Snapshot

The cache as a fresh session has it; what a refused restore yields.

RemotePersistence.save

function · packages/remote/src/persistence.ts:637

save(
  snapshot: Snapshot,
  options: {
    readonly key: string
  } & SnapshotOptions,
): Effect.Effect<
  void,
  KeyValueStore.KeyValueStoreError,
  KeyValueStore.KeyValueStore
>

Writes the snapshot under key, without what has expired by the Clock and within maxBytes, or removes the key when not even that fits, so a stale smaller snapshot cannot outlive a larger store it no longer describes.

RemotePersistence.restore

function · packages/remote/src/persistence.ts:652

restore(
  options: {
    readonly key: string
  } & SnapshotOptions,
): Effect.Effect<
  Snapshot,
  KeyValueStore.KeyValueStoreError,
  KeyValueStore.KeyValueStore
>

Reads the cache, without what has expired by the Clock. A missing key yields emptySnapshot; anything hydrate refuses yields emptySnapshot and removes the key, so the next restore is clean and the planner refetches.