Remote / foldkit-remote-drizzle

WriteLedger

interface · packages/remote-drizzle/src/index.ts:1119

interface WriteLedger<P> {
  readonly table: Table & {
    readonly scope: AnyColumn
    readonly operation: AnyColumn
    readonly target: AnyColumn
    readonly answer: AnyColumn
    readonly at: AnyColumn
    readonly request: AnyColumn
  }
  readonly scope: (principal: P) => string
  readonly retention?: number
}

Where a writer records each update and insert it lands, by the operation that asked for it, so a retry of that operation is answered from the record rather than written again. Without one, a create of an id already taken is refused, retry or not. A table the application migrates:

sql
create table write_ledger (
  scope text not null, operation text not null, target text not null,
  answer text not null, at bigint not null, request text,
  primary key (scope, operation, target)
);
create index write_ledger_at on write_ledger (at);

target is the row (Entity:id), so one operation that updates two rows records each, and an operation id sent again for another row is not that row's retry. at is milliseconds, past a Postgres integer. request is a SHA-256 digest of what the operation asked (its mutation, keys and input): an operation id sent again with another request is refused rather than answered as a retry. A ledger made before it gains the column with alter table write_ledger add column request text; a record without one is answered as a retry, as before, until its retention passes.

Members

WriteLedger.table

property · packages/remote-drizzle/src/index.ts:1121

readonly table: Table & {
  readonly scope: AnyColumn
  readonly operation: AnyColumn
  readonly target: AnyColumn
  readonly answer: AnyColumn
  readonly at: AnyColumn
  readonly request: AnyColumn
}

The ledger table, its columns named scope, operation, target, answer, at and request.

WriteLedger.scope

property · packages/remote-drizzle/src/index.ts:1130

readonly scope: (principal: P) => string

Whose operations they are (a principal's key), so no one is answered with another's write.

WriteLedger.retention

property · packages/remote-drizzle/src/index.ts:1132

readonly retention?: number

How long an answer is kept, in milliseconds: a day unless given. A later retry is new.