@kubb/ast 5.0.0-beta.56 → 5.0.0-beta.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +1710 -1745
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -46
- package/dist/index.js +1682 -1740
- package/dist/index.js.map +1 -1
- package/dist/{types-BL7RpQAE.d.ts → types-C5aVnRE1.d.ts} +1730 -1789
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/dedupe.ts +1 -1
- package/src/factory.ts +3 -763
- package/src/guards.ts +1 -53
- package/src/index.ts +35 -20
- package/src/mocks.ts +6 -1
- package/src/node.ts +128 -0
- package/src/nodes/base.ts +3 -2
- package/src/nodes/code.ts +115 -0
- package/src/nodes/content.ts +19 -0
- package/src/nodes/file.ts +54 -0
- package/src/nodes/function.ts +221 -146
- package/src/nodes/index.ts +11 -3
- package/src/nodes/input.ts +36 -0
- package/src/nodes/operation.ts +59 -1
- package/src/nodes/output.ts +23 -0
- package/src/nodes/parameter.ts +33 -0
- package/src/nodes/property.ts +36 -0
- package/src/nodes/requestBody.ts +23 -1
- package/src/nodes/response.ts +39 -1
- package/src/nodes/schema.ts +72 -0
- package/src/registry.ts +70 -0
- package/src/transformers.ts +2 -2
- package/src/types.ts +5 -3
- package/src/utils/ast.ts +116 -193
- package/src/visitor.ts +3 -47
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["visitorDepths","isValidVarName","camelCase","extractRefName","path","extractRefName","obj","extractRefName","isScalarPrimitive","enumPropName"],"sources":["../../../internals/utils/src/fs.ts","../../../internals/utils/src/promise.ts","../src/guards.ts","../src/visitor.ts","../src/utils/ast.ts","../src/factory.ts","../src/signature.ts","../src/dedupe.ts","../src/dialect.ts","../src/printer.ts","../src/transformers.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join, posix, resolve } from 'node:path'\nimport { camelCase } from './casing.ts'\nimport { runtime } from './runtime.ts'\n\n/**\n * Walks up the directory tree from `cwd` (defaults to `process.cwd()`) and\n * returns the absolute path of the nearest `package.json`, or `null` when none\n * is found before reaching the filesystem root.\n *\n * @example\n * ```ts\n * const pkgPath = findPackageJSON('/home/user/project/src') // '/home/user/project/package.json'\n * ```\n */\nexport function findPackageJSON(cwd?: string): string | null {\n let dir = cwd ? resolve(cwd) : process.cwd()\n while (true) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) return pkgPath\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\n/**\n * Converts all backslashes to forward slashes.\n * Extended-length Windows paths (`\\\\?\\...`) are left unchanged.\n */\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Writes `data` to `path`, trimming leading/trailing whitespace before saving.\n * Skips the write when the trimmed content is empty or identical to what is already on disk.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns trimmed content\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const resolved = resolve(path)\n\n if (runtime.isBun) {\n const file = Bun.file(resolved)\n const oldContent = (await file.exists()) ? await file.text() : null\n if (oldContent === trimmed) return null\n await Bun.write(resolved, trimmed)\n return trimmed\n }\n\n try {\n const oldContent = await readFile(resolved, { encoding: 'utf-8' })\n if (oldContent === trimmed) return null\n } catch {\n /* file doesn't exist yet */\n }\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, trimmed, { encoding: 'utf-8' })\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== trimmed) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return trimmed\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import type { HttpOperationNode, InputNode, Node, NodeKind, OperationNode, OutputNode, SchemaNode, SchemaNodeByType } from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\nfunction isKind<T extends Node>(kind: NodeKind) {\n return (node: unknown): node is T => (node as Node).kind === kind\n}\n\n/**\n * Returns `true` when the input is an `InputNode`.\n *\n * @example\n * ```ts\n * if (isInputNode(node)) {\n * console.log(node.schemas.length)\n * }\n * ```\n */\nexport const isInputNode = isKind<InputNode>('Input')\n\n/**\n * Returns `true` when the input is an `OutputNode`.\n *\n * @example\n * ```ts\n * if (isOutputNode(node)) {\n * console.log(node.files.length)\n * }\n * ```\n */\nexport const isOutputNode = isKind<OutputNode>('Output')\n\n/**\n * Returns `true` when the input is an `OperationNode`.\n *\n * @example\n * ```ts\n * if (isOperationNode(node)) {\n * console.log(node.operationId)\n * }\n * ```\n */\nexport const isOperationNode = isKind<OperationNode>('Operation')\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode`, guaranteeing `method` and `path`.\n *\n * @example\n * ```ts\n * if (isHttpOperationNode(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n\n/**\n * Returns `true` when the input is a `SchemaNode`.\n *\n * @example\n * ```ts\n * if (isSchemaNode(node)) {\n * console.log(node.type)\n * }\n * ```\n */\nexport const isSchemaNode = isKind<SchemaNode>('Schema')\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport { createParameter, createProperty } from './factory.ts'\nimport type {\n ContentNode,\n InputNode,\n Node,\n NodeKind,\n OperationNode,\n OutputNode,\n ParameterNode,\n PropertyNode,\n RequestBodyNode,\n ResponseNode,\n SchemaNode,\n} from './nodes/index.ts'\n\n/**\n * Creates a small async concurrency limiter.\n *\n * At most `concurrency` tasks are in flight at once. Extra tasks are queued.\n *\n * @example\n * ```ts\n * const limit = createLimit(2)\n * for (const task of [taskA, taskB, taskC]) {\n * await limit(() => task())\n * }\n * // only 2 tasks run at the same time\n * ```\n */\nfunction createLimit(concurrency: number) {\n let active = 0\n const queue: Array<() => void> = []\n\n function next() {\n if (active < concurrency && queue.length > 0) {\n active++\n queue.shift()!()\n }\n }\n\n return function limit<T>(fn: () => Promise<T> | T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n queue.push(() => {\n Promise.resolve(fn())\n .then(resolve, reject)\n .finally(() => {\n active--\n next()\n })\n })\n next()\n })\n }\n}\n\ntype LimitFn = ReturnType<typeof createLimit>\n\n/**\n * Ordered mapping of `[NodeType, ParentType]` pairs.\n *\n * `ParentOf` uses this map to find parent types.\n */\ntype ParentNodeMap = [\n [InputNode, undefined],\n [OutputNode, undefined],\n [OperationNode, InputNode],\n [RequestBodyNode, OperationNode],\n [ContentNode, RequestBodyNode | ResponseNode],\n [SchemaNode, InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode],\n [PropertyNode, SchemaNode],\n [ParameterNode, OperationNode],\n [ResponseNode, OperationNode],\n]\n\n/**\n * Resolves the parent node type for a given AST node type.\n *\n * This is used by visitor context so `ctx.parent` is correctly typed\n * for each callback.\n *\n * @example\n * ```ts\n * type InputParent = ParentOf<InputNode>\n * // undefined\n * ```\n *\n * @example\n * ```ts\n * type PropertyParent = ParentOf<PropertyNode>\n * // SchemaNode\n * ```\n *\n * @example\n * ```ts\n * type SchemaParent = ParentOf<SchemaNode>\n * // InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode\n * ```\n */\nexport type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [\n infer TEntry extends [Node, unknown],\n ...infer TRest extends ReadonlyArray<[Node, unknown]>,\n]\n ? T extends TEntry[0]\n ? TEntry[1]\n : ParentOf<T, TRest>\n : Node\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n * `parent` is typed from the current node type.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent type is narrowed by node kind\n * },\n * }\n * ```\n */\nexport type VisitorContext<T extends Node = Node> = {\n /**\n * Parent node of the currently visited node.\n * For `InputNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites operation IDs, drops descriptions, or otherwise tweaks the AST\n * before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode\n output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode\n}\n\n/**\n * Utility type for values that can be returned directly or asynchronously.\n */\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.\n *\n * @example\n * ```ts\n * const visitor: AsyncVisitor = {\n * async operation(node) {\n * await Promise.resolve(node.operationId)\n * },\n * }\n * ```\n */\ntype AsyncVisitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<undefined | null | InputNode>\n output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<undefined | null | OutputNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<undefined | null | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<undefined | null | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<undefined | null | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<undefined | null | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<undefined | null | ResponseNode>\n}\n\n/**\n * Visitor used by `collect`.\n *\n * @example\n * ```ts\n * const visitor: CollectVisitor<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\ntype CollectVisitor<T> = {\n input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined\n output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `walk`.\n *\n * @example\n * ```ts\n * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }\n * ```\n */\nexport type WalkOptions = AsyncVisitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Maximum number of sibling nodes visited concurrently.\n * @default 30\n */\n concurrency?: number\n}\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = CollectVisitor<T> & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n *\n * Each listed property holds a child node, an array of child nodes, or, for\n * `additionalProperties` a node or the literal `true` (skipped). Every value\n * in a child slot is a node, so one table drives both `getChildren` and `transform`.\n */\nconst VISITOR_KEYS = {\n Input: ['schemas', 'operations'],\n Operation: ['parameters', 'requestBody', 'responses'],\n RequestBody: ['content'],\n Content: ['schema'],\n Response: ['content'],\n Schema: ['properties', 'items', 'members', 'additionalProperties'],\n Property: ['schema'],\n Parameter: ['schema'],\n} as const satisfies Partial<Record<NodeKind, ReadonlyArray<string>>>\n\nconst visitorKeysByKind = VISITOR_KEYS as Record<string, ReadonlyArray<string> | undefined>\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && 'kind' in value\n}\n\n/**\n * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.\n *\n * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, the request body, and responses\n * ```\n */\nfunction* getChildren(node: Node, recurse: boolean): Generator<Node, void, undefined> {\n if (node.kind === 'Schema' && !recurse) return\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return\n\n const record = node as unknown as Record<string, unknown>\n for (const key of keys) {\n const value = record[key]\n if (Array.isArray(value)) {\n for (const item of value) if (isNode(item)) yield item\n } else if (isNode(value)) {\n yield value\n }\n }\n}\n\n/**\n * Maps a node `kind` to the matching visitor callback name. Only the seven\n * traversable node kinds have an entry. Every other kind resolves to\n * `undefined` and is skipped.\n */\nconst VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, keyof Visitor>> = {\n Input: 'input',\n Output: 'output',\n Operation: 'operation',\n Schema: 'schema',\n Property: 'property',\n Parameter: 'parameter',\n Response: 'response',\n}\n\n/**\n * Invokes the visitor callback that matches `node.kind`, passing the traversal\n * context. Returns the callback's result (a replacement node, a collected\n * value, or `undefined` when no callback is registered for the kind).\n *\n * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives\n * in one place. `TResult` is the caller's expected return: the same node type\n * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | AsyncVisitor | CollectVisitor<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Async depth-first traversal for side effects. Visitor return values are\n * ignored. Use `transform` when you want to rewrite nodes.\n *\n * Sibling nodes at each depth run concurrently up to `options.concurrency`\n * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor\n * work. Lower values reduce memory pressure.\n *\n * @example Log every operation\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example Only visit the root node\n * ```ts\n * await walk(root, { depth: 'shallow', input: () => {} })\n * ```\n */\nexport async function walk(node: Node, options: WalkOptions): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const limit = createLimit(options.concurrency ?? WALK_CONCURRENCY)\n\n return _walk(node, options, recurse, limit, undefined)\n}\n\nasync function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn, parent: Node | undefined): Promise<void> {\n await limit(() => applyVisitor(node, visitor, parent))\n\n // Visit siblings concurrently and let the shared `limit` cap how many callbacks\n // run at once. Awaiting each child sequentially here would serialize the whole\n // traversal and make `concurrency` inert, every visitor callback would run one\n // at a time regardless of the limit.\n const children = Array.from(getChildren(node, recurse))\n if (children.length === 0) return\n\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback gets a chance to\n * return a replacement node; `undefined` keeps the original.\n *\n * The transform is immutable. The original tree is not mutated. A new tree\n * is returned. Use `depth: 'shallow'` to skip recursion into children.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Replace only the root node\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform(node: InputNode, options: TransformOptions): InputNode\nexport function transform(node: OutputNode, options: TransformOptions): OutputNode\nexport function transform(node: OperationNode, options: TransformOptions): OperationNode\nexport function transform(node: SchemaNode, options: TransformOptions): SchemaNode\nexport function transform(node: PropertyNode, options: TransformOptions): PropertyNode\nexport function transform(node: ParameterNode, options: TransformOptions): ParameterNode\nexport function transform(node: ResponseNode, options: TransformOptions): ResponseNode\nexport function transform(node: Node, options: TransformOptions): Node\nexport function transform(node: Node, options: TransformOptions): Node {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n const rebuilt = transformChildren(visited, options, recurse)\n\n // Structural sharing: when the visitor and child rebuild both left this node\n // untouched, return the original reference so callers can detect \"nothing\n // changed\" by identity and ancestors can avoid reallocating.\n if (rebuilt === node) return node\n\n const finalize = nodeFinalizers[rebuilt.kind]\n return finalize ? finalize(rebuilt) : rebuilt\n}\n\n/**\n * Per-kind builders rerun after children are rebuilt. `Property`/`Parameter`\n * resync schema optionality against their `required` flag once the schema may\n * have changed.\n */\nconst nodeFinalizers: Partial<Record<NodeKind, (node: Node) => Node>> = {\n Property: (node) => createProperty(node as PropertyNode),\n Parameter: (node) => createParameter(node as ParameterNode),\n}\n\n/**\n * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming\n * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.\n * `Schema` children are skipped in shallow mode.\n */\nfunction transformChildren(node: Node, options: TransformOptions, recurse: boolean): Node {\n if (node.kind === 'Schema' && !recurse) return node\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n const childOptions = { ...options, parent: node }\n let updates: Record<string, unknown> | undefined\n\n for (const key of keys) {\n if (!(key in record)) continue\n const value = record[key]\n if (Array.isArray(value)) {\n let changed = false\n const mapped = value.map((item) => {\n if (!isNode(item)) return item\n const next = transform(item, childOptions)\n if (next !== item) changed = true\n return next\n })\n if (changed) (updates ??= {})[key] = mapped\n } else if (isNode(value)) {\n const next = transform(value, childOptions)\n if (next !== value) (updates ??= {})[key] = next\n }\n }\n\n return updates ? ({ ...node, ...updates } as Node) : node\n}\n/**\n * Lazy depth-first collection pass. Yields every non-null value returned by\n * the visitor callbacks. Use `collect` for the eager array form.\n *\n * @example Collect every operationId\n * ```ts\n * const ids: string[] = []\n * for (const id of collectLazy<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })) {\n * ids.push(id)\n * }\n * ```\n */\nexport function* collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) yield v\n\n for (const child of getChildren(node, recurse)) {\n yield* collectLazy(child, { ...options, parent: node })\n }\n}\n\n/**\n * Eager depth-first collection pass. Returns an array of every non-null value\n * the visitor callbacks return.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n return Array.from(collectLazy(node, options))\n}\n","import { camelCase, isValidVarName, memoize } from '@internals/utils'\n\nimport { createFunctionParameter, createFunctionParameters, createParameterGroup, createParamsType, createProperty, createSchema } from '../factory.ts'\nimport { narrowSchema } from '../guards.ts'\nimport type {\n CodeNode,\n ExportNode,\n FunctionParameterNode,\n FunctionParametersNode,\n ImportNode,\n OperationNode,\n ParameterGroupNode,\n ParameterNode,\n ParamsTypeNode,\n SchemaNode,\n SourceNode,\n} from '../nodes/index.ts'\nimport type { SchemaType } from '../nodes/schema.ts'\nimport { extractRefName } from './index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node\n * override the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.\n *\n * @example\n * ```ts\n * // Ref with description override\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Applies casing rules to parameter names and returns a new parameter array.\n *\n * Use this before passing parameters to schema builders so output property keys match\n * the desired casing while preserving `OperationNode.parameters` for other consumers.\n * The input array is not mutated. When `casing` is not set, the original array is returned unchanged.\n */\nconst caseParamsMemo = memoize(new WeakMap<Array<ParameterNode>, (casing: string) => Array<ParameterNode>>(), (params) =>\n memoize(new Map<string, Array<ParameterNode>>(), (casing: string) =>\n params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n return { ...param, name: transformed }\n }),\n ),\n)\n\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) return params\n return caseParamsMemo(params)(casing)\n}\n\n/**\n * Creates a single-property object schema used as a discriminator literal.\n *\n * @example\n * ```ts\n * createDiscriminantNode({ propertyName: 'type', value: 'dog' })\n * // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }\n * ```\n */\nexport function createDiscriminantNode({ propertyName, value }: { propertyName: string; value: string }): SchemaNode {\n return createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n createProperty({\n name: propertyName,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: [value],\n }),\n required: true,\n }),\n ],\n })\n}\n\n/**\n * Named type for a group of parameters (query or header) emitted as a single typed parameter.\n */\ntype ParamGroupType = {\n /**\n * TypeNode for the group type.\n */\n type: ParamsTypeNode\n /**\n * Whether the parameter group is optional.\n */\n optional: boolean\n}\n\n/**\n * Resolver interface for {@link createOperationParams}.\n *\n * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.\n */\nexport type OperationParamsResolver = {\n /**\n * Resolves the type name for an individual parameter.\n *\n * @example Individual path parameter name\n * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`\n */\n resolveParamName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the request body type name.\n *\n * @example Request body type name\n * `resolver.resolveDataName(node) // → 'CreatePetData'`\n */\n resolveDataName(node: OperationNode): string\n /**\n * Resolves the grouped path parameters type name.\n * When the return value equals `resolveParamName`, no indexed access is emitted.\n *\n * @example Grouped path params type name\n * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`\n */\n resolvePathParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped query parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped query params type name\n * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`\n */\n resolveQueryParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped header parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped header params type name\n * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`\n */\n resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string\n}\n\n/**\n * Options for {@link createOperationParams}.\n */\nexport type CreateOperationParamsOptions = {\n /**\n * How all operation parameters are grouped in the function signature.\n * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`\n * - `'inline'` emits each param category as a separate top-level parameter\n */\n paramsType: 'object' | 'inline'\n /**\n * How path parameters are emitted when `paramsType` is `'inline'`.\n * - `'object'` groups them as `{ petId, storeId }: PathParams`\n * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`\n * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`\n */\n pathParamsType: 'object' | 'inline' | 'inlineSpread'\n /**\n * Converts parameter names to camelCase before output.\n */\n paramsCasing?: 'camelcase'\n /**\n * Resolver for parameter and request body type names.\n * Pass `ResolverTs` from `@kubb/plugin-ts` directly.\n * When omitted, falls back to the schema primitive or `'unknown'`.\n */\n resolver?: OperationParamsResolver\n /**\n * Default value for the path parameters binding when `pathParamsType` is `'object'`.\n * Falls back to `'{}'` when all path params are optional.\n */\n pathParamsDefault?: string\n /**\n * Extra parameters appended after the standard operation parameters.\n *\n * @example Plugin-specific trailing parameter\n * ```ts\n * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]\n * ```\n */\n extraParams?: Array<FunctionParameterNode | ParameterGroupNode>\n /**\n * Override the default parameter names used for body, query, header, and rest-path groups.\n *\n * Useful when targeting languages or frameworks with different naming conventions.\n *\n * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }\n */\n paramNames?: {\n /**\n * Name for the request body parameter.\n * @default 'data'\n */\n data?: string\n /**\n * Name for the query parameters group parameter.\n * @default 'params'\n */\n params?: string\n /**\n * Name for the header parameters group parameter.\n * @default 'headers'\n */\n headers?: string\n /**\n * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.\n * @default 'pathParams'\n */\n path?: string\n }\n /**\n * Applies a uniform transformation to every resolved type name before it is used\n * in a parameter node. Use this for framework-level type wrappers.\n *\n * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`\n * `typeWrapper: (t) => \\`MaybeRefOrGetter<${t}>\\``\n */\n typeWrapper?: (type: string) => string\n}\n\nfunction resolveParamsType({\n node,\n param,\n resolver,\n}: {\n node: OperationNode\n param: ParameterNode\n resolver: OperationParamsResolver | undefined\n}): ParamsTypeNode {\n if (!resolver) {\n return createParamsType({\n variant: 'reference',\n name: param.schema.primitive ?? 'unknown',\n })\n }\n\n const individualName = resolver.resolveParamName(node, param)\n\n const groupLocation = param.in === 'path' || param.in === 'query' || param.in === 'header' ? param.in : undefined\n\n const groupResolvers = {\n path: resolver.resolvePathParamsName,\n query: resolver.resolveQueryParamsName,\n header: resolver.resolveHeaderParamsName,\n } as const\n\n const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : undefined\n\n if (groupName && groupName !== individualName) {\n return createParamsType({\n variant: 'member',\n base: groupName,\n key: param.name,\n })\n }\n\n return createParamsType({ variant: 'reference', name: individualName })\n}\n\n/**\n * Converts an `OperationNode` into function parameters for code generation.\n *\n * Centralizes parameter grouping logic for all plugins. Provide a `resolver` for type name resolution\n * and `extraParams` for plugin-specific trailing parameters (e.g., `options` objects).\n * Supports three grouping modes: `object` (single destructured param), `inline` (separate params),\n * and `inlineSpread` (rest parameter). Use `CreateOperationParamsOptions` to fine-tune output.\n */\nexport function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode {\n const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options\n\n const dataName = paramNames?.data ?? 'data'\n const paramsName = paramNames?.params ?? 'params'\n const headersName = paramNames?.headers ?? 'headers'\n const pathName = paramNames?.path ?? 'pathParams'\n\n const wrapType = (type: string): ParamsTypeNode =>\n createParamsType({\n variant: 'reference',\n name: typeWrapper ? typeWrapper(type) : type,\n })\n // Only reference-variant TypeNodes are wrapped, they hold a plain type name string that needs casing applied.\n // Member and struct TypeNodes are pre-resolved structured expressions and are passed through unchanged.\n const wrapTypeNode = (type: ParamsTypeNode): ParamsTypeNode => (type.kind === 'ParamsType' && type.variant === 'reference' ? wrapType(type.name) : type)\n\n const casedParams = caseParams(node.parameters, paramsCasing)\n const pathParams = casedParams.filter((p) => p.in === 'path')\n const queryParams = casedParams.filter((p) => p.in === 'query')\n const headerParams = casedParams.filter((p) => p.in === 'header')\n\n const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined\n const bodyRequired = node.requestBody?.required ?? false\n\n const queryGroupType = resolver\n ? resolveGroupType({\n node,\n params: queryParams,\n groupMethod: resolver.resolveQueryParamsName,\n resolver,\n })\n : undefined\n const headerGroupType = resolver\n ? resolveGroupType({\n node,\n params: headerParams,\n groupMethod: resolver.resolveHeaderParamsName,\n resolver,\n })\n : undefined\n\n const params: Array<FunctionParameterNode | ParameterGroupNode> = []\n\n if (paramsType === 'object') {\n const children: Array<FunctionParameterNode> = [\n ...pathParams.map((p) => {\n const type = resolveParamsType({ node, param: p, resolver })\n return createFunctionParameter({\n name: p.name,\n type: wrapTypeNode(type),\n optional: !p.required,\n })\n }),\n ...(bodyType\n ? [\n createFunctionParameter({\n name: dataName,\n type: bodyType,\n optional: !bodyRequired,\n }),\n ]\n : []),\n ...buildGroupParam({\n name: paramsName,\n node,\n params: queryParams,\n groupType: queryGroupType,\n resolver,\n wrapType,\n }),\n ...buildGroupParam({\n name: headersName,\n node,\n params: headerParams,\n groupType: headerGroupType,\n resolver,\n wrapType,\n }),\n ]\n\n if (children.length) {\n params.push(\n createParameterGroup({\n properties: children,\n default: children.every((c) => c.optional) ? '{}' : undefined,\n }),\n )\n }\n } else {\n if (pathParams.length) {\n if (pathParamsType === 'inlineSpread') {\n const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]!)\n params.push(\n createFunctionParameter({\n name: pathName,\n type: spreadType ? wrapType(spreadType) : undefined,\n rest: true,\n }),\n )\n } else {\n const pathChildren = pathParams.map((p) => {\n const type = resolveParamsType({ node, param: p, resolver })\n return createFunctionParameter({\n name: p.name,\n type: wrapTypeNode(type),\n optional: !p.required,\n })\n })\n params.push(\n createParameterGroup({\n properties: pathChildren,\n inline: pathParamsType === 'inline',\n default: pathParamsDefault ?? (pathChildren.every((c) => c.optional) ? '{}' : undefined),\n }),\n )\n }\n }\n\n if (bodyType) {\n params.push(\n createFunctionParameter({\n name: dataName,\n type: bodyType,\n optional: !bodyRequired,\n }),\n )\n }\n\n params.push(\n ...buildGroupParam({\n name: paramsName,\n node,\n params: queryParams,\n groupType: queryGroupType,\n resolver,\n wrapType,\n }),\n )\n params.push(\n ...buildGroupParam({\n name: headersName,\n node,\n params: headerParams,\n groupType: headerGroupType,\n resolver,\n wrapType,\n }),\n )\n }\n\n params.push(...extraParams)\n\n return createFunctionParameters({ params })\n}\n\n/**\n * Builds a single {@link FunctionParameterNode} for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * If a pre-resolved `groupType` is provided it emits `name: GroupType`.\n * Otherwise, it builds an inline struct from the individual params.\n */\nfunction buildGroupParam({\n name,\n node,\n params,\n groupType,\n resolver,\n wrapType,\n}: {\n name: string\n node: OperationNode\n params: Array<ParameterNode>\n groupType: ParamGroupType | null | undefined\n resolver: OperationParamsResolver | undefined\n wrapType: (type: string) => ParamsTypeNode\n}): Array<FunctionParameterNode> {\n if (groupType) {\n const type = groupType.type.kind === 'ParamsType' && groupType.type.variant === 'reference' ? wrapType(groupType.type.name) : groupType.type\n return [createFunctionParameter({ name, type, optional: groupType.optional })]\n }\n if (params.length) {\n return [\n createFunctionParameter({\n name,\n type: toStructType({ node, params, resolver }),\n optional: params.every((p) => !p.required),\n }),\n ]\n }\n return []\n}\n\n/**\n * Derives a {@link ParamGroupType} from the resolver's group method.\n * Returns `null` when the group name equals the individual param name (no real group).\n */\nfunction resolveGroupType({\n node,\n params,\n groupMethod,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n groupMethod: (_node: OperationNode, _param: ParameterNode) => string\n resolver: OperationParamsResolver\n}): ParamGroupType | null {\n if (!params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n const allOptional = params.every((p) => !p.required)\n return {\n type: createParamsType({ variant: 'reference', name: groupName }),\n optional: allOptional,\n }\n}\n\n/**\n * Builds a {@link TypeNode} with `variant: 'struct'` for an inline anonymous type grouping named fields.\n *\n * Used when query or header parameters have no dedicated group type name.\n * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).\n */\nfunction toStructType({\n node,\n params,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n resolver: OperationParamsResolver | undefined\n}): ParamsTypeNode {\n return createParamsType({\n variant: 'struct',\n properties: params.map((p) => ({\n name: p.name,\n optional: !p.required,\n type: resolveParamsType({ node, param: p, resolver }),\n })),\n })\n}\n\nfunction sourceKey(source: SourceNode): string {\n const nameKey = source.name ?? extractStringsFromNodes(source.nodes)\n return `${nameKey}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`\n}\n\nfunction pathTypeKey(path: string, isTypeOnly: boolean | null | undefined): string {\n return `${path}:${isTypeOnly ?? false}`\n}\n\nfunction exportKey(path: string, name: string | null | undefined, isTypeOnly: boolean | null | undefined, asAlias: boolean | null | undefined): string {\n return `${path}:${name ?? ''}:${isTypeOnly ?? false}:${asAlias ?? ''}`\n}\n\nfunction importKey(path: string, name: string | null | undefined, isTypeOnly: boolean | null | undefined): string {\n return `${path}:${name ?? ''}:${isTypeOnly ?? false}`\n}\n\n/**\n * Computes a multi-level sort key for exports and imports:\n * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.\n */\nfunction sortKey(node: { name?: string | Array<unknown> | null; isTypeOnly?: boolean | null; path: string }): string {\n const isArray = Array.isArray(node.name) ? '1' : '0'\n const typeOnly = node.isTypeOnly ? '0' : '1'\n const hasName = node.name != null ? '1' : '0'\n const name = Array.isArray(node.name) ? node.name.toSorted().join('\\0') : (node.name ?? '')\n return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`\n}\n\n/**\n * Deduplicates and merges `SourceNode` objects by `name + isExportable + isTypeOnly`.\n *\n * Unnamed sources are deduplicated by object reference. Returns a deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Map<string, SourceNode>()\n for (const source of sources) {\n const key = sourceKey(source)\n if (!seen.has(key)) seen.set(key, source)\n }\n return [...seen.values()]\n}\n\n/**\n * Merges `incoming` names into `existing`, preserving order and dropping duplicates.\n *\n * Shared by `combineExports` and `combineImports` for the same-path name-merge case.\n */\nfunction mergeNameArrays<TName>(existing: Array<TName>, incoming: Array<TName>): Array<TName> {\n const merged = new Set(existing)\n for (const name of incoming) merged.add(name)\n return [...merged]\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects by path and type.\n *\n * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.\n * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n const result: Array<ExportNode> = []\n // Accumulates array-named exports keyed by `path:isTypeOnly` for name-merging\n const namedByPath = new Map<string, ExportNode>()\n // Deduplicates non-array exports by their exact identity\n const seen = new Set<string>()\n\n // Precompute sort keys once, avoids recomputing per comparison.\n const keyed = exports.map((node) => ({ node, key: sortKey(node) }))\n keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { node: curr } of keyed) {\n const { name, path, isTypeOnly, asAlias } = curr\n\n if (Array.isArray(name)) {\n if (!name.length) continue\n\n const key = pathTypeKey(path, isTypeOnly)\n const existing = namedByPath.get(key)\n\n if (existing && Array.isArray(existing.name)) {\n existing.name = mergeNameArrays(existing.name, name)\n } else {\n const newItem: ExportNode = { ...curr, name: [...new Set(name)] }\n result.push(newItem)\n namedByPath.set(key, newItem)\n }\n } else {\n const key = exportKey(path, name, isTypeOnly, asAlias)\n if (!seen.has(key)) {\n result.push(curr)\n seen.add(key)\n }\n }\n }\n\n return result\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports that are referenced in `source` or re-exported. Imports with the same path and\n * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.\n *\n * @note Use this when combining imports from multiple files to avoid duplicate declarations.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((e) => (Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])))\n const isUsed = (importName: string): boolean => !source || source.includes(importName) || exportedNames.has(importName)\n\n // Memoize object import names so the same logical (propertyName, name) pair always\n // reuses the same object reference. Set-based deduplication then works correctly.\n const importNameMemo = new Map<string, { propertyName: string; name?: string }>()\n const canonicalizeName = (n: string | { propertyName: string; name?: string }): string | { propertyName: string; name?: string } => {\n if (typeof n === 'string') return n\n const key = `${n.propertyName}:${n.name ?? ''}`\n if (!importNameMemo.has(key)) importNameMemo.set(key, n)\n return importNameMemo.get(key)!\n }\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set<string>()\n for (const node of imports) {\n if (!Array.isArray(node.name)) continue\n if (node.name.some((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))) {\n pathsWithUsedNamedImport.add(node.path)\n }\n }\n\n const result: Array<ImportNode> = []\n // Accumulates array-named imports keyed by `path:isTypeOnly` for name-merging\n const namedByPath = new Map<string, ImportNode>()\n // Deduplicates non-array imports by their exact identity\n const seen = new Set<string>()\n\n // Precompute sort keys once, avoids recomputing per comparison.\n const keyed = imports.map((node) => ({ node, key: sortKey(node) }))\n keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { node: curr } of keyed) {\n if (curr.path === curr.root) continue\n\n const { path, isTypeOnly } = curr\n let { name } = curr\n\n if (Array.isArray(name)) {\n name = [...new Set(name.map(canonicalizeName))].filter((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))\n if (!name.length) continue\n\n const key = pathTypeKey(path, isTypeOnly)\n const existing = namedByPath.get(key)\n\n if (existing && Array.isArray(existing.name)) {\n existing.name = mergeNameArrays(existing.name, name)\n } else {\n const newItem: ImportNode = { ...curr, name }\n result.push(newItem)\n namedByPath.set(key, newItem)\n }\n } else {\n if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue\n\n const key = importKey(path, name, isTypeOnly)\n if (!seen.has(key)) {\n result.push(curr)\n seen.add(key)\n }\n }\n }\n\n return result\n}\n\n/**\n * Extracts all string content from a `CodeNode` tree recursively.\n *\n * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),\n * and nested node content. Used internally to build the full source string for import filtering.\n */\nexport function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string {\n if (!nodes?.length) return ''\n return nodes\n .map((node) => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return node as string\n if (node.kind === 'Text') return node.value\n if (node.kind === 'Break') return ''\n if (node.kind === 'Jsx') return node.value\n\n const parts: Array<string> = []\n\n if ('params' in node && node.params) parts.push(node.params)\n if ('generics' in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(', ') : node.generics)\n if ('returnType' in node && node.returnType) parts.push(node.returnType)\n if ('type' in node && typeof node.type === 'string') parts.push(node.type)\n\n const nested = extractStringsFromNodes(node.nodes)\n\n if (nested) parts.push(nested)\n\n return parts.join('\\n')\n })\n .filter(Boolean)\n .join('\\n')\n}\n\n/**\n * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's\n * identifier for type definitions or error messages.\n *\n * @example\n * ```ts\n * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })\n * // => 'Pet'\n * ```\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Collects every named schema referenced (transitively) from a node via ref edges.\n *\n * Refs are followed by name only, the resolved `node.schema` is not traversed inline.\n * Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // → Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when any of its parameters, request body content, or responses\n * reference it, directly or indirectly through other named schemas.\n * The walk is iterative and safe against reference cycles.\n *\n * Use this together with `include` filters to determine which schemas from `components/schemas`\n * are reachable from the allowed operations, so that schemas used only by excluded operations\n * are not generated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter(op => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // … generate schema\n * }\n * ```\n *\n * @example Check whether a specific schema is needed\n * ```ts\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n * allowed.has('OrderStatus') // false when no included operation references OrderStatus\n * ```\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Identifies all schemas that participate in circular dependency chains, including direct self-loops.\n *\n * Returns a Set of schema names with circular dependencies. Use this to wrap recursive schema positions\n * in deferred constructs (lazy getter, `z.lazy(() => …)`) to prevent infinite recursion when generated code runs.\n * Refs are followed by name only, keeping the algorithm linear in the schema graph size.\n *\n * @note Call this once on the full schema graph, then use `containsCircularRef()` to check individual schemas.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Type guard returning `true` when a schema or anything nested within it contains a ref to a circular schema.\n *\n * Use `excludeName` to ignore refs to specific schemas (useful when self-references are handled separately).\n * Commonly used with `findCircularSchemas()` to detect where lazy wrappers are needed in code generation.\n *\n * @note Returns `true` for the first matching circular ref found. Use for fast dependency checks.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { InferSchemaNode } from './infer.ts'\nimport type {\n ArrowFunctionNode,\n BreakNode,\n ConstNode,\n ContentNode,\n ExportNode,\n FileNode,\n FunctionNode,\n FunctionParameterNode,\n FunctionParametersNode,\n GenericOperationNode,\n HttpOperationNode,\n ImportNode,\n InputMeta,\n InputNode,\n JsxNode,\n Node,\n ObjectSchemaNode,\n OperationNode,\n OutputNode,\n ParameterGroupNode,\n ParameterNode,\n ParamsTypeNode,\n PrimitiveSchemaType,\n PropertyNode,\n RequestBodyNode,\n ResponseNode,\n SchemaNode,\n SourceNode,\n TextNode,\n TypeNode,\n} from './nodes/index.ts'\nimport { combineExports, combineImports, combineSources, extractStringsFromNodes } from './utils/ast.ts'\n\n/**\n * Updates a schema's `optional` and `nullish` flags from a parent's `required`\n * value and the schema's own `nullable`. Mirrors how OpenAPI parameters and\n * object properties combine \"required\" and \"nullable\" into a single AST.\n *\n * - Non-required + non-nullable → `optional: true`.\n * - Non-required + nullable → `nullish: true`.\n * - Required → both flags cleared.\n */\nexport function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode {\n const nullable = schema.nullable ?? false\n\n return {\n ...schema,\n optional: !required && !nullable ? true : undefined,\n nullish: !required && nullable ? true : undefined,\n }\n}\n\n/**\n * Distributive `Omit` that preserves each member of a union.\n *\n * @example\n * ```ts\n * type A = { kind: 'a'; keep: string; drop: number }\n * type B = { kind: 'b'; keep: boolean; drop: number }\n * type Result = DistributiveOmit<A | B, 'drop'>\n * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }\n * ```\n */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract, pair it with the\n * structural sharing in {@link transform} so a no-op rewrite doesn't allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is\n * shallow: a structurally-equal but newly-allocated array/object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n\ntype CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & { properties?: Array<PropertyNode>; primitive?: 'object' }\ntype CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>\ntype CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {\n kind: 'Schema'\n}\n\n/**\n * Creates an `InputNode` with stable defaults for `schemas` and `operations`.\n *\n * @example\n * ```ts\n * const input = createInput()\n * // { kind: 'Input', schemas: [], operations: [] }\n * ```\n *\n * @example\n * ```ts\n * const input = createInput({ schemas: [petSchema] })\n * // keeps default operations: []\n * ```\n */\nexport function createInput(overrides: Partial<Omit<InputNode, 'kind'>> = {}): InputNode {\n return {\n schemas: [],\n operations: [],\n meta: { circularNames: [], enumNames: [] },\n ...overrides,\n kind: 'Input',\n }\n}\n\n/**\n * Creates a streaming `InputNode<true>` from pre-built `AsyncIterable` sources.\n *\n * @example\n * ```ts\n * const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })\n * ```\n */\nexport function createStreamInput(schemas: AsyncIterable<SchemaNode>, operations: AsyncIterable<OperationNode>, meta?: InputMeta): InputNode<true> {\n return { kind: 'Input', schemas, operations, meta }\n}\n\n/**\n * Creates an `OutputNode` with a stable default for `files`.\n *\n * @example\n * ```ts\n * const output = createOutput()\n * // { kind: 'Output', files: [] }\n * ```\n *\n * @example\n * ```ts\n * const output = createOutput({ files: [petFile] })\n * ```\n */\nexport function createOutput(overrides: Partial<Omit<OutputNode, 'kind'>> = {}): OutputNode {\n return {\n files: [],\n ...overrides,\n kind: 'Output',\n }\n}\n\n/**\n * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.\n *\n * @example\n * ```ts\n * const operation = createOperation({\n * operationId: 'getPetById',\n * method: 'GET',\n * path: '/pet/{petId}',\n * })\n * // tags, parameters, and responses are []\n * ```\n *\n * @example\n * ```ts\n * const operation = createOperation({\n * operationId: 'findPets',\n * method: 'GET',\n * path: '/pet/findByStatus',\n * tags: ['pet'],\n * })\n * ```\n */\n/**\n * Loosely-typed content entry accepted by the builders, normalized into a {@link ContentNode}.\n */\ntype UserContent = Omit<ContentNode, 'kind'>\n\n/**\n * Creates a `ContentNode` for a single request-body or response content type.\n */\nfunction createContent(props: UserContent): ContentNode {\n return {\n ...props,\n kind: 'Content',\n }\n}\n\n/**\n * Loosely-typed request body accepted by `createOperation`, normalized into a {@link RequestBodyNode}.\n */\ntype UserRequestBody = Omit<RequestBodyNode, 'kind' | 'content'> & {\n content?: Array<UserContent>\n}\n\n/**\n * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.\n */\nfunction createRequestBody(props: UserRequestBody): RequestBodyNode {\n return {\n ...props,\n kind: 'RequestBody',\n content: props.content?.map(createContent),\n }\n}\n\nexport function createOperation(\n props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &\n Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {\n requestBody?: UserRequestBody\n },\n): HttpOperationNode\nexport function createOperation(\n props: Pick<GenericOperationNode, 'operationId'> &\n Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {\n requestBody?: UserRequestBody\n },\n): GenericOperationNode\nexport function createOperation(props: {\n operationId: string\n method?: HttpOperationNode['method']\n path?: HttpOperationNode['path']\n requestBody?: UserRequestBody\n [key: string]: unknown\n}): OperationNode {\n const { requestBody, ...rest } = props\n const isHttp = rest.method !== undefined && rest.path !== undefined\n\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...rest,\n ...(isHttp ? { protocol: 'http' } : {}),\n kind: 'Operation',\n requestBody: requestBody ? createRequestBody(requestBody) : undefined,\n } as OperationNode\n}\n\n/**\n * Maps schema `type` to its underlying `primitive`.\n * Primitive types map to themselves. Special string formats map to `'string'`.\n * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.\n */\nconst TYPE_TO_PRIMITIVE: Partial<Record<SchemaNode['type'], PrimitiveSchemaType>> = {\n string: 'string',\n number: 'number',\n integer: 'integer',\n bigint: 'bigint',\n boolean: 'boolean',\n null: 'null',\n any: 'any',\n unknown: 'unknown',\n void: 'void',\n never: 'never',\n object: 'object',\n array: 'array',\n date: 'date',\n uuid: 'string',\n email: 'string',\n url: 'string',\n datetime: 'string',\n time: 'string',\n}\n\n/**\n * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n * For object schemas, `properties` defaults to an empty array.\n * `primitive` is automatically inferred from `type` when not explicitly provided.\n *\n * @example\n * ```ts\n * const scalar = createSchema({ type: 'string' })\n * // { kind: 'Schema', type: 'string', primitive: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const uuid = createSchema({ type: 'uuid' })\n * // { kind: 'Schema', type: 'uuid', primitive: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const object = createSchema({ type: 'object' })\n * // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }\n * ```\n *\n * @example\n * ```ts\n * const enumSchema = createSchema({\n * type: 'enum',\n * primitive: 'string',\n * enumValues: ['available', 'pending'],\n * })\n * ```\n */\nexport function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>\nexport function createSchema(props: CreateSchemaInput): SchemaNode\nexport function createSchema(props: CreateSchemaInput): SchemaNode {\n const inferredPrimitive = TYPE_TO_PRIMITIVE[props.type as keyof typeof TYPE_TO_PRIMITIVE]\n\n if (props['type'] === 'object') {\n return {\n properties: [],\n primitive: 'object',\n ...props,\n kind: 'Schema',\n } as CreateSchemaOutput<typeof props>\n }\n\n return {\n primitive: inferredPrimitive,\n ...props,\n kind: 'Schema',\n } as CreateSchemaOutput<typeof props>\n}\n\ntype UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>\n\n/**\n * Creates a `PropertyNode`.\n *\n * `required` defaults to `false`.\n * `schema.optional` and `schema.nullish` are derived from `required` and `schema.nullable`.\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * schema: createSchema({ type: 'string' }),\n * })\n * // required=false, schema.optional=true\n * ```\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * required: true,\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=true, no optional/nullish\n * ```\n */\nexport function createProperty(props: UserPropertyNode): PropertyNode {\n const required = props.required ?? false\n\n return {\n ...props,\n kind: 'Property',\n required,\n schema: syncOptionality(props.schema, required),\n }\n}\n\n/**\n * Creates a `ParameterNode`.\n *\n * `required` defaults to `false`.\n * Nested schema flags are set from `required` and `schema.nullable`.\n *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'petId',\n * in: 'path',\n * required: true,\n * schema: createSchema({ type: 'string' }),\n * })\n * ```\n *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'status',\n * in: 'query',\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=false, schema.nullish=true\n * ```\n */\nexport function createParameter(\n props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>,\n): ParameterNode {\n const required = props.required ?? false\n return {\n ...props,\n kind: 'Parameter',\n required,\n schema: syncOptionality(props.schema, required),\n }\n}\n\n/**\n * Creates a `ResponseNode`.\n *\n * Response body schemas live inside `content`. For convenience a single legacy `schema`\n * (with optional `mediaType`/`keysToOmit`) is normalized into one `content` entry, so the same\n * schema is never stored both at the node root and inside `content`.\n *\n * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],\n * })\n * ```\n */\nexport function createResponse(\n props: Pick<ResponseNode, 'statusCode'> &\n Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {\n content?: Array<UserContent>\n schema?: SchemaNode\n mediaType?: string | null\n keysToOmit?: Array<string> | null\n },\n): ResponseNode {\n const { schema, mediaType, keysToOmit, content, ...rest } = props\n const entries = content ?? (schema ? [{ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null }] : undefined)\n\n return {\n ...rest,\n kind: 'Response',\n content: entries?.map(createContent),\n }\n}\n\n/**\n * Creates a `FunctionParameterNode`.\n *\n * `optional` defaults to `false`.\n *\n * @example Required typed param\n * ```ts\n * createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }) })\n * // → petId: string\n * ```\n *\n * @example Optional param\n * ```ts\n * createFunctionParameter({ name: 'params', type: createParamsType({ variant: 'reference', name: 'QueryParams' }), optional: true })\n * // → params?: QueryParams\n * ```\n *\n * @example Param with default (implicitly optional. Cannot combine with `optional: true`)\n * ```ts\n * createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })\n * // → config: RequestConfig = {}\n * ```\n */\nexport function createFunctionParameter(\n props: { name: string; type?: ParamsTypeNode; rest?: boolean } & ({ optional: true; default?: never } | { optional?: false; default?: string }),\n): FunctionParameterNode {\n return {\n optional: false,\n ...props,\n kind: 'FunctionParameter',\n } as FunctionParameterNode\n}\n\n/**\n * Creates a {@link TypeNode} representing a language-agnostic structured type expression.\n *\n * Use `variant: 'struct'` for inline anonymous types and `variant: 'member'` for a single\n * named field accessed from a group type. Each language's printer renders the variant\n * into its own syntax (TypeScript, Python, C#, Kotlin, …).\n *\n * @example Reference type (TypeScript: `QueryParams`)\n * ```ts\n * createParamsType({ variant: 'reference', name: 'QueryParams' })\n * ```\n *\n * @example Struct type (TypeScript: `{ petId: string }`)\n * ```ts\n * createParamsType({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createParamsType({ variant: 'reference', name: 'string' }) }] })\n * ```\n *\n * @example Member type (TypeScript: `DeletePetPathParams['petId']`)\n * ```ts\n * createParamsType({ variant: 'member', base: 'DeletePetPathParams', key: 'petId' })\n * ```\n */\nexport function createParamsType(\n props:\n | { variant: 'reference'; name: string }\n | {\n variant: 'struct'\n properties: Array<{\n name: string\n optional: boolean\n type: ParamsTypeNode\n }>\n }\n | { variant: 'member'; base: string; key: string },\n): ParamsTypeNode {\n return { ...props, kind: 'ParamsType' } as ParamsTypeNode\n}\n\n/**\n * Creates a `ParameterGroupNode` representing a group of related parameters treated as a unit.\n *\n * @example Grouped param (TypeScript declaration)\n * ```ts\n * createParameterGroup({\n * properties: [\n * createFunctionParameter({ name: 'id', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),\n * createFunctionParameter({ name: 'name', type: createParamsType({ variant: 'reference', name: 'string' }), optional: true }),\n * ],\n * default: '{}',\n * })\n * // declaration → { id, name? }: { id: string; name?: string } = {}\n * // call → { id, name }\n * ```\n *\n * @example Inline (spread), children emitted as individual top-level parameters\n * ```ts\n * createParameterGroup({\n * properties: [createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false })],\n * inline: true,\n * })\n * // declaration → petId: string\n * // call → petId\n * ```\n */\nexport function createParameterGroup(\n props: Pick<ParameterGroupNode, 'properties'> & Partial<Omit<ParameterGroupNode, 'kind' | 'properties'>>,\n): ParameterGroupNode {\n return {\n ...props,\n kind: 'ParameterGroup',\n }\n}\n\n/**\n * Creates a `FunctionParametersNode` from an ordered list of parameters.\n *\n * @example\n * ```ts\n * createFunctionParameters({\n * params: [\n * createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),\n * createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), optional: false, default: '{}' }),\n * ],\n * })\n * ```\n *\n * @example\n * ```ts\n * const empty = createFunctionParameters()\n * // { kind: 'FunctionParameters', params: [] }\n * ```\n */\nexport function createFunctionParameters(props: Partial<Omit<FunctionParametersNode, 'kind'>> = {}): FunctionParametersNode {\n return {\n params: [],\n ...props,\n kind: 'FunctionParameters',\n }\n}\n\n/**\n * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.\n *\n * @example Named import\n * ```ts\n * createImport({ name: ['useState'], path: 'react' })\n * // import { useState } from 'react'\n * ```\n *\n * @example Type-only import\n * ```ts\n * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })\n * // import type { FC } from 'react'\n * ```\n */\nexport function createImport(props: Omit<ImportNode, 'kind'>): ImportNode {\n return { ...props, kind: 'Import' }\n}\n\n/**\n * Creates an `ExportNode` representing a language-agnostic export/public API declaration.\n *\n * @example Named export\n * ```ts\n * createExport({ name: ['Pet'], path: './Pet' })\n * // export { Pet } from './Pet'\n * ```\n *\n * @example Wildcard export\n * ```ts\n * createExport({ path: './utils' })\n * // export * from './utils'\n * ```\n */\nexport function createExport(props: Omit<ExportNode, 'kind'>): ExportNode {\n return { ...props, kind: 'Export' }\n}\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })\n * ```\n */\nexport function createSource(props: Omit<SourceNode, 'kind'>): SourceNode {\n return { ...props, kind: 'Source' }\n}\n\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const rawExtname = path.extname(input.baseName)\n // Handle dotfile basename like '.ts' where path.extname returns ''\n const extname = (rawExtname || (input.baseName.startsWith('.') ? input.baseName : '')) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const source = (input.sources ?? [])\n .flatMap((item) => item.nodes ?? [])\n .map((node) => extractStringsFromNodes([node]))\n .filter(Boolean)\n .join('\\n\\n')\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []\n const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name): name is string => Boolean(name)))\n const nameOf = (item: string | { propertyName: string; name?: string }): string => (typeof item === 'string' ? item : (item.name ?? item.propertyName))\n // Drop self-imports. Consolidating output (`mode: 'file'`) can place a symbol's\n // definition and a cross-file import of it in the same file. The first pass catches imports that\n // resolve to this file's own path. The second drops imports of names the file already defines,\n // the case consolidation produces when the import path no longer matches `input.path`. Sources\n // stay intact, so the local definition remains. Bare specifiers like `'zod'` never match a path.\n const resolvedImports = combinedImports\n .filter((imp) => imp.path !== input.path)\n .flatMap((imp) => {\n if (!Array.isArray(imp.name)) {\n return typeof imp.name === 'string' && localNames.has(imp.name) ? [] : [imp]\n }\n const kept = imp.name.filter((item) => !localNames.has(nameOf(item)))\n if (!kept.length) return []\n return [kept.length === imp.name.length ? imp : { ...imp, name: kept }]\n })\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n return {\n kind: 'File',\n ...input,\n id: hash('sha256', input.path, 'hex'),\n name: trimExtName(input.baseName),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: input.meta ?? ({} as TMeta),\n }\n}\n\n/**\n * Creates a `ConstNode` representing a TypeScript `const` declaration.\n *\n * Mirrors the `Const` component from `@kubb/renderer-jsx`.\n * The component's `children` are represented as `nodes`.\n *\n * @example Simple constant\n * ```ts\n * createConst({ name: 'pet' })\n * // const pet = ...\n * ```\n *\n * @example Exported constant with type and `as const`\n * ```ts\n * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })\n * // export const pets: Pet[] = ... as const\n * ```\n *\n * @example With JSDoc and child nodes\n * ```ts\n * createConst({\n * name: 'config',\n * export: true,\n * JSDoc: { comments: ['@description App configuration'] },\n * nodes: [],\n * })\n * ```\n */\nexport function createConst(props: Omit<ConstNode, 'kind'>): ConstNode {\n return { ...props, kind: 'Const' }\n}\n\n/**\n * Creates a `TypeNode` representing a TypeScript `type` alias declaration.\n *\n * Mirrors the `Type` component from `@kubb/renderer-jsx`.\n * The component's `children` are represented as `nodes`.\n *\n * @example Simple type alias\n * ```ts\n * createType({ name: 'Pet' })\n * // type Pet = ...\n * ```\n *\n * @example Exported type with JSDoc\n * ```ts\n * createType({\n * name: 'PetStatus',\n * export: true,\n * JSDoc: { comments: ['@description Status of a pet'] },\n * })\n * // export type PetStatus = ...\n * ```\n */\nexport function createType(props: Omit<TypeNode, 'kind'>): TypeNode {\n return { ...props, kind: 'Type' }\n}\n\n/**\n * Creates a `FunctionNode` representing a TypeScript `function` declaration.\n *\n * Mirrors the `Function` component from `@kubb/renderer-jsx`.\n * The component's `children` are represented as `nodes`.\n *\n * @example Simple function\n * ```ts\n * createFunction({ name: 'getPet' })\n * // function getPet() { ... }\n * ```\n *\n * @example Exported async function with return type\n * ```ts\n * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })\n * // export async function fetchPet(): Promise<Pet> { ... }\n * ```\n *\n * @example Function with generics and params\n * ```ts\n * createFunction({\n * name: 'identity',\n * export: true,\n * generics: ['T'],\n * params: 'value: T',\n * returnType: 'T',\n * })\n * // export function identity<T>(value: T): T { ... }\n * ```\n */\nexport function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode {\n return { ...props, kind: 'Function' }\n}\n\n/**\n * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.\n *\n * Mirrors the `Function.Arrow` component from `@kubb/renderer-jsx`.\n * The component's `children` are represented as `nodes`.\n *\n * @example Simple arrow function\n * ```ts\n * createArrowFunction({ name: 'getPet' })\n * // const getPet = () => { ... }\n * ```\n *\n * @example Single-line exported arrow function\n * ```ts\n * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })\n * // export const double = (n: number) => ...\n * ```\n *\n * @example Async arrow function with generics\n * ```ts\n * createArrowFunction({\n * name: 'fetchPet',\n * export: true,\n * async: true,\n * generics: ['T'],\n * params: 'id: string',\n * returnType: 'T',\n * })\n * // export const fetchPet = async <T>(id: string): Promise<T> => { ... }\n * ```\n */\nexport function createArrowFunction(props: Omit<ArrowFunctionNode, 'kind'>): ArrowFunctionNode {\n return { ...props, kind: 'ArrowFunction' }\n}\n\n/**\n * Creates a {@link TextNode} representing a raw string fragment in the source output.\n *\n * Use this instead of bare strings when building `nodes` arrays so that every\n * entry in the array is a typed {@link CodeNode}.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport function createText(value: string): TextNode {\n return { value, kind: 'Text' }\n}\n\n/**\n * Creates a {@link BreakNode} representing a line break in the source output.\n *\n * Corresponds to `<br/>` in JSX components. Prints as an empty string which,\n * when joined with `\\n` by `printNodes`, produces a blank line.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport function createBreak(): BreakNode {\n return { kind: 'Break' }\n}\n\n/**\n * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.\n *\n * Use this to embed JSX markup (including fragments `<>…</>`) directly in generated code.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport function createJsx(value: string): JsxNode {\n return { value, kind: 'Jsx' }\n}\n","import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Node → digest cache, keyed by identity. A `WeakMap` so entries die with the node, and so a tree\n * hashed during dedupe planning is not walked again when it is rewritten during streaming. Reuse\n * is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: SchemaNode, b: SchemaNode): boolean {\n return signatureOf(a) === signatureOf(b)\n}\n","import { createSchema } from './factory.ts'\nimport type { Node, OperationNode, SchemaNode } from './nodes/index.ts'\nimport { signatureOf } from './signature.ts'\nimport { extractRefName } from './utils/index.ts'\nimport { collectLazy, transform } from './visitor.ts'\n\n/**\n * A canonical destination for a deduplicated shape: the shared schema name and\n * the synthetic `$ref` path that points at it.\n */\nexport type DedupeCanonical = {\n /**\n * Canonical schema name every duplicate occurrence refers to.\n */\n name: string\n /**\n * `$ref` path stored on the generated `ref` nodes (for example `#/components/schemas/Status`).\n */\n ref: string\n}\n\n/**\n * The result of {@link buildDedupePlan}: a lookup from structural signature to its\n * canonical target, plus the freshly hoisted definitions that must be added to\n * the schema list.\n */\nexport type DedupePlan = {\n /**\n * Maps a structural signature to the canonical schema that represents it.\n */\n canonicalBySignature: Map<string, DedupeCanonical>\n /**\n * Maps the name of a top-level schema that duplicates a canonical one to that canonical, so\n * references to the duplicate can be repointed at the first schema with the same content.\n */\n aliasNames: Map<string, DedupeCanonical>\n /**\n * New top-level schema definitions created for inline shapes that had no existing\n * named component. Nested duplicates inside each definition are already collapsed.\n */\n hoisted: Array<SchemaNode>\n}\n\n/**\n * The lookups {@link applyDedupe} needs from a {@link DedupePlan}.\n */\nexport type DedupeLookups = Pick<DedupePlan, 'canonicalBySignature' | 'aliasNames'>\n\n/**\n * Options that inject the naming and candidate policy into {@link buildDedupePlan}.\n * The mechanics (grouping, counting, rewriting) live here. The policy lives in the caller.\n */\nexport type BuildDedupePlanOptions = {\n /**\n * Returns `true` when a node should be deduplicated. This is the only gate, so it must\n * reject both ineligible kinds (return `false` for anything other than, say, enums and\n * objects) and unsafe shapes (e.g. nodes that reference a circular schema).\n */\n isCandidate: (node: SchemaNode) => boolean\n /**\n * Produces the canonical name for an inline shape with no existing named component.\n * Return `null` to leave the shape inline (for example when no contextual name exists).\n */\n nameFor: (node: SchemaNode, signature: string) => string | null\n /**\n * Builds the `$ref` path for a canonical name.\n */\n refFor: (name: string) => string\n /**\n * Minimum number of occurrences before a shape is deduplicated.\n *\n * @default 2\n */\n minOccurrences?: number\n}\n\n/**\n * Builds the shared `ref` replacement for a duplicate occurrence, carrying the\n * usage-slot and documentation fields that are not part of the canonical type.\n */\nfunction createRefNode(node: SchemaNode, canonical: DedupeCanonical): SchemaNode {\n return createSchema({\n type: 'ref',\n name: canonical.name,\n ref: canonical.ref,\n optional: node.optional,\n nullish: node.nullish,\n readOnly: node.readOnly,\n writeOnly: node.writeOnly,\n deprecated: node.deprecated,\n description: node.description,\n default: node.default,\n example: node.example,\n })\n}\n\n/**\n * Rewrites a node, replacing every candidate sub-schema whose signature has a canonical\n * target with a `ref` to that target. Replacing a node with a `ref` prunes its subtree,\n * so nested duplicates inside a replaced shape are not visited again. A `ref` that points\n * at a duplicate top-level schema (see `aliasNames`) is repointed at the first schema with\n * the same content.\n *\n * Pass `skipRootMatch` when rewriting a canonical definition so its own root is not\n * turned into a reference to itself. Nested duplicates are still collapsed.\n *\n * @example\n * ```ts\n * const next = applyDedupe(operationNode, plan)\n * ```\n */\nexport function applyDedupe(node: SchemaNode, plan: DedupeLookups, skipRootMatch?: boolean): SchemaNode\nexport function applyDedupe(node: OperationNode, plan: DedupeLookups, skipRootMatch?: boolean): OperationNode\nexport function applyDedupe(node: Node, plan: DedupeLookups, skipRootMatch = false): Node {\n const { canonicalBySignature, aliasNames } = plan\n if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node\n\n const root = node\n\n return transform(node, {\n schema(schemaNode) {\n if (schemaNode.type === 'ref') {\n const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name\n const canonical = target ? aliasNames.get(target) : undefined\n\n return canonical ? { ...schemaNode, name: canonical.name, ref: canonical.ref } : undefined\n }\n\n const signature = signatureOf(schemaNode)\n if (skipRootMatch && schemaNode === root) return undefined\n\n const canonical = canonicalBySignature.get(signature)\n if (!canonical) return undefined\n\n return createRefNode(schemaNode, canonical)\n },\n })\n}\n\n/**\n * Strips usage-slot flags from a hoisted definition and applies its canonical name.\n * A standalone definition is never optional, so `optional`/`nullish` are cleared.\n */\nfunction cleanDefinition(node: SchemaNode, name: string): SchemaNode {\n return { ...node, name, optional: undefined, nullish: undefined }\n}\n\n/**\n * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.\n *\n * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence\n * is a named top-level schema, the first one becomes the canonical (so other top-level\n * duplicates and inline copies turn into references to it). Every other top-level name with\n * the same content is recorded in `aliasNames`, so refs to it can be repointed at the\n * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied\n * per node with {@link applyDedupe}.\n *\n * @example\n * ```ts\n * const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {\n * isCandidate: (node) => node.type === 'enum' || node.type === 'object',\n * nameFor: (node) => node.name ?? null,\n * refFor: (name) => `#/components/schemas/${name}`,\n * })\n * ```\n */\nexport function buildDedupePlan(roots: ReadonlyArray<Node>, options: BuildDedupePlanOptions): DedupePlan {\n const { isCandidate, nameFor, refFor, minOccurrences = 2 } = options\n\n const topLevelNodes = new Set<SchemaNode>()\n\n type Group = {\n count: number\n representative: SchemaNode\n topLevelNames: Array<string>\n }\n const groups = new Map<string, Group>()\n\n function record(schemaNode: SchemaNode): void {\n const signature = signatureOf(schemaNode)\n if (!isCandidate(schemaNode)) return\n\n const isTopLevel = topLevelNodes.has(schemaNode) && !!schemaNode.name\n const group = groups.get(signature)\n if (group) {\n group.count++\n if (isTopLevel) group.topLevelNames.push(schemaNode.name!)\n } else {\n groups.set(signature, { count: 1, representative: schemaNode, topLevelNames: isTopLevel ? [schemaNode.name!] : [] })\n }\n }\n\n for (const root of roots) {\n if (root.kind === 'Schema') topLevelNodes.add(root)\n for (const schemaNode of collectLazy<SchemaNode>(root, { schema: (node) => node })) {\n record(schemaNode)\n }\n }\n\n const canonicalBySignature = new Map<string, DedupeCanonical>()\n const aliasNames = new Map<string, DedupeCanonical>()\n const pendingHoists: Array<{ name: string; representative: SchemaNode }> = []\n\n for (const [signature, group] of groups) {\n if (group.count < minOccurrences) continue\n\n const [firstName, ...duplicateNames] = group.topLevelNames\n if (firstName) {\n const canonical: DedupeCanonical = { name: firstName, ref: refFor(firstName) }\n canonicalBySignature.set(signature, canonical)\n for (const duplicate of duplicateNames) {\n aliasNames.set(duplicate, canonical)\n }\n continue\n }\n\n const name = nameFor(group.representative, signature)\n if (!name) continue\n\n canonicalBySignature.set(signature, { name, ref: refFor(name) })\n pendingHoists.push({ name, representative: group.representative })\n }\n\n // Build hoisted definitions only after every canonical name is known, so nested\n // duplicates inside a definition also resolve to refs.\n const hoisted = pendingHoists.map(({ name, representative }) =>\n cleanDefinition(applyDedupe(representative, { canonicalBySignature, aliasNames }, true), name),\n )\n\n return { canonicalBySignature, aliasNames, hoisted }\n}\n","/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * Whether the schema is nullable.\n */\n isNullable: (schema?: TSchema) => boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference: (value?: unknown) => value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator: (value?: unknown) => value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary: (schema: TSchema) => boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef: <TResolved>(document: TDocument, ref: string) => TResolved | null | undefined\n}\n\n/**\n * Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineSchemaDialect({\n * name: 'oas',\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * })\n * ```\n */\nexport function defineSchemaDialect<TSchema, TRef, TDiscriminated, TDocument>(\n dialect: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>,\n): SchemaDialect<TSchema, TRef, TDiscriminated, TDocument> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.\n **\n * @example\n * ```ts\n * export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(\n * (node) => kindToHandlerKey[node.kind],\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n","import { isScalarPrimitive } from './constants.ts'\nimport { createProperty, createSchema } from './factory.ts'\nimport { narrowSchema } from './guards.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { enumPropName } from './utils/index.ts'\n\n/**\n * Replaces a discriminator property's schema with a string enum of allowed values.\n *\n * If `node` is not an object schema, or if the property does not exist, the input\n * node is returned as-is.\n *\n * @example\n * ```ts\n * const schema = createSchema({\n * type: 'object',\n * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],\n * })\n * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })\n * ```\n */\nexport function setDiscriminatorEnum({\n node,\n propertyName,\n values,\n enumName,\n}: {\n node: SchemaNode\n propertyName: string\n values: Array<string>\n enumName?: string\n}): SchemaNode {\n const objectNode = narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) {\n return node\n }\n\n const hasProperty = objectNode.properties.some((prop) => prop.name === propertyName)\n if (!hasProperty) {\n return node\n }\n\n return createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) {\n return prop\n }\n\n return createProperty({\n ...prop,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n}\n\n/**\n * Merges adjacent anonymous object members into a single anonymous object member.\n *\n * @example\n * ```ts\n * const merged = mergeAdjacentObjects([\n * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),\n * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),\n * ])\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n\nexport function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode> {\n return [...mergeAdjacentObjectsLazy(members)]\n}\n\n/**\n * Removes enum members that are covered by broader scalar primitives in the same union.\n *\n * @example\n * ```ts\n * const simplified = simplifyUnion([\n * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),\n * createSchema({ type: 'string' }),\n * ])\n * // keeps only string member\n * ```\n */\nexport function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode> {\n const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type))\n\n if (!scalarPrimitives.size) {\n return members\n }\n\n return members.filter((member) => {\n const enumNode = narrowSchema(member, 'enum')\n if (!enumNode) {\n return true\n }\n\n const primitive = enumNode.primitive\n if (!primitive) {\n return true\n }\n\n const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0\n if (enumValueCount <= 1) {\n return true\n }\n\n if (scalarPrimitives.has(primitive)) {\n return false\n }\n\n if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) {\n return false\n }\n\n return true\n })\n}\n\nexport function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode {\n const enumNode = narrowSchema(propNode, 'enum')\n\n if (enumNode?.primitive === 'boolean') {\n return { ...propNode, name: null }\n }\n\n if (enumNode) {\n return {\n ...propNode,\n name: enumPropName(parentName, propName, enumSuffix),\n }\n }\n\n return propNode\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8LA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,GAAG;CACrC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,QAAQ,GAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ;CAE/B,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACvDA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;;;;;;ACzIA,SAAgB,aAA2C,MAA8B,MAAqC;CAC5H,OAAO,MAAM,SAAS,OAAQ,OAA+B;AAC/D;AAEA,SAAS,OAAuB,MAAgB;CAC9C,QAAQ,SAA8B,KAAc,SAAS;AAC/D;;;;;;;;;;;AAYA,MAAa,cAAc,OAAkB,OAAO;;;;;;;;;;;AAYpD,MAAa,eAAe,OAAmB,QAAQ;;;;;;;;;;;AAYvD,MAAa,kBAAkB,OAAsB,WAAW;;;;;;;;;;;AAYhE,SAAgB,oBAAoB,MAAgD;CAClF,OAAO,KAAK,aAAa,UAAW,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;AACjF;;;;;;;;;;;AAYA,MAAa,eAAe,OAAmB,QAAQ;;;;;;;;;;;;;;;;;AChDvD,SAAS,YAAY,aAAqB;CACxC,IAAI,SAAS;CACb,MAAM,QAA2B,CAAC;CAElC,S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AC,WACH,OAAO;EAIT,KADuB,SAAS,iBAAiB,UAAU,SAAS,YAAY,UAAU,MACpE,GACpB,OAAO;EAGT,IAAI,iBAAiB,IAAI,SAAS,GAChC,OAAO;EAGT,KAAK,cAAc,aAAa,cAAc,cAAc,iBAAiB,IAAI,SAAS,KAAK,iBAAiB,IAAI,QAAQ,IAC1H,OAAO;EAGT,OAAO;CACT,CAAC;AACH;AAEA,SAAgB,YAAY,UAAsB,YAAuC,UAAkB,YAAgC;CACzI,MAAM,WAAW,aAAa,UAAU,MAAM;CAE9C,IAAI,UAAU,cAAc,WAC1B,OAAO;EAAE,GAAG;EAAU,MAAM;CAAK;CAGnC,IAAI,UACF,OAAO;EACL,GAAG;EACH,MAAMC,cAAAA,aAAa,YAAY,UAAU,UAAU;CACrD;CAGF,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["extractRefName","obj","visitorDepths","extractRefName","isValidVarName","camelCase","extractRefName","path","isScalarPrimitive","enumPropName"],"sources":["../src/node.ts","../src/nodes/schema.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/promise.ts","../src/signature.ts","../src/nodes/code.ts","../src/nodes/content.ts","../src/nodes/file.ts","../src/nodes/function.ts","../src/nodes/input.ts","../src/nodes/requestBody.ts","../src/nodes/operation.ts","../src/nodes/output.ts","../src/nodes/parameter.ts","../src/nodes/property.ts","../src/nodes/response.ts","../src/registry.ts","../src/visitor.ts","../src/dedupe.ts","../src/dialect.ts","../src/guards.ts","../src/utils/ast.ts","../src/factory.ts","../src/printer.ts","../src/transformers.ts"],"sourcesContent":["import type { BaseNode, NodeKind } from './nodes/base.ts'\nimport type { SchemaNode } from './nodes/index.ts'\n\n/**\n * Visitor callback names, one per traversable node kind. Kept in sync with the\n * keys of `Visitor` in `visitor.ts`.\n */\ntype VisitorKey = 'input' | 'output' | 'operation' | 'schema' | 'property' | 'parameter' | 'response'\n\n/**\n * Distributive `Omit` that preserves each member of a union.\n *\n * @example\n * ```ts\n * type A = { kind: 'a'; keep: string; drop: number }\n * type B = { kind: 'b'; keep: boolean; drop: number }\n * type Result = DistributiveOmit<A | B, 'drop'>\n * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }\n * ```\n */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/**\n * Builds a type guard that matches nodes of the given `kind`.\n */\nexport function isKind<T extends BaseNode>(kind: NodeKind) {\n return (node: unknown): node is T => (node as BaseNode).kind === kind\n}\n\n/**\n * Updates a schema's `optional` and `nullish` flags from a parent's `required`\n * value and the schema's own `nullable`. Mirrors how OpenAPI parameters and\n * object properties combine \"required\" and \"nullable\" into a single AST.\n *\n * - Non-required + non-nullable → `optional: true`.\n * - Non-required + nullable → `nullish: true`.\n * - Required → both flags cleared.\n */\nexport function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode {\n const nullable = schema.nullable ?? false\n\n return {\n ...schema,\n optional: !required && !nullable ? true : undefined,\n nullish: !required && nullable ? true : undefined,\n }\n}\n\n/**\n * The single definition derived from one {@link defineNode} call: the node's\n * `create` builder, its `is` guard, and the traversal metadata the registry\n * collects into the visitor tables.\n */\nexport type NodeDef<TNode extends BaseNode = BaseNode, TInput = never> = {\n /**\n * Node discriminator this definition owns.\n */\n kind: NodeKind\n /**\n * Builds a node from its input, applying `defaults` and the optional `build` hook.\n */\n create: (input: TInput) => TNode\n /**\n * Type guard matching this node kind.\n */\n is: (node: unknown) => node is TNode\n /**\n * Child node fields in traversal order. Feeds `VISITOR_KEYS`.\n */\n children?: ReadonlyArray<string>\n /**\n * Visitor callback name. Feeds `VISITOR_KEY_BY_KIND`.\n */\n visitorKey?: VisitorKey\n /**\n * When `true`, `create` is rerun after children are rebuilt so computed fields\n * stay in sync. Feeds `nodeRebuilders`.\n */\n rebuild?: boolean\n}\n\ntype DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {\n kind: TNode['kind']\n defaults?: Partial<TNode>\n build?: (input: TInput) => TBuilt\n children?: ReadonlyArray<string>\n visitorKey?: VisitorKey\n rebuild?: boolean\n}\n\n/**\n * Defines a node once and derives its `create` builder, `is` guard, and traversal\n * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the\n * `kind`, so node construction lives in one place without scattered `as` casts.\n *\n * Set `rebuild: true` when the `build` hook derives fields from children. After a\n * transform rewrites those children, the registry reruns `create` so the derived\n * fields stay correct.\n *\n * @example Simple node\n * ```ts\n * const importDef = defineNode<ImportNode>({ kind: 'Import' })\n * const createImport = importDef.create\n * ```\n *\n * @example Node with a build hook that is rerun on transform\n * ```ts\n * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({\n * kind: 'Property',\n * build: (props) => ({ ...props, required: props.required ?? false }),\n * children: ['schema'],\n * visitorKey: 'property',\n * rebuild: true,\n * })\n * ```\n */\nexport function defineNode<TNode extends BaseNode, TInput = Omit<TNode, 'kind'>, TBuilt extends object = Omit<TNode, 'kind'>>(\n config: DefineNodeConfig<TNode, TInput, TBuilt>,\n): NodeDef<TNode, TInput> {\n const { kind, defaults, build, children, visitorKey, rebuild } = config\n\n function create(input: TInput): TNode {\n const base = build ? build(input) : input\n return { ...defaults, ...(base as object), kind } as TNode\n }\n\n return { kind, create, is: isKind<TNode>(kind), children, visitorKey, rebuild }\n}\n","import type { InferSchemaNode } from '../infer.ts'\nimport { defineNode, type DistributiveOmit } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { PropertyNode } from './property.ts'\n\nexport type PrimitiveSchemaType =\n /**\n * Text value.\n */\n | 'string'\n /**\n * Floating-point number.\n */\n | 'number'\n /**\n * Integer number.\n */\n | 'integer'\n /**\n * Big integer number.\n */\n | 'bigint'\n /**\n * Boolean value.\n */\n | 'boolean'\n /**\n * Null value.\n */\n | 'null'\n /**\n * Any value.\n */\n | 'any'\n /**\n * Unknown value.\n */\n | 'unknown'\n /**\n * No value (`void`).\n */\n | 'void'\n /**\n * Never value.\n */\n | 'never'\n /**\n * Object value.\n */\n | 'object'\n /**\n * Array value.\n */\n | 'array'\n /**\n * Date value.\n */\n | 'date'\n\n/**\n * Composite schema types.\n */\ntype ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum'\n\n/**\n * Schema types that need special handling in generators.\n */\ntype SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob'\n\n/**\n * All schema type strings.\n */\nexport type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType\n\n/**\n * Scalar schema types without extra object/array/ref structure.\n */\nexport type ScalarSchemaType = Exclude<\n SchemaType,\n | 'object'\n | 'array'\n | 'tuple'\n | 'union'\n | 'intersection'\n | 'enum'\n | 'ref'\n | 'datetime'\n | 'date'\n | 'time'\n | 'string'\n | 'number'\n | 'integer'\n | 'bigint'\n | 'url'\n | 'uuid'\n | 'email'\n>\n\n/**\n * Fields shared by all schema nodes.\n */\ntype SchemaNodeBase = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Schema'\n /**\n * Schema name for named definitions (for example, `\"Pet\"`).\n * Inline schemas omit this field.\n * `null` means kubb has processed this and determined there is no applicable name.\n * `undefined` means the name has not been set yet.\n */\n name?: string | null\n /**\n * Short schema title.\n */\n title?: string\n /**\n * Schema description text.\n */\n description?: string\n /**\n * Whether `null` is allowed.\n */\n nullable?: boolean\n /**\n * Whether the field is optional.\n */\n optional?: boolean\n /**\n * Both optional and nullable (`optional` + `nullable`).\n */\n nullish?: boolean\n /**\n * Whether the schema is deprecated.\n */\n deprecated?: boolean\n /**\n * Whether the schema is read-only.\n */\n readOnly?: boolean\n /**\n * Whether the schema is write-only.\n */\n writeOnly?: boolean\n /**\n * Default value.\n */\n default?: unknown\n /**\n * Example value.\n */\n example?: unknown\n /**\n * Base primitive type.\n * For example, this is `'string'` for a `uuid` schema.\n */\n primitive?: PrimitiveSchemaType\n /**\n * Schema `format` value.\n */\n format?: string\n}\n\n/**\n * Object schema with ordered properties.\n *\n * @example\n * ```ts\n * const objectSchema: ObjectSchemaNode = {\n * kind: 'Schema',\n * type: 'object',\n * properties: [],\n * }\n * ```\n */\nexport type ObjectSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'object'\n /**\n * Primitive type, always `'object'` for object schemas.\n */\n primitive: 'object'\n /**\n * Ordered object properties.\n */\n properties: Array<PropertyNode>\n /**\n * Additional object properties behavior:\n * - `true`: allow any value\n * - `false`: reject unknown properties (maps to `.strict()` in Zod)\n * - `SchemaNode`: allow values that match that schema\n * - `undefined`: no additional properties constraint (open object)\n */\n additionalProperties?: SchemaNode | boolean\n /**\n * Pattern-based property schemas.\n */\n patternProperties?: Record<string, SchemaNode>\n /**\n * Minimum number of properties allowed.\n */\n minProperties?: number\n /**\n * Maximum number of properties allowed.\n */\n maxProperties?: number\n}\n\n/**\n * Array-like schema (`array` or `tuple`).\n *\n * @example\n * ```ts\n * const arraySchema: ArraySchemaNode = {\n * kind: 'Schema',\n * type: 'array',\n * items: [],\n * }\n * ```\n */\nexport type ArraySchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator (`array` or `tuple`).\n */\n type: 'array' | 'tuple'\n /**\n * Item schemas.\n */\n items?: Array<SchemaNode>\n /**\n * Tuple rest-item schema for elements beyond positional `items`.\n */\n rest?: SchemaNode\n /**\n * Minimum item count (or tuple length).\n */\n min?: number\n /**\n * Maximum item count (or tuple length).\n */\n max?: number\n /**\n * Whether all items must be unique.\n */\n unique?: boolean\n}\n\n/**\n * Shared shape for union and intersection schemas.\n */\ntype CompositeSchemaNodeBase = SchemaNodeBase & {\n /**\n * Member schemas.\n */\n members?: Array<SchemaNode>\n}\n\n/**\n * Union schema, often from `oneOf` or `anyOf`.\n *\n * @example\n * ```ts\n * const unionSchema: UnionSchemaNode = {\n * kind: 'Schema',\n * type: 'union',\n * members: [],\n * }\n * ```\n */\nexport type UnionSchemaNode = CompositeSchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'union'\n /**\n * Discriminator property name from OpenAPI `discriminator.propertyName`.\n */\n discriminatorPropertyName?: string\n /**\n * Logical strategy applied to union members: 'one' means exactly one member must be valid (from `oneOf`),\n * 'any' means any number of members can be valid (from `anyOf`).\n */\n strategy?: 'one' | 'any'\n}\n\n/**\n * Intersection schema, often from `allOf`.\n *\n * @example\n * ```ts\n * const intersectionSchema: IntersectionSchemaNode = {\n * kind: 'Schema',\n * type: 'intersection',\n * members: [],\n * }\n * ```\n */\nexport type IntersectionSchemaNode = CompositeSchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'intersection'\n}\n\n/**\n * One named enum item.\n */\ntype EnumValueNode = {\n /**\n * Enum item name.\n */\n name: string\n /**\n * Enum item value.\n */\n value: string | number | boolean\n /**\n * Primitive type of the enum value.\n */\n primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>\n}\n\n/**\n * Enum schema node.\n *\n * @example\n * ```ts\n * const enumSchema: EnumSchemaNode = {\n * kind: 'Schema',\n * type: 'enum',\n * enumValues: ['a', 'b'],\n * }\n * ```\n */\nexport type EnumSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'enum'\n /**\n * Enum values in simple form.\n */\n enumValues?: Array<string | number | boolean | null>\n /**\n * Enum values in named form.\n * If present, this is used instead of `enumValues`.\n */\n namedEnumValues?: Array<EnumValueNode>\n}\n\n/**\n * Reference schema that points to another schema definition.\n *\n * @example\n * ```ts\n * const refSchema: RefSchemaNode = {\n * kind: 'Schema',\n * type: 'ref',\n * ref: '#/components/schemas/Pet',\n * }\n * ```\n */\nexport type RefSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'ref'\n /**\n * Referenced schema name.\n * `null` means Kubb has processed this and determined there is no applicable name.\n */\n name?: string | null\n /**\n * Original `$ref` path, for example, `#/components/schemas/Order`.\n * Used to resolve names later.\n */\n ref?: string\n /**\n * Pattern copied from a sibling `pattern` field.\n */\n pattern?: string\n /**\n * The fully-parsed schema this ref resolves to, so its structure (`primitive`, `properties`)\n * can be read without following the reference. Populated during OAS parsing when the\n * definition resolves, `null` when it can't or the ref is circular, and `undefined` when\n * resolution has not been attempted.\n */\n schema?: SchemaNode | null\n}\n\n/**\n * Datetime schema.\n *\n * @example\n * ```ts\n * const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }\n * ```\n */\nexport type DatetimeSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'datetime'\n /**\n * Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).\n */\n offset?: boolean\n /**\n * Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).\n */\n local?: boolean\n}\n\n/**\n * Shared base for `date` and `time` schemas.\n */\ntype TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: T\n /**\n * Output representation in generated code.\n */\n representation: 'date' | 'string'\n}\n\n/**\n * Date schema node.\n *\n * @example\n * ```ts\n * const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }\n * ```\n */\nexport type DateSchemaNode = TemporalSchemaNodeBase<'date'>\n\n/**\n * Time schema node.\n *\n * @example\n * ```ts\n * const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }\n * ```\n */\nexport type TimeSchemaNode = TemporalSchemaNodeBase<'time'>\n\n/**\n * String schema node.\n *\n * @example\n * ```ts\n * const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }\n * ```\n */\nexport type StringSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'string'\n /**\n * Minimum string length.\n */\n min?: number\n /**\n * Maximum string length.\n */\n max?: number\n /**\n * Regex pattern.\n */\n pattern?: string\n}\n\n/**\n * Numeric schema (`number`, `integer`, or `bigint`).\n *\n * @example\n * ```ts\n * const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }\n * ```\n */\nexport type NumberSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'number' | 'integer' | 'bigint'\n /**\n * Minimum value.\n */\n min?: number\n /**\n * Maximum value.\n */\n max?: number\n /**\n * Exclusive minimum value.\n */\n exclusiveMinimum?: number\n /**\n * Exclusive maximum value.\n */\n exclusiveMaximum?: number\n /**\n * The value must be a multiple of this number.\n */\n multipleOf?: number\n}\n\n/**\n * Scalar schema with no extra constraints.\n *\n * @example\n * ```ts\n * const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }\n * ```\n */\nexport type ScalarSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: ScalarSchemaType\n}\n\n/**\n * URL schema node.\n * Can include an OpenAPI-style path template for template literal types.\n *\n * @example\n * ```ts\n * const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }\n * ```\n */\nexport type UrlSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'url'\n /**\n * OpenAPI-style path template, for example, `'/pets/{petId}'`.\n */\n path?: string\n /**\n * Minimum string length.\n */\n min?: number\n /**\n * Maximum string length.\n */\n max?: number\n}\n\n/**\n * Format-string schema for string-based formats that support length constraints.\n *\n * @example\n * ```ts\n * const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }\n * ```\n */\ntype FormatStringSchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'uuid' | 'email'\n /**\n * Minimum string length.\n */\n min?: number\n /**\n * Maximum string length.\n */\n max?: number\n}\n\n/**\n * IPv4 address schema node.\n *\n * @example\n * ```ts\n * const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }\n * ```\n */\ntype Ipv4SchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'ipv4'\n}\n\n/**\n * IPv6 address schema node.\n *\n * @example\n * ```ts\n * const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }\n * ```\n */\ntype Ipv6SchemaNode = SchemaNodeBase & {\n /**\n * Schema type discriminator.\n */\n type: 'ipv6'\n}\n\n/**\n * Mapping from schema type literals to concrete schema node types.\n * Used by `narrowSchema`.\n */\nexport type SchemaNodeByType = {\n object: ObjectSchemaNode\n array: ArraySchemaNode\n tuple: ArraySchemaNode\n union: UnionSchemaNode\n intersection: IntersectionSchemaNode\n enum: EnumSchemaNode\n ref: RefSchemaNode\n datetime: DatetimeSchemaNode\n date: DateSchemaNode\n time: TimeSchemaNode\n string: StringSchemaNode\n number: NumberSchemaNode\n integer: NumberSchemaNode\n bigint: NumberSchemaNode\n boolean: ScalarSchemaNode\n null: ScalarSchemaNode\n any: ScalarSchemaNode\n unknown: ScalarSchemaNode\n void: ScalarSchemaNode\n never: ScalarSchemaNode\n uuid: FormatStringSchemaNode\n email: FormatStringSchemaNode\n url: UrlSchemaNode\n ipv4: Ipv4SchemaNode\n ipv6: Ipv6SchemaNode\n blob: ScalarSchemaNode\n}\n\n/**\n * Union of all schema node types.\n */\nexport type SchemaNode =\n | ObjectSchemaNode\n | ArraySchemaNode\n | UnionSchemaNode\n | IntersectionSchemaNode\n | EnumSchemaNode\n | RefSchemaNode\n | DatetimeSchemaNode\n | DateSchemaNode\n | TimeSchemaNode\n | StringSchemaNode\n | NumberSchemaNode\n | UrlSchemaNode\n | FormatStringSchemaNode\n | Ipv4SchemaNode\n | Ipv6SchemaNode\n | ScalarSchemaNode\n\ntype CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & { properties?: Array<PropertyNode>; primitive?: 'object' }\ntype CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>\ntype CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {\n kind: 'Schema'\n}\n\n/**\n * Maps schema `type` to its underlying `primitive`.\n * Primitive types map to themselves. Special string formats map to `'string'`.\n * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.\n */\nconst TYPE_TO_PRIMITIVE: Partial<Record<SchemaNode['type'], PrimitiveSchemaType>> = {\n string: 'string',\n number: 'number',\n integer: 'integer',\n bigint: 'bigint',\n boolean: 'boolean',\n null: 'null',\n any: 'any',\n unknown: 'unknown',\n void: 'void',\n never: 'never',\n object: 'object',\n array: 'array',\n date: 'date',\n uuid: 'string',\n email: 'string',\n url: 'string',\n datetime: 'string',\n time: 'string',\n}\n\n/**\n * Definition for the {@link SchemaNode}. Object schemas default `properties` to an\n * empty array, and `primitive` is inferred from `type` when not explicitly provided.\n */\nexport const schemaDef = defineNode<SchemaNode, CreateSchemaInput>({\n kind: 'Schema',\n build: (props) => {\n if (props.type === 'object') {\n return { properties: [], primitive: 'object' as const, ...props }\n }\n\n return { primitive: TYPE_TO_PRIMITIVE[props.type as keyof typeof TYPE_TO_PRIMITIVE], ...props }\n },\n children: ['properties', 'items', 'members', 'additionalProperties'],\n visitorKey: 'schema',\n})\n\n/**\n * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n *\n * @example\n * ```ts\n * const scalar = createSchema({ type: 'string' })\n * // { kind: 'Schema', type: 'string', primitive: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const object = createSchema({ type: 'object' })\n * // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }\n * ```\n */\nexport function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>\nexport function createSchema(props: CreateSchemaInput): SchemaNode\nexport function createSchema(props: CreateSchemaInput): SchemaNode {\n return schemaDef.create(props)\n}\n","import { existsSync } from 'node:fs'\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join, posix, resolve } from 'node:path'\nimport { camelCase } from './casing.ts'\nimport { runtime } from './runtime.ts'\n\n/**\n * Walks up the directory tree from `cwd` (defaults to `process.cwd()`) and\n * returns the absolute path of the nearest `package.json`, or `null` when none\n * is found before reaching the filesystem root.\n *\n * @example\n * ```ts\n * const pkgPath = findPackageJSON('/home/user/project/src') // '/home/user/project/package.json'\n * ```\n */\nexport function findPackageJSON(cwd?: string): string | null {\n let dir = cwd ? resolve(cwd) : process.cwd()\n while (true) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) return pkgPath\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\n/**\n * Converts all backslashes to forward slashes.\n * Extended-length Windows paths (`\\\\?\\...`) are left unchanged.\n */\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Writes `data` to `path`, trimming leading/trailing whitespace before saving.\n * Skips the write when the trimmed content is empty or identical to what is already on disk.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns trimmed content\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const resolved = resolve(path)\n\n if (runtime.isBun) {\n const file = Bun.file(resolved)\n const oldContent = (await file.exists()) ? await file.text() : null\n if (oldContent === trimmed) return null\n await Bun.write(resolved, trimmed)\n return trimmed\n }\n\n try {\n const oldContent = await readFile(resolved, { encoding: 'utf-8' })\n if (oldContent === trimmed) return null\n } catch {\n /* file doesn't exist yet */\n }\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, trimmed, { encoding: 'utf-8' })\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== trimmed) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return trimmed\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\n}\n","function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { hash } from 'node:crypto'\nimport type { SchemaNode } from './nodes/index.ts'\nimport { extractRefName } from './utils/index.ts'\n\n/**\n * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.\n */\nfunction flagsDescriptor(node: SchemaNode): string {\n return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`\n}\n\nfunction refTargetName(node: Extract<SchemaNode, { type: 'ref' }>): string {\n if (node.ref) return extractRefName(node.ref)\n return node.name ?? ''\n}\n\ntype ScalarField = { kind: 'scalar'; key: string; prefix: string }\ntype BoolField = { kind: 'bool'; key: string; prefix: string }\ntype ChildField = { kind: 'child'; key: string; prefix: string }\ntype ChildrenField = { kind: 'children'; key: string; prefix: string }\ntype ObjectPropsField = { kind: 'objectProps' }\ntype AdditionalPropsField = { kind: 'additionalProps' }\ntype PatternPropsField = { kind: 'patternProps' }\ntype EnumValuesField = { kind: 'enumValues' }\ntype RefTargetField = { kind: 'refTarget' }\n\ntype ShapeField =\n | ScalarField\n | BoolField\n | ChildField\n | ChildrenField\n | ObjectPropsField\n | AdditionalPropsField\n | PatternPropsField\n | EnumValuesField\n | RefTargetField\n\nconst arrayTupleFields: ReadonlyArray<ShapeField> = [\n { kind: 'children', key: 'items', prefix: 'i' },\n { kind: 'child', key: 'rest', prefix: 'r' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'bool', key: 'unique', prefix: 'u' },\n]\n\nconst numericFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'exclusiveMinimum', prefix: 'emn' },\n { kind: 'scalar', key: 'exclusiveMaximum', prefix: 'emx' },\n { kind: 'scalar', key: 'multipleOf', prefix: 'mo' },\n]\n\nconst rangeFields: ReadonlyArray<ShapeField> = [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n]\n\n/**\n * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map\n * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.\n */\nconst SHAPE_KEYS: Partial<Record<SchemaNode['type'], ReadonlyArray<ShapeField>>> = {\n object: [\n { kind: 'objectProps' },\n { kind: 'additionalProps' },\n { kind: 'patternProps' },\n { kind: 'scalar', key: 'minProperties', prefix: 'mn' },\n { kind: 'scalar', key: 'maxProperties', prefix: 'mx' },\n ],\n array: arrayTupleFields,\n tuple: arrayTupleFields,\n union: [\n { kind: 'scalar', key: 'strategy', prefix: 's' },\n { kind: 'scalar', key: 'discriminatorPropertyName', prefix: 'd' },\n { kind: 'children', key: 'members', prefix: 'm' },\n ],\n intersection: [{ kind: 'children', key: 'members', prefix: 'm' }],\n enum: [{ kind: 'enumValues' }],\n ref: [{ kind: 'refTarget' }],\n string: [\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n { kind: 'scalar', key: 'pattern', prefix: 'pt' },\n ],\n number: numericFields,\n integer: numericFields,\n bigint: numericFields,\n url: [\n { kind: 'scalar', key: 'path', prefix: 'path' },\n { kind: 'scalar', key: 'min', prefix: 'mn' },\n { kind: 'scalar', key: 'max', prefix: 'mx' },\n ],\n uuid: rangeFields,\n email: rangeFields,\n datetime: [\n { kind: 'bool', key: 'offset', prefix: 'o' },\n { kind: 'bool', key: 'local', prefix: 'l' },\n ],\n date: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n time: [{ kind: 'scalar', key: 'representation', prefix: 'rep' }],\n}\n\nfunction serializeShapeField(field: ShapeField, node: SchemaNode, record: Record<string, unknown>): string {\n switch (field.kind) {\n case 'scalar':\n return `${field.prefix}:${record[field.key] ?? ''}`\n case 'bool':\n return `${field.prefix}:${record[field.key] ? 1 : 0}`\n case 'child': {\n const child = record[field.key] as SchemaNode | undefined\n return `${field.prefix}:${child ? signatureOf(child) : ''}`\n }\n case 'children': {\n const children = (record[field.key] as Array<SchemaNode> | undefined) ?? []\n return `${field.prefix}[${children.map((c) => signatureOf(c)).join(',')}]`\n }\n case 'objectProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const props = (obj.properties ?? []).map((prop) => `${prop.name}${prop.required ? '!' : '?'}${signatureOf(prop.schema)}`).join(',')\n return `p[${props}]`\n }\n case 'additionalProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n if (typeof obj.additionalProperties === 'boolean') return `ab:${obj.additionalProperties}`\n if (obj.additionalProperties) return `as:${signatureOf(obj.additionalProperties)}`\n return ''\n }\n case 'patternProps': {\n const obj = node as Extract<SchemaNode, { type: 'object' }>\n const pattern = obj.patternProperties\n ? Object.keys(obj.patternProperties)\n .sort()\n .map((key) => `${key}=${signatureOf(obj.patternProperties![key]!)}`)\n .join(',')\n : ''\n return `pp[${pattern}]`\n }\n case 'enumValues': {\n const en = node as Extract<SchemaNode, { type: 'enum' }>\n let values = ''\n if (en.namedEnumValues?.length) {\n values = en.namedEnumValues.map((entry) => `${entry.name}=${entry.primitive}:${String(entry.value)}`).join(',')\n } else if (en.enumValues?.length) {\n values = en.enumValues.map((value) => `${value === null ? 'null' : typeof value}:${String(value)}`).join(',')\n }\n return `v[${values}]`\n }\n case 'refTarget': {\n return `->${refTargetName(node as Extract<SchemaNode, { type: 'ref' }>)}`\n }\n }\n}\n\n/**\n * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,\n * constraints, and its children's signatures.\n */\nfunction describeShape(node: SchemaNode): string {\n const flags = flagsDescriptor(node)\n const fields = SHAPE_KEYS[node.type]\n if (!fields) return `${node.type}|${flags}`\n\n const record = node as unknown as Record<string, unknown>\n const parts: Array<string> = [`${node.type}|${flags}`]\n for (const field of fields) {\n parts.push(serializeShapeField(field, node, record))\n }\n return parts.join('|')\n}\n\n/**\n * Node → digest cache, keyed by identity. A `WeakMap` so entries die with the node, and so a tree\n * hashed during dedupe planning is not walked again when it is rewritten during streaming. Reuse\n * is safe because a signature depends only on content, and nodes are immutable once created.\n */\nconst signatureCache = new WeakMap<SchemaNode, string>()\n\n/**\n * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas\n * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,\n * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,\n * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`\n * nodes compare by target name, which also terminates on circular shapes.\n *\n * @example Two enums with different descriptions share a signature\n * ```ts\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===\n * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))\n * ```\n */\nexport function signatureOf(node: SchemaNode): string {\n const cached = signatureCache.get(node)\n if (cached !== undefined) return cached\n const signature = hash('sha256', describeShape(node), 'hex')\n signatureCache.set(node, signature)\n\n return signature\n}\n\n/**\n * Returns `true` when two schema nodes are structurally identical under shape-only equality,\n * meaning they produce the same TypeScript type.\n */\nexport function isSchemaEqual(a: SchemaNode, b: SchemaNode): boolean {\n return signatureOf(a) === signatureOf(b)\n}\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\n\n/**\n * JSDoc documentation metadata attached to code declarations.\n */\nexport type JSDocNode = {\n /**\n * JSDoc comment lines. `undefined` entries are filtered out during rendering.\n * @example ['@description A pet resource', '@deprecated']\n */\n comments?: Array<string | undefined>\n}\n\n/**\n * AST node representing a TypeScript `const` declaration.\n *\n * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createConst({ name: 'pet', export: true, asConst: true })\n * // export const pet = ... as const\n * ```\n */\nexport type ConstNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Const'\n /**\n * Name of the constant declaration.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n * @default false\n */\n export?: boolean | null\n /**\n * Optional explicit type annotation.\n * @example 'Pet'\n */\n type?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Whether to append `as const` to the declaration.\n * @default false\n */\n asConst?: boolean | null\n /**\n * Child nodes representing the value of the constant (children of the `Const` component).\n * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `type` alias declaration.\n *\n * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport type TypeNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Type'\n /**\n * Name of the type alias.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n * @default false\n */\n export?: boolean | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the type body (children of the `Type` component).\n * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `function` declaration.\n *\n * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createFunctionDeclaration({ name: 'getPet', export: true, async: true, returnType: 'Pet' })\n * // export async function getPet(): Promise<Pet> { ... }\n * ```\n */\nexport type FunctionNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Function'\n /**\n * Name of the function.\n */\n name: string\n /**\n * Whether the function is a default export.\n * @default false\n */\n default?: boolean | null\n /**\n * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).\n */\n params?: string | null\n /**\n * Whether the function should be exported.\n * @default false\n */\n export?: boolean | null\n /**\n * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.\n * @default false\n */\n async?: boolean | null\n /**\n * TypeScript generic type parameters.\n * @example ['T', 'U extends string']\n */\n generics?: string | Array<string> | null\n /**\n * Return type annotation.\n * @example 'Pet'\n */\n returnType?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the function body (children of the `Function` component).\n * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript arrow function (`const name = () => { ... }`).\n *\n * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createArrowFunctionDeclaration({ name: 'getPet', export: true, singleLine: true })\n * // export const getPet = () => ...\n * ```\n */\nexport type ArrowFunctionNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'ArrowFunction'\n /**\n * Name of the arrow function (used as the `const` variable name).\n */\n name: string\n /**\n * Whether the function is a default export.\n * @default false\n */\n default?: boolean | null\n /**\n * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).\n */\n params?: string | null\n /**\n * Whether the arrow function should be exported.\n * @default false\n */\n export?: boolean | null\n /**\n * Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.\n * @default false\n */\n async?: boolean | null\n /**\n * TypeScript generic type parameters.\n * @example ['T', 'U extends string']\n */\n generics?: string | Array<string> | null\n /**\n * Return type annotation.\n * @example 'Pet'\n */\n returnType?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Render the arrow function body as a single-line expression.\n * @default false\n */\n singleLine?: boolean | null\n /**\n * Child nodes representing the function body (children of the `Function.Arrow` component).\n * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a raw text/string fragment in the source output.\n *\n * Used instead of bare `string` values so that all entries in `nodes` arrays\n * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport type TextNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Text'\n /**\n * The raw string content.\n */\n value: string\n}\n\n/**\n * AST node representing a line break in the source output.\n *\n * Corresponds to `<br/>` in JSX components. When printed, produces an empty\n * string that, joined with `\\n` by `printNodes` creates a blank line\n * between surrounding code nodes.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * // prints as '' → blank line when surrounded by other nodes\n * ```\n */\nexport type BreakNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Break'\n}\n\n/**\n * AST node representing a raw JSX fragment in the source output.\n *\n * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Use this to embed raw\n * JSX/TSX markup (including fragments `<>…</>`) directly in generated code.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport type JsxNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Jsx'\n /**\n * The raw JSX string content.\n */\n value: string\n}\n\n/**\n * Union of all code-generation AST nodes.\n *\n * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as\n * structured children in {@link SourceNode.nodes}.\n */\nexport type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode\n\n/**\n * Definition for the {@link ConstNode}.\n */\nexport const constDef = defineNode<ConstNode>({ kind: 'Const' })\n\n/**\n * Creates a `ConstNode` representing a TypeScript `const` declaration.\n *\n * @example Exported constant with type and `as const`\n * ```ts\n * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })\n * // export const pets: Pet[] = ... as const\n * ```\n */\nexport const createConst = constDef.create\n\n/**\n * Definition for the {@link TypeNode}.\n */\nexport const typeDef = defineNode<TypeNode>({ kind: 'Type' })\n\n/**\n * Creates a `TypeNode` representing a TypeScript `type` alias declaration.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport const createType = typeDef.create\n\n/**\n * Definition for the {@link FunctionNode}.\n */\nexport const functionDef = defineNode<FunctionNode>({ kind: 'Function' })\n\n/**\n * Creates a `FunctionNode` representing a TypeScript `function` declaration.\n *\n * @example\n * ```ts\n * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })\n * // export async function fetchPet(): Promise<Pet> { ... }\n * ```\n */\nexport const createFunction = functionDef.create\n\n/**\n * Definition for the {@link ArrowFunctionNode}.\n */\nexport const arrowFunctionDef = defineNode<ArrowFunctionNode>({ kind: 'ArrowFunction' })\n\n/**\n * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.\n *\n * @example\n * ```ts\n * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })\n * // export const double = (n: number) => ...\n * ```\n */\nexport const createArrowFunction = arrowFunctionDef.create\n\n/**\n * Definition for the {@link TextNode}.\n */\nexport const textDef = defineNode<TextNode, string>({ kind: 'Text', build: (value) => ({ value }) })\n\n/**\n * Creates a {@link TextNode} representing a raw string fragment in the source output.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport const createText = textDef.create\n\n/**\n * Definition for the {@link BreakNode}.\n */\nexport const breakDef = defineNode<BreakNode, void>({ kind: 'Break', build: () => ({}) })\n\n/**\n * Creates a {@link BreakNode} representing a line break in the source output.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport function createBreak(): BreakNode {\n return breakDef.create()\n}\n\n/**\n * Definition for the {@link JsxNode}.\n */\nexport const jsxDef = defineNode<JsxNode, string>({ kind: 'Jsx', build: (value) => ({ value }) })\n\n/**\n * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport const createJsx = jsxDef.create\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * AST node representing one content-type entry of a request body or response.\n *\n * One entry per content type declared in the spec (e.g. `application/json`,\n * `multipart/form-data`), each carrying its own body schema.\n *\n * @example\n * ```ts\n * const content: ContentNode = {\n * kind: 'Content',\n * contentType: 'application/json',\n * schema: createSchema({ type: 'string' }),\n * }\n * ```\n */\nexport type ContentNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Content'\n /**\n * The content type for this entry (e.g. `'application/json'`).\n */\n contentType: string\n /**\n * Body schema for this content type.\n */\n schema?: SchemaNode\n /**\n * Property keys to exclude from the generated type via `Omit<Type, Keys>`.\n * Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.\n */\n keysToOmit?: Array<string> | null\n}\n\n/**\n * Loosely-typed content entry accepted by the builders, normalized into a {@link ContentNode}.\n */\nexport type UserContent = Omit<ContentNode, 'kind'>\n\n/**\n * Definition for the {@link ContentNode}.\n */\nexport const contentDef = defineNode<ContentNode, UserContent>({\n kind: 'Content',\n children: ['schema'],\n})\n\n/**\n * Creates a `ContentNode` for a single request-body or response content type.\n */\nexport const createContent = contentDef.create\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { CodeNode } from './code.ts'\n\n/**\n * Supported file extensions.\n */\ntype Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\ntype ImportName = string | Array<string | { propertyName: string; name?: string }>\n\n/**\n * Represents a language-agnostic import/dependency declaration.\n *\n * @example Named import (TypeScript: `import { useState } from 'react'`)\n * ```ts\n * createImport({ name: ['useState'], path: 'react' })\n * ```\n *\n * @example Default import (TypeScript: `import React from 'react'`)\n * ```ts\n * createImport({ name: 'React', path: 'react' })\n * ```\n *\n * @example Type-only import (TypeScript: `import type { FC } from 'react'`)\n * ```ts\n * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })\n * ```\n *\n * @example Namespace import (TypeScript: `import * as React from 'react'`)\n * ```ts\n * createImport({ name: 'React', path: 'react', isNameSpace: true })\n * ```\n */\nexport type ImportNode = BaseNode & {\n kind: 'Import'\n /**\n * Import name(s) to be used.\n * @example ['useState']\n * @example 'React'\n */\n name: ImportName\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add type-only import prefix.\n * - `true` generates `import type { Type } from './path'`\n * - `false` generates `import { Type } from './path'`\n * @default false\n */\n isTypeOnly?: boolean | null\n /**\n * Import entire module as namespace.\n * - `true` generates `import * as Name from './path'`\n * - `false` generates standard import\n * @default false\n */\n isNameSpace?: boolean | null\n /**\n * When set, the import path is resolved relative to this root.\n */\n root?: string | null\n}\n\n/**\n * Represents a language-agnostic export/public API declaration.\n *\n * @example Named export (TypeScript: `export { Pets } from './Pets'`)\n * ```ts\n * createExport({ name: ['Pets'], path: './Pets' })\n * ```\n *\n * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)\n * ```ts\n * createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })\n * ```\n *\n * @example Wildcard export (TypeScript: `export * from './utils'`)\n * ```ts\n * createExport({ path: './utils' })\n * ```\n *\n * @example Namespace alias (TypeScript: `export * as utils from './utils'`)\n * ```ts\n * createExport({ name: 'utils', path: './utils', asAlias: true })\n * ```\n */\nexport type ExportNode = BaseNode & {\n kind: 'Export'\n /**\n * Export name(s) to be used. When omitted, generates a wildcard export.\n * @example ['useState']\n * @example 'React'\n */\n name?: string | Array<string> | null\n /**\n * Path for the export.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add type-only export prefix.\n * - `true` generates `export type { Type } from './path'`\n * - `false` generates `export { Type } from './path'`\n * @default false\n */\n isTypeOnly?: boolean | null\n /**\n * Export as an aliased namespace.\n * - `true` generates `export * as aliasName from './path'`\n * - `false` generates a standard export\n * @default false\n */\n asAlias?: boolean | null\n}\n\n/**\n * Represents a fragment of source code within a file.\n *\n * @example Named exportable source\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })\n * ```\n *\n * @example Inline unnamed code block\n * ```ts\n * createSource({ nodes: [createText('const x = 1')] })\n * ```\n */\nexport type SourceNode = BaseNode & {\n kind: 'Source'\n /**\n * Optional name identifying this source (used for deduplication and barrel generation).\n */\n name?: string | null\n /**\n * Mark this source as a type-only export.\n * @default false\n */\n isTypeOnly?: boolean | null\n /**\n * Include `export` keyword in the generated source.\n * @default false\n */\n isExportable?: boolean | null\n /**\n * Include this source in barrel/index file generation.\n * @default false\n */\n isIndexable?: boolean | null\n /**\n * Structured child nodes representing the content of this source fragment, in DOM order.\n * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * Represents a fully resolved file in the AST.\n *\n * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input\n * and deduplicates `imports`, `exports`, and `sources`.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of the path\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport type FileNode<TMeta extends object = object> = BaseNode & {\n kind: 'File'\n /**\n * Unique identifier derived from a SHA256 hash of the file path. Computed\n * by `createFile`; callers do not need to provide it.\n */\n id: string\n /**\n * File name without extension, derived from `baseName`.\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n /**\n * File base name, including extension.\n * Based on UNIX basename: `${name}${extname}`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: `${string}.${string}`\n /**\n * Full qualified path to the file.\n */\n path: string\n /**\n * File extension extracted from `baseName`.\n */\n extname: Extname\n /**\n * Deduplicated list of source code fragments.\n */\n sources: Array<SourceNode>\n /**\n * Deduplicated list of import declarations.\n */\n imports: Array<ImportNode>\n /**\n * Deduplicated list of export declarations.\n */\n exports: Array<ExportNode>\n /**\n * Optional metadata attached to this file (used by plugins for barrel generation etc.).\n */\n meta?: TMeta\n /**\n * Optional banner prepended to the generated file content.\n * Accepts `null` so `resolver.resolveBanner()` results can be passed directly.\n */\n banner?: string | null\n /**\n * Optional footer appended to the generated file content.\n * Accepts `null` so `resolver.resolveFooter()` results can be passed directly.\n */\n footer?: string | null\n}\n\n/**\n * Definition for the {@link ImportNode}.\n */\nexport const importDef = defineNode<ImportNode>({ kind: 'Import' })\n\n/**\n * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.\n *\n * @example Named import\n * ```ts\n * createImport({ name: ['useState'], path: 'react' })\n * // import { useState } from 'react'\n * ```\n */\nexport const createImport = importDef.create\n\n/**\n * Definition for the {@link ExportNode}.\n */\nexport const exportDef = defineNode<ExportNode>({ kind: 'Export' })\n\n/**\n * Creates an `ExportNode` representing a language-agnostic export/public API declaration.\n *\n * @example Named export\n * ```ts\n * createExport({ name: ['Pet'], path: './Pet' })\n * // export { Pet } from './Pet'\n * ```\n */\nexport const createExport = exportDef.create\n\n/**\n * Definition for the {@link SourceNode}.\n */\nexport const sourceDef = defineNode<SourceNode>({ kind: 'Source' })\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })\n * ```\n */\nexport const createSource = sourceDef.create\n\n/**\n * Definition for the {@link FileNode}. The fully resolved builder lives in\n * `createFile`, so this definition only supplies the guard.\n */\nexport const fileDef = defineNode<FileNode>({ kind: 'File' })\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\n\n/**\n * A language-agnostic type expression used as a function parameter type annotation.\n *\n * - a plain `string` is a type reference rendered as-is, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`\n * - a {@link TypeLiteralNode} is an inline anonymous type, e.g. `{ petId: string; name?: string }`\n * - an {@link IndexedAccessTypeNode} is a single field accessed from a named type, e.g. `PathParams['petId']`\n */\nexport type TypeExpression = string | TypeLiteralNode | IndexedAccessTypeNode\n\n/**\n * AST node for an inline anonymous object type grouping named fields.\n * TypeScript renders as `{ key: Type; other?: OtherType }`.\n *\n * @example\n * ```ts\n * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })\n * // { petId: string }\n * ```\n */\nexport type TypeLiteralNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'TypeLiteral'\n /**\n * Members of the object type, rendered in order.\n */\n members: Array<{\n /**\n * Member key.\n */\n name: string\n /**\n * Member type expression.\n */\n type: TypeExpression\n /**\n * Whether the member is optional, rendered with `?`.\n */\n optional?: boolean\n }>\n}\n\n/**\n * AST node for a single field accessed from a named group type.\n * TypeScript renders as `objectType['indexType']`.\n *\n * @example\n * ```ts\n * createIndexedAccessType({ objectType: 'GetPetPathParams', indexType: 'petId' })\n * // GetPetPathParams['petId']\n * ```\n */\nexport type IndexedAccessTypeNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'IndexedAccessType'\n /**\n * Name of the type being indexed, e.g. `'GetPetPathParams'`.\n */\n objectType: string\n /**\n * Field key to access, e.g. `'petId'`.\n */\n indexType: string\n}\n\n/**\n * AST node for an object destructuring binding, used as the name of a grouped function parameter.\n * TypeScript renders as `{ id, name }` or `{ id: renamed }` when `propertyName` differs.\n *\n * @example\n * ```ts\n * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })\n * // { id, name }\n * ```\n */\nexport type ObjectBindingPatternNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'ObjectBindingPattern'\n /**\n * Bound elements, rendered in order.\n */\n elements: Array<{\n /**\n * Local binding name.\n */\n name: string\n /**\n * Source key when it differs from the binding name, rendered as `propertyName: name`.\n */\n propertyName?: string\n }>\n}\n\n/**\n * AST node for one function parameter.\n *\n * A simple parameter has a `string` name. A destructured group has an\n * {@link ObjectBindingPatternNode} name paired with a {@link TypeLiteralNode} type.\n *\n * @example Required parameter\n * `name: Type`\n *\n * @example Optional parameter\n * `name?: Type`\n *\n * @example Parameter with default value\n * `name: Type = defaultValue`\n *\n * @example Rest parameter\n * `...name: Type[]`\n *\n * @example Destructured group\n * `{ id, name? }: { id: string; name?: string } = {}`\n */\nexport type FunctionParameterNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'FunctionParameter'\n /**\n * Parameter name, or an {@link ObjectBindingPatternNode} for a destructured group.\n */\n name: string | ObjectBindingPatternNode\n /**\n * Type annotation as a {@link TypeExpression}. Omit for untyped output.\n */\n type?: TypeExpression\n /**\n * Whether the parameter is optional, rendered with `?`.\n */\n optional?: boolean\n /**\n * Default value, written verbatim after `=`. Commonly `'{}'` for a destructured group.\n */\n default?: string\n /**\n * When `true` the parameter is emitted as a rest parameter, e.g. `...name: Type[]`.\n */\n rest?: boolean\n}\n\n/**\n * AST node for a complete function parameter list.\n *\n * Printers are responsible for sorting (`required` → `optional` → `defaulted`).\n * Nodes are plain immutable data.\n *\n * Renders differently depending on the output mode:\n * - `declaration` → `(id: string, config: Config = {})` function declaration parameters\n * - `call` → `(id, { method, url })` function call arguments\n */\nexport type FunctionParametersNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'FunctionParameters'\n /**\n * Ordered parameter nodes.\n */\n params: ReadonlyArray<FunctionParameterNode>\n}\n\n/**\n * Union of all function-parameter AST node variants used by the function-parameter printer.\n */\nexport type FunctionParamNode = FunctionParameterNode | FunctionParametersNode | TypeLiteralNode | IndexedAccessTypeNode | ObjectBindingPatternNode\n\n/**\n * Handler map keys, one per `FunctionParamNode` kind.\n */\nexport type FunctionNodeType = 'functionParameter' | 'functionParameters' | 'typeLiteral' | 'indexedAccessType' | 'objectBindingPattern'\n\n/**\n * Definition for the {@link TypeLiteralNode}.\n */\nexport const typeLiteralDef = defineNode<TypeLiteralNode, Pick<TypeLiteralNode, 'members'>>({ kind: 'TypeLiteral' })\n\n/**\n * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.\n *\n * @example\n * ```ts\n * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })\n * // { petId: string }\n * ```\n */\nexport const createTypeLiteral = typeLiteralDef.create\n\n/**\n * Definition for the {@link IndexedAccessTypeNode}.\n */\nexport const indexedAccessTypeDef = defineNode<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, 'kind'>>({ kind: 'IndexedAccessType' })\n\n/**\n * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.\n *\n * @example\n * ```ts\n * createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })\n * // DeletePetPathParams['petId']\n * ```\n */\nexport const createIndexedAccessType = indexedAccessTypeDef.create\n\n/**\n * Definition for the {@link ObjectBindingPatternNode}.\n */\nexport const objectBindingPatternDef = defineNode<ObjectBindingPatternNode, Pick<ObjectBindingPatternNode, 'elements'>>({ kind: 'ObjectBindingPattern' })\n\n/**\n * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.\n *\n * @example\n * ```ts\n * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })\n * // { id, name }\n * ```\n */\nexport const createObjectBindingPattern = objectBindingPatternDef.create\n\n/**\n * Plain property descriptor for a destructured group built by {@link createFunctionParameter}.\n */\ntype FunctionParameterProperty = {\n name: string\n type: TypeExpression\n optional?: boolean\n}\n\ntype FunctionParameterInput =\n | { name: string; type?: TypeExpression; optional?: boolean; default?: string; rest?: boolean }\n | { properties: Array<FunctionParameterProperty>; optional?: boolean; default?: string }\n\n/**\n * Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.\n * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name\n * paired with a {@link TypeLiteralNode} type.\n */\nexport const functionParameterDef = defineNode<FunctionParameterNode, FunctionParameterInput>({\n kind: 'FunctionParameter',\n build: (input) => {\n if ('properties' in input) {\n return {\n name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),\n type: createTypeLiteral({ members: input.properties.map((p) => ({ name: p.name, type: p.type, optional: p.optional ?? false })) }),\n optional: input.optional ?? false,\n ...(input.default !== undefined ? { default: input.default } : {}),\n }\n }\n return { optional: false, ...input }\n },\n})\n\n/**\n * Creates a `FunctionParameterNode`. `optional` defaults to `false`.\n *\n * @example Optional param\n * ```ts\n * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })\n * // → params?: QueryParams\n * ```\n *\n * @example Destructured group\n * ```ts\n * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })\n * // → { id, name }: { id: string; name?: string } = {}\n * ```\n */\nexport const createFunctionParameter = functionParameterDef.create\n\n/**\n * Definition for the {@link FunctionParametersNode}.\n */\nexport const functionParametersDef = defineNode<FunctionParametersNode, Partial<Omit<FunctionParametersNode, 'kind'>>>({\n kind: 'FunctionParameters',\n defaults: { params: [] },\n})\n\n/**\n * Creates a `FunctionParametersNode` from an ordered list of parameters.\n *\n * @example\n * ```ts\n * const empty = createFunctionParameters()\n * // { kind: 'FunctionParameters', params: [] }\n * ```\n */\nexport function createFunctionParameters(props: Partial<Omit<FunctionParametersNode, 'kind'>> = {}): FunctionParametersNode {\n return functionParametersDef.create(props)\n}\n","import type { Streamable } from '@internals/utils'\nimport { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { OperationNode } from './operation.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * Metadata for an API document, populated by the adapter and available to every generator.\n *\n * All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.\n * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter\n * pre-scan so generators never need to iterate the full schema list themselves.\n *\n * @example\n * ```ts\n * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://petstore.swagger.io/v2', circularNames: [], enumNames: [] }\n * ```\n */\nexport type InputMeta = {\n /**\n * API title from `info.title` in the source document.\n */\n title?: string\n /**\n * API description from `info.description` in the source document.\n */\n description?: string\n /**\n * API version string from `info.version` in the source document.\n */\n version?: string\n /**\n * Resolved base URL from the first matching server entry in the source document.\n */\n baseURL?: string | null\n /**\n * Names of schemas that participate in a circular reference chain.\n * Computed once during the adapter pre-scan, use this instead of calling\n * `findCircularSchemas` per generator call.\n *\n * Convert to a `Set` once at the start of a generator, not per-schema,\n * to keep lookup O(1) without repeated allocations.\n *\n * @example Wrap a circular schema in z.lazy()\n * ```ts\n * const circular = new Set(meta.circularNames)\n * if (circular.has(schema.name)) { ... }\n * ```\n */\n circularNames: ReadonlyArray<string>\n /**\n * Names of schemas whose type is `enum`.\n * Computed once during the adapter pre-scan, use this instead of filtering\n * schemas per generator call.\n *\n * Convert to a `Set` once at the start of a generator when you need repeated\n * membership checks, rather than calling `.includes()` per schema.\n *\n * @example Check if a referenced schema is an enum\n * `const enums = new Set(meta.enumNames)`\n * `const isEnum = enums.has(schemaName)`\n */\n enumNames: ReadonlyArray<string>\n}\n\n/**\n * Input AST node that contains all schemas and operations for one API document.\n * Produced by the adapter and consumed by all Kubb plugins.\n *\n * `Stream` switches `schemas` and `operations` between eager `Array`s (the default) and lazy\n * `AsyncIterable`s. The streaming variant `InputNode<true>` yields nodes one at a time and makes\n * `meta` optional, since the adapter can emit metadata before the first node is parsed.\n *\n * @example\n * ```ts\n * const input: InputNode = {\n * kind: 'Input',\n * schemas: [],\n * operations: [],\n * meta: { circularNames: [], enumNames: [] },\n * }\n * ```\n *\n * @example Streaming variant for large specs\n * ```ts\n * for await (const schema of inputNode.schemas) {\n * // only this one SchemaNode is live here. Previous ones are GC-eligible\n * }\n * ```\n */\nexport type InputNode<Stream extends boolean = false> = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Input'\n /**\n * All schema nodes in the document.\n */\n schemas: Streamable<SchemaNode, Stream>\n /**\n * All operation nodes in the document.\n */\n operations: Streamable<OperationNode, Stream>\n} & (Stream extends true ? { meta?: InputMeta } : { meta: InputMeta })\n\n/**\n * Definition for the {@link InputNode}.\n */\nexport const inputDef = defineNode<InputNode, Partial<Omit<InputNode, 'kind'>>>({\n kind: 'Input',\n defaults: { schemas: [], operations: [], meta: { circularNames: [], enumNames: [] } },\n children: ['schemas', 'operations'],\n visitorKey: 'input',\n})\n\n/**\n * Creates an `InputNode` with stable defaults for `schemas` and `operations`.\n *\n * @example\n * ```ts\n * const input = createInput()\n * // { kind: 'Input', schemas: [], operations: [] }\n * ```\n */\nexport function createInput(overrides: Partial<Omit<InputNode, 'kind'>> = {}): InputNode {\n return inputDef.create(overrides)\n}\n\n/**\n * Creates a streaming `InputNode<true>` from pre-built `AsyncIterable` sources.\n *\n * @example\n * ```ts\n * const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })\n * ```\n */\nexport function createStreamInput(schemas: AsyncIterable<SchemaNode>, operations: AsyncIterable<OperationNode>, meta?: InputMeta): InputNode<true> {\n return { kind: 'Input', schemas, operations, meta }\n}\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport { type ContentNode, createContent, type UserContent } from './content.ts'\n\n/**\n * AST node representing an operation request body.\n *\n * Body schemas live exclusively inside the `content` array (one entry per content type),\n * mirroring {@link ResponseNode}.\n *\n * @example\n * ```ts\n * const requestBody: RequestBodyNode = {\n * kind: 'RequestBody',\n * required: true,\n * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type RequestBodyNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'RequestBody'\n /**\n * Human-readable request body description.\n */\n description?: string\n /**\n * Whether the request body is required (`requestBody.required: true` in the spec).\n * When `false` or absent, the generated `data` parameter should be optional.\n */\n required?: boolean\n /**\n * All available content type entries for this request body.\n *\n * When the adapter `contentType` option is set, this array contains exactly one entry for\n * that content type. Otherwise it contains one entry per content type declared in the spec,\n * so that plugins can generate code for every variant (e.g. separate hooks for\n * `application/json` and `multipart/form-data`).\n */\n content?: Array<ContentNode>\n}\n\n/**\n * Loosely-typed request body accepted by `createOperation`, normalized into a {@link RequestBodyNode}.\n */\nexport type UserRequestBody = Omit<RequestBodyNode, 'kind' | 'content'> & {\n content?: Array<UserContent>\n}\n\n/**\n * Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.\n */\nexport const requestBodyDef = defineNode<RequestBodyNode, UserRequestBody>({\n kind: 'RequestBody',\n build: (props) => ({ ...props, content: props.content?.map(createContent) }),\n children: ['content'],\n})\n\n/**\n * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.\n */\nexport const createRequestBody = requestBodyDef.create\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport { createRequestBody, type RequestBodyNode, type UserRequestBody } from './requestBody.ts'\nimport type { ResponseNode } from './response.ts'\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE'\n\n/**\n * Transport an operation belongs to.\n */\ntype OperationProtocol = 'http'\n\n/**\n * Fields shared by every operation, regardless of transport.\n */\ntype OperationNodeBase = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Operation'\n /**\n * Operation identifier, usually from OpenAPI `operationId`.\n */\n operationId: string\n /**\n * Group labels for the operation.\n * Usually copied from OpenAPI `tags`.\n */\n tags: Array<string>\n /**\n * Short one-line operation summary.\n */\n summary?: string\n /**\n * Full operation description.\n */\n description?: string\n /**\n * Marks the operation as deprecated.\n */\n deprecated?: boolean\n /**\n * Parameters that could be used, we have QueryParams, PathParams, HeaderParams and CookieParams\n */\n parameters: Array<ParameterNode>\n /**\n * Request body for the operation.\n */\n requestBody?: RequestBodyNode\n /**\n * Operation responses.\n */\n responses: Array<ResponseNode>\n}\n\n/**\n * Operation served over HTTP/REST (OpenAPI). `method` and `path` are guaranteed.\n *\n * @example\n * ```ts\n * const operation: HttpOperationNode = {\n * kind: 'Operation',\n * operationId: 'listPets',\n * protocol: 'http',\n * method: 'GET',\n * path: '/pets',\n * tags: [],\n * parameters: [],\n * responses: [],\n * }\n * ```\n */\nexport type HttpOperationNode = OperationNodeBase & {\n /**\n * Transport the operation belongs to.\n */\n protocol?: 'http'\n /**\n * HTTP method like `'GET'`.\n */\n method: HttpMethod\n /**\n * OpenAPI-style path string, for example `/pets/{petId}`, with `{param}` notation preserved.\n */\n path: string\n}\n\n/**\n * Operation for a non-HTTP transport. HTTP-only fields are forbidden.\n */\nexport type GenericOperationNode = OperationNodeBase & {\n /**\n * Transport the operation belongs to.\n */\n protocol?: Exclude<OperationProtocol, 'http'>\n method?: never\n path?: never\n}\n\n/**\n * AST node representing one API operation.\n *\n * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees\n * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with\n * `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.\n */\nexport type OperationNode = HttpOperationNode | GenericOperationNode\n\ntype OperationInput = {\n operationId: string\n method?: HttpOperationNode['method']\n path?: HttpOperationNode['path']\n requestBody?: UserRequestBody\n [key: string]: unknown\n}\n\n/**\n * Definition for the {@link OperationNode}. HTTP operations (those carrying both\n * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is\n * normalized into a `RequestBodyNode`.\n */\nexport const operationDef = defineNode<OperationNode, OperationInput>({\n kind: 'Operation',\n build: (props) => {\n const { requestBody, ...rest } = props\n const isHttp = rest.method !== undefined && rest.path !== undefined\n\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...rest,\n ...(isHttp ? { protocol: 'http' as const } : {}),\n requestBody: requestBody ? createRequestBody(requestBody) : undefined,\n }\n },\n children: ['parameters', 'requestBody', 'responses'],\n visitorKey: 'operation',\n})\n\n/**\n * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.\n *\n * @example\n * ```ts\n * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })\n * // tags, parameters, and responses are []\n * ```\n */\nexport function createOperation(\n props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &\n Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {\n requestBody?: UserRequestBody\n },\n): HttpOperationNode\nexport function createOperation(\n props: Pick<GenericOperationNode, 'operationId'> &\n Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {\n requestBody?: UserRequestBody\n },\n): GenericOperationNode\nexport function createOperation(props: OperationInput): OperationNode {\n return operationDef.create(props)\n}\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { FileNode } from './file.ts'\n\n/**\n * Output AST node that groups all generated file output for one API document.\n *\n * Produced by generators and consumed by the build pipeline to write files.\n *\n * @example\n * ```ts\n * const output: OutputNode = {\n * kind: 'Output',\n * files: [],\n * }\n * ```\n */\nexport type OutputNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Output'\n /**\n * Generated file nodes.\n */\n files: Array<FileNode>\n}\n\n/**\n * Definition for the {@link OutputNode}.\n */\nexport const outputDef = defineNode<OutputNode, Partial<Omit<OutputNode, 'kind'>>>({\n kind: 'Output',\n defaults: { files: [] },\n visitorKey: 'output',\n})\n\n/**\n * Creates an `OutputNode` with a stable default for `files`.\n *\n * @example\n * ```ts\n * const output = createOutput()\n * // { kind: 'Output', files: [] }\n * ```\n */\nexport function createOutput(overrides: Partial<Omit<OutputNode, 'kind'>> = {}): OutputNode {\n return outputDef.create(overrides)\n}\n","import { defineNode, syncOptionality } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { SchemaNode } from './schema.ts'\n\nexport type ParameterLocation = 'path' | 'query' | 'header' | 'cookie'\n\n/**\n * AST node representing one operation parameter.\n *\n * @example\n * ```ts\n * const param: ParameterNode = {\n * kind: 'Parameter',\n * name: 'petId',\n * in: 'path',\n * schema: createSchema({ type: 'string' }),\n * required: true,\n * }\n * ```\n */\nexport type ParameterNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Parameter'\n /**\n * Parameter name.\n */\n name: string\n /**\n * Parameter location (`path`, `query`, `header`, or `cookie`).\n */\n in: ParameterLocation\n /**\n * Parameter schema.\n */\n schema: SchemaNode\n /**\n * Whether the parameter is required.\n */\n required: boolean\n}\n\ntype UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>\n\n/**\n * Definition for the {@link ParameterNode}. `required` defaults to `false` and the\n * schema's `optional`/`nullish` flags are kept in sync with it.\n */\nexport const parameterDef = defineNode<ParameterNode, UserParameterNode>({\n kind: 'Parameter',\n build: (props) => {\n const required = props.required ?? false\n return { ...props, required, schema: syncOptionality(props.schema, required) }\n },\n children: ['schema'],\n visitorKey: 'parameter',\n rebuild: true,\n})\n\n/**\n * Creates a `ParameterNode`.\n *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'petId',\n * in: 'path',\n * required: true,\n * schema: createSchema({ type: 'string' }),\n * })\n * ```\n */\nexport const createParameter = parameterDef.create\n","import { defineNode, syncOptionality } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * AST node representing one named object property.\n *\n * @example\n * ```ts\n * const property: PropertyNode = {\n * kind: 'Property',\n * name: 'id',\n * schema: createSchema({ type: 'integer' }),\n * required: true,\n * }\n * ```\n */\nexport type PropertyNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Property'\n /**\n * Property key.\n */\n name: string\n /**\n * Property schema.\n */\n schema: SchemaNode\n /**\n * Whether the property is required.\n */\n required: boolean\n}\n\n/**\n * Loosely-typed property accepted by `createProperty`, with `required` optional.\n */\nexport type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>\n\n/**\n * Definition for the {@link PropertyNode}. `required` defaults to `false` and the\n * schema's `optional`/`nullish` flags are kept in sync with it.\n */\nexport const propertyDef = defineNode<PropertyNode, UserPropertyNode>({\n kind: 'Property',\n build: (props) => {\n const required = props.required ?? false\n return { ...props, required, schema: syncOptionality(props.schema, required) }\n },\n children: ['schema'],\n visitorKey: 'property',\n rebuild: true,\n})\n\n/**\n * Creates a `PropertyNode`.\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * required: true,\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=true, no optional/nullish\n * ```\n */\nexport const createProperty = propertyDef.create\n","import { defineNode } from '../node.ts'\nimport type { BaseNode } from './base.ts'\nimport { type ContentNode, createContent, type UserContent } from './content.ts'\nimport type { StatusCode } from './http.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * AST node representing one operation response variant.\n *\n * Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside\n * the `content` array (one entry per content type), so the same schema is never duplicated at the\n * node root and inside `content`.\n *\n * @example\n * ```ts\n * const response: ResponseNode = {\n * kind: 'Response',\n * statusCode: '200',\n * content: [{ contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type ResponseNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Response'\n /**\n * HTTP status code or `'default'` for a fallback response.\n */\n statusCode: StatusCode\n /**\n * Optional response description.\n */\n description?: string\n /**\n * All available content type entries for this response.\n *\n * When the adapter `contentType` option is set, this array contains exactly one entry for that\n * content type. Otherwise it contains one entry per content type declared in the spec, so that\n * plugins can generate a union of response types (e.g. `application/json` and `application/xml`).\n * Body-less responses keep a single entry whose `schema` is the empty/`void` placeholder.\n *\n * @example\n * ```ts\n * // spec response declares both application/json and application/xml\n * response.content[0].contentType // 'application/json'\n * response.content[1].contentType // 'application/xml'\n * ```\n */\n content?: Array<ContentNode>\n}\n\ntype ResponseInput = Pick<ResponseNode, 'statusCode'> &\n Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {\n content?: Array<UserContent>\n schema?: SchemaNode\n mediaType?: string | null\n keysToOmit?: Array<string> | null\n }\n\n/**\n * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional\n * `mediaType`/`keysToOmit`) is normalized into one `content` entry.\n */\nexport const responseDef = defineNode<ResponseNode, ResponseInput>({\n kind: 'Response',\n build: (props) => {\n const { schema, mediaType, keysToOmit, content, ...rest } = props\n const entries = content ?? (schema ? [{ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null }] : undefined)\n return { ...rest, content: entries?.map(createContent) }\n },\n children: ['content'],\n visitorKey: 'response',\n})\n\n/**\n * Creates a `ResponseNode`.\n *\n * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],\n * })\n * ```\n */\nexport const createResponse = responseDef.create\n","import type { NodeDef } from './node.ts'\nimport { arrowFunctionDef, breakDef, constDef, functionDef, jsxDef, textDef, typeDef } from './nodes/code.ts'\nimport { contentDef } from './nodes/content.ts'\nimport { exportDef, fileDef, importDef, sourceDef } from './nodes/file.ts'\nimport { functionParameterDef, functionParametersDef, indexedAccessTypeDef, objectBindingPatternDef, typeLiteralDef } from './nodes/function.ts'\nimport type { Node, NodeKind } from './nodes/index.ts'\nimport { inputDef } from './nodes/input.ts'\nimport { operationDef } from './nodes/operation.ts'\nimport { outputDef } from './nodes/output.ts'\nimport { parameterDef } from './nodes/parameter.ts'\nimport { propertyDef } from './nodes/property.ts'\nimport { requestBodyDef } from './nodes/requestBody.ts'\nimport { responseDef } from './nodes/response.ts'\nimport { schemaDef } from './nodes/schema.ts'\n\n/**\n * Every node definition. Adding a node means adding its `defineNode` to one\n * `nodes/*.ts` file and listing it here. The visitor tables below derive from it.\n */\nexport const nodeDefs = [\n inputDef,\n outputDef,\n operationDef,\n requestBodyDef,\n contentDef,\n responseDef,\n schemaDef,\n propertyDef,\n parameterDef,\n functionParameterDef,\n functionParametersDef,\n typeLiteralDef,\n indexedAccessTypeDef,\n objectBindingPatternDef,\n constDef,\n typeDef,\n functionDef,\n arrowFunctionDef,\n textDef,\n breakDef,\n jsxDef,\n importDef,\n exportDef,\n sourceDef,\n fileDef,\n] satisfies ReadonlyArray<NodeDef>\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n * Derived from each definition's `children`.\n */\nexport const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => (def.children ? [[def.kind, def.children] as const] : []))) as Partial<\n Record<NodeKind, ReadonlyArray<string>>\n>\n\n/**\n * Maps a node kind to the matching visitor callback name. Derived from each\n * definition's `visitorKey`.\n */\nexport const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => (def.visitorKey ? [[def.kind, def.visitorKey] as const] : []))) as Partial<\n Record<NodeKind, NonNullable<NodeDef['visitorKey']>>\n>\n\n/**\n * Per-kind builders rerun after children are rebuilt. Derived from each\n * definition's `rebuild` flag.\n */\nexport const nodeRebuilders = Object.fromEntries(\n nodeDefs.flatMap((def) => (def.rebuild ? [[def.kind, def.create as unknown as (node: Node) => Node] as const] : [])),\n) as Partial<Record<NodeKind, (node: Node) => Node>>\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport { nodeRebuilders, VISITOR_KEY_BY_KIND, VISITOR_KEYS } from './registry.ts'\nimport type {\n ContentNode,\n InputNode,\n Node,\n OperationNode,\n OutputNode,\n ParameterNode,\n PropertyNode,\n RequestBodyNode,\n ResponseNode,\n SchemaNode,\n} from './nodes/index.ts'\n\n/**\n * Creates a small async concurrency limiter.\n *\n * At most `concurrency` tasks are in flight at once. Extra tasks are queued.\n *\n * @example\n * ```ts\n * const limit = createLimit(2)\n * for (const task of [taskA, taskB, taskC]) {\n * await limit(() => task())\n * }\n * // only 2 tasks run at the same time\n * ```\n */\nfunction createLimit(concurrency: number) {\n let active = 0\n const queue: Array<() => void> = []\n\n function next() {\n if (active < concurrency && queue.length > 0) {\n active++\n queue.shift()!()\n }\n }\n\n return function limit<T>(fn: () => Promise<T> | T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n queue.push(() => {\n Promise.resolve(fn())\n .then(resolve, reject)\n .finally(() => {\n active--\n next()\n })\n })\n next()\n })\n }\n}\n\ntype LimitFn = ReturnType<typeof createLimit>\n\n/**\n * Ordered mapping of `[NodeType, ParentType]` pairs.\n *\n * `ParentOf` uses this map to find parent types.\n */\ntype ParentNodeMap = [\n [InputNode, undefined],\n [OutputNode, undefined],\n [OperationNode, InputNode],\n [RequestBodyNode, OperationNode],\n [ContentNode, RequestBodyNode | ResponseNode],\n [SchemaNode, InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode],\n [PropertyNode, SchemaNode],\n [ParameterNode, OperationNode],\n [ResponseNode, OperationNode],\n]\n\n/**\n * Resolves the parent node type for a given AST node type.\n *\n * This is used by visitor context so `ctx.parent` is correctly typed\n * for each callback.\n *\n * @example\n * ```ts\n * type InputParent = ParentOf<InputNode>\n * // undefined\n * ```\n *\n * @example\n * ```ts\n * type PropertyParent = ParentOf<PropertyNode>\n * // SchemaNode\n * ```\n *\n * @example\n * ```ts\n * type SchemaParent = ParentOf<SchemaNode>\n * // InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode\n * ```\n */\nexport type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [\n infer TEntry extends [Node, unknown],\n ...infer TRest extends ReadonlyArray<[Node, unknown]>,\n]\n ? T extends TEntry[0]\n ? TEntry[1]\n : ParentOf<T, TRest>\n : Node\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n * `parent` is typed from the current node type.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent type is narrowed by node kind\n * },\n * }\n * ```\n */\nexport type VisitorContext<T extends Node = Node> = {\n /**\n * Parent node of the currently visited node.\n * For `InputNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites operation IDs, drops descriptions, or otherwise tweaks the AST\n * before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode\n output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode\n}\n\n/**\n * Utility type for values that can be returned directly or asynchronously.\n */\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.\n *\n * @example\n * ```ts\n * const visitor: AsyncVisitor = {\n * async operation(node) {\n * await Promise.resolve(node.operationId)\n * },\n * }\n * ```\n */\ntype AsyncVisitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<undefined | null | InputNode>\n output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<undefined | null | OutputNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<undefined | null | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<undefined | null | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<undefined | null | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<undefined | null | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<undefined | null | ResponseNode>\n}\n\n/**\n * Visitor used by `collect`.\n *\n * @example\n * ```ts\n * const visitor: CollectVisitor<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\ntype CollectVisitor<T> = {\n input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined\n output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `walk`.\n *\n * @example\n * ```ts\n * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }\n * ```\n */\nexport type WalkOptions = AsyncVisitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Maximum number of sibling nodes visited concurrently.\n * @default 30\n */\n concurrency?: number\n}\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = CollectVisitor<T> & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\nconst visitorKeysByKind = VISITOR_KEYS as Record<string, ReadonlyArray<string> | undefined>\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && 'kind' in value\n}\n\n/**\n * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.\n *\n * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, the request body, and responses\n * ```\n */\nfunction* getChildren(node: Node, recurse: boolean): Generator<Node, void, undefined> {\n if (node.kind === 'Schema' && !recurse) return\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return\n\n const record = node as unknown as Record<string, unknown>\n for (const key of keys) {\n const value = record[key]\n if (Array.isArray(value)) {\n for (const item of value) if (isNode(item)) yield item\n } else if (isNode(value)) {\n yield value\n }\n }\n}\n\n/**\n * Invokes the visitor callback that matches `node.kind`, passing the traversal\n * context. Returns the callback's result (a replacement node, a collected\n * value, or `undefined` when no callback is registered for the kind).\n *\n * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives\n * in one place. `TResult` is the caller's expected return: the same node type\n * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | AsyncVisitor | CollectVisitor<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Async depth-first traversal for side effects. Visitor return values are\n * ignored. Use `transform` when you want to rewrite nodes.\n *\n * Sibling nodes at each depth run concurrently up to `options.concurrency`\n * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor\n * work. Lower values reduce memory pressure.\n *\n * @example Log every operation\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example Only visit the root node\n * ```ts\n * await walk(root, { depth: 'shallow', input: () => {} })\n * ```\n */\nexport async function walk(node: Node, options: WalkOptions): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const limit = createLimit(options.concurrency ?? WALK_CONCURRENCY)\n\n return _walk(node, options, recurse, limit, undefined)\n}\n\nasync function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn, parent: Node | undefined): Promise<void> {\n await limit(() => applyVisitor(node, visitor, parent))\n\n // Visit siblings concurrently and let the shared `limit` cap how many callbacks\n // run at once. Awaiting each child sequentially here would serialize the whole\n // traversal and make `concurrency` inert, every visitor callback would run one\n // at a time regardless of the limit.\n const children = Array.from(getChildren(node, recurse))\n if (children.length === 0) return\n\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback gets a chance to\n * return a replacement node; `undefined` keeps the original.\n *\n * The transform is immutable. The original tree is not mutated. A new tree\n * is returned. Use `depth: 'shallow'` to skip recursion into children.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Replace only the root node\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform(node: InputNode, options: TransformOptions): InputNode\nexport function transform(node: OutputNode, options: TransformOptions): OutputNode\nexport function transform(node: OperationNode, options: TransformOptions): OperationNode\nexport function transform(node: SchemaNode, options: TransformOptions): SchemaNode\nexport function transform(node: PropertyNode, options: TransformOptions): PropertyNode\nexport function transform(node: ParameterNode, options: TransformOptions): ParameterNode\nexport function transform(node: ResponseNode, options: TransformOptions): ResponseNode\nexport function transform(node: Node, options: TransformOptions): Node\nexport function transform(node: Node, options: TransformOptions): Node {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n const rebuilt = transformChildren(visited, options, recurse)\n\n // Structural sharing: when the visitor and child rebuild both left this node\n // untouched, return the original reference so callers can detect \"nothing\n // changed\" by identity and ancestors can avoid reallocating.\n if (rebuilt === node) return node\n\n const rebuild = nodeRebuilders[rebuilt.kind]\n return rebuild ? rebuild(rebuilt) : rebuilt\n}\n\n/**\n * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming\n * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.\n * `Schema` children are skipped in shallow mode.\n */\nfunction transformChildren(node: Node, options: TransformOptions, recurse: boolean): Node {\n if (node.kind === 'Schema' && !recurse) return node\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n const childOptions = { ...options, parent: node }\n let updates: Record<string, unknown> | undefined\n\n for (const key of keys) {\n if (!(key in record)) continue\n const value = record[key]\n if (Array.isArray(value)) {\n let changed = false\n const mapped = value.map((item) => {\n if (!isNode(item)) return item\n const next = transform(item, childOptions)\n if (next !== item) changed = true\n return next\n })\n if (changed) (updates ??= {})[key] = mapped\n } else if (isNode(value)) {\n const next = transform(value, childOptions)\n if (next !== value) (updates ??= {})[key] = next\n }\n }\n\n return updates ? ({ ...node, ...updates } as Node) : node\n}\n/**\n * Lazy depth-first collection pass. Yields every non-null value returned by\n * the visitor callbacks. Use `collect` for the eager array form.\n *\n * @example Collect every operationId\n * ```ts\n * const ids: string[] = []\n * for (const id of collectLazy<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })) {\n * ids.push(id)\n * }\n * ```\n */\nexport function* collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) yield v\n\n for (const child of getChildren(node, recurse)) {\n yield* collectLazy(child, { ...options, parent: node })\n }\n}\n\n/**\n * Eager depth-first collection pass. Returns an array of every non-null value\n * the visitor callbacks return.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n return Array.from(collectLazy(node, options))\n}\n","import type { Node, OperationNode, SchemaNode } from './nodes/index.ts'\nimport { createSchema } from './nodes/schema.ts'\nimport { signatureOf } from './signature.ts'\nimport { extractRefName } from './utils/index.ts'\nimport { collectLazy, transform } from './visitor.ts'\n\n/**\n * A canonical destination for a deduplicated shape: the shared schema name and\n * the synthetic `$ref` path that points at it.\n */\nexport type DedupeCanonical = {\n /**\n * Canonical schema name every duplicate occurrence refers to.\n */\n name: string\n /**\n * `$ref` path stored on the generated `ref` nodes (for example `#/components/schemas/Status`).\n */\n ref: string\n}\n\n/**\n * The result of {@link buildDedupePlan}: a lookup from structural signature to its\n * canonical target, plus the freshly hoisted definitions that must be added to\n * the schema list.\n */\nexport type DedupePlan = {\n /**\n * Maps a structural signature to the canonical schema that represents it.\n */\n canonicalBySignature: Map<string, DedupeCanonical>\n /**\n * Maps the name of a top-level schema that duplicates a canonical one to that canonical, so\n * references to the duplicate can be repointed at the first schema with the same content.\n */\n aliasNames: Map<string, DedupeCanonical>\n /**\n * New top-level schema definitions created for inline shapes that had no existing\n * named component. Nested duplicates inside each definition are already collapsed.\n */\n hoisted: Array<SchemaNode>\n}\n\n/**\n * The lookups {@link applyDedupe} needs from a {@link DedupePlan}.\n */\nexport type DedupeLookups = Pick<DedupePlan, 'canonicalBySignature' | 'aliasNames'>\n\n/**\n * Options that inject the naming and candidate policy into {@link buildDedupePlan}.\n * The mechanics (grouping, counting, rewriting) live here. The policy lives in the caller.\n */\nexport type BuildDedupePlanOptions = {\n /**\n * Returns `true` when a node should be deduplicated. This is the only gate, so it must\n * reject both ineligible kinds (return `false` for anything other than, say, enums and\n * objects) and unsafe shapes (e.g. nodes that reference a circular schema).\n */\n isCandidate: (node: SchemaNode) => boolean\n /**\n * Produces the canonical name for an inline shape with no existing named component.\n * Return `null` to leave the shape inline (for example when no contextual name exists).\n */\n nameFor: (node: SchemaNode, signature: string) => string | null\n /**\n * Builds the `$ref` path for a canonical name.\n */\n refFor: (name: string) => string\n /**\n * Minimum number of occurrences before a shape is deduplicated.\n *\n * @default 2\n */\n minOccurrences?: number\n}\n\n/**\n * Builds the shared `ref` replacement for a duplicate occurrence, carrying the\n * usage-slot and documentation fields that are not part of the canonical type.\n */\nfunction createRefNode(node: SchemaNode, canonical: DedupeCanonical): SchemaNode {\n return createSchema({\n type: 'ref',\n name: canonical.name,\n ref: canonical.ref,\n optional: node.optional,\n nullish: node.nullish,\n readOnly: node.readOnly,\n writeOnly: node.writeOnly,\n deprecated: node.deprecated,\n description: node.description,\n default: node.default,\n example: node.example,\n })\n}\n\n/**\n * Rewrites a node, replacing every candidate sub-schema whose signature has a canonical\n * target with a `ref` to that target. Replacing a node with a `ref` prunes its subtree,\n * so nested duplicates inside a replaced shape are not visited again. A `ref` that points\n * at a duplicate top-level schema (see `aliasNames`) is repointed at the first schema with\n * the same content.\n *\n * Pass `skipRootMatch` when rewriting a canonical definition so its own root is not\n * turned into a reference to itself. Nested duplicates are still collapsed.\n *\n * @example\n * ```ts\n * const next = applyDedupe(operationNode, plan)\n * ```\n */\nexport function applyDedupe(node: SchemaNode, plan: DedupeLookups, skipRootMatch?: boolean): SchemaNode\nexport function applyDedupe(node: OperationNode, plan: DedupeLookups, skipRootMatch?: boolean): OperationNode\nexport function applyDedupe(node: Node, plan: DedupeLookups, skipRootMatch = false): Node {\n const { canonicalBySignature, aliasNames } = plan\n if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node\n\n const root = node\n\n return transform(node, {\n schema(schemaNode) {\n if (schemaNode.type === 'ref') {\n const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name\n const canonical = target ? aliasNames.get(target) : undefined\n\n return canonical ? { ...schemaNode, name: canonical.name, ref: canonical.ref } : undefined\n }\n\n const signature = signatureOf(schemaNode)\n if (skipRootMatch && schemaNode === root) return undefined\n\n const canonical = canonicalBySignature.get(signature)\n if (!canonical) return undefined\n\n return createRefNode(schemaNode, canonical)\n },\n })\n}\n\n/**\n * Strips usage-slot flags from a hoisted definition and applies its canonical name.\n * A standalone definition is never optional, so `optional`/`nullish` are cleared.\n */\nfunction cleanDefinition(node: SchemaNode, name: string): SchemaNode {\n return { ...node, name, optional: undefined, nullish: undefined }\n}\n\n/**\n * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.\n *\n * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence\n * is a named top-level schema, the first one becomes the canonical (so other top-level\n * duplicates and inline copies turn into references to it). Every other top-level name with\n * the same content is recorded in `aliasNames`, so refs to it can be repointed at the\n * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied\n * per node with {@link applyDedupe}.\n *\n * @example\n * ```ts\n * const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {\n * isCandidate: (node) => node.type === 'enum' || node.type === 'object',\n * nameFor: (node) => node.name ?? null,\n * refFor: (name) => `#/components/schemas/${name}`,\n * })\n * ```\n */\nexport function buildDedupePlan(roots: ReadonlyArray<Node>, options: BuildDedupePlanOptions): DedupePlan {\n const { isCandidate, nameFor, refFor, minOccurrences = 2 } = options\n\n const topLevelNodes = new Set<SchemaNode>()\n\n type Group = {\n count: number\n representative: SchemaNode\n topLevelNames: Array<string>\n }\n const groups = new Map<string, Group>()\n\n function record(schemaNode: SchemaNode): void {\n const signature = signatureOf(schemaNode)\n if (!isCandidate(schemaNode)) return\n\n const isTopLevel = topLevelNodes.has(schemaNode) && !!schemaNode.name\n const group = groups.get(signature)\n if (group) {\n group.count++\n if (isTopLevel) group.topLevelNames.push(schemaNode.name!)\n } else {\n groups.set(signature, { count: 1, representative: schemaNode, topLevelNames: isTopLevel ? [schemaNode.name!] : [] })\n }\n }\n\n for (const root of roots) {\n if (root.kind === 'Schema') topLevelNodes.add(root)\n for (const schemaNode of collectLazy<SchemaNode>(root, { schema: (node) => node })) {\n record(schemaNode)\n }\n }\n\n const canonicalBySignature = new Map<string, DedupeCanonical>()\n const aliasNames = new Map<string, DedupeCanonical>()\n const pendingHoists: Array<{ name: string; representative: SchemaNode }> = []\n\n for (const [signature, group] of groups) {\n if (group.count < minOccurrences) continue\n\n const [firstName, ...duplicateNames] = group.topLevelNames\n if (firstName) {\n const canonical: DedupeCanonical = { name: firstName, ref: refFor(firstName) }\n canonicalBySignature.set(signature, canonical)\n for (const duplicate of duplicateNames) {\n aliasNames.set(duplicate, canonical)\n }\n continue\n }\n\n const name = nameFor(group.representative, signature)\n if (!name) continue\n\n canonicalBySignature.set(signature, { name, ref: refFor(name) })\n pendingHoists.push({ name, representative: group.representative })\n }\n\n // Build hoisted definitions only after every canonical name is known, so nested\n // duplicates inside a definition also resolve to refs.\n const hoisted = pendingHoists.map(({ name, representative }) =>\n cleanDefinition(applyDedupe(representative, { canonicalBySignature, aliasNames }, true), name),\n )\n\n return { canonicalBySignature, aliasNames, hoisted }\n}\n","/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * Whether the schema is nullable.\n */\n isNullable: (schema?: TSchema) => boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference: (value?: unknown) => value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator: (value?: unknown) => value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary: (schema: TSchema) => boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef: <TResolved>(document: TDocument, ref: string) => TResolved | null | undefined\n}\n\n/**\n * Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineSchemaDialect({\n * name: 'oas',\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * })\n * ```\n */\nexport function defineSchemaDialect<TSchema, TRef, TDiscriminated, TDocument>(\n dialect: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>,\n): SchemaDialect<TSchema, TRef, TDiscriminated, TDocument> {\n return dialect\n}\n","import type { HttpOperationNode, OperationNode, SchemaNode, SchemaNodeByType } from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode`, guaranteeing `method` and `path`.\n *\n * @example\n * ```ts\n * if (isHttpOperationNode(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n","import { camelCase, isValidVarName, memoize } from '@internals/utils'\n\nimport { narrowSchema } from '../guards.ts'\nimport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createTypeLiteral } from '../nodes/function.ts'\nimport { createProperty } from '../nodes/property.ts'\nimport { createSchema } from '../nodes/schema.ts'\nimport type {\n CodeNode,\n ExportNode,\n FunctionParameterNode,\n FunctionParametersNode,\n ImportNode,\n OperationNode,\n ParameterNode,\n SchemaNode,\n SourceNode,\n TypeExpression,\n TypeLiteralNode,\n} from '../nodes/index.ts'\nimport type { SchemaType } from '../nodes/schema.ts'\nimport { extractRefName } from './index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node\n * override the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.\n *\n * @example\n * ```ts\n * // Ref with description override\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Applies casing rules to parameter names and returns a new parameter array.\n *\n * Use this before passing parameters to schema builders so output property keys match\n * the desired casing while preserving `OperationNode.parameters` for other consumers.\n * The input array is not mutated. When `casing` is not set, the original array is returned unchanged.\n */\nconst caseParamsMemo = memoize(new WeakMap<Array<ParameterNode>, (casing: string) => Array<ParameterNode>>(), (params) =>\n memoize(new Map<string, Array<ParameterNode>>(), (casing: string) =>\n params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n return { ...param, name: transformed }\n }),\n ),\n)\n\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) return params\n return caseParamsMemo(params)(casing)\n}\n\n/**\n * Creates a single-property object schema used as a discriminator literal.\n *\n * @example\n * ```ts\n * createDiscriminantNode({ propertyName: 'type', value: 'dog' })\n * // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }\n * ```\n */\nexport function createDiscriminantNode({ propertyName, value }: { propertyName: string; value: string }): SchemaNode {\n return createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n createProperty({\n name: propertyName,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: [value],\n }),\n required: true,\n }),\n ],\n })\n}\n\n/**\n * Named type for a group of parameters (query or header) emitted as a single typed parameter.\n */\ntype ParamGroupType = {\n /**\n * Type expression for the group, a plain group-name reference.\n */\n type: TypeExpression\n /**\n * Whether the parameter group is optional.\n */\n optional: boolean\n}\n\n/**\n * A single member of a destructured parameter group, fed to `createFunctionParameter({ properties })`.\n */\ntype GroupProperty = {\n name: string\n type: TypeExpression\n optional?: boolean\n}\n\n/**\n * Resolver interface for {@link createOperationParams}.\n *\n * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.\n */\nexport type OperationParamsResolver = {\n /**\n * Resolves the type name for an individual parameter.\n *\n * @example Individual path parameter name\n * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`\n */\n resolveParamName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the request body type name.\n *\n * @example Request body type name\n * `resolver.resolveDataName(node) // → 'CreatePetData'`\n */\n resolveDataName(node: OperationNode): string\n /**\n * Resolves the grouped path parameters type name.\n * When the return value equals `resolveParamName`, no indexed access is emitted.\n *\n * @example Grouped path params type name\n * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`\n */\n resolvePathParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped query parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped query params type name\n * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`\n */\n resolveQueryParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped header parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped header params type name\n * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`\n */\n resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string\n}\n\n/**\n * Options for {@link createOperationParams}.\n */\nexport type CreateOperationParamsOptions = {\n /**\n * How all operation parameters are grouped in the function signature.\n * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`\n * - `'inline'` emits each param category as a separate top-level parameter\n */\n paramsType: 'object' | 'inline'\n /**\n * How path parameters are emitted when `paramsType` is `'inline'`.\n * - `'object'` groups them as `{ petId, storeId }: PathParams`\n * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`\n * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`\n */\n pathParamsType: 'object' | 'inline' | 'inlineSpread'\n /**\n * Converts parameter names to camelCase before output.\n */\n paramsCasing?: 'camelcase'\n /**\n * Resolver for parameter and request body type names.\n * Pass `ResolverTs` from `@kubb/plugin-ts` directly.\n * When omitted, falls back to the schema primitive or `'unknown'`.\n */\n resolver?: OperationParamsResolver\n /**\n * Default value for the path parameters binding when `pathParamsType` is `'object'`.\n * Falls back to `'{}'` when all path params are optional.\n */\n pathParamsDefault?: string\n /**\n * Extra parameters appended after the standard operation parameters.\n *\n * @example Plugin-specific trailing parameter\n * ```ts\n * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]\n * ```\n */\n extraParams?: Array<FunctionParameterNode>\n /**\n * Override the default parameter names used for body, query, header, and rest-path groups.\n *\n * Useful when targeting languages or frameworks with different naming conventions.\n *\n * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }\n */\n paramNames?: {\n /**\n * Name for the request body parameter.\n * @default 'data'\n */\n data?: string\n /**\n * Name for the query parameters group parameter.\n * @default 'params'\n */\n params?: string\n /**\n * Name for the header parameters group parameter.\n * @default 'headers'\n */\n headers?: string\n /**\n * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.\n * @default 'pathParams'\n */\n path?: string\n }\n /**\n * Applies a uniform transformation to every resolved type name before it is used\n * in a parameter node. Use this for framework-level type wrappers.\n *\n * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`\n * `typeWrapper: (t) => \\`MaybeRefOrGetter<${t}>\\``\n */\n typeWrapper?: (type: string) => string\n}\n\n/**\n * Resolves the {@link TypeExpression} for an individual parameter.\n *\n * Without a resolver, falls back to the schema primitive (a plain type-name string).\n * When the parameter belongs to a named group, emits an {@link IndexedAccessTypeNode}\n * (`GroupParams['petId']`); otherwise the resolved individual name as a plain string.\n */\nexport function resolveParamType({\n node,\n param,\n resolver,\n}: {\n node: OperationNode\n param: ParameterNode\n resolver: OperationParamsResolver | undefined\n}): TypeExpression {\n if (!resolver) {\n return param.schema.primitive ?? 'unknown'\n }\n\n const individualName = resolver.resolveParamName(node, param)\n\n const groupLocation = param.in === 'path' || param.in === 'query' || param.in === 'header' ? param.in : undefined\n\n const groupResolvers = {\n path: resolver.resolvePathParamsName,\n query: resolver.resolveQueryParamsName,\n header: resolver.resolveHeaderParamsName,\n } as const\n\n const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : undefined\n\n if (groupName && groupName !== individualName) {\n return createIndexedAccessType({ objectType: groupName, indexType: param.name })\n }\n\n return individualName\n}\n\n/**\n * Converts an `OperationNode` into function parameters for code generation.\n *\n * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one\n * destructured object parameter (`object`) and separate top-level parameters (`inline`), while\n * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type\n * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.\n */\nexport function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode {\n const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options\n\n const dataName = paramNames?.data ?? 'data'\n const paramsName = paramNames?.params ?? 'params'\n const headersName = paramNames?.headers ?? 'headers'\n const pathName = paramNames?.path ?? 'pathParams'\n\n const wrapType = (type: string): string => (typeWrapper ? typeWrapper(type) : type)\n // Only plain type-name references are wrapped, they need casing applied.\n // TypeLiteral and IndexedAccessType expressions are pre-resolved and pass through unchanged.\n const wrapTypeExpression = (type: TypeExpression): TypeExpression => (typeof type === 'string' ? wrapType(type) : type)\n\n const casedParams = caseParams(node.parameters, paramsCasing)\n const pathParams = casedParams.filter((p) => p.in === 'path')\n const queryParams = casedParams.filter((p) => p.in === 'query')\n const headerParams = casedParams.filter((p) => p.in === 'header')\n\n const toProperty = (param: ParameterNode): GroupProperty => ({\n name: param.name,\n type: wrapTypeExpression(resolveParamType({ node, param, resolver })),\n optional: !param.required,\n })\n const emptyObjectDefault = (props: Array<GroupProperty>): string | undefined => (props.every((p) => p.optional) ? '{}' : undefined)\n\n const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined\n const bodyProperty: Array<GroupProperty> = bodyType ? [{ name: dataName, type: bodyType, optional: !(node.requestBody?.required ?? false) }] : []\n\n const trailingGroups: Array<BuildGroupArgs> = [\n { name: paramsName, node, params: queryParams, groupType: resolveGroupType({ node, params: queryParams, group: 'query', resolver }), resolver, wrapType },\n {\n name: headersName,\n node,\n params: headerParams,\n groupType: resolveGroupType({ node, params: headerParams, group: 'header', resolver }),\n resolver,\n wrapType,\n },\n ]\n\n const params: Array<FunctionParameterNode> = []\n\n if (paramsType === 'object') {\n const children = [...pathParams.map(toProperty), ...bodyProperty, ...trailingGroups.flatMap(buildGroupProperty)]\n if (children.length) {\n params.push(createFunctionParameter({ properties: children, default: emptyObjectDefault(children) }))\n }\n } else {\n if (pathParamsType === 'inlineSpread' && pathParams.length) {\n const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]!)\n params.push(createFunctionParameter({ name: pathName, type: spreadType ? wrapType(spreadType) : undefined, rest: true }))\n } else if (pathParamsType === 'inline') {\n params.push(...pathParams.map((p) => createFunctionParameter(toProperty(p))))\n } else if (pathParams.length) {\n const pathChildren = pathParams.map(toProperty)\n params.push(createFunctionParameter({ properties: pathChildren, default: pathParamsDefault ?? emptyObjectDefault(pathChildren) }))\n }\n\n params.push(...bodyProperty.map((p) => createFunctionParameter(p)))\n params.push(...trailingGroups.flatMap(buildGroupParam))\n }\n\n params.push(...extraParams)\n\n return createFunctionParameters({ params })\n}\n\n/**\n * Shared arguments for building a query or header parameter group.\n */\ntype BuildGroupArgs = {\n name: string\n node: OperationNode\n params: Array<ParameterNode>\n groupType: ParamGroupType | null\n resolver: OperationParamsResolver | undefined\n wrapType: (type: string) => string\n}\n\n/**\n * Builds the property descriptor for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nfunction buildGroupProperty({ name, node, params, groupType, resolver, wrapType }: BuildGroupArgs): Array<GroupProperty> {\n if (groupType) {\n const type = typeof groupType.type === 'string' ? wrapType(groupType.type) : groupType.type\n return [{ name, type, optional: groupType.optional }]\n }\n if (params.length) {\n return [{ name, type: buildTypeLiteral({ node, params, resolver }), optional: params.every((p) => !p.required) }]\n }\n return []\n}\n\n/**\n * Builds a single {@link FunctionParameterNode} for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nexport function buildGroupParam(args: BuildGroupArgs): Array<FunctionParameterNode> {\n return buildGroupProperty(args).map((p) => createFunctionParameter(p))\n}\n\n/**\n * Derives a {@link ParamGroupType} for a query or header group from the resolver.\n *\n * Returns `null` when there is no resolver, no params, or the group name equals the\n * individual param name (so there is no real group to emit).\n */\nexport function resolveGroupType({\n node,\n params,\n group,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n group: 'query' | 'header'\n resolver: OperationParamsResolver | undefined\n}): ParamGroupType | null {\n if (!resolver || !params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupMethod = group === 'query' ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n return { type: groupName, optional: params.every((p) => !p.required) }\n}\n\n/**\n * Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.\n *\n * Used when query or header parameters have no dedicated group type name.\n * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).\n */\nexport function buildTypeLiteral({\n node,\n params,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n resolver: OperationParamsResolver | undefined\n}): TypeLiteralNode {\n return createTypeLiteral({\n members: params.map((p) => ({\n name: p.name,\n type: resolveParamType({ node, param: p, resolver }),\n optional: !p.required,\n })),\n })\n}\n\nfunction sourceKey(source: SourceNode): string {\n const nameKey = source.name ?? extractStringsFromNodes(source.nodes)\n return `${nameKey}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`\n}\n\nfunction pathTypeKey(path: string, isTypeOnly: boolean | null | undefined): string {\n return `${path}:${isTypeOnly ?? false}`\n}\n\nfunction exportKey(path: string, name: string | null | undefined, isTypeOnly: boolean | null | undefined, asAlias: boolean | null | undefined): string {\n return `${path}:${name ?? ''}:${isTypeOnly ?? false}:${asAlias ?? ''}`\n}\n\nfunction importKey(path: string, name: string | null | undefined, isTypeOnly: boolean | null | undefined): string {\n return `${path}:${name ?? ''}:${isTypeOnly ?? false}`\n}\n\n/**\n * Computes a multi-level sort key for exports and imports:\n * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.\n */\nfunction sortKey(node: { name?: string | Array<unknown> | null; isTypeOnly?: boolean | null; path: string }): string {\n const isArray = Array.isArray(node.name) ? '1' : '0'\n const typeOnly = node.isTypeOnly ? '0' : '1'\n const hasName = node.name != null ? '1' : '0'\n const name = Array.isArray(node.name) ? node.name.toSorted().join('\\0') : (node.name ?? '')\n return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`\n}\n\n/**\n * Deduplicates and merges `SourceNode` objects by `name + isExportable + isTypeOnly`.\n *\n * Unnamed sources are deduplicated by object reference. Returns a deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Map<string, SourceNode>()\n for (const source of sources) {\n const key = sourceKey(source)\n if (!seen.has(key)) seen.set(key, source)\n }\n return [...seen.values()]\n}\n\n/**\n * Merges `incoming` names into `existing`, preserving order and dropping duplicates.\n *\n * Shared by `combineExports` and `combineImports` for the same-path name-merge case.\n */\nfunction mergeNameArrays<TName>(existing: Array<TName>, incoming: Array<TName>): Array<TName> {\n const merged = new Set(existing)\n for (const name of incoming) merged.add(name)\n return [...merged]\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects by path and type.\n *\n * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.\n * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n const result: Array<ExportNode> = []\n // Accumulates array-named exports keyed by `path:isTypeOnly` for name-merging\n const namedByPath = new Map<string, ExportNode>()\n // Deduplicates non-array exports by their exact identity\n const seen = new Set<string>()\n\n // Precompute sort keys once, avoids recomputing per comparison.\n const keyed = exports.map((node) => ({ node, key: sortKey(node) }))\n keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { node: curr } of keyed) {\n const { name, path, isTypeOnly, asAlias } = curr\n\n if (Array.isArray(name)) {\n if (!name.length) continue\n\n const key = pathTypeKey(path, isTypeOnly)\n const existing = namedByPath.get(key)\n\n if (existing && Array.isArray(existing.name)) {\n existing.name = mergeNameArrays(existing.name, name)\n } else {\n const newItem: ExportNode = { ...curr, name: [...new Set(name)] }\n result.push(newItem)\n namedByPath.set(key, newItem)\n }\n } else {\n const key = exportKey(path, name, isTypeOnly, asAlias)\n if (!seen.has(key)) {\n result.push(curr)\n seen.add(key)\n }\n }\n }\n\n return result\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports that are referenced in `source` or re-exported. Imports with the same path and\n * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.\n *\n * @note Use this when combining imports from multiple files to avoid duplicate declarations.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((e) => (Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])))\n const isUsed = (importName: string): boolean => !source || source.includes(importName) || exportedNames.has(importName)\n\n // Memoize object import names so the same logical (propertyName, name) pair always\n // reuses the same object reference. Set-based deduplication then works correctly.\n const importNameMemo = new Map<string, { propertyName: string; name?: string }>()\n const canonicalizeName = (n: string | { propertyName: string; name?: string }): string | { propertyName: string; name?: string } => {\n if (typeof n === 'string') return n\n const key = `${n.propertyName}:${n.name ?? ''}`\n if (!importNameMemo.has(key)) importNameMemo.set(key, n)\n return importNameMemo.get(key)!\n }\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set<string>()\n for (const node of imports) {\n if (!Array.isArray(node.name)) continue\n if (node.name.some((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))) {\n pathsWithUsedNamedImport.add(node.path)\n }\n }\n\n const result: Array<ImportNode> = []\n // Accumulates array-named imports keyed by `path:isTypeOnly` for name-merging\n const namedByPath = new Map<string, ImportNode>()\n // Deduplicates non-array imports by their exact identity\n const seen = new Set<string>()\n\n // Precompute sort keys once, avoids recomputing per comparison.\n const keyed = imports.map((node) => ({ node, key: sortKey(node) }))\n keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { node: curr } of keyed) {\n if (curr.path === curr.root) continue\n\n const { path, isTypeOnly } = curr\n let { name } = curr\n\n if (Array.isArray(name)) {\n name = [...new Set(name.map(canonicalizeName))].filter((item) => (typeof item === 'string' ? isUsed(item) : isUsed(item.name ?? item.propertyName)))\n if (!name.length) continue\n\n const key = pathTypeKey(path, isTypeOnly)\n const existing = namedByPath.get(key)\n\n if (existing && Array.isArray(existing.name)) {\n existing.name = mergeNameArrays(existing.name, name)\n } else {\n const newItem: ImportNode = { ...curr, name }\n result.push(newItem)\n namedByPath.set(key, newItem)\n }\n } else {\n if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue\n\n const key = importKey(path, name, isTypeOnly)\n if (!seen.has(key)) {\n result.push(curr)\n seen.add(key)\n }\n }\n }\n\n return result\n}\n\n/**\n * Extracts all string content from a `CodeNode` tree recursively.\n *\n * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),\n * and nested node content. Used internally to build the full source string for import filtering.\n */\nexport function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string {\n if (!nodes?.length) return ''\n return nodes\n .map((node) => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return node as string\n if (node.kind === 'Text') return node.value\n if (node.kind === 'Break') return ''\n if (node.kind === 'Jsx') return node.value\n\n const parts: Array<string> = []\n\n if ('params' in node && node.params) parts.push(node.params)\n if ('generics' in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(', ') : node.generics)\n if ('returnType' in node && node.returnType) parts.push(node.returnType)\n if ('type' in node && typeof node.type === 'string') parts.push(node.type)\n\n const nested = extractStringsFromNodes(node.nodes)\n\n if (nested) parts.push(nested)\n\n return parts.join('\\n')\n })\n .filter(Boolean)\n .join('\\n')\n}\n\n/**\n * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's\n * identifier for type definitions or error messages.\n *\n * @example\n * ```ts\n * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })\n * // => 'Pet'\n * ```\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Collects every named schema referenced (transitively) from a node via ref edges.\n *\n * Refs are followed by name only, the resolved `node.schema` is not traversed inline.\n * Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // → Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when any of its parameters, request body content, or responses\n * reference it, directly or indirectly through other named schemas.\n * The walk is iterative and safe against reference cycles.\n *\n * Use this together with `include` filters to determine which schemas from `components/schemas`\n * are reachable from the allowed operations, so that schemas used only by excluded operations\n * are not generated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter(op => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // … generate schema\n * }\n * ```\n *\n * @example Check whether a specific schema is needed\n * ```ts\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n * allowed.has('OrderStatus') // false when no included operation references OrderStatus\n * ```\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Identifies all schemas that participate in circular dependency chains, including direct self-loops.\n *\n * Returns a Set of schema names with circular dependencies. Use this to wrap recursive schema positions\n * in deferred constructs (lazy getter, `z.lazy(() => …)`) to prevent infinite recursion when generated code runs.\n * Refs are followed by name only, keeping the algorithm linear in the schema graph size.\n *\n * @note Call this once on the full schema graph, then use `containsCircularRef()` to check individual schemas.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Type guard returning `true` when a schema or anything nested within it contains a ref to a circular schema.\n *\n * Use `excludeName` to ignore refs to specific schemas (useful when self-references are handled separately).\n * Commonly used with `findCircularSchemas()` to detect where lazy wrappers are needed in code generation.\n *\n * @note Returns `true` for the first matching circular ref found. Use for fast dependency checks.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { FileNode, Node } from './nodes/index.ts'\nimport { combineExports, combineImports, combineSources, extractStringsFromNodes } from './utils/ast.ts'\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract, pair it with the\n * structural sharing in {@link transform} so a no-op rewrite doesn't allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is\n * shallow: a structurally-equal but newly-allocated array/object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n\n/**\n * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed\n * and `imports`/`exports`/`sources` are deduplicated.\n */\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const rawExtname = path.extname(input.baseName)\n // Handle dotfile basename like '.ts' where path.extname returns ''\n const extname = (rawExtname || (input.baseName.startsWith('.') ? input.baseName : '')) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const source = (input.sources ?? [])\n .flatMap((item) => item.nodes ?? [])\n .map((node) => extractStringsFromNodes([node]))\n .filter(Boolean)\n .join('\\n\\n')\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []\n const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name): name is string => Boolean(name)))\n const nameOf = (item: string | { propertyName: string; name?: string }): string => (typeof item === 'string' ? item : (item.name ?? item.propertyName))\n // Drop self-imports. Consolidating output (`mode: 'file'`) can place a symbol's\n // definition and a cross-file import of it in the same file. The first pass catches imports that\n // resolve to this file's own path. The second drops imports of names the file already defines,\n // the case consolidation produces when the import path no longer matches `input.path`. Sources\n // stay intact, so the local definition remains. Bare specifiers like `'zod'` never match a path.\n const resolvedImports = combinedImports\n .filter((imp) => imp.path !== input.path)\n .flatMap((imp) => {\n if (!Array.isArray(imp.name)) {\n return typeof imp.name === 'string' && localNames.has(imp.name) ? [] : [imp]\n }\n const kept = imp.name.filter((item) => !localNames.has(nameOf(item)))\n if (!kept.length) return []\n return [kept.length === imp.name.length ? imp : { ...imp, name: kept }]\n })\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n return {\n kind: 'File',\n ...input,\n id: hash('sha256', input.path, 'hex'),\n name: trimExtName(input.baseName),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: input.meta ?? ({} as TMeta),\n }\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Defines a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.\n **\n * @example\n * ```ts\n * export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(\n * (node) => kindToHandlerKey[node.kind],\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNodeByKey[K],\n ) => T['output'] | null\n }>\n print?: (\n this: {\n transform: (node: TNode) => T['output'] | null\n options: T['options']\n },\n node: TNode,\n ) => T['printOutput'] | null\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null\n print: (node: TNode) => T['printOutput'] | null\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null => {\n const key = getKey(node)\n if (key === null) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null,\n }\n }\n }\n}\n","import { isScalarPrimitive } from './constants.ts'\nimport { narrowSchema } from './guards.ts'\nimport { createProperty } from './nodes/property.ts'\nimport { createSchema, type SchemaNode } from './nodes/schema.ts'\nimport { enumPropName } from './utils/index.ts'\n\n/**\n * Replaces a discriminator property's schema with a string enum of allowed values.\n *\n * If `node` is not an object schema, or if the property does not exist, the input\n * node is returned as-is.\n *\n * @example\n * ```ts\n * const schema = createSchema({\n * type: 'object',\n * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],\n * })\n * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })\n * ```\n */\nexport function setDiscriminatorEnum({\n node,\n propertyName,\n values,\n enumName,\n}: {\n node: SchemaNode\n propertyName: string\n values: Array<string>\n enumName?: string\n}): SchemaNode {\n const objectNode = narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) {\n return node\n }\n\n const hasProperty = objectNode.properties.some((prop) => prop.name === propertyName)\n if (!hasProperty) {\n return node\n }\n\n return createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) {\n return prop\n }\n\n return createProperty({\n ...prop,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n}\n\n/**\n * Merges adjacent anonymous object members into a single anonymous object member.\n *\n * @example\n * ```ts\n * const merged = mergeAdjacentObjects([\n * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),\n * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),\n * ])\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n\nexport function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode> {\n return [...mergeAdjacentObjectsLazy(members)]\n}\n\n/**\n * Removes enum members that are covered by broader scalar primitives in the same union.\n *\n * @example\n * ```ts\n * const simplified = simplifyUnion([\n * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),\n * createSchema({ type: 'string' }),\n * ])\n * // keeps only string member\n * ```\n */\nexport function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode> {\n const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type))\n\n if (!scalarPrimitives.size) {\n return members\n }\n\n return members.filter((member) => {\n const enumNode = narrowSchema(member, 'enum')\n if (!enumNode) {\n return true\n }\n\n const primitive = enumNode.primitive\n if (!primitive) {\n return true\n }\n\n const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0\n if (enumValueCount <= 1) {\n return true\n }\n\n if (scalarPrimitives.has(primitive)) {\n return false\n }\n\n if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) {\n return false\n }\n\n return true\n })\n}\n\nexport function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode {\n const enumNode = narrowSchema(propNode, 'enum')\n\n if (enumNode?.primitive === 'boolean') {\n return { ...propNode, name: null }\n }\n\n if (enumNode) {\n return {\n ...propNode,\n name: enumPropName(parentName, propName, enumSuffix),\n }\n }\n\n return propNode\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,OAA2B,MAAgB;CACzD,QAAQ,SAA8B,KAAkB,SAAS;AACnE;;;;;;;;;;AAWA,SAAgB,gBAAgB,QAAoB,UAA+B;CACjF,MAAM,WAAW,OAAO,YAAY;CAEpC,OAAO;EACL,GAAG;EACH,UAAU,CAAC,YAAY,CAAC,WAAW,OAAO,KAAA;EAC1C,SAAS,CAAC,YAAY,WAAW,OAAO,KAAA;CAC1C;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,WACd,QACwB;CACxB,MAAM,EAAE,MAAM,UAAU,OAAO,UAAU,YAAY,YAAY;CAEjE,SAAS,OAAO,OAAsB;EACpC,MAAM,OAAO,QAAQ,MAAM,KAAK,IAAI;EACpC,OAAO;GAAE,GAAG;GAAU,GAAI;GAAiB;EAAK;CAClD;CAEA,O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