@kubb/ast 5.0.0-beta.27 → 5.0.0-beta.28

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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/constants.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/guards.ts","../src/refs.ts","../src/visitor.ts","../src/utils.ts","../src/factory.ts","../src/printer.ts","../src/resolvers.ts","../src/transformers.ts"],"sourcesContent":["import type { NodeKind } from './nodes/base.ts'\nimport type { MediaType } from './nodes/http.ts'\nimport type { HttpMethod } from './nodes/operation.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` — visits only the immediate node, skipping children.\n * - `'deep'` — recursively visits all descendant nodes.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\nexport const visitorDepths = {\n shallow: 'shallow',\n deep: 'deep',\n} as const satisfies Record<VisitorDepth, VisitorDepth>\n\nexport const nodeKinds = {\n input: 'Input',\n output: 'Output',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n functionParameter: 'FunctionParameter',\n parameterGroup: 'ParameterGroup',\n functionParameters: 'FunctionParameters',\n type: 'Type',\n file: 'File',\n import: 'Import',\n export: 'Export',\n source: 'Source',\n text: 'Text',\n break: 'Break',\n} as const satisfies Record<string, NodeKind>\n\n/**\n * Schema type discriminators used by all AST schema nodes.\n *\n * These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).\n * Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),\n * and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.\n */\nexport const schemaTypes = {\n /**\n * Text value.\n */\n string: 'string',\n /**\n * Floating-point number (`float`, `double`).\n */\n number: 'number',\n /**\n * Whole number (`int32`). Use `bigint` for `int64`.\n */\n integer: 'integer',\n /**\n * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.\n */\n bigint: 'bigint',\n /**\n * Boolean value\n */\n boolean: 'boolean',\n /**\n * Explicit null value.\n */\n null: 'null',\n /**\n * Any value (no type restriction).\n */\n any: 'any',\n /**\n * Unknown value (must be narrowed before usage).\n */\n unknown: 'unknown',\n /**\n * No return value (`void`).\n */\n void: 'void',\n /**\n * Object with named properties.\n */\n object: 'object',\n /**\n * Sequential list of items.\n */\n array: 'array',\n /**\n * Fixed-length list with position-specific items.\n */\n tuple: 'tuple',\n /**\n * \"One of\" multiple schema members.\n */\n union: 'union',\n /**\n * \"All of\" multiple schema members.\n */\n intersection: 'intersection',\n /**\n * Enum schema.\n */\n enum: 'enum',\n /**\n * Reference to another schema.\n */\n ref: 'ref',\n /**\n * Calendar date (for example `2026-03-24`).\n */\n date: 'date',\n /**\n * Date-time value (for example `2026-03-24T09:00:00Z`).\n */\n datetime: 'datetime',\n /**\n * Time-only value (for example `09:00:00`).\n */\n time: 'time',\n /**\n * UUID value.\n */\n uuid: 'uuid',\n /**\n * Email address value.\n */\n email: 'email',\n /**\n * URL value.\n */\n url: 'url',\n /**\n * IPv4 address value.\n */\n ipv4: 'ipv4',\n /**\n * IPv6 address value.\n */\n ipv6: 'ipv6',\n /**\n * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\nexport type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'\n\n/**\n * Scalar primitive schema types used for union simplification and type narrowing.\n *\n * Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.\n */\nexport const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])\n\n/**\n * Type guard that returns `true` when `type` is a scalar primitive schema type.\n *\n * Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).\n */\nexport function isScalarPrimitive(type: string): type is ScalarPrimitive {\n return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)\n}\n\n/**\n * HTTP method identifiers used by operation nodes.\n *\n * Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).\n */\nexport const httpMethods = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n head: 'HEAD',\n options: 'OPTIONS',\n trace: 'TRACE',\n} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>\n\n/**\n * Default concurrency limit for `walk()` traversal utility.\n *\n * Set to 30 to balance I/O-bound resolver parallelism against event loop pressure and memory usage during large spec traversals.\n * Use `WALK_CONCURRENCY` when calling `walk()` or override for different hardware constraints.\n *\n * @example\n * ```ts\n * import { walk, WALK_CONCURRENCY } from '@kubb/ast'\n *\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Common MIME types used in request/response content negotiation.\n *\n * Covers JSON, XML, form data, PDFs, images, audio, and video formats.\n * Use these as keys when serializing request/response bodies.\n */\nexport const mediaTypes = {\n applicationJson: 'application/json',\n applicationXml: 'application/xml',\n applicationFormUrlEncoded: 'application/x-www-form-urlencoded',\n applicationOctetStream: 'application/octet-stream',\n applicationPdf: 'application/pdf',\n applicationZip: 'application/zip',\n applicationGraphql: 'application/graphql',\n multipartFormData: 'multipart/form-data',\n textPlain: 'text/plain',\n textHtml: 'text/html',\n textCsv: 'text/csv',\n textXml: 'text/xml',\n imagePng: 'image/png',\n imageJpeg: 'image/jpeg',\n imageGif: 'image/gif',\n imageWebp: 'image/webp',\n imageSvgXml: 'image/svg+xml',\n audioMpeg: 'audio/mpeg',\n videoMp4: 'video/mp4',\n} as const satisfies Record<string, MediaType>\n","type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<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: readonly T[] | AsyncIterable<T>,\n process: (batch: 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: 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/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\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 fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\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\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\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 * 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: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type {\n FunctionParameterNode,\n FunctionParametersNode,\n InputNode,\n Node,\n NodeKind,\n OperationNode,\n OutputNode,\n ParameterGroupNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n SchemaNode,\n SchemaNodeByType,\n} 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 * 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\n/**\n * Returns `true` when the input is a `PropertyNode`.\n */\nexport const isPropertyNode = isKind<PropertyNode>('Property')\n\n/**\n * Returns `true` when the input is a `ParameterNode`.\n */\nexport const isParameterNode = isKind<ParameterNode>('Parameter')\n\n/**\n * Returns `true` when the input is a `ResponseNode`.\n */\nexport const isResponseNode = isKind<ResponseNode>('Response')\n\n/**\n * Returns `true` when the input is a `FunctionParameterNode`.\n */\nexport const isFunctionParameterNode = isKind<FunctionParameterNode>('FunctionParameter')\n\n/**\n * Returns `true` when the input is a `ParameterGroupNode`.\n */\nexport const isParameterGroupNode = isKind<ParameterGroupNode>('ParameterGroup')\n\n/**\n * Returns `true` when the input is a `FunctionParametersNode`.\n */\nexport const isFunctionParametersNode = isKind<FunctionParametersNode>('FunctionParameters')\n","import type { InputNode } from './nodes/root.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\n\n/**\n * Lookup map from schema name to `SchemaNode`.\n */\nexport type RefMap = Map<string, SchemaNode>\n\n/**\n * Returns the last path segment of a reference string.\n *\n * Example: `#/components/schemas/Pet` becomes `Pet`.\n *\n * @example\n * ```ts\n * extractRefName('#/components/schemas/Pet') // 'Pet'\n * ```\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Builds a `RefMap` from `input.schemas` using each schema's `name`.\n *\n * Unnamed schemas are skipped.\n *\n * @example\n * ```ts\n * const refMap = buildRefMap(input)\n * const pet = refMap.get('Pet')\n * ```\n */\nexport function buildRefMap(input: InputNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of input.schemas) {\n if (schema.name) {\n map.set(schema.name, schema)\n }\n }\n return map\n}\n\n/**\n * Resolves a schema by name from a `RefMap`.\n *\n * Returns `null` when the ref is not found.\n *\n * @example\n * ```ts\n * const petSchema = resolveRef(refMap, 'Pet')\n * ```\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | null {\n return refMap.get(ref) ?? null\n}\n\n/**\n * Converts a `RefMap` into a plain object.\n *\n * @example\n * ```ts\n * const refsObject = refMapToObject(refMap)\n * ```\n */\nexport function refMapToObject(refMap: RefMap): Record<string, SchemaNode> {\n return Object.fromEntries(refMap)\n}\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport { createParameter, createProperty } from './factory.ts'\nimport type { InputNode, Node, OperationNode, OutputNode, ParameterNode, PropertyNode, ResponseNode, SchemaNode } 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 [SchemaNode, InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode],\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 */\nexport type 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 */\nexport type 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 * Returns the immediate traversable children of `node`.\n *\n * For `Schema` nodes, children (`properties`, `items`, `members`, and non-boolean\n * `additionalProperties`) are only included\n * when `recurse` is `true`; shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, requestBody schema (if present), and responses\n * ```\n */\nfunction* getChildren(node: Node, recurse: boolean): Generator<Node, void, undefined> {\n if (node.kind === 'Input') {\n yield* node.schemas\n yield* node.operations\n\n return\n }\n if (node.kind === 'Output') return\n if (node.kind === 'Operation') {\n yield* node.parameters\n if (node.requestBody?.content) {\n for (const c of node.requestBody.content) {\n if (c.schema) yield c.schema\n }\n }\n yield* node.responses\n\n return\n }\n if (node.kind === 'Schema') {\n if (!recurse) return\n if ('properties' in node && node.properties.length > 0) yield* node.properties\n if ('items' in node && node.items) yield* node.items\n if ('members' in node && node.members) yield* node.members\n if ('additionalProperties' in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties\n\n return\n }\n if (node.kind === 'Property') {\n yield node.schema\n\n return\n }\n if (node.kind === 'Parameter') {\n yield node.schema\n\n return\n }\n if (node.kind === 'Response') {\n if (node.schema) yield node.schema\n return\n }\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 switch (node.kind) {\n case 'Input':\n await limit(() => visitor.input?.(node, { parent: parent as ParentOf<InputNode> }))\n break\n case 'Output':\n await limit(() => visitor.output?.(node, { parent: parent as ParentOf<OutputNode> }))\n break\n case 'Operation':\n await limit(() => visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> }))\n break\n case 'Schema':\n await limit(() => visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }))\n break\n case 'Property':\n await limit(() => visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }))\n break\n case 'Parameter':\n await limit(() => visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> }))\n break\n case 'Response':\n await limit(() => visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }))\n break\n }\n\n const children = getChildren(node, recurse)\n for (const child of children) {\n await _walk(child, visitor, recurse, limit, node)\n }\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 if (node.kind === 'Input') {\n const input = visitor.input?.(node, { parent: parent as ParentOf<InputNode> }) ?? node\n\n return {\n ...input,\n schemas: input.schemas.map((s) => transform(s, { ...options, parent: input })),\n operations: input.operations.map((op) => transform(op, { ...options, parent: input })),\n }\n }\n\n if (node.kind === 'Output') {\n return visitor.output?.(node, { parent: parent as ParentOf<OutputNode> }) ?? node\n }\n\n if (node.kind === 'Operation') {\n const op = visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> }) ?? node\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),\n requestBody: op.requestBody\n ? {\n ...op.requestBody,\n content: op.requestBody.content?.map((c) => ({\n ...c,\n schema: c.schema ? transform(c.schema, { ...options, parent: op }) : undefined,\n })),\n }\n : undefined,\n responses: op.responses.map((r) => transform(r, { ...options, parent: op })),\n }\n }\n\n if (node.kind === 'Schema') {\n const schema = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }) ?? node\n\n const childOptions = { ...options, parent: schema }\n\n return {\n ...schema,\n ...('properties' in schema && recurse\n ? {\n properties: schema.properties.map((p) => transform(p, childOptions)),\n }\n : {}),\n ...('items' in schema && recurse ? { items: schema.items?.map((i) => transform(i, childOptions)) } : {}),\n ...('members' in schema && recurse ? { members: schema.members?.map((m) => transform(m, childOptions)) } : {}),\n ...('additionalProperties' in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true\n ? {\n additionalProperties: transform(schema.additionalProperties, childOptions),\n }\n : {}),\n } as SchemaNode\n }\n\n if (node.kind === 'Property') {\n const prop = visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }) ?? node\n\n return createProperty({\n ...prop,\n schema: transform(prop.schema, { ...options, parent: prop }),\n })\n }\n\n if (node.kind === 'Parameter') {\n const param = visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> }) ?? node\n\n return createParameter({\n ...param,\n schema: transform(param.schema, { ...options, parent: param }),\n })\n }\n\n if (node.kind === 'Response') {\n const response = visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }) ?? node\n\n return {\n ...response,\n schema: transform(response.schema, { ...options, parent: response }),\n }\n }\n\n return 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 let v: T | null | undefined\n switch (node.kind) {\n case 'Input':\n v = visitor.input?.(node, { parent: parent as ParentOf<InputNode> })\n break\n case 'Output':\n v = visitor.output?.(node, { parent: parent as ParentOf<OutputNode> })\n break\n case 'Operation':\n v = visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> })\n break\n case 'Schema':\n v = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> })\n break\n case 'Property':\n v = visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> })\n break\n case 'Parameter':\n v = visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> })\n break\n case 'Response':\n v = visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> })\n break\n }\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 './refs.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 */\nexport type 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].sort().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 * 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 const merged = new Set(existing.name)\n for (const n of name) merged.add(n)\n existing.name = [...merged]\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 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 const merged = new Set(existing.name)\n for (const n of name) merged.add(n)\n existing.name = [...merged]\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)) 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 { createHash } 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 ExportNode,\n FileNode,\n FunctionNode,\n FunctionParameterNode,\n FunctionParametersNode,\n ImportNode,\n InputMeta,\n InputNode,\n InputStreamNode,\n JsxNode,\n ObjectSchemaNode,\n OperationNode,\n OutputNode,\n ParameterGroupNode,\n ParameterNode,\n ParamsTypeNode,\n PrimitiveSchemaType,\n PropertyNode,\n ResponseNode,\n SchemaNode,\n SourceNode,\n TextNode,\n TypeNode,\n} from './nodes/index.ts'\nimport { combineExports, combineImports, combineSources, extractStringsFromNodes } from './utils.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\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 an `InputStreamNode` 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): InputStreamNode {\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 */\nexport function createOperation(\n props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>,\n): OperationNode {\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...props,\n kind: 'Operation',\n }\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 * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * description: 'Success',\n * schema: createSchema({ type: 'object', properties: [] }),\n * })\n * ```\n */\nexport function createResponse(\n props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>,\n): ResponseNode {\n return {\n ...props,\n kind: 'Response',\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 resolvedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n return {\n kind: 'File',\n ...input,\n id: createHash('sha256').update(input.path).digest('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 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 */\nexport type 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 */\nexport type 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 { pascalCase } from '@internals/utils'\nimport { narrowSchema } from './guards.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { extractRefName } from './refs.ts'\nimport { collect } from './visitor.ts'\n\nexport function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null {\n if (!mapping || !ref) return null\n return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null\n}\n\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Collects import entries for all `ref` schema nodes in `node`.\n */\nexport function collectImports<TImport>({\n node,\n nameMapping,\n resolve,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolve: (schemaName: string) => TImport | null\n}): Array<TImport> {\n return collect<TImport>(node, {\n schema(schemaNode): TImport | null {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n if (!schemaRef?.ref) return null\n\n const rawName = extractRefName(schemaRef.ref)\n const schemaName = nameMapping.get(rawName) ?? rawName\n const result = resolve(schemaName)\n if (!result) return null\n\n return result\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 './resolvers.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":";;;;AAaA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,OAAO;CACP,QAAQ;CACR,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;CACV,mBAAmB;CACnB,gBAAgB;CAChB,oBAAoB;CACpB,MAAM;CACN,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,OAAO;CACR;;;;;;;;AASD,MAAa,cAAc;;;;CAIzB,QAAQ;;;;CAIR,QAAQ;;;;CAIR,SAAS;;;;CAIT,QAAQ;;;;CAIR,SAAS;;;;CAIT,MAAM;;;;CAIN,KAAK;;;;CAIL,SAAS;;;;CAIT,MAAM;;;;CAIN,QAAQ;;;;CAIR,OAAO;;;;CAIP,OAAO;;;;CAIP,OAAO;;;;CAIP,cAAc;;;;CAId,MAAM;;;;CAIN,KAAK;;;;CAIL,MAAM;;;;CAIN,UAAU;;;;CAIV,MAAM;;;;CAIN,MAAM;;;;CAIN,OAAO;;;;CAIP,KAAK;;;;CAIL,MAAM;;;;CAIN,MAAM;;;;CAIN,MAAM;;;;CAIN,OAAO;CACR;;;;;;AASD,MAAa,yBAAyB,IAAI,IAAqB;CAAC;CAAU;CAAU;CAAW;CAAU;CAAU,CAAC;;;;;;AAOpH,SAAgB,kBAAkB,MAAuC;CACvE,OAAO,uBAAuB,IAAI,KAAwB;;;;;;;AAQ5D,MAAa,cAAc;CACzB,KAAK;CACL,MAAM;CACN,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CAC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Q,WAAW,kBAAkB,OAAO,KAAK,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK,CAAC;CAE/G,IAAI,CAAC,iBAAiB,MACpB,OAAO;CAGT,OAAO,QAAQ,QAAQ,WAAW;EAChC,MAAM,WAAW,aAAa,QAAQ,OAAO;EAC7C,IAAI,CAAC,UACH,OAAO;EAGT,MAAM,YAAY,SAAS;EAC3B,IAAI,CAAC,WACH,OAAO;EAIT,KADuB,SAAS,iBAAiB,UAAU,SAAS,YAAY,UAAU,MACpE,GACpB,OAAO;EAGT,IAAI,iBAAiB,IAAI,UAAU,EACjC,OAAO;EAGT,KAAK,cAAc,aAAa,cAAc,cAAc,iBAAiB,IAAI,UAAU,IAAI,iBAAiB,IAAI,SAAS,GAC3H,OAAO;EAGT,OAAO;GACP;;AAGJ,SAAgB,YAAY,UAAsB,YAAuC,UAAkB,YAAgC;CACzI,MAAM,WAAW,aAAa,UAAU,OAAO;CAE/C,IAAI,UAAU,cAAc,WAC1B,OAAO;EAAE,GAAG;EAAU,MAAM;EAAM;CAGpC,IAAI,UACF,OAAO;EACL,GAAG;EACH,MAAM,aAAa,YAAY,UAAU,WAAW;EACrD;CAGH,OAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/constants.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/guards.ts","../src/refs.ts","../src/visitor.ts","../src/utils.ts","../src/factory.ts","../src/printer.ts","../src/resolvers.ts","../src/transformers.ts"],"sourcesContent":["import type { NodeKind } from './nodes/base.ts'\nimport type { MediaType } from './nodes/http.ts'\nimport type { HttpMethod } from './nodes/operation.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` — visits only the immediate node, skipping children.\n * - `'deep'` — recursively visits all descendant nodes.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\nexport const visitorDepths = {\n shallow: 'shallow',\n deep: 'deep',\n} as const satisfies Record<VisitorDepth, VisitorDepth>\n\nexport const nodeKinds = {\n input: 'Input',\n output: 'Output',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n functionParameter: 'FunctionParameter',\n parameterGroup: 'ParameterGroup',\n functionParameters: 'FunctionParameters',\n type: 'Type',\n file: 'File',\n import: 'Import',\n export: 'Export',\n source: 'Source',\n text: 'Text',\n break: 'Break',\n} as const satisfies Record<string, NodeKind>\n\n/**\n * Schema type discriminators used by all AST schema nodes.\n *\n * These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).\n * Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),\n * and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.\n */\nexport const schemaTypes = {\n /**\n * Text value.\n */\n string: 'string',\n /**\n * Floating-point number (`float`, `double`).\n */\n number: 'number',\n /**\n * Whole number (`int32`). Use `bigint` for `int64`.\n */\n integer: 'integer',\n /**\n * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.\n */\n bigint: 'bigint',\n /**\n * Boolean value\n */\n boolean: 'boolean',\n /**\n * Explicit null value.\n */\n null: 'null',\n /**\n * Any value (no type restriction).\n */\n any: 'any',\n /**\n * Unknown value (must be narrowed before usage).\n */\n unknown: 'unknown',\n /**\n * No return value (`void`).\n */\n void: 'void',\n /**\n * Object with named properties.\n */\n object: 'object',\n /**\n * Sequential list of items.\n */\n array: 'array',\n /**\n * Fixed-length list with position-specific items.\n */\n tuple: 'tuple',\n /**\n * \"One of\" multiple schema members.\n */\n union: 'union',\n /**\n * \"All of\" multiple schema members.\n */\n intersection: 'intersection',\n /**\n * Enum schema.\n */\n enum: 'enum',\n /**\n * Reference to another schema.\n */\n ref: 'ref',\n /**\n * Calendar date (for example `2026-03-24`).\n */\n date: 'date',\n /**\n * Date-time value (for example `2026-03-24T09:00:00Z`).\n */\n datetime: 'datetime',\n /**\n * Time-only value (for example `09:00:00`).\n */\n time: 'time',\n /**\n * UUID value.\n */\n uuid: 'uuid',\n /**\n * Email address value.\n */\n email: 'email',\n /**\n * URL value.\n */\n url: 'url',\n /**\n * IPv4 address value.\n */\n ipv4: 'ipv4',\n /**\n * IPv6 address value.\n */\n ipv6: 'ipv6',\n /**\n * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\nexport type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'\n\n/**\n * Scalar primitive schema types used for union simplification and type narrowing.\n *\n * Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.\n */\nexport const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])\n\n/**\n * Type guard that returns `true` when `type` is a scalar primitive schema type.\n *\n * Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).\n */\nexport function isScalarPrimitive(type: string): type is ScalarPrimitive {\n return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)\n}\n\n/**\n * HTTP method identifiers used by operation nodes.\n *\n * Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).\n */\nexport const httpMethods = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n head: 'HEAD',\n options: 'OPTIONS',\n trace: 'TRACE',\n} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>\n\n/**\n * Default concurrency limit for `walk()` traversal utility.\n *\n * Set to 30 to balance I/O-bound resolver parallelism against event loop pressure and memory usage during large spec traversals.\n * Use `WALK_CONCURRENCY` when calling `walk()` or override for different hardware constraints.\n *\n * @example\n * ```ts\n * import { walk, WALK_CONCURRENCY } from '@kubb/ast'\n *\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Common MIME types used in request/response content negotiation.\n *\n * Covers JSON, XML, form data, PDFs, images, audio, and video formats.\n * Use these as keys when serializing request/response bodies.\n */\nexport const mediaTypes = {\n applicationJson: 'application/json',\n applicationXml: 'application/xml',\n applicationFormUrlEncoded: 'application/x-www-form-urlencoded',\n applicationOctetStream: 'application/octet-stream',\n applicationPdf: 'application/pdf',\n applicationZip: 'application/zip',\n applicationGraphql: 'application/graphql',\n multipartFormData: 'multipart/form-data',\n textPlain: 'text/plain',\n textHtml: 'text/html',\n textCsv: 'text/csv',\n textXml: 'text/xml',\n imagePng: 'image/png',\n imageJpeg: 'image/jpeg',\n imageGif: 'image/gif',\n imageWebp: 'image/webp',\n imageSvgXml: 'image/svg+xml',\n audioMpeg: 'audio/mpeg',\n videoMp4: 'video/mp4',\n} as const satisfies Record<string, MediaType>\n","type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<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: readonly T[] | AsyncIterable<T>,\n process: (batch: 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: 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/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\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 fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\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\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\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 * 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: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\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","import type {\n FunctionParameterNode,\n FunctionParametersNode,\n InputNode,\n Node,\n NodeKind,\n OperationNode,\n OutputNode,\n ParameterGroupNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n SchemaNode,\n SchemaNodeByType,\n} 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 * 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\n/**\n * Returns `true` when the input is a `PropertyNode`.\n */\nexport const isPropertyNode = isKind<PropertyNode>('Property')\n\n/**\n * Returns `true` when the input is a `ParameterNode`.\n */\nexport const isParameterNode = isKind<ParameterNode>('Parameter')\n\n/**\n * Returns `true` when the input is a `ResponseNode`.\n */\nexport const isResponseNode = isKind<ResponseNode>('Response')\n\n/**\n * Returns `true` when the input is a `FunctionParameterNode`.\n */\nexport const isFunctionParameterNode = isKind<FunctionParameterNode>('FunctionParameter')\n\n/**\n * Returns `true` when the input is a `ParameterGroupNode`.\n */\nexport const isParameterGroupNode = isKind<ParameterGroupNode>('ParameterGroup')\n\n/**\n * Returns `true` when the input is a `FunctionParametersNode`.\n */\nexport const isFunctionParametersNode = isKind<FunctionParametersNode>('FunctionParameters')\n","import type { InputNode } from './nodes/root.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\n\n/**\n * Lookup map from schema name to `SchemaNode`.\n */\nexport type RefMap = Map<string, SchemaNode>\n\n/**\n * Returns the last path segment of a reference string.\n *\n * Example: `#/components/schemas/Pet` becomes `Pet`.\n *\n * @example\n * ```ts\n * extractRefName('#/components/schemas/Pet') // 'Pet'\n * ```\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Builds a `RefMap` from `input.schemas` using each schema's `name`.\n *\n * Unnamed schemas are skipped.\n *\n * @example\n * ```ts\n * const refMap = buildRefMap(input)\n * const pet = refMap.get('Pet')\n * ```\n */\nexport function buildRefMap(input: InputNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of input.schemas) {\n if (schema.name) {\n map.set(schema.name, schema)\n }\n }\n return map\n}\n\n/**\n * Resolves a schema by name from a `RefMap`.\n *\n * Returns `null` when the ref is not found.\n *\n * @example\n * ```ts\n * const petSchema = resolveRef(refMap, 'Pet')\n * ```\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | null {\n return refMap.get(ref) ?? null\n}\n\n/**\n * Converts a `RefMap` into a plain object.\n *\n * @example\n * ```ts\n * const refsObject = refMapToObject(refMap)\n * ```\n */\nexport function refMapToObject(refMap: RefMap): Record<string, SchemaNode> {\n return Object.fromEntries(refMap)\n}\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport { createParameter, createProperty } from './factory.ts'\nimport type { InputNode, Node, OperationNode, OutputNode, ParameterNode, PropertyNode, ResponseNode, SchemaNode } 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 [SchemaNode, InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode],\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 */\nexport type 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 */\nexport type 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 * Returns the immediate traversable children of `node`.\n *\n * For `Schema` nodes, children (`properties`, `items`, `members`, and non-boolean\n * `additionalProperties`) are only included\n * when `recurse` is `true`; shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, requestBody schema (if present), and responses\n * ```\n */\nfunction* getChildren(node: Node, recurse: boolean): Generator<Node, void, undefined> {\n if (node.kind === 'Input') {\n yield* node.schemas\n yield* node.operations\n\n return\n }\n if (node.kind === 'Output') return\n if (node.kind === 'Operation') {\n yield* node.parameters\n if (node.requestBody?.content) {\n for (const c of node.requestBody.content) {\n if (c.schema) yield c.schema\n }\n }\n yield* node.responses\n\n return\n }\n if (node.kind === 'Schema') {\n if (!recurse) return\n if ('properties' in node && node.properties.length > 0) yield* node.properties\n if ('items' in node && node.items) yield* node.items\n if ('members' in node && node.members) yield* node.members\n if ('additionalProperties' in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties\n\n return\n }\n if (node.kind === 'Property') {\n yield node.schema\n\n return\n }\n if (node.kind === 'Parameter') {\n yield node.schema\n\n return\n }\n if (node.kind === 'Response') {\n if (node.schema) yield node.schema\n return\n }\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 switch (node.kind) {\n case 'Input':\n await limit(() => visitor.input?.(node, { parent: parent as ParentOf<InputNode> }))\n break\n case 'Output':\n await limit(() => visitor.output?.(node, { parent: parent as ParentOf<OutputNode> }))\n break\n case 'Operation':\n await limit(() => visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> }))\n break\n case 'Schema':\n await limit(() => visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }))\n break\n case 'Property':\n await limit(() => visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }))\n break\n case 'Parameter':\n await limit(() => visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> }))\n break\n case 'Response':\n await limit(() => visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }))\n break\n }\n\n const children = getChildren(node, recurse)\n for (const child of children) {\n await _walk(child, visitor, recurse, limit, node)\n }\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 if (node.kind === 'Input') {\n const input = visitor.input?.(node, { parent: parent as ParentOf<InputNode> }) ?? node\n\n return {\n ...input,\n schemas: input.schemas.map((s) => transform(s, { ...options, parent: input })),\n operations: input.operations.map((op) => transform(op, { ...options, parent: input })),\n }\n }\n\n if (node.kind === 'Output') {\n return visitor.output?.(node, { parent: parent as ParentOf<OutputNode> }) ?? node\n }\n\n if (node.kind === 'Operation') {\n const op = visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> }) ?? node\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),\n requestBody: op.requestBody\n ? {\n ...op.requestBody,\n content: op.requestBody.content?.map((c) => ({\n ...c,\n schema: c.schema ? transform(c.schema, { ...options, parent: op }) : undefined,\n })),\n }\n : undefined,\n responses: op.responses.map((r) => transform(r, { ...options, parent: op })),\n }\n }\n\n if (node.kind === 'Schema') {\n const schema = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }) ?? node\n\n const childOptions = { ...options, parent: schema }\n\n return {\n ...schema,\n ...('properties' in schema && recurse\n ? {\n properties: schema.properties.map((p) => transform(p, childOptions)),\n }\n : {}),\n ...('items' in schema && recurse ? { items: schema.items?.map((i) => transform(i, childOptions)) } : {}),\n ...('members' in schema && recurse ? { members: schema.members?.map((m) => transform(m, childOptions)) } : {}),\n ...('additionalProperties' in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true\n ? {\n additionalProperties: transform(schema.additionalProperties, childOptions),\n }\n : {}),\n } as SchemaNode\n }\n\n if (node.kind === 'Property') {\n const prop = visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }) ?? node\n\n return createProperty({\n ...prop,\n schema: transform(prop.schema, { ...options, parent: prop }),\n })\n }\n\n if (node.kind === 'Parameter') {\n const param = visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> }) ?? node\n\n return createParameter({\n ...param,\n schema: transform(param.schema, { ...options, parent: param }),\n })\n }\n\n if (node.kind === 'Response') {\n const response = visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }) ?? node\n\n return {\n ...response,\n schema: transform(response.schema, { ...options, parent: response }),\n }\n }\n\n return 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 let v: T | null | undefined\n switch (node.kind) {\n case 'Input':\n v = visitor.input?.(node, { parent: parent as ParentOf<InputNode> })\n break\n case 'Output':\n v = visitor.output?.(node, { parent: parent as ParentOf<OutputNode> })\n break\n case 'Operation':\n v = visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> })\n break\n case 'Schema':\n v = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> })\n break\n case 'Property':\n v = visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> })\n break\n case 'Parameter':\n v = visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> })\n break\n case 'Response':\n v = visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> })\n break\n }\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 './refs.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 */\nexport type 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].sort().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 * 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 const merged = new Set(existing.name)\n for (const n of name) merged.add(n)\n existing.name = [...merged]\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 const merged = new Set(existing.name)\n for (const n of name) merged.add(n)\n existing.name = [...merged]\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 { createHash } 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 ExportNode,\n FileNode,\n FunctionNode,\n FunctionParameterNode,\n FunctionParametersNode,\n ImportNode,\n InputMeta,\n InputNode,\n InputStreamNode,\n JsxNode,\n ObjectSchemaNode,\n OperationNode,\n OutputNode,\n ParameterGroupNode,\n ParameterNode,\n ParamsTypeNode,\n PrimitiveSchemaType,\n PropertyNode,\n ResponseNode,\n SchemaNode,\n SourceNode,\n TextNode,\n TypeNode,\n} from './nodes/index.ts'\nimport { combineExports, combineImports, combineSources, extractStringsFromNodes } from './utils.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\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 an `InputStreamNode` 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): InputStreamNode {\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 */\nexport function createOperation(\n props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>,\n): OperationNode {\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...props,\n kind: 'Operation',\n }\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 * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * description: 'Success',\n * schema: createSchema({ type: 'object', properties: [] }),\n * })\n * ```\n */\nexport function createResponse(\n props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>,\n): ResponseNode {\n return {\n ...props,\n kind: 'Response',\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 resolvedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n return {\n kind: 'File',\n ...input,\n id: createHash('sha256').update(input.path).digest('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 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 */\nexport type 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 */\nexport type 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 { pascalCase } from '@internals/utils'\nimport { narrowSchema } from './guards.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { extractRefName } from './refs.ts'\nimport { collect } from './visitor.ts'\n\nexport function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null {\n if (!mapping || !ref) return null\n return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null\n}\n\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Collects import entries for all `ref` schema nodes in `node`.\n */\nexport function collectImports<TImport>({\n node,\n nameMapping,\n resolve,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolve: (schemaName: string) => TImport | null\n}): Array<TImport> {\n return collect<TImport>(node, {\n schema(schemaNode): TImport | null {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n if (!schemaRef?.ref) return null\n\n const rawName = extractRefName(schemaRef.ref)\n const schemaName = nameMapping.get(rawName) ?? rawName\n const result = resolve(schemaName)\n if (!result) return null\n\n return result\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 './resolvers.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":";;;;AAaA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,OAAO;CACP,Q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