Remote / foldkit-remote-drizzle

foldkit-remote-drizzle

Provisional. A Drizzle compiler for foldkit-remote and foldkit-remote-server.

A Remote client already knows which semantic fields it needs. A RemoteServer Source already knows which ids and authorized fields to load. foldkit-remote-drizzle turns that Source request into the smallest useful Drizzle query, then turns the rows back into normalized Remote patches.

Remote Selection
      |
      v
Remote requirement
  Project:p1 [id,name]
      |
      v
RemoteServer Source context
  ids=[p1]
  fields=[id,name]
      |
      v
foldkit-remote-drizzle
  SELECT id,name
  FROM projects
  WHERE id IN (...)
      |
      v
normalized patch
  Project:p1 { id, name }

The important design choice is that an Entity is declared once:

ts
const Project = entity('Project', projects)

That value is both the Drizzle binding and the Remote EntityDescriptor. A Selection therefore checks fields against the real table declaration, while source(Project) can compile those same semantic fields back into SQL without a second mapping per screen.

Use this package when your Remote entities map cleanly onto Drizzle tables and you want projection, relation loading, and keyset pagination derived from the Remote contract. It is not an ORM on top of Drizzle and it does not own the database connection. Sources require a DrizzleDatabase Effect service supplied by the application.

What it owns

foldkit-remote
  semantic Entity / Selection / Query
             |
             v
foldkit-remote-server
  authorized Source request
             |
             v
foldkit-remote-drizzle
  columns / joins / pagination SQL
  row -> Remote normalization
             |
             v
Drizzle
  database execution

It does not own:

  • client caching or rendering;
  • Remote field authorization policy itself;
  • authentication;
  • mutation semantics;
  • a database connection;
  • arbitrary aggregate/query DSLs.

Those boundaries are deliberate. The adapter compiles Remote's existing semantics instead of introducing a second data model.

Install

bash
pnpm add foldkit-remote-drizzle drizzle-orm

effect and drizzle-orm (currently 1.0.0-rc.4) are peer dependencies, so the adapter reads the tables you define with your own Drizzle, not a copy of its own; foldkit-remote and foldkit-remote-server come with the package.

For the ownership and requirement-planning model first, read Server-derived state.