Skip to main content

Function: generateSchemaLiteFile()

generateSchemaLiteFile(schemaImportPath, exportName, info): string | null

Defined in: packages/codegen/src/schema-lite-codegen.ts:103

Generate the content of a .lite.ts file that reconstructs a lite Zod schema from the imported schema's check objects at runtime. Returns null when no schemaLite is needed (no top-level effects were detected).

Parameters

schemaImportPath

string

Module specifier for the original schema file (e.g. './schema').

exportName

string

The named schema export (e.g. 'UserSchema').

info

SchemaLiteInfo

Metadata from WalkResult.schemaLiteInfo describing what to reconstruct.

Returns

string | null

The complete .lite.ts file source, or null if no lite schema is needed.

Remarks

Three reconstruction strategies based on info.type:

  • 'original' — re-exports the original schema unchanged (non-decomposable pipes)
  • 'checks' — slices _zod.def.checks at runtime to extract superRefine/refine checks
  • 'transform' — extracts both inner checks and the transform function from a pipe wrapper Fallthrough fields are included in the base object via shape references into the original schema.

Example

const liteSource = generateSchemaLiteFile('./schema', 'UserSchema', schemaLiteInfo);
if (liteSource) {
await writeFile('./UserForm.lite.ts', liteSource, 'utf8');
}