Remote / foldkit-remote/maintained

Maintained

namespace · packages/remote/src/maintained/definition.ts:6

export * as Maintained from './definition.js'

foldkit-remote/maintained: a value over the rows of a loaded list (a total, a minimum, the rows themselves) kept up to date from the rows that changed rather than worked out from all of them again (#580).

In the guides

Members

Maintained.Definition

type · packages/remote/src/maintained/definition.ts:43

type Definition<Row> =
  | ListAggregate<Row>
  | ListDefinition
  | ReduceDefinition<Row, unknown>
  | JoinDefinition<Row>

What a maintained value keeps: a @doeixd/metakit/aggregates value, reduce, join, or list.

Maintained.join

function · packages/remote/src/maintained/join.ts:33

function join<Row>(
  targetOf: (row: Row) => string | null | undefined,
): JoinDefinition<Row>

Define a maintained join grouping rows by the target id returned by targetOf.

Maintained.JoinDefinition

interface · packages/remote/src/maintained/join.ts:13

interface JoinDefinition<Row> {
  readonly _tag: 'Join'
  readonly targetOf: (row: Row) => string | null | undefined
}

Maintained.JoinedRows

interface · packages/remote/src/maintained/join.ts:23

interface JoinedRows<Row> {
  readonly targetCount: number
  readonly forTarget: (targetId: string) => ReadonlyArray<Row>
}

Live reverse-indexed view of grouped rows: forTarget reads the maintained ReverseIndex for the latest Maintained.value read, so callers should not retain old JoinedRows references as historical point-in-time snapshots.

Maintained.list

const · packages/remote/src/maintained/definition.ts:40

const list = { _tag }

The counted rows in the loaded connection's order. where picks which rows count. The array is the same object while no row of it changed, and each row is the same object while its fields are, so a view over one row is not drawn again when another changes.

Maintained.ListDefinition

interface · packages/remote/src/maintained/definition.ts:30

interface ListDefinition {
  readonly _tag: 'List'
}

The counted rows in the loaded connection's order.

Maintained.MaintainedValue

interface · packages/remote/src/maintained/definition.ts:70

interface MaintainedValue<A> {
  readonly value: A
  readonly complete: boolean
}

A maintained value over every row the client has loaded for the list's query and input, as filtered is: not the rows that exist, and not the window the read given as over shows (a read asking first: 25 of a list holding 50 rows shows 25; the value is over the 50).

complete is filtered's. It is false when a loaded row could not be judged by where, when a counted row lacks a field the list selects, when the server has not said the loaded rows reach the start and the end, or when a gap lies between loaded pages; the value is then over the rows that could be counted.

Maintained.reduce

function · packages/remote/src/maintained/reduce.ts:41

function reduce<Row, V>(
  op: AnyOperation,
  pick: (row: Row) => V | null | undefined,
  implementations: OperationImplementations,
  options?: ReduceOptions,
): ReduceDefinition<Row, V>

Define a maintained fold over a custom @doeixd/metakit/operation commutative monoid. Refuses at definition time if op does not claim commutative: true, associative: true, and an identity.

Maintained.ReduceDefinition

interface · packages/remote/src/maintained/reduce.ts:18

interface ReduceDefinition<Row, V> {
  readonly _tag: 'Reduce'
  readonly op: AnyOperation
  readonly pick: (row: Row) => V | null | undefined
  readonly implementations: OperationImplementations
  readonly rewritePolicy: Expr.ForeignRewritePolicy | undefined
}

Maintained.ReduceOptions

interface · packages/remote/src/maintained/reduce.ts:27

interface ReduceOptions {
  readonly rewritePolicy?: Expr.ForeignRewritePolicy
}

What reduce reads the operation's claims under: Expr.RewritePolicy.verified(evidence) or trusted.

Maintained.value

function · packages/remote/src/maintained/definition.ts:192

function value<
  Domain extends AnyDomain,
  Row,
  Name extends string,
  Input,
  D extends Definition<Row>,
>(
  domain: Domain,
  model: ModelOfDomain<Domain>,
  over: QueryProjection<ModelOfDomain<Domain>, Row, Name, Input>,
  definition: D,
): MaintainedValue<ValueOf<D, Row>>
function value<
  Domain extends AnyDomain,
  Row,
  Name extends string,
  Input,
  D extends Definition<Row>,
  Q extends QueryDescriptor<any, any, any>,
>(
  domain: Domain,
  model: ModelOfDomain<Domain>,
  over: QueryProjection<ModelOfDomain<Domain>, Row, Name, Input>,
  definition: D,
  where: MaintainedWhere<
    Q & Registered<Q['name'], QueryNames<Domain>, 'Query'>
  >,
): MaintainedValue<ValueOf<D, Row>>

A value over the rows of a loaded list, decoded as the list decodes them: the rows where matches, or every row without it. Pass a definition made once at module scope to keep its value between reads.

The value is kept between calls and changed by the rows that changed since the last: a row written, a pending write shown or rolled back, a row entering or leaving where. A live echo of a pending write changes nothing shown, so it changes nothing kept. sum and count update the total from each change and recompute if an intermediate total overflows. every and any keep a count of the rows holding. min and max fold a row in, and read the counted rows again only when the row holding the extreme leaves or loses it. What cannot be traced to writes (a hydrated snapshot, a change of who is viewing, any store change when where or the Selection reads other rows) reads every row again and compares each with what was kept. A change to the list itself (a page merged, a refetch) or a pending write over it compares the list's keys, and judges only rows not judged before.

Asks the server nothing and creates no connection: complete says whether the answer is about the whole list.

Maintained.ValueOf

type · packages/remote/src/maintained/definition.ts:50

type ValueOf<D, Row> = D extends ListDefinition
  ? ReadonlyArray<Row>
  : D extends ReduceDefinition<Row, infer V>
    ? V
    : D extends JoinDefinition<Row>
      ? JoinedRows<Row>
      : AggregateValue<D>

What a definition gives over rows of type Row.