Sync / foldkit-sync/journal

EditsJournalOptions

interface · packages/sync/src/journal.ts:281

interface EditsJournalOptions<Shared, Principal, Change> {
  readonly documentId: string
  readonly journal: Journal<Operation, Shared, Principal, Operation>
  readonly editsOf: (operation: Operation) => Option.Option<{
    readonly changes: ReadonlyArray<Change>
    readonly at: Option.Option<number>
  }>
  readonly apply: (change: Change, at: number) => Effect.Effect<void, unknown>
  readonly tableRevision: Effect.Effect<number, unknown>
  readonly holdsThrough: (snapshot: Shared, through: number) => boolean
  readonly absorbed: (through: number, cursor: number) => Operation
  readonly server: Principal
}

Members

EditsJournalOptions.documentId

property · packages/sync/src/journal.ts:283

readonly documentId: string

The document whose edits the table reads.

EditsJournalOptions.journal

property · packages/sync/src/journal.ts:285

readonly journal: Journal<Operation, Shared, Principal, Operation>

The journal the edits commit to.

EditsJournalOptions.editsOf

property · packages/sync/src/journal.ts:291

readonly editsOf: (operation: Operation) => Option.Option<{
  readonly changes: ReadonlyArray<Change>
  readonly at: Option.Option<number>
}>

The cells an operation edits, with the sequence its stamp wrote in; none for an operation that edits nothing. An edit committed without a sequence is not this journal's: its intents fail rather than write revision 0.

EditsJournalOptions.apply

property · packages/sync/src/journal.ts:306

readonly apply: (change: Change, at: number) => Effect.Effect<void, unknown>

Writes one committed change to the table, with the sequence it committed at. It runs as a recovery intent, so it may run again after a crash: it must never move a row back (revision <= at). A failure stops recovery there, and the next settle tries it again.

It cannot refuse an edit: the edit has committed. One naming a row the table lacks is refused at commit instead, by the journal's validate, so its sender is told; let through, it would change nothing and vanish once absorbed.

EditsJournalOptions.tableRevision

property · packages/sync/src/journal.ts:313

readonly tableRevision: Effect.Effect<number, unknown>

The highest revision the table holds. Settling refuses to start while it is past the journal's cursor (TableAheadOfJournalError), since every edit would then be skipped and counted absorbed; it asks again on each settle until the two agree.

EditsJournalOptions.holdsThrough

property · packages/sync/src/journal.ts:315

readonly holdsThrough: (snapshot: Shared, through: number) => boolean

Whether the snapshot still keeps an edit committed through through: whether to absorb.

EditsJournalOptions.absorbed

property · packages/sync/src/journal.ts:321

readonly absorbed: (through: number, cursor: number) => Operation

The server's operation saying the table holds every edit through through, sequenced from cursor, the journal's: the replicas drop those edits on hearing it.

EditsJournalOptions.server

property · packages/sync/src/journal.ts:323

readonly server: Principal

Who the server commits absorbed as; the contract's authorize should let only it.