@kubb/ast 5.0.0-beta.61 → 5.0.0-beta.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{defineMacro-BLIR6k-j.d.ts → defineMacro-BATi7xoC.d.ts} +11 -20
- package/dist/{defineMacro-Bv9R_9a2.cjs → defineMacro-CEZHaCXE.cjs} +13 -21
- package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
- package/dist/{defineMacro-BTXvS8nI.js → defineMacro-Shz8f6SG.js} +12 -19
- package/dist/defineMacro-Shz8f6SG.js.map +1 -0
- package/dist/factory.cjs +88 -28
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.ts +6 -41
- package/dist/factory.js +58 -3
- package/dist/factory.js.map +1 -0
- package/dist/{index-BzjwdK2M.d.ts → index-B9cc8MBS.d.ts} +164 -194
- package/dist/index.cjs +144 -274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +43 -37
- package/dist/index.js +109 -235
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +41 -28
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.d.ts +14 -12
- package/dist/macros.js +34 -21
- package/dist/macros.js.map +1 -1
- package/dist/{operationParams-BZ07xDm0.d.ts → operationParams-k5CKwSWZ.d.ts} +9 -2
- package/dist/{visitor-DJ6ZEJvq.js → refs-BjNDuCBD.js} +116 -159
- package/dist/refs-BjNDuCBD.js.map +1 -0
- package/dist/{visitor-DpKZ9Tk0.cjs → refs-u5SDdyV7.cjs} +140 -195
- package/dist/refs-u5SDdyV7.cjs.map +1 -0
- package/dist/{response-hnSw2NKE.cjs → schema-BkvrrOAr.cjs} +496 -231
- package/dist/schema-BkvrrOAr.cjs.map +1 -0
- package/dist/{response-KUdWiDWw.js → schema-Cbnxmz4b.js} +472 -220
- package/dist/schema-Cbnxmz4b.js.map +1 -0
- package/dist/{types-DyDzizSf.d.ts → types-BB_xgRJ3.d.ts} +49 -123
- package/dist/types.d.ts +5 -6
- package/dist/{utils-BLJwyza-.cjs → utils-CEepwqmb.cjs} +76 -69
- package/dist/utils-CEepwqmb.cjs.map +1 -0
- package/dist/{utils-CF_-Pn_c.js → utils-DaXkewb1.js} +58 -51
- package/dist/utils-DaXkewb1.js.map +1 -0
- package/dist/utils.cjs +11 -11
- package/dist/utils.d.ts +53 -30
- package/dist/utils.js +3 -3
- package/package.json +1 -1
- package/src/constants.ts +3 -36
- package/src/defineMacro.ts +20 -13
- package/src/{node.ts → defineNode.ts} +12 -38
- package/src/{printer.ts → definePrinter.ts} +5 -3
- package/src/dialect.ts +52 -19
- package/src/factory.ts +7 -94
- package/src/index.ts +7 -9
- package/src/infer.ts +1 -1
- package/src/macros/macroDiscriminatorEnum.ts +7 -1
- package/src/macros/macroEnumName.ts +10 -2
- package/src/macros/macroSimplifyUnion.ts +29 -19
- package/src/nodes/code.ts +40 -80
- package/src/nodes/content.ts +2 -7
- package/src/nodes/file.ts +107 -18
- package/src/nodes/function.ts +46 -46
- package/src/nodes/index.ts +2 -3
- package/src/nodes/input.ts +13 -9
- package/src/nodes/operation.ts +8 -5
- package/src/nodes/output.ts +1 -1
- package/src/nodes/parameter.ts +5 -5
- package/src/nodes/property.ts +5 -5
- package/src/nodes/requestBody.ts +6 -13
- package/src/nodes/response.ts +93 -8
- package/src/nodes/schema.ts +5 -5
- package/src/optionality.ts +15 -0
- package/src/registry.ts +1 -1
- package/src/types.ts +4 -6
- package/src/utils/codegen.ts +6 -7
- package/src/utils/extractStringsFromNodes.ts +1 -0
- package/src/utils/fileMerge.ts +7 -8
- package/src/utils/operationParams.ts +9 -9
- package/src/utils/refs.ts +14 -18
- package/src/utils/schemaGraph.ts +41 -33
- package/src/utils/schemaMerge.ts +2 -2
- package/src/visitor.ts +3 -14
- package/dist/defineMacro-BTXvS8nI.js.map +0 -1
- package/dist/defineMacro-Bv9R_9a2.cjs.map +0 -1
- package/dist/extractStringsFromNodes-Cja-xxx5.js +0 -29
- package/dist/extractStringsFromNodes-Cja-xxx5.js.map +0 -1
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs +0 -34
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +0 -1
- package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +0 -14
- package/dist/factory-CZNOGI-N.js +0 -283
- package/dist/factory-CZNOGI-N.js.map +0 -1
- package/dist/factory-DG1CVkEb.cjs +0 -300
- package/dist/factory-DG1CVkEb.cjs.map +0 -1
- package/dist/response-KUdWiDWw.js.map +0 -1
- package/dist/response-hnSw2NKE.cjs.map +0 -1
- package/dist/utils-BLJwyza-.cjs.map +0 -1
- package/dist/utils-CF_-Pn_c.js.map +0 -1
- package/dist/visitor-DJ6ZEJvq.js.map +0 -1
- package/dist/visitor-DpKZ9Tk0.cjs.map +0 -1
- package/src/dedupe.ts +0 -239
- package/src/mocks.ts +0 -56
- package/src/nodes/http.ts +0 -85
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DaXkewb1.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","../src/utils/operationParams.ts"],"sourcesContent":["function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\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","import { camelCase, isValidVarName, memoize } from '@internals/utils'\nimport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createTypeLiteral } from '../nodes/function.ts'\nimport type { FunctionParameterNode, FunctionParametersNode, OperationNode, ParameterNode, TypeExpression, TypeLiteralNode } from '../nodes/index.ts'\nimport { resolveGroupType } from './refs.ts'\n\nconst caseParamsMemo = memoize(new WeakMap<Array<ParameterNode>, (casing: string) => Array<ParameterNode>>(), (params) =>\n memoize(new Map<string, Array<ParameterNode>>(), (casing: string) =>\n params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n return { ...param, name: transformed }\n }),\n ),\n)\n\n/**\n * Applies casing rules to parameter names and returns a new array without mutating the input.\n *\n * Run it before handing parameters to schema builders so output property keys get the right casing\n * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the\n * original array is returned unchanged.\n */\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) return params\n return caseParamsMemo(params)(casing)\n}\n\n/**\n * Named type for a group of parameters (query or header) emitted as a single typed parameter.\n */\nexport type ParamGroupType = {\n /**\n * Type expression for the group, a plain group-name reference.\n */\n type: TypeExpression\n /**\n * Whether the parameter group is optional.\n */\n optional: boolean\n}\n\n/**\n * A single member of a destructured parameter group, fed to `createFunctionParameter({ properties })`.\n */\ntype GroupProperty = {\n name: string\n type: TypeExpression\n optional?: boolean\n}\n\n/**\n * Resolver interface for {@link createOperationParams}.\n *\n * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.\n */\nexport type OperationParamsResolver = {\n /**\n * Resolves the type name for an individual parameter.\n *\n * @example Individual path parameter name\n * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`\n */\n resolveParamName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the request body type name.\n *\n * @example Request body type name\n * `resolver.resolveDataName(node) // → 'CreatePetData'`\n */\n resolveDataName(node: OperationNode): string\n /**\n * Resolves the grouped path parameters type name.\n * When the return value equals `resolveParamName`, no indexed access is emitted.\n *\n * @example Grouped path params type name\n * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`\n */\n resolvePathParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped query parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped query params type name\n * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`\n */\n resolveQueryParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped header parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped header params type name\n * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`\n */\n resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string\n}\n\n/**\n * Options for {@link createOperationParams}.\n */\nexport type CreateOperationParamsOptions = {\n /**\n * How all operation parameters are grouped in the function signature.\n * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`\n * - `'inline'` emits each param category as a separate top-level parameter\n */\n paramsType: 'object' | 'inline'\n /**\n * How path parameters are emitted when `paramsType` is `'inline'`.\n * - `'object'` groups them as `{ petId, storeId }: PathParams`\n * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`\n * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`\n */\n pathParamsType: 'object' | 'inline' | 'inlineSpread'\n /**\n * Converts parameter names to camelCase before output.\n */\n paramsCasing?: 'camelcase'\n /**\n * Resolver for parameter and request body type names.\n * Pass `ResolverTs` from `@kubb/plugin-ts` directly.\n * When omitted, falls back to the schema primitive or `'unknown'`.\n */\n resolver?: OperationParamsResolver\n /**\n * Default value for the path parameters binding when `pathParamsType` is `'object'`.\n * Falls back to `'{}'` when all path params are optional.\n */\n pathParamsDefault?: string\n /**\n * Extra parameters appended after the standard operation parameters.\n *\n * @example Plugin-specific trailing parameter\n * ```ts\n * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]\n * ```\n */\n extraParams?: Array<FunctionParameterNode>\n /**\n * Override the default parameter names used for body, query, header, and rest-path groups.\n *\n * Useful when targeting languages or frameworks with different naming conventions.\n *\n * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }\n */\n paramNames?: {\n /**\n * Name for the request body parameter.\n * @default 'data'\n */\n data?: string\n /**\n * Name for the query parameters group parameter.\n * @default 'params'\n */\n params?: string\n /**\n * Name for the header parameters group parameter.\n * @default 'headers'\n */\n headers?: string\n /**\n * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.\n * @default 'pathParams'\n */\n path?: string\n }\n /**\n * Transforms every resolved type name before it lands in a parameter node, for framework-level\n * type wrappers.\n *\n * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`\n * `typeWrapper: (t) => \\`MaybeRefOrGetter<${t}>\\``\n */\n typeWrapper?: (type: string) => string\n}\n\n/**\n * Resolves the {@link TypeExpression} for an individual parameter.\n *\n * Without a resolver, it falls back to the schema primitive (a plain type-name string). When the\n * parameter belongs to a named group, it emits an {@link IndexedAccessTypeNode} like\n * `GroupParams['petId']`, otherwise the resolved individual name.\n */\nexport function resolveParamType({\n node,\n param,\n resolver,\n}: {\n node: OperationNode\n param: ParameterNode\n resolver: OperationParamsResolver | undefined\n}): TypeExpression {\n if (!resolver) {\n return param.schema.primitive ?? 'unknown'\n }\n\n const individualName = resolver.resolveParamName(node, param)\n\n const groupLocation = param.in === 'path' || param.in === 'query' || param.in === 'header' ? param.in : undefined\n\n const groupResolvers = {\n path: resolver.resolvePathParamsName,\n query: resolver.resolveQueryParamsName,\n header: resolver.resolveHeaderParamsName,\n } as const\n\n const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : undefined\n\n if (groupName && groupName !== individualName) {\n return createIndexedAccessType({ target: groupName, key: param.name })\n }\n\n return individualName\n}\n\n/**\n * Converts an `OperationNode` into function parameters for code generation.\n *\n * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one\n * destructured object parameter (`object`) and separate top-level parameters (`inline`), while\n * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type\n * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.\n */\nexport function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode {\n const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options\n\n const dataName = paramNames?.data ?? 'data'\n const paramsName = paramNames?.params ?? 'params'\n const headersName = paramNames?.headers ?? 'headers'\n const pathName = paramNames?.path ?? 'pathParams'\n\n const wrapType = (type: string): string => (typeWrapper ? typeWrapper(type) : type)\n // typeWrapper takes a type-name string, so only plain references are wrapped.\n // TypeLiteral and IndexedAccessType expressions are pre-resolved and pass through unchanged.\n const wrapTypeExpression = (type: TypeExpression): TypeExpression => (typeof type === 'string' ? wrapType(type) : type)\n\n const casedParams = caseParams(node.parameters, paramsCasing)\n const pathParams = casedParams.filter((p) => p.in === 'path')\n const queryParams = casedParams.filter((p) => p.in === 'query')\n const headerParams = casedParams.filter((p) => p.in === 'header')\n\n const toProperty = (param: ParameterNode): GroupProperty => ({\n name: param.name,\n type: wrapTypeExpression(resolveParamType({ node, param, resolver })),\n optional: !param.required,\n })\n const emptyObjectDefault = (props: Array<GroupProperty>): string | undefined => (props.every((p) => p.optional) ? '{}' : undefined)\n\n const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined\n const bodyProperty: Array<GroupProperty> = bodyType ? [{ name: dataName, type: bodyType, optional: !(node.requestBody?.required ?? false) }] : []\n\n const trailingGroups: Array<BuildGroupArgs> = [\n { name: paramsName, node, params: queryParams, groupType: resolveGroupType({ node, params: queryParams, group: 'query', resolver }), resolver, wrapType },\n {\n name: headersName,\n node,\n params: headerParams,\n groupType: resolveGroupType({ node, params: headerParams, group: 'header', resolver }),\n resolver,\n wrapType,\n },\n ]\n\n const params: Array<FunctionParameterNode> = []\n\n if (paramsType === 'object') {\n const children = [...pathParams.map(toProperty), ...bodyProperty, ...trailingGroups.flatMap(buildGroupProperty)]\n if (children.length) {\n params.push(createFunctionParameter({ properties: children, default: emptyObjectDefault(children) }))\n }\n } else {\n if (pathParamsType === 'inlineSpread' && pathParams.length) {\n const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]!)\n params.push(createFunctionParameter({ name: pathName, type: spreadType ? wrapType(spreadType) : undefined, rest: true }))\n } else if (pathParamsType === 'inline') {\n params.push(...pathParams.map((p) => createFunctionParameter(toProperty(p))))\n } else if (pathParams.length) {\n const pathChildren = pathParams.map(toProperty)\n params.push(createFunctionParameter({ properties: pathChildren, default: pathParamsDefault ?? emptyObjectDefault(pathChildren) }))\n }\n\n params.push(...bodyProperty.map((p) => createFunctionParameter(p)))\n params.push(...trailingGroups.flatMap(buildGroupParam))\n }\n\n params.push(...extraParams)\n\n return createFunctionParameters({ params })\n}\n\n/**\n * Shared arguments for building a query or header parameter group.\n */\nexport type BuildGroupArgs = {\n name: string\n node: OperationNode\n params: Array<ParameterNode>\n groupType: ParamGroupType | null\n resolver: OperationParamsResolver | undefined\n wrapType: (type: string) => string\n}\n\n/**\n * Builds the property descriptor for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nfunction buildGroupProperty({ name, node, params, groupType, resolver, wrapType }: BuildGroupArgs): Array<GroupProperty> {\n if (groupType) {\n const type = typeof groupType.type === 'string' ? wrapType(groupType.type) : groupType.type\n return [{ name, type, optional: groupType.optional }]\n }\n if (params.length) {\n return [{ name, type: buildTypeLiteral({ node, params, resolver }), optional: params.every((p) => !p.required) }]\n }\n return []\n}\n\n/**\n * Builds a single {@link FunctionParameterNode} for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nexport function buildGroupParam(args: BuildGroupArgs): Array<FunctionParameterNode> {\n return buildGroupProperty(args).map((p) => createFunctionParameter(p))\n}\n\n/**\n * Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.\n *\n * Used when query or header parameters have no dedicated group type name.\n * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).\n */\nexport function buildTypeLiteral({\n node,\n params,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n resolver: OperationParamsResolver | undefined\n}): TypeLiteralNode {\n return createTypeLiteral({\n members: params.map((p) => ({\n name: p.name,\n type: resolveParamType({ node, param: p, resolver }),\n optional: !p.required,\n })),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA,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;;;;;;;AChJA,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;CAC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qBAAqB,mBAAmB,YAAY;GAAE,CAAC,CAAC;EACnI;EAEA,OAAO,KAAK,GAAG,aAAa,KAAK,MAAM,wBAAwB,CAAC,CAAC,CAAC;EAClE,OAAO,KAAK,GAAG,eAAe,QAAQ,eAAe,CAAC;CACxD;CAEA,OAAO,KAAK,GAAG,WAAW;CAE1B,OAAO,yBAAyB,EAAE,OAAO,CAAC;AAC5C;;;;;;;;AAqBA,SAAS,mBAAmB,EAAE,MAAM,MAAM,QAAQ,WAAW,UAAU,YAAkD;CACvH,IAAI,WAEF,OAAO,CAAC;EAAE;EAAM,MADH,OAAO,UAAU,SAAS,WAAW,SAAS,UAAU,IAAI,IAAI,UAAU;EACjE,UAAU,UAAU;CAAS,CAAC;CAEtD,IAAI,OAAO,QACT,OAAO,CAAC;EAAE;EAAM,MAAM,iBAAiB;GAAE;GAAM;GAAQ;EAAS,CAAC;EAAG,UAAU,OAAO,OAAO,MAAM,CAAC,EAAE,QAAQ;CAAE,CAAC;CAElH,OAAO,CAAC;AACV;;;;;;;;AASA,SAAgB,gBAAgB,MAAoD;CAClF,OAAO,mBAAmB,IAAI,CAAC,CAAC,KAAK,MAAM,wBAAwB,CAAC,CAAC;AACvE;;;;;;;AAQA,SAAgB,iBAAiB,EAC/B,MACA,QACA,YAKkB;CAClB,OAAO,kBAAkB,EACvB,SAAS,OAAO,KAAK,OAAO;EAC1B,MAAM,EAAE;EACR,MAAM,iBAAiB;GAAE;GAAM,OAAO;GAAG;EAAS,CAAC;EACnD,UAAU,CAAC,EAAE;CACf,EAAE,EACJ,CAAC;AACH"}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
const require_schema = require("./schema-BkvrrOAr.cjs");
|
|
3
|
+
const require_refs = require("./refs-u5SDdyV7.cjs");
|
|
4
|
+
const require_utils = require("./utils-CEepwqmb.cjs");
|
|
5
5
|
exports.buildGroupParam = require_utils.buildGroupParam;
|
|
6
6
|
exports.buildJSDoc = require_utils.buildJSDoc;
|
|
7
7
|
exports.buildList = require_utils.buildList;
|
|
8
8
|
exports.buildObject = require_utils.buildObject;
|
|
9
9
|
exports.buildTypeLiteral = require_utils.buildTypeLiteral;
|
|
10
10
|
exports.caseParams = require_utils.caseParams;
|
|
11
|
-
exports.childName =
|
|
11
|
+
exports.childName = require_refs.childName;
|
|
12
12
|
exports.collectUsedSchemaNames = require_utils.collectUsedSchemaNames;
|
|
13
13
|
exports.containsCircularRef = require_utils.containsCircularRef;
|
|
14
14
|
exports.createOperationParams = require_utils.createOperationParams;
|
|
15
|
-
exports.enumPropName =
|
|
16
|
-
exports.extractRefName =
|
|
17
|
-
exports.extractStringsFromNodes =
|
|
15
|
+
exports.enumPropName = require_refs.enumPropName;
|
|
16
|
+
exports.extractRefName = require_refs.extractRefName;
|
|
17
|
+
exports.extractStringsFromNodes = require_schema.extractStringsFromNodes;
|
|
18
18
|
exports.findCircularSchemas = require_utils.findCircularSchemas;
|
|
19
19
|
exports.getNestedAccessor = require_utils.getNestedAccessor;
|
|
20
|
-
exports.isStringType =
|
|
20
|
+
exports.isStringType = require_refs.isStringType;
|
|
21
21
|
exports.isValidVarName = require_utils.isValidVarName;
|
|
22
22
|
exports.jsStringEscape = require_utils.jsStringEscape;
|
|
23
23
|
exports.lazyGetter = require_utils.lazyGetter;
|
|
@@ -26,11 +26,11 @@ exports.mapSchemaMembers = require_utils.mapSchemaMembers;
|
|
|
26
26
|
exports.mapSchemaProperties = require_utils.mapSchemaProperties;
|
|
27
27
|
exports.mergeAdjacentObjectsLazy = require_utils.mergeAdjacentObjectsLazy;
|
|
28
28
|
exports.objectKey = require_utils.objectKey;
|
|
29
|
-
exports.resolveGroupType =
|
|
29
|
+
exports.resolveGroupType = require_refs.resolveGroupType;
|
|
30
30
|
exports.resolveParamType = require_utils.resolveParamType;
|
|
31
|
-
exports.resolveRefName =
|
|
31
|
+
exports.resolveRefName = require_refs.resolveRefName;
|
|
32
32
|
exports.stringify = require_utils.stringify;
|
|
33
33
|
exports.stringifyObject = require_utils.stringifyObject;
|
|
34
|
-
exports.syncSchemaRef =
|
|
34
|
+
exports.syncSchemaRef = require_refs.syncSchemaRef;
|
|
35
35
|
exports.toRegExpString = require_utils.toRegExpString;
|
|
36
36
|
exports.trimQuotes = require_utils.trimQuotes;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-CNktS9qV.js";
|
|
2
|
-
import { Et as PropertyNode, St as UnionSchemaNode, _t as SchemaNode, f as OperationNode, ft as ObjectSchemaNode, ot as ArraySchemaNode, ut as IntersectionSchemaNode
|
|
3
|
-
import { a as buildTypeLiteral, c as resolveParamType, i as buildGroupParam, n as OperationParamsResolver, o as caseParams, r as ParamGroupType, s as createOperationParams, t as BuildGroupArgs } from "./operationParams-
|
|
4
|
-
import { t as extractStringsFromNodes } from "./extractStringsFromNodes-p4mX1TQD.js";
|
|
2
|
+
import { C as ParameterNode, Et as PropertyNode, Pt as CodeNode, St as UnionSchemaNode, _t as SchemaNode, f as OperationNode, ft as ObjectSchemaNode, ot as ArraySchemaNode, ut as IntersectionSchemaNode } from "./index-B9cc8MBS.js";
|
|
3
|
+
import { a as buildTypeLiteral, c as resolveParamType, i as buildGroupParam, n as OperationParamsResolver, o as caseParams, r as ParamGroupType, s as createOperationParams, t as BuildGroupArgs } from "./operationParams-k5CKwSWZ.js";
|
|
5
4
|
|
|
6
5
|
//#region ../../internals/utils/src/reserved.d.ts
|
|
7
6
|
/**
|
|
@@ -18,8 +17,8 @@ declare function isValidVarName(name: string): boolean;
|
|
|
18
17
|
//#endregion
|
|
19
18
|
//#region src/utils/codegen.d.ts
|
|
20
19
|
/**
|
|
21
|
-
* Builds a JSDoc comment block from an array of lines
|
|
22
|
-
* comments
|
|
20
|
+
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
21
|
+
* comments.
|
|
23
22
|
*
|
|
24
23
|
* @example
|
|
25
24
|
* ```ts
|
|
@@ -57,9 +56,8 @@ declare function buildJSDoc(comments: Array<string>, options?: {
|
|
|
57
56
|
declare function objectKey(name: string): string;
|
|
58
57
|
/**
|
|
59
58
|
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
60
|
-
* level and closing the brace at column zero.
|
|
61
|
-
*
|
|
62
|
-
* formatter's multi-line style.
|
|
59
|
+
* level and closing the brace at column zero. Entries that are themselves multi-line objects indent
|
|
60
|
+
* cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
|
|
63
61
|
*
|
|
64
62
|
* @example
|
|
65
63
|
* ```ts
|
|
@@ -71,8 +69,8 @@ declare function buildObject(entries: Array<string>): string;
|
|
|
71
69
|
/**
|
|
72
70
|
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
73
71
|
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
74
|
-
* one level with a trailing comma and the closing bracket at column zero.
|
|
75
|
-
* `z.
|
|
72
|
+
* one level with a trailing comma and the closing bracket at column zero. Used for member lists such
|
|
73
|
+
* as `z.union([…])` and `z.array([…])`.
|
|
76
74
|
*
|
|
77
75
|
* @example
|
|
78
76
|
* ```ts
|
|
@@ -82,37 +80,42 @@ declare function buildObject(entries: Array<string>): string;
|
|
|
82
80
|
*/
|
|
83
81
|
declare function buildList(items: Array<string>, brackets?: [open: string, close: string]): string;
|
|
84
82
|
//#endregion
|
|
83
|
+
//#region src/utils/extractStringsFromNodes.d.ts
|
|
84
|
+
/**
|
|
85
|
+
* Extracts all string content from a `CodeNode` tree recursively.
|
|
86
|
+
*
|
|
87
|
+
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
88
|
+
* and nested node content. Used to build the full source string for import filtering.
|
|
89
|
+
*/
|
|
90
|
+
declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
91
|
+
//#endregion
|
|
85
92
|
//#region src/utils/refs.d.ts
|
|
86
93
|
/**
|
|
87
94
|
* Returns the last path segment of a reference string.
|
|
88
95
|
*
|
|
89
96
|
* @example
|
|
90
|
-
*
|
|
91
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
92
|
-
* ```
|
|
97
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
93
98
|
*/
|
|
94
99
|
declare function extractRefName(ref: string): string;
|
|
95
100
|
/**
|
|
96
|
-
* Resolves the schema name of a ref node
|
|
101
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
102
|
+
* back to `name` then nested `schema.name`.
|
|
97
103
|
*
|
|
98
104
|
* Returns `null` for non-ref nodes or when no name resolves.
|
|
99
105
|
*
|
|
100
106
|
* @example
|
|
101
|
-
*
|
|
102
|
-
* resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
|
|
103
|
-
* // => 'Pet'
|
|
104
|
-
* ```
|
|
107
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
105
108
|
*/
|
|
106
109
|
declare function resolveRefName(node: SchemaNode | undefined): string | null;
|
|
107
110
|
/**
|
|
108
111
|
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
109
112
|
* Returns `null` when there is no parent to nest under.
|
|
110
113
|
*
|
|
111
|
-
* @example
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
114
|
+
* @example Nested under a parent
|
|
115
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
116
|
+
*
|
|
117
|
+
* @example No parent
|
|
118
|
+
* `childName(undefined, 'params') // null`
|
|
116
119
|
*/
|
|
117
120
|
declare function childName(parentName: string | null | undefined, propName: string): string | null;
|
|
118
121
|
/**
|
|
@@ -120,16 +123,16 @@ declare function childName(parentName: string | null | undefined, propName: stri
|
|
|
120
123
|
* empty parts.
|
|
121
124
|
*
|
|
122
125
|
* @example
|
|
123
|
-
*
|
|
124
|
-
* enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
|
|
125
|
-
* ```
|
|
126
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
126
127
|
*/
|
|
127
128
|
declare function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string;
|
|
128
129
|
/**
|
|
129
130
|
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
130
131
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
132
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
133
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
134
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
135
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
133
136
|
*
|
|
134
137
|
* @example
|
|
135
138
|
* ```ts
|
|
@@ -166,8 +169,8 @@ declare function resolveGroupType({
|
|
|
166
169
|
//#region src/utils/schemaMerge.d.ts
|
|
167
170
|
/**
|
|
168
171
|
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
169
|
-
* run and pass through.
|
|
170
|
-
*
|
|
172
|
+
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
173
|
+
* combine by where they place them in the sequence.
|
|
171
174
|
*
|
|
172
175
|
* @example
|
|
173
176
|
* ```ts
|
|
@@ -250,6 +253,26 @@ declare function stringifyObject(value: Record<string, unknown>): string;
|
|
|
250
253
|
declare function getNestedAccessor(param: string | Array<string>, accessor: string): string | null;
|
|
251
254
|
//#endregion
|
|
252
255
|
//#region src/utils/schemaGraph.d.ts
|
|
256
|
+
/**
|
|
257
|
+
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
258
|
+
*
|
|
259
|
+
* An operation uses a schema when its parameters, request body, or responses reference it, directly
|
|
260
|
+
* or through other named schemas. Once a name is added to the result it is not revisited, so
|
|
261
|
+
* reference cycles terminate.
|
|
262
|
+
*
|
|
263
|
+
* Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
|
|
264
|
+
*
|
|
265
|
+
* @example Only generate schemas referenced by included operations
|
|
266
|
+
* ```ts
|
|
267
|
+
* const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
|
|
268
|
+
* const allowed = collectUsedSchemaNames(includedOps, schemas)
|
|
269
|
+
*
|
|
270
|
+
* for (const schema of schemas) {
|
|
271
|
+
* if (schema.name && !allowed.has(schema.name)) continue
|
|
272
|
+
* // generate schema
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
253
276
|
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
254
277
|
/**
|
|
255
278
|
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { a as resolveGroupType, i as isStringType, n as enumPropName, o as resolveRefName, r as extractRefName, s as syncSchemaRef, t as childName } from "./refs-BjNDuCBD.js";
|
|
2
|
+
import { I as extractStringsFromNodes } from "./schema-Cbnxmz4b.js";
|
|
3
|
+
import { C as objectKey, S as buildObject, _ as toRegExpString, a as resolveParamType, b as buildJSDoc, c as mapSchemaMembers, d as containsCircularRef, f as findCircularSchemas, g as stringifyObject, h as stringify, i as createOperationParams, l as mapSchemaProperties, m as jsStringEscape, n as buildTypeLiteral, o as lazyGetter, p as getNestedAccessor, r as caseParams, s as mapSchemaItems, t as buildGroupParam, u as collectUsedSchemaNames, v as trimQuotes, w as isValidVarName, x as buildList, y as mergeAdjacentObjectsLazy } from "./utils-DaXkewb1.js";
|
|
4
4
|
export { buildGroupParam, buildJSDoc, buildList, buildObject, buildTypeLiteral, caseParams, childName, collectUsedSchemaNames, containsCircularRef, createOperationParams, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, getNestedAccessor, isStringType, isValidVarName, jsStringEscape, lazyGetter, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, objectKey, resolveGroupType, resolveParamType, resolveRefName, stringify, stringifyObject, syncSchemaRef, toRegExpString, trimQuotes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/ast",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.63",
|
|
4
4
|
"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
5
|
"keywords": [
|
|
6
6
|
"ast",
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HttpMethod } from './nodes/operation.ts'
|
|
2
1
|
import type { SchemaType } from './nodes/schema.ts'
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -18,7 +17,6 @@ export const visitorDepths = {
|
|
|
18
17
|
* Schema type discriminators used by all AST schema nodes.
|
|
19
18
|
*
|
|
20
19
|
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
21
|
-
* Call `isScalarPrimitive()` to check for the scalar types.
|
|
22
20
|
*/
|
|
23
21
|
export const schemaTypes = {
|
|
24
22
|
/**
|
|
@@ -127,46 +125,15 @@ export const schemaTypes = {
|
|
|
127
125
|
never: 'never',
|
|
128
126
|
} as const satisfies Record<SchemaType, SchemaType>
|
|
129
127
|
|
|
130
|
-
export type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
134
|
-
*/
|
|
135
|
-
const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
|
|
136
|
-
|
|
137
128
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
export function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
142
|
-
return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* HTTP method identifiers used by operation nodes.
|
|
147
|
-
*/
|
|
148
|
-
export const httpMethods = {
|
|
149
|
-
get: 'GET',
|
|
150
|
-
post: 'POST',
|
|
151
|
-
put: 'PUT',
|
|
152
|
-
patch: 'PATCH',
|
|
153
|
-
delete: 'DELETE',
|
|
154
|
-
head: 'HEAD',
|
|
155
|
-
options: 'OPTIONS',
|
|
156
|
-
trace: 'TRACE',
|
|
157
|
-
} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Default concurrency limit for the `walk()` traversal utility.
|
|
161
|
-
*
|
|
162
|
-
* Set to 30 to balance I/O-bound resolver parallelism against event-loop and memory pressure
|
|
163
|
-
* during large spec traversals. Override it for different hardware constraints.
|
|
129
|
+
* Default sibling concurrency for `walk()`. Higher values overlap I/O-bound visitor work,
|
|
130
|
+
* lower values reduce memory pressure. Pass `concurrency` to `walk()` to override it.
|
|
164
131
|
*
|
|
165
132
|
* @example
|
|
166
133
|
* ```ts
|
|
167
134
|
* import { walk, WALK_CONCURRENCY } from '@kubb/ast'
|
|
168
135
|
*
|
|
169
|
-
* walk(root, { concurrency: WALK_CONCURRENCY,
|
|
136
|
+
* walk(root, { concurrency: WALK_CONCURRENCY, operation: () => {} })
|
|
170
137
|
* ```
|
|
171
138
|
*/
|
|
172
139
|
export const WALK_CONCURRENCY = 30
|
package/src/defineMacro.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { VisitorDepth } from './constants.ts'
|
|
2
|
+
import type { VisitorKey } from './defineNode.ts'
|
|
3
|
+
import { visitorKeys } from './defineNode.ts'
|
|
2
4
|
import type { Node } from './nodes/index.ts'
|
|
3
5
|
import type { Visitor, VisitorContext } from './visitor.ts'
|
|
4
6
|
import { transform } from './visitor.ts'
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,
|
|
10
|
+
* and `undefined` keeps declaration order.
|
|
9
11
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type MacroKey = (typeof macroKeys)[number]
|
|
12
|
+
export type Enforce = 'pre' | 'post'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
16
16
|
* list keeps its authored order.
|
|
17
17
|
*/
|
|
18
|
-
function enforceWeight(enforce?:
|
|
18
|
+
function enforceWeight(enforce?: Enforce): number {
|
|
19
19
|
if (enforce === 'pre') return 0
|
|
20
20
|
if (enforce === 'post') return 2
|
|
21
21
|
return 1
|
|
@@ -29,14 +29,14 @@ function enforceWeight(enforce?: 'pre' | 'post'): number {
|
|
|
29
29
|
*/
|
|
30
30
|
export type Macro = Visitor & {
|
|
31
31
|
/**
|
|
32
|
-
* Macro identifier
|
|
32
|
+
* Macro identifier used to tell macros apart, for example `'simplify-union'`.
|
|
33
33
|
*/
|
|
34
34
|
name: string
|
|
35
35
|
/**
|
|
36
36
|
* Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.
|
|
37
37
|
* Ordering within a bucket follows list order.
|
|
38
38
|
*/
|
|
39
|
-
enforce?:
|
|
39
|
+
enforce?: Enforce
|
|
40
40
|
/**
|
|
41
41
|
* Gate checked against the current node before any callback runs. When it returns `false`
|
|
42
42
|
* the macro is skipped for that node.
|
|
@@ -64,12 +64,19 @@ export function defineMacro(macro: Macro): Macro {
|
|
|
64
64
|
|
|
65
65
|
type MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined
|
|
66
66
|
|
|
67
|
+
type ChainProps = {
|
|
68
|
+
macros: ReadonlyArray<Macro>
|
|
69
|
+
key: VisitorKey
|
|
70
|
+
node: Node
|
|
71
|
+
context: VisitorContext
|
|
72
|
+
}
|
|
73
|
+
|
|
67
74
|
/**
|
|
68
75
|
* Runs every macro's callback for one node kind in order, chaining the result so each macro sees
|
|
69
76
|
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
70
77
|
* original reference (structural sharing).
|
|
71
78
|
*/
|
|
72
|
-
function chain(macros
|
|
79
|
+
function chain({ macros, key, node, context }: ChainProps): Node | undefined {
|
|
73
80
|
let current = node
|
|
74
81
|
|
|
75
82
|
for (const macro of macros) {
|
|
@@ -100,11 +107,11 @@ export function composeMacros(macros: ReadonlyArray<Macro>): Visitor {
|
|
|
100
107
|
const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))
|
|
101
108
|
|
|
102
109
|
const visitor: Visitor = {}
|
|
103
|
-
for (const key of
|
|
110
|
+
for (const key of visitorKeys) {
|
|
104
111
|
if (!ordered.some((macro) => typeof macro[key] === 'function')) continue
|
|
105
112
|
|
|
106
|
-
const callback = (node: Node, context: VisitorContext) => chain(ordered, key, node, context)
|
|
107
|
-
;(visitor as Record<
|
|
113
|
+
const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })
|
|
114
|
+
;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
return visitor
|
|
@@ -128,5 +135,5 @@ export function composeMacros(macros: ReadonlyArray<Macro>): Visitor {
|
|
|
128
135
|
export function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {
|
|
129
136
|
if (macros.length === 0) return root
|
|
130
137
|
|
|
131
|
-
return transform(root, { ...composeMacros(macros),
|
|
138
|
+
return transform(root, { ...composeMacros(macros), ...options }) as TNode
|
|
132
139
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { BaseNode, NodeKind } from './nodes/base.ts'
|
|
2
|
-
import type { SchemaNode } from './nodes/index.ts'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
* Visitor callback names, one per traversable node kind
|
|
6
|
-
* keys of `Visitor` in `visitor.ts`.
|
|
4
|
+
* Visitor callback names, one per traversable node kind, in traversal order.
|
|
5
|
+
* Kept in sync with the keys of `Visitor` in `visitor.ts`.
|
|
7
6
|
*/
|
|
8
|
-
|
|
7
|
+
export const visitorKeys = ['input', 'output', 'operation', 'schema', 'property', 'parameter', 'response'] as const
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One of the {@link visitorKeys} callback names.
|
|
11
|
+
*/
|
|
12
|
+
export type VisitorKey = (typeof visitorKeys)[number]
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* Distributive `Omit` that preserves each member of a union.
|
|
@@ -24,26 +28,7 @@ export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omi
|
|
|
24
28
|
* Builds a type guard that matches nodes of the given `kind`.
|
|
25
29
|
*/
|
|
26
30
|
function isKind<T extends BaseNode>(kind: NodeKind) {
|
|
27
|
-
return (node: unknown): node is T => (node as BaseNode)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Updates a schema's `optional` and `nullish` flags from a parent's `required`
|
|
32
|
-
* value and the schema's own `nullable`. Mirrors how OpenAPI parameters and
|
|
33
|
-
* object properties combine "required" and "nullable" into a single AST.
|
|
34
|
-
*
|
|
35
|
-
* - Non-required + non-nullable → `optional: true`.
|
|
36
|
-
* - Non-required + nullable → `nullish: true`.
|
|
37
|
-
* - Required → both flags cleared.
|
|
38
|
-
*/
|
|
39
|
-
export function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode {
|
|
40
|
-
const nullable = schema.nullable ?? false
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
...schema,
|
|
44
|
-
optional: !required && !nullable ? true : undefined,
|
|
45
|
-
nullish: !required && nullable ? true : undefined,
|
|
46
|
-
}
|
|
31
|
+
return (node: unknown): node is T => (node as BaseNode | undefined)?.kind === kind
|
|
47
32
|
}
|
|
48
33
|
|
|
49
34
|
/**
|
|
@@ -72,11 +57,6 @@ export type NodeDef<TNode extends BaseNode = BaseNode, TInput = never> = {
|
|
|
72
57
|
* Visitor callback name. Feeds `VISITOR_KEY_BY_KIND`.
|
|
73
58
|
*/
|
|
74
59
|
visitorKey?: VisitorKey
|
|
75
|
-
/**
|
|
76
|
-
* When `true`, `create` is rerun after children are rebuilt so computed fields
|
|
77
|
-
* stay in sync. Feeds `nodeRebuilders`.
|
|
78
|
-
*/
|
|
79
|
-
rebuild?: boolean
|
|
80
60
|
}
|
|
81
61
|
|
|
82
62
|
type DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {
|
|
@@ -85,7 +65,6 @@ type DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {
|
|
|
85
65
|
build?: (input: TInput) => TBuilt
|
|
86
66
|
children?: ReadonlyArray<string>
|
|
87
67
|
visitorKey?: VisitorKey
|
|
88
|
-
rebuild?: boolean
|
|
89
68
|
}
|
|
90
69
|
|
|
91
70
|
/**
|
|
@@ -93,36 +72,31 @@ type DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {
|
|
|
93
72
|
* metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
|
|
94
73
|
* `kind`, so node construction lives in one place without scattered `as` casts.
|
|
95
74
|
*
|
|
96
|
-
* Set `rebuild: true` when the `build` hook derives fields from children. After a
|
|
97
|
-
* transform rewrites those children, the registry reruns `create` so the derived
|
|
98
|
-
* fields stay correct.
|
|
99
|
-
*
|
|
100
75
|
* @example Simple node
|
|
101
76
|
* ```ts
|
|
102
77
|
* const importDef = defineNode<ImportNode>({ kind: 'Import' })
|
|
103
78
|
* const createImport = importDef.create
|
|
104
79
|
* ```
|
|
105
80
|
*
|
|
106
|
-
* @example Node with a build hook
|
|
81
|
+
* @example Node with a build hook
|
|
107
82
|
* ```ts
|
|
108
83
|
* const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
|
|
109
84
|
* kind: 'Property',
|
|
110
85
|
* build: (props) => ({ ...props, required: props.required ?? false }),
|
|
111
86
|
* children: ['schema'],
|
|
112
87
|
* visitorKey: 'property',
|
|
113
|
-
* rebuild: true,
|
|
114
88
|
* })
|
|
115
89
|
* ```
|
|
116
90
|
*/
|
|
117
91
|
export function defineNode<TNode extends BaseNode, TInput = Omit<TNode, 'kind'>, TBuilt extends object = Omit<TNode, 'kind'>>(
|
|
118
92
|
config: DefineNodeConfig<TNode, TInput, TBuilt>,
|
|
119
93
|
): NodeDef<TNode, TInput> {
|
|
120
|
-
const { kind, defaults, build, children, visitorKey
|
|
94
|
+
const { kind, defaults, build, children, visitorKey } = config
|
|
121
95
|
|
|
122
96
|
function create(input: TInput): TNode {
|
|
123
97
|
const base = build ? build(input) : input
|
|
124
98
|
return { ...defaults, ...(base as object), kind } as TNode
|
|
125
99
|
}
|
|
126
100
|
|
|
127
|
-
return { kind, create, is: isKind<TNode>(kind), children, visitorKey
|
|
101
|
+
return { kind, create, is: isKind<TNode>(kind), children, visitorKey }
|
|
128
102
|
}
|
|
@@ -191,11 +191,13 @@ export function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOp
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
|
-
* Generic printer
|
|
194
|
+
* Generic printer factory behind `definePrinter`. Pass a `getKey` function that maps a node to its
|
|
195
|
+
* handler key, and it returns a `definePrinter`-style helper for that node and key type. `definePrinter`
|
|
196
|
+
* itself is this factory keyed by `node.type`.
|
|
195
197
|
*
|
|
196
|
-
* @example
|
|
198
|
+
* @example Key a printer by `node.kind` instead of `node.type`
|
|
197
199
|
* ```ts
|
|
198
|
-
*
|
|
200
|
+
* const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
|
|
199
201
|
* (node) => node.kind,
|
|
200
202
|
* )
|
|
201
203
|
* ```
|