@danielhritcu/zenstack-custom
v1.2.64
Published
ZenStack codegen pipeline and Drizzle helpers for custom ORM schema generation
Readme
ZenStack codegen (Drizzle → ZenStack schema)
Reads Drizzle table/view/enum definitions plus a TypeScript config file and emits a ZenStack v3 schema together with companion type files (typed JSON shapes, branded ids, Zod validation, relation metadata) consumed by the ZenStack ORM runtime.
Drizzle is the source of truth for the database. There is no .zmodel file — configuration is
plain TypeScript.
Install
pnpm add -D @danielhritcu/zenstack-custom tsxtsx is required to load a .ts config file.
Generate
npx zen-orm generate ./zen.config.ts [--ignore-cfk=app_slug]Set ZEN_STRICT_TYPED_JSON=1 to fail the build when a $type<>() annotation cannot be lowered into
a typed shape (it otherwise degrades to raw Json with a warning).
Config
import { defineConfig, defineRls } from '@danielhritcu/zenstack-custom/codegen';
import * as t from './supabase/schema/tables';
import * as enums from './supabase/schema/enums';
export default defineConfig(t, {
schema: { enums, types: './supabase/schema/types.ts', output: './src/zenstack' },
default: { where: { deletedAt: null } },
models: (orm) => ({ /* per-table relations, scopes, derived fields, validation */ }),
});Exports
.— everything re-exported./codegen—defineConfig,defineRls, the DSL, and the emit/discover/typed-JSON functions./drizzle—pgOrmEnum,toPgEnum,ENUM_MAP./cli—runCodegen()for programmatic generation
For AI agents
See AGENTS.md — it covers the non-obvious behaviour (typed-JSON key mapping,
jsonArray vs array, nullability rules, hardcoded scanner paths) that is easy to get wrong.
