import { CompiledSchemaInfo } from "../core/pipeline.js"; import { TransformOptions, ZodCompilerPluginOptions } from "./types.js"; //#region src/unplugin/transform.d.ts /** JSON shape of the composed sourcemap returned alongside transformed code. */ interface TransformSourceMap { version: number; sources: (string | null)[]; sourcesContent?: (string | null)[]; names: string[]; mappings: string; file?: string | null; } /** * Matches a runtime (non-type-only) import from "zod". * * One of the three triggers ZOD_MENTION (the transform hook's `code` filter) * must remain a superset of — widening this to a specifier that does not * contain "zod" silently strips those files from every bundler with native * hook filters. `describe("code filter soundness")` fails if it drifts. */ declare const HAS_RUNTIME_ZOD_IMPORT: RegExp; /** * Check if a file should be transformed by the plugin. */ declare function shouldTransform(id: string, options?: ZodCompilerPluginOptions): boolean; /** * `id` half of the transform hook filter: the option-independent checks of * shouldTransform(), restated as patterns the bundler can evaluate itself. * Rolldown, Vite and Rollup 4.40+ apply hook filters natively, so a rejected * module never crosses into JS; unplugin applies the same patterns in JS for * the rest (webpack/rspack skip installing the transform loader entirely). * * The `include`/`exclude` options stay out of the filter on purpose: they are * matched with picomatch's `contains: true` semantics, which the native glob * support (patterns resolved against cwd, matched whole) would silently * narrow — shouldTransform() keeps applying them inside the handler. */ declare const TRANSFORM_ID_FILTER: { exclude: RegExp[]; include: RegExp[]; }; /** * `code` half of the transform hook filter, or undefined when no sound filter * exists. A custom `hoist.schemaNamePattern` promotes arbitrary imported * identifiers to schema roots (`UserModel`), so nothing in such a file is * guaranteed to mention zod — those setups keep the unfiltered behavior. */ declare function transformCodeFilter(options?: ZodCompilerPluginOptions): RegExp | undefined; declare function log(msg: string): void; declare function warn(msg: string): void; interface TransformOutput { code: string; map: TransformSourceMap | null; } /** * Transform source code by replacing compile() calls with optimized validators. * Returns the transformed code or null if no transformation was needed. * Compatibility wrapper over transformCodeWithMap() — discards the map. */ declare function transformCode(code: string, id: string, options: TransformOptions): Promise; /** * transformCode + a composed sourcemap (original → output). Stack traces in * transformed files shift by prepended declarations and expanded IIFEs * without it — a vitest assertion can be reported dozens of lines off. */ declare function transformCodeWithMap(code: string, id: string, options: TransformOptions): Promise; /** * Rewrite source code by replacing compile() calls with IIFE-wrapped optimized validators. */ declare function rewriteSource(code: string, schemas: CompiledSchemaInfo[], options?: { zodCompat?: boolean | undefined; }): string; /** * Find the end position of a JavaScript expression starting at `start` using acorn. * Returns the end offset, or -1 if the expression cannot be parsed. */ declare function findExpressionEnd(code: string, start: number): number; /** * Rewrite source code by replacing plain Zod schema exports with IIFE-wrapped optimized validators. * Used by autoDiscover mode (no compile() wrappers needed). */ declare function rewriteSourceAutoDiscover(code: string, schemas: CompiledSchemaInfo[], options?: { zodCompat?: boolean | undefined; }): string; /** * Remove the `compile` binding from `import { compile, ... } from "zod-compiler"` statements. * If `compile` is the only import, the entire import line is removed. */ declare function removeCompileImport(code: string): string; //#endregion export { HAS_RUNTIME_ZOD_IMPORT, TRANSFORM_ID_FILTER, TransformOutput, TransformSourceMap, findExpressionEnd, log, removeCompileImport, rewriteSource, rewriteSourceAutoDiscover, shouldTransform, transformCode, transformCodeFilter, transformCodeWithMap, warn }; //# sourceMappingURL=transform.d.ts.map