import type { ModelProjection } from './types.js'; import type { GenerateContextType, InsertModelOptions } from '../../context/generateTypes.js'; import type { ContentSettings } from '../ContentSettings.js'; import type { GeneratedDefinition } from '../GeneratedValue.js'; import type { GeneratedValue } from '../GeneratedValue.js'; import type { RefName } from '../../types/RefName.js'; /** * The `insertModel` call plus the context. The Driver defaults `variant` * to `'main'` and `noExport` to `false`, and reads the caller's options * once for the identity statics and the constructor. */ type CreateModelArgs = { context: GenerateContextType; projection: ModelProjection; refName: RefName; rootRef?: RefName; } & InsertModelOptions; /** * Driver for the model insertion lifecycle. * * Resolves the projection's identifier and export path, looks up an * existing `Definition` in the target file, instantiates the projection * (constructing its value) when no cache hit exists, registers the new * definition, and stitches an import into `destinationPath` if it differs * from the projection's `exportPath`. */ export declare class ModelDriver { context: GenerateContextType; projection: ModelProjection; refName: RefName; settings: ContentSettings; destinationPath?: string; definition: GeneratedDefinition; rootRef?: RefName; noExport: boolean; variant: string; /** The caller's options, as passed to `insertModel`. */ options: ProjectionOptions; /** * @param settings - The model's content settings, when the caller has * already built them with the same `args` (`toModelRef` does). */ constructor(args: CreateModelArgs, settings?: ContentSettings); private apply; /** * Ensure the file at `path` exists, creating it on first write through * the projection's language — the static read off the projection class * at the use site, never persisted (works pre-construction on the * cache-hit path). Returns the normalized path. */ private ensureFile; /** The code File at `path`, created through the projection's language on first use. */ private ensureCodeFile; private getDefinition; private affirmDefinition; } /** * Whether anything referred back to the model of `settings` while its * projection was being constructed: the model is recursive, on its own or in * a cycle with others. Call it from the projection's constructor, after the * value is built, while the model is still pending. */ export declare const isReferencedBack: ({ context, settings }: IsReferencedBackArgs) => boolean; type IsReferencedBackArgs = { context: GenerateContextType; settings: { identifier: { name: string; }; exportPath: string; }; }; /** * What a ref snippet gets for a reference to a model: `suspended` when the * model is pending (a back-reference, which the snippet renders deferred, * e.g. `z.lazy(() => Name)`: the value does not exist yet), else the * Definition the Driver constructed or found. */ export type ModelRef = { suspended: true; settings: ContentSettings; } | { suspended: false; settings: ContentSettings; definition: GeneratedDefinition; /** * The model reached a model that is still pending, so this reference is * inside a cycle. Every reference inside a cycle must be deferred where * the target language reads the value when the module loads (zod's * `z.lazy`): any model of the cycle can be the first one loaded. */ inCycle: boolean; }; /** * Reference a model from a ref snippet. A pending model (its projection is * being constructed further up the stack) is a back-reference: its marker * counts it, so its projection can tell that it is recursive * ({@link isReferencedBack}), and its import is stitched into * `destinationPath` as for any reference. The import matters when the * back-reference crosses files: in a cycle of two or more models, the model * that refers back lives in another file. Any other model goes through the * {@link ModelDriver}. */ export declare const toModelRef: (args: CreateModelArgs) => ModelRef; export {};