/** * Converts the TypeScript type text carried by a PJTG `![...]` annotation into * a Zod expression string. * * Two rules govern everything here: * * 1. **Never half-convert.** Any construct outside the documented subset makes * the whole conversion fail with a reason. A wrong Zod schema rejects valid * production data at runtime, which is far worse than an unconverted field. * * 2. **Never emit the postfix `X.array()` form.** The CRUD emitter appends its * list wrapper only when the expression does not already contain the * substring `.array()`, so an expression carrying it silently loses a * dimension. Arrays are always emitted as `z.array(X)`. * * The parser is a hand-written recursive-descent parser over a small token * stream. It is deliberately not TypeScript's own parser: pulling in the * compiler API to read a dozen characters out of a doc comment is not a trade * this generator should make, and the supported grammar is tiny. */ /** How a bare type reference (`WorkflowNode`) resolves to a Zod expression. */ export type TypeNameResolution = { expression: string; } | { error: string; }; export interface TsTypeConversionOptions { /** * Resolve a type reference to a Zod expression. Dotted names such as * `PrismaJson.Simple` are passed through whole. Returning `{ error }` makes * the whole conversion unconvertible with that error as the reason. */ resolveTypeName?: (name: string) => TypeNameResolution; /** Maximum nesting depth before bailing out. Defaults to 32. */ maxDepth?: number; } export interface TsTypeConversionSuccess { ok: true; /** The Zod expression, e.g. `z.array(z.tuple([z.array(z.number())]))`. */ expression: string; /** Every type reference resolved while converting, in first-seen order. */ referencedTypeNames: string[]; } export interface TsTypeConversionFailure { ok: false; /** Why the type could not be converted. Always a complete sentence fragment. */ reason: string; } export type TsTypeConversionResult = TsTypeConversionSuccess | TsTypeConversionFailure; /** Render a string value as a single-quoted JavaScript string literal. */ export declare function quoteStringLiteral(value: string): string; /** * Convert TypeScript type text to a Zod expression string. * * Never throws. Anything outside the supported subset comes back as * `{ ok: false, reason }` so the caller can fall back to today's behaviour. */ export declare function convertTsTypeToZod(typeText: string, options?: TsTypeConversionOptions): TsTypeConversionResult;