Composition / foldkit-composition/remote

QueryBlock

namespace · packages/composition/src/remote/index.ts:77

const QueryBlock = { define, active, reads }

Its type

type QueryBlock<
  Name extends string,
  Props extends Schema.Top,
  Regions extends Readonly<Record<string, Region>>,
  Value,
> = Block<Name, Props, Regions> & {
  readonly rows: (data: unknown) => RemoteData<Page<Value>>
}

A Block whose content is a page of a query's rows.

In the guides

Members

QueryBlock.define

function · packages/composition/src/remote/index.ts:83

define<
  const Name extends string,
  Props extends Schema.Top,
  Q extends QueryDescriptor<any, any, any>,
  Value,
  Entity extends string,
  const Regions extends Readonly<Record<string, Region>> = {},
>(
  name: Name,
  config: {
    readonly Props: Props
    readonly regions?: Regions
    readonly provides: ReadonlyArray<Content>
    readonly query: Q
    readonly input: (props: Props['Type']) => QueryInput<Q>
    readonly select: EntitySelection<Value, Entity> &
      SelectsEntity<Entity, QueryEntity<Q>>
    readonly first?: (props: Props['Type']) => number
  },
): QueryBlock<Name, Props, Regions, Value>

A Block reading a page of query: input from its props, select of each row, and first rows. The query must be registered with the Remote domain that reads the page.

QueryBlock.active

function · packages/composition/src/remote/index.ts:131

active<AppModel>(
  name: string,
  owner: object,
  data: QueryReader<AppModel>,
  catalog: Catalog,
  documentOf: (model: AppModel) => Option.Option<Document>,
): QueryReads<AppModel>

The page's reads as an active Surface of the application owner (App.owner), for Data.wiring, Data.subscriptions or an SSR plan's surfaces: active while documentOf gives a page, reading its Query Blocks. Remote.resume(Data) then carries what they read.

QueryBlock.reads

function · packages/composition/src/remote/index.ts:167

reads<AppModel>(
  data: QueryReader<AppModel>,
  catalog: Catalog,
  document: Document,
): Option.Option<
  Projection<AppModel, Readonly<Record<string, RemoteData<unknown>>>>
>

Every Query Block on the page as one Projection over the Model, keyed by node id; none when the page has none. A node whose props do not decode, or whose Block the Catalog lacks, reads nothing.