Remote / foldkit-remote-server

LiveSource

interface · packages/remote-server/src/index.ts:903

interface LiveSource<P, R = never> {
  readonly entity: string
  subscribe(context: {
    readonly requirements: ReadonlyArray<Requirement>
    readonly queries: ReadonlyArray<LiveQuery<R>>
    readonly after: number
    readonly principal: P
    readonly viewer?: Option.Option<EntityRef> | undefined
  }): Stream.Stream<Schema.Schema.Type<typeof LiveChange>, RemoteServerError, R>
  readonly reads?: EntitySource<P, R> | undefined
}

In the guides

Members

LiveSource.entity

property · packages/remote-server/src/index.ts:904

readonly entity: string

LiveSource.subscribe

method · packages/remote-server/src/index.ts:915

subscribe(context: {
  readonly requirements: ReadonlyArray<Requirement>
  readonly queries: ReadonlyArray<LiveQuery<R>>
  readonly after: number
  readonly principal: P
  readonly viewer?: Option.Option<EntityRef> | undefined
}): Stream.Stream<Schema.Schema.Type<typeof LiveChange>, RemoteServerError, R>

Called by handlers only with requirements it has admitted: no more distinct ids of one entity than maxIdsPerEntity (a live list's first counted with them), and no more pages of one relation than a read may ask. A larger subscription is refused with RemoteLiveRefused before any live source is asked.

A method, not a function property: queries carries R into the parameter, which would make a source of R = never no LiveSource<any, any>.

LiveSource.reads

property · packages/remote-server/src/index.ts:930

readonly reads?: EntitySource<P, R> | undefined

The entity source every value it sends is read through, as RemoteServer.readAs reads (pollLive sets it). The server never reads it: a startup check such as GuardServer.validate does, to accept a live source over the source it has checked.