@kubb/core 5.0.0-beta.29 → 5.0.0-beta.30
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/{KubbDriver-x86YM1Ia.js → KubbDriver-CFx2DdhF.js} +20 -42
- package/dist/KubbDriver-CFx2DdhF.js.map +1 -0
- package/dist/{KubbDriver-BSu9kdM9.cjs → KubbDriver-vyD7F0Ip.cjs} +20 -42
- package/dist/KubbDriver-vyD7F0Ip.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.js +1 -1
- package/package.json +4 -4
- package/src/KubbDriver.ts +37 -34
- package/src/defineResolver.ts +2 -2
- package/dist/KubbDriver-BSu9kdM9.cjs.map +0 -1
- package/dist/KubbDriver-x86YM1Ia.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KubbDriver-vyD7F0Ip.cjs","names":["#emitter","NodeEventEmitter","#emitAll","#options","#transformParam","#eachParam","path","#cache","#onUpsert","#store","#dedupe","#sorted","#fileProcessor","#eventGeneratorPlugins","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#registerPlugin","#registerMiddleware","#registerAdapter","#studio","#middlewareListeners","#trackHookListener","#filesPayload","#emitPluginEnd","#runGenerators","#getDefaultResolver","openInStudioFn"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/time.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/constants.ts","../src/definePlugin.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/FileProcessor.ts","../src/KubbDriver.ts"],"sourcesContent":["/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n return this.#emitAll(eventName, listeners, eventArgs)\n }\n\n async #emitAll<TEventName extends keyof TEvents & string>(\n eventName: TEventName,\n listeners: Array<AsyncListener<TEvents[TEventName]>>,\n eventArgs: TEvents[TEventName],\n ): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Returns the number of listeners registered for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', handler)\n * emitter.listenerCount('build') // 1\n * ```\n */\n listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number {\n return this.#emitter.listenerCount(eventName)\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.\n * Rounds to 2 decimal places for sub-millisecond precision without noise.\n *\n * @example\n * ```ts\n * const start = process.hrtime()\n * doWork()\n * getElapsedMs(start) // 42.35\n * ```\n */\nexport function getElapsedMs(hrStart: [number, number]): number {\n const [seconds, nanoseconds] = process.hrtime(hrStart)\n const ms = seconds * 1000 + nanoseconds / 1e6\n return Math.round(ms * 100) / 100\n}\n\n/**\n * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).\n *\n * @example\n * ```ts\n * formatMs(250) // '250ms'\n * formatMs(1500) // '1.50s'\n * formatMs(90000) // '1m 30.0s'\n * ```\n */\nexport function formatMs(ms: number): string {\n if (ms >= 60000) {\n const mins = Math.floor(ms / 60000)\n const secs = ((ms % 60000) / 1000).toFixed(1)\n return `${mins}m ${secs}s`\n }\n\n if (ms >= 1000) {\n return `${(ms / 1000).toFixed(2)}s`\n }\n return `${Math.round(ms)}ms`\n}\n\n/**\n * Formats the elapsed time since `hrStart` as a human-readable string.\n *\n * @example\n * ```ts\n * const start = process.hrtime()\n * doWork()\n * formatHrtime(start) // '1.50s'\n * ```\n */\nexport function formatHrtime(hrStart: [number, number]): string {\n return formatMs(getElapsedMs(hrStart))\n}\n","function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\n/**\n * Returns a wrapper that caches the result of the first invocation and replays\n * it for every subsequent call, ignoring later arguments.\n *\n * Works for sync and async factories — for async, the cached value is the\n * promise itself, so concurrent callers share one in-flight execution and\n * cannot race each other.\n *\n * @example\n * ```ts\n * const loadDocument = once(async (path: string) => parse(await readFile(path)))\n * const a = loadDocument('./a.yaml') // parses\n * const b = loadDocument('./b.yaml') // returns the cached promise from the first call\n * ```\n */\nexport function once<TArgs extends unknown[], TReturn>(factory: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn {\n let cache: { value: TReturn } | undefined\n return (...args: TArgs): TReturn => {\n if (!cache) cache = { value: factory(...args) }\n return cache.value\n }\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: readonly T[]): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","import { camelCase } from './casing.ts'\nimport { isValidVarName } from './reserved.ts'\n\nexport type URLObject = {\n /**\n * The resolved URL string (Express-style or template literal, depending on context).\n */\n url: string\n /**\n * Extracted path parameters as a key-value map, or `undefined` when the path has none.\n */\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n /**\n * Controls whether the `url` is rendered as an Express path or a template literal.\n * @default 'path'\n */\n type?: 'path' | 'template'\n /**\n * Optional transform applied to each extracted parameter name.\n */\n replacer?: (pathParam: string) => string\n /**\n * When `true`, the result is serialized to a string expression instead of a plain object.\n */\n stringify?: boolean\n}\n\n/**\n * Supported identifier casing strategies for path parameters.\n */\ntype PathCasing = 'camelcase'\n\ntype Options = {\n /**\n * Casing strategy applied to path parameter names.\n * @default undefined (original identifier preserved)\n */\n casing?: PathCasing\n}\n\n/**\n * Parses and transforms an OpenAPI/Swagger path string into various URL formats.\n *\n * @example\n * const p = new URLPath('/pet/{petId}')\n * p.URL // '/pet/:petId'\n * p.template // '`/pet/${petId}`'\n */\nexport class URLPath {\n /**\n * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.\n */\n path: string\n\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').URL // '/pet/:petId'\n * ```\n */\n get URL(): string {\n return this.toURLPath()\n }\n\n /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).\n *\n * @example\n * ```ts\n * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true\n * new URLPath('/pet/{petId}').isURL // false\n * ```\n */\n get isURL(): boolean {\n try {\n return !!new URL(this.path).href\n } catch {\n return false\n }\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n *\n * @example\n * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'\n * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'\n */\n get template(): string {\n return this.toTemplateString()\n }\n\n /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').object\n * // { url: '/pet/:petId', params: { petId: 'petId' } }\n * ```\n */\n get object(): URLObject | string {\n return this.toObject()\n }\n\n /** Returns a map of path parameter names, or `undefined` when the path has no parameters.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').params // { petId: 'petId' }\n * new URLPath('/pet').params // undefined\n * ```\n */\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n #transformParam(raw: string): string {\n const param = isValidVarName(raw) ? raw : camelCase(raw)\n return this.#options.casing === 'camelcase' ? camelCase(param) : param\n }\n\n /**\n * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.\n */\n #eachParam(fn: (raw: string, param: string) => void): void {\n for (const match of this.path.matchAll(/\\{([^}]+)\\}/g)) {\n const raw = match[1]!\n fn(raw, this.#transformParam(raw))\n }\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n * An optional `replacer` can transform each extracted parameter name before interpolation.\n *\n * @example\n * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'\n */\n toTemplateString({\n prefix,\n replacer,\n }: {\n prefix?: string | null\n replacer?: (pathParam: string) => string\n } = {}): string {\n const parts = this.path.split(/\\{([^}]+)\\}/)\n const result = parts\n .map((part, i) => {\n if (i % 2 === 0) return part\n const param = this.#transformParam(part)\n return `\\${${replacer ? replacer(param) : param}}`\n })\n .join('')\n\n return `\\`${prefix ?? ''}${result}\\``\n }\n\n /**\n * Extracts all `{param}` segments from the path and returns them as a key-value map.\n * An optional `replacer` transforms each parameter name in both key and value positions.\n * Returns `undefined` when no path parameters are found.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}/tag/{tagId}').getParams()\n * // { petId: 'petId', tagId: 'tagId' }\n * ```\n */\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const params: Record<string, string> = {}\n\n this.#eachParam((_raw, param) => {\n const key = replacer ? replacer(param) : param\n params[key] = key\n })\n\n return Object.keys(params).length > 0 ? params : undefined\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'\n * ```\n */\n toURLPath(): string {\n return this.path.replace(/\\{([^}]+)\\}/g, ':$1')\n }\n}\n","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://kubb.studio' as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Number of file writes to batch in parallel during `flushPendingFiles`.\n */\nexport const STREAM_FLUSH_EVERY = 50\n\n/**\n * Number of schema/operation nodes to dispatch concurrently during generation.\n */\nexport const SCHEMA_PARALLEL = 8\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import { extname } from 'node:path'\nimport type { FileNode, HttpMethod, UserFileNode, Visitor } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { BannerMeta, Resolver } from './defineResolver.ts'\nimport type { Config, KubbHooks } from './types.ts'\n\n/**\n * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.\n * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`\n * without requiring changes to core.\n *\n * @internal\n */\ntype ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}\n\n/**\n * Output configuration shared by every plugin. Each plugin extends this with\n * its own keys via the `Kubb.PluginOptionsRegistry.output` interface merge.\n */\nexport type Output<_TOptions = unknown> = {\n /**\n * Folder (or single file) where the plugin writes its generated code.\n * Resolved against the global `output.path` set on `defineConfig`.\n */\n path: string\n /**\n * Text prepended to every generated file. Useful for license headers,\n * lint disables, or `@ts-nocheck` directives.\n *\n * A string is applied to every file (including barrel and aggregation re-export files).\n * Pass a function to compute the banner from the file's `BannerMeta` — document metadata\n * plus per-file context (`isBarrel`, `isAggregation`, `filePath`, `baseName`) — so you can\n * skip the banner on specific files.\n *\n * @example Add a directive to source files but not re-export files\n * `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : \"'use server'\"`\n */\n banner?: string | ((meta: BannerMeta) => string)\n /**\n * Text appended at the end of every generated file. Mirror of `banner`.\n * Pass a function to compute the footer from the file's `BannerMeta`.\n */\n footer?: string | ((meta: BannerMeta) => string)\n /**\n * Allows the plugin to overwrite hand-written files at the same path.\n * Defaults to `false` to protect manual edits.\n *\n * @default false\n */\n override?: boolean\n} & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>\n\n/**\n * Groups generated files into subdirectories based on an OpenAPI tag or path\n * segment.\n */\nexport type Group = {\n /**\n * Property used to assign each operation to a group.\n * - `'tag'` — uses the first tag (`operation.getTags().at(0)?.name`).\n * - `'path'` — uses the first segment of the operation's URL.\n */\n type: 'tag' | 'path'\n /**\n * Returns the subdirectory name from the group key. Defaults to\n * `${camelCase(group)}Controller` for tags, or the first path segment.\n */\n name?: (context: { group: string }) => string\n}\n\ntype ByTag = {\n /**\n * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.\n */\n type: 'tag'\n /**\n * Tag name to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByOperationId = {\n /**\n * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.\n */\n type: 'operationId'\n /**\n * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByPath = {\n /**\n * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.\n */\n type: 'path'\n /**\n * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.\n */\n pattern: string | RegExp\n}\n\ntype ByMethod = {\n /**\n * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.\n */\n type: 'method'\n /**\n * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).\n */\n pattern: HttpMethod | RegExp\n}\n// TODO implement as alternative for ByMethod\n// type ByMethods = {\n// type: 'methods'\n// pattern: Array<HttpMethod>\n// }\n\ntype BySchemaName = {\n /**\n * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.\n */\n type: 'schemaName'\n /**\n * Schema name to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByContentType = {\n /**\n * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.\n */\n type: 'contentType'\n /**\n * Content type to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\n/**\n * Filter that skips matching operations or schemas during generation. Use it\n * to drop deprecated endpoints, internal-only schemas, or anything you do\n * not want code generated for.\n *\n * @example\n * ```ts\n * exclude: [\n * { type: 'tag', pattern: 'internal' },\n * { type: 'path', pattern: /^\\/admin/ },\n * { type: 'operationId', pattern: /^deprecated_/ },\n * ]\n * ```\n */\nexport type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName\n\n/**\n * Filter that restricts generation to operations or schemas matching at least\n * one entry. Useful for partial builds (one tag, one API version).\n *\n * @example\n * ```ts\n * include: [\n * { type: 'tag', pattern: 'public' },\n * { type: 'path', pattern: /^\\/api\\/v1/ },\n * ]\n * ```\n */\nexport type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName\n\n/**\n * Filter paired with a partial options object. When the filter matches, the\n * options are merged on top of the plugin defaults for that operation only.\n * Useful for \"this one tag goes to a different folder\" rules.\n *\n * Entries are evaluated top to bottom; the first matching entry wins.\n *\n * @example\n * ```ts\n * override: [\n * {\n * type: 'tag',\n * pattern: 'admin',\n * options: { output: { path: './src/gen/admin' } },\n * },\n * {\n * type: 'operationId',\n * pattern: 'listPets',\n * options: { enumType: 'literal' },\n * },\n * ]\n * ```\n */\nexport type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {\n //TODO should be options: Omit<Partial<TOptions>, 'override'>\n options: Partial<TOptions>\n}\n\nexport type PluginFactoryOptions<\n /**\n * Unique plugin name.\n */\n TName extends string = string,\n /**\n * User-facing plugin options.\n */\n TOptions extends object = object,\n /**\n * Plugin options after defaults are applied.\n */\n TResolvedOptions extends object = TOptions,\n /**\n * Resolver that encapsulates naming and path-resolution helpers.\n * Define with `defineResolver` and export alongside the plugin.\n */\n TResolver extends Resolver = Resolver,\n> = {\n name: TName\n options: TOptions\n resolvedOptions: TResolvedOptions\n resolver: TResolver\n}\n\n/**\n * Context for hook-style plugin `kubb:plugin:setup` handler.\n * Provides methods to register generators, configure resolvers, transformers, and renderers.\n */\nexport type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {\n /**\n * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)\n * just like generators declared statically on `createPlugin`.\n */\n addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void\n /**\n * Set or override the resolver for this plugin.\n * The resolver controls file naming and path resolution.\n */\n setResolver(resolver: Partial<TFactory['resolver']>): void\n /**\n * Set the AST transformer to pre-process nodes before they reach generators.\n */\n setTransformer(visitor: Visitor): void\n /**\n * Set the renderer factory to process JSX elements from generators.\n */\n setRenderer(renderer: RendererFactory): void\n /**\n * Set resolved options merged into the normalized plugin's `options`.\n * Call this in `kubb:plugin:setup` to provide options generators need.\n */\n setOptions(options: TFactory['resolvedOptions']): void\n /**\n * Inject a raw file into the build output, bypassing the generation pipeline.\n */\n injectFile(userFileNode: UserFileNode): void\n /**\n * Merge a partial config update into the current build configuration.\n */\n updateConfig(config: Partial<Config>): void\n /**\n * The resolved build configuration at setup time.\n */\n config: Config\n /**\n * The plugin's user-provided options.\n */\n options: TFactory['options']\n}\n\n/**\n * A plugin object produced by `definePlugin`.\n * Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property\n * (matching Astro's integration naming convention).\n *\n * @template TFactory - The plugin's `PluginFactoryOptions` type.\n */\nexport type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {\n /**\n * Unique name for the plugin, following the same naming convention as `createPlugin`.\n */\n name: string\n /**\n * Plugins that must be registered before this plugin executes.\n * An error is thrown at startup when any listed dependency is missing.\n */\n dependencies?: Array<string>\n /**\n * Controls the execution order of this plugin relative to others.\n *\n * - `'pre'` — runs before all normal plugins.\n * - `'post'` — runs after all normal plugins.\n * - `undefined` (default) — runs in declaration order among normal plugins.\n *\n * Dependency constraints always take precedence over `enforce`.\n */\n enforce?: 'pre' | 'post'\n /**\n * The options passed by the user when calling the plugin factory.\n */\n options?: TFactory['options']\n /**\n * Lifecycle event handlers for this plugin.\n * Any event from the global `KubbHooks` map can be subscribed to here.\n */\n hooks: {\n [K in keyof KubbHooks as K extends 'kubb:plugin:setup' ? never : K]?: (...args: KubbHooks[K]) => void | Promise<void>\n } & {\n 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>\n }\n}\n\n/**\n * Normalized plugin after setup, with runtime fields populated.\n * For internal use only — plugins use the public `Plugin` type externally.\n *\n * @internal\n */\nexport type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {\n options: TOptions['resolvedOptions'] & {\n output: Output\n include?: Array<Include>\n exclude: Array<Exclude>\n override: Array<Override<TOptions['resolvedOptions']>>\n }\n resolver: TOptions['resolver']\n transformer?: Visitor\n renderer?: RendererFactory\n generators?: Array<Generator>\n apply?: (config: Config) => boolean\n version?: string\n}\n\nexport type KubbPluginStartContext = {\n plugin: NormalizedPlugin\n}\n\nexport type KubbPluginEndContext = {\n plugin: NormalizedPlugin\n duration: number\n success: boolean\n error?: Error\n config: Config\n /**\n * Returns all files currently in the file manager (lazy snapshot).\n * Includes files added by plugins that have already run.\n */\n readonly files: ReadonlyArray<FileNode>\n /**\n * Upsert one or more files into the file manager.\n */\n upsertFile: (...files: Array<FileNode>) => void\n}\n\n/**\n * Wraps a plugin factory and returns a function that accepts user options and\n * yields a fully typed `Plugin`. Lifecycle handlers go inside a single\n * `hooks` object (inspired by Astro integrations).\n *\n * Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside\n * `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`\n * convention (`plugin-react-query`, `plugin-zod`, ...).\n *\n * @example\n * ```ts\n * import { definePlugin } from '@kubb/core'\n *\n * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({\n * name: 'plugin-ts',\n * hooks: {\n * 'kubb:plugin:setup'(ctx) {\n * ctx.setResolver(resolverTs)\n * },\n * },\n * }))\n * ```\n */\nexport function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(\n factory: (options: TFactory['options']) => Plugin<TFactory>,\n): (options?: TFactory['options']) => Plugin<TFactory> {\n return (options) => factory(options ?? ({} as TFactory['options']))\n}\n\n/**\n * Detects whether an output path points at a single file (`'single'`) or a\n * directory (`'split'`). Decided purely from the presence of a file extension.\n *\n * @example Directory\n * `getMode('./types') // 'split'`\n *\n * @example Single file\n * `getMode('./api.ts') // 'single'`\n */\nexport function getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) return 'split'\n return extname(fileOrFolder) ? 'single' : 'split'\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport type { PluginFactoryOptions } from './definePlugin.ts'\nimport { getMode } from './definePlugin.ts'\nimport type { Config, Group, Output } from './types.ts'\n\n/**\n * Type/string pattern filter for include/exclude/override matching.\n */\ntype PatternFilter = {\n type: string\n pattern: string | RegExp\n}\n\n/**\n * Pattern filter with partial option overrides applied when the pattern matches.\n */\ntype PatternOverride<TOptions> = PatternFilter & {\n options: Omit<Partial<TOptions>, 'override'>\n}\n\n/**\n * Context for resolving filtered options for a given operation or schema node.\n *\n * @internal\n */\nexport type ResolveOptionsContext<TOptions> = {\n options: TOptions\n exclude?: Array<PatternFilter>\n include?: Array<PatternFilter>\n override?: Array<PatternOverride<TOptions>>\n}\n\n/**\n * Base constraint for all plugin resolver objects.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.\n *\n * @example\n * ```ts\n * type MyResolver = Resolver & {\n * resolveName(node: SchemaNode): string\n * resolveTypedName(node: SchemaNode): string\n * }\n * ```\n */\nexport type Resolver = {\n name: string\n pluginName: string\n default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string\n resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null\n resolvePath(params: ResolverPathParams, context: ResolverContext): string\n resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode\n resolveBanner(meta: InputMeta | undefined, context: ResolveBannerContext): string | null\n resolveFooter(meta: InputMeta | undefined, context: ResolveBannerContext): string | null\n}\n\n/**\n * File-specific parameters for `Resolver.resolvePath`.\n *\n * Pass alongside a `ResolverContext` to identify which file to resolve.\n * Provide `tag` for tag-based grouping or `path` for path-based grouping.\n *\n * @example\n * ```ts\n * resolver.resolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n */\nexport type ResolverPathParams = {\n baseName: FileNode['baseName']\n pathMode?: 'single' | 'split'\n /**\n * Tag value used when `group.type === 'tag'`.\n */\n tag?: string\n /**\n * Path value used when `group.type === 'path'`.\n */\n path?: string\n}\n\n/**\n * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.\n *\n * Describes where on disk output is rooted, which output config is active, and the optional\n * grouping strategy that controls subdirectory layout.\n *\n * @example\n * ```ts\n * const context: ResolverContext = {\n * root: config.root,\n * output,\n * group,\n * }\n * ```\n */\nexport type ResolverContext = {\n root: string\n output: Output\n group?: Group\n /**\n * Plugin name used to populate `meta.pluginName` on the resolved file.\n */\n pluginName?: string\n}\n\n/**\n * File-specific parameters for `Resolver.resolveFile`.\n *\n * Pass alongside a `ResolverContext` to fully describe the file to resolve.\n * `tag` and `path` are used only when a matching `group` is present in the context.\n *\n * @example\n * ```ts\n * resolver.resolveFile(\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport type ResolverFileParams = {\n name: string\n extname: FileNode['extname']\n /**\n * Tag value used when `group.type === 'tag'`.\n */\n tag?: string\n /**\n * Path value used when `group.type === 'path'`.\n */\n path?: string\n}\n\n/**\n * Per-file context describing the file a banner/footer is being resolved for.\n *\n * Supplied by the generator (or the barrel middleware) at resolve-time and merged\n * into `BannerMeta` so a `banner`/`footer` function can branch on the file kind —\n * e.g. omit a `'use server'` directive on re-export files.\n */\nexport type ResolveBannerFile = {\n /**\n * Full output path of the file being generated.\n */\n path: string\n /**\n * File name only, e.g. `'stocks.ts'`.\n */\n baseName: string\n /**\n * `true` for `index.ts` re-export barrels.\n */\n isBarrel?: boolean\n /**\n * `true` for group `[dir]/[dir].ts` aggregation files.\n */\n isAggregation?: boolean\n}\n\n/**\n * Document metadata extended with per-file context, passed to a `banner`/`footer` function.\n *\n * Carries everything in {@link InputMeta} plus the file the banner is rendered into, so a\n * single function can decide per file (e.g. skip a directive on barrel/aggregation files).\n *\n * @example Skip a directive on re-export files\n * `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : \"'use server'\"`\n */\nexport type BannerMeta = InputMeta & {\n /**\n * Full output path of the file being generated.\n */\n filePath: string\n /**\n * File name only, e.g. `'stocks.ts'`.\n */\n baseName: string\n /**\n * `true` for `index.ts` re-export barrels.\n */\n isBarrel: boolean\n /**\n * `true` for group `[dir]/[dir].ts` aggregation files.\n */\n isAggregation: boolean\n}\n\n/**\n * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.\n *\n * `output` is optional — not every plugin configures a banner/footer.\n * `config` carries the global Kubb config, used to derive the default Kubb banner.\n * `file` carries per-file context forwarded to a `banner`/`footer` function.\n *\n * @example\n * ```ts\n * resolver.resolveBanner(meta, { output: { banner: '// generated' }, config })\n * // → '// generated'\n * ```\n */\nexport type ResolveBannerContext = {\n output?: Pick<Output, 'banner' | 'footer'>\n config: Config\n file?: ResolveBannerFile\n}\n\n/**\n * Merges document `meta` with per-file `file` context into the `BannerMeta` passed to a\n * `banner`/`footer` function. Missing fields default to empty/`false` so the object shape\n * is stable even when a caller (e.g. the barrel middleware) has no document metadata.\n */\nfunction buildBannerMeta({ meta, file }: { meta: InputMeta | undefined; file: ResolveBannerFile | undefined }): BannerMeta {\n return {\n title: meta?.title,\n description: meta?.description,\n version: meta?.version,\n baseURL: meta?.baseURL,\n circularNames: meta?.circularNames ?? [],\n enumNames: meta?.enumNames ?? [],\n filePath: file?.path ?? '',\n baseName: file?.baseName ?? '',\n isBarrel: file?.isBarrel ?? false,\n isAggregation: file?.isAggregation ?? false,\n }\n}\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n *\n * Methods in the returned object can call sibling resolver methods via `this`.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n } & ThisType<T['resolver']>\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n if (type === 'tag') return node.tags.some((tag) => testPattern(tag, pattern))\n if (type === 'operationId') return testPattern(node.operationId, pattern)\n if (type === 'path') return node.path !== undefined && testPattern(node.path, pattern)\n if (type === 'method') return node.method !== undefined && testPattern(node.method.toLowerCase(), pattern)\n if (type === 'contentType') return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false\n return false\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n if (type === 'schemaName') return node.name ? testPattern(node.name, pattern) : false\n return null\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n if (type === 'file' || type === 'function') return camelCase(name, { isFile: type === 'file' })\n if (type === 'type') return pascalCase(name)\n return camelCase(name)\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nconst resolveOptionsCache = new WeakMap<object, WeakMap<Node, { value: unknown }>>()\n\nfunction computeOptions<TOptions>(\n node: Node,\n options: TOptions,\n exclude: Array<PatternFilter>,\n include: Array<PatternFilter> | undefined,\n override: Array<PatternOverride<TOptions>>,\n): TOptions | null {\n if (isOperationNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n\n if (applicable.length > 0 && !applicable.includes(true)) return null\n }\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n const optionsKey = options as object\n let byOptions = resolveOptionsCache.get(optionsKey)\n if (!byOptions) {\n byOptions = new WeakMap()\n resolveOptionsCache.set(optionsKey, byOptions)\n }\n const cached = byOptions.get(node)\n if (cached !== undefined) return cached.value as TOptions | null\n\n const result = computeOptions(node, options, exclude, include, override)\n\n byOptions.set(node, { value: result })\n\n return result\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n const result: string = (() => {\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n return path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n }\n return path.resolve(root, output.path, baseName)\n })()\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile.call(\n * resolver,\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile.call(\n * resolver,\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile(this: Resolver, { name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext): FileNode {\n const pathMode = getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : this.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = this.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: this.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n const source = (() => {\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) return path.basename(first.path)\n return ''\n }\n if (config.input && 'path' in config.input) return path.basename(config.input.path)\n if (config.input && 'data' in config.input) return 'text content'\n return ''\n })()\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the document metadata when `meta` is provided).\n *\n * - When `output.banner` is a function, calls it with the file's `BannerMeta` and returns the result.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with metadata\n * ```ts\n * defaultResolveBanner(meta, { output: { banner: (m) => `// v${m.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example Function banner skips re-export files\n * ```ts\n * defaultResolveBanner(meta, { output: { banner: (m) => (m.isBarrel ? '' : \"'use server'\") }, config, file: { path, baseName, isBarrel: true } })\n * // → ''\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(meta, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → null\n * ```\n */\nexport function defaultResolveBanner(meta: InputMeta | undefined, { output, config, file }: ResolveBannerContext): string | null {\n if (typeof output?.banner === 'function') {\n return output.banner(buildBannerMeta({ meta, file }))\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return null\n }\n\n return buildDefaultBanner({\n title: meta?.title,\n version: meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function, calls it with the file's `BannerMeta` and returns the result.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with metadata\n * ```ts\n * defaultResolveFooter(meta, { output: { footer: (m) => `// ${m.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(meta: InputMeta | undefined, { output, file }: ResolveBannerContext): string | null {\n if (typeof output?.footer === 'function') {\n return output.footer(buildBannerMeta({ meta, file }))\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return null\n}\n\n/**\n * Defines a plugin resolver. The resolver is the object that decides what\n * every generated symbol and file path is called. Built-in defaults handle\n * name casing, include/exclude/override filtering, output path computation,\n * and file construction. Supply your own to override any of them:\n *\n * - `default` — name casing strategy (camelCase / PascalCase).\n * - `resolveOptions` — include/exclude/override filtering.\n * - `resolvePath` — output path computation.\n * - `resolveFile` — full `FileNode` construction.\n * - `resolveBanner` / `resolveFooter` — top/bottom-of-file text.\n *\n * Methods in the returned object can call sibling resolver methods via `this`,\n * which keeps custom rules small (`this.default(name, 'type')` to delegate).\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolverTs = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveName(name) {\n * return this.default(name, 'function')\n * },\n * resolveTypeName(name) {\n * return this.default(name, 'type')\n * },\n * }))\n * ```\n *\n * @example Custom output path\n * ```ts\n * import path from 'node:path'\n *\n * export const resolverTs = defineResolver<PluginTs>(() => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n // `resolver` is kept so the default `resolveFile` wrapper can reference the fully assembled\n // object via `.call(resolver, ...)` at call-time, after the result is assigned below.\n let resolver: T['resolver']\n\n const result = {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n resolveFile: (params: ResolverFileParams, context: ResolverContext) => defaultResolveFile.call(resolver as Resolver, params, context),\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n ...build(),\n } as T['resolver']\n\n resolver = result\n\n return resolver\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\n\nexport type DevtoolsOptions = {\n /**\n * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.\n * @default false\n */\n ast?: boolean\n}\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n // Incoming file (b) takes precedence for banner/footer so a barrel file (whose\n // banner/footer the barrel middleware resolves last) wins over a plugin-generated\n // file at the same path.\n banner: b.banner,\n footer: b.footer,\n sources: a.sources.length ? (b.sources.length ? [...a.sources, ...b.sources] : a.sources) : b.sources,\n imports: a.imports.length ? (b.imports.length ? [...a.imports, ...b.imports] : a.imports) : b.imports,\n exports: a.exports.length ? (b.exports.length ? [...a.exports, ...b.exports] : a.exports) : b.exports,\n }\n}\n\nfunction isIndexPath(path: string): boolean {\n return path.endsWith('/index.ts') || path === 'index.ts'\n}\n\n// Sort order: shortest path first; within a length bucket, index.ts barrels last.\nfunction compareFiles(a: FileNode, b: FileNode): number {\n const lenDiff = a.path.length - b.path.length\n if (lenDiff !== 0) return lenDiff\n const aIsIndex = isIndexPath(a.path)\n const bIsIndex = isIndexPath(b.path)\n if (aIsIndex && !bIsIndex) return 1\n if (!aIsIndex && bIsIndex) return -1\n return 0\n}\n\n/**\n * In-memory file store for generated files. Files sharing a `path` are merged\n * (sources/imports/exports concatenated). The `files` getter is sorted by\n * path length (barrel `index.ts` last within a bucket).\n *\n * @example\n * ```ts\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * manager.files // sorted view\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n // Cached sorted view; null means stale and rebuilt lazily on next `files` read.\n // Nulled (not mutated) on every write so callers holding a prior reference\n // keep their snapshot — `dispose()` must not silently empty an array the\n // consumer already holds.\n #sorted: Array<FileNode> | null = null\n #onUpsert: ((file: FileNode) => void) | null = null\n\n /**\n * Registers a callback invoked with the resolved {@link FileNode} on every\n * `add` / `upsert`. Used by the build loop to track newly written files\n * without keeping its own scan-based diff. Single subscriber by design —\n * setting again replaces the previous callback. Pass `null` to detach.\n */\n setOnUpsert(callback: ((file: FileNode) => void) | null): void {\n this.#onUpsert = callback\n }\n\n add(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, false)\n }\n\n upsert(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, true)\n }\n\n #store(files: ReadonlyArray<FileNode>, mergeExisting: boolean): Array<FileNode> {\n const batch = files.length > 1 ? this.#dedupe(files) : files\n const resolved: Array<FileNode> = []\n\n for (const file of batch) {\n const existing = this.#cache.get(file.path)\n const merged = existing && mergeExisting ? createFile(mergeFile(existing, file)) : createFile(file)\n this.#cache.set(merged.path, merged)\n resolved.push(merged)\n this.#onUpsert?.(merged)\n }\n\n if (resolved.length > 0) this.#sorted = null\n return resolved\n }\n\n // Merges same-path entries within a batch so the cache update loop stays\n // uniform. Only called for multi-file batches.\n #dedupe(files: ReadonlyArray<FileNode>): Array<FileNode> {\n const seen = new Map<string, FileNode>()\n for (const file of files) {\n const prev = seen.get(file.path)\n seen.set(file.path, prev ? mergeFile(prev, file) : file)\n }\n return [...seen.values()]\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n if (!this.#cache.delete(path)) return\n this.#sorted = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#sorted = null\n }\n\n /**\n * Releases all stored files. Called by the core after `kubb:build:end`.\n */\n dispose(): void {\n this.clear()\n this.#onUpsert = null\n }\n\n [Symbol.dispose](): void {\n this.dispose()\n }\n\n /**\n * All stored files in stable sort order (shortest path first, barrel files\n * last within a length bucket). Returns a cached view — do not mutate.\n */\n get files(): Array<FileNode> {\n return (this.#sorted ??= [...this.#cache.values()].sort(compareFiles))\n }\n}\n","import type { CodeNode, FileNode } from '@kubb/ast'\nimport { extractStringsFromNodes } from '@kubb/ast'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport type { Parser } from './defineParser.ts'\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n}\n\nexport type FileProcessorEvents = {\n start: [files: Array<FileNode>]\n update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]\n end: [files: Array<FileNode>]\n}\n\nexport type ParsedFile = {\n file: FileNode\n source: string\n processed: number\n total: number\n percentage: number\n}\n\nfunction joinSources(file: FileNode): string {\n const sources = file.sources\n if (sources.length === 0) return ''\n const parts: Array<string> = []\n for (const source of sources) {\n const s = extractStringsFromNodes(source.nodes as Array<CodeNode>)\n if (s) parts.push(s)\n }\n return parts.join('\\n\\n')\n}\n\n/**\n * Converts a single file to a string using the registered parsers.\n * Falls back to joining source values when no matching parser is found.\n *\n * @internal\n */\nexport class FileProcessor {\n readonly events = new AsyncEventEmitter<FileProcessorEvents>()\n\n parse(file: FileNode, { parsers, extension }: ParseOptions = {}): string {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers || !file.extname) {\n return joinSources(file)\n }\n\n const parser = parsers.get(file.extname)\n\n if (!parser) {\n return joinSources(file)\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n *stream(files: ReadonlyArray<FileNode>, options: ParseOptions = {}): Generator<ParsedFile> {\n const total = files.length\n if (total === 0) return\n\n let processed = 0\n for (const file of files) {\n const source = this.parse(file, options)\n processed++\n\n yield { file, source, processed, total, percentage: (processed / total) * 100 }\n }\n }\n\n async run(files: Array<FileNode>, options: ParseOptions = {}): Promise<Array<FileNode>> {\n await this.events.emit('start', files)\n\n for (const { file, source, processed, total, percentage } of this.stream(files, options)) {\n await this.events.emit('update', { file, source, processed, percentage, total })\n }\n\n await this.events.emit('end', files)\n\n return files\n }\n\n /**\n * Clears all registered event listeners.\n */\n dispose(): void {\n this.events.removeAll()\n }\n\n [Symbol.dispose](): void {\n this.dispose()\n }\n}\n","import { resolve } from 'node:path'\nimport { arrayToAsyncIterable, type AsyncEventEmitter, forBatches, formatMs, getElapsedMs, isPromise, memoize, URLPath } from '@internals/utils'\nimport { collectUsedSchemaNames, createFile, createStreamInput, transform } from '@kubb/ast'\nimport type { FileNode, InputMeta, InputNode, InputStreamNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL, SCHEMA_PARALLEL, STREAM_FLUSH_EVERY } from './constants.ts'\nimport type { Storage } from './createStorage.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { getMode } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport { FileProcessor } from './FileProcessor.ts'\nimport type { Renderer, RendererFactory } from './createRenderer.ts'\n\nimport type {\n Adapter,\n AdapterSource,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n Middleware,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nfunction enforceOrder(enforce: 'pre' | 'post' | undefined): number {\n return enforce === 'pre' ? -1 : enforce === 'post' ? 1 : 0\n}\n\nconst OPERATION_FILTER_TYPES = new Set(['tag', 'operationId', 'path', 'method', 'contentType'])\n\nexport class KubbDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * KubbDriver.getMode('src/gen/types.ts') // 'single'\n * KubbDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n return getMode(fileOrFolder)\n }\n\n /**\n * The streaming `InputStreamNode` produced by the adapter.\n * Always set after adapter setup — parse-only adapters are wrapped automatically.\n */\n inputNode: InputStreamNode | null = null\n adapter: Adapter | null = null\n /**\n * Studio session state, kept together so `dispose()` can reset it atomically.\n *\n * - `source` holds the raw adapter source so `adapter.parse()` can be called lazily.\n * Intentionally outlives the build; cleared by `dispose()`.\n * - `isOpen` prevents opening the studio more than once per build.\n * - `inputNode` caches the parse promise so `adapter.parse()` is called at most once\n * per studio session, even when `openInStudio()` is called multiple times.\n */\n #studio: { source: AdapterSource | null; isOpen: boolean; inputNode: Promise<InputNode> | null } = {\n source: null,\n isOpen: false,\n inputNode: null,\n }\n\n // Register middleware hooks after all plugin hooks are registered.\n // Because AsyncEventEmitter calls listeners in registration order,\n // middleware hooks for any event fire after all plugin hooks for that event.\n // Handlers are tracked so they can be removed after each build (disposeMiddleware),\n // preventing accumulation when multiple configs share the same hooks instance.\n #middlewareListeners: Array<[keyof KubbHooks & string, (...args: Array<never>) => void | Promise<void>]> = []\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n readonly #fileProcessor = new FileProcessor()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #eventGeneratorPlugins = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: Array<never>) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n this.adapter = config.adapter ?? null\n }\n\n async setup() {\n const normalized: Array<NormalizedPlugin> = this.config.plugins.map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n\n normalized.sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n\n return enforceOrder(a.enforce) - enforceOrder(b.enforce)\n })\n\n for (const plugin of normalized) {\n if (plugin.apply) {\n plugin.apply(this.config)\n }\n\n this.#registerPlugin(plugin)\n this.plugins.set(plugin.name, plugin)\n }\n\n if (this.config.middleware) {\n for (const middleware of this.config.middleware) {\n for (const event of Object.keys(middleware.hooks) as Array<keyof KubbHooks & string>) {\n this.#registerMiddleware(event, middleware.hooks)\n }\n }\n }\n if (this.config.adapter) {\n await this.#registerAdapter(this.config.adapter)\n }\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(plugin: Plugin): NormalizedPlugin {\n const normalized: NormalizedPlugin = {\n name: plugin.name,\n dependencies: plugin.dependencies,\n enforce: plugin.enforce,\n hooks: plugin.hooks,\n options: plugin.options ?? { output: { path: '.' }, exclude: [], override: [] },\n } as NormalizedPlugin\n\n if ('apply' in plugin && typeof plugin.apply === 'function') {\n normalized.apply = plugin.apply as (config: Config) => boolean\n }\n\n return normalized\n }\n\n async #registerAdapter(adapter: Adapter) {\n const source = inputToAdapterSource(this.config)\n this.#studio.source = source\n\n if (adapter.stream) {\n this.inputNode = await adapter.stream(source)\n\n await this.hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Adapter '${adapter.name}' producing input stream`],\n })\n } else {\n // Adapter does not implement stream() — eagerly parse and wrap in a\n // reusable AsyncIterable so the rest of the pipeline stays stream-only.\n const inputNode = await adapter.parse(source)\n this.inputNode = createStreamInput(arrayToAsyncIterable(inputNode.schemas), arrayToAsyncIterable(inputNode.operations), inputNode.meta)\n\n await this.hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n `✓ Adapter '${adapter.name}' resolved InputNode (wrapped as stream)`,\n ` • Schemas: ${inputNode.schemas.length}`,\n ` • Operations: ${inputNode.operations.length}`,\n ],\n })\n }\n }\n\n #registerMiddleware<K extends keyof KubbHooks & string>(event: K, middlewareHooks: Middleware['hooks']) {\n const handler = middlewareHooks[event]\n\n if (!handler) {\n return\n }\n\n this.hooks.on(event, handler)\n this.#middlewareListeners.push([event, handler as (...args: Array<never>) => void | Promise<void>])\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n #registerPlugin(plugin: NormalizedPlugin): void {\n const { hooks } = plugin\n\n if (!hooks) return\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: plugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(plugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(plugin.name, resolver)\n },\n setTransformer: (visitor) => {\n plugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n plugin.renderer = renderer\n },\n setOptions: (opts) => {\n plugin.options = { ...plugin.options, ...opts }\n },\n injectFile: (userFileNode) => {\n this.fileManager.add(createFile(userFileNode))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: Array<never>) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: Array<never>) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: Array<never>) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: Array<never>) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: Array<never>) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: Array<never>) => void | Promise<void>)\n }\n\n this.#eventGeneratorPlugins.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasEventGenerators(pluginName: string): boolean {\n return this.#eventGeneratorPlugins.has(pluginName)\n }\n\n /**\n * Runs the full plugin pipeline. Returns timings/failures collected so far even\n * when an outer hook throws — the orchestrator preserves partial state by capturing\n * the error into `error` instead of propagating.\n */\n async run({ storage }: { storage: Storage }): Promise<{\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n pluginTimings: Map<string, number>\n error?: Error\n }> {\n const hooks = this.hooks\n const config = this.config\n const failedPlugins = new Set<{ plugin: Plugin; error: Error }>()\n const pluginTimings = new Map<string, number>()\n const parsersMap = new Map<FileNode['extname'], Parser>()\n\n for (const parser of config.parsers) {\n if (parser.extNames) {\n for (const ext of parser.extNames) parsersMap.set(ext, parser)\n }\n }\n\n const pendingFiles = new Map<string, FileNode>()\n this.fileManager.setOnUpsert((file) => {\n pendingFiles.set(file.path, file)\n })\n\n try {\n const flushPending = async (): Promise<void> => {\n if (pendingFiles.size === 0) return\n const files = [...pendingFiles.values()]\n pendingFiles.clear()\n\n await hooks.emit('kubb:debug', { date: new Date(), logs: [`Writing ${files.length} files...`] })\n await hooks.emit('kubb:files:processing:start', { files })\n\n const items = [...this.#fileProcessor.stream(files, { parsers: parsersMap, extension: config.output.extension })]\n\n await hooks.emit('kubb:files:processing:update', {\n files: items.map(({ file, source, processed, total, percentage }) => ({ file, source, processed, total, percentage, config })),\n })\n\n const queue: Array<Promise<void>> = []\n for (const { file, source } of items) {\n if (source) {\n queue.push(storage.setItem(file.path, source))\n if (queue.length >= STREAM_FLUSH_EVERY) await Promise.all(queue.splice(0))\n }\n }\n await Promise.all(queue)\n\n await hooks.emit('kubb:files:processing:end', { files })\n await hooks.emit('kubb:debug', { date: new Date(), logs: [`✓ File write process completed for ${files.length} files`] })\n }\n\n await this.emitSetupHooks()\n\n if (this.adapter && this.inputNode) {\n await hooks.emit(\n 'kubb:build:start',\n Object.assign({ config, adapter: this.adapter, meta: this.inputNode.meta, getPlugin: this.getPlugin.bind(this) }, this.#filesPayload()),\n )\n }\n\n const generatorPlugins: Array<{ plugin: NormalizedPlugin; context: GeneratorContext; hrStart: ReturnType<typeof process.hrtime> }> = []\n\n for (const plugin of this.plugins.values()) {\n const context = this.getContext(plugin)\n const hrStart = process.hrtime()\n\n try {\n await hooks.emit('kubb:plugin:start', { plugin })\n await hooks.emit('kubb:debug', { date: new Date(), logs: ['Starting plugin...', ` • Plugin Name: ${plugin.name}`] })\n } catch (caughtError) {\n const error = caughtError as Error\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\n await this.#emitPluginEnd({ plugin, duration, success: false, error })\n failedPlugins.add({ plugin, error })\n continue\n }\n\n if (plugin.generators?.length || this.hasEventGenerators(plugin.name)) {\n generatorPlugins.push({ plugin, context, hrStart })\n continue\n }\n\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\n await this.#emitPluginEnd({ plugin, duration, success: true })\n await hooks.emit('kubb:debug', { date: new Date(), logs: [`✓ Plugin started successfully (${formatMs(duration)})`] })\n }\n\n if (generatorPlugins.length > 0) {\n if (this.inputNode) {\n const { timings, failed } = await this.#runGenerators(generatorPlugins, flushPending)\n // Drain any files written after the last batch's flush.\n await flushPending()\n for (const [name, duration] of timings) pluginTimings.set(name, duration)\n for (const entry of failed) failedPlugins.add(entry)\n } else {\n // No adapter input: generator-plugins have nothing to dispatch, but still\n // need their `kubb:plugin:end` so middleware (e.g. barrel) completes.\n for (const { plugin, hrStart } of generatorPlugins) {\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\n await this.#emitPluginEnd({ plugin, duration, success: true })\n }\n }\n }\n\n await hooks.emit('kubb:plugins:end', Object.assign({ config }, this.#filesPayload()))\n\n await flushPending()\n\n const files = this.fileManager.files\n\n await hooks.emit('kubb:build:end', { files, config, outputDir: resolve(config.root, config.output.path) })\n\n return { failedPlugins, pluginTimings }\n } catch (caughtError) {\n return { failedPlugins, pluginTimings, error: caughtError as Error }\n } finally {\n this.fileManager.setOnUpsert(null)\n }\n }\n\n // Returns a fresh object with a lazy `files` getter and a bound `upsertFile`.\n // Caller must use `Object.assign(extra, this.#filesPayload())`, not object spread —\n // spread would eagerly invoke the getter and freeze a stale snapshot into the payload.\n #filesPayload(): { readonly files: Array<FileNode>; upsertFile: (...files: Array<FileNode>) => Array<FileNode> } {\n const driver = this\n return {\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files: Array<FileNode>) => driver.fileManager.upsert(...files),\n }\n }\n\n #emitPluginEnd({ plugin, duration, success, error }: { plugin: NormalizedPlugin; duration: number; success: boolean; error?: Error }): Promise<void> | void {\n return this.hooks.emit(\n 'kubb:plugin:end',\n Object.assign({ plugin, duration, success, ...(error ? { error } : {}), config: this.config }, this.#filesPayload()),\n )\n }\n\n async #runGenerators(\n entries: Array<{ plugin: NormalizedPlugin; context: GeneratorContext; hrStart: ReturnType<typeof process.hrtime> }>,\n flushPending: () => Promise<void>,\n ): Promise<{ timings: Map<string, number>; failed: Set<{ plugin: Plugin; error: Error }> }> {\n const timings = new Map<string, number>()\n const failed = new Set<{ plugin: Plugin; error: Error }>()\n type PluginState = {\n plugin: NormalizedPlugin\n generatorContext: GeneratorContext\n generators: Array<Generator>\n hrStart: ReturnType<typeof process.hrtime>\n failed: boolean\n error: Error | null\n optionsAreStatic: boolean\n allowedSchemaNames: Set<string> | null\n }\n\n const driver = this\n const { schemas, operations } = this.inputNode!\n const states: Array<PluginState> = entries.map(({ plugin, context, hrStart }) => {\n const { exclude, include, override } = plugin.options\n const hasExclude = Array.isArray(exclude) && exclude.length > 0\n const hasInclude = Array.isArray(include) && include.length > 0\n const hasOverride = Array.isArray(override) && override.length > 0\n return {\n plugin,\n generatorContext: { ...context, resolver: this.getResolver(plugin.name) },\n generators: plugin.generators ?? [],\n hrStart,\n failed: false,\n error: null,\n optionsAreStatic: !hasExclude && !hasInclude && !hasOverride,\n allowedSchemaNames: null,\n }\n })\n\n const emitsSchemaHook = this.hooks.listenerCount('kubb:generate:schema') > 0\n const emitsOperationHook = this.hooks.listenerCount('kubb:generate:operation') > 0\n\n // Pre-scan: plugins with operation-based includes (but no schemaName include) need\n // the reachable schema set. This requires the full schema graph in memory at once —\n // transitive reachability can't be derived from a single node. `allSchemas` is\n // released as soon as the pre-scan returns; the main passes get fresh iterators.\n const pruningStates = states.filter(({ plugin }) => {\n const { include } = plugin.options\n return (include?.some(({ type }) => OPERATION_FILTER_TYPES.has(type)) ?? false) && !(include?.some(({ type }) => type === 'schemaName') ?? false)\n })\n\n if (pruningStates.length > 0) {\n const allSchemas: Array<SchemaNode> = []\n for await (const schema of schemas) allSchemas.push(schema)\n\n const includedOpsByState = new Map<PluginState, Array<OperationNode>>(pruningStates.map((s) => [s, []]))\n for await (const operation of operations) {\n for (const state of pruningStates) {\n const { exclude, include, override } = state.plugin.options\n const options = state.generatorContext.resolver.resolveOptions(operation, { options: state.plugin.options, exclude, include, override })\n if (options !== null) includedOpsByState.get(state)?.push(operation)\n }\n }\n\n for (const state of pruningStates) {\n state.allowedSchemaNames = collectUsedSchemaNames(includedOpsByState.get(state) ?? [], allSchemas)\n includedOpsByState.delete(state)\n }\n }\n\n const resolveRendererFor = (gen: Generator, state: PluginState): RendererFactory | undefined =>\n gen.renderer === null ? undefined : (gen.renderer ?? state.plugin.renderer ?? state.generatorContext.config.renderer)\n\n // Schema and operation passes share this body. They differ only in which\n // generator method runs, which hook is emitted, and the schema-only\n // `allowedSchemaNames` prune (operations don't carry that constraint).\n const dispatchNode = async <TNode extends SchemaNode | OperationNode>(\n state: PluginState,\n node: TNode,\n dispatch: {\n method: 'schema' | 'operation'\n checkAllowedNames: boolean\n emit: ((node: TNode, ctx: GeneratorContext) => Promise<void> | void) | null\n },\n ): Promise<void> => {\n if (state.failed) return\n try {\n const { plugin, generatorContext, generators } = state\n const transformedNode: TNode = plugin.transformer ? (transform(node, plugin.transformer) as TNode) : node\n\n if (\n dispatch.checkAllowedNames &&\n state.allowedSchemaNames !== null &&\n 'name' in transformedNode &&\n transformedNode.name &&\n !state.allowedSchemaNames.has(transformedNode.name)\n ) {\n return\n }\n\n const { exclude, include, override } = plugin.options\n const options = state.optionsAreStatic\n ? plugin.options\n : generatorContext.resolver.resolveOptions(transformedNode, { options: plugin.options, exclude, include, override })\n if (options === null) return\n\n const ctx = { ...generatorContext, options }\n for (const gen of generators) {\n const generate = gen[dispatch.method] as ((node: TNode, ctx: GeneratorContext) => unknown) | undefined\n if (!generate) continue\n const raw = generate(transformedNode, ctx)\n const result = isPromise(raw) ? await raw : raw\n const applied = applyHookResult({ result, driver, rendererFactory: resolveRendererFor(gen, state) })\n if (isPromise(applied)) await applied\n }\n if (dispatch.emit) await dispatch.emit(transformedNode, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n\n const schemaDispatch = {\n method: 'schema',\n checkAllowedNames: true,\n emit: emitsSchemaHook ? (node: SchemaNode, ctx: GeneratorContext) => this.hooks.emit('kubb:generate:schema', node, ctx) : null,\n } as const\n const operationDispatch = {\n method: 'operation',\n checkAllowedNames: false,\n emit: emitsOperationHook ? (node: OperationNode, ctx: GeneratorContext) => this.hooks.emit('kubb:generate:operation', node, ctx) : null,\n } as const\n\n // Skip building the aggregated operations array when nothing consumes it.\n // Saves an N-sized allocation that lives until the build ends, on the common\n // path where plugins only define per-node `gen.operation`.\n const needsCollectedOperations = this.hooks.listenerCount('kubb:generate:operations') > 0 || states.some((s) => s.generators.some((g) => !!g.operations))\n const collectedOperations: Array<OperationNode> = needsCollectedOperations ? [] : (undefined as never)\n\n // Run schemas before operations: the two passes share `flushPending` and the\n // FileProcessor's event emitter, so running them concurrently would interleave\n // `kubb:files:processing:start|end` events and race on the shared dirty list.\n await forBatches(schemas, (nodes) => Promise.all(nodes.flatMap((n) => states.map((state) => dispatchNode(state, n, schemaDispatch)))), {\n concurrency: SCHEMA_PARALLEL,\n flush: flushPending,\n })\n\n await forBatches(\n operations,\n (nodes) => {\n if (needsCollectedOperations) collectedOperations.push(...nodes)\n return Promise.all(nodes.flatMap((n) => states.map((state) => dispatchNode(state, n, operationDispatch))))\n },\n { concurrency: SCHEMA_PARALLEL, flush: flushPending },\n )\n\n for (const state of states) {\n if (!state.failed && needsCollectedOperations) {\n try {\n const { plugin, generatorContext, generators } = state\n const ctx = { ...generatorContext, options: plugin.options }\n // Filter to operations this plugin would have dispatched to gen.operation():\n // excludes/includes/overrides that resolve to null in dispatchOperation must also\n // be hidden from the batched gen.operations() hook, otherwise grouped/barrel\n // generators emit references to operation files that the per-op hook intentionally skipped.\n const pluginOperations = state.optionsAreStatic\n ? collectedOperations\n : collectedOperations.filter((node) => {\n const transformed = plugin.transformer ? transform(node, plugin.transformer) : node\n const { exclude, include, override } = plugin.options\n\n return generatorContext.resolver.resolveOptions(transformed, { options: plugin.options, exclude, include, override }) !== null\n })\n for (const gen of generators) {\n if (!gen.operations) continue\n const result = await gen.operations(pluginOperations, ctx)\n await applyHookResult({ result, driver, rendererFactory: resolveRendererFor(gen, state) })\n }\n await this.hooks.emit('kubb:generate:operations', pluginOperations, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n\n const duration = getElapsedMs(state.hrStart)\n timings.set(state.plugin.name, duration)\n await this.#emitPluginEnd({ plugin: state.plugin, duration, success: !state.failed, error: state.failed && state.error ? state.error : undefined })\n\n if (state.failed && state.error) failed.add({ plugin: state.plugin, error: state.error })\n\n await this.hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [state.failed ? '✗ Plugin start failed' : `✓ Plugin started successfully (${formatMs(duration)})`],\n })\n }\n\n return { timings, failed }\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n\n this.#hookListeners.clear()\n this.#eventGeneratorPlugins.clear()\n // Release resolver closures — the driver is rebuilt for each build() call\n // so there is no value in retaining these maps after disposal.\n this.#resolvers.clear()\n this.#defaultResolvers.clear()\n // Release the FileNode cache, parsed adapter graph, and studio state so\n // memory is reclaimed between builds. The returned `BuildOutput.files`\n // array still references any FileNodes the caller needs to inspect.\n this.fileManager.dispose()\n this.#fileProcessor.dispose()\n this.inputNode = null\n this.#studio = { source: null, isOpen: false, inputNode: null }\n\n for (const [event, handler] of this.#middlewareListeners) {\n this.hooks.off(event, handler as never)\n }\n }\n\n [Symbol.dispose](): void {\n this.dispose()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: Array<never>) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #getDefaultResolver = memoize(\n this.#defaultResolvers,\n (pluginName: string): Resolver => defineResolver<PluginFactoryOptions>(() => ({ name: 'default', pluginName })),\n )\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#getDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#getDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n return {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return KubbDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get meta(): InputMeta {\n return driver.inputNode?.meta ?? { circularNames: [], enumNames: [] }\n },\n get adapter(): Adapter | null {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', { message })\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', { error: typeof error === 'string' ? new Error(error) : error })\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', { message })\n },\n async openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studio.isOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.adapter || !driver.#studio.source) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studio.isOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n driver.#studio.inputNode ??= Promise.resolve(driver.adapter.parse(driver.#studio.source))\n const inputNode = await driver.#studio.inputNode\n\n return openInStudioFn(inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport function applyHookResult<TElement = unknown>({\n result,\n driver,\n rendererFactory,\n}: {\n result: TElement | Array<FileNode> | undefined | null\n driver: KubbDriver\n rendererFactory?: RendererFactory<TElement> | null\n}): void | Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n if (renderer.stream) {\n using r = renderer\n for (const file of r.stream!(result)) {\n driver.fileManager.upsert(file)\n }\n return\n }\n return applyAsyncRender({ renderer, result, driver })\n}\n\nasync function applyAsyncRender<TElement>({ renderer, result, driver }: { renderer: Renderer<TElement>; result: TElement; driver: KubbDriver }): Promise<void> {\n using r = renderer\n await r.render(result)\n driver.fileManager.upsert(...r.files)\n}\n\nfunction inputToAdapterSource(config: Config): AdapterSource {\n const input = config.input\n if (!input) {\n throw new Error('[kubb] input is required when using an adapter. Provide input.path or input.data in your config.')\n }\n\n if ('data' in input) {\n return { type: 'data', data: input.data }\n }\n\n if (new URLPath(input.path).isURL) {\n return { type: 'path', path: input.path }\n }\n\n const resolved = resolve(config.root, input.path)\n\n return { type: 'path', path: resolved }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YAA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Q,OAAO,EAAE;EACzB,OAAO,YAAY,OAAO,GAAI,OAA2B;EACzD;;CAGF,IAAI,CAAC,iBACH;CAGF,MAAM,WAAW,iBAAiB;CAClC,IAAI,SAAS,QAAQ,IAAA;;EACnB,MAAM,IAAA,YAAA,EAAI,SAAA;EACV,KAAK,MAAM,QAAQ,EAAE,OAAQ,OAAO,EAClC,OAAO,YAAY,OAAO,KAAK;EAEjC;;;;;;CAEF,OAAO,iBAAiB;EAAE;EAAU;EAAQ;EAAQ,CAAC;;AAGvD,eAAe,iBAA2B,EAAE,UAAU,QAAQ,UAAiG;;;EAC7J,MAAM,IAAA,WAAA,EAAI,SAAA;EACV,MAAM,EAAE,OAAO,OAAO;EACtB,OAAO,YAAY,OAAO,GAAG,EAAE,MAAM;;;;;;;AAGvC,SAAS,qBAAqB,QAA+B;CAC3D,MAAM,QAAQ,OAAO;CACrB,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,mGAAmG;CAGrH,IAAI,UAAU,OACZ,OAAO;EAAE,MAAM;EAAQ,MAAM,MAAM;EAAM;CAG3C,IAAI,IAAI,QAAQ,MAAM,KAAK,CAAC,OAC1B,OAAO;EAAE,MAAM;EAAQ,MAAM,MAAM;EAAM;CAK3C,OAAO;EAAE,MAAM;EAAQ,OAAA,GAAA,UAAA,SAFE,OAAO,MAAM,MAAM,KAEP;EAAE"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_KubbDriver = require("./KubbDriver-
|
|
2
|
+
const require_KubbDriver = require("./KubbDriver-vyD7F0Ip.cjs");
|
|
3
3
|
let node_fs_promises = require("node:fs/promises");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
let _kubb_ast = require("@kubb/ast");
|
|
@@ -107,7 +107,7 @@ function createAdapter(build) {
|
|
|
107
107
|
}
|
|
108
108
|
//#endregion
|
|
109
109
|
//#region package.json
|
|
110
|
-
var version = "5.0.0-beta.
|
|
110
|
+
var version = "5.0.0-beta.30";
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/createStorage.ts
|
|
113
113
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as FileManager, c as DEFAULT_BANNER, d as logLevel, f as URLPath, i as FileProcessor, l as DEFAULT_EXTENSION, m as BuildError, o as defineResolver, p as AsyncEventEmitter, r as _usingCtx, s as definePlugin, t as KubbDriver, u as DEFAULT_STUDIO_URL } from "./KubbDriver-
|
|
2
|
+
import { a as FileManager, c as DEFAULT_BANNER, d as logLevel, f as URLPath, i as FileProcessor, l as DEFAULT_EXTENSION, m as BuildError, o as defineResolver, p as AsyncEventEmitter, r as _usingCtx, s as definePlugin, t as KubbDriver, u as DEFAULT_STUDIO_URL } from "./KubbDriver-CFx2DdhF.js";
|
|
3
3
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import * as ast from "@kubb/ast";
|
|
@@ -106,7 +106,7 @@ function createAdapter(build) {
|
|
|
106
106
|
}
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region package.json
|
|
109
|
-
var version$1 = "5.0.0-beta.
|
|
109
|
+
var version$1 = "5.0.0-beta.30";
|
|
110
110
|
//#endregion
|
|
111
111
|
//#region src/createStorage.ts
|
|
112
112
|
/**
|
package/dist/mocks.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_KubbDriver = require("./KubbDriver-
|
|
2
|
+
const require_KubbDriver = require("./KubbDriver-vyD7F0Ip.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
let _kubb_ast = require("@kubb/ast");
|
|
5
5
|
//#region src/mocks.ts
|
package/dist/mocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as FileManager, n as applyHookResult, t as KubbDriver } from "./KubbDriver-
|
|
2
|
+
import { a as FileManager, n as applyHookResult, t as KubbDriver } from "./KubbDriver-CFx2DdhF.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { transform } from "@kubb/ast";
|
|
5
5
|
//#region src/mocks.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.30",
|
|
4
4
|
"description": "Core engine for Kubb's plugin-based code generation system. Provides the plugin driver, file manager, defineConfig, and build orchestration used by every Kubb plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generator",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"fflate": "^0.8.3",
|
|
60
60
|
"tinyexec": "^1.1.2",
|
|
61
|
-
"@kubb/ast": "5.0.0-beta.
|
|
61
|
+
"@kubb/ast": "5.0.0-beta.30"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@internals/utils": "0.0.0",
|
|
65
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
65
|
+
"@kubb/renderer-jsx": "5.0.0-beta.30"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@kubb/renderer-jsx": "5.0.0-beta.
|
|
68
|
+
"@kubb/renderer-jsx": "5.0.0-beta.30"
|
|
69
69
|
},
|
|
70
70
|
"size-limit": [
|
|
71
71
|
{
|
package/src/KubbDriver.ts
CHANGED
|
@@ -571,13 +571,30 @@ export class KubbDriver {
|
|
|
571
571
|
const resolveRendererFor = (gen: Generator, state: PluginState): RendererFactory | undefined =>
|
|
572
572
|
gen.renderer === null ? undefined : (gen.renderer ?? state.plugin.renderer ?? state.generatorContext.config.renderer)
|
|
573
573
|
|
|
574
|
-
|
|
574
|
+
// Schema and operation passes share this body. They differ only in which
|
|
575
|
+
// generator method runs, which hook is emitted, and the schema-only
|
|
576
|
+
// `allowedSchemaNames` prune (operations don't carry that constraint).
|
|
577
|
+
const dispatchNode = async <TNode extends SchemaNode | OperationNode>(
|
|
578
|
+
state: PluginState,
|
|
579
|
+
node: TNode,
|
|
580
|
+
dispatch: {
|
|
581
|
+
method: 'schema' | 'operation'
|
|
582
|
+
checkAllowedNames: boolean
|
|
583
|
+
emit: ((node: TNode, ctx: GeneratorContext) => Promise<void> | void) | null
|
|
584
|
+
},
|
|
585
|
+
): Promise<void> => {
|
|
575
586
|
if (state.failed) return
|
|
576
587
|
try {
|
|
577
588
|
const { plugin, generatorContext, generators } = state
|
|
578
|
-
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node
|
|
579
|
-
|
|
580
|
-
if (
|
|
589
|
+
const transformedNode: TNode = plugin.transformer ? (transform(node, plugin.transformer) as TNode) : node
|
|
590
|
+
|
|
591
|
+
if (
|
|
592
|
+
dispatch.checkAllowedNames &&
|
|
593
|
+
state.allowedSchemaNames !== null &&
|
|
594
|
+
'name' in transformedNode &&
|
|
595
|
+
transformedNode.name &&
|
|
596
|
+
!state.allowedSchemaNames.has(transformedNode.name)
|
|
597
|
+
) {
|
|
581
598
|
return
|
|
582
599
|
}
|
|
583
600
|
|
|
@@ -589,44 +606,30 @@ export class KubbDriver {
|
|
|
589
606
|
|
|
590
607
|
const ctx = { ...generatorContext, options }
|
|
591
608
|
for (const gen of generators) {
|
|
592
|
-
|
|
593
|
-
|
|
609
|
+
const generate = gen[dispatch.method] as ((node: TNode, ctx: GeneratorContext) => unknown) | undefined
|
|
610
|
+
if (!generate) continue
|
|
611
|
+
const raw = generate(transformedNode, ctx)
|
|
594
612
|
const result = isPromise(raw) ? await raw : raw
|
|
595
613
|
const applied = applyHookResult({ result, driver, rendererFactory: resolveRendererFor(gen, state) })
|
|
596
614
|
if (isPromise(applied)) await applied
|
|
597
615
|
}
|
|
598
|
-
if (
|
|
616
|
+
if (dispatch.emit) await dispatch.emit(transformedNode, ctx)
|
|
599
617
|
} catch (caughtError) {
|
|
600
618
|
state.failed = true
|
|
601
619
|
state.error = caughtError as Error
|
|
602
620
|
}
|
|
603
621
|
}
|
|
604
622
|
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
const ctx = { ...generatorContext, options }
|
|
617
|
-
for (const gen of generators) {
|
|
618
|
-
if (!gen.operation) continue
|
|
619
|
-
const raw = gen.operation(transformedNode, ctx)
|
|
620
|
-
const result = isPromise(raw) ? await raw : raw
|
|
621
|
-
const applied = applyHookResult({ result, driver, rendererFactory: resolveRendererFor(gen, state) })
|
|
622
|
-
if (isPromise(applied)) await applied
|
|
623
|
-
}
|
|
624
|
-
if (emitsOperationHook) await this.hooks.emit('kubb:generate:operation', transformedNode, ctx)
|
|
625
|
-
} catch (caughtError) {
|
|
626
|
-
state.failed = true
|
|
627
|
-
state.error = caughtError as Error
|
|
628
|
-
}
|
|
629
|
-
}
|
|
623
|
+
const schemaDispatch = {
|
|
624
|
+
method: 'schema',
|
|
625
|
+
checkAllowedNames: true,
|
|
626
|
+
emit: emitsSchemaHook ? (node: SchemaNode, ctx: GeneratorContext) => this.hooks.emit('kubb:generate:schema', node, ctx) : null,
|
|
627
|
+
} as const
|
|
628
|
+
const operationDispatch = {
|
|
629
|
+
method: 'operation',
|
|
630
|
+
checkAllowedNames: false,
|
|
631
|
+
emit: emitsOperationHook ? (node: OperationNode, ctx: GeneratorContext) => this.hooks.emit('kubb:generate:operation', node, ctx) : null,
|
|
632
|
+
} as const
|
|
630
633
|
|
|
631
634
|
// Skip building the aggregated operations array when nothing consumes it.
|
|
632
635
|
// Saves an N-sized allocation that lives until the build ends, on the common
|
|
@@ -637,7 +640,7 @@ export class KubbDriver {
|
|
|
637
640
|
// Run schemas before operations: the two passes share `flushPending` and the
|
|
638
641
|
// FileProcessor's event emitter, so running them concurrently would interleave
|
|
639
642
|
// `kubb:files:processing:start|end` events and race on the shared dirty list.
|
|
640
|
-
await forBatches(schemas, (nodes) => Promise.all(nodes.flatMap((n) => states.map((state) =>
|
|
643
|
+
await forBatches(schemas, (nodes) => Promise.all(nodes.flatMap((n) => states.map((state) => dispatchNode(state, n, schemaDispatch)))), {
|
|
641
644
|
concurrency: SCHEMA_PARALLEL,
|
|
642
645
|
flush: flushPending,
|
|
643
646
|
})
|
|
@@ -646,7 +649,7 @@ export class KubbDriver {
|
|
|
646
649
|
operations,
|
|
647
650
|
(nodes) => {
|
|
648
651
|
if (needsCollectedOperations) collectedOperations.push(...nodes)
|
|
649
|
-
return Promise.all(nodes.flatMap((n) => states.map((state) =>
|
|
652
|
+
return Promise.all(nodes.flatMap((n) => states.map((state) => dispatchNode(state, n, operationDispatch))))
|
|
650
653
|
},
|
|
651
654
|
{ concurrency: SCHEMA_PARALLEL, flush: flushPending },
|
|
652
655
|
)
|
package/src/defineResolver.ts
CHANGED
|
@@ -271,8 +271,8 @@ function testPattern(value: string, pattern: string | RegExp): boolean {
|
|
|
271
271
|
function matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {
|
|
272
272
|
if (type === 'tag') return node.tags.some((tag) => testPattern(tag, pattern))
|
|
273
273
|
if (type === 'operationId') return testPattern(node.operationId, pattern)
|
|
274
|
-
if (type === 'path') return testPattern(node.path, pattern)
|
|
275
|
-
if (type === 'method') return testPattern(node.method.toLowerCase(), pattern)
|
|
274
|
+
if (type === 'path') return node.path !== undefined && testPattern(node.path, pattern)
|
|
275
|
+
if (type === 'method') return node.method !== undefined && testPattern(node.method.toLowerCase(), pattern)
|
|
276
276
|
if (type === 'contentType') return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false
|
|
277
277
|
return false
|
|
278
278
|
}
|