Sync / foldkit-sync/journal

EditsJournalOptions

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

interface EditsJournalOptions<Shared, Principal, Change, Absorbed = never> {
  readonly documentId: string
  readonly journal: Journal<Operation, Shared, Principal, WrittenOperation>
  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 asServer?:
    | {
        readonly journal: ServerJournal<Absorbed, any>
        readonly absorbed: (through: number) => Absorbed
      }
    | undefined
  readonly absorbed?:
    ((through: number, cursor: number) => WrittenOperation) | undefined
  readonly server?: Principal | undefined
}

Members

EditsJournalOptions.documentId

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

readonly documentId: string

The document whose edits the table reads.

EditsJournalOptions.journal

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

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

The journal the edits commit to.

EditsJournalOptions.editsOf

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

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:612

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:619

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:621

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

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

EditsJournalOptions.asServer

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

readonly asServer?:
  | {
      readonly journal: ServerJournal<Absorbed, any>
      readonly absorbed: (through: number) => Absorbed
    }
  | undefined

Records that the table holds every edit through through, as the server: absorbed(through) is the server-only Message the replicas drop those edits on hearing, appended under the key absorbed/<through>. The log is compacted no further than the server journal's settledThrough, so its reactions see every commit first.

EditsJournalOptions.absorbed

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

readonly absorbed?:
  ((through: number, cursor: number) => WrittenOperation) | undefined
@deprecated

Declare the Message serverOnly and pass asServer; removed in the next release. The server's operation saying the table holds every edit through through, sequenced from cursor, the journal's, appended as written.

EditsJournalOptions.server

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

readonly server?: Principal | undefined
@deprecated

With absorbed: who the server commits it as.