Remote / foldkit-remote-domain
Bind paged lists and one relations
DomainRemote.query connects a Remote Query to a paged Domain Query: Domain chooses the matching row ids and cursor order, and the adapter fetches each listed row through its bound View (dropping any row the View's validate hides):
ts
import { Query } from 'foldkit-remote'
const Stocked = Query.define('Stocked', { shelf: Schema.String }, () =>
Query.from(Product).pipe(
Query.where(Expr.gt(Product.fields.stock, Expr.field(Product.fields.reserved))),
Query.orderBy(Order.asc(Product.fields.id)),
),
)
const Listed = DomainRemote.query(Stocked, ShopApi, 'InStock', {
input: input => ({ shelf: input.shelf }),
id: entry => entry.id,
})
DomainRemote.layer(ShopApi, { views: [Products], commands: [], queries: [Listed], principal, denied })Key list and relation rules:
- Forward-only paging:
firstmaps to Domain'stakeandafterto Domain's cursor. Backward windows (last,before),first: 0, and cursors over 1,024 characters are rejected. - Write answers refresh affected lists: when a write specifies
MutationRequest.lists, the adapter reads each list at the write's receipt (atLeast), omitting lists that have not caught up withinconfirmWithin. - Live lists: opening a stream sends one
ConnectionInvalidate, then watches every listed row and re-queries 50 ms after a row changes. Rows joining without modifying a currently listed row appear on the next read. onerelations: stored as target id ornullin View state, returned as Remote ref keys ('Supplier:s1'), and batch-fetched once per target.manyrelations and relation windows fail withRemoteReadError.