@kubb/ast 5.0.0-alpha.20 → 5.0.0-alpha.22
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.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{visitor-DCQyoFvH.d.ts → visitor-COwfCgLK.d.ts} +17 -10
- package/package.json +1 -1
- package/src/printers/functionPrinter.ts +4 -4
- package/src/printers/printer.ts +27 -14
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
Object.defineProperty;
|
|
3
2
|
//#endregion
|
|
4
3
|
//#region src/constants.ts
|
|
5
4
|
const visitorDepths = {
|
|
@@ -594,10 +593,10 @@ function createFunctionParameters(props = {}) {
|
|
|
594
593
|
* - `options` — options stored on the returned printer instance
|
|
595
594
|
* - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`
|
|
596
595
|
* - `print` _(optional)_ — top-level override exposed as `printer.print`
|
|
597
|
-
* - Inside this function, `this.
|
|
596
|
+
* - Inside this function, use `this.transform(node)` to dispatch to the `nodes` map
|
|
598
597
|
* - This keeps recursion safe and avoids self-calls
|
|
599
598
|
*
|
|
600
|
-
* When no `print` override is provided, `printer.print`
|
|
599
|
+
* When no `print` override is provided, `printer.print` falls back to `printer.transform` (the node-level dispatcher).
|
|
601
600
|
*
|
|
602
601
|
* @example Basic usage — Zod schema printer
|
|
603
602
|
* ```ts
|
|
@@ -609,7 +608,7 @@ function createFunctionParameters(props = {}) {
|
|
|
609
608
|
* nodes: {
|
|
610
609
|
* string: () => 'z.string()',
|
|
611
610
|
* object(node) {
|
|
612
|
-
* const props = node.properties.map(p => `${p.name}: ${this.
|
|
611
|
+
* const props = node.properties.map(p => `${p.name}: ${this.transform(p.schema)}`).join(', ')
|
|
613
612
|
* return `z.object({ ${props} })`
|
|
614
613
|
* },
|
|
615
614
|
* },
|
|
@@ -635,7 +634,7 @@ function createPrinterFactory(getKey) {
|
|
|
635
634
|
const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? {});
|
|
636
635
|
const context = {
|
|
637
636
|
options: resolvedOptions,
|
|
638
|
-
|
|
637
|
+
transform: (node) => {
|
|
639
638
|
const key = getKey(node);
|
|
640
639
|
if (key === void 0) return null;
|
|
641
640
|
const handler = nodes[key];
|
|
@@ -646,7 +645,8 @@ function createPrinterFactory(getKey) {
|
|
|
646
645
|
return {
|
|
647
646
|
name,
|
|
648
647
|
options: resolvedOptions,
|
|
649
|
-
|
|
648
|
+
transform: context.transform,
|
|
649
|
+
print: printOverride ? printOverride.bind(context) : context.transform
|
|
650
650
|
};
|
|
651
651
|
};
|
|
652
652
|
};
|
|
@@ -676,11 +676,11 @@ const kindToHandlerKey = {
|
|
|
676
676
|
* return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name
|
|
677
677
|
* },
|
|
678
678
|
* objectBindingParameter(node) {
|
|
679
|
-
* const inner = node.properties.map(p => this.
|
|
679
|
+
* const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
680
680
|
* return `{ ${inner} }`
|
|
681
681
|
* },
|
|
682
682
|
* functionParameters(node) {
|
|
683
|
-
* return node.params.map(p => this.
|
|
683
|
+
* return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
684
684
|
* },
|
|
685
685
|
* },
|
|
686
686
|
* }))
|
|
@@ -741,7 +741,7 @@ const functionPrinter = defineFunctionPrinter((options) => ({
|
|
|
741
741
|
const { mode, transformName, transformType } = this.options;
|
|
742
742
|
const sorted = sortChildParams(node.properties);
|
|
743
743
|
const isOptional = node.optional ?? sorted.every((p) => p.optional || p.default !== void 0);
|
|
744
|
-
if (node.inline) return sorted.map((p) => this.
|
|
744
|
+
if (node.inline) return sorted.map((p) => this.transform(p)).filter(Boolean).join(", ");
|
|
745
745
|
if (mode === "keys" || mode === "values") return `{ ${sorted.map((p) => p.name).join(", ")} }`;
|
|
746
746
|
if (mode === "call") return `{ ${sorted.map((p) => p.name).join(", ")} }`;
|
|
747
747
|
const names = sorted.map((p) => {
|
|
@@ -764,7 +764,7 @@ const functionPrinter = defineFunctionPrinter((options) => ({
|
|
|
764
764
|
return node.default ? `${nameStr} = ${node.default}` : nameStr;
|
|
765
765
|
},
|
|
766
766
|
functionParameters(node) {
|
|
767
|
-
return sortParams(node.params).map((p) => this.
|
|
767
|
+
return sortParams(node.params).map((p) => this.transform(p)).filter(Boolean).join(", ");
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
770
|
}));
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/guards.ts","../src/utils.ts","../src/factory.ts","../src/printers/printer.ts","../src/printers/functionPrinter.ts","../src/refs.ts","../src/visitor.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 { ParameterLocation } from './nodes/parameter.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth used by AST visitor utilities.\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 root: 'Root',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n functionParameter: 'FunctionParameter',\n objectBindingParameter: 'ObjectBindingParameter',\n functionParameters: 'FunctionParameters',\n} as const satisfies Record<string, NodeKind>\n\n/**\n * Canonical schema type strings used by AST schema nodes.\n *\n * These values are used across the AST as stable discriminators\n * (for example `schema.type === schemaTypes.object`).\n *\n * The map is grouped by intent:\n * - primitives (`string`, `number`, `boolean`, ...)\n * - structural/composite (`object`, `array`, `union`, ...)\n * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)\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 * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\n/**\n * Primitive scalar schema types used when simplifying union members.\n */\nexport const SCALAR_PRIMITIVE_TYPES = new Set(['string', 'number', 'integer', 'bigint', 'boolean'] as const)\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\nexport const parameterLocations = {\n path: 'path',\n query: 'query',\n header: 'header',\n cookie: 'cookie',\n} as const satisfies Record<ParameterLocation, ParameterLocation>\n\n/**\n * Default maximum number of concurrent callbacks used by `walk`.\n *\n * @example\n * ```ts\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Fallback response status code used for catch-all responses.\n *\n * @example\n * ```ts\n * const status = DEFAULT_STATUS_CODE // 'default'\n * ```\n */\nexport const DEFAULT_STATUS_CODE = 'default' as const\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 */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).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\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\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 try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import type {\n FunctionParameterNode,\n FunctionParametersNode,\n Node,\n NodeKind,\n ObjectBindingParameterNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\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 | undefined\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined {\n return node?.type === type ? (node as SchemaNodeByType[T]) : undefined\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 a `RootNode`.\n *\n * @example\n * ```ts\n * if (isRootNode(node)) {\n * console.log(node.schemas.length)\n * }\n * ```\n */\nexport const isRootNode = isKind<RootNode>('Root')\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 an `ObjectBindingParameterNode`.\n */\nexport const isObjectBindingParameterNode = isKind<ObjectBindingParameterNode>('ObjectBindingParameter')\n\n/**\n * Returns `true` when the input is a `FunctionParametersNode`.\n */\nexport const isFunctionParametersNode = isKind<FunctionParametersNode>('FunctionParameters')\n","import { camelCase, isValidVarName } from '@internals/utils'\n\nimport { narrowSchema } from './guards.ts'\nimport type { ParameterNode, SchemaNode } from './nodes/index.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns `true` when a schema is emitted as a plain TypeScript `string`.\n *\n * - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.\n * - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.\n *\n * @example\n * ```ts\n * isStringType(createSchema({ type: 'uuid' })) // true\n * isStringType(createSchema({ type: 'date', representation: 'date' })) // false\n * ```\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 * The input array is not mutated.\n * If `casing` is not set, the original array is returned unchanged.\n *\n * Use this before passing parameters to schema builders so that property keys\n * in generated output match the desired casing while preserving\n * `OperationNode.parameters` for other consumers.\n *\n * @example\n * ```ts\n * const params = [createParameter({ name: 'pet_id', in: 'query', schema: createSchema({ type: 'string' }) })]\n * const cased = caseParams(params, 'camelcase')\n * // cased[0].name === 'petId'\n * ```\n */\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) {\n return params\n }\n\n return params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n\n return { ...param, name: transformed }\n })\n}\n\n/**\n * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.\n *\n * - `optional` is set for non-required, non-nullable schemas.\n * - `nullish` is set for non-required, nullable schemas.\n */\nexport function syncOptionality(required: boolean, schema: SchemaNode): 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","import type { InferSchemaNode } from './infer.ts'\nimport type {\n FunctionParameterNode,\n FunctionParametersNode,\n ObjectBindingParameterNode,\n ObjectSchemaNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\n SchemaNode,\n} from './nodes/index.ts'\nimport { syncOptionality } from './utils.ts'\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'> & { properties?: Array<PropertyNode> }\ntype CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>\ntype CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & { kind: 'Schema' }\n\n/**\n * Creates a `RootNode` with stable defaults for `schemas` and `operations`.\n *\n * @example\n * ```ts\n * const root = createRoot()\n * // { kind: 'Root', schemas: [], operations: [] }\n * ```\n *\n * @example\n * ```ts\n * const root = createRoot({ schemas: [petSchema] })\n * // keeps default operations: []\n * ```\n */\nexport function createRoot(overrides: Partial<Omit<RootNode, 'kind'>> = {}): RootNode {\n return {\n schemas: [],\n operations: [],\n ...overrides,\n kind: 'Root',\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 * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n * For object schemas, `properties` defaults to an empty array.\n *\n * @example\n * ```ts\n * const scalar = createSchema({ type: 'string' })\n * // { kind: 'Schema', type: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const object = createSchema({ type: 'object' })\n * // { kind: 'Schema', type: '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 if (props['type'] === 'object') {\n return { properties: [], ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n }\n\n return { ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n}\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: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode {\n const required = props.required ?? false\n\n return {\n ...props,\n kind: 'Property',\n required,\n schema: syncOptionality(required, props.schema),\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(required, props.schema),\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 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 * Creates a `FunctionParameterNode`.\n *\n * `optional` defaults to `false`.\n *\n * @example Required typed param\n * ```ts\n * createFunctionParameter({ name: 'petId', type: 'string' })\n * // → petId: string\n * ```\n *\n * @example Optional param\n * ```ts\n * createFunctionParameter({ name: 'params', type: '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: 'RequestConfig', default: '{}' })\n * // → config: RequestConfig = {}\n * ```\n */\nexport function createFunctionParameter(\n props: { name: string; type?: string; 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 an `ObjectBindingParameterNode` for object-destructured parameter groups.\n *\n * @example Destructured object param\n * ```ts\n * createObjectBindingParameter({\n * properties: [\n * createFunctionParameter({ name: 'id', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'name', type: 'string', optional: true }),\n * ],\n * default: '{}',\n * })\n * // declaration → { id, name? }: { id: string; name?: string } = {}\n * // call → { id, name }\n * ```\n *\n * @example Inline mode — children emitted as individual top-level parameters\n * ```ts\n * createObjectBindingParameter({\n * properties: [createFunctionParameter({ name: 'petId', type: 'string', optional: false })],\n * inline: true,\n * })\n * // declaration → petId: string\n * // call → petId\n * ```\n */\nexport function createObjectBindingParameter(\n props: Pick<ObjectBindingParameterNode, 'properties'> & Partial<Omit<ObjectBindingParameterNode, 'kind' | 'properties'>>,\n): ObjectBindingParameterNode {\n return {\n ...props,\n kind: 'ObjectBindingParameter',\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: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: '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","import type { SchemaNode, SchemaNodeByType, SchemaType } from '../nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.print` always dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * print: () => 'value',\n * }\n * ```\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively print a nested `SchemaNode` using the node-level handlers.\n */\n print: (node: SchemaNode) => TOutput | null | undefined\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 | undefined\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 * 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 | undefined\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 * `this.print(node)` inside this function calls the node-level dispatcher (`nodes` handlers),\n * not the override itself — so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null | undefined\n}\n\n/**\n * Creates a schema printer factory.\n *\n * This function wraps a builder and makes options optional at call sites.\n *\n * The builder receives resolved options and returns:\n * - `name` — a unique identifier for the printer\n * - `options` — options stored on the returned printer instance\n * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`\n * - `print` _(optional)_ — top-level override exposed as `printer.print`\n * - Inside this function, `this.print(node)` still dispatches to the `nodes` map\n * - This keeps recursion safe and avoids self-calls\n *\n * When no `print` override is provided, `printer.print` is the node-level dispatcher directly.\n *\n * @example Basic usage — Zod schema printer\n * ```ts\n * type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<ZodPrinter>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties.map(p => `${p.name}: ${this.print(p.schema)}`).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 | undefined) {\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: { print: (node: TNode) => T['output'] | null | undefined; options: T['options'] },\n node: TNodeByKey[K],\n ) => T['output'] | null | undefined\n }>\n print?: (this: { print: (node: TNode) => T['output'] | null | undefined; options: T['options'] }, node: TNode) => T['printOutput'] | null | undefined\n },\n ): (options?: T['options']) => { name: T['name']; options: T['options']; print: (node: TNode) => T['printOutput'] | null | undefined } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n print: (node: TNode): T['output'] | null | undefined => {\n const key = getKey(node)\n if (key === undefined) 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 | undefined).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n print: (printOverride ? printOverride.bind(context) : context.print) as (node: TNode) => T['printOutput'] | null | undefined,\n }\n }\n }\n}\n","import type { FunctionNode, FunctionNodeType } from '../nodes/function.ts'\nimport type { FunctionParameterNode, FunctionParametersNode, ObjectBindingParameterNode } from '../nodes/index.ts'\nimport type { PrinterFactoryOptions } from './printer.ts'\nimport { createPrinterFactory } from './printer.ts'\n\n/**\n * Maps each function-printer handler key to its concrete node type.\n */\nexport type FunctionNodeByType = {\n functionParameter: FunctionParameterNode\n objectBindingParameter: ObjectBindingParameterNode\n functionParameters: FunctionParametersNode\n}\n\nconst kindToHandlerKey = {\n FunctionParameter: 'functionParameter',\n ObjectBindingParameter: 'objectBindingParameter',\n FunctionParameters: 'functionParameters',\n} satisfies Record<string, FunctionNodeType>\n\n/**\n * Creates a function-parameter printer factory.\n *\n * This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`\n * (for function nodes) rather than by `node.type` (for schema nodes).\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { mode: 'declaration' | 'call' }, string>\n *\n * export const myPrinter = defineFunctionPrinter<MyPrinter>((options) => ({\n * name: 'my',\n * options,\n * nodes: {\n * functionParameter(node) {\n * return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name\n * },\n * objectBindingParameter(node) {\n * const inner = node.properties.map(p => this.print(p)).filter(Boolean).join(', ')\n * return `{ ${inner} }`\n * },\n * functionParameters(node) {\n * return node.params.map(p => this.print(p)).filter(Boolean).join(', ')\n * },\n * },\n * }))\n * ```\n */\nexport const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>((node) => kindToHandlerKey[node.kind])\n\nexport type FunctionPrinterOptions = {\n /**\n * Rendering modes supported by `functionPrinter`.\n *\n * | Mode | Output example | Use case |\n * |---------------|---------------------------------------------|---------------------------------|\n * | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |\n * | `call` | `id, { method, url }` | Function call arguments |\n * | `keys` | `{ id, config }` | Key names only (destructuring) |\n * | `values` | `{ id: id, config: config }` | Key/value object entries |\n */\n mode: 'declaration' | 'call' | 'keys' | 'values'\n /**\n * Optional transformation applied to every parameter name before printing.\n */\n transformName?: (name: string) => string\n /**\n * Optional transformation applied to every type string before printing.\n */\n transformType?: (type: string) => string\n}\n\ntype DefaultPrinter = PrinterFactoryOptions<'functionParameters', FunctionPrinterOptions, string>\n\nfunction rank(param: FunctionParameterNode | ObjectBindingParameterNode): number {\n if (param.kind === 'ObjectBindingParameter') {\n if (param.default) return 2\n const isOptional = param.optional ?? param.properties.every((p) => p.optional || p.default !== undefined)\n return isOptional ? 1 : 0\n }\n if (param.rest) return 3\n if (param.default) return 2\n return param.optional ? 1 : 0\n}\n\nfunction sortParams(params: Array<FunctionParameterNode | ObjectBindingParameterNode>): Array<FunctionParameterNode | ObjectBindingParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\nfunction sortChildParams(params: Array<FunctionParameterNode>): Array<FunctionParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\n/**\n * Default function-signature printer.\n * Covers the four standard output modes used across Kubb plugins.\n *\n * @example\n * ```ts\n * const printer = functionPrinter({ mode: 'declaration' })\n *\n * const sig = createFunctionParameters({\n * params: [\n * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),\n * ],\n * })\n *\n * printer.print(sig) // → \"petId: string, config: Config = {}\"\n * ```\n */\nexport const functionPrinter = defineFunctionPrinter<DefaultPrinter>((options) => ({\n name: 'functionParameters',\n options,\n nodes: {\n functionParameter(node) {\n const { mode, transformName, transformType } = this.options\n const name = transformName ? transformName(node.name) : node.name\n const type = node.type && transformType ? transformType(node.type) : node.type\n\n if (mode === 'keys' || mode === 'values') {\n return node.rest ? `...${name}` : name\n }\n\n if (mode === 'call') {\n return node.rest ? `...${name}` : name\n }\n\n if (node.rest) {\n return type ? `...${name}: ${type}` : `...${name}`\n }\n if (type) {\n if (node.optional) return `${name}?: ${type}`\n return node.default ? `${name}: ${type} = ${node.default}` : `${name}: ${type}`\n }\n return node.default ? `${name} = ${node.default}` : name\n },\n objectBindingParameter(node) {\n const { mode, transformName, transformType } = this.options\n const sorted = sortChildParams(node.properties)\n const isOptional = node.optional ?? sorted.every((p) => p.optional || p.default !== undefined)\n\n if (node.inline) {\n return sorted\n .map((p) => this.print(p))\n .filter(Boolean)\n .join(', ')\n }\n\n if (mode === 'keys' || mode === 'values') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n if (mode === 'call') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n const names = sorted.map((p) => {\n const n = transformName ? transformName(p.name) : p.name\n\n return n\n })\n\n const nameStr = names.length ? `{ ${names.join(', ')} }` : undefined\n if (!nameStr) return null\n\n let typeAnnotation = node.type\n if (!typeAnnotation) {\n const typeParts = sorted\n .filter((p) => p.type)\n .map((p) => {\n const t = transformType && p.type ? transformType(p.type) : p.type!\n return p.optional || p.default !== undefined ? `${p.name}?: ${t}` : `${p.name}: ${t}`\n })\n typeAnnotation = typeParts.length ? `{ ${typeParts.join('; ')} }` : undefined\n }\n\n if (typeAnnotation) {\n if (isOptional) return `${nameStr}: ${typeAnnotation} = ${node.default ?? '{}'}`\n return node.default ? `${nameStr}: ${typeAnnotation} = ${node.default}` : `${nameStr}: ${typeAnnotation}`\n }\n\n return node.default ? `${nameStr} = ${node.default}` : nameStr\n },\n functionParameters(node) {\n const sorted = sortParams(node.params)\n\n return sorted\n .map((p) => this.print(p))\n .filter(Boolean)\n .join(', ')\n },\n },\n}))\n","import type { RootNode } 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 `root.schemas` using each schema's `name`.\n *\n * Unnamed schemas are skipped.\n *\n * @example\n * ```ts\n * const refMap = buildRefMap(root)\n * const pet = refMap.get('Pet')\n * ```\n */\nexport function buildRefMap(root: RootNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of root.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 * @example\n * ```ts\n * const petSchema = resolveRef(refMap, 'Pet')\n * ```\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined {\n return refMap.get(ref)\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 { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, 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 * await Promise.all([\n * limit(() => taskA()),\n * limit(() => taskB()),\n * limit(() => taskC()),\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 [RootNode, undefined],\n [OperationNode, RootNode],\n [SchemaNode, RootNode | 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 RootParent = ParentOf<RootNode>\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 * // RootNode | 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 `RootNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor used by `transform`.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `x_${node.operationId}` }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n root?(node: RootNode, context: VisitorContext<RootNode>): void | RootNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | 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 root?(node: RootNode, context: VisitorContext<RootNode>): MaybePromise<void | RootNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | 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 root?(node: RootNode, context: VisitorContext<RootNode>): T | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | 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): Array<Node> {\n switch (node.kind) {\n case 'Root':\n return [...node.schemas, ...node.operations]\n case 'Operation':\n return [...node.parameters, ...(node.requestBody?.schema ? [node.requestBody.schema] : []), ...node.responses]\n case 'Schema': {\n const children: Array<Node> = []\n\n if (!recurse) return []\n\n if ('properties' in node && node.properties.length > 0) children.push(...node.properties)\n if ('items' in node && node.items) children.push(...node.items)\n if ('members' in node && node.members) children.push(...node.members)\n if ('additionalProperties' in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties)\n\n return children\n }\n case 'Property':\n return [node.schema]\n case 'Parameter':\n return [node.schema]\n case 'Response':\n return node.schema ? [node.schema] : []\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return []\n }\n}\n\n/**\n * Depth-first traversal for side effects. Visitor return values are ignored.\n * Sibling nodes at each level are visited concurrently up to `options.concurrency`\n * (default: `WALK_CONCURRENCY`).\n *\n * @example\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Visit only the current node\n * await walk(root, { depth: 'shallow', root: () => {} })\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 'Root':\n await limit(() => visitor.root?.(node, { parent: parent as ParentOf<RootNode> }))\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 case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n\n const children = getChildren(node, recurse)\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Runs a depth-first immutable transform.\n *\n * If a visitor returns a node, it replaces the current node.\n * If it returns `undefined`, the current node stays the same.\n *\n * @example\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Shallow mode: only transform the input node\n * const next = transform(root, { depth: 'shallow', root: (node) => node })\n * ```\n */\nexport function transform(node: RootNode, options: TransformOptions): RootNode\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 switch (node.kind) {\n case 'Root': {\n let root = node\n const replaced = visitor.root?.(root, { parent: parent as ParentOf<RootNode> })\n if (replaced) root = replaced\n\n return {\n ...root,\n schemas: root.schemas.map((s) => transform(s, { ...options, parent: root })),\n operations: root.operations.map((op) => transform(op, { ...options, parent: root })),\n }\n }\n case 'Operation': {\n let op = node\n const replaced = visitor.operation?.(op, { parent: parent as ParentOf<OperationNode> })\n if (replaced) op = replaced\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),\n requestBody: op.requestBody\n ? { ...op.requestBody, schema: op.requestBody.schema ? transform(op.requestBody.schema, { ...options, parent: op }) : undefined }\n : undefined,\n responses: op.responses.map((r) => transform(r, { ...options, parent: op })),\n }\n }\n case 'Schema': {\n let schema = node\n const replaced = visitor.schema?.(schema, { parent: parent as ParentOf<SchemaNode> })\n if (replaced) schema = replaced\n\n const childOptions = { ...options, parent: schema }\n\n return {\n ...schema,\n ...('properties' in schema && recurse ? { properties: schema.properties.map((p) => transform(p, childOptions)) } : {}),\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 ? { additionalProperties: transform(schema.additionalProperties, childOptions) }\n : {}),\n } as SchemaNode\n }\n case 'Property': {\n let prop = node\n const replaced = visitor.property?.(prop, { parent: parent as ParentOf<PropertyNode> })\n if (replaced) prop = replaced\n\n return createProperty({\n ...prop,\n schema: transform(prop.schema, { ...options, parent: prop }),\n })\n }\n case 'Parameter': {\n let param = node\n const replaced = visitor.parameter?.(param, { parent: parent as ParentOf<ParameterNode> })\n if (replaced) param = replaced\n\n return createParameter({\n ...param,\n schema: transform(param.schema, { ...options, parent: param }),\n })\n }\n case 'Response': {\n let response = node\n const replaced = visitor.response?.(response, { parent: parent as ParentOf<ResponseNode> })\n if (replaced) response = replaced\n\n return {\n ...response,\n schema: transform(response.schema, { ...options, parent: response }),\n }\n }\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return node\n }\n}\n\n/**\n * Composes multiple visitors into one visitor, applied left to right.\n *\n * For each node kind, output from one visitor is input to the next.\n * If a visitor returns `undefined`, the previous node value is kept.\n *\n * @example\n * ```ts\n * const visitor = composeTransformers(\n * { operation: (node) => ({ ...node, operationId: `a_${node.operationId}` }) },\n * { operation: (node) => ({ ...node, operationId: `b_${node.operationId}` }) },\n * )\n * ```\n */\nexport function composeTransformers(...visitors: Array<Visitor>): Visitor {\n return {\n root(node, context) {\n return visitors.reduce<RootNode>((acc, v) => v.root?.(acc, context) ?? acc, node)\n },\n operation(node, context) {\n return visitors.reduce<OperationNode>((acc, v) => v.operation?.(acc, context) ?? acc, node)\n },\n schema(node, context) {\n return visitors.reduce<SchemaNode>((acc, v) => v.schema?.(acc, context) ?? acc, node)\n },\n property(node, context) {\n return visitors.reduce<PropertyNode>((acc, v) => v.property?.(acc, context) ?? acc, node)\n },\n parameter(node, context) {\n return visitors.reduce<ParameterNode>((acc, v) => v.parameter?.(acc, context) ?? acc, node)\n },\n response(node, context) {\n return visitors.reduce<ResponseNode>((acc, v) => v.response?.(acc, context) ?? acc, node)\n },\n }\n}\n\n/**\n * Runs a depth-first synchronous collection pass.\n *\n * Non-`undefined` values returned by visitor callbacks are appended to the result.\n *\n * @example\n * ```ts\n * const ids = collect(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Collect from only the current node\n * const values = collect(root, { depth: 'shallow', root: () => 'root' })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n const results: Array<T> = []\n\n let v: T | undefined\n switch (node.kind) {\n case 'Root':\n v = visitor.root?.(node, { parent: parent as ParentOf<RootNode> })\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 case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n if (v !== undefined) results.push(v)\n\n for (const child of getChildren(node, recurse)) {\n for (const item of collect(child, { ...options, parent: node })) {\n results.push(item)\n }\n }\n\n return results\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 | undefined\n}): Array<TImport> {\n return collect<TImport>(node, {\n schema(schemaNode): TImport | undefined {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n if (!schemaRef?.ref) return\n\n const rawName = extractRefName(schemaRef.ref)\n const schemaName = nameMapping.get(rawName) ?? rawName\n const result = resolve(schemaName)\n if (!result) return\n\n return result\n },\n })\n}\n","import { SCALAR_PRIMITIVE_TYPES } 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'\nimport { transform } from './visitor.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 mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode> {\n return members.reduce<Array<SchemaNode>>((acc, member) => {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name) {\n const previous = acc.at(-1)\n const previousObject = previous ? narrowSchema(previous, 'object') : undefined\n\n if (previousObject && !previousObject.name) {\n acc[acc.length - 1] = createSchema({\n ...previousObject,\n properties: [...(previousObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n return acc\n }\n }\n\n acc.push(member)\n return acc\n }, [])\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(\n members.filter((member) => SCALAR_PRIMITIVE_TYPES.has(member.type as typeof SCALAR_PRIMITIVE_TYPES extends Set<infer T> ? T : never)).map((m) => m.type),\n )\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: undefined }\n }\n\n if (enumNode) {\n return { ...propNode, name: enumPropName(parentName, propName, enumSuffix) }\n }\n\n return propNode\n}\n\n/**\n * Walks a schema tree and resolves `ref`/`enum` names through callbacks.\n */\nexport function resolveNames({\n node,\n nameMapping,\n resolveName,\n resolveEnumName,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolveName: (ref: string) => string | undefined\n resolveEnumName?: (name: string) => string | undefined\n}): SchemaNode {\n return transform(node, {\n schema(schemaNode) {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n\n if (schemaRef && (schemaRef.ref || schemaRef.name)) {\n const rawRef = schemaRef.ref ?? schemaRef.name!\n const resolved = resolveName(nameMapping.get(rawRef) ?? rawRef)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n\n const schemaEnum = narrowSchema(schemaNode, 'enum')\n if (schemaEnum?.name) {\n const resolved = (resolveEnumName ?? resolveName)(schemaEnum.name)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n },\n }) as SchemaNode\n}\n"],"mappings":";;;;AAWA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,MAAM;CACN,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;CACV,mBAAmB;CACnB,wBAAwB;CACxB,oBAAoB;CACrB;;;;;;;;;;;;AAaD,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,OAAO;CACR;;;;AAKD,MAAa,yBAAyB,IAAI,IAAI;CAAC;CAAU;CAAU;CAAW;CAAU;CAAU,CAAU;AAE5G,MAAa,cAAc;CACzB,KAAK;CACL,MAAM;CACN,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,OAAO;CACR;AA6BD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB;CAChB,2BAA2B;CAC3B,wBAAwB;CACxB,gBAAgB;CAChB,gBAAgB;CAChB,oBAAoB;CACpB,mBAAmB;CACnB,WAAW;CACX,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,aAAa;CACb,WAAW;CACX,UAAU;CACX;;;;;;;;;;ACnLD,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAA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c,cAAc,iBAAiB,IAAI,UAAU,IAAI,iBAAiB,IAAI,SAAS,EAC3H,QAAO;AAGT,SAAO;GACP;;AAGJ,SAAgB,YAAY,UAAsB,YAAuC,UAAkB,YAAgC;CACzI,MAAM,WAAW,aAAa,UAAU,OAAO;AAE/C,KAAI,UAAU,cAAc,UAC1B,QAAO;EAAE,GAAG;EAAU,MAAM,KAAA;EAAW;AAGzC,KAAI,SACF,QAAO;EAAE,GAAG;EAAU,MAAM,aAAa,YAAY,UAAU,WAAW;EAAE;AAG9E,QAAO;;;;;AAMT,SAAgB,aAAa,EAC3B,MACA,aACA,aACA,mBAMa;AACb,QAAO,UAAU,MAAM,EACrB,OAAO,YAAY;EACjB,MAAM,YAAY,aAAa,YAAY,MAAM;AAEjD,MAAI,cAAc,UAAU,OAAO,UAAU,OAAO;GAClD,MAAM,SAAS,UAAU,OAAO,UAAU;GAC1C,MAAM,WAAW,YAAY,YAAY,IAAI,OAAO,IAAI,OAAO;AAC/D,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;EAI5C,MAAM,aAAa,aAAa,YAAY,OAAO;AACnD,MAAI,YAAY,MAAM;GACpB,MAAM,YAAY,mBAAmB,aAAa,WAAW,KAAK;AAClE,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;IAI/C,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/guards.ts","../src/utils.ts","../src/factory.ts","../src/printers/printer.ts","../src/printers/functionPrinter.ts","../src/refs.ts","../src/visitor.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 { ParameterLocation } from './nodes/parameter.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth used by AST visitor utilities.\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 root: 'Root',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n functionParameter: 'FunctionParameter',\n objectBindingParameter: 'ObjectBindingParameter',\n functionParameters: 'FunctionParameters',\n} as const satisfies Record<string, NodeKind>\n\n/**\n * Canonical schema type strings used by AST schema nodes.\n *\n * These values are used across the AST as stable discriminators\n * (for example `schema.type === schemaTypes.object`).\n *\n * The map is grouped by intent:\n * - primitives (`string`, `number`, `boolean`, ...)\n * - structural/composite (`object`, `array`, `union`, ...)\n * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)\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 * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\n/**\n * Primitive scalar schema types used when simplifying union members.\n */\nexport const SCALAR_PRIMITIVE_TYPES = new Set(['string', 'number', 'integer', 'bigint', 'boolean'] as const)\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\nexport const parameterLocations = {\n path: 'path',\n query: 'query',\n header: 'header',\n cookie: 'cookie',\n} as const satisfies Record<ParameterLocation, ParameterLocation>\n\n/**\n * Default maximum number of concurrent callbacks used by `walk`.\n *\n * @example\n * ```ts\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Fallback response status code used for catch-all responses.\n *\n * @example\n * ```ts\n * const status = DEFAULT_STATUS_CODE // 'default'\n * ```\n */\nexport const DEFAULT_STATUS_CODE = 'default' as const\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 */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).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\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\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 try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import type {\n FunctionParameterNode,\n FunctionParametersNode,\n Node,\n NodeKind,\n ObjectBindingParameterNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\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 | undefined\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined {\n return node?.type === type ? (node as SchemaNodeByType[T]) : undefined\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 a `RootNode`.\n *\n * @example\n * ```ts\n * if (isRootNode(node)) {\n * console.log(node.schemas.length)\n * }\n * ```\n */\nexport const isRootNode = isKind<RootNode>('Root')\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 an `ObjectBindingParameterNode`.\n */\nexport const isObjectBindingParameterNode = isKind<ObjectBindingParameterNode>('ObjectBindingParameter')\n\n/**\n * Returns `true` when the input is a `FunctionParametersNode`.\n */\nexport const isFunctionParametersNode = isKind<FunctionParametersNode>('FunctionParameters')\n","import { camelCase, isValidVarName } from '@internals/utils'\n\nimport { narrowSchema } from './guards.ts'\nimport type { ParameterNode, SchemaNode } from './nodes/index.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns `true` when a schema is emitted as a plain TypeScript `string`.\n *\n * - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.\n * - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.\n *\n * @example\n * ```ts\n * isStringType(createSchema({ type: 'uuid' })) // true\n * isStringType(createSchema({ type: 'date', representation: 'date' })) // false\n * ```\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 * The input array is not mutated.\n * If `casing` is not set, the original array is returned unchanged.\n *\n * Use this before passing parameters to schema builders so that property keys\n * in generated output match the desired casing while preserving\n * `OperationNode.parameters` for other consumers.\n *\n * @example\n * ```ts\n * const params = [createParameter({ name: 'pet_id', in: 'query', schema: createSchema({ type: 'string' }) })]\n * const cased = caseParams(params, 'camelcase')\n * // cased[0].name === 'petId'\n * ```\n */\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) {\n return params\n }\n\n return params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n\n return { ...param, name: transformed }\n })\n}\n\n/**\n * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.\n *\n * - `optional` is set for non-required, non-nullable schemas.\n * - `nullish` is set for non-required, nullable schemas.\n */\nexport function syncOptionality(required: boolean, schema: SchemaNode): 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","import type { InferSchemaNode } from './infer.ts'\nimport type {\n FunctionParameterNode,\n FunctionParametersNode,\n ObjectBindingParameterNode,\n ObjectSchemaNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\n SchemaNode,\n} from './nodes/index.ts'\nimport { syncOptionality } from './utils.ts'\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'> & { properties?: Array<PropertyNode> }\ntype CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>\ntype CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & { kind: 'Schema' }\n\n/**\n * Creates a `RootNode` with stable defaults for `schemas` and `operations`.\n *\n * @example\n * ```ts\n * const root = createRoot()\n * // { kind: 'Root', schemas: [], operations: [] }\n * ```\n *\n * @example\n * ```ts\n * const root = createRoot({ schemas: [petSchema] })\n * // keeps default operations: []\n * ```\n */\nexport function createRoot(overrides: Partial<Omit<RootNode, 'kind'>> = {}): RootNode {\n return {\n schemas: [],\n operations: [],\n ...overrides,\n kind: 'Root',\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 * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n * For object schemas, `properties` defaults to an empty array.\n *\n * @example\n * ```ts\n * const scalar = createSchema({ type: 'string' })\n * // { kind: 'Schema', type: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const object = createSchema({ type: 'object' })\n * // { kind: 'Schema', type: '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 if (props['type'] === 'object') {\n return { properties: [], ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n }\n\n return { ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n}\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: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode {\n const required = props.required ?? false\n\n return {\n ...props,\n kind: 'Property',\n required,\n schema: syncOptionality(required, props.schema),\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(required, props.schema),\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 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 * Creates a `FunctionParameterNode`.\n *\n * `optional` defaults to `false`.\n *\n * @example Required typed param\n * ```ts\n * createFunctionParameter({ name: 'petId', type: 'string' })\n * // → petId: string\n * ```\n *\n * @example Optional param\n * ```ts\n * createFunctionParameter({ name: 'params', type: '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: 'RequestConfig', default: '{}' })\n * // → config: RequestConfig = {}\n * ```\n */\nexport function createFunctionParameter(\n props: { name: string; type?: string; 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 an `ObjectBindingParameterNode` for object-destructured parameter groups.\n *\n * @example Destructured object param\n * ```ts\n * createObjectBindingParameter({\n * properties: [\n * createFunctionParameter({ name: 'id', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'name', type: 'string', optional: true }),\n * ],\n * default: '{}',\n * })\n * // declaration → { id, name? }: { id: string; name?: string } = {}\n * // call → { id, name }\n * ```\n *\n * @example Inline mode — children emitted as individual top-level parameters\n * ```ts\n * createObjectBindingParameter({\n * properties: [createFunctionParameter({ name: 'petId', type: 'string', optional: false })],\n * inline: true,\n * })\n * // declaration → petId: string\n * // call → petId\n * ```\n */\nexport function createObjectBindingParameter(\n props: Pick<ObjectBindingParameterNode, 'properties'> & Partial<Omit<ObjectBindingParameterNode, 'kind' | 'properties'>>,\n): ObjectBindingParameterNode {\n return {\n ...props,\n kind: 'ObjectBindingParameter',\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: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: '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","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 | undefined\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 | undefined\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 | undefined\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 | undefined\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/**\n * Creates a schema printer factory.\n *\n * This function wraps a builder and makes options optional at call sites.\n *\n * The builder receives resolved options and returns:\n * - `name` — a unique identifier for the printer\n * - `options` — options stored on the returned printer instance\n * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`\n * - `print` _(optional)_ — top-level override exposed as `printer.print`\n * - Inside this function, use `this.transform(node)` to dispatch to the `nodes` map\n * - This keeps recursion safe and avoids self-calls\n *\n * When no `print` override is provided, `printer.print` falls back to `printer.transform` (the node-level dispatcher).\n *\n * @example Basic usage — Zod schema printer\n * ```ts\n * type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<ZodPrinter>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties.map(p => `${p.name}: ${this.transform(p.schema)}`).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 | undefined) {\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: { transform: (node: TNode) => T['output'] | null | undefined; options: T['options'] },\n node: TNodeByKey[K],\n ) => T['output'] | null | undefined\n }>\n print?: (this: { transform: (node: TNode) => T['output'] | null | undefined; options: T['options'] }, node: TNode) => T['printOutput'] | null | undefined\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null | undefined\n print: (node: TNode) => T['printOutput'] | null | undefined\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 | undefined => {\n const key = getKey(node)\n if (key === undefined) 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 | undefined).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 | undefined,\n }\n }\n }\n}\n","import type { FunctionNode, FunctionNodeType } from '../nodes/function.ts'\nimport type { FunctionParameterNode, FunctionParametersNode, ObjectBindingParameterNode } from '../nodes/index.ts'\nimport type { PrinterFactoryOptions } from './printer.ts'\nimport { createPrinterFactory } from './printer.ts'\n\n/**\n * Maps each function-printer handler key to its concrete node type.\n */\nexport type FunctionNodeByType = {\n functionParameter: FunctionParameterNode\n objectBindingParameter: ObjectBindingParameterNode\n functionParameters: FunctionParametersNode\n}\n\nconst kindToHandlerKey = {\n FunctionParameter: 'functionParameter',\n ObjectBindingParameter: 'objectBindingParameter',\n FunctionParameters: 'functionParameters',\n} satisfies Record<string, FunctionNodeType>\n\n/**\n * Creates a function-parameter printer factory.\n *\n * This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`\n * (for function nodes) rather than by `node.type` (for schema nodes).\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { mode: 'declaration' | 'call' }, string>\n *\n * export const myPrinter = defineFunctionPrinter<MyPrinter>((options) => ({\n * name: 'my',\n * options,\n * nodes: {\n * functionParameter(node) {\n * return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name\n * },\n * objectBindingParameter(node) {\n * const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')\n * return `{ ${inner} }`\n * },\n * functionParameters(node) {\n * return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')\n * },\n * },\n * }))\n * ```\n */\nexport const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>((node) => kindToHandlerKey[node.kind])\n\nexport type FunctionPrinterOptions = {\n /**\n * Rendering modes supported by `functionPrinter`.\n *\n * | Mode | Output example | Use case |\n * |---------------|---------------------------------------------|---------------------------------|\n * | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |\n * | `call` | `id, { method, url }` | Function call arguments |\n * | `keys` | `{ id, config }` | Key names only (destructuring) |\n * | `values` | `{ id: id, config: config }` | Key/value object entries |\n */\n mode: 'declaration' | 'call' | 'keys' | 'values'\n /**\n * Optional transformation applied to every parameter name before printing.\n */\n transformName?: (name: string) => string\n /**\n * Optional transformation applied to every type string before printing.\n */\n transformType?: (type: string) => string\n}\n\ntype DefaultPrinter = PrinterFactoryOptions<'functionParameters', FunctionPrinterOptions, string>\n\nfunction rank(param: FunctionParameterNode | ObjectBindingParameterNode): number {\n if (param.kind === 'ObjectBindingParameter') {\n if (param.default) return 2\n const isOptional = param.optional ?? param.properties.every((p) => p.optional || p.default !== undefined)\n return isOptional ? 1 : 0\n }\n if (param.rest) return 3\n if (param.default) return 2\n return param.optional ? 1 : 0\n}\n\nfunction sortParams(params: Array<FunctionParameterNode | ObjectBindingParameterNode>): Array<FunctionParameterNode | ObjectBindingParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\nfunction sortChildParams(params: Array<FunctionParameterNode>): Array<FunctionParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\n/**\n * Default function-signature printer.\n * Covers the four standard output modes used across Kubb plugins.\n *\n * @example\n * ```ts\n * const printer = functionPrinter({ mode: 'declaration' })\n *\n * const sig = createFunctionParameters({\n * params: [\n * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),\n * ],\n * })\n *\n * printer.print(sig) // → \"petId: string, config: Config = {}\"\n * ```\n */\nexport const functionPrinter = defineFunctionPrinter<DefaultPrinter>((options) => ({\n name: 'functionParameters',\n options,\n nodes: {\n functionParameter(node) {\n const { mode, transformName, transformType } = this.options\n const name = transformName ? transformName(node.name) : node.name\n const type = node.type && transformType ? transformType(node.type) : node.type\n\n if (mode === 'keys' || mode === 'values') {\n return node.rest ? `...${name}` : name\n }\n\n if (mode === 'call') {\n return node.rest ? `...${name}` : name\n }\n\n if (node.rest) {\n return type ? `...${name}: ${type}` : `...${name}`\n }\n if (type) {\n if (node.optional) return `${name}?: ${type}`\n return node.default ? `${name}: ${type} = ${node.default}` : `${name}: ${type}`\n }\n return node.default ? `${name} = ${node.default}` : name\n },\n objectBindingParameter(node) {\n const { mode, transformName, transformType } = this.options\n const sorted = sortChildParams(node.properties)\n const isOptional = node.optional ?? sorted.every((p) => p.optional || p.default !== undefined)\n\n if (node.inline) {\n return sorted\n .map((p) => this.transform(p))\n .filter(Boolean)\n .join(', ')\n }\n\n if (mode === 'keys' || mode === 'values') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n if (mode === 'call') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n const names = sorted.map((p) => {\n const n = transformName ? transformName(p.name) : p.name\n\n return n\n })\n\n const nameStr = names.length ? `{ ${names.join(', ')} }` : undefined\n if (!nameStr) return null\n\n let typeAnnotation = node.type\n if (!typeAnnotation) {\n const typeParts = sorted\n .filter((p) => p.type)\n .map((p) => {\n const t = transformType && p.type ? transformType(p.type) : p.type!\n return p.optional || p.default !== undefined ? `${p.name}?: ${t}` : `${p.name}: ${t}`\n })\n typeAnnotation = typeParts.length ? `{ ${typeParts.join('; ')} }` : undefined\n }\n\n if (typeAnnotation) {\n if (isOptional) return `${nameStr}: ${typeAnnotation} = ${node.default ?? '{}'}`\n return node.default ? `${nameStr}: ${typeAnnotation} = ${node.default}` : `${nameStr}: ${typeAnnotation}`\n }\n\n return node.default ? `${nameStr} = ${node.default}` : nameStr\n },\n functionParameters(node) {\n const sorted = sortParams(node.params)\n\n return sorted\n .map((p) => this.transform(p))\n .filter(Boolean)\n .join(', ')\n },\n },\n}))\n","import type { RootNode } 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 `root.schemas` using each schema's `name`.\n *\n * Unnamed schemas are skipped.\n *\n * @example\n * ```ts\n * const refMap = buildRefMap(root)\n * const pet = refMap.get('Pet')\n * ```\n */\nexport function buildRefMap(root: RootNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of root.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 * @example\n * ```ts\n * const petSchema = resolveRef(refMap, 'Pet')\n * ```\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined {\n return refMap.get(ref)\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 { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, 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 * await Promise.all([\n * limit(() => taskA()),\n * limit(() => taskB()),\n * limit(() => taskC()),\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 [RootNode, undefined],\n [OperationNode, RootNode],\n [SchemaNode, RootNode | 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 RootParent = ParentOf<RootNode>\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 * // RootNode | 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 `RootNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor used by `transform`.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `x_${node.operationId}` }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n root?(node: RootNode, context: VisitorContext<RootNode>): void | RootNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | 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 root?(node: RootNode, context: VisitorContext<RootNode>): MaybePromise<void | RootNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | 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 root?(node: RootNode, context: VisitorContext<RootNode>): T | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | 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): Array<Node> {\n switch (node.kind) {\n case 'Root':\n return [...node.schemas, ...node.operations]\n case 'Operation':\n return [...node.parameters, ...(node.requestBody?.schema ? [node.requestBody.schema] : []), ...node.responses]\n case 'Schema': {\n const children: Array<Node> = []\n\n if (!recurse) return []\n\n if ('properties' in node && node.properties.length > 0) children.push(...node.properties)\n if ('items' in node && node.items) children.push(...node.items)\n if ('members' in node && node.members) children.push(...node.members)\n if ('additionalProperties' in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties)\n\n return children\n }\n case 'Property':\n return [node.schema]\n case 'Parameter':\n return [node.schema]\n case 'Response':\n return node.schema ? [node.schema] : []\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return []\n }\n}\n\n/**\n * Depth-first traversal for side effects. Visitor return values are ignored.\n * Sibling nodes at each level are visited concurrently up to `options.concurrency`\n * (default: `WALK_CONCURRENCY`).\n *\n * @example\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Visit only the current node\n * await walk(root, { depth: 'shallow', root: () => {} })\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 'Root':\n await limit(() => visitor.root?.(node, { parent: parent as ParentOf<RootNode> }))\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 case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n\n const children = getChildren(node, recurse)\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Runs a depth-first immutable transform.\n *\n * If a visitor returns a node, it replaces the current node.\n * If it returns `undefined`, the current node stays the same.\n *\n * @example\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Shallow mode: only transform the input node\n * const next = transform(root, { depth: 'shallow', root: (node) => node })\n * ```\n */\nexport function transform(node: RootNode, options: TransformOptions): RootNode\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 switch (node.kind) {\n case 'Root': {\n let root = node\n const replaced = visitor.root?.(root, { parent: parent as ParentOf<RootNode> })\n if (replaced) root = replaced\n\n return {\n ...root,\n schemas: root.schemas.map((s) => transform(s, { ...options, parent: root })),\n operations: root.operations.map((op) => transform(op, { ...options, parent: root })),\n }\n }\n case 'Operation': {\n let op = node\n const replaced = visitor.operation?.(op, { parent: parent as ParentOf<OperationNode> })\n if (replaced) op = replaced\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),\n requestBody: op.requestBody\n ? { ...op.requestBody, schema: op.requestBody.schema ? transform(op.requestBody.schema, { ...options, parent: op }) : undefined }\n : undefined,\n responses: op.responses.map((r) => transform(r, { ...options, parent: op })),\n }\n }\n case 'Schema': {\n let schema = node\n const replaced = visitor.schema?.(schema, { parent: parent as ParentOf<SchemaNode> })\n if (replaced) schema = replaced\n\n const childOptions = { ...options, parent: schema }\n\n return {\n ...schema,\n ...('properties' in schema && recurse ? { properties: schema.properties.map((p) => transform(p, childOptions)) } : {}),\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 ? { additionalProperties: transform(schema.additionalProperties, childOptions) }\n : {}),\n } as SchemaNode\n }\n case 'Property': {\n let prop = node\n const replaced = visitor.property?.(prop, { parent: parent as ParentOf<PropertyNode> })\n if (replaced) prop = replaced\n\n return createProperty({\n ...prop,\n schema: transform(prop.schema, { ...options, parent: prop }),\n })\n }\n case 'Parameter': {\n let param = node\n const replaced = visitor.parameter?.(param, { parent: parent as ParentOf<ParameterNode> })\n if (replaced) param = replaced\n\n return createParameter({\n ...param,\n schema: transform(param.schema, { ...options, parent: param }),\n })\n }\n case 'Response': {\n let response = node\n const replaced = visitor.response?.(response, { parent: parent as ParentOf<ResponseNode> })\n if (replaced) response = replaced\n\n return {\n ...response,\n schema: transform(response.schema, { ...options, parent: response }),\n }\n }\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return node\n }\n}\n\n/**\n * Composes multiple visitors into one visitor, applied left to right.\n *\n * For each node kind, output from one visitor is input to the next.\n * If a visitor returns `undefined`, the previous node value is kept.\n *\n * @example\n * ```ts\n * const visitor = composeTransformers(\n * { operation: (node) => ({ ...node, operationId: `a_${node.operationId}` }) },\n * { operation: (node) => ({ ...node, operationId: `b_${node.operationId}` }) },\n * )\n * ```\n */\nexport function composeTransformers(...visitors: Array<Visitor>): Visitor {\n return {\n root(node, context) {\n return visitors.reduce<RootNode>((acc, v) => v.root?.(acc, context) ?? acc, node)\n },\n operation(node, context) {\n return visitors.reduce<OperationNode>((acc, v) => v.operation?.(acc, context) ?? acc, node)\n },\n schema(node, context) {\n return visitors.reduce<SchemaNode>((acc, v) => v.schema?.(acc, context) ?? acc, node)\n },\n property(node, context) {\n return visitors.reduce<PropertyNode>((acc, v) => v.property?.(acc, context) ?? acc, node)\n },\n parameter(node, context) {\n return visitors.reduce<ParameterNode>((acc, v) => v.parameter?.(acc, context) ?? acc, node)\n },\n response(node, context) {\n return visitors.reduce<ResponseNode>((acc, v) => v.response?.(acc, context) ?? acc, node)\n },\n }\n}\n\n/**\n * Runs a depth-first synchronous collection pass.\n *\n * Non-`undefined` values returned by visitor callbacks are appended to the result.\n *\n * @example\n * ```ts\n * const ids = collect(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Collect from only the current node\n * const values = collect(root, { depth: 'shallow', root: () => 'root' })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n const results: Array<T> = []\n\n let v: T | undefined\n switch (node.kind) {\n case 'Root':\n v = visitor.root?.(node, { parent: parent as ParentOf<RootNode> })\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 case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n if (v !== undefined) results.push(v)\n\n for (const child of getChildren(node, recurse)) {\n for (const item of collect(child, { ...options, parent: node })) {\n results.push(item)\n }\n }\n\n return results\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 | undefined\n}): Array<TImport> {\n return collect<TImport>(node, {\n schema(schemaNode): TImport | undefined {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n if (!schemaRef?.ref) return\n\n const rawName = extractRefName(schemaRef.ref)\n const schemaName = nameMapping.get(rawName) ?? rawName\n const result = resolve(schemaName)\n if (!result) return\n\n return result\n },\n })\n}\n","import { SCALAR_PRIMITIVE_TYPES } 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'\nimport { transform } from './visitor.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 mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode> {\n return members.reduce<Array<SchemaNode>>((acc, member) => {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name) {\n const previous = acc.at(-1)\n const previousObject = previous ? narrowSchema(previous, 'object') : undefined\n\n if (previousObject && !previousObject.name) {\n acc[acc.length - 1] = createSchema({\n ...previousObject,\n properties: [...(previousObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n return acc\n }\n }\n\n acc.push(member)\n return acc\n }, [])\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(\n members.filter((member) => SCALAR_PRIMITIVE_TYPES.has(member.type as typeof SCALAR_PRIMITIVE_TYPES extends Set<infer T> ? T : never)).map((m) => m.type),\n )\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: undefined }\n }\n\n if (enumNode) {\n return { ...propNode, name: enumPropName(parentName, propName, enumSuffix) }\n }\n\n return propNode\n}\n\n/**\n * Walks a schema tree and resolves `ref`/`enum` names through callbacks.\n */\nexport function resolveNames({\n node,\n nameMapping,\n resolveName,\n resolveEnumName,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolveName: (ref: string) => string | undefined\n resolveEnumName?: (name: string) => string | undefined\n}): SchemaNode {\n return transform(node, {\n schema(schemaNode) {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n\n if (schemaRef && (schemaRef.ref || schemaRef.name)) {\n const rawRef = schemaRef.ref ?? schemaRef.name!\n const resolved = resolveName(nameMapping.get(rawRef) ?? rawRef)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n\n const schemaEnum = narrowSchema(schemaNode, 'enum')\n if (schemaEnum?.name) {\n const resolved = (resolveEnumName ?? resolveName)(schemaEnum.name)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n },\n }) as SchemaNode\n}\n"],"mappings":";;;AAWA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,MAAM;CACN,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;CACV,mBAAmB;CACnB,wBAAwB;CACxB,oBAAoB;CACrB;;;;;;;;;;;;AAaD,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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AI,OAAO;AAC/D,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;EAI5C,MAAM,aAAa,aAAa,YAAY,OAAO;AACnD,MAAI,YAAY,MAAM;GACpB,MAAM,YAAY,mBAAmB,aAAa,WAAW,KAAK;AAClE,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;IAI/C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as createRoot, B as ResponseNode, C as createFunctionParameter, Ct as httpMethods, D as createParameter, E as createOperation, Et as schemaTypes, G as ParameterNode, L as RootNode, M as InferSchema, N as InferSchemaNode, O as createProperty, P as ParserOptions, S as createDiscriminantNode, T as createObjectBindingParameter, Tt as nodeKinds, _ as resolveRef, _t as FunctionParametersNode, at as SchemaNode, b as definePrinter, d as transform, f as walk, g as refMapToObject, gt as FunctionParameterNode, h as extractRefName, j as createSchema, k as createResponse, l as collect, m as buildRefMap, mt as FunctionNode, ot as SchemaNodeByType, pt as PropertyNode, u as composeTransformers, vt as ObjectBindingParameterNode, w as createFunctionParameters, wt as mediaTypes, xt as SCALAR_PRIMITIVE_TYPES, y as PrinterFactoryOptions, z as OperationNode } from "./visitor-
|
|
2
|
+
import { A as createRoot, B as ResponseNode, C as createFunctionParameter, Ct as httpMethods, D as createParameter, E as createOperation, Et as schemaTypes, G as ParameterNode, L as RootNode, M as InferSchema, N as InferSchemaNode, O as createProperty, P as ParserOptions, S as createDiscriminantNode, T as createObjectBindingParameter, Tt as nodeKinds, _ as resolveRef, _t as FunctionParametersNode, at as SchemaNode, b as definePrinter, d as transform, f as walk, g as refMapToObject, gt as FunctionParameterNode, h as extractRefName, j as createSchema, k as createResponse, l as collect, m as buildRefMap, mt as FunctionNode, ot as SchemaNodeByType, pt as PropertyNode, u as composeTransformers, vt as ObjectBindingParameterNode, w as createFunctionParameters, wt as mediaTypes, xt as SCALAR_PRIMITIVE_TYPES, y as PrinterFactoryOptions, z as OperationNode } from "./visitor-COwfCgLK.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -89,11 +89,11 @@ declare const isFunctionParametersNode: (node: unknown) => node is FunctionParam
|
|
|
89
89
|
* return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name
|
|
90
90
|
* },
|
|
91
91
|
* objectBindingParameter(node) {
|
|
92
|
-
* const inner = node.properties.map(p => this.
|
|
92
|
+
* const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
93
93
|
* return `{ ${inner} }`
|
|
94
94
|
* },
|
|
95
95
|
* functionParameters(node) {
|
|
96
|
-
* return node.params.map(p => this.
|
|
96
|
+
* return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
97
97
|
* },
|
|
98
98
|
* },
|
|
99
99
|
* }))
|
|
@@ -104,25 +104,26 @@ declare const defineFunctionPrinter: <T extends PrinterFactoryOptions>(build: (o
|
|
|
104
104
|
options: T["options"];
|
|
105
105
|
nodes: Partial<{
|
|
106
106
|
functionParameter: (this: {
|
|
107
|
-
|
|
107
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
108
108
|
options: T["options"];
|
|
109
109
|
}, node: FunctionParameterNode) => T["output"] | null | undefined;
|
|
110
110
|
objectBindingParameter: (this: {
|
|
111
|
-
|
|
111
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
112
112
|
options: T["options"];
|
|
113
113
|
}, node: ObjectBindingParameterNode) => T["output"] | null | undefined;
|
|
114
114
|
functionParameters: (this: {
|
|
115
|
-
|
|
115
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
116
116
|
options: T["options"];
|
|
117
117
|
}, node: FunctionParametersNode) => T["output"] | null | undefined;
|
|
118
118
|
}>;
|
|
119
119
|
print?: ((this: {
|
|
120
|
-
|
|
120
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
121
121
|
options: T["options"];
|
|
122
122
|
}, node: FunctionNode) => T["printOutput"] | null | undefined) | undefined;
|
|
123
123
|
}) => (options?: T["options"] | undefined) => {
|
|
124
124
|
name: T["name"];
|
|
125
125
|
options: T["options"];
|
|
126
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
126
127
|
print: (node: FunctionNode) => T["printOutput"] | null | undefined;
|
|
127
128
|
};
|
|
128
129
|
type FunctionPrinterOptions = {
|
|
@@ -167,6 +168,7 @@ type FunctionPrinterOptions = {
|
|
|
167
168
|
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
168
169
|
name: "functionParameters";
|
|
169
170
|
options: FunctionPrinterOptions;
|
|
171
|
+
transform: (node: FunctionNode) => string | null | undefined;
|
|
170
172
|
print: (node: FunctionNode) => string | null | undefined;
|
|
171
173
|
};
|
|
172
174
|
//#endregion
|