@kubb/ast
Advanced tools
| const require_visitor = require("./visitor-CDa9Cn6x.cjs"); | ||
| //#region src/defineMacro.ts | ||
| /** | ||
| * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain | ||
| * list keeps its authored order. | ||
| */ | ||
| function enforceWeight(enforce) { | ||
| if (enforce === "pre") return 0; | ||
| if (enforce === "post") return 2; | ||
| return 1; | ||
| } | ||
| /** | ||
| * Types a macro for inference and a single construction site, mirroring `definePlugin`. | ||
| * Adds no runtime behavior. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const macroUntagged = defineMacro({ | ||
| * name: 'untagged', | ||
| * operation(node) { | ||
| * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] } | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineMacro(macro) { | ||
| return macro; | ||
| } | ||
| /** | ||
| * Runs every macro's callback for one node kind in order, chaining the result so each macro sees | ||
| * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the | ||
| * original reference (structural sharing). | ||
| */ | ||
| function chain({ macros, key, node, context }) { | ||
| let current = node; | ||
| for (const macro of macros) { | ||
| const callback = macro[key]; | ||
| if (!callback) continue; | ||
| if (macro.when && !macro.when(current)) continue; | ||
| const next = callback(current, context); | ||
| if (next != null) current = next; | ||
| } | ||
| return current === node ? void 0 : current; | ||
| } | ||
| /** | ||
| * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin | ||
| * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied | ||
| * sequentially per node so later macros see earlier output. This differs from a plain visitor, which | ||
| * has no names, ordering, or composition. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum]) | ||
| * const next = transform(root, visitor) | ||
| * ``` | ||
| */ | ||
| function composeMacros(macros) { | ||
| const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce)); | ||
| const visitor = {}; | ||
| for (const key of require_visitor.visitorKeys) { | ||
| if (!ordered.some((macro) => typeof macro[key] === "function")) continue; | ||
| const callback = (node, context) => chain({ | ||
| macros: ordered, | ||
| key, | ||
| node, | ||
| context | ||
| }); | ||
| visitor[key] = callback; | ||
| } | ||
| return visitor; | ||
| } | ||
| /** | ||
| * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s | ||
| * structural sharing, so an empty or no-op macro list returns the same reference. Pass | ||
| * `depth: 'shallow'` to rewrite the root node only. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const next = applyMacros(root, [macroIntegerToString]) | ||
| * ``` | ||
| * | ||
| * @example Apply to the root node only | ||
| * ```ts | ||
| * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' }) | ||
| * ``` | ||
| */ | ||
| function applyMacros(root, macros, options) { | ||
| if (macros.length === 0) return root; | ||
| return require_visitor.transform(root, { | ||
| ...composeMacros(macros), | ||
| ...options | ||
| }); | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "applyMacros", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return applyMacros; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "composeMacros", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return composeMacros; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "defineMacro", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return defineMacro; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=defineMacro-C58x6uaa.cjs.map |
| {"version":3,"file":"defineMacro-C58x6uaa.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,gBAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"} |
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { X as visitorKeys, r as transform } from "./visitor-Ns-njjbG.js"; | ||
| //#region src/defineMacro.ts | ||
| /** | ||
| * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain | ||
| * list keeps its authored order. | ||
| */ | ||
| function enforceWeight(enforce) { | ||
| if (enforce === "pre") return 0; | ||
| if (enforce === "post") return 2; | ||
| return 1; | ||
| } | ||
| /** | ||
| * Types a macro for inference and a single construction site, mirroring `definePlugin`. | ||
| * Adds no runtime behavior. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const macroUntagged = defineMacro({ | ||
| * name: 'untagged', | ||
| * operation(node) { | ||
| * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] } | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineMacro(macro) { | ||
| return macro; | ||
| } | ||
| /** | ||
| * Runs every macro's callback for one node kind in order, chaining the result so each macro sees | ||
| * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the | ||
| * original reference (structural sharing). | ||
| */ | ||
| function chain({ macros, key, node, context }) { | ||
| let current = node; | ||
| for (const macro of macros) { | ||
| const callback = macro[key]; | ||
| if (!callback) continue; | ||
| if (macro.when && !macro.when(current)) continue; | ||
| const next = callback(current, context); | ||
| if (next != null) current = next; | ||
| } | ||
| return current === node ? void 0 : current; | ||
| } | ||
| /** | ||
| * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin | ||
| * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied | ||
| * sequentially per node so later macros see earlier output. This differs from a plain visitor, which | ||
| * has no names, ordering, or composition. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum]) | ||
| * const next = transform(root, visitor) | ||
| * ``` | ||
| */ | ||
| function composeMacros(macros) { | ||
| const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce)); | ||
| const visitor = {}; | ||
| for (const key of visitorKeys) { | ||
| if (!ordered.some((macro) => typeof macro[key] === "function")) continue; | ||
| const callback = (node, context) => chain({ | ||
| macros: ordered, | ||
| key, | ||
| node, | ||
| context | ||
| }); | ||
| visitor[key] = callback; | ||
| } | ||
| return visitor; | ||
| } | ||
| /** | ||
| * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s | ||
| * structural sharing, so an empty or no-op macro list returns the same reference. Pass | ||
| * `depth: 'shallow'` to rewrite the root node only. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const next = applyMacros(root, [macroIntegerToString]) | ||
| * ``` | ||
| * | ||
| * @example Apply to the root node only | ||
| * ```ts | ||
| * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' }) | ||
| * ``` | ||
| */ | ||
| function applyMacros(root, macros, options) { | ||
| if (macros.length === 0) return root; | ||
| return transform(root, { | ||
| ...composeMacros(macros), | ||
| ...options | ||
| }); | ||
| } | ||
| //#endregion | ||
| export { composeMacros as n, defineMacro as r, applyMacros as t }; | ||
| //# sourceMappingURL=defineMacro-Zagno12u.js.map |
| {"version":3,"file":"defineMacro-Zagno12u.js","names":[],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"} |
| const require_visitor = require("./visitor-CDa9Cn6x.cjs"); | ||
| //#region src/utils/refs.ts | ||
| const plainStringTypes = new Set([ | ||
| "string", | ||
| "uuid", | ||
| "email", | ||
| "url", | ||
| "datetime" | ||
| ]); | ||
| /** | ||
| * Returns the last path segment of a reference string. | ||
| * | ||
| * @example | ||
| * `extractRefName('#/components/schemas/Pet') // 'Pet'` | ||
| */ | ||
| function extractRefName(ref) { | ||
| return ref.split("/").at(-1) ?? ref; | ||
| } | ||
| /** | ||
| * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls | ||
| * back to `name` then nested `schema.name`. | ||
| * | ||
| * Returns `null` for non-ref nodes or when no name resolves. | ||
| * | ||
| * @example | ||
| * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'` | ||
| */ | ||
| function resolveRefName(node) { | ||
| if (!node || node.type !== "ref") return null; | ||
| if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null; | ||
| return node.name ?? node.schema?.name ?? null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase child schema name by joining a parent name and property name. | ||
| * Returns `null` when there is no parent to nest under. | ||
| * | ||
| * @example Nested under a parent | ||
| * `childName('Order', 'shipping_address') // 'OrderShippingAddress'` | ||
| * | ||
| * @example No parent | ||
| * `childName(undefined, 'params') // null` | ||
| */ | ||
| function childName(parentName, propName) { | ||
| return parentName ? require_visitor.pascalCase([parentName, propName].join(" ")) : null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any | ||
| * empty parts. | ||
| * | ||
| * @example | ||
| * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'` | ||
| */ | ||
| function enumPropName(parentName, propName, enumSuffix) { | ||
| return require_visitor.pascalCase([ | ||
| parentName, | ||
| propName, | ||
| enumSuffix | ||
| ].filter(Boolean).join(" ")); | ||
| } | ||
| /** | ||
| * Merges a ref node with its resolved schema, giving usage-site fields precedence. | ||
| * | ||
| * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the | ||
| * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`, | ||
| * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref | ||
| * nodes and refs without a resolved `schema` are returned unchanged. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' }) | ||
| * const merged = syncSchemaRef(ref) // merges with resolved Pet schema | ||
| * ``` | ||
| */ | ||
| function syncSchemaRef(node) { | ||
| const ref = require_visitor.narrowSchema(node, "ref"); | ||
| if (!ref) return node; | ||
| if (!ref.schema) return node; | ||
| const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref; | ||
| const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0)); | ||
| return require_visitor.createSchema({ | ||
| ...ref.schema, | ||
| ...definedOverrides | ||
| }); | ||
| } | ||
| /** | ||
| * Type guard that returns `true` when a schema emits as a plain `string` type. | ||
| * | ||
| * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time` | ||
| * types, returns `true` only when `representation` is `'string'` rather than `'date'`. | ||
| */ | ||
| function isStringType(node) { | ||
| if (plainStringTypes.has(node.type)) return true; | ||
| const temporal = require_visitor.narrowSchema(node, "date") ?? require_visitor.narrowSchema(node, "time"); | ||
| if (temporal) return temporal.representation !== "date"; | ||
| return false; | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "childName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return childName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "enumPropName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return enumPropName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "extractRefName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return extractRefName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isStringType", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return isStringType; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "resolveRefName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return resolveRefName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "syncSchemaRef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return syncSchemaRef; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=refs-DhraOHHv.cjs.map |
| {"version":3,"file":"refs-DhraOHHv.cjs","names":["pascalCase","narrowSchema","createSchema"],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;A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AGT,MAAM,WAAWD,gBAAAA,aAAa,MAAM,MAAM,KAAKA,gBAAAA,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"} |
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { M as pascalCase, Q as narrowSchema, o as createSchema } from "./visitor-Ns-njjbG.js"; | ||
| //#region src/utils/refs.ts | ||
| const plainStringTypes = new Set([ | ||
| "string", | ||
| "uuid", | ||
| "email", | ||
| "url", | ||
| "datetime" | ||
| ]); | ||
| /** | ||
| * Returns the last path segment of a reference string. | ||
| * | ||
| * @example | ||
| * `extractRefName('#/components/schemas/Pet') // 'Pet'` | ||
| */ | ||
| function extractRefName(ref) { | ||
| return ref.split("/").at(-1) ?? ref; | ||
| } | ||
| /** | ||
| * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls | ||
| * back to `name` then nested `schema.name`. | ||
| * | ||
| * Returns `null` for non-ref nodes or when no name resolves. | ||
| * | ||
| * @example | ||
| * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'` | ||
| */ | ||
| function resolveRefName(node) { | ||
| if (!node || node.type !== "ref") return null; | ||
| if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null; | ||
| return node.name ?? node.schema?.name ?? null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase child schema name by joining a parent name and property name. | ||
| * Returns `null` when there is no parent to nest under. | ||
| * | ||
| * @example Nested under a parent | ||
| * `childName('Order', 'shipping_address') // 'OrderShippingAddress'` | ||
| * | ||
| * @example No parent | ||
| * `childName(undefined, 'params') // null` | ||
| */ | ||
| function childName(parentName, propName) { | ||
| return parentName ? pascalCase([parentName, propName].join(" ")) : null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any | ||
| * empty parts. | ||
| * | ||
| * @example | ||
| * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'` | ||
| */ | ||
| function enumPropName(parentName, propName, enumSuffix) { | ||
| return pascalCase([ | ||
| parentName, | ||
| propName, | ||
| enumSuffix | ||
| ].filter(Boolean).join(" ")); | ||
| } | ||
| /** | ||
| * Merges a ref node with its resolved schema, giving usage-site fields precedence. | ||
| * | ||
| * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the | ||
| * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`, | ||
| * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref | ||
| * nodes and refs without a resolved `schema` are returned unchanged. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' }) | ||
| * const merged = syncSchemaRef(ref) // merges with resolved Pet schema | ||
| * ``` | ||
| */ | ||
| function syncSchemaRef(node) { | ||
| const ref = narrowSchema(node, "ref"); | ||
| if (!ref) return node; | ||
| if (!ref.schema) return node; | ||
| const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref; | ||
| const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0)); | ||
| return createSchema({ | ||
| ...ref.schema, | ||
| ...definedOverrides | ||
| }); | ||
| } | ||
| /** | ||
| * Type guard that returns `true` when a schema emits as a plain `string` type. | ||
| * | ||
| * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time` | ||
| * types, returns `true` only when `representation` is `'string'` rather than `'date'`. | ||
| */ | ||
| function isStringType(node) { | ||
| if (plainStringTypes.has(node.type)) return true; | ||
| const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time"); | ||
| if (temporal) return temporal.representation !== "date"; | ||
| return false; | ||
| } | ||
| //#endregion | ||
| export { resolveRefName as a, isStringType as i, enumPropName as n, syncSchemaRef as o, extractRefName as r, childName as t }; | ||
| //# sourceMappingURL=refs-DliAPaUa.js.map |
| {"version":3,"file":"refs-DliAPaUa.js","names":[],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;;AAKA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAa,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAO,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAM,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAO,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAW,aAAa,MAAM,MAAM,KAAK,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"} |
| //#region \0rolldown/runtime.js | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __name = (target, value) => __defProp(target, "name", { | ||
| value, | ||
| configurable: true | ||
| }); | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __exportAll = (all, no_symbols) => { | ||
| let target = {}; | ||
| for (var name in all) __defProp(target, name, { | ||
| get: all[name], | ||
| enumerable: true | ||
| }); | ||
| if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" }); | ||
| return target; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { | ||
| key = keys[i]; | ||
| if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { | ||
| get: ((k) => from[k]).bind(null, key), | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { | ||
| value: mod, | ||
| enumerable: true | ||
| }) : target, mod)); | ||
| //#endregion | ||
| let node_crypto = require("node:crypto"); | ||
| let node_path = require("node:path"); | ||
| node_path = __toESM(node_path, 1); | ||
| //#region src/constants.ts | ||
| const visitorDepths = { | ||
| shallow: "shallow", | ||
| deep: "deep" | ||
| }; | ||
| /** | ||
| * Schema type discriminators used by all AST schema nodes. | ||
| * | ||
| * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`). | ||
| */ | ||
| const schemaTypes = { | ||
| /** | ||
| * Text value. | ||
| */ | ||
| string: "string", | ||
| /** | ||
| * Floating-point number (`float`, `double`). | ||
| */ | ||
| number: "number", | ||
| /** | ||
| * Whole number (`int32`). Use `bigint` for `int64`. | ||
| */ | ||
| integer: "integer", | ||
| /** | ||
| * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`. | ||
| */ | ||
| bigint: "bigint", | ||
| /** | ||
| * Boolean value. | ||
| */ | ||
| boolean: "boolean", | ||
| /** | ||
| * Explicit null value. | ||
| */ | ||
| null: "null", | ||
| /** | ||
| * Any value (no type restriction). | ||
| */ | ||
| any: "any", | ||
| /** | ||
| * Unknown value (must be narrowed before usage). | ||
| */ | ||
| unknown: "unknown", | ||
| /** | ||
| * No return value (`void`). | ||
| */ | ||
| void: "void", | ||
| /** | ||
| * Object with named properties. | ||
| */ | ||
| object: "object", | ||
| /** | ||
| * Sequential list of items. | ||
| */ | ||
| array: "array", | ||
| /** | ||
| * Fixed-length list with position-specific items. | ||
| */ | ||
| tuple: "tuple", | ||
| /** | ||
| * "One of" multiple schema members. | ||
| */ | ||
| union: "union", | ||
| /** | ||
| * "All of" multiple schema members. | ||
| */ | ||
| intersection: "intersection", | ||
| /** | ||
| * Enum schema. | ||
| */ | ||
| enum: "enum", | ||
| /** | ||
| * Reference to another schema. | ||
| */ | ||
| ref: "ref", | ||
| /** | ||
| * Calendar date (for example `2026-03-24`). | ||
| */ | ||
| date: "date", | ||
| /** | ||
| * Date-time value (for example `2026-03-24T09:00:00Z`). | ||
| */ | ||
| datetime: "datetime", | ||
| /** | ||
| * Time-only value (for example `09:00:00`). | ||
| */ | ||
| time: "time", | ||
| /** | ||
| * UUID value. | ||
| */ | ||
| uuid: "uuid", | ||
| /** | ||
| * Email address value. | ||
| */ | ||
| email: "email", | ||
| /** | ||
| * URL value. | ||
| */ | ||
| url: "url", | ||
| /** | ||
| * IPv4 address value. | ||
| */ | ||
| ipv4: "ipv4", | ||
| /** | ||
| * IPv6 address value. | ||
| */ | ||
| ipv6: "ipv6", | ||
| /** | ||
| * Binary/blob value. | ||
| */ | ||
| blob: "blob", | ||
| /** | ||
| * Impossible value (`never`). | ||
| */ | ||
| never: "never" | ||
| }; | ||
| //#endregion | ||
| //#region src/guards.ts | ||
| /** | ||
| * Narrows a `SchemaNode` to the variant that matches `type`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const schema = createSchema({ type: 'string' }) | ||
| * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null | ||
| * ``` | ||
| */ | ||
| function narrowSchema(node, type) { | ||
| return node?.type === type ? node : null; | ||
| } | ||
| /** | ||
| * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * if (isHttpOperationNode(node)) { | ||
| * console.log(node.method, node.path) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function isHttpOperationNode(node) { | ||
| return node.protocol === "http" || node.method !== void 0 && node.path !== void 0; | ||
| } | ||
| //#endregion | ||
| //#region src/defineNode.ts | ||
| /** | ||
| * Visitor callback names, one per traversable node kind, in traversal order. | ||
| * Kept in sync with the keys of `Visitor` in `visitor.ts`. | ||
| */ | ||
| const visitorKeys = [ | ||
| "input", | ||
| "output", | ||
| "operation", | ||
| "schema", | ||
| "property", | ||
| "parameter", | ||
| "response" | ||
| ]; | ||
| /** | ||
| * Builds a type guard that matches nodes of the given `kind`. | ||
| */ | ||
| function isKind(kind) { | ||
| return (node) => node?.kind === kind; | ||
| } | ||
| /** | ||
| * Defines a node once and derives its `create` builder, `is` guard, and traversal | ||
| * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the | ||
| * `kind`, so node construction lives in one place without scattered `as` casts. | ||
| * | ||
| * @example Simple node | ||
| * ```ts | ||
| * const importDef = defineNode<ImportNode>({ kind: 'Import' }) | ||
| * const createImport = importDef.create | ||
| * ``` | ||
| * | ||
| * @example Node with a build hook | ||
| * ```ts | ||
| * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({ | ||
| * kind: 'Property', | ||
| * build: (props) => ({ ...props, required: props.required ?? false }), | ||
| * children: ['schema'], | ||
| * visitorKey: 'property', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineNode(config) { | ||
| const { kind, defaults, build, children, visitorKey } = config; | ||
| function create(input) { | ||
| const base = build ? build(input) : input; | ||
| return { | ||
| ...defaults, | ||
| ...base, | ||
| kind | ||
| }; | ||
| } | ||
| return { | ||
| kind, | ||
| create, | ||
| is: isKind(kind), | ||
| children, | ||
| visitorKey | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/code.ts | ||
| /** | ||
| * Definition for the {@link ConstNode}. | ||
| */ | ||
| const constDef = defineNode({ kind: "Const" }); | ||
| /** | ||
| * Definition for the {@link TypeNode}. | ||
| */ | ||
| const typeDef = defineNode({ kind: "Type" }); | ||
| /** | ||
| * Definition for the {@link FunctionNode}. | ||
| */ | ||
| const functionDef = defineNode({ kind: "Function" }); | ||
| /** | ||
| * Definition for the {@link ArrowFunctionNode}. | ||
| */ | ||
| const arrowFunctionDef = defineNode({ kind: "ArrowFunction" }); | ||
| /** | ||
| * Definition for the {@link TextNode}. | ||
| */ | ||
| const textDef = defineNode({ | ||
| kind: "Text", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Definition for the {@link BreakNode}. | ||
| */ | ||
| const breakDef = defineNode({ | ||
| kind: "Break", | ||
| build: () => ({}) | ||
| }); | ||
| /** | ||
| * Definition for the {@link JsxNode}. | ||
| */ | ||
| const jsxDef = defineNode({ | ||
| kind: "Jsx", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Creates a `ConstNode` representing a TypeScript `const` declaration. | ||
| * | ||
| * @example Exported constant with type and `as const` | ||
| * ```ts | ||
| * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true }) | ||
| * // export const pets: Pet[] = ... as const | ||
| * ``` | ||
| */ | ||
| const createConst = constDef.create; | ||
| /** | ||
| * Creates a `TypeNode` representing a TypeScript `type` alias declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createType({ name: 'Pet', export: true }) | ||
| * // export type Pet = ... | ||
| * ``` | ||
| */ | ||
| const createType = typeDef.create; | ||
| /** | ||
| * Creates a `FunctionNode` representing a TypeScript `function` declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' }) | ||
| * // export async function fetchPet(): Promise<Pet> { ... } | ||
| * ``` | ||
| */ | ||
| const createFunction = functionDef.create; | ||
| /** | ||
| * Creates an `ArrowFunctionNode` representing a TypeScript arrow function. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true }) | ||
| * // export const double = (n: number) => ... | ||
| * ``` | ||
| */ | ||
| const createArrowFunction = arrowFunctionDef.create; | ||
| /** | ||
| * Creates a {@link TextNode} representing a raw string fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createText('return fetch(id)') | ||
| * // { kind: 'Text', value: 'return fetch(id)' } | ||
| * ``` | ||
| */ | ||
| const createText = textDef.create; | ||
| /** | ||
| * Creates a {@link BreakNode} representing a line break in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createBreak() | ||
| * // { kind: 'Break' } | ||
| * ``` | ||
| */ | ||
| function createBreak() { | ||
| return breakDef.create(); | ||
| } | ||
| /** | ||
| * Creates a {@link JsxNode} representing a raw JSX fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createJsx('<>\n <a href={href}>Open</a>\n</>') | ||
| * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' } | ||
| * ``` | ||
| */ | ||
| const createJsx = jsxDef.create; | ||
| //#endregion | ||
| //#region src/nodes/content.ts | ||
| /** | ||
| * Definition for the {@link ContentNode}. | ||
| */ | ||
| const contentDef = defineNode({ | ||
| kind: "Content", | ||
| children: ["schema"] | ||
| }); | ||
| /** | ||
| * Creates a `ContentNode` for a single request-body or response content type. | ||
| */ | ||
| const createContent = contentDef.create; | ||
| //#endregion | ||
| //#region ../../internals/utils/src/casing.ts | ||
| /** | ||
| * Shared implementation for camelCase and PascalCase conversion. | ||
| * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons) | ||
| * and capitalizes each word according to `pascal`. | ||
| * | ||
| * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are. | ||
| */ | ||
| function toCamelOrPascal(text, pascal) { | ||
| return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => { | ||
| if (word.length > 1 && word === word.toUpperCase()) return word; | ||
| return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1); | ||
| }).join("").replace(/[^a-zA-Z0-9]/g, ""); | ||
| } | ||
| /** | ||
| * Converts `text` to PascalCase. | ||
| * | ||
| * @example Word boundaries | ||
| * `pascalCase('hello-world') // 'HelloWorld'` | ||
| * | ||
| * @example With a suffix | ||
| * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'` | ||
| */ | ||
| function pascalCase(text, { prefix = "", suffix = "" } = {}) { | ||
| return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true); | ||
| } | ||
| //#endregion | ||
| //#region ../../internals/utils/src/fs.ts | ||
| /** | ||
| * Strips the file extension from a path or file name. | ||
| * Only removes the last `.ext` segment when the dot is not part of a directory name. | ||
| * | ||
| * @example | ||
| * trimExtName('petStore.ts') // 'petStore' | ||
| * trimExtName('/src/models/pet.ts') // '/src/models/pet' | ||
| * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet' | ||
| * trimExtName('noExtension') // 'noExtension' | ||
| */ | ||
| function trimExtName(text) { | ||
| const dotIndex = text.lastIndexOf("."); | ||
| if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex); | ||
| return text; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/extractStringsFromNodes.ts | ||
| /** | ||
| * Extracts all string content from a `CodeNode` tree recursively. | ||
| * | ||
| * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`), | ||
| * and nested node content. Used to build the full source string for import filtering. | ||
| */ | ||
| function extractStringsFromNodes(nodes) { | ||
| if (!nodes?.length) return ""; | ||
| return nodes.map((node) => { | ||
| if (typeof node === "string") return node; | ||
| if (node.kind === "Text") return node.value; | ||
| if (node.kind === "Break") return ""; | ||
| if (node.kind === "Jsx") return node.value; | ||
| const parts = []; | ||
| if ("params" in node && node.params) parts.push(node.params); | ||
| if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics); | ||
| if ("returnType" in node && node.returnType) parts.push(node.returnType); | ||
| if ("type" in node && typeof node.type === "string") parts.push(node.type); | ||
| const nested = extractStringsFromNodes(node.nodes); | ||
| if (nested) parts.push(nested); | ||
| return parts.join("\n"); | ||
| }).filter(Boolean).join("\n"); | ||
| } | ||
| //#endregion | ||
| //#region src/utils/fileMerge.ts | ||
| function sourceKey(source) { | ||
| return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`; | ||
| } | ||
| function pathTypeKey(path, isTypeOnly) { | ||
| return `${path}:${isTypeOnly ?? false}`; | ||
| } | ||
| function exportKey(path, name, isTypeOnly, asAlias) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`; | ||
| } | ||
| function importKey(path, name, isTypeOnly) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}`; | ||
| } | ||
| /** | ||
| * Computes a multi-level sort key for exports and imports: | ||
| * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named. | ||
| */ | ||
| function sortKey(node) { | ||
| const isArray = Array.isArray(node.name) ? "1" : "0"; | ||
| const typeOnly = node.isTypeOnly ? "0" : "1"; | ||
| const hasName = node.name != null ? "1" : "0"; | ||
| const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? ""; | ||
| return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`; | ||
| } | ||
| /** | ||
| * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each | ||
| * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns | ||
| * the deduplicated array in original order. | ||
| */ | ||
| function combineSources(sources) { | ||
| const seen = /* @__PURE__ */ new Map(); | ||
| for (const source of sources) { | ||
| const key = sourceKey(source); | ||
| if (!seen.has(key)) seen.set(key, source); | ||
| } | ||
| return [...seen.values()]; | ||
| } | ||
| /** | ||
| * Merges `incoming` names into `existing`, preserving order and dropping duplicates. | ||
| * | ||
| * Shared by `combineExports` and `combineImports` for the same-path name-merge case. | ||
| */ | ||
| function mergeNameArrays(existing, incoming) { | ||
| const merged = new Set(existing); | ||
| for (const name of incoming) merged.add(name); | ||
| return [...merged]; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ExportNode` objects by path and type. | ||
| * | ||
| * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export. | ||
| * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array. | ||
| */ | ||
| function combineExports(exports) { | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = exports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| const { name, path, isTypeOnly, asAlias } = curr; | ||
| if (Array.isArray(name)) { | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name: [...new Set(name)] | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| const key = exportKey(path, name, isTypeOnly, asAlias); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ImportNode` objects, filtering out unused imports. | ||
| * | ||
| * Retains imports that are referenced in `source` or re-exported. Imports with the same path and | ||
| * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array. | ||
| */ | ||
| function combineImports(imports, exports, source) { | ||
| const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])); | ||
| const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName); | ||
| const importNameMemo = /* @__PURE__ */ new Map(); | ||
| const canonicalizeName = (n) => { | ||
| if (typeof n === "string") return n; | ||
| const key = `${n.propertyName}:${n.name ?? ""}`; | ||
| if (!importNameMemo.has(key)) importNameMemo.set(key, n); | ||
| return importNameMemo.get(key); | ||
| }; | ||
| const pathsWithUsedNamedImport = /* @__PURE__ */ new Set(); | ||
| for (const node of imports) { | ||
| if (!Array.isArray(node.name)) continue; | ||
| if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path); | ||
| } | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = imports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| if (curr.path === curr.root) continue; | ||
| const { path, isTypeOnly } = curr; | ||
| let { name } = curr; | ||
| if (Array.isArray(name)) { | ||
| name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName)); | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue; | ||
| const key = importKey(path, name, isTypeOnly); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/file.ts | ||
| /** | ||
| * Definition for the {@link ImportNode}. | ||
| */ | ||
| const importDef = defineNode({ kind: "Import" }); | ||
| /** | ||
| * Definition for the {@link ExportNode}. | ||
| */ | ||
| const exportDef = defineNode({ kind: "Export" }); | ||
| /** | ||
| * Definition for the {@link SourceNode}. | ||
| */ | ||
| const sourceDef = defineNode({ kind: "Source" }); | ||
| /** | ||
| * Definition for the {@link FileNode}. The fully resolved builder lives in | ||
| * `createFile`, so this definition only supplies the guard. | ||
| */ | ||
| const fileDef = defineNode({ kind: "File" }); | ||
| /** | ||
| * Creates an `ImportNode` representing a language-agnostic import/dependency declaration. | ||
| * | ||
| * @example Named import | ||
| * ```ts | ||
| * createImport({ name: ['useState'], path: 'react' }) | ||
| * // import { useState } from 'react' | ||
| * ``` | ||
| */ | ||
| const createImport = importDef.create; | ||
| /** | ||
| * Creates an `ExportNode` representing a language-agnostic export/public API declaration. | ||
| * | ||
| * @example Named export | ||
| * ```ts | ||
| * createExport({ name: ['Pet'], path: './Pet' }) | ||
| * // export { Pet } from './Pet' | ||
| * ``` | ||
| */ | ||
| const createExport = exportDef.create; | ||
| /** | ||
| * Creates a `SourceNode` representing a fragment of source code within a file. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true }) | ||
| * ``` | ||
| */ | ||
| const createSource = sourceDef.create; | ||
| /** | ||
| * Creates a fully resolved `FileNode` from a file input descriptor. | ||
| * | ||
| * Computes: | ||
| * - `id` SHA256 hash of the file path | ||
| * - `name` `baseName` without extension | ||
| * - `extname` extension extracted from `baseName` | ||
| * | ||
| * Deduplicates: | ||
| * - `sources` via `combineSources` | ||
| * - `exports` via `combineExports` | ||
| * - `imports` via `combineImports` (also filters unused imports) | ||
| * | ||
| * @throws {Error} when `baseName` has no extension. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'petStore.ts', | ||
| * path: 'src/models/petStore.ts', | ||
| * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })], | ||
| * imports: [createImport({ name: ['z'], path: 'zod' })], | ||
| * exports: [createExport({ name: ['Pet'], path: './petStore' })], | ||
| * }) | ||
| * // file.id = SHA256 hash of 'src/models/petStore.ts' | ||
| * // file.name = 'petStore' | ||
| * // file.extname = '.ts' | ||
| * ``` | ||
| * | ||
| * @example Copy a real file into the output verbatim | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'client.ts', | ||
| * path: 'src/gen/client.ts', | ||
| * copy: '/abs/path/to/templates/client.ts', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function createFile(input) { | ||
| const extname = node_path.default.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : ""); | ||
| if (!extname) throw new Error(`No extname found for ${input.baseName}`); | ||
| const source = (input.sources ?? []).flatMap((item) => item.nodes ?? []).map((node) => extractStringsFromNodes([node])).filter(Boolean).join("\n\n"); | ||
| const resolvedExports = input.exports?.length ? combineExports(input.exports) : []; | ||
| const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || void 0) : []; | ||
| const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name))); | ||
| const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName; | ||
| const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => { | ||
| if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp]; | ||
| const kept = imp.name.filter((item) => !localNames.has(nameOf(item))); | ||
| if (!kept.length) return []; | ||
| return [kept.length === imp.name.length ? imp : { | ||
| ...imp, | ||
| name: kept | ||
| }]; | ||
| }); | ||
| const resolvedSources = input.sources?.length ? combineSources(input.sources) : []; | ||
| return { | ||
| kind: "File", | ||
| ...input, | ||
| id: (0, node_crypto.hash)("sha256", input.path, "hex"), | ||
| name: trimExtName(input.baseName), | ||
| extname, | ||
| imports: resolvedImports, | ||
| exports: resolvedExports, | ||
| sources: resolvedSources, | ||
| meta: input.meta ?? {} | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/input.ts | ||
| /** | ||
| * Definition for the {@link InputNode}. | ||
| */ | ||
| const inputDef = defineNode({ | ||
| kind: "Input", | ||
| defaults: { | ||
| schemas: [], | ||
| operations: [], | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| } | ||
| }, | ||
| children: ["schemas", "operations"], | ||
| visitorKey: "input" | ||
| }); | ||
| /** | ||
| * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and | ||
| * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array | ||
| * `schemas`/`operations`. Both variants get the defaulted `meta`. | ||
| * | ||
| * @example Eager | ||
| * ```ts | ||
| * const input = createInput() | ||
| * // { kind: 'Input', schemas: [], operations: [] } | ||
| * ``` | ||
| * | ||
| * @example Streaming | ||
| * ```ts | ||
| * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } }) | ||
| * ``` | ||
| */ | ||
| function createInput(options = {}) { | ||
| const { stream, ...overrides } = options; | ||
| if (stream) return { | ||
| kind: "Input", | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| }, | ||
| ...overrides | ||
| }; | ||
| return inputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/requestBody.ts | ||
| /** | ||
| * Definition for the {@link RequestBodyNode}. Content entries are built upfront with | ||
| * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes. | ||
| */ | ||
| const requestBodyDef = defineNode({ | ||
| kind: "RequestBody", | ||
| children: ["content"] | ||
| }); | ||
| /** | ||
| * Creates a `RequestBodyNode`. | ||
| */ | ||
| const createRequestBody = requestBodyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/operation.ts | ||
| /** | ||
| * Definition for the {@link OperationNode}. HTTP operations (those carrying both | ||
| * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is | ||
| * normalized into a `RequestBodyNode`. | ||
| */ | ||
| const operationDef = defineNode({ | ||
| kind: "Operation", | ||
| build: (props) => { | ||
| const { requestBody, ...rest } = props; | ||
| const isHttp = rest.method !== void 0 && rest.path !== void 0; | ||
| return { | ||
| tags: [], | ||
| parameters: [], | ||
| responses: [], | ||
| ...rest, | ||
| ...isHttp ? { protocol: "http" } : {}, | ||
| requestBody: requestBody ? createRequestBody(requestBody) : void 0 | ||
| }; | ||
| }, | ||
| children: [ | ||
| "parameters", | ||
| "requestBody", | ||
| "responses" | ||
| ], | ||
| visitorKey: "operation" | ||
| }); | ||
| function createOperation(props) { | ||
| return operationDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/output.ts | ||
| /** | ||
| * Definition for the {@link OutputNode}. | ||
| */ | ||
| const outputDef = defineNode({ | ||
| kind: "Output", | ||
| defaults: { files: [] }, | ||
| visitorKey: "output" | ||
| }); | ||
| /** | ||
| * Creates an `OutputNode` with a stable default for `files`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const output = createOutput() | ||
| * // { kind: 'Output', files: [] } | ||
| * ``` | ||
| */ | ||
| function createOutput(overrides = {}) { | ||
| return outputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/optionality.ts | ||
| /** | ||
| * Generic JSON Schema optionality: a non-required field is optional, and a | ||
| * non-required nullable field is nullish. | ||
| */ | ||
| function optionality(schema, required) { | ||
| const nullable = schema.nullable ?? false; | ||
| return { | ||
| ...schema, | ||
| optional: !required && !nullable ? true : void 0, | ||
| nullish: !required && nullable ? true : void 0 | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/parameter.ts | ||
| /** | ||
| * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const parameterDef = defineNode({ | ||
| kind: "Parameter", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "parameter" | ||
| }); | ||
| /** | ||
| * Creates a `ParameterNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const param = createParameter({ | ||
| * name: 'petId', | ||
| * in: 'path', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string' }), | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createParameter = parameterDef.create; | ||
| //#endregion | ||
| //#region src/nodes/property.ts | ||
| /** | ||
| * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const propertyDef = defineNode({ | ||
| kind: "Property", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "property" | ||
| }); | ||
| /** | ||
| * Creates a `PropertyNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const property = createProperty({ | ||
| * name: 'status', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string', nullable: true }), | ||
| * }) | ||
| * // required=true, no optional/nullish | ||
| * ``` | ||
| */ | ||
| const createProperty = propertyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/response.ts | ||
| /** | ||
| * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional | ||
| * `mediaType`/`keysToOmit`) is normalized into one `content` entry. | ||
| */ | ||
| const responseDef = defineNode({ | ||
| kind: "Response", | ||
| build: (props) => { | ||
| const { schema, mediaType, keysToOmit, content, ...rest } = props; | ||
| const entries = content ?? (schema ? [createContent({ | ||
| contentType: mediaType ?? "application/json", | ||
| schema, | ||
| keysToOmit: keysToOmit ?? null | ||
| })] : void 0); | ||
| return { | ||
| ...rest, | ||
| content: entries | ||
| }; | ||
| }, | ||
| children: ["content"], | ||
| visitorKey: "response" | ||
| }); | ||
| /** | ||
| * Creates a `ResponseNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const response = createResponse({ | ||
| * statusCode: '200', | ||
| * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createResponse = responseDef.create; | ||
| //#endregion | ||
| //#region src/nodes/schema.ts | ||
| /** | ||
| * Maps schema `type` to its underlying `primitive`. | ||
| * Primitive types map to themselves and special string formats map to `'string'`. | ||
| * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`. | ||
| */ | ||
| const TYPE_TO_PRIMITIVE = { | ||
| string: "string", | ||
| number: "number", | ||
| integer: "integer", | ||
| bigint: "bigint", | ||
| boolean: "boolean", | ||
| null: "null", | ||
| any: "any", | ||
| unknown: "unknown", | ||
| void: "void", | ||
| never: "never", | ||
| object: "object", | ||
| array: "array", | ||
| date: "date", | ||
| uuid: "string", | ||
| email: "string", | ||
| url: "string", | ||
| datetime: "string", | ||
| time: "string" | ||
| }; | ||
| /** | ||
| * Definition for the {@link SchemaNode}. Object schemas default `properties` to an | ||
| * empty array, and `primitive` is inferred from `type` when not explicitly provided. | ||
| */ | ||
| const schemaDef = defineNode({ | ||
| kind: "Schema", | ||
| build: (props) => { | ||
| if (props.type === "object") return { | ||
| properties: [], | ||
| primitive: "object", | ||
| ...props | ||
| }; | ||
| return { | ||
| primitive: TYPE_TO_PRIMITIVE[props.type], | ||
| ...props | ||
| }; | ||
| }, | ||
| children: [ | ||
| "properties", | ||
| "items", | ||
| "members", | ||
| "additionalProperties" | ||
| ], | ||
| visitorKey: "schema" | ||
| }); | ||
| function createSchema(props) { | ||
| return schemaDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/registry.ts | ||
| /** | ||
| * Every node definition. Adding a node means adding its `defineNode` to one | ||
| * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it. | ||
| */ | ||
| const nodeDefs = [ | ||
| inputDef, | ||
| outputDef, | ||
| operationDef, | ||
| requestBodyDef, | ||
| contentDef, | ||
| responseDef, | ||
| schemaDef, | ||
| propertyDef, | ||
| parameterDef, | ||
| constDef, | ||
| typeDef, | ||
| functionDef, | ||
| arrowFunctionDef, | ||
| textDef, | ||
| breakDef, | ||
| jsxDef, | ||
| importDef, | ||
| exportDef, | ||
| sourceDef, | ||
| fileDef | ||
| ]; | ||
| //#endregion | ||
| //#region src/visitor.ts | ||
| /** | ||
| * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`). | ||
| * Derived from each definition's `children`. | ||
| */ | ||
| const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : [])); | ||
| /** | ||
| * Maps a node kind to the matching visitor callback name. Derived from each | ||
| * definition's `visitorKey`. | ||
| */ | ||
| const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : [])); | ||
| /** | ||
| * Creates a small async concurrency limiter. | ||
| * | ||
| * At most `concurrency` tasks are in flight at once. Extra tasks are queued. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const limit = createLimit(2) | ||
| * for (const task of [taskA, taskB, taskC]) { | ||
| * await limit(() => task()) | ||
| * } | ||
| * // only 2 tasks run at the same time | ||
| * ``` | ||
| */ | ||
| function createLimit(concurrency) { | ||
| let active = 0; | ||
| const queue = []; | ||
| function next() { | ||
| if (active < concurrency && queue.length > 0) { | ||
| active++; | ||
| queue.shift()(); | ||
| } | ||
| } | ||
| return function limit(fn) { | ||
| return new Promise((resolve, reject) => { | ||
| queue.push(() => { | ||
| Promise.resolve(fn()).then(resolve, reject).finally(() => { | ||
| active--; | ||
| next(); | ||
| }); | ||
| }); | ||
| next(); | ||
| }); | ||
| }; | ||
| } | ||
| const visitorKeysByKind = VISITOR_KEYS; | ||
| /** | ||
| * Returns `true` when `value` is an AST node (an object carrying a `kind`). | ||
| */ | ||
| function isNode(value) { | ||
| return typeof value === "object" && value !== null && "kind" in value; | ||
| } | ||
| /** | ||
| * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}. | ||
| * | ||
| * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const children = getChildren(operationNode, true) | ||
| * // returns parameters, the request body, and responses | ||
| * ``` | ||
| */ | ||
| function* getChildren(node, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return; | ||
| const record = node; | ||
| for (const key of keys) { | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) if (isNode(item)) yield item; | ||
| } else if (isNode(value)) yield value; | ||
| } | ||
| } | ||
| /** | ||
| * Runs the visitor callback that matches `node.kind` with the traversal | ||
| * context. The result is a replacement node, a collected value, or `undefined` | ||
| * when no callback is registered for the kind. | ||
| * | ||
| * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives | ||
| * in one place. `TResult` is the caller's expected return: the same node type | ||
| * for `transform`, the collected value type for `collectLazy`, ignored for `walk`. | ||
| */ | ||
| function applyVisitor(node, visitor, parent) { | ||
| const key = VISITOR_KEY_BY_KIND[node.kind]; | ||
| if (!key) return void 0; | ||
| const fn = visitor[key]; | ||
| return fn?.(node, { parent }); | ||
| } | ||
| /** | ||
| * Async depth-first traversal for side effects. Visitor return values are | ||
| * ignored. Use `transform` when you want to rewrite nodes. | ||
| * | ||
| * Sibling nodes at each depth run concurrently up to `options.concurrency` | ||
| * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor | ||
| * work. Lower values reduce memory pressure. | ||
| * | ||
| * @example Log every operation | ||
| * ```ts | ||
| * await walk(root, { | ||
| * operation(node) { | ||
| * console.log(node.operationId) | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @example Only visit the root node | ||
| * ```ts | ||
| * await walk(root, { depth: 'shallow', input: () => {} }) | ||
| * ``` | ||
| */ | ||
| async function walk(node, options) { | ||
| return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0); | ||
| } | ||
| async function _walk(node, visitor, recurse, limit, parent) { | ||
| await limit(() => applyVisitor(node, visitor, parent)); | ||
| const children = Array.from(getChildren(node, recurse)); | ||
| if (children.length === 0) return; | ||
| await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node))); | ||
| } | ||
| function transform(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse); | ||
| } | ||
| /** | ||
| * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming | ||
| * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact. | ||
| * `Schema` children are skipped in shallow mode. | ||
| */ | ||
| function transformChildren(node, options, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return node; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return node; | ||
| const record = node; | ||
| const childOptions = { | ||
| ...options, | ||
| parent: node | ||
| }; | ||
| let updates; | ||
| for (const key of keys) { | ||
| if (!(key in record)) continue; | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| let changed = false; | ||
| const mapped = value.map((item) => { | ||
| if (!isNode(item)) return item; | ||
| const next = transform(item, childOptions); | ||
| if (next !== item) changed = true; | ||
| return next; | ||
| }); | ||
| if (changed) (updates ??= {})[key] = mapped; | ||
| } else if (isNode(value)) { | ||
| const next = transform(value, childOptions); | ||
| if (next !== value) (updates ??= {})[key] = next; | ||
| } | ||
| } | ||
| return updates ? { | ||
| ...node, | ||
| ...updates | ||
| } : node; | ||
| } | ||
| /** | ||
| * Lazy depth-first collection pass. Yields every non-null value returned by | ||
| * the visitor callbacks. Use `collect` for the eager array form. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids: string[] = [] | ||
| * for (const id of collectLazy<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * })) { | ||
| * ids.push(id) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function* collectLazy(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| const v = applyVisitor(node, visitor, parent); | ||
| if (v != null) yield v; | ||
| for (const child of getChildren(node, recurse)) yield* collectLazy(child, { | ||
| ...options, | ||
| parent: node | ||
| }); | ||
| } | ||
| /** | ||
| * Eager depth-first collection pass. Gathers every non-null value the visitor | ||
| * callbacks return into an array. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids = collect<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function collect(node, options) { | ||
| return Array.from(collectLazy(node, options)); | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "__exportAll", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return __exportAll; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "__name", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return __name; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "arrowFunctionDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return arrowFunctionDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "breakDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return breakDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "collect", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return collect; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "collectLazy", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return collectLazy; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "constDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return constDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "contentDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return contentDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createArrowFunction", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createArrowFunction; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createBreak", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createBreak; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createConst", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createConst; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createContent", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createContent; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createExport", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createExport; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createFile", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createFile; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createFunction", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createFunction; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createImport", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createImport; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createInput", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createInput; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createJsx", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createJsx; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createOperation", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createOperation; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createOutput", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createOutput; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createParameter", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createParameter; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createProperty", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createProperty; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createRequestBody", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createRequestBody; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createResponse", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createResponse; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createSchema", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createSchema; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createSource", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createSource; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createText", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createText; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createType", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createType; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "defineNode", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return defineNode; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "exportDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return exportDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "extractStringsFromNodes", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return extractStringsFromNodes; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "fileDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return fileDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "functionDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return functionDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "importDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return importDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "inputDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return inputDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isHttpOperationNode", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return isHttpOperationNode; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "jsxDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return jsxDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "narrowSchema", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return narrowSchema; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "nodeDefs", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return nodeDefs; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "operationDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return operationDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "optionality", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return optionality; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "outputDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return outputDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "parameterDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return parameterDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "pascalCase", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return pascalCase; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "propertyDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return propertyDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "requestBodyDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return requestBodyDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "responseDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return responseDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "schemaDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return schemaDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "schemaTypes", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return schemaTypes; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "sourceDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return sourceDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "textDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return textDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "transform", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return transform; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "typeDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return typeDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "visitorKeys", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return visitorKeys; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "walk", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return walk; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=visitor-CDa9Cn6x.cjs.map |
Sorry, the diff of this file is too big to display
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { hash } from "node:crypto"; | ||
| import path from "node:path"; | ||
| //#region src/constants.ts | ||
| const visitorDepths = { | ||
| shallow: "shallow", | ||
| deep: "deep" | ||
| }; | ||
| /** | ||
| * Schema type discriminators used by all AST schema nodes. | ||
| * | ||
| * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`). | ||
| */ | ||
| const schemaTypes = { | ||
| /** | ||
| * Text value. | ||
| */ | ||
| string: "string", | ||
| /** | ||
| * Floating-point number (`float`, `double`). | ||
| */ | ||
| number: "number", | ||
| /** | ||
| * Whole number (`int32`). Use `bigint` for `int64`. | ||
| */ | ||
| integer: "integer", | ||
| /** | ||
| * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`. | ||
| */ | ||
| bigint: "bigint", | ||
| /** | ||
| * Boolean value. | ||
| */ | ||
| boolean: "boolean", | ||
| /** | ||
| * Explicit null value. | ||
| */ | ||
| null: "null", | ||
| /** | ||
| * Any value (no type restriction). | ||
| */ | ||
| any: "any", | ||
| /** | ||
| * Unknown value (must be narrowed before usage). | ||
| */ | ||
| unknown: "unknown", | ||
| /** | ||
| * No return value (`void`). | ||
| */ | ||
| void: "void", | ||
| /** | ||
| * Object with named properties. | ||
| */ | ||
| object: "object", | ||
| /** | ||
| * Sequential list of items. | ||
| */ | ||
| array: "array", | ||
| /** | ||
| * Fixed-length list with position-specific items. | ||
| */ | ||
| tuple: "tuple", | ||
| /** | ||
| * "One of" multiple schema members. | ||
| */ | ||
| union: "union", | ||
| /** | ||
| * "All of" multiple schema members. | ||
| */ | ||
| intersection: "intersection", | ||
| /** | ||
| * Enum schema. | ||
| */ | ||
| enum: "enum", | ||
| /** | ||
| * Reference to another schema. | ||
| */ | ||
| ref: "ref", | ||
| /** | ||
| * Calendar date (for example `2026-03-24`). | ||
| */ | ||
| date: "date", | ||
| /** | ||
| * Date-time value (for example `2026-03-24T09:00:00Z`). | ||
| */ | ||
| datetime: "datetime", | ||
| /** | ||
| * Time-only value (for example `09:00:00`). | ||
| */ | ||
| time: "time", | ||
| /** | ||
| * UUID value. | ||
| */ | ||
| uuid: "uuid", | ||
| /** | ||
| * Email address value. | ||
| */ | ||
| email: "email", | ||
| /** | ||
| * URL value. | ||
| */ | ||
| url: "url", | ||
| /** | ||
| * IPv4 address value. | ||
| */ | ||
| ipv4: "ipv4", | ||
| /** | ||
| * IPv6 address value. | ||
| */ | ||
| ipv6: "ipv6", | ||
| /** | ||
| * Binary/blob value. | ||
| */ | ||
| blob: "blob", | ||
| /** | ||
| * Impossible value (`never`). | ||
| */ | ||
| never: "never" | ||
| }; | ||
| //#endregion | ||
| //#region src/guards.ts | ||
| /** | ||
| * Narrows a `SchemaNode` to the variant that matches `type`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const schema = createSchema({ type: 'string' }) | ||
| * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null | ||
| * ``` | ||
| */ | ||
| function narrowSchema(node, type) { | ||
| return node?.type === type ? node : null; | ||
| } | ||
| /** | ||
| * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * if (isHttpOperationNode(node)) { | ||
| * console.log(node.method, node.path) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function isHttpOperationNode(node) { | ||
| return node.protocol === "http" || node.method !== void 0 && node.path !== void 0; | ||
| } | ||
| //#endregion | ||
| //#region src/defineNode.ts | ||
| /** | ||
| * Visitor callback names, one per traversable node kind, in traversal order. | ||
| * Kept in sync with the keys of `Visitor` in `visitor.ts`. | ||
| */ | ||
| const visitorKeys = [ | ||
| "input", | ||
| "output", | ||
| "operation", | ||
| "schema", | ||
| "property", | ||
| "parameter", | ||
| "response" | ||
| ]; | ||
| /** | ||
| * Builds a type guard that matches nodes of the given `kind`. | ||
| */ | ||
| function isKind(kind) { | ||
| return (node) => node?.kind === kind; | ||
| } | ||
| /** | ||
| * Defines a node once and derives its `create` builder, `is` guard, and traversal | ||
| * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the | ||
| * `kind`, so node construction lives in one place without scattered `as` casts. | ||
| * | ||
| * @example Simple node | ||
| * ```ts | ||
| * const importDef = defineNode<ImportNode>({ kind: 'Import' }) | ||
| * const createImport = importDef.create | ||
| * ``` | ||
| * | ||
| * @example Node with a build hook | ||
| * ```ts | ||
| * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({ | ||
| * kind: 'Property', | ||
| * build: (props) => ({ ...props, required: props.required ?? false }), | ||
| * children: ['schema'], | ||
| * visitorKey: 'property', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineNode(config) { | ||
| const { kind, defaults, build, children, visitorKey } = config; | ||
| function create(input) { | ||
| const base = build ? build(input) : input; | ||
| return { | ||
| ...defaults, | ||
| ...base, | ||
| kind | ||
| }; | ||
| } | ||
| return { | ||
| kind, | ||
| create, | ||
| is: isKind(kind), | ||
| children, | ||
| visitorKey | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/code.ts | ||
| /** | ||
| * Definition for the {@link ConstNode}. | ||
| */ | ||
| const constDef = defineNode({ kind: "Const" }); | ||
| /** | ||
| * Definition for the {@link TypeNode}. | ||
| */ | ||
| const typeDef = defineNode({ kind: "Type" }); | ||
| /** | ||
| * Definition for the {@link FunctionNode}. | ||
| */ | ||
| const functionDef = defineNode({ kind: "Function" }); | ||
| /** | ||
| * Definition for the {@link ArrowFunctionNode}. | ||
| */ | ||
| const arrowFunctionDef = defineNode({ kind: "ArrowFunction" }); | ||
| /** | ||
| * Definition for the {@link TextNode}. | ||
| */ | ||
| const textDef = defineNode({ | ||
| kind: "Text", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Definition for the {@link BreakNode}. | ||
| */ | ||
| const breakDef = defineNode({ | ||
| kind: "Break", | ||
| build: () => ({}) | ||
| }); | ||
| /** | ||
| * Definition for the {@link JsxNode}. | ||
| */ | ||
| const jsxDef = defineNode({ | ||
| kind: "Jsx", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Creates a `ConstNode` representing a TypeScript `const` declaration. | ||
| * | ||
| * @example Exported constant with type and `as const` | ||
| * ```ts | ||
| * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true }) | ||
| * // export const pets: Pet[] = ... as const | ||
| * ``` | ||
| */ | ||
| const createConst = constDef.create; | ||
| /** | ||
| * Creates a `TypeNode` representing a TypeScript `type` alias declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createType({ name: 'Pet', export: true }) | ||
| * // export type Pet = ... | ||
| * ``` | ||
| */ | ||
| const createType = typeDef.create; | ||
| /** | ||
| * Creates a `FunctionNode` representing a TypeScript `function` declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' }) | ||
| * // export async function fetchPet(): Promise<Pet> { ... } | ||
| * ``` | ||
| */ | ||
| const createFunction = functionDef.create; | ||
| /** | ||
| * Creates an `ArrowFunctionNode` representing a TypeScript arrow function. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true }) | ||
| * // export const double = (n: number) => ... | ||
| * ``` | ||
| */ | ||
| const createArrowFunction = arrowFunctionDef.create; | ||
| /** | ||
| * Creates a {@link TextNode} representing a raw string fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createText('return fetch(id)') | ||
| * // { kind: 'Text', value: 'return fetch(id)' } | ||
| * ``` | ||
| */ | ||
| const createText = textDef.create; | ||
| /** | ||
| * Creates a {@link BreakNode} representing a line break in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createBreak() | ||
| * // { kind: 'Break' } | ||
| * ``` | ||
| */ | ||
| function createBreak() { | ||
| return breakDef.create(); | ||
| } | ||
| /** | ||
| * Creates a {@link JsxNode} representing a raw JSX fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createJsx('<>\n <a href={href}>Open</a>\n</>') | ||
| * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' } | ||
| * ``` | ||
| */ | ||
| const createJsx = jsxDef.create; | ||
| //#endregion | ||
| //#region src/nodes/content.ts | ||
| /** | ||
| * Definition for the {@link ContentNode}. | ||
| */ | ||
| const contentDef = defineNode({ | ||
| kind: "Content", | ||
| children: ["schema"] | ||
| }); | ||
| /** | ||
| * Creates a `ContentNode` for a single request-body or response content type. | ||
| */ | ||
| const createContent = contentDef.create; | ||
| //#endregion | ||
| //#region ../../internals/utils/src/casing.ts | ||
| /** | ||
| * Shared implementation for camelCase and PascalCase conversion. | ||
| * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons) | ||
| * and capitalizes each word according to `pascal`. | ||
| * | ||
| * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are. | ||
| */ | ||
| function toCamelOrPascal(text, pascal) { | ||
| return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => { | ||
| if (word.length > 1 && word === word.toUpperCase()) return word; | ||
| return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1); | ||
| }).join("").replace(/[^a-zA-Z0-9]/g, ""); | ||
| } | ||
| /** | ||
| * Converts `text` to PascalCase. | ||
| * | ||
| * @example Word boundaries | ||
| * `pascalCase('hello-world') // 'HelloWorld'` | ||
| * | ||
| * @example With a suffix | ||
| * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'` | ||
| */ | ||
| function pascalCase(text, { prefix = "", suffix = "" } = {}) { | ||
| return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true); | ||
| } | ||
| //#endregion | ||
| //#region ../../internals/utils/src/fs.ts | ||
| /** | ||
| * Strips the file extension from a path or file name. | ||
| * Only removes the last `.ext` segment when the dot is not part of a directory name. | ||
| * | ||
| * @example | ||
| * trimExtName('petStore.ts') // 'petStore' | ||
| * trimExtName('/src/models/pet.ts') // '/src/models/pet' | ||
| * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet' | ||
| * trimExtName('noExtension') // 'noExtension' | ||
| */ | ||
| function trimExtName(text) { | ||
| const dotIndex = text.lastIndexOf("."); | ||
| if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex); | ||
| return text; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/extractStringsFromNodes.ts | ||
| /** | ||
| * Extracts all string content from a `CodeNode` tree recursively. | ||
| * | ||
| * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`), | ||
| * and nested node content. Used to build the full source string for import filtering. | ||
| */ | ||
| function extractStringsFromNodes(nodes) { | ||
| if (!nodes?.length) return ""; | ||
| return nodes.map((node) => { | ||
| if (typeof node === "string") return node; | ||
| if (node.kind === "Text") return node.value; | ||
| if (node.kind === "Break") return ""; | ||
| if (node.kind === "Jsx") return node.value; | ||
| const parts = []; | ||
| if ("params" in node && node.params) parts.push(node.params); | ||
| if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics); | ||
| if ("returnType" in node && node.returnType) parts.push(node.returnType); | ||
| if ("type" in node && typeof node.type === "string") parts.push(node.type); | ||
| const nested = extractStringsFromNodes(node.nodes); | ||
| if (nested) parts.push(nested); | ||
| return parts.join("\n"); | ||
| }).filter(Boolean).join("\n"); | ||
| } | ||
| //#endregion | ||
| //#region src/utils/fileMerge.ts | ||
| function sourceKey(source) { | ||
| return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`; | ||
| } | ||
| function pathTypeKey(path, isTypeOnly) { | ||
| return `${path}:${isTypeOnly ?? false}`; | ||
| } | ||
| function exportKey(path, name, isTypeOnly, asAlias) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`; | ||
| } | ||
| function importKey(path, name, isTypeOnly) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}`; | ||
| } | ||
| /** | ||
| * Computes a multi-level sort key for exports and imports: | ||
| * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named. | ||
| */ | ||
| function sortKey(node) { | ||
| const isArray = Array.isArray(node.name) ? "1" : "0"; | ||
| const typeOnly = node.isTypeOnly ? "0" : "1"; | ||
| const hasName = node.name != null ? "1" : "0"; | ||
| const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? ""; | ||
| return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`; | ||
| } | ||
| /** | ||
| * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each | ||
| * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns | ||
| * the deduplicated array in original order. | ||
| */ | ||
| function combineSources(sources) { | ||
| const seen = /* @__PURE__ */ new Map(); | ||
| for (const source of sources) { | ||
| const key = sourceKey(source); | ||
| if (!seen.has(key)) seen.set(key, source); | ||
| } | ||
| return [...seen.values()]; | ||
| } | ||
| /** | ||
| * Merges `incoming` names into `existing`, preserving order and dropping duplicates. | ||
| * | ||
| * Shared by `combineExports` and `combineImports` for the same-path name-merge case. | ||
| */ | ||
| function mergeNameArrays(existing, incoming) { | ||
| const merged = new Set(existing); | ||
| for (const name of incoming) merged.add(name); | ||
| return [...merged]; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ExportNode` objects by path and type. | ||
| * | ||
| * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export. | ||
| * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array. | ||
| */ | ||
| function combineExports(exports) { | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = exports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| const { name, path, isTypeOnly, asAlias } = curr; | ||
| if (Array.isArray(name)) { | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name: [...new Set(name)] | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| const key = exportKey(path, name, isTypeOnly, asAlias); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ImportNode` objects, filtering out unused imports. | ||
| * | ||
| * Retains imports that are referenced in `source` or re-exported. Imports with the same path and | ||
| * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array. | ||
| */ | ||
| function combineImports(imports, exports, source) { | ||
| const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])); | ||
| const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName); | ||
| const importNameMemo = /* @__PURE__ */ new Map(); | ||
| const canonicalizeName = (n) => { | ||
| if (typeof n === "string") return n; | ||
| const key = `${n.propertyName}:${n.name ?? ""}`; | ||
| if (!importNameMemo.has(key)) importNameMemo.set(key, n); | ||
| return importNameMemo.get(key); | ||
| }; | ||
| const pathsWithUsedNamedImport = /* @__PURE__ */ new Set(); | ||
| for (const node of imports) { | ||
| if (!Array.isArray(node.name)) continue; | ||
| if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path); | ||
| } | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = imports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| if (curr.path === curr.root) continue; | ||
| const { path, isTypeOnly } = curr; | ||
| let { name } = curr; | ||
| if (Array.isArray(name)) { | ||
| name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName)); | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue; | ||
| const key = importKey(path, name, isTypeOnly); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/file.ts | ||
| /** | ||
| * Definition for the {@link ImportNode}. | ||
| */ | ||
| const importDef = defineNode({ kind: "Import" }); | ||
| /** | ||
| * Definition for the {@link ExportNode}. | ||
| */ | ||
| const exportDef = defineNode({ kind: "Export" }); | ||
| /** | ||
| * Definition for the {@link SourceNode}. | ||
| */ | ||
| const sourceDef = defineNode({ kind: "Source" }); | ||
| /** | ||
| * Definition for the {@link FileNode}. The fully resolved builder lives in | ||
| * `createFile`, so this definition only supplies the guard. | ||
| */ | ||
| const fileDef = defineNode({ kind: "File" }); | ||
| /** | ||
| * Creates an `ImportNode` representing a language-agnostic import/dependency declaration. | ||
| * | ||
| * @example Named import | ||
| * ```ts | ||
| * createImport({ name: ['useState'], path: 'react' }) | ||
| * // import { useState } from 'react' | ||
| * ``` | ||
| */ | ||
| const createImport = importDef.create; | ||
| /** | ||
| * Creates an `ExportNode` representing a language-agnostic export/public API declaration. | ||
| * | ||
| * @example Named export | ||
| * ```ts | ||
| * createExport({ name: ['Pet'], path: './Pet' }) | ||
| * // export { Pet } from './Pet' | ||
| * ``` | ||
| */ | ||
| const createExport = exportDef.create; | ||
| /** | ||
| * Creates a `SourceNode` representing a fragment of source code within a file. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true }) | ||
| * ``` | ||
| */ | ||
| const createSource = sourceDef.create; | ||
| /** | ||
| * Creates a fully resolved `FileNode` from a file input descriptor. | ||
| * | ||
| * Computes: | ||
| * - `id` SHA256 hash of the file path | ||
| * - `name` `baseName` without extension | ||
| * - `extname` extension extracted from `baseName` | ||
| * | ||
| * Deduplicates: | ||
| * - `sources` via `combineSources` | ||
| * - `exports` via `combineExports` | ||
| * - `imports` via `combineImports` (also filters unused imports) | ||
| * | ||
| * @throws {Error} when `baseName` has no extension. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'petStore.ts', | ||
| * path: 'src/models/petStore.ts', | ||
| * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })], | ||
| * imports: [createImport({ name: ['z'], path: 'zod' })], | ||
| * exports: [createExport({ name: ['Pet'], path: './petStore' })], | ||
| * }) | ||
| * // file.id = SHA256 hash of 'src/models/petStore.ts' | ||
| * // file.name = 'petStore' | ||
| * // file.extname = '.ts' | ||
| * ``` | ||
| * | ||
| * @example Copy a real file into the output verbatim | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'client.ts', | ||
| * path: 'src/gen/client.ts', | ||
| * copy: '/abs/path/to/templates/client.ts', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function createFile(input) { | ||
| const extname = path.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : ""); | ||
| if (!extname) throw new Error(`No extname found for ${input.baseName}`); | ||
| const source = (input.sources ?? []).flatMap((item) => item.nodes ?? []).map((node) => extractStringsFromNodes([node])).filter(Boolean).join("\n\n"); | ||
| const resolvedExports = input.exports?.length ? combineExports(input.exports) : []; | ||
| const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || void 0) : []; | ||
| const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name))); | ||
| const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName; | ||
| const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => { | ||
| if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp]; | ||
| const kept = imp.name.filter((item) => !localNames.has(nameOf(item))); | ||
| if (!kept.length) return []; | ||
| return [kept.length === imp.name.length ? imp : { | ||
| ...imp, | ||
| name: kept | ||
| }]; | ||
| }); | ||
| const resolvedSources = input.sources?.length ? combineSources(input.sources) : []; | ||
| return { | ||
| kind: "File", | ||
| ...input, | ||
| id: hash("sha256", input.path, "hex"), | ||
| name: trimExtName(input.baseName), | ||
| extname, | ||
| imports: resolvedImports, | ||
| exports: resolvedExports, | ||
| sources: resolvedSources, | ||
| meta: input.meta ?? {} | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/input.ts | ||
| /** | ||
| * Definition for the {@link InputNode}. | ||
| */ | ||
| const inputDef = defineNode({ | ||
| kind: "Input", | ||
| defaults: { | ||
| schemas: [], | ||
| operations: [], | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| } | ||
| }, | ||
| children: ["schemas", "operations"], | ||
| visitorKey: "input" | ||
| }); | ||
| /** | ||
| * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and | ||
| * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array | ||
| * `schemas`/`operations`. Both variants get the defaulted `meta`. | ||
| * | ||
| * @example Eager | ||
| * ```ts | ||
| * const input = createInput() | ||
| * // { kind: 'Input', schemas: [], operations: [] } | ||
| * ``` | ||
| * | ||
| * @example Streaming | ||
| * ```ts | ||
| * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } }) | ||
| * ``` | ||
| */ | ||
| function createInput(options = {}) { | ||
| const { stream, ...overrides } = options; | ||
| if (stream) return { | ||
| kind: "Input", | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| }, | ||
| ...overrides | ||
| }; | ||
| return inputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/requestBody.ts | ||
| /** | ||
| * Definition for the {@link RequestBodyNode}. Content entries are built upfront with | ||
| * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes. | ||
| */ | ||
| const requestBodyDef = defineNode({ | ||
| kind: "RequestBody", | ||
| children: ["content"] | ||
| }); | ||
| /** | ||
| * Creates a `RequestBodyNode`. | ||
| */ | ||
| const createRequestBody = requestBodyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/operation.ts | ||
| /** | ||
| * Definition for the {@link OperationNode}. HTTP operations (those carrying both | ||
| * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is | ||
| * normalized into a `RequestBodyNode`. | ||
| */ | ||
| const operationDef = defineNode({ | ||
| kind: "Operation", | ||
| build: (props) => { | ||
| const { requestBody, ...rest } = props; | ||
| const isHttp = rest.method !== void 0 && rest.path !== void 0; | ||
| return { | ||
| tags: [], | ||
| parameters: [], | ||
| responses: [], | ||
| ...rest, | ||
| ...isHttp ? { protocol: "http" } : {}, | ||
| requestBody: requestBody ? createRequestBody(requestBody) : void 0 | ||
| }; | ||
| }, | ||
| children: [ | ||
| "parameters", | ||
| "requestBody", | ||
| "responses" | ||
| ], | ||
| visitorKey: "operation" | ||
| }); | ||
| function createOperation(props) { | ||
| return operationDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/output.ts | ||
| /** | ||
| * Definition for the {@link OutputNode}. | ||
| */ | ||
| const outputDef = defineNode({ | ||
| kind: "Output", | ||
| defaults: { files: [] }, | ||
| visitorKey: "output" | ||
| }); | ||
| /** | ||
| * Creates an `OutputNode` with a stable default for `files`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const output = createOutput() | ||
| * // { kind: 'Output', files: [] } | ||
| * ``` | ||
| */ | ||
| function createOutput(overrides = {}) { | ||
| return outputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/optionality.ts | ||
| /** | ||
| * Generic JSON Schema optionality: a non-required field is optional, and a | ||
| * non-required nullable field is nullish. | ||
| */ | ||
| function optionality(schema, required) { | ||
| const nullable = schema.nullable ?? false; | ||
| return { | ||
| ...schema, | ||
| optional: !required && !nullable ? true : void 0, | ||
| nullish: !required && nullable ? true : void 0 | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/parameter.ts | ||
| /** | ||
| * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const parameterDef = defineNode({ | ||
| kind: "Parameter", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "parameter" | ||
| }); | ||
| /** | ||
| * Creates a `ParameterNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const param = createParameter({ | ||
| * name: 'petId', | ||
| * in: 'path', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string' }), | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createParameter = parameterDef.create; | ||
| //#endregion | ||
| //#region src/nodes/property.ts | ||
| /** | ||
| * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const propertyDef = defineNode({ | ||
| kind: "Property", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "property" | ||
| }); | ||
| /** | ||
| * Creates a `PropertyNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const property = createProperty({ | ||
| * name: 'status', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string', nullable: true }), | ||
| * }) | ||
| * // required=true, no optional/nullish | ||
| * ``` | ||
| */ | ||
| const createProperty = propertyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/response.ts | ||
| /** | ||
| * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional | ||
| * `mediaType`/`keysToOmit`) is normalized into one `content` entry. | ||
| */ | ||
| const responseDef = defineNode({ | ||
| kind: "Response", | ||
| build: (props) => { | ||
| const { schema, mediaType, keysToOmit, content, ...rest } = props; | ||
| const entries = content ?? (schema ? [createContent({ | ||
| contentType: mediaType ?? "application/json", | ||
| schema, | ||
| keysToOmit: keysToOmit ?? null | ||
| })] : void 0); | ||
| return { | ||
| ...rest, | ||
| content: entries | ||
| }; | ||
| }, | ||
| children: ["content"], | ||
| visitorKey: "response" | ||
| }); | ||
| /** | ||
| * Creates a `ResponseNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const response = createResponse({ | ||
| * statusCode: '200', | ||
| * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createResponse = responseDef.create; | ||
| //#endregion | ||
| //#region src/nodes/schema.ts | ||
| /** | ||
| * Maps schema `type` to its underlying `primitive`. | ||
| * Primitive types map to themselves and special string formats map to `'string'`. | ||
| * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`. | ||
| */ | ||
| const TYPE_TO_PRIMITIVE = { | ||
| string: "string", | ||
| number: "number", | ||
| integer: "integer", | ||
| bigint: "bigint", | ||
| boolean: "boolean", | ||
| null: "null", | ||
| any: "any", | ||
| unknown: "unknown", | ||
| void: "void", | ||
| never: "never", | ||
| object: "object", | ||
| array: "array", | ||
| date: "date", | ||
| uuid: "string", | ||
| email: "string", | ||
| url: "string", | ||
| datetime: "string", | ||
| time: "string" | ||
| }; | ||
| /** | ||
| * Definition for the {@link SchemaNode}. Object schemas default `properties` to an | ||
| * empty array, and `primitive` is inferred from `type` when not explicitly provided. | ||
| */ | ||
| const schemaDef = defineNode({ | ||
| kind: "Schema", | ||
| build: (props) => { | ||
| if (props.type === "object") return { | ||
| properties: [], | ||
| primitive: "object", | ||
| ...props | ||
| }; | ||
| return { | ||
| primitive: TYPE_TO_PRIMITIVE[props.type], | ||
| ...props | ||
| }; | ||
| }, | ||
| children: [ | ||
| "properties", | ||
| "items", | ||
| "members", | ||
| "additionalProperties" | ||
| ], | ||
| visitorKey: "schema" | ||
| }); | ||
| function createSchema(props) { | ||
| return schemaDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/registry.ts | ||
| /** | ||
| * Every node definition. Adding a node means adding its `defineNode` to one | ||
| * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it. | ||
| */ | ||
| const nodeDefs = [ | ||
| inputDef, | ||
| outputDef, | ||
| operationDef, | ||
| requestBodyDef, | ||
| contentDef, | ||
| responseDef, | ||
| schemaDef, | ||
| propertyDef, | ||
| parameterDef, | ||
| constDef, | ||
| typeDef, | ||
| functionDef, | ||
| arrowFunctionDef, | ||
| textDef, | ||
| breakDef, | ||
| jsxDef, | ||
| importDef, | ||
| exportDef, | ||
| sourceDef, | ||
| fileDef | ||
| ]; | ||
| //#endregion | ||
| //#region src/visitor.ts | ||
| /** | ||
| * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`). | ||
| * Derived from each definition's `children`. | ||
| */ | ||
| const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : [])); | ||
| /** | ||
| * Maps a node kind to the matching visitor callback name. Derived from each | ||
| * definition's `visitorKey`. | ||
| */ | ||
| const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : [])); | ||
| /** | ||
| * Creates a small async concurrency limiter. | ||
| * | ||
| * At most `concurrency` tasks are in flight at once. Extra tasks are queued. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const limit = createLimit(2) | ||
| * for (const task of [taskA, taskB, taskC]) { | ||
| * await limit(() => task()) | ||
| * } | ||
| * // only 2 tasks run at the same time | ||
| * ``` | ||
| */ | ||
| function createLimit(concurrency) { | ||
| let active = 0; | ||
| const queue = []; | ||
| function next() { | ||
| if (active < concurrency && queue.length > 0) { | ||
| active++; | ||
| queue.shift()(); | ||
| } | ||
| } | ||
| return function limit(fn) { | ||
| return new Promise((resolve, reject) => { | ||
| queue.push(() => { | ||
| Promise.resolve(fn()).then(resolve, reject).finally(() => { | ||
| active--; | ||
| next(); | ||
| }); | ||
| }); | ||
| next(); | ||
| }); | ||
| }; | ||
| } | ||
| const visitorKeysByKind = VISITOR_KEYS; | ||
| /** | ||
| * Returns `true` when `value` is an AST node (an object carrying a `kind`). | ||
| */ | ||
| function isNode(value) { | ||
| return typeof value === "object" && value !== null && "kind" in value; | ||
| } | ||
| /** | ||
| * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}. | ||
| * | ||
| * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const children = getChildren(operationNode, true) | ||
| * // returns parameters, the request body, and responses | ||
| * ``` | ||
| */ | ||
| function* getChildren(node, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return; | ||
| const record = node; | ||
| for (const key of keys) { | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) if (isNode(item)) yield item; | ||
| } else if (isNode(value)) yield value; | ||
| } | ||
| } | ||
| /** | ||
| * Runs the visitor callback that matches `node.kind` with the traversal | ||
| * context. The result is a replacement node, a collected value, or `undefined` | ||
| * when no callback is registered for the kind. | ||
| * | ||
| * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives | ||
| * in one place. `TResult` is the caller's expected return: the same node type | ||
| * for `transform`, the collected value type for `collectLazy`, ignored for `walk`. | ||
| */ | ||
| function applyVisitor(node, visitor, parent) { | ||
| const key = VISITOR_KEY_BY_KIND[node.kind]; | ||
| if (!key) return void 0; | ||
| const fn = visitor[key]; | ||
| return fn?.(node, { parent }); | ||
| } | ||
| /** | ||
| * Async depth-first traversal for side effects. Visitor return values are | ||
| * ignored. Use `transform` when you want to rewrite nodes. | ||
| * | ||
| * Sibling nodes at each depth run concurrently up to `options.concurrency` | ||
| * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor | ||
| * work. Lower values reduce memory pressure. | ||
| * | ||
| * @example Log every operation | ||
| * ```ts | ||
| * await walk(root, { | ||
| * operation(node) { | ||
| * console.log(node.operationId) | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @example Only visit the root node | ||
| * ```ts | ||
| * await walk(root, { depth: 'shallow', input: () => {} }) | ||
| * ``` | ||
| */ | ||
| async function walk(node, options) { | ||
| return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0); | ||
| } | ||
| async function _walk(node, visitor, recurse, limit, parent) { | ||
| await limit(() => applyVisitor(node, visitor, parent)); | ||
| const children = Array.from(getChildren(node, recurse)); | ||
| if (children.length === 0) return; | ||
| await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node))); | ||
| } | ||
| function transform(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse); | ||
| } | ||
| /** | ||
| * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming | ||
| * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact. | ||
| * `Schema` children are skipped in shallow mode. | ||
| */ | ||
| function transformChildren(node, options, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return node; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return node; | ||
| const record = node; | ||
| const childOptions = { | ||
| ...options, | ||
| parent: node | ||
| }; | ||
| let updates; | ||
| for (const key of keys) { | ||
| if (!(key in record)) continue; | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| let changed = false; | ||
| const mapped = value.map((item) => { | ||
| if (!isNode(item)) return item; | ||
| const next = transform(item, childOptions); | ||
| if (next !== item) changed = true; | ||
| return next; | ||
| }); | ||
| if (changed) (updates ??= {})[key] = mapped; | ||
| } else if (isNode(value)) { | ||
| const next = transform(value, childOptions); | ||
| if (next !== value) (updates ??= {})[key] = next; | ||
| } | ||
| } | ||
| return updates ? { | ||
| ...node, | ||
| ...updates | ||
| } : node; | ||
| } | ||
| /** | ||
| * Lazy depth-first collection pass. Yields every non-null value returned by | ||
| * the visitor callbacks. Use `collect` for the eager array form. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids: string[] = [] | ||
| * for (const id of collectLazy<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * })) { | ||
| * ids.push(id) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function* collectLazy(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| const v = applyVisitor(node, visitor, parent); | ||
| if (v != null) yield v; | ||
| for (const child of getChildren(node, recurse)) yield* collectLazy(child, { | ||
| ...options, | ||
| parent: node | ||
| }); | ||
| } | ||
| /** | ||
| * Eager depth-first collection pass. Gathers every non-null value the visitor | ||
| * callbacks return into an array. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids = collect<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function collect(node, options) { | ||
| return Array.from(collectLazy(node, options)); | ||
| } | ||
| //#endregion | ||
| export { schemaTypes as $, sourceDef as A, createConst as B, createExport as C, exportDef as D, createSource as E, arrowFunctionDef as F, functionDef as G, createJsx as H, breakDef as I, typeDef as J, jsxDef as K, constDef as L, pascalCase as M, contentDef as N, fileDef as O, createContent as P, narrowSchema as Q, createArrowFunction as R, inputDef as S, createImport as T, createText as U, createFunction as V, createType as W, visitorKeys as X, defineNode as Y, isHttpOperationNode as Z, createOperation as _, nodeDefs as a, requestBodyDef as b, createResponse as c, propertyDef as d, createParameter as f, outputDef as g, createOutput as h, walk as i, extractStringsFromNodes as j, importDef as k, responseDef as l, optionality as m, collectLazy as n, createSchema as o, parameterDef as p, textDef as q, transform as r, schemaDef as s, collect as t, createProperty as u, operationDef as v, createFile as w, createInput as x, createRequestBody as y, createBreak as z }; | ||
| //# sourceMappingURL=visitor-Ns-njjbG.js.map |
Sorry, the diff of this file is too big to display
+2
-2
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const require_visitor = require("./visitor-ChiWLwlh.cjs"); | ||
| const require_defineMacro = require("./defineMacro-CI0a-SWY.cjs"); | ||
| const require_visitor = require("./visitor-CDa9Cn6x.cjs"); | ||
| const require_defineMacro = require("./defineMacro-C58x6uaa.cjs"); | ||
| //#region src/defineDialect.ts | ||
@@ -5,0 +5,0 @@ /** |
+2
-2
@@ -61,3 +61,3 @@ import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js"; | ||
| */ | ||
| declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & { | ||
| declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "properties" | "kind" | "primitive"> & { | ||
| properties?: Array<PropertyNode>; | ||
@@ -129,3 +129,3 @@ primitive?: "object"; | ||
| keysToOmit?: Array<string> | null; | ||
| }> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "kind" | "name" | "schema" | "in">>> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[]; | ||
| }> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "name" | "kind" | "schema" | "in">>> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[]; | ||
| declare namespace exports_d_exports { | ||
@@ -132,0 +132,0 @@ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk }; |
+2
-2
| import { t as __exportAll } from "./rolldown-runtime-CNktS9qV.js"; | ||
| import { A as sourceDef, B as createConst, C as createExport, D as exportDef, E as createSource, F as arrowFunctionDef, G as functionDef, H as createJsx, I as breakDef, J as typeDef, K as jsxDef, L as constDef, N as contentDef, O as fileDef, P as createContent, Q as narrowSchema, R as createArrowFunction, S as inputDef, T as createImport, U as createText, V as createFunction, W as createType, Y as defineNode, Z as isHttpOperationNode, _ as createOperation, a as nodeDefs, b as requestBodyDef, c as createResponse, d as propertyDef, et as schemaTypes, f as createParameter, g as outputDef, h as createOutput, i as walk, k as importDef, l as responseDef, m as optionality, o as createSchema, p as parameterDef, q as textDef, r as transform, s as schemaDef, t as collect, u as createProperty, v as operationDef, w as createFile, x as createInput, y as createRequestBody, z as createBreak } from "./visitor-CeO-upp5.js"; | ||
| import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-B5Plh1uq.js"; | ||
| import { $ as schemaTypes, A as sourceDef, B as createConst, C as createExport, D as exportDef, E as createSource, F as arrowFunctionDef, G as functionDef, H as createJsx, I as breakDef, J as typeDef, K as jsxDef, L as constDef, N as contentDef, O as fileDef, P as createContent, Q as narrowSchema, R as createArrowFunction, S as inputDef, T as createImport, U as createText, V as createFunction, W as createType, Y as defineNode, Z as isHttpOperationNode, _ as createOperation, a as nodeDefs, b as requestBodyDef, c as createResponse, d as propertyDef, f as createParameter, g as outputDef, h as createOutput, i as walk, k as importDef, l as responseDef, m as optionality, o as createSchema, p as parameterDef, q as textDef, r as transform, s as schemaDef, t as collect, u as createProperty, v as operationDef, w as createFile, x as createInput, y as createRequestBody, z as createBreak } from "./visitor-Ns-njjbG.js"; | ||
| import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-Zagno12u.js"; | ||
| //#region src/defineDialect.ts | ||
@@ -5,0 +5,0 @@ /** |
+3
-3
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const require_visitor = require("./visitor-ChiWLwlh.cjs"); | ||
| const require_defineMacro = require("./defineMacro-CI0a-SWY.cjs"); | ||
| const require_refs = require("./refs-Dga4lfv7.cjs"); | ||
| const require_visitor = require("./visitor-CDa9Cn6x.cjs"); | ||
| const require_defineMacro = require("./defineMacro-C58x6uaa.cjs"); | ||
| const require_refs = require("./refs-DhraOHHv.cjs"); | ||
| //#region src/macros/macroDiscriminatorEnum.ts | ||
@@ -6,0 +6,0 @@ /** |
+3
-3
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { Q as narrowSchema, o as createSchema, u as createProperty } from "./visitor-CeO-upp5.js"; | ||
| import { r as defineMacro } from "./defineMacro-B5Plh1uq.js"; | ||
| import { n as enumPropName } from "./refs-1t3qfkLE.js"; | ||
| import { Q as narrowSchema, o as createSchema, u as createProperty } from "./visitor-Ns-njjbG.js"; | ||
| import { r as defineMacro } from "./defineMacro-Zagno12u.js"; | ||
| import { n as enumPropName } from "./refs-DliAPaUa.js"; | ||
| //#region src/macros/macroDiscriminatorEnum.ts | ||
@@ -6,0 +6,0 @@ /** |
+3
-3
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const require_visitor = require("./visitor-ChiWLwlh.cjs"); | ||
| const require_refs = require("./refs-Dga4lfv7.cjs"); | ||
| const require_visitor = require("./visitor-CDa9Cn6x.cjs"); | ||
| const require_refs = require("./refs-DhraOHHv.cjs"); | ||
| //#region ../../internals/utils/src/promise.ts | ||
@@ -200,3 +200,3 @@ /** | ||
| if (!text) return ""; | ||
| return text.split("\n").map((line) => line.trim() ? `${require_visitor.INDENT}${line}` : "").join("\n"); | ||
| return text.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n"); | ||
| } | ||
@@ -203,0 +203,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"utils.cjs","names":["INDENT","narrowSchema","createSchema","resolveRefName","collectLazy"],"sources":["../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/codegen.ts","../src/utils/schemaMerge.ts","../src/utils/strings.ts","../src/utils/schemaGraph.ts","../src/utils/schemaTraversal.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\n/**\n * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no\n * comments.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Entries that are themselves multi-line objects indent\n * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Used for member lists such\n * as `z.union([…])` and `z.array([…])`.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n","import { narrowSchema } from '../guards.ts'\nimport { createSchema, type SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.\n *\n * Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated\n * code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { memoize } from '@internals/utils'\nimport type { OperationNode, SchemaNode } from '../nodes/index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\n/**\n * Memoized inner pass that walks a single node and returns the names of every schema it references.\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\n/**\n * Collects the names of every ref found anywhere inside a node's own subtree.\n *\n * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`\n * to accumulate names from several nodes into one set.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Memoized two-level cache keyed first on the operations array, then on the schemas array.\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Stops at the first matching circular ref.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import type { ArraySchemaNode, IntersectionSchemaNode, ObjectSchemaNode, PropertyNode, SchemaNode, UnionSchemaNode } from '../nodes/index.ts'\nimport { objectKey } from './codegen.ts'\n\n/**\n * Converts a child schema to printer output. Plugins instantiate it with their own output type:\n * `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's\n * `this.transform` fits directly, so its `null` for an empty result carries through to `output`.\n */\nexport type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput\n\n/**\n * A union or intersection member, or an array or tuple item, paired with its transformed output.\n */\nexport type MappedSchema<TOutput> = {\n /**\n * The original child schema, kept so the printer can read its metadata for leaf formatting.\n */\n schema: SchemaNode\n /**\n * The child schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * An object property paired with its transformed output.\n */\nexport type MappedProperty<TOutput> = {\n /**\n * The property name as written on the schema, before any identifier quoting.\n */\n name: string\n /**\n * The original property node, kept so the printer can read `required`, `schema`, and metadata.\n */\n property: PropertyNode\n /**\n * The property schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * Maps each property of an object schema to its transformed output. Pairs every result with the\n * original property so the printer keeps full control over modifiers, getters, and key syntax.\n *\n * @example\n * ```ts\n * const entries = mapSchemaProperties(node, (schema) => this.transform(schema))\n * // entries: [{ name: 'id', property, output: 'z.number()' }, ...]\n * ```\n */\nexport function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>> {\n return node.properties.map((property) => ({ name: property.name, property, output: transform(property.schema) }))\n}\n\n/**\n * Maps each member of a union or intersection schema to its transformed output, pairing every\n * result with the original member.\n */\nexport function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.members ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Maps each item of an array or tuple schema to its transformed output, pairing every result with\n * the original item.\n */\nexport function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.items ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key\n * is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation\n * of a recursive schema until first access.\n *\n * @example\n * ```ts\n * lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })\n * // \"get parent() { return z.lazy(() => Pet) }\"\n * ```\n */\nexport function lazyGetter({ name, body }: { name: string; body: string }): string {\n return `get ${objectKey(name)}() { return ${body} }`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;AC9DA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAU;;;;;;;;;;;AA8BV,SAAgB,eAAe,MAAuB;CACpD,IAAI,CAAC,QAAQ,cAAc,IAAI,IAAiB,GAC9C,OAAO;CAET,OAAO,aAAa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S,eAAe,gBAAgB,IAAI,IAAI,IAAI,OAAO;CAC5E,EACF,CAAC,GACC,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;AC5HA,SAAgB,oBAA6B,MAAwB,WAAqE;CACxI,OAAO,KAAK,WAAW,KAAK,cAAc;EAAE,MAAM,SAAS;EAAM;EAAU,QAAQ,UAAU,SAAS,MAAM;CAAE,EAAE;AAClH;;;;;AAMA,SAAgB,iBAA0B,MAAgD,WAAmE;CAC3J,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACrF;;;;;AAMA,SAAgB,eAAwB,MAAuB,WAAmE;CAChI,QAAQ,KAAK,SAAS,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACnF;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,MAAM,QAAgD;CACjF,OAAO,OAAO,UAAU,IAAI,EAAE,cAAc,KAAK;AACnD"} | ||
| {"version":3,"file":"utils.cjs","names":["narrowSchema","createSchema","resolveRefName","collectLazy"],"sources":["../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/codegen.ts","../src/utils/schemaMerge.ts","../src/utils/strings.ts","../src/utils/schemaGraph.ts","../src/utils/schemaTraversal.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\n/**\n * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no\n * comments.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Entries that are themselves multi-line objects indent\n * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Used for member lists such\n * as `z.union([…])` and `z.array([…])`.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n","import { narrowSchema } from '../guards.ts'\nimport { createSchema, type SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.\n *\n * Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated\n * code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { memoize } from '@internals/utils'\nimport type { OperationNode, SchemaNode } from '../nodes/index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\n/**\n * Memoized inner pass that walks a single node and returns the names of every schema it references.\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\n/**\n * Collects the names of every ref found anywhere inside a node's own subtree.\n *\n * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`\n * to accumulate names from several nodes into one set.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Memoized two-level cache keyed first on the operations array, then on the schemas array.\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Stops at the first matching circular ref.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import type { ArraySchemaNode, IntersectionSchemaNode, ObjectSchemaNode, PropertyNode, SchemaNode, UnionSchemaNode } from '../nodes/index.ts'\nimport { objectKey } from './codegen.ts'\n\n/**\n * Converts a child schema to printer output. Plugins instantiate it with their own output type:\n * `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's\n * `this.transform` fits directly, so its `null` for an empty result carries through to `output`.\n */\nexport type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput\n\n/**\n * A union or intersection member, or an array or tuple item, paired with its transformed output.\n */\nexport type MappedSchema<TOutput> = {\n /**\n * The original child schema, kept so the printer can read its metadata for leaf formatting.\n */\n schema: SchemaNode\n /**\n * The child schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * An object property paired with its transformed output.\n */\nexport type MappedProperty<TOutput> = {\n /**\n * The property name as written on the schema, before any identifier quoting.\n */\n name: string\n /**\n * The original property node, kept so the printer can read `required`, `schema`, and metadata.\n */\n property: PropertyNode\n /**\n * The property schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * Maps each property of an object schema to its transformed output. Pairs every result with the\n * original property so the printer keeps full control over modifiers, getters, and key syntax.\n *\n * @example\n * ```ts\n * const entries = mapSchemaProperties(node, (schema) => this.transform(schema))\n * // entries: [{ name: 'id', property, output: 'z.number()' }, ...]\n * ```\n */\nexport function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>> {\n return node.properties.map((property) => ({ name: property.name, property, output: transform(property.schema) }))\n}\n\n/**\n * Maps each member of a union or intersection schema to its transformed output, pairing every\n * result with the original member.\n */\nexport function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.members ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Maps each item of an array or tuple schema to its transformed output, pairing every result with\n * the original item.\n */\nexport function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.items ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key\n * is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation\n * of a recursive schema until first access.\n *\n * @example\n * ```ts\n * lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })\n * // \"get parent() { return z.lazy(() => Pet) }\"\n * ```\n */\nexport function lazyGetter({ name, body }: { name: string; body: string }): string {\n return `get ${objectKey(name)}() { return ${body} }`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;AC9DA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAU;;;;;;;;;;;AA8BV,SAAgB,eAAe,MAAuB;CACpD,IAAI,CAAC,QAAQ,cAAc,IAAI,IAAiB,GAC9C,OAAO;CAET,OAAO,aAAa,IAAI;AAC1B;;;;;;;;;;;;;;AAeA,SAAgB,aAAa,MAAuB;CAClD,OAAO,6BAA6B,KAAK,IAAI;AAC/C;;;;;;;;;;;;;AChIA,SAAgB,YAAY,OAA6D;CACvF,IAA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KAAK,cAAc;EAAE,MAAM,SAAS;EAAM;EAAU,QAAQ,UAAU,SAAS,MAAM;CAAE,EAAE;AAClH;;;;;AAMA,SAAgB,iBAA0B,MAAgD,WAAmE;CAC3J,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACrF;;;;;AAMA,SAAgB,eAAwB,MAAuB,WAAmE;CAChI,QAAQ,KAAK,SAAS,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACnF;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,MAAM,QAAgD;CACjF,OAAO,OAAO,UAAU,IAAI,EAAE,cAAc,KAAK;AACnD"} |
+3
-3
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { $ as INDENT, Q as narrowSchema, j as extractStringsFromNodes, n as collectLazy, o as createSchema, t as collect } from "./visitor-CeO-upp5.js"; | ||
| import { a as resolveRefName, i as isStringType, n as enumPropName, o as syncSchemaRef, r as extractRefName, t as childName } from "./refs-1t3qfkLE.js"; | ||
| import { Q as narrowSchema, j as extractStringsFromNodes, n as collectLazy, o as createSchema, t as collect } from "./visitor-Ns-njjbG.js"; | ||
| import { a as resolveRefName, i as isStringType, n as enumPropName, o as syncSchemaRef, r as extractRefName, t as childName } from "./refs-DliAPaUa.js"; | ||
| //#region ../../internals/utils/src/promise.ts | ||
@@ -200,3 +200,3 @@ /** | ||
| if (!text) return ""; | ||
| return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n"); | ||
| return text.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n"); | ||
| } | ||
@@ -203,0 +203,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"utils.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/codegen.ts","../src/utils/schemaMerge.ts","../src/utils/strings.ts","../src/utils/schemaGraph.ts","../src/utils/schemaTraversal.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\n/**\n * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no\n * comments.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Entries that are themselves multi-line objects indent\n * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Used for member lists such\n * as `z.union([…])` and `z.array([…])`.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n","import { narrowSchema } from '../guards.ts'\nimport { createSchema, type SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.\n *\n * Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated\n * code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { memoize } from '@internals/utils'\nimport type { OperationNode, SchemaNode } from '../nodes/index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\n/**\n * Memoized inner pass that walks a single node and returns the names of every schema it references.\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\n/**\n * Collects the names of every ref found anywhere inside a node's own subtree.\n *\n * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`\n * to accumulate names from several nodes into one set.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Memoized two-level cache keyed first on the operations array, then on the schemas array.\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Stops at the first matching circular ref.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import type { ArraySchemaNode, IntersectionSchemaNode, ObjectSchemaNode, PropertyNode, SchemaNode, UnionSchemaNode } from '../nodes/index.ts'\nimport { objectKey } from './codegen.ts'\n\n/**\n * Converts a child schema to printer output. Plugins instantiate it with their own output type:\n * `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's\n * `this.transform` fits directly, so its `null` for an empty result carries through to `output`.\n */\nexport type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput\n\n/**\n * A union or intersection member, or an array or tuple item, paired with its transformed output.\n */\nexport type MappedSchema<TOutput> = {\n /**\n * The original child schema, kept so the printer can read its metadata for leaf formatting.\n */\n schema: SchemaNode\n /**\n * The child schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * An object property paired with its transformed output.\n */\nexport type MappedProperty<TOutput> = {\n /**\n * The property name as written on the schema, before any identifier quoting.\n */\n name: string\n /**\n * The original property node, kept so the printer can read `required`, `schema`, and metadata.\n */\n property: PropertyNode\n /**\n * The property schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * Maps each property of an object schema to its transformed output. Pairs every result with the\n * original property so the printer keeps full control over modifiers, getters, and key syntax.\n *\n * @example\n * ```ts\n * const entries = mapSchemaProperties(node, (schema) => this.transform(schema))\n * // entries: [{ name: 'id', property, output: 'z.number()' }, ...]\n * ```\n */\nexport function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>> {\n return node.properties.map((property) => ({ name: property.name, property, output: transform(property.schema) }))\n}\n\n/**\n * Maps each member of a union or intersection schema to its transformed output, pairing every\n * result with the original member.\n */\nexport function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.members ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Maps each item of an array or tuple schema to its transformed output, pairing every result with\n * the original item.\n */\nexport function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.items ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key\n * is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation\n * of a recursive schema until first access.\n *\n * @example\n * ```ts\n * lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })\n * // \"get parent() { return z.lazy(() => Pet) }\"\n * ```\n */\nexport function lazyGetter({ name, body }: { name: string; body: string }): string {\n return `get ${objectKey(name)}() { return ${body} }`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;AC9DA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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ACT,IAAI,CAAC,QAAQ,gBAAgB,SAAS,GAAG,OAAO;CAEhD,KAAK,MAAM,KAAK,YAAkB,MAAM,EACtC,OAAO,OAAO;EACZ,IAAI,MAAM,SAAS,OAAO,OAAO;EACjC,MAAM,OAAO,eAAe,KAAK;EACjC,OAAO,QAAQ,SAAS,eAAe,gBAAgB,IAAI,IAAI,IAAI,OAAO;CAC5E,EACF,CAAC,GACC,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;AC5HA,SAAgB,oBAA6B,MAAwB,WAAqE;CACxI,OAAO,KAAK,WAAW,KAAK,cAAc;EAAE,MAAM,SAAS;EAAM;EAAU,QAAQ,UAAU,SAAS,MAAM;CAAE,EAAE;AAClH;;;;;AAMA,SAAgB,iBAA0B,MAAgD,WAAmE;CAC3J,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACrF;;;;;AAMA,SAAgB,eAAwB,MAAuB,WAAmE;CAChI,QAAQ,KAAK,SAAS,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACnF;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,MAAM,QAAgD;CACjF,OAAO,OAAO,UAAU,IAAI,EAAE,cAAc,KAAK;AACnD"} | ||
| {"version":3,"file":"utils.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/codegen.ts","../src/utils/schemaMerge.ts","../src/utils/strings.ts","../src/utils/schemaGraph.ts","../src/utils/schemaTraversal.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\n/**\n * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no\n * comments.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Entries that are themselves multi-line objects indent\n * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Used for member lists such\n * as `z.union([…])` and `z.array([…])`.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n","import { narrowSchema } from '../guards.ts'\nimport { createSchema, type SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.\n *\n * Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated\n * code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { memoize } from '@internals/utils'\nimport type { OperationNode, SchemaNode } from '../nodes/index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\n/**\n * Memoized inner pass that walks a single node and returns the names of every schema it references.\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\n/**\n * Collects the names of every ref found anywhere inside a node's own subtree.\n *\n * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`\n * to accumulate names from several nodes into one set.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Memoized two-level cache keyed first on the operations array, then on the schemas array.\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Stops at the first matching circular ref.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import type { ArraySchemaNode, IntersectionSchemaNode, ObjectSchemaNode, PropertyNode, SchemaNode, UnionSchemaNode } from '../nodes/index.ts'\nimport { objectKey } from './codegen.ts'\n\n/**\n * Converts a child schema to printer output. Plugins instantiate it with their own output type:\n * `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's\n * `this.transform` fits directly, so its `null` for an empty result carries through to `output`.\n */\nexport type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput\n\n/**\n * A union or intersection member, or an array or tuple item, paired with its transformed output.\n */\nexport type MappedSchema<TOutput> = {\n /**\n * The original child schema, kept so the printer can read its metadata for leaf formatting.\n */\n schema: SchemaNode\n /**\n * The child schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * An object property paired with its transformed output.\n */\nexport type MappedProperty<TOutput> = {\n /**\n * The property name as written on the schema, before any identifier quoting.\n */\n name: string\n /**\n * The original property node, kept so the printer can read `required`, `schema`, and metadata.\n */\n property: PropertyNode\n /**\n * The property schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * Maps each property of an object schema to its transformed output. Pairs every result with the\n * original property so the printer keeps full control over modifiers, getters, and key syntax.\n *\n * @example\n * ```ts\n * const entries = mapSchemaProperties(node, (schema) => this.transform(schema))\n * // entries: [{ name: 'id', property, output: 'z.number()' }, ...]\n * ```\n */\nexport function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>> {\n return node.properties.map((property) => ({ name: property.name, property, output: transform(property.schema) }))\n}\n\n/**\n * Maps each member of a union or intersection schema to its transformed output, pairing every\n * result with the original member.\n */\nexport function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.members ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Maps each item of an array or tuple schema to its transformed output, pairing every result with\n * the original item.\n */\nexport function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.items ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key\n * is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation\n * of a recursive schema until first access.\n *\n * @example\n * ```ts\n * lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })\n * // \"get parent() { return z.lazy(() => Pet) }\"\n * ```\n */\nexport function lazyGetter({ name, body }: { name: string; body: string }): string {\n return `get ${objectKey(name)}() { return ${body} }`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;AC9DA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAU;;;;;;;;;;;AA8BV,SAAgB,eAAe,MAAuB;CACpD,IAAI,CAAC,QAAQ,cAAc,IAAI,IAAiB,GAC9C,OAAO;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GT,OAAO;AACT;;;;;;;;;;;;;AC5HA,SAAgB,oBAA6B,MAAwB,WAAqE;CACxI,OAAO,KAAK,WAAW,KAAK,cAAc;EAAE,MAAM,SAAS;EAAM;EAAU,QAAQ,UAAU,SAAS,MAAM;CAAE,EAAE;AAClH;;;;;AAMA,SAAgB,iBAA0B,MAAgD,WAAmE;CAC3J,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACrF;;;;;AAMA,SAAgB,eAAwB,MAAuB,WAAmE;CAChI,QAAQ,KAAK,SAAS,CAAC,EAAA,CAAG,KAAK,YAAY;EAAE;EAAQ,QAAQ,UAAU,MAAM;CAAE,EAAE;AACnF;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,MAAM,QAAgD;CACjF,OAAO,OAAO,UAAU,IAAI,EAAE,cAAc,KAAK;AACnD"} |
+1
-1
| { | ||
| "name": "@kubb/ast", | ||
| "version": "5.0.0-beta.73", | ||
| "version": "5.0.0-beta.74", | ||
| "description": "Spec-agnostic AST layer for Kubb. Defines the node tree, visitor pattern, factory functions, and type guards used across all code generation plugins.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { X as visitorKeys, r as transform } from "./visitor-CeO-upp5.js"; | ||
| //#region src/defineMacro.ts | ||
| /** | ||
| * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain | ||
| * list keeps its authored order. | ||
| */ | ||
| function enforceWeight(enforce) { | ||
| if (enforce === "pre") return 0; | ||
| if (enforce === "post") return 2; | ||
| return 1; | ||
| } | ||
| /** | ||
| * Types a macro for inference and a single construction site, mirroring `definePlugin`. | ||
| * Adds no runtime behavior. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const macroUntagged = defineMacro({ | ||
| * name: 'untagged', | ||
| * operation(node) { | ||
| * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] } | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineMacro(macro) { | ||
| return macro; | ||
| } | ||
| /** | ||
| * Runs every macro's callback for one node kind in order, chaining the result so each macro sees | ||
| * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the | ||
| * original reference (structural sharing). | ||
| */ | ||
| function chain({ macros, key, node, context }) { | ||
| let current = node; | ||
| for (const macro of macros) { | ||
| const callback = macro[key]; | ||
| if (!callback) continue; | ||
| if (macro.when && !macro.when(current)) continue; | ||
| const next = callback(current, context); | ||
| if (next != null) current = next; | ||
| } | ||
| return current === node ? void 0 : current; | ||
| } | ||
| /** | ||
| * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin | ||
| * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied | ||
| * sequentially per node so later macros see earlier output. This differs from a plain visitor, which | ||
| * has no names, ordering, or composition. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum]) | ||
| * const next = transform(root, visitor) | ||
| * ``` | ||
| */ | ||
| function composeMacros(macros) { | ||
| const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce)); | ||
| const visitor = {}; | ||
| for (const key of visitorKeys) { | ||
| if (!ordered.some((macro) => typeof macro[key] === "function")) continue; | ||
| const callback = (node, context) => chain({ | ||
| macros: ordered, | ||
| key, | ||
| node, | ||
| context | ||
| }); | ||
| visitor[key] = callback; | ||
| } | ||
| return visitor; | ||
| } | ||
| /** | ||
| * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s | ||
| * structural sharing, so an empty or no-op macro list returns the same reference. Pass | ||
| * `depth: 'shallow'` to rewrite the root node only. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const next = applyMacros(root, [macroIntegerToString]) | ||
| * ``` | ||
| * | ||
| * @example Apply to the root node only | ||
| * ```ts | ||
| * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' }) | ||
| * ``` | ||
| */ | ||
| function applyMacros(root, macros, options) { | ||
| if (macros.length === 0) return root; | ||
| return transform(root, { | ||
| ...composeMacros(macros), | ||
| ...options | ||
| }); | ||
| } | ||
| //#endregion | ||
| export { composeMacros as n, defineMacro as r, applyMacros as t }; | ||
| //# sourceMappingURL=defineMacro-B5Plh1uq.js.map |
| {"version":3,"file":"defineMacro-B5Plh1uq.js","names":[],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"} |
| const require_visitor = require("./visitor-ChiWLwlh.cjs"); | ||
| //#region src/defineMacro.ts | ||
| /** | ||
| * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain | ||
| * list keeps its authored order. | ||
| */ | ||
| function enforceWeight(enforce) { | ||
| if (enforce === "pre") return 0; | ||
| if (enforce === "post") return 2; | ||
| return 1; | ||
| } | ||
| /** | ||
| * Types a macro for inference and a single construction site, mirroring `definePlugin`. | ||
| * Adds no runtime behavior. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const macroUntagged = defineMacro({ | ||
| * name: 'untagged', | ||
| * operation(node) { | ||
| * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] } | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineMacro(macro) { | ||
| return macro; | ||
| } | ||
| /** | ||
| * Runs every macro's callback for one node kind in order, chaining the result so each macro sees | ||
| * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the | ||
| * original reference (structural sharing). | ||
| */ | ||
| function chain({ macros, key, node, context }) { | ||
| let current = node; | ||
| for (const macro of macros) { | ||
| const callback = macro[key]; | ||
| if (!callback) continue; | ||
| if (macro.when && !macro.when(current)) continue; | ||
| const next = callback(current, context); | ||
| if (next != null) current = next; | ||
| } | ||
| return current === node ? void 0 : current; | ||
| } | ||
| /** | ||
| * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin | ||
| * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied | ||
| * sequentially per node so later macros see earlier output. This differs from a plain visitor, which | ||
| * has no names, ordering, or composition. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum]) | ||
| * const next = transform(root, visitor) | ||
| * ``` | ||
| */ | ||
| function composeMacros(macros) { | ||
| const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce)); | ||
| const visitor = {}; | ||
| for (const key of require_visitor.visitorKeys) { | ||
| if (!ordered.some((macro) => typeof macro[key] === "function")) continue; | ||
| const callback = (node, context) => chain({ | ||
| macros: ordered, | ||
| key, | ||
| node, | ||
| context | ||
| }); | ||
| visitor[key] = callback; | ||
| } | ||
| return visitor; | ||
| } | ||
| /** | ||
| * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s | ||
| * structural sharing, so an empty or no-op macro list returns the same reference. Pass | ||
| * `depth: 'shallow'` to rewrite the root node only. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const next = applyMacros(root, [macroIntegerToString]) | ||
| * ``` | ||
| * | ||
| * @example Apply to the root node only | ||
| * ```ts | ||
| * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' }) | ||
| * ``` | ||
| */ | ||
| function applyMacros(root, macros, options) { | ||
| if (macros.length === 0) return root; | ||
| return require_visitor.transform(root, { | ||
| ...composeMacros(macros), | ||
| ...options | ||
| }); | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "applyMacros", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return applyMacros; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "composeMacros", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return composeMacros; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "defineMacro", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return defineMacro; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=defineMacro-CI0a-SWY.cjs.map |
| {"version":3,"file":"defineMacro-CI0a-SWY.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,gBAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"} |
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { M as pascalCase, Q as narrowSchema, o as createSchema } from "./visitor-CeO-upp5.js"; | ||
| //#region src/utils/refs.ts | ||
| const plainStringTypes = new Set([ | ||
| "string", | ||
| "uuid", | ||
| "email", | ||
| "url", | ||
| "datetime" | ||
| ]); | ||
| /** | ||
| * Returns the last path segment of a reference string. | ||
| * | ||
| * @example | ||
| * `extractRefName('#/components/schemas/Pet') // 'Pet'` | ||
| */ | ||
| function extractRefName(ref) { | ||
| return ref.split("/").at(-1) ?? ref; | ||
| } | ||
| /** | ||
| * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls | ||
| * back to `name` then nested `schema.name`. | ||
| * | ||
| * Returns `null` for non-ref nodes or when no name resolves. | ||
| * | ||
| * @example | ||
| * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'` | ||
| */ | ||
| function resolveRefName(node) { | ||
| if (!node || node.type !== "ref") return null; | ||
| if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null; | ||
| return node.name ?? node.schema?.name ?? null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase child schema name by joining a parent name and property name. | ||
| * Returns `null` when there is no parent to nest under. | ||
| * | ||
| * @example Nested under a parent | ||
| * `childName('Order', 'shipping_address') // 'OrderShippingAddress'` | ||
| * | ||
| * @example No parent | ||
| * `childName(undefined, 'params') // null` | ||
| */ | ||
| function childName(parentName, propName) { | ||
| return parentName ? pascalCase([parentName, propName].join(" ")) : null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any | ||
| * empty parts. | ||
| * | ||
| * @example | ||
| * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'` | ||
| */ | ||
| function enumPropName(parentName, propName, enumSuffix) { | ||
| return pascalCase([ | ||
| parentName, | ||
| propName, | ||
| enumSuffix | ||
| ].filter(Boolean).join(" ")); | ||
| } | ||
| /** | ||
| * Merges a ref node with its resolved schema, giving usage-site fields precedence. | ||
| * | ||
| * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the | ||
| * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`, | ||
| * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref | ||
| * nodes and refs without a resolved `schema` are returned unchanged. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' }) | ||
| * const merged = syncSchemaRef(ref) // merges with resolved Pet schema | ||
| * ``` | ||
| */ | ||
| function syncSchemaRef(node) { | ||
| const ref = narrowSchema(node, "ref"); | ||
| if (!ref) return node; | ||
| if (!ref.schema) return node; | ||
| const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref; | ||
| const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0)); | ||
| return createSchema({ | ||
| ...ref.schema, | ||
| ...definedOverrides | ||
| }); | ||
| } | ||
| /** | ||
| * Type guard that returns `true` when a schema emits as a plain `string` type. | ||
| * | ||
| * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time` | ||
| * types, returns `true` only when `representation` is `'string'` rather than `'date'`. | ||
| */ | ||
| function isStringType(node) { | ||
| if (plainStringTypes.has(node.type)) return true; | ||
| const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time"); | ||
| if (temporal) return temporal.representation !== "date"; | ||
| return false; | ||
| } | ||
| //#endregion | ||
| export { resolveRefName as a, isStringType as i, enumPropName as n, syncSchemaRef as o, extractRefName as r, childName as t }; | ||
| //# sourceMappingURL=refs-1t3qfkLE.js.map |
| {"version":3,"file":"refs-1t3qfkLE.js","names":[],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;;AAKA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAa,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAO,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAM,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAO,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAW,aAAa,MAAM,MAAM,KAAK,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"} |
| const require_visitor = require("./visitor-ChiWLwlh.cjs"); | ||
| //#region src/utils/refs.ts | ||
| const plainStringTypes = new Set([ | ||
| "string", | ||
| "uuid", | ||
| "email", | ||
| "url", | ||
| "datetime" | ||
| ]); | ||
| /** | ||
| * Returns the last path segment of a reference string. | ||
| * | ||
| * @example | ||
| * `extractRefName('#/components/schemas/Pet') // 'Pet'` | ||
| */ | ||
| function extractRefName(ref) { | ||
| return ref.split("/").at(-1) ?? ref; | ||
| } | ||
| /** | ||
| * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls | ||
| * back to `name` then nested `schema.name`. | ||
| * | ||
| * Returns `null` for non-ref nodes or when no name resolves. | ||
| * | ||
| * @example | ||
| * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'` | ||
| */ | ||
| function resolveRefName(node) { | ||
| if (!node || node.type !== "ref") return null; | ||
| if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null; | ||
| return node.name ?? node.schema?.name ?? null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase child schema name by joining a parent name and property name. | ||
| * Returns `null` when there is no parent to nest under. | ||
| * | ||
| * @example Nested under a parent | ||
| * `childName('Order', 'shipping_address') // 'OrderShippingAddress'` | ||
| * | ||
| * @example No parent | ||
| * `childName(undefined, 'params') // null` | ||
| */ | ||
| function childName(parentName, propName) { | ||
| return parentName ? require_visitor.pascalCase([parentName, propName].join(" ")) : null; | ||
| } | ||
| /** | ||
| * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any | ||
| * empty parts. | ||
| * | ||
| * @example | ||
| * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'` | ||
| */ | ||
| function enumPropName(parentName, propName, enumSuffix) { | ||
| return require_visitor.pascalCase([ | ||
| parentName, | ||
| propName, | ||
| enumSuffix | ||
| ].filter(Boolean).join(" ")); | ||
| } | ||
| /** | ||
| * Merges a ref node with its resolved schema, giving usage-site fields precedence. | ||
| * | ||
| * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the | ||
| * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`, | ||
| * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref | ||
| * nodes and refs without a resolved `schema` are returned unchanged. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' }) | ||
| * const merged = syncSchemaRef(ref) // merges with resolved Pet schema | ||
| * ``` | ||
| */ | ||
| function syncSchemaRef(node) { | ||
| const ref = require_visitor.narrowSchema(node, "ref"); | ||
| if (!ref) return node; | ||
| if (!ref.schema) return node; | ||
| const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref; | ||
| const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0)); | ||
| return require_visitor.createSchema({ | ||
| ...ref.schema, | ||
| ...definedOverrides | ||
| }); | ||
| } | ||
| /** | ||
| * Type guard that returns `true` when a schema emits as a plain `string` type. | ||
| * | ||
| * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time` | ||
| * types, returns `true` only when `representation` is `'string'` rather than `'date'`. | ||
| */ | ||
| function isStringType(node) { | ||
| if (plainStringTypes.has(node.type)) return true; | ||
| const temporal = require_visitor.narrowSchema(node, "date") ?? require_visitor.narrowSchema(node, "time"); | ||
| if (temporal) return temporal.representation !== "date"; | ||
| return false; | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "childName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return childName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "enumPropName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return enumPropName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "extractRefName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return extractRefName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isStringType", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return isStringType; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "resolveRefName", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return resolveRefName; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "syncSchemaRef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return syncSchemaRef; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=refs-Dga4lfv7.cjs.map |
| {"version":3,"file":"refs-Dga4lfv7.cjs","names":["pascalCase","narrowSchema","createSchema"],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;AAKA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAaA,gBAAAA,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAOA,gBAAAA,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAMC,gBAAAA,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAOC,gBAAAA,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAWD,gBAAAA,aAAa,MAAM,MAAM,KAAKA,gBAAAA,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"} |
| import "./rolldown-runtime-CNktS9qV.js"; | ||
| import { hash } from "node:crypto"; | ||
| import path from "node:path"; | ||
| //#region src/constants.ts | ||
| const visitorDepths = { | ||
| shallow: "shallow", | ||
| deep: "deep" | ||
| }; | ||
| /** | ||
| * Schema type discriminators used by all AST schema nodes. | ||
| * | ||
| * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`). | ||
| */ | ||
| const schemaTypes = { | ||
| /** | ||
| * Text value. | ||
| */ | ||
| string: "string", | ||
| /** | ||
| * Floating-point number (`float`, `double`). | ||
| */ | ||
| number: "number", | ||
| /** | ||
| * Whole number (`int32`). Use `bigint` for `int64`. | ||
| */ | ||
| integer: "integer", | ||
| /** | ||
| * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`. | ||
| */ | ||
| bigint: "bigint", | ||
| /** | ||
| * Boolean value. | ||
| */ | ||
| boolean: "boolean", | ||
| /** | ||
| * Explicit null value. | ||
| */ | ||
| null: "null", | ||
| /** | ||
| * Any value (no type restriction). | ||
| */ | ||
| any: "any", | ||
| /** | ||
| * Unknown value (must be narrowed before usage). | ||
| */ | ||
| unknown: "unknown", | ||
| /** | ||
| * No return value (`void`). | ||
| */ | ||
| void: "void", | ||
| /** | ||
| * Object with named properties. | ||
| */ | ||
| object: "object", | ||
| /** | ||
| * Sequential list of items. | ||
| */ | ||
| array: "array", | ||
| /** | ||
| * Fixed-length list with position-specific items. | ||
| */ | ||
| tuple: "tuple", | ||
| /** | ||
| * "One of" multiple schema members. | ||
| */ | ||
| union: "union", | ||
| /** | ||
| * "All of" multiple schema members. | ||
| */ | ||
| intersection: "intersection", | ||
| /** | ||
| * Enum schema. | ||
| */ | ||
| enum: "enum", | ||
| /** | ||
| * Reference to another schema. | ||
| */ | ||
| ref: "ref", | ||
| /** | ||
| * Calendar date (for example `2026-03-24`). | ||
| */ | ||
| date: "date", | ||
| /** | ||
| * Date-time value (for example `2026-03-24T09:00:00Z`). | ||
| */ | ||
| datetime: "datetime", | ||
| /** | ||
| * Time-only value (for example `09:00:00`). | ||
| */ | ||
| time: "time", | ||
| /** | ||
| * UUID value. | ||
| */ | ||
| uuid: "uuid", | ||
| /** | ||
| * Email address value. | ||
| */ | ||
| email: "email", | ||
| /** | ||
| * URL value. | ||
| */ | ||
| url: "url", | ||
| /** | ||
| * IPv4 address value. | ||
| */ | ||
| ipv4: "ipv4", | ||
| /** | ||
| * IPv6 address value. | ||
| */ | ||
| ipv6: "ipv6", | ||
| /** | ||
| * Binary/blob value. | ||
| */ | ||
| blob: "blob", | ||
| /** | ||
| * Impossible value (`never`). | ||
| */ | ||
| never: "never" | ||
| }; | ||
| /** | ||
| * One indentation level, derived from {@link INDENT_SIZE}. | ||
| */ | ||
| const INDENT = Array.from({ length: 2 }, () => " ").join(""); | ||
| //#endregion | ||
| //#region src/guards.ts | ||
| /** | ||
| * Narrows a `SchemaNode` to the variant that matches `type`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const schema = createSchema({ type: 'string' }) | ||
| * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null | ||
| * ``` | ||
| */ | ||
| function narrowSchema(node, type) { | ||
| return node?.type === type ? node : null; | ||
| } | ||
| /** | ||
| * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * if (isHttpOperationNode(node)) { | ||
| * console.log(node.method, node.path) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function isHttpOperationNode(node) { | ||
| return node.protocol === "http" || node.method !== void 0 && node.path !== void 0; | ||
| } | ||
| //#endregion | ||
| //#region src/defineNode.ts | ||
| /** | ||
| * Visitor callback names, one per traversable node kind, in traversal order. | ||
| * Kept in sync with the keys of `Visitor` in `visitor.ts`. | ||
| */ | ||
| const visitorKeys = [ | ||
| "input", | ||
| "output", | ||
| "operation", | ||
| "schema", | ||
| "property", | ||
| "parameter", | ||
| "response" | ||
| ]; | ||
| /** | ||
| * Builds a type guard that matches nodes of the given `kind`. | ||
| */ | ||
| function isKind(kind) { | ||
| return (node) => node?.kind === kind; | ||
| } | ||
| /** | ||
| * Defines a node once and derives its `create` builder, `is` guard, and traversal | ||
| * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the | ||
| * `kind`, so node construction lives in one place without scattered `as` casts. | ||
| * | ||
| * @example Simple node | ||
| * ```ts | ||
| * const importDef = defineNode<ImportNode>({ kind: 'Import' }) | ||
| * const createImport = importDef.create | ||
| * ``` | ||
| * | ||
| * @example Node with a build hook | ||
| * ```ts | ||
| * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({ | ||
| * kind: 'Property', | ||
| * build: (props) => ({ ...props, required: props.required ?? false }), | ||
| * children: ['schema'], | ||
| * visitorKey: 'property', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineNode(config) { | ||
| const { kind, defaults, build, children, visitorKey } = config; | ||
| function create(input) { | ||
| const base = build ? build(input) : input; | ||
| return { | ||
| ...defaults, | ||
| ...base, | ||
| kind | ||
| }; | ||
| } | ||
| return { | ||
| kind, | ||
| create, | ||
| is: isKind(kind), | ||
| children, | ||
| visitorKey | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/code.ts | ||
| /** | ||
| * Definition for the {@link ConstNode}. | ||
| */ | ||
| const constDef = defineNode({ kind: "Const" }); | ||
| /** | ||
| * Definition for the {@link TypeNode}. | ||
| */ | ||
| const typeDef = defineNode({ kind: "Type" }); | ||
| /** | ||
| * Definition for the {@link FunctionNode}. | ||
| */ | ||
| const functionDef = defineNode({ kind: "Function" }); | ||
| /** | ||
| * Definition for the {@link ArrowFunctionNode}. | ||
| */ | ||
| const arrowFunctionDef = defineNode({ kind: "ArrowFunction" }); | ||
| /** | ||
| * Definition for the {@link TextNode}. | ||
| */ | ||
| const textDef = defineNode({ | ||
| kind: "Text", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Definition for the {@link BreakNode}. | ||
| */ | ||
| const breakDef = defineNode({ | ||
| kind: "Break", | ||
| build: () => ({}) | ||
| }); | ||
| /** | ||
| * Definition for the {@link JsxNode}. | ||
| */ | ||
| const jsxDef = defineNode({ | ||
| kind: "Jsx", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Creates a `ConstNode` representing a TypeScript `const` declaration. | ||
| * | ||
| * @example Exported constant with type and `as const` | ||
| * ```ts | ||
| * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true }) | ||
| * // export const pets: Pet[] = ... as const | ||
| * ``` | ||
| */ | ||
| const createConst = constDef.create; | ||
| /** | ||
| * Creates a `TypeNode` representing a TypeScript `type` alias declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createType({ name: 'Pet', export: true }) | ||
| * // export type Pet = ... | ||
| * ``` | ||
| */ | ||
| const createType = typeDef.create; | ||
| /** | ||
| * Creates a `FunctionNode` representing a TypeScript `function` declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' }) | ||
| * // export async function fetchPet(): Promise<Pet> { ... } | ||
| * ``` | ||
| */ | ||
| const createFunction = functionDef.create; | ||
| /** | ||
| * Creates an `ArrowFunctionNode` representing a TypeScript arrow function. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true }) | ||
| * // export const double = (n: number) => ... | ||
| * ``` | ||
| */ | ||
| const createArrowFunction = arrowFunctionDef.create; | ||
| /** | ||
| * Creates a {@link TextNode} representing a raw string fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createText('return fetch(id)') | ||
| * // { kind: 'Text', value: 'return fetch(id)' } | ||
| * ``` | ||
| */ | ||
| const createText = textDef.create; | ||
| /** | ||
| * Creates a {@link BreakNode} representing a line break in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createBreak() | ||
| * // { kind: 'Break' } | ||
| * ``` | ||
| */ | ||
| function createBreak() { | ||
| return breakDef.create(); | ||
| } | ||
| /** | ||
| * Creates a {@link JsxNode} representing a raw JSX fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createJsx('<>\n <a href={href}>Open</a>\n</>') | ||
| * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' } | ||
| * ``` | ||
| */ | ||
| const createJsx = jsxDef.create; | ||
| //#endregion | ||
| //#region src/nodes/content.ts | ||
| /** | ||
| * Definition for the {@link ContentNode}. | ||
| */ | ||
| const contentDef = defineNode({ | ||
| kind: "Content", | ||
| children: ["schema"] | ||
| }); | ||
| /** | ||
| * Creates a `ContentNode` for a single request-body or response content type. | ||
| */ | ||
| const createContent = contentDef.create; | ||
| //#endregion | ||
| //#region ../../internals/utils/src/casing.ts | ||
| /** | ||
| * Shared implementation for camelCase and PascalCase conversion. | ||
| * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons) | ||
| * and capitalizes each word according to `pascal`. | ||
| * | ||
| * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are. | ||
| */ | ||
| function toCamelOrPascal(text, pascal) { | ||
| return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => { | ||
| if (word.length > 1 && word === word.toUpperCase()) return word; | ||
| return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1); | ||
| }).join("").replace(/[^a-zA-Z0-9]/g, ""); | ||
| } | ||
| /** | ||
| * Converts `text` to PascalCase. | ||
| * | ||
| * @example Word boundaries | ||
| * `pascalCase('hello-world') // 'HelloWorld'` | ||
| * | ||
| * @example With a suffix | ||
| * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'` | ||
| */ | ||
| function pascalCase(text, { prefix = "", suffix = "" } = {}) { | ||
| return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true); | ||
| } | ||
| //#endregion | ||
| //#region ../../internals/utils/src/fs.ts | ||
| /** | ||
| * Strips the file extension from a path or file name. | ||
| * Only removes the last `.ext` segment when the dot is not part of a directory name. | ||
| * | ||
| * @example | ||
| * trimExtName('petStore.ts') // 'petStore' | ||
| * trimExtName('/src/models/pet.ts') // '/src/models/pet' | ||
| * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet' | ||
| * trimExtName('noExtension') // 'noExtension' | ||
| */ | ||
| function trimExtName(text) { | ||
| const dotIndex = text.lastIndexOf("."); | ||
| if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex); | ||
| return text; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/extractStringsFromNodes.ts | ||
| /** | ||
| * Extracts all string content from a `CodeNode` tree recursively. | ||
| * | ||
| * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`), | ||
| * and nested node content. Used to build the full source string for import filtering. | ||
| */ | ||
| function extractStringsFromNodes(nodes) { | ||
| if (!nodes?.length) return ""; | ||
| return nodes.map((node) => { | ||
| if (typeof node === "string") return node; | ||
| if (node.kind === "Text") return node.value; | ||
| if (node.kind === "Break") return ""; | ||
| if (node.kind === "Jsx") return node.value; | ||
| const parts = []; | ||
| if ("params" in node && node.params) parts.push(node.params); | ||
| if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics); | ||
| if ("returnType" in node && node.returnType) parts.push(node.returnType); | ||
| if ("type" in node && typeof node.type === "string") parts.push(node.type); | ||
| const nested = extractStringsFromNodes(node.nodes); | ||
| if (nested) parts.push(nested); | ||
| return parts.join("\n"); | ||
| }).filter(Boolean).join("\n"); | ||
| } | ||
| //#endregion | ||
| //#region src/utils/fileMerge.ts | ||
| function sourceKey(source) { | ||
| return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`; | ||
| } | ||
| function pathTypeKey(path, isTypeOnly) { | ||
| return `${path}:${isTypeOnly ?? false}`; | ||
| } | ||
| function exportKey(path, name, isTypeOnly, asAlias) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`; | ||
| } | ||
| function importKey(path, name, isTypeOnly) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}`; | ||
| } | ||
| /** | ||
| * Computes a multi-level sort key for exports and imports: | ||
| * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named. | ||
| */ | ||
| function sortKey(node) { | ||
| const isArray = Array.isArray(node.name) ? "1" : "0"; | ||
| const typeOnly = node.isTypeOnly ? "0" : "1"; | ||
| const hasName = node.name != null ? "1" : "0"; | ||
| const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? ""; | ||
| return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`; | ||
| } | ||
| /** | ||
| * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each | ||
| * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns | ||
| * the deduplicated array in original order. | ||
| */ | ||
| function combineSources(sources) { | ||
| const seen = /* @__PURE__ */ new Map(); | ||
| for (const source of sources) { | ||
| const key = sourceKey(source); | ||
| if (!seen.has(key)) seen.set(key, source); | ||
| } | ||
| return [...seen.values()]; | ||
| } | ||
| /** | ||
| * Merges `incoming` names into `existing`, preserving order and dropping duplicates. | ||
| * | ||
| * Shared by `combineExports` and `combineImports` for the same-path name-merge case. | ||
| */ | ||
| function mergeNameArrays(existing, incoming) { | ||
| const merged = new Set(existing); | ||
| for (const name of incoming) merged.add(name); | ||
| return [...merged]; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ExportNode` objects by path and type. | ||
| * | ||
| * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export. | ||
| * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array. | ||
| */ | ||
| function combineExports(exports) { | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = exports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| const { name, path, isTypeOnly, asAlias } = curr; | ||
| if (Array.isArray(name)) { | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name: [...new Set(name)] | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| const key = exportKey(path, name, isTypeOnly, asAlias); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ImportNode` objects, filtering out unused imports. | ||
| * | ||
| * Retains imports that are referenced in `source` or re-exported. Imports with the same path and | ||
| * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array. | ||
| */ | ||
| function combineImports(imports, exports, source) { | ||
| const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])); | ||
| const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName); | ||
| const importNameMemo = /* @__PURE__ */ new Map(); | ||
| const canonicalizeName = (n) => { | ||
| if (typeof n === "string") return n; | ||
| const key = `${n.propertyName}:${n.name ?? ""}`; | ||
| if (!importNameMemo.has(key)) importNameMemo.set(key, n); | ||
| return importNameMemo.get(key); | ||
| }; | ||
| const pathsWithUsedNamedImport = /* @__PURE__ */ new Set(); | ||
| for (const node of imports) { | ||
| if (!Array.isArray(node.name)) continue; | ||
| if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path); | ||
| } | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = imports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| if (curr.path === curr.root) continue; | ||
| const { path, isTypeOnly } = curr; | ||
| let { name } = curr; | ||
| if (Array.isArray(name)) { | ||
| name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName)); | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue; | ||
| const key = importKey(path, name, isTypeOnly); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/file.ts | ||
| /** | ||
| * Definition for the {@link ImportNode}. | ||
| */ | ||
| const importDef = defineNode({ kind: "Import" }); | ||
| /** | ||
| * Definition for the {@link ExportNode}. | ||
| */ | ||
| const exportDef = defineNode({ kind: "Export" }); | ||
| /** | ||
| * Definition for the {@link SourceNode}. | ||
| */ | ||
| const sourceDef = defineNode({ kind: "Source" }); | ||
| /** | ||
| * Definition for the {@link FileNode}. The fully resolved builder lives in | ||
| * `createFile`, so this definition only supplies the guard. | ||
| */ | ||
| const fileDef = defineNode({ kind: "File" }); | ||
| /** | ||
| * Creates an `ImportNode` representing a language-agnostic import/dependency declaration. | ||
| * | ||
| * @example Named import | ||
| * ```ts | ||
| * createImport({ name: ['useState'], path: 'react' }) | ||
| * // import { useState } from 'react' | ||
| * ``` | ||
| */ | ||
| const createImport = importDef.create; | ||
| /** | ||
| * Creates an `ExportNode` representing a language-agnostic export/public API declaration. | ||
| * | ||
| * @example Named export | ||
| * ```ts | ||
| * createExport({ name: ['Pet'], path: './Pet' }) | ||
| * // export { Pet } from './Pet' | ||
| * ``` | ||
| */ | ||
| const createExport = exportDef.create; | ||
| /** | ||
| * Creates a `SourceNode` representing a fragment of source code within a file. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true }) | ||
| * ``` | ||
| */ | ||
| const createSource = sourceDef.create; | ||
| /** | ||
| * Creates a fully resolved `FileNode` from a file input descriptor. | ||
| * | ||
| * Computes: | ||
| * - `id` SHA256 hash of the file path | ||
| * - `name` `baseName` without extension | ||
| * - `extname` extension extracted from `baseName` | ||
| * | ||
| * Deduplicates: | ||
| * - `sources` via `combineSources` | ||
| * - `exports` via `combineExports` | ||
| * - `imports` via `combineImports` (also filters unused imports) | ||
| * | ||
| * @throws {Error} when `baseName` has no extension. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'petStore.ts', | ||
| * path: 'src/models/petStore.ts', | ||
| * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })], | ||
| * imports: [createImport({ name: ['z'], path: 'zod' })], | ||
| * exports: [createExport({ name: ['Pet'], path: './petStore' })], | ||
| * }) | ||
| * // file.id = SHA256 hash of 'src/models/petStore.ts' | ||
| * // file.name = 'petStore' | ||
| * // file.extname = '.ts' | ||
| * ``` | ||
| * | ||
| * @example Copy a real file into the output verbatim | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'client.ts', | ||
| * path: 'src/gen/client.ts', | ||
| * copy: '/abs/path/to/templates/client.ts', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function createFile(input) { | ||
| const extname = path.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : ""); | ||
| if (!extname) throw new Error(`No extname found for ${input.baseName}`); | ||
| const source = (input.sources ?? []).flatMap((item) => item.nodes ?? []).map((node) => extractStringsFromNodes([node])).filter(Boolean).join("\n\n"); | ||
| const resolvedExports = input.exports?.length ? combineExports(input.exports) : []; | ||
| const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || void 0) : []; | ||
| const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name))); | ||
| const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName; | ||
| const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => { | ||
| if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp]; | ||
| const kept = imp.name.filter((item) => !localNames.has(nameOf(item))); | ||
| if (!kept.length) return []; | ||
| return [kept.length === imp.name.length ? imp : { | ||
| ...imp, | ||
| name: kept | ||
| }]; | ||
| }); | ||
| const resolvedSources = input.sources?.length ? combineSources(input.sources) : []; | ||
| return { | ||
| kind: "File", | ||
| ...input, | ||
| id: hash("sha256", input.path, "hex"), | ||
| name: trimExtName(input.baseName), | ||
| extname, | ||
| imports: resolvedImports, | ||
| exports: resolvedExports, | ||
| sources: resolvedSources, | ||
| meta: input.meta ?? {} | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/input.ts | ||
| /** | ||
| * Definition for the {@link InputNode}. | ||
| */ | ||
| const inputDef = defineNode({ | ||
| kind: "Input", | ||
| defaults: { | ||
| schemas: [], | ||
| operations: [], | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| } | ||
| }, | ||
| children: ["schemas", "operations"], | ||
| visitorKey: "input" | ||
| }); | ||
| /** | ||
| * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and | ||
| * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array | ||
| * `schemas`/`operations`. Both variants get the defaulted `meta`. | ||
| * | ||
| * @example Eager | ||
| * ```ts | ||
| * const input = createInput() | ||
| * // { kind: 'Input', schemas: [], operations: [] } | ||
| * ``` | ||
| * | ||
| * @example Streaming | ||
| * ```ts | ||
| * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } }) | ||
| * ``` | ||
| */ | ||
| function createInput(options = {}) { | ||
| const { stream, ...overrides } = options; | ||
| if (stream) return { | ||
| kind: "Input", | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| }, | ||
| ...overrides | ||
| }; | ||
| return inputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/requestBody.ts | ||
| /** | ||
| * Definition for the {@link RequestBodyNode}. Content entries are built upfront with | ||
| * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes. | ||
| */ | ||
| const requestBodyDef = defineNode({ | ||
| kind: "RequestBody", | ||
| children: ["content"] | ||
| }); | ||
| /** | ||
| * Creates a `RequestBodyNode`. | ||
| */ | ||
| const createRequestBody = requestBodyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/operation.ts | ||
| /** | ||
| * Definition for the {@link OperationNode}. HTTP operations (those carrying both | ||
| * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is | ||
| * normalized into a `RequestBodyNode`. | ||
| */ | ||
| const operationDef = defineNode({ | ||
| kind: "Operation", | ||
| build: (props) => { | ||
| const { requestBody, ...rest } = props; | ||
| const isHttp = rest.method !== void 0 && rest.path !== void 0; | ||
| return { | ||
| tags: [], | ||
| parameters: [], | ||
| responses: [], | ||
| ...rest, | ||
| ...isHttp ? { protocol: "http" } : {}, | ||
| requestBody: requestBody ? createRequestBody(requestBody) : void 0 | ||
| }; | ||
| }, | ||
| children: [ | ||
| "parameters", | ||
| "requestBody", | ||
| "responses" | ||
| ], | ||
| visitorKey: "operation" | ||
| }); | ||
| function createOperation(props) { | ||
| return operationDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/output.ts | ||
| /** | ||
| * Definition for the {@link OutputNode}. | ||
| */ | ||
| const outputDef = defineNode({ | ||
| kind: "Output", | ||
| defaults: { files: [] }, | ||
| visitorKey: "output" | ||
| }); | ||
| /** | ||
| * Creates an `OutputNode` with a stable default for `files`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const output = createOutput() | ||
| * // { kind: 'Output', files: [] } | ||
| * ``` | ||
| */ | ||
| function createOutput(overrides = {}) { | ||
| return outputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/optionality.ts | ||
| /** | ||
| * Generic JSON Schema optionality: a non-required field is optional, and a | ||
| * non-required nullable field is nullish. | ||
| */ | ||
| function optionality(schema, required) { | ||
| const nullable = schema.nullable ?? false; | ||
| return { | ||
| ...schema, | ||
| optional: !required && !nullable ? true : void 0, | ||
| nullish: !required && nullable ? true : void 0 | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/parameter.ts | ||
| /** | ||
| * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const parameterDef = defineNode({ | ||
| kind: "Parameter", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "parameter" | ||
| }); | ||
| /** | ||
| * Creates a `ParameterNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const param = createParameter({ | ||
| * name: 'petId', | ||
| * in: 'path', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string' }), | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createParameter = parameterDef.create; | ||
| //#endregion | ||
| //#region src/nodes/property.ts | ||
| /** | ||
| * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const propertyDef = defineNode({ | ||
| kind: "Property", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "property" | ||
| }); | ||
| /** | ||
| * Creates a `PropertyNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const property = createProperty({ | ||
| * name: 'status', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string', nullable: true }), | ||
| * }) | ||
| * // required=true, no optional/nullish | ||
| * ``` | ||
| */ | ||
| const createProperty = propertyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/response.ts | ||
| /** | ||
| * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional | ||
| * `mediaType`/`keysToOmit`) is normalized into one `content` entry. | ||
| */ | ||
| const responseDef = defineNode({ | ||
| kind: "Response", | ||
| build: (props) => { | ||
| const { schema, mediaType, keysToOmit, content, ...rest } = props; | ||
| const entries = content ?? (schema ? [createContent({ | ||
| contentType: mediaType ?? "application/json", | ||
| schema, | ||
| keysToOmit: keysToOmit ?? null | ||
| })] : void 0); | ||
| return { | ||
| ...rest, | ||
| content: entries | ||
| }; | ||
| }, | ||
| children: ["content"], | ||
| visitorKey: "response" | ||
| }); | ||
| /** | ||
| * Creates a `ResponseNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const response = createResponse({ | ||
| * statusCode: '200', | ||
| * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createResponse = responseDef.create; | ||
| //#endregion | ||
| //#region src/nodes/schema.ts | ||
| /** | ||
| * Maps schema `type` to its underlying `primitive`. | ||
| * Primitive types map to themselves and special string formats map to `'string'`. | ||
| * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`. | ||
| */ | ||
| const TYPE_TO_PRIMITIVE = { | ||
| string: "string", | ||
| number: "number", | ||
| integer: "integer", | ||
| bigint: "bigint", | ||
| boolean: "boolean", | ||
| null: "null", | ||
| any: "any", | ||
| unknown: "unknown", | ||
| void: "void", | ||
| never: "never", | ||
| object: "object", | ||
| array: "array", | ||
| date: "date", | ||
| uuid: "string", | ||
| email: "string", | ||
| url: "string", | ||
| datetime: "string", | ||
| time: "string" | ||
| }; | ||
| /** | ||
| * Definition for the {@link SchemaNode}. Object schemas default `properties` to an | ||
| * empty array, and `primitive` is inferred from `type` when not explicitly provided. | ||
| */ | ||
| const schemaDef = defineNode({ | ||
| kind: "Schema", | ||
| build: (props) => { | ||
| if (props.type === "object") return { | ||
| properties: [], | ||
| primitive: "object", | ||
| ...props | ||
| }; | ||
| return { | ||
| primitive: TYPE_TO_PRIMITIVE[props.type], | ||
| ...props | ||
| }; | ||
| }, | ||
| children: [ | ||
| "properties", | ||
| "items", | ||
| "members", | ||
| "additionalProperties" | ||
| ], | ||
| visitorKey: "schema" | ||
| }); | ||
| function createSchema(props) { | ||
| return schemaDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/registry.ts | ||
| /** | ||
| * Every node definition. Adding a node means adding its `defineNode` to one | ||
| * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it. | ||
| */ | ||
| const nodeDefs = [ | ||
| inputDef, | ||
| outputDef, | ||
| operationDef, | ||
| requestBodyDef, | ||
| contentDef, | ||
| responseDef, | ||
| schemaDef, | ||
| propertyDef, | ||
| parameterDef, | ||
| constDef, | ||
| typeDef, | ||
| functionDef, | ||
| arrowFunctionDef, | ||
| textDef, | ||
| breakDef, | ||
| jsxDef, | ||
| importDef, | ||
| exportDef, | ||
| sourceDef, | ||
| fileDef | ||
| ]; | ||
| //#endregion | ||
| //#region src/visitor.ts | ||
| /** | ||
| * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`). | ||
| * Derived from each definition's `children`. | ||
| */ | ||
| const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : [])); | ||
| /** | ||
| * Maps a node kind to the matching visitor callback name. Derived from each | ||
| * definition's `visitorKey`. | ||
| */ | ||
| const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : [])); | ||
| /** | ||
| * Creates a small async concurrency limiter. | ||
| * | ||
| * At most `concurrency` tasks are in flight at once. Extra tasks are queued. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const limit = createLimit(2) | ||
| * for (const task of [taskA, taskB, taskC]) { | ||
| * await limit(() => task()) | ||
| * } | ||
| * // only 2 tasks run at the same time | ||
| * ``` | ||
| */ | ||
| function createLimit(concurrency) { | ||
| let active = 0; | ||
| const queue = []; | ||
| function next() { | ||
| if (active < concurrency && queue.length > 0) { | ||
| active++; | ||
| queue.shift()(); | ||
| } | ||
| } | ||
| return function limit(fn) { | ||
| return new Promise((resolve, reject) => { | ||
| queue.push(() => { | ||
| Promise.resolve(fn()).then(resolve, reject).finally(() => { | ||
| active--; | ||
| next(); | ||
| }); | ||
| }); | ||
| next(); | ||
| }); | ||
| }; | ||
| } | ||
| const visitorKeysByKind = VISITOR_KEYS; | ||
| /** | ||
| * Returns `true` when `value` is an AST node (an object carrying a `kind`). | ||
| */ | ||
| function isNode(value) { | ||
| return typeof value === "object" && value !== null && "kind" in value; | ||
| } | ||
| /** | ||
| * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}. | ||
| * | ||
| * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const children = getChildren(operationNode, true) | ||
| * // returns parameters, the request body, and responses | ||
| * ``` | ||
| */ | ||
| function* getChildren(node, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return; | ||
| const record = node; | ||
| for (const key of keys) { | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) if (isNode(item)) yield item; | ||
| } else if (isNode(value)) yield value; | ||
| } | ||
| } | ||
| /** | ||
| * Runs the visitor callback that matches `node.kind` with the traversal | ||
| * context. The result is a replacement node, a collected value, or `undefined` | ||
| * when no callback is registered for the kind. | ||
| * | ||
| * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives | ||
| * in one place. `TResult` is the caller's expected return: the same node type | ||
| * for `transform`, the collected value type for `collectLazy`, ignored for `walk`. | ||
| */ | ||
| function applyVisitor(node, visitor, parent) { | ||
| const key = VISITOR_KEY_BY_KIND[node.kind]; | ||
| if (!key) return void 0; | ||
| const fn = visitor[key]; | ||
| return fn?.(node, { parent }); | ||
| } | ||
| /** | ||
| * Async depth-first traversal for side effects. Visitor return values are | ||
| * ignored. Use `transform` when you want to rewrite nodes. | ||
| * | ||
| * Sibling nodes at each depth run concurrently up to `options.concurrency` | ||
| * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor | ||
| * work. Lower values reduce memory pressure. | ||
| * | ||
| * @example Log every operation | ||
| * ```ts | ||
| * await walk(root, { | ||
| * operation(node) { | ||
| * console.log(node.operationId) | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @example Only visit the root node | ||
| * ```ts | ||
| * await walk(root, { depth: 'shallow', input: () => {} }) | ||
| * ``` | ||
| */ | ||
| async function walk(node, options) { | ||
| return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0); | ||
| } | ||
| async function _walk(node, visitor, recurse, limit, parent) { | ||
| await limit(() => applyVisitor(node, visitor, parent)); | ||
| const children = Array.from(getChildren(node, recurse)); | ||
| if (children.length === 0) return; | ||
| await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node))); | ||
| } | ||
| function transform(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse); | ||
| } | ||
| /** | ||
| * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming | ||
| * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact. | ||
| * `Schema` children are skipped in shallow mode. | ||
| */ | ||
| function transformChildren(node, options, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return node; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return node; | ||
| const record = node; | ||
| const childOptions = { | ||
| ...options, | ||
| parent: node | ||
| }; | ||
| let updates; | ||
| for (const key of keys) { | ||
| if (!(key in record)) continue; | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| let changed = false; | ||
| const mapped = value.map((item) => { | ||
| if (!isNode(item)) return item; | ||
| const next = transform(item, childOptions); | ||
| if (next !== item) changed = true; | ||
| return next; | ||
| }); | ||
| if (changed) (updates ??= {})[key] = mapped; | ||
| } else if (isNode(value)) { | ||
| const next = transform(value, childOptions); | ||
| if (next !== value) (updates ??= {})[key] = next; | ||
| } | ||
| } | ||
| return updates ? { | ||
| ...node, | ||
| ...updates | ||
| } : node; | ||
| } | ||
| /** | ||
| * Lazy depth-first collection pass. Yields every non-null value returned by | ||
| * the visitor callbacks. Use `collect` for the eager array form. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids: string[] = [] | ||
| * for (const id of collectLazy<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * })) { | ||
| * ids.push(id) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function* collectLazy(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| const v = applyVisitor(node, visitor, parent); | ||
| if (v != null) yield v; | ||
| for (const child of getChildren(node, recurse)) yield* collectLazy(child, { | ||
| ...options, | ||
| parent: node | ||
| }); | ||
| } | ||
| /** | ||
| * Eager depth-first collection pass. Gathers every non-null value the visitor | ||
| * callbacks return into an array. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids = collect<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function collect(node, options) { | ||
| return Array.from(collectLazy(node, options)); | ||
| } | ||
| //#endregion | ||
| export { INDENT as $, sourceDef as A, createConst as B, createExport as C, exportDef as D, createSource as E, arrowFunctionDef as F, functionDef as G, createJsx as H, breakDef as I, typeDef as J, jsxDef as K, constDef as L, pascalCase as M, contentDef as N, fileDef as O, createContent as P, narrowSchema as Q, createArrowFunction as R, inputDef as S, createImport as T, createText as U, createFunction as V, createType as W, visitorKeys as X, defineNode as Y, isHttpOperationNode as Z, createOperation as _, nodeDefs as a, requestBodyDef as b, createResponse as c, propertyDef as d, schemaTypes as et, createParameter as f, outputDef as g, createOutput as h, walk as i, extractStringsFromNodes as j, importDef as k, responseDef as l, optionality as m, collectLazy as n, createSchema as o, parameterDef as p, textDef as q, transform as r, schemaDef as s, collect as t, createProperty as u, operationDef as v, createFile as w, createInput as x, createRequestBody as y, createBreak as z }; | ||
| //# sourceMappingURL=visitor-CeO-upp5.js.map |
Sorry, the diff of this file is too big to display
| //#region \0rolldown/runtime.js | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __name = (target, value) => __defProp(target, "name", { | ||
| value, | ||
| configurable: true | ||
| }); | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __exportAll = (all, no_symbols) => { | ||
| let target = {}; | ||
| for (var name in all) __defProp(target, name, { | ||
| get: all[name], | ||
| enumerable: true | ||
| }); | ||
| if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" }); | ||
| return target; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { | ||
| key = keys[i]; | ||
| if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { | ||
| get: ((k) => from[k]).bind(null, key), | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { | ||
| value: mod, | ||
| enumerable: true | ||
| }) : target, mod)); | ||
| //#endregion | ||
| let node_crypto = require("node:crypto"); | ||
| let node_path = require("node:path"); | ||
| node_path = __toESM(node_path, 1); | ||
| //#region src/constants.ts | ||
| const visitorDepths = { | ||
| shallow: "shallow", | ||
| deep: "deep" | ||
| }; | ||
| /** | ||
| * Schema type discriminators used by all AST schema nodes. | ||
| * | ||
| * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`). | ||
| */ | ||
| const schemaTypes = { | ||
| /** | ||
| * Text value. | ||
| */ | ||
| string: "string", | ||
| /** | ||
| * Floating-point number (`float`, `double`). | ||
| */ | ||
| number: "number", | ||
| /** | ||
| * Whole number (`int32`). Use `bigint` for `int64`. | ||
| */ | ||
| integer: "integer", | ||
| /** | ||
| * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`. | ||
| */ | ||
| bigint: "bigint", | ||
| /** | ||
| * Boolean value. | ||
| */ | ||
| boolean: "boolean", | ||
| /** | ||
| * Explicit null value. | ||
| */ | ||
| null: "null", | ||
| /** | ||
| * Any value (no type restriction). | ||
| */ | ||
| any: "any", | ||
| /** | ||
| * Unknown value (must be narrowed before usage). | ||
| */ | ||
| unknown: "unknown", | ||
| /** | ||
| * No return value (`void`). | ||
| */ | ||
| void: "void", | ||
| /** | ||
| * Object with named properties. | ||
| */ | ||
| object: "object", | ||
| /** | ||
| * Sequential list of items. | ||
| */ | ||
| array: "array", | ||
| /** | ||
| * Fixed-length list with position-specific items. | ||
| */ | ||
| tuple: "tuple", | ||
| /** | ||
| * "One of" multiple schema members. | ||
| */ | ||
| union: "union", | ||
| /** | ||
| * "All of" multiple schema members. | ||
| */ | ||
| intersection: "intersection", | ||
| /** | ||
| * Enum schema. | ||
| */ | ||
| enum: "enum", | ||
| /** | ||
| * Reference to another schema. | ||
| */ | ||
| ref: "ref", | ||
| /** | ||
| * Calendar date (for example `2026-03-24`). | ||
| */ | ||
| date: "date", | ||
| /** | ||
| * Date-time value (for example `2026-03-24T09:00:00Z`). | ||
| */ | ||
| datetime: "datetime", | ||
| /** | ||
| * Time-only value (for example `09:00:00`). | ||
| */ | ||
| time: "time", | ||
| /** | ||
| * UUID value. | ||
| */ | ||
| uuid: "uuid", | ||
| /** | ||
| * Email address value. | ||
| */ | ||
| email: "email", | ||
| /** | ||
| * URL value. | ||
| */ | ||
| url: "url", | ||
| /** | ||
| * IPv4 address value. | ||
| */ | ||
| ipv4: "ipv4", | ||
| /** | ||
| * IPv6 address value. | ||
| */ | ||
| ipv6: "ipv6", | ||
| /** | ||
| * Binary/blob value. | ||
| */ | ||
| blob: "blob", | ||
| /** | ||
| * Impossible value (`never`). | ||
| */ | ||
| never: "never" | ||
| }; | ||
| /** | ||
| * One indentation level, derived from {@link INDENT_SIZE}. | ||
| */ | ||
| const INDENT = Array.from({ length: 2 }, () => " ").join(""); | ||
| //#endregion | ||
| //#region src/guards.ts | ||
| /** | ||
| * Narrows a `SchemaNode` to the variant that matches `type`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const schema = createSchema({ type: 'string' }) | ||
| * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null | ||
| * ``` | ||
| */ | ||
| function narrowSchema(node, type) { | ||
| return node?.type === type ? node : null; | ||
| } | ||
| /** | ||
| * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * if (isHttpOperationNode(node)) { | ||
| * console.log(node.method, node.path) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function isHttpOperationNode(node) { | ||
| return node.protocol === "http" || node.method !== void 0 && node.path !== void 0; | ||
| } | ||
| //#endregion | ||
| //#region src/defineNode.ts | ||
| /** | ||
| * Visitor callback names, one per traversable node kind, in traversal order. | ||
| * Kept in sync with the keys of `Visitor` in `visitor.ts`. | ||
| */ | ||
| const visitorKeys = [ | ||
| "input", | ||
| "output", | ||
| "operation", | ||
| "schema", | ||
| "property", | ||
| "parameter", | ||
| "response" | ||
| ]; | ||
| /** | ||
| * Builds a type guard that matches nodes of the given `kind`. | ||
| */ | ||
| function isKind(kind) { | ||
| return (node) => node?.kind === kind; | ||
| } | ||
| /** | ||
| * Defines a node once and derives its `create` builder, `is` guard, and traversal | ||
| * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the | ||
| * `kind`, so node construction lives in one place without scattered `as` casts. | ||
| * | ||
| * @example Simple node | ||
| * ```ts | ||
| * const importDef = defineNode<ImportNode>({ kind: 'Import' }) | ||
| * const createImport = importDef.create | ||
| * ``` | ||
| * | ||
| * @example Node with a build hook | ||
| * ```ts | ||
| * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({ | ||
| * kind: 'Property', | ||
| * build: (props) => ({ ...props, required: props.required ?? false }), | ||
| * children: ['schema'], | ||
| * visitorKey: 'property', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function defineNode(config) { | ||
| const { kind, defaults, build, children, visitorKey } = config; | ||
| function create(input) { | ||
| const base = build ? build(input) : input; | ||
| return { | ||
| ...defaults, | ||
| ...base, | ||
| kind | ||
| }; | ||
| } | ||
| return { | ||
| kind, | ||
| create, | ||
| is: isKind(kind), | ||
| children, | ||
| visitorKey | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/code.ts | ||
| /** | ||
| * Definition for the {@link ConstNode}. | ||
| */ | ||
| const constDef = defineNode({ kind: "Const" }); | ||
| /** | ||
| * Definition for the {@link TypeNode}. | ||
| */ | ||
| const typeDef = defineNode({ kind: "Type" }); | ||
| /** | ||
| * Definition for the {@link FunctionNode}. | ||
| */ | ||
| const functionDef = defineNode({ kind: "Function" }); | ||
| /** | ||
| * Definition for the {@link ArrowFunctionNode}. | ||
| */ | ||
| const arrowFunctionDef = defineNode({ kind: "ArrowFunction" }); | ||
| /** | ||
| * Definition for the {@link TextNode}. | ||
| */ | ||
| const textDef = defineNode({ | ||
| kind: "Text", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Definition for the {@link BreakNode}. | ||
| */ | ||
| const breakDef = defineNode({ | ||
| kind: "Break", | ||
| build: () => ({}) | ||
| }); | ||
| /** | ||
| * Definition for the {@link JsxNode}. | ||
| */ | ||
| const jsxDef = defineNode({ | ||
| kind: "Jsx", | ||
| build: (value) => ({ value }) | ||
| }); | ||
| /** | ||
| * Creates a `ConstNode` representing a TypeScript `const` declaration. | ||
| * | ||
| * @example Exported constant with type and `as const` | ||
| * ```ts | ||
| * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true }) | ||
| * // export const pets: Pet[] = ... as const | ||
| * ``` | ||
| */ | ||
| const createConst = constDef.create; | ||
| /** | ||
| * Creates a `TypeNode` representing a TypeScript `type` alias declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createType({ name: 'Pet', export: true }) | ||
| * // export type Pet = ... | ||
| * ``` | ||
| */ | ||
| const createType = typeDef.create; | ||
| /** | ||
| * Creates a `FunctionNode` representing a TypeScript `function` declaration. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' }) | ||
| * // export async function fetchPet(): Promise<Pet> { ... } | ||
| * ``` | ||
| */ | ||
| const createFunction = functionDef.create; | ||
| /** | ||
| * Creates an `ArrowFunctionNode` representing a TypeScript arrow function. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true }) | ||
| * // export const double = (n: number) => ... | ||
| * ``` | ||
| */ | ||
| const createArrowFunction = arrowFunctionDef.create; | ||
| /** | ||
| * Creates a {@link TextNode} representing a raw string fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createText('return fetch(id)') | ||
| * // { kind: 'Text', value: 'return fetch(id)' } | ||
| * ``` | ||
| */ | ||
| const createText = textDef.create; | ||
| /** | ||
| * Creates a {@link BreakNode} representing a line break in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createBreak() | ||
| * // { kind: 'Break' } | ||
| * ``` | ||
| */ | ||
| function createBreak() { | ||
| return breakDef.create(); | ||
| } | ||
| /** | ||
| * Creates a {@link JsxNode} representing a raw JSX fragment in the source output. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createJsx('<>\n <a href={href}>Open</a>\n</>') | ||
| * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' } | ||
| * ``` | ||
| */ | ||
| const createJsx = jsxDef.create; | ||
| //#endregion | ||
| //#region src/nodes/content.ts | ||
| /** | ||
| * Definition for the {@link ContentNode}. | ||
| */ | ||
| const contentDef = defineNode({ | ||
| kind: "Content", | ||
| children: ["schema"] | ||
| }); | ||
| /** | ||
| * Creates a `ContentNode` for a single request-body or response content type. | ||
| */ | ||
| const createContent = contentDef.create; | ||
| //#endregion | ||
| //#region ../../internals/utils/src/casing.ts | ||
| /** | ||
| * Shared implementation for camelCase and PascalCase conversion. | ||
| * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons) | ||
| * and capitalizes each word according to `pascal`. | ||
| * | ||
| * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are. | ||
| */ | ||
| function toCamelOrPascal(text, pascal) { | ||
| return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => { | ||
| if (word.length > 1 && word === word.toUpperCase()) return word; | ||
| return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1); | ||
| }).join("").replace(/[^a-zA-Z0-9]/g, ""); | ||
| } | ||
| /** | ||
| * Converts `text` to PascalCase. | ||
| * | ||
| * @example Word boundaries | ||
| * `pascalCase('hello-world') // 'HelloWorld'` | ||
| * | ||
| * @example With a suffix | ||
| * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'` | ||
| */ | ||
| function pascalCase(text, { prefix = "", suffix = "" } = {}) { | ||
| return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true); | ||
| } | ||
| //#endregion | ||
| //#region ../../internals/utils/src/fs.ts | ||
| /** | ||
| * Strips the file extension from a path or file name. | ||
| * Only removes the last `.ext` segment when the dot is not part of a directory name. | ||
| * | ||
| * @example | ||
| * trimExtName('petStore.ts') // 'petStore' | ||
| * trimExtName('/src/models/pet.ts') // '/src/models/pet' | ||
| * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet' | ||
| * trimExtName('noExtension') // 'noExtension' | ||
| */ | ||
| function trimExtName(text) { | ||
| const dotIndex = text.lastIndexOf("."); | ||
| if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex); | ||
| return text; | ||
| } | ||
| //#endregion | ||
| //#region src/utils/extractStringsFromNodes.ts | ||
| /** | ||
| * Extracts all string content from a `CodeNode` tree recursively. | ||
| * | ||
| * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`), | ||
| * and nested node content. Used to build the full source string for import filtering. | ||
| */ | ||
| function extractStringsFromNodes(nodes) { | ||
| if (!nodes?.length) return ""; | ||
| return nodes.map((node) => { | ||
| if (typeof node === "string") return node; | ||
| if (node.kind === "Text") return node.value; | ||
| if (node.kind === "Break") return ""; | ||
| if (node.kind === "Jsx") return node.value; | ||
| const parts = []; | ||
| if ("params" in node && node.params) parts.push(node.params); | ||
| if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics); | ||
| if ("returnType" in node && node.returnType) parts.push(node.returnType); | ||
| if ("type" in node && typeof node.type === "string") parts.push(node.type); | ||
| const nested = extractStringsFromNodes(node.nodes); | ||
| if (nested) parts.push(nested); | ||
| return parts.join("\n"); | ||
| }).filter(Boolean).join("\n"); | ||
| } | ||
| //#endregion | ||
| //#region src/utils/fileMerge.ts | ||
| function sourceKey(source) { | ||
| return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`; | ||
| } | ||
| function pathTypeKey(path, isTypeOnly) { | ||
| return `${path}:${isTypeOnly ?? false}`; | ||
| } | ||
| function exportKey(path, name, isTypeOnly, asAlias) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`; | ||
| } | ||
| function importKey(path, name, isTypeOnly) { | ||
| return `${path}:${name ?? ""}:${isTypeOnly ?? false}`; | ||
| } | ||
| /** | ||
| * Computes a multi-level sort key for exports and imports: | ||
| * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named. | ||
| */ | ||
| function sortKey(node) { | ||
| const isArray = Array.isArray(node.name) ? "1" : "0"; | ||
| const typeOnly = node.isTypeOnly ? "0" : "1"; | ||
| const hasName = node.name != null ? "1" : "0"; | ||
| const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? ""; | ||
| return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`; | ||
| } | ||
| /** | ||
| * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each | ||
| * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns | ||
| * the deduplicated array in original order. | ||
| */ | ||
| function combineSources(sources) { | ||
| const seen = /* @__PURE__ */ new Map(); | ||
| for (const source of sources) { | ||
| const key = sourceKey(source); | ||
| if (!seen.has(key)) seen.set(key, source); | ||
| } | ||
| return [...seen.values()]; | ||
| } | ||
| /** | ||
| * Merges `incoming` names into `existing`, preserving order and dropping duplicates. | ||
| * | ||
| * Shared by `combineExports` and `combineImports` for the same-path name-merge case. | ||
| */ | ||
| function mergeNameArrays(existing, incoming) { | ||
| const merged = new Set(existing); | ||
| for (const name of incoming) merged.add(name); | ||
| return [...merged]; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ExportNode` objects by path and type. | ||
| * | ||
| * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export. | ||
| * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array. | ||
| */ | ||
| function combineExports(exports) { | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = exports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| const { name, path, isTypeOnly, asAlias } = curr; | ||
| if (Array.isArray(name)) { | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name: [...new Set(name)] | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| const key = exportKey(path, name, isTypeOnly, asAlias); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Deduplicates and merges `ImportNode` objects, filtering out unused imports. | ||
| * | ||
| * Retains imports that are referenced in `source` or re-exported. Imports with the same path and | ||
| * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array. | ||
| */ | ||
| function combineImports(imports, exports, source) { | ||
| const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : [])); | ||
| const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName); | ||
| const importNameMemo = /* @__PURE__ */ new Map(); | ||
| const canonicalizeName = (n) => { | ||
| if (typeof n === "string") return n; | ||
| const key = `${n.propertyName}:${n.name ?? ""}`; | ||
| if (!importNameMemo.has(key)) importNameMemo.set(key, n); | ||
| return importNameMemo.get(key); | ||
| }; | ||
| const pathsWithUsedNamedImport = /* @__PURE__ */ new Set(); | ||
| for (const node of imports) { | ||
| if (!Array.isArray(node.name)) continue; | ||
| if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path); | ||
| } | ||
| const result = []; | ||
| const namedByPath = /* @__PURE__ */ new Map(); | ||
| const seen = /* @__PURE__ */ new Set(); | ||
| const keyed = imports.map((node) => ({ | ||
| node, | ||
| key: sortKey(node) | ||
| })); | ||
| keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0); | ||
| for (const { node: curr } of keyed) { | ||
| if (curr.path === curr.root) continue; | ||
| const { path, isTypeOnly } = curr; | ||
| let { name } = curr; | ||
| if (Array.isArray(name)) { | ||
| name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName)); | ||
| if (!name.length) continue; | ||
| const key = pathTypeKey(path, isTypeOnly); | ||
| const existing = namedByPath.get(key); | ||
| if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name); | ||
| else { | ||
| const newItem = { | ||
| ...curr, | ||
| name | ||
| }; | ||
| result.push(newItem); | ||
| namedByPath.set(key, newItem); | ||
| } | ||
| } else { | ||
| if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue; | ||
| const key = importKey(path, name, isTypeOnly); | ||
| if (!seen.has(key)) { | ||
| result.push(curr); | ||
| seen.add(key); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/file.ts | ||
| /** | ||
| * Definition for the {@link ImportNode}. | ||
| */ | ||
| const importDef = defineNode({ kind: "Import" }); | ||
| /** | ||
| * Definition for the {@link ExportNode}. | ||
| */ | ||
| const exportDef = defineNode({ kind: "Export" }); | ||
| /** | ||
| * Definition for the {@link SourceNode}. | ||
| */ | ||
| const sourceDef = defineNode({ kind: "Source" }); | ||
| /** | ||
| * Definition for the {@link FileNode}. The fully resolved builder lives in | ||
| * `createFile`, so this definition only supplies the guard. | ||
| */ | ||
| const fileDef = defineNode({ kind: "File" }); | ||
| /** | ||
| * Creates an `ImportNode` representing a language-agnostic import/dependency declaration. | ||
| * | ||
| * @example Named import | ||
| * ```ts | ||
| * createImport({ name: ['useState'], path: 'react' }) | ||
| * // import { useState } from 'react' | ||
| * ``` | ||
| */ | ||
| const createImport = importDef.create; | ||
| /** | ||
| * Creates an `ExportNode` representing a language-agnostic export/public API declaration. | ||
| * | ||
| * @example Named export | ||
| * ```ts | ||
| * createExport({ name: ['Pet'], path: './Pet' }) | ||
| * // export { Pet } from './Pet' | ||
| * ``` | ||
| */ | ||
| const createExport = exportDef.create; | ||
| /** | ||
| * Creates a `SourceNode` representing a fragment of source code within a file. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true }) | ||
| * ``` | ||
| */ | ||
| const createSource = sourceDef.create; | ||
| /** | ||
| * Creates a fully resolved `FileNode` from a file input descriptor. | ||
| * | ||
| * Computes: | ||
| * - `id` SHA256 hash of the file path | ||
| * - `name` `baseName` without extension | ||
| * - `extname` extension extracted from `baseName` | ||
| * | ||
| * Deduplicates: | ||
| * - `sources` via `combineSources` | ||
| * - `exports` via `combineExports` | ||
| * - `imports` via `combineImports` (also filters unused imports) | ||
| * | ||
| * @throws {Error} when `baseName` has no extension. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'petStore.ts', | ||
| * path: 'src/models/petStore.ts', | ||
| * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })], | ||
| * imports: [createImport({ name: ['z'], path: 'zod' })], | ||
| * exports: [createExport({ name: ['Pet'], path: './petStore' })], | ||
| * }) | ||
| * // file.id = SHA256 hash of 'src/models/petStore.ts' | ||
| * // file.name = 'petStore' | ||
| * // file.extname = '.ts' | ||
| * ``` | ||
| * | ||
| * @example Copy a real file into the output verbatim | ||
| * ```ts | ||
| * const file = createFile({ | ||
| * baseName: 'client.ts', | ||
| * path: 'src/gen/client.ts', | ||
| * copy: '/abs/path/to/templates/client.ts', | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function createFile(input) { | ||
| const extname = node_path.default.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : ""); | ||
| if (!extname) throw new Error(`No extname found for ${input.baseName}`); | ||
| const source = (input.sources ?? []).flatMap((item) => item.nodes ?? []).map((node) => extractStringsFromNodes([node])).filter(Boolean).join("\n\n"); | ||
| const resolvedExports = input.exports?.length ? combineExports(input.exports) : []; | ||
| const combinedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || void 0) : []; | ||
| const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name))); | ||
| const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName; | ||
| const resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => { | ||
| if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp]; | ||
| const kept = imp.name.filter((item) => !localNames.has(nameOf(item))); | ||
| if (!kept.length) return []; | ||
| return [kept.length === imp.name.length ? imp : { | ||
| ...imp, | ||
| name: kept | ||
| }]; | ||
| }); | ||
| const resolvedSources = input.sources?.length ? combineSources(input.sources) : []; | ||
| return { | ||
| kind: "File", | ||
| ...input, | ||
| id: (0, node_crypto.hash)("sha256", input.path, "hex"), | ||
| name: trimExtName(input.baseName), | ||
| extname, | ||
| imports: resolvedImports, | ||
| exports: resolvedExports, | ||
| sources: resolvedSources, | ||
| meta: input.meta ?? {} | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/input.ts | ||
| /** | ||
| * Definition for the {@link InputNode}. | ||
| */ | ||
| const inputDef = defineNode({ | ||
| kind: "Input", | ||
| defaults: { | ||
| schemas: [], | ||
| operations: [], | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| } | ||
| }, | ||
| children: ["schemas", "operations"], | ||
| visitorKey: "input" | ||
| }); | ||
| /** | ||
| * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and | ||
| * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array | ||
| * `schemas`/`operations`. Both variants get the defaulted `meta`. | ||
| * | ||
| * @example Eager | ||
| * ```ts | ||
| * const input = createInput() | ||
| * // { kind: 'Input', schemas: [], operations: [] } | ||
| * ``` | ||
| * | ||
| * @example Streaming | ||
| * ```ts | ||
| * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } }) | ||
| * ``` | ||
| */ | ||
| function createInput(options = {}) { | ||
| const { stream, ...overrides } = options; | ||
| if (stream) return { | ||
| kind: "Input", | ||
| meta: { | ||
| circularNames: [], | ||
| enumNames: [] | ||
| }, | ||
| ...overrides | ||
| }; | ||
| return inputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/requestBody.ts | ||
| /** | ||
| * Definition for the {@link RequestBodyNode}. Content entries are built upfront with | ||
| * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes. | ||
| */ | ||
| const requestBodyDef = defineNode({ | ||
| kind: "RequestBody", | ||
| children: ["content"] | ||
| }); | ||
| /** | ||
| * Creates a `RequestBodyNode`. | ||
| */ | ||
| const createRequestBody = requestBodyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/operation.ts | ||
| /** | ||
| * Definition for the {@link OperationNode}. HTTP operations (those carrying both | ||
| * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is | ||
| * normalized into a `RequestBodyNode`. | ||
| */ | ||
| const operationDef = defineNode({ | ||
| kind: "Operation", | ||
| build: (props) => { | ||
| const { requestBody, ...rest } = props; | ||
| const isHttp = rest.method !== void 0 && rest.path !== void 0; | ||
| return { | ||
| tags: [], | ||
| parameters: [], | ||
| responses: [], | ||
| ...rest, | ||
| ...isHttp ? { protocol: "http" } : {}, | ||
| requestBody: requestBody ? createRequestBody(requestBody) : void 0 | ||
| }; | ||
| }, | ||
| children: [ | ||
| "parameters", | ||
| "requestBody", | ||
| "responses" | ||
| ], | ||
| visitorKey: "operation" | ||
| }); | ||
| function createOperation(props) { | ||
| return operationDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/output.ts | ||
| /** | ||
| * Definition for the {@link OutputNode}. | ||
| */ | ||
| const outputDef = defineNode({ | ||
| kind: "Output", | ||
| defaults: { files: [] }, | ||
| visitorKey: "output" | ||
| }); | ||
| /** | ||
| * Creates an `OutputNode` with a stable default for `files`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const output = createOutput() | ||
| * // { kind: 'Output', files: [] } | ||
| * ``` | ||
| */ | ||
| function createOutput(overrides = {}) { | ||
| return outputDef.create(overrides); | ||
| } | ||
| //#endregion | ||
| //#region src/optionality.ts | ||
| /** | ||
| * Generic JSON Schema optionality: a non-required field is optional, and a | ||
| * non-required nullable field is nullish. | ||
| */ | ||
| function optionality(schema, required) { | ||
| const nullable = schema.nullable ?? false; | ||
| return { | ||
| ...schema, | ||
| optional: !required && !nullable ? true : void 0, | ||
| nullish: !required && nullable ? true : void 0 | ||
| }; | ||
| } | ||
| //#endregion | ||
| //#region src/nodes/parameter.ts | ||
| /** | ||
| * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const parameterDef = defineNode({ | ||
| kind: "Parameter", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "parameter" | ||
| }); | ||
| /** | ||
| * Creates a `ParameterNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const param = createParameter({ | ||
| * name: 'petId', | ||
| * in: 'path', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string' }), | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createParameter = parameterDef.create; | ||
| //#endregion | ||
| //#region src/nodes/property.ts | ||
| /** | ||
| * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's | ||
| * `optional`/`nullish` flags are derived from it through {@link optionality}. | ||
| */ | ||
| const propertyDef = defineNode({ | ||
| kind: "Property", | ||
| build: (props) => { | ||
| const required = props.required ?? false; | ||
| return { | ||
| ...props, | ||
| required, | ||
| schema: optionality(props.schema, required) | ||
| }; | ||
| }, | ||
| children: ["schema"], | ||
| visitorKey: "property" | ||
| }); | ||
| /** | ||
| * Creates a `PropertyNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const property = createProperty({ | ||
| * name: 'status', | ||
| * required: true, | ||
| * schema: createSchema({ type: 'string', nullable: true }), | ||
| * }) | ||
| * // required=true, no optional/nullish | ||
| * ``` | ||
| */ | ||
| const createProperty = propertyDef.create; | ||
| //#endregion | ||
| //#region src/nodes/response.ts | ||
| /** | ||
| * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional | ||
| * `mediaType`/`keysToOmit`) is normalized into one `content` entry. | ||
| */ | ||
| const responseDef = defineNode({ | ||
| kind: "Response", | ||
| build: (props) => { | ||
| const { schema, mediaType, keysToOmit, content, ...rest } = props; | ||
| const entries = content ?? (schema ? [createContent({ | ||
| contentType: mediaType ?? "application/json", | ||
| schema, | ||
| keysToOmit: keysToOmit ?? null | ||
| })] : void 0); | ||
| return { | ||
| ...rest, | ||
| content: entries | ||
| }; | ||
| }, | ||
| children: ["content"], | ||
| visitorKey: "response" | ||
| }); | ||
| /** | ||
| * Creates a `ResponseNode`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const response = createResponse({ | ||
| * statusCode: '200', | ||
| * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })], | ||
| * }) | ||
| * ``` | ||
| */ | ||
| const createResponse = responseDef.create; | ||
| //#endregion | ||
| //#region src/nodes/schema.ts | ||
| /** | ||
| * Maps schema `type` to its underlying `primitive`. | ||
| * Primitive types map to themselves and special string formats map to `'string'`. | ||
| * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`. | ||
| */ | ||
| const TYPE_TO_PRIMITIVE = { | ||
| string: "string", | ||
| number: "number", | ||
| integer: "integer", | ||
| bigint: "bigint", | ||
| boolean: "boolean", | ||
| null: "null", | ||
| any: "any", | ||
| unknown: "unknown", | ||
| void: "void", | ||
| never: "never", | ||
| object: "object", | ||
| array: "array", | ||
| date: "date", | ||
| uuid: "string", | ||
| email: "string", | ||
| url: "string", | ||
| datetime: "string", | ||
| time: "string" | ||
| }; | ||
| /** | ||
| * Definition for the {@link SchemaNode}. Object schemas default `properties` to an | ||
| * empty array, and `primitive` is inferred from `type` when not explicitly provided. | ||
| */ | ||
| const schemaDef = defineNode({ | ||
| kind: "Schema", | ||
| build: (props) => { | ||
| if (props.type === "object") return { | ||
| properties: [], | ||
| primitive: "object", | ||
| ...props | ||
| }; | ||
| return { | ||
| primitive: TYPE_TO_PRIMITIVE[props.type], | ||
| ...props | ||
| }; | ||
| }, | ||
| children: [ | ||
| "properties", | ||
| "items", | ||
| "members", | ||
| "additionalProperties" | ||
| ], | ||
| visitorKey: "schema" | ||
| }); | ||
| function createSchema(props) { | ||
| return schemaDef.create(props); | ||
| } | ||
| //#endregion | ||
| //#region src/registry.ts | ||
| /** | ||
| * Every node definition. Adding a node means adding its `defineNode` to one | ||
| * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it. | ||
| */ | ||
| const nodeDefs = [ | ||
| inputDef, | ||
| outputDef, | ||
| operationDef, | ||
| requestBodyDef, | ||
| contentDef, | ||
| responseDef, | ||
| schemaDef, | ||
| propertyDef, | ||
| parameterDef, | ||
| constDef, | ||
| typeDef, | ||
| functionDef, | ||
| arrowFunctionDef, | ||
| textDef, | ||
| breakDef, | ||
| jsxDef, | ||
| importDef, | ||
| exportDef, | ||
| sourceDef, | ||
| fileDef | ||
| ]; | ||
| //#endregion | ||
| //#region src/visitor.ts | ||
| /** | ||
| * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`). | ||
| * Derived from each definition's `children`. | ||
| */ | ||
| const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : [])); | ||
| /** | ||
| * Maps a node kind to the matching visitor callback name. Derived from each | ||
| * definition's `visitorKey`. | ||
| */ | ||
| const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : [])); | ||
| /** | ||
| * Creates a small async concurrency limiter. | ||
| * | ||
| * At most `concurrency` tasks are in flight at once. Extra tasks are queued. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const limit = createLimit(2) | ||
| * for (const task of [taskA, taskB, taskC]) { | ||
| * await limit(() => task()) | ||
| * } | ||
| * // only 2 tasks run at the same time | ||
| * ``` | ||
| */ | ||
| function createLimit(concurrency) { | ||
| let active = 0; | ||
| const queue = []; | ||
| function next() { | ||
| if (active < concurrency && queue.length > 0) { | ||
| active++; | ||
| queue.shift()(); | ||
| } | ||
| } | ||
| return function limit(fn) { | ||
| return new Promise((resolve, reject) => { | ||
| queue.push(() => { | ||
| Promise.resolve(fn()).then(resolve, reject).finally(() => { | ||
| active--; | ||
| next(); | ||
| }); | ||
| }); | ||
| next(); | ||
| }); | ||
| }; | ||
| } | ||
| const visitorKeysByKind = VISITOR_KEYS; | ||
| /** | ||
| * Returns `true` when `value` is an AST node (an object carrying a `kind`). | ||
| */ | ||
| function isNode(value) { | ||
| return typeof value === "object" && value !== null && "kind" in value; | ||
| } | ||
| /** | ||
| * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}. | ||
| * | ||
| * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const children = getChildren(operationNode, true) | ||
| * // returns parameters, the request body, and responses | ||
| * ``` | ||
| */ | ||
| function* getChildren(node, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return; | ||
| const record = node; | ||
| for (const key of keys) { | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| for (const item of value) if (isNode(item)) yield item; | ||
| } else if (isNode(value)) yield value; | ||
| } | ||
| } | ||
| /** | ||
| * Runs the visitor callback that matches `node.kind` with the traversal | ||
| * context. The result is a replacement node, a collected value, or `undefined` | ||
| * when no callback is registered for the kind. | ||
| * | ||
| * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives | ||
| * in one place. `TResult` is the caller's expected return: the same node type | ||
| * for `transform`, the collected value type for `collectLazy`, ignored for `walk`. | ||
| */ | ||
| function applyVisitor(node, visitor, parent) { | ||
| const key = VISITOR_KEY_BY_KIND[node.kind]; | ||
| if (!key) return void 0; | ||
| const fn = visitor[key]; | ||
| return fn?.(node, { parent }); | ||
| } | ||
| /** | ||
| * Async depth-first traversal for side effects. Visitor return values are | ||
| * ignored. Use `transform` when you want to rewrite nodes. | ||
| * | ||
| * Sibling nodes at each depth run concurrently up to `options.concurrency` | ||
| * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor | ||
| * work. Lower values reduce memory pressure. | ||
| * | ||
| * @example Log every operation | ||
| * ```ts | ||
| * await walk(root, { | ||
| * operation(node) { | ||
| * console.log(node.operationId) | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @example Only visit the root node | ||
| * ```ts | ||
| * await walk(root, { depth: 'shallow', input: () => {} }) | ||
| * ``` | ||
| */ | ||
| async function walk(node, options) { | ||
| return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0); | ||
| } | ||
| async function _walk(node, visitor, recurse, limit, parent) { | ||
| await limit(() => applyVisitor(node, visitor, parent)); | ||
| const children = Array.from(getChildren(node, recurse)); | ||
| if (children.length === 0) return; | ||
| await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node))); | ||
| } | ||
| function transform(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse); | ||
| } | ||
| /** | ||
| * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming | ||
| * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact. | ||
| * `Schema` children are skipped in shallow mode. | ||
| */ | ||
| function transformChildren(node, options, recurse) { | ||
| if (node.kind === "Schema" && !recurse) return node; | ||
| const keys = visitorKeysByKind[node.kind]; | ||
| if (!keys) return node; | ||
| const record = node; | ||
| const childOptions = { | ||
| ...options, | ||
| parent: node | ||
| }; | ||
| let updates; | ||
| for (const key of keys) { | ||
| if (!(key in record)) continue; | ||
| const value = record[key]; | ||
| if (Array.isArray(value)) { | ||
| let changed = false; | ||
| const mapped = value.map((item) => { | ||
| if (!isNode(item)) return item; | ||
| const next = transform(item, childOptions); | ||
| if (next !== item) changed = true; | ||
| return next; | ||
| }); | ||
| if (changed) (updates ??= {})[key] = mapped; | ||
| } else if (isNode(value)) { | ||
| const next = transform(value, childOptions); | ||
| if (next !== value) (updates ??= {})[key] = next; | ||
| } | ||
| } | ||
| return updates ? { | ||
| ...node, | ||
| ...updates | ||
| } : node; | ||
| } | ||
| /** | ||
| * Lazy depth-first collection pass. Yields every non-null value returned by | ||
| * the visitor callbacks. Use `collect` for the eager array form. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids: string[] = [] | ||
| * for (const id of collectLazy<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * })) { | ||
| * ids.push(id) | ||
| * } | ||
| * ``` | ||
| */ | ||
| function* collectLazy(node, options) { | ||
| const { depth, parent, ...visitor } = options; | ||
| const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep; | ||
| const v = applyVisitor(node, visitor, parent); | ||
| if (v != null) yield v; | ||
| for (const child of getChildren(node, recurse)) yield* collectLazy(child, { | ||
| ...options, | ||
| parent: node | ||
| }); | ||
| } | ||
| /** | ||
| * Eager depth-first collection pass. Gathers every non-null value the visitor | ||
| * callbacks return into an array. | ||
| * | ||
| * @example Collect every operationId | ||
| * ```ts | ||
| * const ids = collect<string>(root, { | ||
| * operation(node) { | ||
| * return node.operationId | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function collect(node, options) { | ||
| return Array.from(collectLazy(node, options)); | ||
| } | ||
| //#endregion | ||
| Object.defineProperty(exports, "INDENT", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return INDENT; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "__exportAll", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return __exportAll; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "__name", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return __name; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "arrowFunctionDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return arrowFunctionDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "breakDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return breakDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "collect", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return collect; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "collectLazy", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return collectLazy; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "constDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return constDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "contentDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return contentDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createArrowFunction", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createArrowFunction; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createBreak", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createBreak; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createConst", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createConst; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createContent", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createContent; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createExport", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createExport; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createFile", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createFile; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createFunction", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createFunction; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createImport", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createImport; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createInput", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createInput; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createJsx", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createJsx; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createOperation", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createOperation; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createOutput", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createOutput; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createParameter", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createParameter; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createProperty", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createProperty; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createRequestBody", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createRequestBody; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createResponse", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createResponse; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createSchema", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createSchema; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createSource", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createSource; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createText", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createText; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "createType", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createType; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "defineNode", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return defineNode; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "exportDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return exportDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "extractStringsFromNodes", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return extractStringsFromNodes; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "fileDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return fileDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "functionDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return functionDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "importDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return importDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "inputDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return inputDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "isHttpOperationNode", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return isHttpOperationNode; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "jsxDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return jsxDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "narrowSchema", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return narrowSchema; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "nodeDefs", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return nodeDefs; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "operationDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return operationDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "optionality", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return optionality; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "outputDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return outputDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "parameterDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return parameterDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "pascalCase", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return pascalCase; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "propertyDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return propertyDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "requestBodyDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return requestBodyDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "responseDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return responseDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "schemaDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return schemaDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "schemaTypes", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return schemaTypes; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "sourceDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return sourceDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "textDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return textDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "transform", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return transform; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "typeDef", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return typeDef; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "visitorKeys", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return visitorKeys; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "walk", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return walk; | ||
| } | ||
| }); | ||
| //# sourceMappingURL=visitor-ChiWLwlh.cjs.map |
Sorry, the diff of this file is too big to display
635984
-0.17%8486
-0.18%