Sync / foldkit-durable

Pairing with foldkit-sync

When backing a foldkit-sync contract, pass ...contract.journalContract() to Journal.make so Durable reuses the Sync contract's codecs, empty snapshot, reducer, replica binding, and authorization rules directly:

ts
import { DocumentId as SyncDocumentId, Sync } from 'foldkit-sync'

const TodoSync = Sync.define({
  documentId: SyncDocumentId.make('todos'),
  message: Schema.Struct({ _tag: Schema.Literal('Renamed'), title: Schema.String }),
  shared: Schema.Struct({ titles: Schema.Array(Schema.String) }),
  empty: { titles: [] },
  durable: () => true,
  replay: shared => shared,
})

const syncedProgram = Effect.gen(function* () {
  const journal = yield* Journal.make({
    ...TodoSync.journalContract(),
    file: 'todos.sqlite',
    opId: operation => OpId.make(operation.opId),
    actorId: (principal: Principal) => ActorId.make(principal.actorId),
  })

  return yield* journal.load(DocumentId.make('todos'))
}).pipe(Effect.scoped)

Your Foldkit application owns Model, Message, and update; foldkit-sync owns what is shared and durable; foldkit-durable owns commit ordering and SQLite storage. Pair this journal with serveJournal from foldkit-sync/journal to speak the Sync wire protocol; see Replicated state.