@drzl/generator-effect
v0.5.4
Published
Generate Effect Schema validators from a Drizzle schema
Readme
@drzl/generator-effect
Effect Schema validators from your Drizzle analysis (insert / update / select).
💚 Sponsor DRZL
DRZL is crafted nights & weekends. Sponsorships keep the generators fast, tested, and free.
- Every dollar speeds up CI hardware and offsets long test runs on my aging laptop.
- Sponsors get roadmap input and priority responses in GitHub Issues.
- Prefer a quick overview? The current goals and thank-yous are at https://use-drzl.github.io/drzl/sponsor.
Install
effect is an optional peer, so it is never installed for you. Install it yourself:
npm install effecteffect 3.x, imported as effect/Schema from core. Not @effect/schema, which stopped at 0.75.5
and predates the move into core, and not the 4.0 beta. The floor is 3.13.0, where
Schema.standardSchemaV1 first appears.
The peer is optional rather than required because [email protected] declares its own optional
peer on effect as >=4.0.0-beta.83 || >=4.0.0, and npm installs a required peer automatically.
Declaring one made npm install @drzl/cli [email protected] fail with ERESOLVE for every
consumer, whether or not they used this generator.
Use
Add to drzl.config.ts:
generators: [{ kind: 'effect', path: 'src/validators/effect' }];Output
Insert<Table>Schema,Update<Table>Schema,Select<Table>Schemaas plainSchema.StructsStandard<Name>beside each:Schema.standardSchemaV1(<Name>), which is what a tRPC or oRPC route needs, since a bareSchema.Structcarries no~standardkeyInsert<Table>Input,Update<Table>Input,Select<Table>Outputtype aliases- Optional
indexbarrel, nested relation schemas and a duplicate finder
Both forms are emitted because neither substitutes for the other: the wrapper is the only one with
a ~standard, and the bare Struct is the only one that keeps .fields, which Schema.pick,
Schema.omit and a spread into a wider Struct all read.
Custom names
affix renames the exported schemas and type aliases, and tableCase: 'pascal' upper-camels
the Drizzle export name (users -> Users) instead of interpolating it verbatim. Omit it and
the names above are unchanged. The Standard prefix sits in front of whatever the affix resolved,
so StandardInsertUsersSchema wraps InsertUsersSchema.
generators: [
{
kind: 'effect',
path: 'src/validators/effect',
affix: {
tableCase: 'pascal',
schema: { suffix: 'Schema' },
type: {
prefix: { insert: 'Create', update: 'Edit', select: '' },
suffix: { insert: 'Input', update: 'Input', select: '' },
},
},
},
];See the Effect generator docs for the column table, the
character-count rule and how NaN and the infinities are handled, which runs the opposite way here
from every other validator DRZL emits.
