Metakit / Prune SSR payloads and gate queries
Gate dependent queries (queryReadiness)
For a cascading filter over { row, params }, queryReadiness(expr, partialEnv) (from @doeixd/metakit/graph/readiness) fills in the choices you have. The residual is the filter simplified by those choices. It is ready by default once its remaining reads are row fields and its expression can be lowered to SQL pieces.
To check a specific renderer, pass a prepare function that sends the residual to Sql.toWhere or Drizzle.toWhere with your configuration. Readiness then includes the renderer's checks for foreign operations, columns and relation mappings. missing lists any unbound parameters. Once they are bound, unsupported gives the reason preparation refused the filter.
ts
import { Result } from 'effect'
import { queryReadiness } from '@doeixd/metakit/graph/readiness'
import * as Sql from '@doeixd/metakit/sql'
const City = Schema.Struct({ id: Schema.String, countryId: Schema.String, regionId: Schema.String })
const Params = Schema.Struct({
all: Schema.Boolean,
countryId: Schema.String,
regionId: Schema.String,
})
const filter = Expr.in({ row: City, params: Params }, ({ row, params }) =>
Expr.any(
Eq.is(params.all, true),
Expr.all(Eq.is(row.countryId, params.countryId), Eq.is(row.regionId, params.regionId)),
),
)
const step1 = queryReadiness(filter, { params: { countryId: 'US' } })
// step1 -> { ready: false, missing: Some([['params', 'all'], ['params', 'regionId']]),
// unsupported: None, residual }
const step2 = queryReadiness(filter, { params: { all: true } })
// step2 -> { ready: true, residual } (`all` is true, so countryId and regionId are not required)
const prepare = (residual: typeof filter) => Sql.toWhere(residual, { dialect: 'postgres' })
const step3 = queryReadiness(
filter,
{ params: { all: false, countryId: 'US', regionId: 'CA' } },
{ prepare },
)
if (step3.ready) {
const where = Result.getOrThrow(prepare(step3.residual))
// where.params -> ['US', 'CA']
void where
}
void Option.isSome(analysis.liveModelPaths)
void pruned
void step1
void step2Next
- Prove the machines you analyze here: Verify a state machine in CI.
- Expose a machine's transitions to an AI assistant: Let an agent call your state machine's transitions.