Remote / foldkit-remote-drizzle

source

function · packages/remote-drizzle/src/index.ts:496

function source<P = unknown, B extends AnyEntityBinding = AnyEntityBinding>(
  binding: B,
  options?: {
    readonly authorize?:
      EntitySource<P, DrizzleDatabase>['authorize'] | undefined
    readonly filter?: EntitySource<P, DrizzleDatabase>['filter'] | undefined
    readonly shared?: ReadonlyArray<string> | undefined
    readonly policies?:
      | Readonly<
          Record<string, ((principal: P) => SQL | undefined) | undefined>
        >
      | undefined
    readonly maxCollection?: number | undefined
    readonly revision?: (keyof B['fields'] & string) | undefined
  },
): EntitySource<P, DrizzleDatabase>

A RemoteServer.entity source backed by the DrizzleDatabase service. It selects the requested columns in one batch, then resolves each selected relation: a one relation becomes a ref key, and a many relation loads the target ids in one statement, at most options.maxCollection (100) a row unless the read asks a window: a row holding more is refused, as a whole list cannot say it was cut short. options.policies adds a principal-scoped filter to a collection relation (e.g. only rows this principal may see), and options.filter decides what a principal sees of each record, as RemoteServer.entity's does.

A Derived.exists of the binding is answered for whoever reads, as the server it is mounted in says (RemoteServer.make's viewer), which is refused without one; a read made outside a server is refused it.