@kubb/core 5.0.0-beta.4 → 5.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#emitter","NodeEventEmitter","#options","#transformParam","#eachParam","Node","#head","#tail","#size","#limit"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/time.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/createAdapter.ts","../../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js","../../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js","../src/FileProcessor.ts","../src/createStorage.ts","../src/storages/fsStorage.ts","../package.json","../src/utils/diagnostics.ts","../src/utils/isInputPath.ts","../src/createKubb.ts","../src/createRenderer.ts","../src/defineGenerator.ts","../src/defineLogger.ts","../src/defineMiddleware.ts","../src/defineParser.ts","../src/definePlugin.ts","../src/storages/memoryStorage.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 async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\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","/**\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","import { existsSync, readFileSync } from 'node:fs'\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join, posix, resolve } from 'node:path'\n\n/**\n * Walks up the directory tree from `cwd` (defaults to `process.cwd()`) and\n * returns the absolute path of the nearest `package.json`, or `null` when none\n * is found before reaching the filesystem root.\n *\n * @example\n * ```ts\n * const pkgPath = findPackageJSON('/home/user/project/src') // '/home/user/project/package.json'\n * ```\n */\nexport function findPackageJSON(cwd?: string): string | null {\n let dir = cwd ? resolve(cwd) : process.cwd()\n while (true) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) return pkgPath\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\n/**\n * Converts all backslashes to forward slashes.\n * Extended-length Windows paths (`\\\\?\\...`) are left unchanged.\n */\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (typeof Bun !== 'undefined') {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (typeof Bun !== 'undefined') {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\n/**\n * Synchronous counterpart of `read`.\n *\n * @example\n * ```ts\n * const source = readSync('./src/Pet.ts')\n * ```\n */\nexport function readSync(path: string): string {\n return readFileSync(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Writes `data` to `path`, trimming leading/trailing whitespace before saving.\n * Skips the write when the trimmed content is empty or identical to what is already on disk.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns trimmed content\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const resolved = resolve(path)\n\n if (typeof Bun !== 'undefined') {\n const file = Bun.file(resolved)\n const oldContent = (await file.exists()) ? await file.text() : null\n if (oldContent === trimmed) return null\n await Bun.write(resolved, trimmed)\n return trimmed\n }\n\n try {\n const oldContent = await readFile(resolved, { encoding: 'utf-8' })\n if (oldContent === trimmed) return null\n } catch {\n /* file doesn't exist yet */\n }\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, trimmed, { encoding: 'utf-8' })\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== trimmed) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return trimmed\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\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\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 { Adapter, AdapterFactoryOptions } from './types.ts'\n\ntype AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>\n\n/**\n * Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.\n *\n * Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.\n * Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.\n *\n * @note Adapters must parse their input format to Kubb's `InputNode` structure.\n *\n * @example\n * ```ts\n * export const myAdapter = createAdapter<MyAdapter>((options) => {\n * return {\n * name: 'my-adapter',\n * options,\n * async parse(source) {\n * // Transform source format to InputNode\n * return { ... }\n * },\n * }\n * })\n *\n * // Instantiate:\n * const adapter = myAdapter({ validate: true })\n * ```\n */\nexport function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T> {\n return (options) => build(options ?? ({} as T['options']))\n}\n","/*\nHow it works:\n`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.\n*/\n\nclass Node {\n\tvalue;\n\tnext;\n\n\tconstructor(value) {\n\t\tthis.value = value;\n\t}\n}\n\nexport default class Queue {\n\t#head;\n\t#tail;\n\t#size;\n\n\tconstructor() {\n\t\tthis.clear();\n\t}\n\n\tenqueue(value) {\n\t\tconst node = new Node(value);\n\n\t\tif (this.#head) {\n\t\t\tthis.#tail.next = node;\n\t\t\tthis.#tail = node;\n\t\t} else {\n\t\t\tthis.#head = node;\n\t\t\tthis.#tail = node;\n\t\t}\n\n\t\tthis.#size++;\n\t}\n\n\tdequeue() {\n\t\tconst current = this.#head;\n\t\tif (!current) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#head = this.#head.next;\n\t\tthis.#size--;\n\n\t\t// Clean up tail reference when queue becomes empty\n\t\tif (!this.#head) {\n\t\t\tthis.#tail = undefined;\n\t\t}\n\n\t\treturn current.value;\n\t}\n\n\tpeek() {\n\t\tif (!this.#head) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#head.value;\n\n\t\t// TODO: Node.js 18.\n\t\t// return this.#head?.value;\n\t}\n\n\tclear() {\n\t\tthis.#head = undefined;\n\t\tthis.#tail = undefined;\n\t\tthis.#size = 0;\n\t}\n\n\tget size() {\n\t\treturn this.#size;\n\t}\n\n\t* [Symbol.iterator]() {\n\t\tlet current = this.#head;\n\n\t\twhile (current) {\n\t\t\tyield current.value;\n\t\t\tcurrent = current.next;\n\t\t}\n\t}\n\n\t* drain() {\n\t\twhile (this.#head) {\n\t\t\tyield this.dequeue();\n\t\t}\n\t}\n}\n","import Queue from 'yocto-queue';\n\nexport default function pLimit(concurrency) {\n\tlet rejectOnClear = false;\n\n\tif (typeof concurrency === 'object') {\n\t\t({concurrency, rejectOnClear = false} = concurrency);\n\t}\n\n\tvalidateConcurrency(concurrency);\n\n\tif (typeof rejectOnClear !== 'boolean') {\n\t\tthrow new TypeError('Expected `rejectOnClear` to be a boolean');\n\t}\n\n\tconst queue = new Queue();\n\tlet activeCount = 0;\n\n\tconst resumeNext = () => {\n\t\t// Process the next queued function if we're under the concurrency limit\n\t\tif (activeCount < concurrency && queue.size > 0) {\n\t\t\tactiveCount++;\n\t\t\tqueue.dequeue().run();\n\t\t}\n\t};\n\n\tconst next = () => {\n\t\tactiveCount--;\n\t\tresumeNext();\n\t};\n\n\tconst run = async (function_, resolve, arguments_) => {\n\t\t// Execute the function and capture the result promise\n\t\tconst result = (async () => function_(...arguments_))();\n\n\t\t// Resolve immediately with the promise (don't wait for completion)\n\t\tresolve(result);\n\n\t\t// Wait for the function to complete (success or failure)\n\t\t// We catch errors here to prevent unhandled rejections,\n\t\t// but the original promise rejection is preserved for the caller\n\t\ttry {\n\t\t\tawait result;\n\t\t} catch {}\n\n\t\t// Decrement active count and process next queued function\n\t\tnext();\n\t};\n\n\tconst enqueue = (function_, resolve, reject, arguments_) => {\n\t\tconst queueItem = {reject};\n\n\t\t// Queue the internal resolve function instead of the run function\n\t\t// to preserve the asynchronous execution context.\n\t\tnew Promise(internalResolve => { // eslint-disable-line promise/param-names\n\t\t\tqueueItem.run = internalResolve;\n\t\t\tqueue.enqueue(queueItem);\n\t\t}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then\n\n\t\t// Start processing immediately if we haven't reached the concurrency limit\n\t\tif (activeCount < concurrency) {\n\t\t\tresumeNext();\n\t\t}\n\t};\n\n\tconst generator = (function_, ...arguments_) => new Promise((resolve, reject) => {\n\t\tenqueue(function_, resolve, reject, arguments_);\n\t});\n\n\tObject.defineProperties(generator, {\n\t\tactiveCount: {\n\t\t\tget: () => activeCount,\n\t\t},\n\t\tpendingCount: {\n\t\t\tget: () => queue.size,\n\t\t},\n\t\tclearQueue: {\n\t\t\tvalue() {\n\t\t\t\tif (!rejectOnClear) {\n\t\t\t\t\tqueue.clear();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst abortError = AbortSignal.abort().reason;\n\n\t\t\t\twhile (queue.size > 0) {\n\t\t\t\t\tqueue.dequeue().reject(abortError);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tconcurrency: {\n\t\t\tget: () => concurrency,\n\n\t\t\tset(newConcurrency) {\n\t\t\t\tvalidateConcurrency(newConcurrency);\n\t\t\t\tconcurrency = newConcurrency;\n\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t// eslint-disable-next-line no-unmodified-loop-condition\n\t\t\t\t\twhile (activeCount < concurrency && queue.size > 0) {\n\t\t\t\t\t\tresumeNext();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tmap: {\n\t\t\tasync value(iterable, function_) {\n\t\t\t\tconst promises = Array.from(iterable, (value, index) => this(function_, value, index));\n\t\t\t\treturn Promise.all(promises);\n\t\t\t},\n\t\t},\n\t});\n\n\treturn generator;\n}\n\nexport function limitFunction(function_, options) {\n\tconst limit = pLimit(options);\n\n\treturn (...arguments_) => limit(() => function_(...arguments_));\n}\n\nfunction validateConcurrency(concurrency) {\n\tif (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {\n\t\tthrow new TypeError('Expected `concurrency` to be a number from 1 and up');\n\t}\n}\n","import type { CodeNode, FileNode } from '@kubb/ast'\nimport { extractStringsFromNodes } from '@kubb/ast'\nimport pLimit from 'p-limit'\nimport { PARALLEL_CONCURRENCY_LIMIT } from './constants.ts'\nimport type { Parser } from './defineParser.ts'\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n}\n\ntype RunOptions = ParseOptions & {\n /**\n * @default 'sequential'\n */\n mode?: 'sequential' | 'parallel'\n onStart?: (files: Array<FileNode>) => Promise<void> | void\n onEnd?: (files: Array<FileNode>) => Promise<void> | void\n onUpdate?: (params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }) => Promise<void> | void\n}\n\nfunction joinSources(file: FileNode): string {\n return file.sources\n .map((item) => extractStringsFromNodes(item.nodes as Array<CodeNode>))\n .filter(Boolean)\n .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 #limit = pLimit(PARALLEL_CONCURRENCY_LIMIT)\n\n async parse(file: FileNode, { parsers, extension }: ParseOptions = {}): Promise<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 async run(files: Array<FileNode>, { parsers, mode = 'sequential', extension, onStart, onEnd, onUpdate }: RunOptions = {}): Promise<Array<FileNode>> {\n await onStart?.(files)\n\n const total = files.length\n let processed = 0\n\n const processOne = async (file: FileNode) => {\n const source = await this.parse(file, { extension, parsers })\n const currentProcessed = ++processed\n const percentage = (currentProcessed / total) * 100\n\n await onUpdate?.({\n file,\n source,\n processed: currentProcessed,\n percentage,\n total,\n })\n }\n\n if (mode === 'sequential') {\n for (const file of files) {\n await processOne(file)\n }\n } else {\n await Promise.all(files.map((file) => this.#limit(() => processOne(file))))\n }\n\n await onEnd?.(files)\n\n return files\n }\n}\n","export type Storage = {\n /**\n * Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).\n */\n readonly name: string\n /**\n * Returns `true` when an entry for `key` exists in storage.\n */\n hasItem(key: string): Promise<boolean>\n /**\n * Returns the stored string value, or `null` when `key` does not exist.\n */\n getItem(key: string): Promise<string | null>\n /**\n * Persists `value` under `key`, creating any required structure.\n */\n setItem(key: string, value: string): Promise<void>\n /**\n * Removes the entry for `key`. No-ops when the key does not exist.\n */\n removeItem(key: string): Promise<void>\n /**\n * Returns all keys, optionally filtered to those starting with `base`.\n */\n getKeys(base?: string): Promise<Array<string>>\n /**\n * Removes all entries, optionally scoped to those starting with `base`.\n */\n clear(base?: string): Promise<void>\n /**\n * Optional teardown hook called after the build completes.\n */\n dispose?(): Promise<void>\n}\n\n/**\n * Factory for implementing custom storage backends that control where generated files are written.\n *\n * Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.\n * Kubb provides filesystem and in-memory implementations out of the box.\n *\n * @note Call the returned factory with optional options to instantiate the storage adapter.\n *\n * @example\n * ```ts\n * import { createStorage } from '@kubb/core'\n *\n * export const memoryStorage = createStorage(() => {\n * const store = new Map<string, string>()\n * return {\n * name: 'memory',\n * async hasItem(key) { return store.has(key) },\n * async getItem(key) { return store.get(key) ?? null },\n * async setItem(key, value) { store.set(key, value) },\n * async removeItem(key) { store.delete(key) },\n * async getKeys(base) {\n * const keys = [...store.keys()]\n * return base ? keys.filter((k) => k.startsWith(base)) : keys\n * },\n * async clear(base) { if (!base) store.clear() },\n * }\n * })\n *\n * // Instantiate:\n * const storage = memoryStorage()\n * ```\n */\nexport function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage {\n return (options) => build(options ?? ({} as TOptions))\n}\n","import type { Dirent } from 'node:fs'\nimport { access, readdir, readFile, rm } from 'node:fs/promises'\nimport { join, resolve } from 'node:path'\nimport { clean, write } from '@internals/utils'\nimport { createStorage } from '../createStorage.ts'\n\n/**\n * Detects the filesystem error used to indicate that a path does not exist.\n */\nfunction isMissingPathError(error: unknown): error is NodeJS.ErrnoException {\n return typeof error === 'object' && error !== null && 'code' in error && (error as NodeJS.ErrnoException).code === 'ENOENT'\n}\n\n/**\n * Built-in filesystem storage driver.\n *\n * This is the default storage when no `storage` option is configured in the root config.\n * Keys are resolved against `process.cwd()`, so root-relative paths such as\n * `src/gen/api/getPets.ts` are written to the correct location without extra configuration.\n *\n * Internally uses the `write` utility from `@internals/utils`, which:\n * - trims leading/trailing whitespace before writing\n * - skips the write when file content is already identical (deduplication)\n * - creates missing parent directories automatically\n * - supports Bun's native file API when running under Bun\n *\n * @example\n * ```ts\n * import { fsStorage } from '@kubb/core'\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * storage: fsStorage(),\n * })\n * ```\n */\nexport const fsStorage = createStorage(() => ({\n name: 'fs',\n async hasItem(key: string) {\n try {\n await access(resolve(key))\n return true\n } catch (error) {\n if (isMissingPathError(error)) {\n return false\n }\n\n throw new Error(`Failed to access storage item \"${key}\"`, {\n cause: error as Error,\n })\n }\n },\n async getItem(key: string) {\n try {\n return await readFile(resolve(key), 'utf8')\n } catch (error) {\n if (isMissingPathError(error)) {\n return null\n }\n\n throw new Error(`Failed to read storage item \"${key}\"`, {\n cause: error as Error,\n })\n }\n },\n async setItem(key: string, value: string) {\n await write(resolve(key), value, { sanity: false })\n },\n async removeItem(key: string) {\n await rm(resolve(key), { force: true })\n },\n async getKeys(base?: string) {\n const keys: Array<string> = []\n const resolvedBase = resolve(base ?? process.cwd())\n\n async function walk(dir: string, prefix: string): Promise<void> {\n let entries: Array<Dirent>\n try {\n entries = (await readdir(dir, {\n withFileTypes: true,\n })) as Array<Dirent>\n } catch (error) {\n if (isMissingPathError(error)) {\n return\n }\n\n throw new Error(`Failed to list storage keys under \"${resolvedBase}\"`, {\n cause: error as Error,\n })\n }\n for (const entry of entries) {\n const rel = prefix ? `${prefix}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n await walk(join(dir, entry.name), rel)\n } else {\n keys.push(rel)\n }\n }\n }\n\n await walk(resolvedBase, '')\n\n return keys\n },\n async clear(base?: string) {\n if (!base) {\n return\n }\n\n await clean(resolve(base))\n },\n}))\n","","import { version as nodeVersion } from 'node:process'\nimport { version as KubbVersion } from '../../package.json'\n\n/**\n * Returns a snapshot of the current runtime environment.\n *\n * Useful for attaching context to debug logs and error reports so that\n * issues can be reproduced without manual information gathering.\n */\nexport function getDiagnosticInfo() {\n return {\n nodeVersion,\n KubbVersion,\n platform: process.platform,\n arch: process.arch,\n cwd: process.cwd(),\n } as const\n}\n","import type { Config, InputPath, UserConfig } from '../types'\n\n/**\n * Type guard to check if a given config has an `input.path`.\n */\nexport function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> & { input: InputPath }\nexport function isInputPath(config: Config | undefined): config is Config<InputPath> & { input: InputPath }\nexport function isInputPath(config: Config | UserConfig | undefined): config is (Config<InputPath> | UserConfig<InputPath>) & { input: InputPath } {\n return typeof config?.input === 'object' && config.input !== null && 'path' in config.input\n}\n","import { resolve } from 'node:path'\nimport { AsyncEventEmitter, BuildError, exists, formatMs, getElapsedMs, URLPath } from '@internals/utils'\nimport type { FileNode, OperationNode } from '@kubb/ast'\nimport { collectUsedSchemaNames, transform, walk } from '@kubb/ast'\nimport { DEFAULT_BANNER, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { FileProcessor } from './FileProcessor.ts'\nimport type { Kubb } from './Kubb.ts'\nimport { PluginDriver } from './PluginDriver.ts'\nimport { applyHookResult } from './renderNode.ts'\nimport { fsStorage } from './storages/fsStorage.ts'\nimport type { AdapterSource, Config, GeneratorContext, KubbHooks, Middleware, NormalizedPlugin, Storage, UserConfig } from './types.ts'\nimport { getDiagnosticInfo } from './utils/diagnostics.ts'\nimport { isInputPath } from './utils/isInputPath.ts'\n\ntype SetupOptions = {\n hooks?: AsyncEventEmitter<KubbHooks>\n}\n\n/**\n * Full output produced by a successful or failed build.\n */\nexport type BuildOutput = {\n /**\n * Plugins that threw during installation, paired with the caught error.\n */\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n files: Array<FileNode>\n driver: PluginDriver\n /**\n * Elapsed time in milliseconds for each plugin, keyed by plugin name.\n */\n pluginTimings: Map<string, number>\n error?: Error\n /**\n * Raw generated source, keyed by absolute file path.\n */\n sources: Map<string, string>\n}\n\ntype SetupResult = {\n hooks: AsyncEventEmitter<KubbHooks>\n driver: PluginDriver\n sources: Map<string, string>\n config: Config\n storage: Storage | null\n}\n\nasync function setup(userConfig: UserConfig, options: SetupOptions = {}): Promise<SetupResult> {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\n\n const sources: Map<string, string> = new Map<string, string>()\n const diagnosticInfo = getDiagnosticInfo()\n\n if (Array.isArray(userConfig.input)) {\n await hooks.emit('kubb:warn', { message: 'This feature is still under development — use with caution' })\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n 'Configuration:',\n ` • Name: ${userConfig.name || 'unnamed'}`,\n ` • Root: ${userConfig.root || process.cwd()}`,\n ` • Output: ${userConfig.output?.path || 'not specified'}`,\n ` • Plugins: ${userConfig.plugins?.length || 0}`,\n 'Output Settings:',\n ` • Storage: ${userConfig.storage ? `custom(${userConfig.storage.name})` : userConfig.output?.write === false ? 'disabled' : 'filesystem (default)'}`,\n ` • Formatter: ${userConfig.output?.format || 'none'}`,\n ` • Linter: ${userConfig.output?.lint || 'none'}`,\n 'Environment:',\n Object.entries(diagnosticInfo)\n .map(([key, value]) => ` • ${key}: ${value}`)\n .join('\\n'),\n ],\n })\n\n try {\n if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {\n await exists(userConfig.input.path)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Input file validated: ${userConfig.input.path}`],\n })\n }\n } catch (caughtError) {\n if (isInputPath(userConfig)) {\n const error = caughtError as Error\n\n throw new Error(\n `Cannot read file/URL defined in \\`input.path\\` or set with \\`kubb generate PATH\\` in the CLI of your Kubb config ${userConfig.input.path}`,\n {\n cause: error,\n },\n )\n }\n }\n\n const config: Config = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n parsers: userConfig.parsers ?? [],\n adapter: userConfig.adapter,\n output: {\n format: false,\n lint: false,\n write: true,\n extension: DEFAULT_EXTENSION,\n defaultBanner: DEFAULT_BANNER,\n ...userConfig.output,\n },\n devtools: userConfig.devtools\n ? {\n studioUrl: DEFAULT_STUDIO_URL,\n ...(typeof userConfig.devtools === 'boolean' ? {} : userConfig.devtools),\n }\n : undefined,\n plugins: userConfig.plugins as unknown as Config['plugins'],\n }\n\n const storage: Storage | null = config.output.write === false ? null : (config.storage ?? fsStorage())\n\n if (config.output.clean) {\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: ['Cleaning output directories', ` • Output: ${config.output.path}`],\n })\n await storage?.clear(resolve(config.root, config.output.path))\n }\n\n const driver = new PluginDriver(config, {\n hooks,\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 function registerMiddlewareHook<K extends keyof KubbHooks & string>(event: K, middlewareHooks: Middleware['hooks']) {\n const handler = middlewareHooks[event]\n if (handler) {\n hooks.on(event, handler)\n }\n }\n\n for (const middleware of config.middleware ?? []) {\n for (const event of Object.keys(middleware.hooks) as Array<keyof KubbHooks & string>) {\n registerMiddlewareHook(event, middleware.hooks)\n }\n }\n\n if (config.adapter) {\n const source = inputToAdapterSource(config)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Running adapter: ${config.adapter.name}`],\n })\n\n driver.adapter = config.adapter\n driver.inputNode = await config.adapter.parse(source)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n `✓ Adapter '${config.adapter.name}' resolved InputNode`,\n ` • Schemas: ${driver.inputNode.schemas.length}`,\n ` • Operations: ${driver.inputNode.operations.length}`,\n ],\n })\n }\n\n return {\n config,\n hooks,\n driver,\n sources,\n storage,\n }\n}\n\n/**\n * Walks the AST and dispatches nodes to a plugin's direct AST hooks\n * (`schema`, `operation`, `operations`).\n *\n * When `include` contains only operation-scoped filters (`tag`, `operationId`, `path`,\n * `method`, `contentType`) and no `schemaName` filter, the function pre-computes the set\n * of top-level schema names transitively reachable from the included operations and skips\n * schemas that fall outside that set. This ensures that component schemas referenced\n * exclusively by excluded operations are not generated.\n */\nasync function runPluginAstHooks(plugin: NormalizedPlugin, context: GeneratorContext): Promise<void> {\n const { adapter, inputNode, resolver, driver } = context\n const { exclude, include, override } = plugin.options\n\n if (!adapter || !inputNode) {\n throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. pluginOas()) before this plugin in your Kubb config.`)\n }\n\n function resolveRenderer(gen: Generator): RendererFactory | undefined {\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin.renderer ?? context.config.renderer)\n }\n\n const generators = plugin.generators ?? []\n const collectedOperations: Array<OperationNode> = []\n\n const generatorContext = {\n ...context,\n resolver: driver.getResolver(plugin.name),\n }\n\n // When `include` has operation-based filters (tag, operationId, path, method, contentType)\n // but no schema-level filters (schemaName), pre-compute the set of top-level schema names\n // that are transitively referenced by the included operations. Schemas outside that set are\n // skipped so that types belonging exclusively to excluded operations are not generated.\n const operationFilterTypes = new Set(['tag', 'operationId', 'path', 'method', 'contentType'])\n const hasOperationBasedIncludes = include?.some(({ type }) => operationFilterTypes.has(type)) ?? false\n const hasSchemaNameIncludes = include?.some(({ type }) => type === 'schemaName') ?? false\n\n let allowedSchemaNames: Set<string> | undefined\n if (hasOperationBasedIncludes && !hasSchemaNameIncludes) {\n const includedOps = inputNode.operations.filter((op) => resolver.resolveOptions(op, { options: plugin.options, exclude, include, override }) !== null)\n allowedSchemaNames = collectUsedSchemaNames(includedOps, inputNode.schemas)\n }\n\n await walk(inputNode, {\n depth: 'shallow',\n async schema(node) {\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n\n // Skip named top-level schemas that are not reachable from any included operation.\n if (allowedSchemaNames !== undefined && transformedNode.name && !allowedSchemaNames.has(transformedNode.name)) {\n return\n }\n\n const options = resolver.resolveOptions(transformedNode, {\n options: plugin.options,\n exclude,\n include,\n override,\n })\n if (options === null) return\n\n const ctx = { ...generatorContext, options }\n\n for (const gen of generators) {\n if (!gen.schema) continue\n const result = await gen.schema(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:schema', transformedNode, ctx)\n },\n async operation(node) {\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = resolver.resolveOptions(transformedNode, {\n options: plugin.options,\n exclude,\n include,\n override,\n })\n if (options !== null) {\n collectedOperations.push(transformedNode)\n\n const ctx = { ...generatorContext, options }\n\n for (const gen of generators) {\n if (!gen.operation) continue\n const result = await gen.operation(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:operation', transformedNode, ctx)\n }\n },\n })\n\n if (collectedOperations.length > 0) {\n const ctx = { ...generatorContext, options: plugin.options }\n\n for (const gen of generators) {\n if (!gen.operations) continue\n const result = await gen.operations(collectedOperations, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:operations', collectedOperations, ctx)\n }\n}\n\nasync function safeBuild(setupResult: SetupResult): Promise<BuildOutput> {\n const { driver, hooks, sources, storage } = setupResult\n\n const failedPlugins = new Set<{ plugin: Plugin; error: Error }>()\n const pluginTimings = new Map<string, number>()\n const config = driver.config\n\n try {\n await driver.emitSetupHooks()\n\n if (driver.adapter && driver.inputNode) {\n await hooks.emit('kubb:build:start', {\n config,\n adapter: driver.adapter,\n inputNode: driver.inputNode,\n getPlugin: driver.getPlugin.bind(driver),\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n }\n\n for (const plugin of driver.plugins.values()) {\n const context = driver.getContext(plugin)\n const hrStart = process.hrtime()\n\n try {\n const timestamp = new Date()\n\n await hooks.emit('kubb:plugin:start', { plugin })\n\n await hooks.emit('kubb:debug', {\n date: timestamp,\n logs: ['Starting plugin...', ` • Plugin Name: ${plugin.name}`],\n })\n\n if (plugin.generators?.length || driver.hasRegisteredGenerators(plugin.name)) {\n await runPluginAstHooks(plugin, context)\n }\n\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\n\n await hooks.emit('kubb:plugin:end', {\n plugin,\n duration,\n success: true,\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Plugin started successfully (${formatMs(duration)})`],\n })\n } catch (caughtError) {\n const error = caughtError as Error\n const errorTimestamp = new Date()\n const duration = getElapsedMs(hrStart)\n\n await hooks.emit('kubb:plugin:end', {\n plugin,\n duration,\n success: false,\n error,\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n await hooks.emit('kubb:debug', {\n date: errorTimestamp,\n logs: [\n '✗ Plugin start failed',\n ` • Plugin Name: ${plugin.name}`,\n ` • Error: ${error.constructor.name} - ${error.message}`,\n ' • Stack Trace:',\n error.stack || 'No stack trace available',\n ],\n })\n\n failedPlugins.add({ plugin, error })\n }\n }\n\n await hooks.emit('kubb:plugins:end', {\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n const files = driver.fileManager.files\n\n const parsersMap = new Map<FileNode['extname'], Parser>()\n for (const parser of config.parsers) {\n if (parser.extNames) {\n for (const extname of parser.extNames) {\n parsersMap.set(extname, parser)\n }\n }\n }\n\n const fileProcessor = new FileProcessor()\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Writing ${files.length} files...`],\n })\n\n await fileProcessor.run(files, {\n parsers: parsersMap,\n extension: config.output.extension,\n onStart: async (processingFiles) => {\n await hooks.emit('kubb:files:processing:start', { files: processingFiles })\n },\n onUpdate: async ({ file, source, processed, total, percentage }) => {\n await hooks.emit('kubb:file:processing:update', {\n file,\n source,\n processed,\n total,\n percentage,\n config,\n })\n if (source) {\n await storage?.setItem(file.path, source)\n sources.set(file.path, source)\n }\n },\n onEnd: async (processedFiles) => {\n await hooks.emit('kubb:files:processing:end', { files: processedFiles })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ File write process completed for ${processedFiles.length} files`],\n })\n },\n })\n\n await hooks.emit('kubb:build:end', {\n files,\n config,\n outputDir: resolve(config.root, config.output.path),\n })\n\n return {\n failedPlugins,\n files,\n driver,\n pluginTimings,\n sources,\n }\n } catch (error) {\n return {\n failedPlugins,\n files: [],\n driver,\n pluginTimings,\n error: error as Error,\n sources,\n }\n } finally {\n driver.dispose()\n }\n}\n\nasync function build(setupResult: SetupResult): Promise<BuildOutput> {\n const { files, driver, failedPlugins, pluginTimings, error, sources } = await safeBuild(setupResult)\n\n if (error) {\n throw error\n }\n\n if (failedPlugins.size > 0) {\n const errors = [...failedPlugins].map(({ error }) => error)\n\n throw new BuildError(`Build Error with ${failedPlugins.size} failed plugins`, { errors })\n }\n\n return {\n failedPlugins,\n files,\n driver,\n pluginTimings,\n error: undefined,\n sources,\n }\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 (Array.isArray(input)) {\n return {\n type: 'paths',\n paths: input.map((i) => (new URLPath(i.path).isURL ? i.path : resolve(config.root, i.path))),\n }\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 return { type: 'path', path: resolved }\n}\n\ntype CreateKubbOptions = {\n hooks?: AsyncEventEmitter<KubbHooks>\n}\n\n/**\n * Creates a Kubb instance bound to a single config entry.\n *\n * Accepts a user-facing config shape and resolves it to a full {@link Config} during\n * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)\n * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before\n * calling `setup()` or `build()`.\n *\n * @example\n * ```ts\n * const kubb = createKubb(userConfig)\n *\n * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {\n * console.log(`${plugin.name} completed in ${duration}ms`)\n * })\n *\n * const { files, failedPlugins } = await kubb.safeBuild()\n * ```\n */\nexport function createKubb(userConfig: UserConfig, options: CreateKubbOptions = {}): Kubb {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\n let setupResult: SetupResult | undefined\n\n const instance: Kubb = {\n get hooks() {\n return hooks\n },\n get sources() {\n return setupResult?.sources ?? new Map()\n },\n get driver() {\n return setupResult?.driver\n },\n get config() {\n return setupResult?.config\n },\n async setup() {\n setupResult = await setup(userConfig, { hooks })\n },\n async build() {\n if (!setupResult) {\n await instance.setup()\n }\n return build(setupResult!)\n },\n async safeBuild() {\n if (!setupResult) {\n await instance.setup()\n }\n return safeBuild(setupResult!)\n },\n }\n\n return instance\n}\n","import type { FileNode } from '@kubb/ast'\n\n/**\n * Minimal interface any Kubb renderer must satisfy.\n *\n * The generic `TElement` is the type of the element the renderer accepts —\n * e.g. `KubbReactElement` for `@kubb/renderer-jsx`, or a custom type for\n * your own renderer. Defaults to `unknown` so that generators which do not\n * care about the element type continue to work without specifying it.\n *\n * This allows core to drive rendering without a hard dependency on\n * `@kubb/renderer-jsx` or any specific renderer implementation.\n */\nexport type Renderer<TElement = unknown> = {\n render(element: TElement): Promise<void>\n unmount(error?: Error | number | null): void\n readonly files: Array<FileNode>\n}\n\n/**\n * A factory function that produces a fresh {@link Renderer} per render.\n *\n * Generators use this to declare which renderer handles their output.\n */\nexport type RendererFactory<TElement = unknown> = () => Renderer<TElement>\n\n/**\n * Creates a renderer factory for use in generator definitions.\n *\n * Wrap your renderer factory function with this helper to register it as the\n * renderer for a generator. Core will call this factory once per render cycle\n * to obtain a fresh renderer instance.\n *\n * @example\n * ```ts\n * // packages/renderer-jsx/src/index.ts\n * export const jsxRenderer = createRenderer(() => {\n * const runtime = new Runtime()\n * return {\n * async render(element) { await runtime.render(element) },\n * get files() { return runtime.nodes },\n * unmount(error) { runtime.unmount(error) },\n * }\n * })\n *\n * // packages/plugin-zod/src/generators/zodGenerator.tsx\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n * export const zodGenerator = defineGenerator<PluginZod>({\n * name: 'zod',\n * renderer: jsxRenderer,\n * schema(node, options) { return <File ...>...</File> },\n * })\n * ```\n */\nexport function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement> {\n return factory\n}\n","import type { PossiblePromise } from '@internals/utils'\nimport type { FileNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { GeneratorContext, PluginFactoryOptions } from './types.ts'\n\nexport type { GeneratorContext } from './types.ts'\n\n/**\n * Declares a named generator unit that walks the AST and emits files.\n *\n * Each method (`schema`, `operation`, `operations`) is called for the matching node type.\n * Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.\n * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.\n *\n * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.\n *\n * @example\n * ```ts\n * import { defineGenerator } from '@kubb/core'\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n *\n * export const typeGenerator = defineGenerator({\n * name: 'typescript',\n * renderer: jsxRenderer,\n * schema(node, ctx) {\n * const { adapter, resolver, root, options } = ctx\n * return <File ...><Type node={node} resolver={resolver} /></File>\n * },\n * })\n * ```\n */\nexport type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {\n /**\n * Used in diagnostic messages and debug output.\n */\n name: string\n /**\n * Optional renderer factory that produces a {@link Renderer} for each render cycle.\n *\n * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this\n * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).\n *\n * Generators that only return `Array<FileNode>` or `void` do not need to set this.\n *\n * Set `renderer: null` to explicitly opt out of rendering even when the parent plugin\n * declares a `renderer` (overrides the plugin-level fallback).\n *\n * @example\n * ```ts\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n * export const myGenerator = defineGenerator<PluginTs>({\n * renderer: jsxRenderer,\n * schema(node, ctx) { return <File ...>...</File> },\n * })\n * ```\n */\n renderer?: RendererFactory<TElement> | null\n /**\n * Called for each schema node in the AST walk.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the per-node resolved options (after exclude/include/override).\n */\n schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n /**\n * Called for each operation node in the AST walk.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the per-node resolved options (after exclude/include/override).\n */\n operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n /**\n * Called once after all operations have been walked.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the plugin-level options for the batch call.\n */\n operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n}\n\n/**\n * Defines a generator. Returns the object as-is with correct `this` typings.\n * `applyHookResult` handles renderer elements and `File[]` uniformly using\n * the generator's declared `renderer` factory.\n */\nexport function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(\n generator: Generator<TOptions, TElement>,\n): Generator<TOptions, TElement> {\n return generator\n}\n","import type { Logger, LoggerOptions, UserLogger } from './types.ts'\n\n/**\n * Wraps a logger definition into a typed {@link Logger}.\n *\n * @example\n * ```ts\n * export const myLogger = defineLogger({\n * name: 'my-logger',\n * install(context, options) {\n * context.on('kubb:info', (message) => console.log('ℹ', message))\n * context.on('kubb:error', (error) => console.error('✗', error.message))\n * },\n * })\n * ```\n */\nexport function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options> {\n return logger\n}\n","import type { KubbHooks } from './Kubb.ts'\n\n/**\n * A middleware instance produced by calling a factory created with `defineMiddleware`.\n * It declares event handlers under a `hooks` object which are registered on the\n * shared emitter after all plugin hooks, so middleware handlers for any event\n * always fire last.\n */\nexport type Middleware = {\n /**\n * Unique identifier for this middleware.\n */\n name: string\n /**\n * Lifecycle event handlers for this middleware.\n * Any event from the global `KubbHooks` map can be subscribed to here.\n * Handlers are registered after all plugin handlers, so they always fire last.\n */\n hooks: {\n [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void>\n }\n}\n\n/**\n * Creates a middleware factory using the hook-style `hooks` API.\n *\n * Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.\n * Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.\n *\n * @note The factory can accept typed options. See examples for using options and per-build state patterns.\n *\n * @example\n * ```ts\n * import { defineMiddleware } from '@kubb/core'\n *\n * // Stateless middleware\n * export const logMiddleware = defineMiddleware(() => ({\n * name: 'log-middleware',\n * hooks: {\n * 'kubb:build:end'({ files }) {\n * console.log(`Build complete with ${files.length} files`)\n * },\n * },\n * }))\n *\n * // Middleware with options and per-build state\n * export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {\n * const seen = new Set<string>()\n * return {\n * name: 'prefix-middleware',\n * hooks: {\n * 'kubb:plugin:end'({ plugin }) {\n * seen.add(`${options.prefix}${plugin.name}`)\n * },\n * },\n * }\n * })\n * ```\n */\nexport function defineMiddleware<TOptions extends object = object>(factory: (options: TOptions) => Middleware): (options?: TOptions) => Middleware {\n return (options) => factory(options ?? ({} as TOptions))\n}\n","import type { FileNode } from '@kubb/ast'\n\ntype PrintOptions = {\n extname?: FileNode['extname']\n}\n\nexport type Parser<TMeta extends object = any> = {\n name: string\n /**\n * File extensions this parser handles.\n * Use `undefined` to create a catch-all fallback parser.\n *\n * @example Handled extensions\n * `['.ts', '.js']`\n */\n extNames: Array<FileNode['extname']> | undefined\n /**\n * Convert a resolved file to a string.\n */\n parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string\n}\n\n/**\n * Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.\n *\n * @note Call the returned factory with optional options to instantiate the parser.\n *\n * @example\n * ```ts\n * import { defineParser } from '@kubb/core'\n *\n * export const jsonParser = defineParser({\n * name: 'json',\n * extNames: ['.json'],\n * parse(file) {\n * const { extractStringsFromNodes } = await import('@kubb/ast')\n * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\\n')\n * },\n * })\n * ```\n */\nexport function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta> {\n return parser\n}\n","import type { KubbHooks } from './Kubb.ts'\nimport type { KubbPluginSetupContext, PluginFactoryOptions } from './types.ts'\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 Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void>\n } & {\n 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>\n }\n}\n\n/**\n * Returns `true` when `plugin` is a hook-style plugin created with `definePlugin`.\n *\n * Used by `PluginDriver` to distinguish hook-style plugins from legacy `createPlugin` plugins\n * so it can normalize them and register their handlers on the `AsyncEventEmitter`.\n */\nexport function isPlugin(plugin: unknown): plugin is Plugin {\n return typeof plugin === 'object' && plugin !== null && 'hooks' in plugin\n}\n\n/**\n * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.\n *\n * Handlers live in a single `hooks` object (inspired by Astro integrations).\n * All lifecycle events from `KubbHooks` are available for subscription.\n *\n * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.\n * Plugin names should follow the convention `plugin-<feature>` (e.g., `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","import { createStorage } from '../createStorage.ts'\n\n/**\n * In-memory storage driver. Useful for testing and dry-run scenarios where\n * generated output should be captured without touching the filesystem.\n *\n * All data lives in a `Map` scoped to the storage instance and is discarded\n * when the instance is garbage-collected.\n *\n * @example\n * ```ts\n * import { memoryStorage } from '@kubb/core'\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * storage: memoryStorage(),\n * })\n * ```\n */\nexport const memoryStorage = createStorage(() => {\n const store = new Map<string, string>()\n\n return {\n name: 'memory',\n async hasItem(key: string) {\n return store.has(key)\n },\n async getItem(key: string) {\n return store.get(key) ?? null\n },\n async setItem(key: string, value: string) {\n store.set(key, value)\n },\n async removeItem(key: string) {\n store.delete(key)\n },\n async getKeys(base?: string) {\n const keys = [...store.keys()]\n return base ? keys.filter((k) => k.startsWith(base)) : keys\n },\n async clear(base?: string) {\n if (!base) {\n store.clear()\n return\n }\n for (const key of store.keys()) {\n if (key.startsWith(base)) {\n store.delete(key)\n }\n }\n },\n }\n})\n"],"x_google_ignoreList":[7,8],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YAAY,SAAiB,SAAkD;AAC7E,QAAM,SAAS,EAAE,OAAO,QAAQ,OAAO,CAAC;AACxC,OAAK,OAAO;AACZ,OAAK,SAAS,QAAQ;;;;;;;;;;;;;;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B,QAAO;;;;;;;;;;;;;;;;;;ACrET,SAAgB,aAA4D,QAA8C;AACxH,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC0CT,SAAgB,iBAAmD,SAAgF;AACjJ,SAAQ,YAAY,QAAQ,WAAY,EAAE,CAAc;;;;;;;;;;;;;;;;;;;;;;;ACnB1D,SAAgB,aAAyC,QAAsC;AAC7F,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoCT,SAAgB,aACd,SACqD;AACrD,SAAQ,YAAY,QAAQ,WAAY,EAAE,CAAyB;;;;;;;;;;;;;;;;;;;;;;;AC5DrE,MAAa,gBAAgB,oBAAoB;CAC/C,MAAM,wBAAQ,IAAI,KAAqB;AAEvC,QAAO;EACL,MAAM;EACN,MAAM,QAAQ,KAAa;AACzB,UAAO,MAAM,IAAI,IAAI;;EAEvB,MAAM,QAAQ,KAAa;AACzB,UAAO,MAAM,IAAI,IAAI,IAAI;;EAE3B,MAAM,QAAQ,KAAa,OAAe;AACxC,SAAM,IAAI,KAAK,MAAM;;EAEvB,MAAM,WAAW,KAAa;AAC5B,SAAM,OAAO,IAAI;;EAEnB,MAAM,QAAQ,MAAe;GAC3B,MAAM,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;AAC9B,UAAO,OAAO,KAAK,QAAQ,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG;;EAEzD,MAAM,MAAM,MAAe;AACzB,OAAI,CAAC,MAAM;AACT,UAAM,OAAO;AACb;;AAEF,QAAK,MAAM,OAAO,MAAM,MAAM,CAC5B,KAAI,IAAI,WAAW,KAAK,CACtB,OAAM,OAAO,IAAI;;EAIxB;EACD"}
1
+ {"version":3,"file":"index.js","names":["#emitter","NodeEventEmitter","#options","#transformParam","#eachParam","Node","#head","#tail","#size","#limit"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../../../internals/utils/src/time.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/createAdapter.ts","../../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js","../../../node_modules/.pnpm/p-limit@7.3.0/node_modules/p-limit/index.js","../src/FileProcessor.ts","../src/createStorage.ts","../src/storages/fsStorage.ts","../package.json","../src/utils/diagnostics.ts","../src/utils/isInputPath.ts","../src/createKubb.ts","../src/createRenderer.ts","../src/defineGenerator.ts","../src/defineLogger.ts","../src/defineMiddleware.ts","../src/defineParser.ts","../src/definePlugin.ts","../src/storages/memoryStorage.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 async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\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","/**\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","import { existsSync, readFileSync } from 'node:fs'\nimport { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join, posix, resolve } from 'node:path'\n\n/**\n * Walks up the directory tree from `cwd` (defaults to `process.cwd()`) and\n * returns the absolute path of the nearest `package.json`, or `null` when none\n * is found before reaching the filesystem root.\n *\n * @example\n * ```ts\n * const pkgPath = findPackageJSON('/home/user/project/src') // '/home/user/project/package.json'\n * ```\n */\nexport function findPackageJSON(cwd?: string): string | null {\n let dir = cwd ? resolve(cwd) : process.cwd()\n while (true) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) return pkgPath\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\n/**\n * Converts all backslashes to forward slashes.\n * Extended-length Windows paths (`\\\\?\\...`) are left unchanged.\n */\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (typeof Bun !== 'undefined') {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (typeof Bun !== 'undefined') {\n return Bun.file(path).text()\n }\n return readFile(path, { encoding: 'utf8' })\n}\n\n/**\n * Synchronous counterpart of `read`.\n *\n * @example\n * ```ts\n * const source = readSync('./src/Pet.ts')\n * ```\n */\nexport function readSync(path: string): string {\n return readFileSync(path, { encoding: 'utf8' })\n}\n\ntype WriteOptions = {\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Writes `data` to `path`, trimming leading/trailing whitespace before saving.\n * Skips the write when the trimmed content is empty or identical to what is already on disk.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns trimmed content\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const resolved = resolve(path)\n\n if (typeof Bun !== 'undefined') {\n const file = Bun.file(resolved)\n const oldContent = (await file.exists()) ? await file.text() : null\n if (oldContent === trimmed) return null\n await Bun.write(resolved, trimmed)\n return trimmed\n }\n\n try {\n const oldContent = await readFile(resolved, { encoding: 'utf-8' })\n if (oldContent === trimmed) return null\n } catch {\n /* file doesn't exist yet */\n }\n\n await mkdir(dirname(resolved), { recursive: true })\n await writeFile(resolved, trimmed, { encoding: 'utf-8' })\n\n if (options.sanity) {\n const savedData = await readFile(resolved, { encoding: 'utf-8' })\n if (savedData !== trimmed) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return trimmed\n}\n\n/**\n * Recursively removes `path`. Silently succeeds when `path` does not exist.\n *\n * @example\n * ```ts\n * await clean('./dist')\n * ```\n */\nexport async function clean(path: string): Promise<void> {\n return rm(path, { recursive: true, force: true })\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\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 { Adapter, AdapterFactoryOptions } from './types.ts'\n\ntype AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>\n\n/**\n * Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.\n *\n * Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.\n * Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.\n *\n * @note Adapters must parse their input format to Kubb's `InputNode` structure.\n *\n * @example\n * ```ts\n * export const myAdapter = createAdapter<MyAdapter>((options) => {\n * return {\n * name: 'my-adapter',\n * options,\n * async parse(source) {\n * // Transform source format to InputNode\n * return { ... }\n * },\n * }\n * })\n *\n * // Instantiate:\n * const adapter = myAdapter({ validate: true })\n * ```\n */\nexport function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T> {\n return (options) => build(options ?? ({} as T['options']))\n}\n","/*\nHow it works:\n`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.\n*/\n\nclass Node {\n\tvalue;\n\tnext;\n\n\tconstructor(value) {\n\t\tthis.value = value;\n\t}\n}\n\nexport default class Queue {\n\t#head;\n\t#tail;\n\t#size;\n\n\tconstructor() {\n\t\tthis.clear();\n\t}\n\n\tenqueue(value) {\n\t\tconst node = new Node(value);\n\n\t\tif (this.#head) {\n\t\t\tthis.#tail.next = node;\n\t\t\tthis.#tail = node;\n\t\t} else {\n\t\t\tthis.#head = node;\n\t\t\tthis.#tail = node;\n\t\t}\n\n\t\tthis.#size++;\n\t}\n\n\tdequeue() {\n\t\tconst current = this.#head;\n\t\tif (!current) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#head = this.#head.next;\n\t\tthis.#size--;\n\n\t\t// Clean up tail reference when queue becomes empty\n\t\tif (!this.#head) {\n\t\t\tthis.#tail = undefined;\n\t\t}\n\n\t\treturn current.value;\n\t}\n\n\tpeek() {\n\t\tif (!this.#head) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn this.#head.value;\n\n\t\t// TODO: Node.js 18.\n\t\t// return this.#head?.value;\n\t}\n\n\tclear() {\n\t\tthis.#head = undefined;\n\t\tthis.#tail = undefined;\n\t\tthis.#size = 0;\n\t}\n\n\tget size() {\n\t\treturn this.#size;\n\t}\n\n\t* [Symbol.iterator]() {\n\t\tlet current = this.#head;\n\n\t\twhile (current) {\n\t\t\tyield current.value;\n\t\t\tcurrent = current.next;\n\t\t}\n\t}\n\n\t* drain() {\n\t\twhile (this.#head) {\n\t\t\tyield this.dequeue();\n\t\t}\n\t}\n}\n","import Queue from 'yocto-queue';\n\nexport default function pLimit(concurrency) {\n\tlet rejectOnClear = false;\n\n\tif (typeof concurrency === 'object') {\n\t\t({concurrency, rejectOnClear = false} = concurrency);\n\t}\n\n\tvalidateConcurrency(concurrency);\n\n\tif (typeof rejectOnClear !== 'boolean') {\n\t\tthrow new TypeError('Expected `rejectOnClear` to be a boolean');\n\t}\n\n\tconst queue = new Queue();\n\tlet activeCount = 0;\n\n\tconst resumeNext = () => {\n\t\t// Process the next queued function if we're under the concurrency limit\n\t\tif (activeCount < concurrency && queue.size > 0) {\n\t\t\tactiveCount++;\n\t\t\tqueue.dequeue().run();\n\t\t}\n\t};\n\n\tconst next = () => {\n\t\tactiveCount--;\n\t\tresumeNext();\n\t};\n\n\tconst run = async (function_, resolve, arguments_) => {\n\t\t// Execute the function and capture the result promise\n\t\tconst result = (async () => function_(...arguments_))();\n\n\t\t// Resolve immediately with the promise (don't wait for completion)\n\t\tresolve(result);\n\n\t\t// Wait for the function to complete (success or failure)\n\t\t// We catch errors here to prevent unhandled rejections,\n\t\t// but the original promise rejection is preserved for the caller\n\t\ttry {\n\t\t\tawait result;\n\t\t} catch {}\n\n\t\t// Decrement active count and process next queued function\n\t\tnext();\n\t};\n\n\tconst enqueue = (function_, resolve, reject, arguments_) => {\n\t\tconst queueItem = {reject};\n\n\t\t// Queue the internal resolve function instead of the run function\n\t\t// to preserve the asynchronous execution context.\n\t\tnew Promise(internalResolve => { // eslint-disable-line promise/param-names\n\t\t\tqueueItem.run = internalResolve;\n\t\t\tqueue.enqueue(queueItem);\n\t\t}).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then\n\n\t\t// Start processing immediately if we haven't reached the concurrency limit\n\t\tif (activeCount < concurrency) {\n\t\t\tresumeNext();\n\t\t}\n\t};\n\n\tconst generator = (function_, ...arguments_) => new Promise((resolve, reject) => {\n\t\tenqueue(function_, resolve, reject, arguments_);\n\t});\n\n\tObject.defineProperties(generator, {\n\t\tactiveCount: {\n\t\t\tget: () => activeCount,\n\t\t},\n\t\tpendingCount: {\n\t\t\tget: () => queue.size,\n\t\t},\n\t\tclearQueue: {\n\t\t\tvalue() {\n\t\t\t\tif (!rejectOnClear) {\n\t\t\t\t\tqueue.clear();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst abortError = AbortSignal.abort().reason;\n\n\t\t\t\twhile (queue.size > 0) {\n\t\t\t\t\tqueue.dequeue().reject(abortError);\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tconcurrency: {\n\t\t\tget: () => concurrency,\n\n\t\t\tset(newConcurrency) {\n\t\t\t\tvalidateConcurrency(newConcurrency);\n\t\t\t\tconcurrency = newConcurrency;\n\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t// eslint-disable-next-line no-unmodified-loop-condition\n\t\t\t\t\twhile (activeCount < concurrency && queue.size > 0) {\n\t\t\t\t\t\tresumeNext();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t\tmap: {\n\t\t\tasync value(iterable, function_) {\n\t\t\t\tconst promises = Array.from(iterable, (value, index) => this(function_, value, index));\n\t\t\t\treturn Promise.all(promises);\n\t\t\t},\n\t\t},\n\t});\n\n\treturn generator;\n}\n\nexport function limitFunction(function_, options) {\n\tconst limit = pLimit(options);\n\n\treturn (...arguments_) => limit(() => function_(...arguments_));\n}\n\nfunction validateConcurrency(concurrency) {\n\tif (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {\n\t\tthrow new TypeError('Expected `concurrency` to be a number from 1 and up');\n\t}\n}\n","import type { CodeNode, FileNode } from '@kubb/ast'\nimport { extractStringsFromNodes } from '@kubb/ast'\nimport pLimit from 'p-limit'\nimport { PARALLEL_CONCURRENCY_LIMIT } from './constants.ts'\nimport type { Parser } from './defineParser.ts'\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n}\n\ntype RunOptions = ParseOptions & {\n /**\n * @default 'sequential'\n */\n mode?: 'sequential' | 'parallel'\n onStart?: (files: Array<FileNode>) => Promise<void> | void\n onEnd?: (files: Array<FileNode>) => Promise<void> | void\n onUpdate?: (params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }) => Promise<void> | void\n}\n\nfunction joinSources(file: FileNode): string {\n return file.sources\n .map((item) => extractStringsFromNodes(item.nodes as Array<CodeNode>))\n .filter(Boolean)\n .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 #limit = pLimit(PARALLEL_CONCURRENCY_LIMIT)\n\n async parse(file: FileNode, { parsers, extension }: ParseOptions = {}): Promise<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 async run(files: Array<FileNode>, { parsers, mode = 'sequential', extension, onStart, onEnd, onUpdate }: RunOptions = {}): Promise<Array<FileNode>> {\n await onStart?.(files)\n\n const total = files.length\n let processed = 0\n\n const processOne = async (file: FileNode) => {\n const source = await this.parse(file, { extension, parsers })\n const currentProcessed = ++processed\n const percentage = (currentProcessed / total) * 100\n\n await onUpdate?.({\n file,\n source,\n processed: currentProcessed,\n percentage,\n total,\n })\n }\n\n if (mode === 'sequential') {\n for (const file of files) {\n await processOne(file)\n }\n } else {\n await Promise.all(files.map((file) => this.#limit(() => processOne(file))))\n }\n\n await onEnd?.(files)\n\n return files\n }\n}\n","export type Storage = {\n /**\n * Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).\n */\n readonly name: string\n /**\n * Returns `true` when an entry for `key` exists in storage.\n */\n hasItem(key: string): Promise<boolean>\n /**\n * Returns the stored string value, or `null` when `key` does not exist.\n */\n getItem(key: string): Promise<string | null>\n /**\n * Persists `value` under `key`, creating any required structure.\n */\n setItem(key: string, value: string): Promise<void>\n /**\n * Removes the entry for `key`. No-ops when the key does not exist.\n */\n removeItem(key: string): Promise<void>\n /**\n * Returns all keys, optionally filtered to those starting with `base`.\n */\n getKeys(base?: string): Promise<Array<string>>\n /**\n * Removes all entries, optionally scoped to those starting with `base`.\n */\n clear(base?: string): Promise<void>\n /**\n * Optional teardown hook called after the build completes.\n */\n dispose?(): Promise<void>\n}\n\n/**\n * Factory for implementing custom storage backends that control where generated files are written.\n *\n * Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.\n * Kubb provides filesystem and in-memory implementations out of the box.\n *\n * @note Call the returned factory with optional options to instantiate the storage adapter.\n *\n * @example\n * ```ts\n * import { createStorage } from '@kubb/core'\n *\n * export const memoryStorage = createStorage(() => {\n * const store = new Map<string, string>()\n * return {\n * name: 'memory',\n * async hasItem(key) { return store.has(key) },\n * async getItem(key) { return store.get(key) ?? null },\n * async setItem(key, value) { store.set(key, value) },\n * async removeItem(key) { store.delete(key) },\n * async getKeys(base) {\n * const keys = [...store.keys()]\n * return base ? keys.filter((k) => k.startsWith(base)) : keys\n * },\n * async clear(base) { if (!base) store.clear() },\n * }\n * })\n *\n * // Instantiate:\n * const storage = memoryStorage()\n * ```\n */\nexport function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage {\n return (options) => build(options ?? ({} as TOptions))\n}\n","import type { Dirent } from 'node:fs'\nimport { access, readdir, readFile, rm } from 'node:fs/promises'\nimport { join, resolve } from 'node:path'\nimport { clean, write } from '@internals/utils'\nimport { createStorage } from '../createStorage.ts'\n\n/**\n * Detects the filesystem error used to indicate that a path does not exist.\n */\nfunction isMissingPathError(error: unknown): error is NodeJS.ErrnoException {\n return typeof error === 'object' && error !== null && 'code' in error && (error as NodeJS.ErrnoException).code === 'ENOENT'\n}\n\n/**\n * Built-in filesystem storage driver.\n *\n * This is the default storage when no `storage` option is configured in the root config.\n * Keys are resolved against `process.cwd()`, so root-relative paths such as\n * `src/gen/api/getPets.ts` are written to the correct location without extra configuration.\n *\n * Internally uses the `write` utility from `@internals/utils`, which:\n * - trims leading/trailing whitespace before writing\n * - skips the write when file content is already identical (deduplication)\n * - creates missing parent directories automatically\n * - supports Bun's native file API when running under Bun\n *\n * @example\n * ```ts\n * import { fsStorage } from '@kubb/core'\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * storage: fsStorage(),\n * })\n * ```\n */\nexport const fsStorage = createStorage(() => ({\n name: 'fs',\n async hasItem(key: string) {\n try {\n await access(resolve(key))\n return true\n } catch (error) {\n if (isMissingPathError(error)) {\n return false\n }\n\n throw new Error(`Failed to access storage item \"${key}\"`, {\n cause: error as Error,\n })\n }\n },\n async getItem(key: string) {\n try {\n return await readFile(resolve(key), 'utf8')\n } catch (error) {\n if (isMissingPathError(error)) {\n return null\n }\n\n throw new Error(`Failed to read storage item \"${key}\"`, {\n cause: error as Error,\n })\n }\n },\n async setItem(key: string, value: string) {\n await write(resolve(key), value, { sanity: false })\n },\n async removeItem(key: string) {\n await rm(resolve(key), { force: true })\n },\n async getKeys(base?: string) {\n const keys: Array<string> = []\n const resolvedBase = resolve(base ?? process.cwd())\n\n async function walk(dir: string, prefix: string): Promise<void> {\n let entries: Array<Dirent>\n try {\n entries = (await readdir(dir, {\n withFileTypes: true,\n })) as Array<Dirent>\n } catch (error) {\n if (isMissingPathError(error)) {\n return\n }\n\n throw new Error(`Failed to list storage keys under \"${resolvedBase}\"`, {\n cause: error as Error,\n })\n }\n for (const entry of entries) {\n const rel = prefix ? `${prefix}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n await walk(join(dir, entry.name), rel)\n } else {\n keys.push(rel)\n }\n }\n }\n\n await walk(resolvedBase, '')\n\n return keys\n },\n async clear(base?: string) {\n if (!base) {\n return\n }\n\n await clean(resolve(base))\n },\n}))\n","","import { version as nodeVersion } from 'node:process'\nimport { version as KubbVersion } from '../../package.json'\n\n/**\n * Returns a snapshot of the current runtime environment.\n *\n * Useful for attaching context to debug logs and error reports so that\n * issues can be reproduced without manual information gathering.\n */\nexport function getDiagnosticInfo() {\n return {\n nodeVersion,\n KubbVersion,\n platform: process.platform,\n arch: process.arch,\n cwd: process.cwd(),\n } as const\n}\n","import type { Config, InputPath, UserConfig } from '../types'\n\n/**\n * Type guard to check if a given config has an `input.path`.\n */\nexport function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> & { input: InputPath }\nexport function isInputPath(config: Config | undefined): config is Config<InputPath> & { input: InputPath }\nexport function isInputPath(config: Config | UserConfig | undefined): config is (Config<InputPath> | UserConfig<InputPath>) & { input: InputPath } {\n return typeof config?.input === 'object' && config.input !== null && 'path' in config.input\n}\n","import { resolve } from 'node:path'\nimport { AsyncEventEmitter, BuildError, exists, formatMs, getElapsedMs, URLPath } from '@internals/utils'\nimport type { FileNode, OperationNode } from '@kubb/ast'\nimport { collectUsedSchemaNames, transform, walk } from '@kubb/ast'\nimport { DEFAULT_BANNER, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { FileProcessor } from './FileProcessor.ts'\nimport type { Kubb } from './Kubb.ts'\nimport { PluginDriver } from './PluginDriver.ts'\nimport { applyHookResult } from './renderNode.ts'\nimport { fsStorage } from './storages/fsStorage.ts'\nimport type { AdapterSource, Config, GeneratorContext, KubbHooks, Middleware, NormalizedPlugin, Storage, UserConfig } from './types.ts'\nimport { getDiagnosticInfo } from './utils/diagnostics.ts'\nimport { isInputPath } from './utils/isInputPath.ts'\n\ntype SetupOptions = {\n hooks?: AsyncEventEmitter<KubbHooks>\n}\n\n/**\n * Full output produced by a successful or failed build.\n */\nexport type BuildOutput = {\n /**\n * Plugins that threw during installation, paired with the caught error.\n */\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n files: Array<FileNode>\n driver: PluginDriver\n /**\n * Elapsed time in milliseconds for each plugin, keyed by plugin name.\n */\n pluginTimings: Map<string, number>\n error?: Error\n /**\n * Raw generated source, keyed by absolute file path.\n */\n sources: Map<string, string>\n}\n\ntype SetupResult = {\n hooks: AsyncEventEmitter<KubbHooks>\n driver: PluginDriver\n sources: Map<string, string>\n config: Config\n storage: Storage | null\n}\n\nasync function setup(userConfig: UserConfig, options: SetupOptions = {}): Promise<SetupResult> {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\n\n const sources: Map<string, string> = new Map<string, string>()\n const diagnosticInfo = getDiagnosticInfo()\n\n if (Array.isArray(userConfig.input)) {\n await hooks.emit('kubb:warn', { message: 'This feature is still under development — use with caution' })\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n 'Configuration:',\n ` • Name: ${userConfig.name || 'unnamed'}`,\n ` • Root: ${userConfig.root || process.cwd()}`,\n ` • Output: ${userConfig.output?.path || 'not specified'}`,\n ` • Plugins: ${userConfig.plugins?.length || 0}`,\n 'Output Settings:',\n ` • Storage: ${userConfig.storage ? `custom(${userConfig.storage.name})` : userConfig.output?.write === false ? 'disabled' : 'filesystem (default)'}`,\n ` • Formatter: ${userConfig.output?.format || 'none'}`,\n ` • Linter: ${userConfig.output?.lint || 'none'}`,\n 'Environment:',\n Object.entries(diagnosticInfo)\n .map(([key, value]) => ` • ${key}: ${value}`)\n .join('\\n'),\n ],\n })\n\n try {\n if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {\n await exists(userConfig.input.path)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Input file validated: ${userConfig.input.path}`],\n })\n }\n } catch (caughtError) {\n if (isInputPath(userConfig)) {\n const error = caughtError as Error\n\n throw new Error(\n `Cannot read file/URL defined in \\`input.path\\` or set with \\`kubb generate PATH\\` in the CLI of your Kubb config ${userConfig.input.path}`,\n {\n cause: error,\n },\n )\n }\n }\n\n const config: Config = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n parsers: userConfig.parsers ?? [],\n adapter: userConfig.adapter,\n output: {\n format: false,\n lint: false,\n write: true,\n extension: DEFAULT_EXTENSION,\n defaultBanner: DEFAULT_BANNER,\n ...userConfig.output,\n },\n devtools: userConfig.devtools\n ? {\n studioUrl: DEFAULT_STUDIO_URL,\n ...(typeof userConfig.devtools === 'boolean' ? {} : userConfig.devtools),\n }\n : undefined,\n plugins: (userConfig.plugins ?? []) as unknown as Config['plugins'],\n }\n\n const storage: Storage | null = config.output.write === false ? null : (config.storage ?? fsStorage())\n\n if (config.output.clean) {\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: ['Cleaning output directories', ` • Output: ${config.output.path}`],\n })\n await storage?.clear(resolve(config.root, config.output.path))\n }\n\n const driver = new PluginDriver(config, {\n hooks,\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 function registerMiddlewareHook<K extends keyof KubbHooks & string>(event: K, middlewareHooks: Middleware['hooks']) {\n const handler = middlewareHooks[event]\n if (handler) {\n hooks.on(event, handler)\n }\n }\n\n for (const middleware of config.middleware ?? []) {\n for (const event of Object.keys(middleware.hooks) as Array<keyof KubbHooks & string>) {\n registerMiddlewareHook(event, middleware.hooks)\n }\n }\n\n if (config.adapter) {\n const source = inputToAdapterSource(config)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Running adapter: ${config.adapter.name}`],\n })\n\n driver.adapter = config.adapter\n driver.inputNode = await config.adapter.parse(source)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n `✓ Adapter '${config.adapter.name}' resolved InputNode`,\n ` • Schemas: ${driver.inputNode.schemas.length}`,\n ` • Operations: ${driver.inputNode.operations.length}`,\n ],\n })\n }\n\n return {\n config,\n hooks,\n driver,\n sources,\n storage,\n }\n}\n\n/**\n * Walks the AST and dispatches nodes to a plugin's direct AST hooks\n * (`schema`, `operation`, `operations`).\n *\n * When `include` contains only operation-scoped filters (`tag`, `operationId`, `path`,\n * `method`, `contentType`) and no `schemaName` filter, the function pre-computes the set\n * of top-level schema names transitively reachable from the included operations and skips\n * schemas that fall outside that set. This ensures that component schemas referenced\n * exclusively by excluded operations are not generated.\n */\nasync function runPluginAstHooks(plugin: NormalizedPlugin, context: GeneratorContext): Promise<void> {\n const { adapter, inputNode, resolver, driver } = context\n const { exclude, include, override } = plugin.options\n\n if (!adapter || !inputNode) {\n throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. pluginOas()) before this plugin in your Kubb config.`)\n }\n\n function resolveRenderer(gen: Generator): RendererFactory | undefined {\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin.renderer ?? context.config.renderer)\n }\n\n const generators = plugin.generators ?? []\n const collectedOperations: Array<OperationNode> = []\n\n const generatorContext = {\n ...context,\n resolver: driver.getResolver(plugin.name),\n }\n\n // When `include` has operation-based filters (tag, operationId, path, method, contentType)\n // but no schema-level filters (schemaName), pre-compute the set of top-level schema names\n // that are transitively referenced by the included operations. Schemas outside that set are\n // skipped so that types belonging exclusively to excluded operations are not generated.\n const operationFilterTypes = new Set(['tag', 'operationId', 'path', 'method', 'contentType'])\n const hasOperationBasedIncludes = include?.some(({ type }) => operationFilterTypes.has(type)) ?? false\n const hasSchemaNameIncludes = include?.some(({ type }) => type === 'schemaName') ?? false\n\n let allowedSchemaNames: Set<string> | undefined\n if (hasOperationBasedIncludes && !hasSchemaNameIncludes) {\n const includedOps = inputNode.operations.filter((op) => resolver.resolveOptions(op, { options: plugin.options, exclude, include, override }) !== null)\n allowedSchemaNames = collectUsedSchemaNames(includedOps, inputNode.schemas)\n }\n\n await walk(inputNode, {\n depth: 'shallow',\n async schema(node) {\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n\n // Skip named top-level schemas that are not reachable from any included operation.\n if (allowedSchemaNames !== undefined && transformedNode.name && !allowedSchemaNames.has(transformedNode.name)) {\n return\n }\n\n const options = resolver.resolveOptions(transformedNode, {\n options: plugin.options,\n exclude,\n include,\n override,\n })\n if (options === null) return\n\n const ctx = { ...generatorContext, options }\n\n for (const gen of generators) {\n if (!gen.schema) continue\n const result = await gen.schema(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:schema', transformedNode, ctx)\n },\n async operation(node) {\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = resolver.resolveOptions(transformedNode, {\n options: plugin.options,\n exclude,\n include,\n override,\n })\n if (options !== null) {\n collectedOperations.push(transformedNode)\n\n const ctx = { ...generatorContext, options }\n\n for (const gen of generators) {\n if (!gen.operation) continue\n const result = await gen.operation(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:operation', transformedNode, ctx)\n }\n },\n })\n\n if (collectedOperations.length > 0) {\n const ctx = { ...generatorContext, options: plugin.options }\n\n for (const gen of generators) {\n if (!gen.operations) continue\n const result = await gen.operations(collectedOperations, ctx)\n await applyHookResult(result, driver, resolveRenderer(gen))\n }\n\n await driver.hooks.emit('kubb:generate:operations', collectedOperations, ctx)\n }\n}\n\nasync function safeBuild(setupResult: SetupResult): Promise<BuildOutput> {\n const { driver, hooks, sources, storage } = setupResult\n\n const failedPlugins = new Set<{ plugin: Plugin; error: Error }>()\n const pluginTimings = new Map<string, number>()\n const config = driver.config\n\n try {\n await driver.emitSetupHooks()\n\n if (driver.adapter && driver.inputNode) {\n await hooks.emit('kubb:build:start', {\n config,\n adapter: driver.adapter,\n inputNode: driver.inputNode,\n getPlugin: driver.getPlugin.bind(driver),\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n }\n\n for (const plugin of driver.plugins.values()) {\n const context = driver.getContext(plugin)\n const hrStart = process.hrtime()\n\n try {\n const timestamp = new Date()\n\n await hooks.emit('kubb:plugin:start', { plugin })\n\n await hooks.emit('kubb:debug', {\n date: timestamp,\n logs: ['Starting plugin...', ` • Plugin Name: ${plugin.name}`],\n })\n\n if (plugin.generators?.length || driver.hasRegisteredGenerators(plugin.name)) {\n await runPluginAstHooks(plugin, context)\n }\n\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\n\n await hooks.emit('kubb:plugin:end', {\n plugin,\n duration,\n success: true,\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Plugin started successfully (${formatMs(duration)})`],\n })\n } catch (caughtError) {\n const error = caughtError as Error\n const errorTimestamp = new Date()\n const duration = getElapsedMs(hrStart)\n\n await hooks.emit('kubb:plugin:end', {\n plugin,\n duration,\n success: false,\n error,\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n await hooks.emit('kubb:debug', {\n date: errorTimestamp,\n logs: [\n '✗ Plugin start failed',\n ` • Plugin Name: ${plugin.name}`,\n ` • Error: ${error.constructor.name} - ${error.message}`,\n ' • Stack Trace:',\n error.stack || 'No stack trace available',\n ],\n })\n\n failedPlugins.add({ plugin, error })\n }\n }\n\n await hooks.emit('kubb:plugins:end', {\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n const files = driver.fileManager.files\n\n const parsersMap = new Map<FileNode['extname'], Parser>()\n for (const parser of config.parsers) {\n if (parser.extNames) {\n for (const extname of parser.extNames) {\n parsersMap.set(extname, parser)\n }\n }\n }\n\n const fileProcessor = new FileProcessor()\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Writing ${files.length} files...`],\n })\n\n await fileProcessor.run(files, {\n parsers: parsersMap,\n extension: config.output.extension,\n onStart: async (processingFiles) => {\n await hooks.emit('kubb:files:processing:start', { files: processingFiles })\n },\n onUpdate: async ({ file, source, processed, total, percentage }) => {\n await hooks.emit('kubb:file:processing:update', {\n file,\n source,\n processed,\n total,\n percentage,\n config,\n })\n if (source) {\n await storage?.setItem(file.path, source)\n sources.set(file.path, source)\n }\n },\n onEnd: async (processedFiles) => {\n await hooks.emit('kubb:files:processing:end', { files: processedFiles })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ File write process completed for ${processedFiles.length} files`],\n })\n },\n })\n\n await hooks.emit('kubb:build:end', {\n files,\n config,\n outputDir: resolve(config.root, config.output.path),\n })\n\n return {\n failedPlugins,\n files,\n driver,\n pluginTimings,\n sources,\n }\n } catch (error) {\n return {\n failedPlugins,\n files: [],\n driver,\n pluginTimings,\n error: error as Error,\n sources,\n }\n } finally {\n driver.dispose()\n }\n}\n\nasync function build(setupResult: SetupResult): Promise<BuildOutput> {\n const { files, driver, failedPlugins, pluginTimings, error, sources } = await safeBuild(setupResult)\n\n if (error) {\n throw error\n }\n\n if (failedPlugins.size > 0) {\n const errors = [...failedPlugins].map(({ error }) => error)\n\n throw new BuildError(`Build Error with ${failedPlugins.size} failed plugins`, { errors })\n }\n\n return {\n failedPlugins,\n files,\n driver,\n pluginTimings,\n error: undefined,\n sources,\n }\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 (Array.isArray(input)) {\n return {\n type: 'paths',\n paths: input.map((i) => (new URLPath(i.path).isURL ? i.path : resolve(config.root, i.path))),\n }\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 return { type: 'path', path: resolved }\n}\n\ntype CreateKubbOptions = {\n hooks?: AsyncEventEmitter<KubbHooks>\n}\n\n/**\n * Creates a Kubb instance bound to a single config entry.\n *\n * Accepts a user-facing config shape and resolves it to a full {@link Config} during\n * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)\n * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before\n * calling `setup()` or `build()`.\n *\n * @example\n * ```ts\n * const kubb = createKubb(userConfig)\n *\n * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {\n * console.log(`${plugin.name} completed in ${duration}ms`)\n * })\n *\n * const { files, failedPlugins } = await kubb.safeBuild()\n * ```\n */\nexport function createKubb(userConfig: UserConfig, options: CreateKubbOptions = {}): Kubb {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\n let setupResult: SetupResult | undefined\n\n const instance: Kubb = {\n get hooks() {\n return hooks\n },\n get sources() {\n return setupResult?.sources ?? new Map()\n },\n get driver() {\n return setupResult?.driver\n },\n get config() {\n return setupResult?.config\n },\n async setup() {\n setupResult = await setup(userConfig, { hooks })\n },\n async build() {\n if (!setupResult) {\n await instance.setup()\n }\n return build(setupResult!)\n },\n async safeBuild() {\n if (!setupResult) {\n await instance.setup()\n }\n return safeBuild(setupResult!)\n },\n }\n\n return instance\n}\n","import type { FileNode } from '@kubb/ast'\n\n/**\n * Minimal interface any Kubb renderer must satisfy.\n *\n * The generic `TElement` is the type of the element the renderer accepts —\n * e.g. `KubbReactElement` for `@kubb/renderer-jsx`, or a custom type for\n * your own renderer. Defaults to `unknown` so that generators which do not\n * care about the element type continue to work without specifying it.\n *\n * This allows core to drive rendering without a hard dependency on\n * `@kubb/renderer-jsx` or any specific renderer implementation.\n */\nexport type Renderer<TElement = unknown> = {\n render(element: TElement): Promise<void>\n unmount(error?: Error | number | null): void\n readonly files: Array<FileNode>\n}\n\n/**\n * A factory function that produces a fresh {@link Renderer} per render.\n *\n * Generators use this to declare which renderer handles their output.\n */\nexport type RendererFactory<TElement = unknown> = () => Renderer<TElement>\n\n/**\n * Creates a renderer factory for use in generator definitions.\n *\n * Wrap your renderer factory function with this helper to register it as the\n * renderer for a generator. Core will call this factory once per render cycle\n * to obtain a fresh renderer instance.\n *\n * @example\n * ```ts\n * // packages/renderer-jsx/src/index.ts\n * export const jsxRenderer = createRenderer(() => {\n * const runtime = new Runtime()\n * return {\n * async render(element) { await runtime.render(element) },\n * get files() { return runtime.nodes },\n * unmount(error) { runtime.unmount(error) },\n * }\n * })\n *\n * // packages/plugin-zod/src/generators/zodGenerator.tsx\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n * export const zodGenerator = defineGenerator<PluginZod>({\n * name: 'zod',\n * renderer: jsxRenderer,\n * schema(node, options) { return <File ...>...</File> },\n * })\n * ```\n */\nexport function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement> {\n return factory\n}\n","import type { PossiblePromise } from '@internals/utils'\nimport type { FileNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { GeneratorContext, PluginFactoryOptions } from './types.ts'\n\nexport type { GeneratorContext } from './types.ts'\n\n/**\n * Declares a named generator unit that walks the AST and emits files.\n *\n * Each method (`schema`, `operation`, `operations`) is called for the matching node type.\n * Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.\n * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.\n *\n * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.\n *\n * @example\n * ```ts\n * import { defineGenerator } from '@kubb/core'\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n *\n * export const typeGenerator = defineGenerator({\n * name: 'typescript',\n * renderer: jsxRenderer,\n * schema(node, ctx) {\n * const { adapter, resolver, root, options } = ctx\n * return <File ...><Type node={node} resolver={resolver} /></File>\n * },\n * })\n * ```\n */\nexport type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {\n /**\n * Used in diagnostic messages and debug output.\n */\n name: string\n /**\n * Optional renderer factory that produces a {@link Renderer} for each render cycle.\n *\n * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this\n * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).\n *\n * Generators that only return `Array<FileNode>` or `void` do not need to set this.\n *\n * Set `renderer: null` to explicitly opt out of rendering even when the parent plugin\n * declares a `renderer` (overrides the plugin-level fallback).\n *\n * @example\n * ```ts\n * import { jsxRenderer } from '@kubb/renderer-jsx'\n * export const myGenerator = defineGenerator<PluginTs>({\n * renderer: jsxRenderer,\n * schema(node, ctx) { return <File ...>...</File> },\n * })\n * ```\n */\n renderer?: RendererFactory<TElement> | null\n /**\n * Called for each schema node in the AST walk.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the per-node resolved options (after exclude/include/override).\n */\n schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n /**\n * Called for each operation node in the AST walk.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the per-node resolved options (after exclude/include/override).\n */\n operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n /**\n * Called once after all operations have been walked.\n * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,\n * plus `ctx.options` with the plugin-level options for the batch call.\n */\n operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>\n}\n\n/**\n * Defines a generator. Returns the object as-is with correct `this` typings.\n * `applyHookResult` handles renderer elements and `File[]` uniformly using\n * the generator's declared `renderer` factory.\n */\nexport function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(\n generator: Generator<TOptions, TElement>,\n): Generator<TOptions, TElement> {\n return generator\n}\n","import type { Logger, LoggerOptions, UserLogger } from './types.ts'\n\n/**\n * Wraps a logger definition into a typed {@link Logger}.\n *\n * @example\n * ```ts\n * export const myLogger = defineLogger({\n * name: 'my-logger',\n * install(context, options) {\n * context.on('kubb:info', (message) => console.log('ℹ', message))\n * context.on('kubb:error', (error) => console.error('✗', error.message))\n * },\n * })\n * ```\n */\nexport function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options> {\n return logger\n}\n","import type { KubbHooks } from './Kubb.ts'\n\n/**\n * A middleware instance produced by calling a factory created with `defineMiddleware`.\n * It declares event handlers under a `hooks` object which are registered on the\n * shared emitter after all plugin hooks, so middleware handlers for any event\n * always fire last.\n */\nexport type Middleware = {\n /**\n * Unique identifier for this middleware.\n */\n name: string\n /**\n * Lifecycle event handlers for this middleware.\n * Any event from the global `KubbHooks` map can be subscribed to here.\n * Handlers are registered after all plugin handlers, so they always fire last.\n */\n hooks: {\n [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void>\n }\n}\n\n/**\n * Creates a middleware factory using the hook-style `hooks` API.\n *\n * Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.\n * Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.\n *\n * @note The factory can accept typed options. See examples for using options and per-build state patterns.\n *\n * @example\n * ```ts\n * import { defineMiddleware } from '@kubb/core'\n *\n * // Stateless middleware\n * export const logMiddleware = defineMiddleware(() => ({\n * name: 'log-middleware',\n * hooks: {\n * 'kubb:build:end'({ files }) {\n * console.log(`Build complete with ${files.length} files`)\n * },\n * },\n * }))\n *\n * // Middleware with options and per-build state\n * export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {\n * const seen = new Set<string>()\n * return {\n * name: 'prefix-middleware',\n * hooks: {\n * 'kubb:plugin:end'({ plugin }) {\n * seen.add(`${options.prefix}${plugin.name}`)\n * },\n * },\n * }\n * })\n * ```\n */\nexport function defineMiddleware<TOptions extends object = object>(factory: (options: TOptions) => Middleware): (options?: TOptions) => Middleware {\n return (options) => factory(options ?? ({} as TOptions))\n}\n","import type { FileNode } from '@kubb/ast'\n\ntype PrintOptions = {\n extname?: FileNode['extname']\n}\n\nexport type Parser<TMeta extends object = any> = {\n name: string\n /**\n * File extensions this parser handles.\n * Use `undefined` to create a catch-all fallback parser.\n *\n * @example Handled extensions\n * `['.ts', '.js']`\n */\n extNames: Array<FileNode['extname']> | undefined\n /**\n * Convert a resolved file to a string.\n */\n parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string\n}\n\n/**\n * Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.\n *\n * @note Call the returned factory with optional options to instantiate the parser.\n *\n * @example\n * ```ts\n * import { defineParser } from '@kubb/core'\n *\n * export const jsonParser = defineParser({\n * name: 'json',\n * extNames: ['.json'],\n * parse(file) {\n * const { extractStringsFromNodes } = await import('@kubb/ast')\n * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\\n')\n * },\n * })\n * ```\n */\nexport function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta> {\n return parser\n}\n","import type { KubbHooks } from './Kubb.ts'\nimport type { KubbPluginSetupContext, PluginFactoryOptions } from './types.ts'\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 Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void>\n } & {\n 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>\n }\n}\n\n/**\n * Returns `true` when `plugin` is a hook-style plugin created with `definePlugin`.\n *\n * Used by `PluginDriver` to distinguish hook-style plugins from legacy `createPlugin` plugins\n * so it can normalize them and register their handlers on the `AsyncEventEmitter`.\n */\nexport function isPlugin(plugin: unknown): plugin is Plugin {\n return typeof plugin === 'object' && plugin !== null && 'hooks' in plugin\n}\n\n/**\n * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.\n *\n * Handlers live in a single `hooks` object (inspired by Astro integrations).\n * All lifecycle events from `KubbHooks` are available for subscription.\n *\n * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.\n * Plugin names should follow the convention `plugin-<feature>` (e.g., `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","import { createStorage } from '../createStorage.ts'\n\n/**\n * In-memory storage driver. Useful for testing and dry-run scenarios where\n * generated output should be captured without touching the filesystem.\n *\n * All data lives in a `Map` scoped to the storage instance and is discarded\n * when the instance is garbage-collected.\n *\n * @example\n * ```ts\n * import { memoryStorage } from '@kubb/core'\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * storage: memoryStorage(),\n * })\n * ```\n */\nexport const memoryStorage = createStorage(() => {\n const store = new Map<string, string>()\n\n return {\n name: 'memory',\n async hasItem(key: string) {\n return store.has(key)\n },\n async getItem(key: string) {\n return store.get(key) ?? null\n },\n async setItem(key: string, value: string) {\n store.set(key, value)\n },\n async removeItem(key: string) {\n store.delete(key)\n },\n async getKeys(base?: string) {\n const keys = [...store.keys()]\n return base ? keys.filter((k) => k.startsWith(base)) : keys\n },\n async clear(base?: string) {\n if (!base) {\n store.clear()\n return\n }\n for (const key of store.keys()) {\n if (key.startsWith(base)) {\n store.delete(key)\n }\n }\n },\n }\n})\n"],"x_google_ignoreList":[7,8],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YAAY,SAAiB,SAAkD;AAC7E,QAAM,SAAS,EAAE,OAAO,QAAQ,OAAO,CAAC;AACxC,OAAK,OAAO;AACZ,OAAK,SAAS,QAAQ;;;;;;;;;;;;;;AAe1B,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;;;;;ACZlE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;AAC5B,QAAA,QAAc,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,cAAkB;;;;;;;;;;CAWjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,MAAA,QAAc,UAAU,UAAU;AAEpD,MAA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AQ,YAAY,QAAQ,WAAY,EAAE,CAAyB;;;;;;;;;;;;;;;;;;;;;;;AC5DrE,MAAa,gBAAgB,oBAAoB;CAC/C,MAAM,wBAAQ,IAAI,KAAqB;AAEvC,QAAO;EACL,MAAM;EACN,MAAM,QAAQ,KAAa;AACzB,UAAO,MAAM,IAAI,IAAI;;EAEvB,MAAM,QAAQ,KAAa;AACzB,UAAO,MAAM,IAAI,IAAI,IAAI;;EAE3B,MAAM,QAAQ,KAAa,OAAe;AACxC,SAAM,IAAI,KAAK,MAAM;;EAEvB,MAAM,WAAW,KAAa;AAC5B,SAAM,OAAO,IAAI;;EAEnB,MAAM,QAAQ,MAAe;GAC3B,MAAM,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;AAC9B,UAAO,OAAO,KAAK,QAAQ,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG;;EAEzD,MAAM,MAAM,MAAe;AACzB,OAAI,CAAC,MAAM;AACT,UAAM,OAAO;AACb;;AAEF,QAAK,MAAM,OAAO,MAAM,MAAM,CAC5B,KAAI,IAAI,WAAW,KAAK,CACtB,OAAM,OAAO,IAAI;;EAIxB;EACD"}
package/dist/mocks.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_PluginDriver = require("./PluginDriver-Ds-Us-e4.cjs");
2
+ const require_PluginDriver = require("./PluginDriver-Cadu4ORh.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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { R as NormalizedPlugin, V as PluginFactoryOptions, a as Config, n as AdapterFactoryOptions, ot as PluginDriver, t as Adapter, ut as Generator } from "./types-Cd0jhNmx.js";
2
+ import { R as NormalizedPlugin, V as PluginFactoryOptions, a as Config, n as AdapterFactoryOptions, ot as PluginDriver, t as Adapter, ut as Generator } from "./types-CestVgap.js";
3
3
  import { OperationNode, SchemaNode, Visitor } from "@kubb/ast";
4
4
 
5
5
  //#region src/mocks.d.ts
package/dist/mocks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { n as applyHookResult, r as FileManager, t as PluginDriver } from "./PluginDriver-Wi34Pegx.js";
2
+ import { n as applyHookResult, r as FileManager, t as PluginDriver } from "./PluginDriver-BkTRD2H2.js";
3
3
  import { resolve } from "node:path";
4
4
  import { transform } from "@kubb/ast";
5
5
  //#region src/mocks.ts
@@ -98,7 +98,7 @@ type PossiblePromise<T> = Promise<T> | T;
98
98
  /**
99
99
  * Base URL for the Kubb Studio web app.
100
100
  */
101
- declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
101
+ declare const DEFAULT_STUDIO_URL: "https://kubb.studio";
102
102
  /**
103
103
  * Numeric log-level thresholds used internally to compare verbosity.
104
104
  *
@@ -1325,7 +1325,7 @@ type Config<TInput = Input> = {
1325
1325
  /**
1326
1326
  * Kubb Studio cloud integration settings.
1327
1327
  *
1328
- * Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
1328
+ * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.
1329
1329
  * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
1330
1330
  *
1331
1331
  * @default false // disabled by default
@@ -1338,7 +1338,7 @@ type Config<TInput = Input> = {
1338
1338
  devtools?: true | {
1339
1339
  /**
1340
1340
  * Override the Kubb Studio base URL.
1341
- * @default 'https://studio.kubb.dev'
1341
+ * @default 'https://kubb.studio'
1342
1342
  */
1343
1343
  studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
1344
1344
  };
@@ -2150,4 +2150,4 @@ type CLIOptions = {
2150
2150
  type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
2151
2151
  //#endregion
2152
2152
  export { defineParser as $, KubbPluginStartContext as A, Override as B, KubbGenerationSummaryContext as C, KubbLifecycleStartContext as D, KubbInfoContext as E, Logger as F, ResolveOptionsContext as G, PossibleConfig as H, LoggerContext as I, ResolverFileParams as J, Resolver as K, LoggerOptions as L, KubbSuccessContext as M, KubbVersionNewContext as N, KubbPluginEndContext as O, KubbWarnContext as P, Parser as Q, NormalizedPlugin as R, KubbGenerationStartContext as S, KubbHookStartContext as T, ResolveBannerContext as U, PluginFactoryOptions as V, ResolveNameParams as W, UserConfig as X, ResolverPathParams as Y, UserLogger as Z, KubbErrorContext as _, logLevel as _t, Config as a, createKubb as at, KubbFilesProcessingStartContext as b, GeneratorContext as c, Plugin as ct, InputData as d, defineGenerator as dt, Middleware as et, InputPath as f, Storage as ft, KubbDebugContext as g, createRenderer as gt, KubbConfigEndContext as h, RendererFactory as ht, CLIOptions as i, BuildOutput as it, KubbPluginsEndContext as j, KubbPluginSetupContext as k, Group as l, definePlugin as lt, KubbBuildStartContext as m, Renderer as mt, AdapterFactoryOptions as n, Kubb$1 as nt, DevtoolsOptions as o, PluginDriver as ot, KubbBuildEndContext as p, createStorage as pt, ResolverContext as q, AdapterSource as r, KubbHooks as rt, Exclude$1 as s, FileManager as st, Adapter as t, defineMiddleware as tt, Include as u, Generator as ut, KubbFileProcessingUpdateContext as v, AsyncEventEmitter as vt, KubbHookEndContext as w, KubbGenerationEndContext as x, KubbFilesProcessingEndContext as y, Output as z };
2153
- //# sourceMappingURL=types-Cd0jhNmx.d.ts.map
2153
+ //# sourceMappingURL=types-CestVgap.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "ast",
@@ -65,15 +65,15 @@
65
65
  "dependencies": {
66
66
  "fflate": "^0.8.2",
67
67
  "tinyexec": "^1.1.2",
68
- "@kubb/ast": "5.0.0-beta.4"
68
+ "@kubb/ast": "5.0.0-beta.5"
69
69
  },
70
70
  "devDependencies": {
71
71
  "p-limit": "^7.3.0",
72
72
  "@internals/utils": "0.0.0",
73
- "@kubb/renderer-jsx": "5.0.0-beta.4"
73
+ "@kubb/renderer-jsx": "5.0.0-beta.5"
74
74
  },
75
75
  "peerDependencies": {
76
- "@kubb/renderer-jsx": "5.0.0-beta.4"
76
+ "@kubb/renderer-jsx": "5.0.0-beta.5"
77
77
  },
78
78
  "size-limit": [
79
79
  {
@@ -138,6 +138,8 @@ export class PluginDriver {
138
138
  registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {
139
139
  const { hooks } = hookPlugin
140
140
 
141
+ if (!hooks) return
142
+
141
143
  // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with
142
144
  // plugin-specific implementations so that addGenerator / setResolver / etc. target
143
145
  // this plugin's normalizedPlugin entry rather than being no-ops.
package/src/constants.ts CHANGED
@@ -3,7 +3,7 @@ import type { FileNode } from '@kubb/ast'
3
3
  /**
4
4
  * Base URL for the Kubb Studio web app.
5
5
  */
6
- export const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const
6
+ export const DEFAULT_STUDIO_URL = 'https://kubb.studio' as const
7
7
 
8
8
  /**
9
9
  * Maximum number of files processed in parallel by FileProcessor.
package/src/createKubb.ts CHANGED
@@ -119,7 +119,7 @@ async function setup(userConfig: UserConfig, options: SetupOptions = {}): Promis
119
119
  ...(typeof userConfig.devtools === 'boolean' ? {} : userConfig.devtools),
120
120
  }
121
121
  : undefined,
122
- plugins: userConfig.plugins as unknown as Config['plugins'],
122
+ plugins: (userConfig.plugins ?? []) as unknown as Config['plugins'],
123
123
  }
124
124
 
125
125
  const storage: Storage | null = config.output.write === false ? null : (config.storage ?? fsStorage())
package/src/types.ts CHANGED
@@ -411,7 +411,7 @@ export type Config<TInput = Input> = {
411
411
  /**
412
412
  * Kubb Studio cloud integration settings.
413
413
  *
414
- * Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
414
+ * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.
415
415
  * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
416
416
  *
417
417
  * @default false // disabled by default
@@ -426,7 +426,7 @@ export type Config<TInput = Input> = {
426
426
  | {
427
427
  /**
428
428
  * Override the Kubb Studio base URL.
429
- * @default 'https://studio.kubb.dev'
429
+ * @default 'https://kubb.studio'
430
430
  */
431
431
  studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})
432
432
  }