@mdht/generator-core
v0.2.0
Published
Shared IR builder over the ZModel AST, used by schema-codegen-bridge's generator plugins so none of them re-implements AST traversal.
Readme
@mdht/generator-core
The shared ZModel AST → intermediate representation used by the Schema Codegen Bridge plugins. Use it when building a ZenStack generator that should agree with the Jazz, ts-rest, and BetterAuth outputs without reimplementing AST traversal.
Install
npm install @mdht/generator-coreAPI
import { buildIr } from '@mdht/generator-core';
import type { CliPlugin } from '@zenstackhq/sdk';
const plugin: CliPlugin = {
name: 'My generator',
generate({ model }) {
const ir = buildIr(model);
for (const dataModel of ir.models) {
console.log(dataModel.name, dataModel.fields);
}
},
};
export default plugin;buildIr(model) returns:
interface Ir {
models: Array<{
name: string;
fields: Array<
| { kind: 'scalar'; name: string; scalarType: string; isList: boolean; isOptional: boolean }
| { kind: 'enum'; name: string; enumName: string; isList: boolean; isOptional: boolean }
| { kind: 'relation'; name: string; relationTarget: string; isList: boolean; isOptional: boolean }
>;
}>;
enums: Array<{ name: string; values: string[] }>;
}Mixin-owned fields are included through ZenStack's ModelUtils.getOwnedFields.
Unsupported database-native types remain explicit as Unsupported; they are not
silently reported as strings.
Requirements
- Node.js 22.6 or newer
- ZenStack 3.9.x
See the repository for the complete generator suite and verified example.
License
MIT
