@kubb/core 5.0.0-beta.17 → 5.0.0-beta.18

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"],"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","../package.json","../src/createStorage.ts","../src/FileProcessor.ts","../src/storages/fsStorage.ts","../src/createKubb.ts","../src/createRenderer.ts","../src/defineGenerator.ts","../src/defineLogger.ts","../src/defineMiddleware.ts","../src/defineParser.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 { PossiblePromise } from '@internals/utils'\nimport type { ImportNode, InputNode, InputStreamNode, SchemaNode } from '@kubb/ast'\n\n/**\n * Source data passed to an adapter's `parse` function.\n * Mirrors the config input shape with paths resolved to absolute.\n */\nexport type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }\n\n/**\n * Generic type parameters for an adapter definition.\n *\n * - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)\n * - `TOptions` — user-facing options passed to the adapter factory\n * - `TResolvedOptions` — options after defaults applied\n * - `TDocument` — type of the parsed source document\n */\nexport type AdapterFactoryOptions<\n TName extends string = string,\n TOptions extends object = object,\n TResolvedOptions extends object = TOptions,\n TDocument = unknown,\n> = {\n name: TName\n options: TOptions\n resolvedOptions: TResolvedOptions\n document: TDocument\n}\n\n/**\n * Adapter that converts input files or data into an `InputNode`.\n *\n * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's\n * universal intermediate representation that all plugins consume.\n *\n * @example\n * ```ts\n * import { adapterOas } from '@kubb/adapter-oas'\n *\n * export default defineConfig({\n * adapter: adapterOas(),\n * input: { path: './openapi.yaml' },\n * plugins: [pluginTs(), pluginZod()],\n * })\n * ```\n */\nexport type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {\n /**\n * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).\n */\n name: TOptions['name']\n /**\n * Resolved adapter options after defaults have been applied.\n */\n options: TOptions['resolvedOptions']\n /**\n * Parsed source document after the first `parse()` call. `null` before parsing.\n */\n document: TOptions['document'] | null\n /**\n * Parse the source into a universal `InputNode`.\n */\n parse: (source: AdapterSource) => PossiblePromise<InputNode>\n /**\n * Extract `ImportNode` entries for a schema tree.\n * Returns an empty array before the first `parse()` call.\n *\n * The `resolve` callback receives the collision-corrected schema name and must\n * return `{ name, path }` for the import, or `undefined` to skip it.\n */\n getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>\n /**\n * Validate the document at the given path or URL.\n */\n validate: (input: string, options?: { throwOnError?: boolean }) => Promise<void>\n /**\n * Lightweight pre-flight count of schemas and operations without parsing AST nodes.\n * The adapter should cache the loaded document so subsequent `parse()` or `stream()` calls\n * do not reload it.\n *\n * Used by the core to decide whether to use `parse()` or `stream()`.\n */\n count?: (source: AdapterSource) => Promise<{ schemas: number; operations: number }>\n /**\n * Memory-efficient streaming variant of `parse()`.\n *\n * Returns an `InputStreamNode` whose `schemas` and `operations` are `AsyncIterable`.\n * Each `for await` loop creates a fresh parse pass over the cached in-memory document —\n * no pre-built arrays are held in memory.\n */\n stream?: (source: AdapterSource) => Promise<InputStreamNode>\n}\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","","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 { CodeNode, FileNode } from '@kubb/ast'\nimport { extractStringsFromNodes } from '@kubb/ast'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport type { Parser } from './defineParser.ts'\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n}\n\nexport type FileProcessorEvents = {\n start: [files: Array<FileNode>]\n update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]\n end: [files: Array<FileNode>]\n}\n\nexport type ParsedFile = {\n file: FileNode\n source: string\n processed: number\n total: number\n percentage: number\n}\n\nfunction joinSources(file: FileNode): string {\n 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 events = new AsyncEventEmitter<FileProcessorEvents>()\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 /**\n * Streams parsed files one at a time as each is processed.\n *\n * Unlike `run()`, files are yielded immediately after parsing rather than batched.\n * Storage writes can begin as soon as the first file is ready, keeping peak\n * memory proportional to one file at a time instead of the full batch.\n */\n async *stream(files: ReadonlyArray<FileNode>, options: ParseOptions = {}): AsyncGenerator<ParsedFile> {\n const total = files.length\n let processed = 0\n\n for (const file of files) {\n const source = await this.parse(file, options)\n processed++\n yield { file, source, processed, total, percentage: (processed / total) * 100 }\n }\n }\n\n async run(files: Array<FileNode>, options: ParseOptions = {}): Promise<Array<FileNode>> {\n await this.events.emit('start', files)\n\n for await (const { file, source, processed, total, percentage } of this.stream(files, options)) {\n await this.events.emit('update', { file, source, processed, percentage, total })\n }\n\n await this.events.emit('end', files)\n\n return files\n }\n}\n","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 * 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 return false\n }\n },\n async getItem(key: string) {\n try {\n return await readFile(resolve(key), 'utf8')\n } catch (_error) {\n return null\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 resolvedBase = resolve(base ?? process.cwd())\n\n async function* walk(dir: string, prefix: string): AsyncGenerator<string, void, undefined> {\n let entries: Array<Dirent>\n try {\n entries = (await readdir(dir, {\n withFileTypes: true,\n })) as Array<Dirent>\n } catch (_error) {\n return\n }\n for (const entry of entries) {\n const rel = prefix ? `${prefix}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n yield* walk(join(dir, entry.name), rel)\n } else {\n yield rel\n }\n }\n }\n\n const keys: Array<string> = []\n for await (const key of walk(resolvedBase, '')) {\n keys.push(key)\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 { resolve } from 'node:path'\nimport { version as nodeVersion } from 'node:process'\nimport type { PossiblePromise } from '@internals/utils'\nimport { AsyncEventEmitter, BuildError, exists, formatMs, getElapsedMs, URLPath } from '@internals/utils'\nimport type { FileNode, InputNode, InputStreamNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { collectUsedSchemaNames, transform, walk } from '@kubb/ast'\nimport { version as KubbVersion } from '../package.json'\nimport { DEFAULT_BANNER, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL, STREAM_FLUSH_EVERY, STREAM_SCHEMA_THRESHOLD } from './constants.ts'\nimport type { Adapter, AdapterSource } from './createAdapter.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport { createStorage, type Storage } from './createStorage.ts'\nimport type { GeneratorContext, Generator } from './defineGenerator.ts'\nimport type { Middleware } from './defineMiddleware.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NormalizedPlugin, Plugin } from './definePlugin.ts'\nimport { FileProcessor } from './FileProcessor.ts'\nimport { applyHookResult, PluginDriver } from './PluginDriver.ts'\nimport { fsStorage } from './storages/fsStorage.ts'\n\n/**\n * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.\n * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`\n * without requiring changes to core.\n *\n * @internal\n */\ntype ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}\n\n/**\n * Reference to an input file to generate code from.\n *\n * Specify an absolute path or a path relative to the config file location.\n * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.\n */\nexport type InputPath = {\n /**\n * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.\n *\n * @example\n * ```ts\n * { path: './petstore.yaml' }\n * { path: '/absolute/path/to/openapi.json' }\n * ```\n */\n path: string\n}\n\n/**\n * Inline input data to generate code from.\n *\n * Useful when you want to pass the specification directly instead of from a file.\n * Can be a string (YAML/JSON) or a parsed object.\n */\nexport type InputData = {\n /**\n * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.\n *\n * @example\n * ```ts\n * { data: fs.readFileSync('./openapi.yaml', 'utf8') }\n * { data: { openapi: '3.1.0', info: { ... } } }\n * ```\n */\n data: string | unknown\n}\n\ntype Input = InputPath | InputData\n\n/**\n * Build configuration for Kubb code generation.\n *\n * The Config is the main entry point for customizing how Kubb generates code. It specifies:\n * - What to generate from (adapter + input)\n * - Where to output generated code (output)\n * - How to generate (plugins + middleware)\n * - Runtime details (parsers, storage, renderer)\n *\n * See `UserConfig` for a relaxed version with sensible defaults.\n *\n * @private\n */\nexport type Config<TInput = Input> = {\n /**\n * Display name for this configuration in CLI output and logs.\n * Useful when running multiple builds with `defineConfig` arrays.\n *\n * @example\n * ```ts\n * name: 'api-client'\n * ```\n */\n name?: string\n /**\n * Project root directory, absolute or relative to the config file.\n * @default process.cwd()\n */\n root: string\n /**\n * Parsers that convert generated files to strings.\n * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).\n * A fallback parser is appended for unhandled extensions.\n * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.\n *\n * @default [parserTs] from `@kubb/parser-ts`\n * @example\n * ```ts\n * import { parserTs, tsxParser } from '@kubb/parser-ts'\n * export default defineConfig({\n * parsers: [parserTs, tsxParser],\n * })\n * ```\n */\n parsers: Array<Parser>\n /**\n * Adapter that parses input files into the universal `InputNode` representation.\n * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.\n *\n * When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files\n * injected via `injectFile` are written, but no AST walk occurs and generator hooks\n * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.\n *\n * @example\n * ```ts\n * import { adapterOas } from '@kubb/adapter-oas'\n * export default defineConfig({\n * adapter: adapterOas(),\n * input: { path: './petstore.yaml' },\n * })\n * ```\n */\n adapter?: Adapter\n /**\n * Source file or data to generate code from.\n * Use `input.path` for a file path or `input.data` for inline data.\n * Required when an adapter is configured; omit when running in plugin-only mode.\n */\n input?: TInput\n output: {\n /**\n * Output directory for generated files, absolute or relative to `root`.\n *\n * All generated files will be written under this directory. Subdirectories can be created\n * by plugins based on grouping strategy (by tag, path, etc.).\n *\n * @example\n * ```ts\n * output: {\n * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.\n * }\n * ```\n */\n path: string\n /**\n * Remove all files from the output directory before starting the build.\n *\n * Useful to ensure old generated files aren't mixed with new ones.\n * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.\n *\n * @default false\n * @example\n * ```ts\n * clean: true // wipes ./src/gen/* before generating\n * ```\n */\n clean?: boolean\n /**\n * Auto-format generated files after code generation completes.\n *\n * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter\n * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).\n *\n * @default false\n * @example\n * ```ts\n * format: 'auto' // auto-detect prettier, biome, or oxfmt\n * format: 'prettier' // force prettier\n * format: false // skip formatting\n * ```\n */\n format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false\n /**\n * Auto-lint generated files after code generation completes.\n *\n * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter\n * is available on your system. Pass `false` to skip linting.\n *\n * @default false\n * @example\n * ```ts\n * lint: 'auto' // auto-detect oxlint, biome, or eslint\n * lint: 'eslint' // force eslint\n * lint: false // skip linting\n * ```\n */\n lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false\n /**\n * Map file extensions to different output extensions.\n *\n * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).\n * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.\n *\n * @default { '.ts': '.ts' }\n * @example\n * ```ts\n * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'\n * extension: { '.ts': '', '.tsx': '.jsx' }\n * ```\n */\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n /**\n * Banner text prepended to every generated file.\n *\n * Useful for auto-generation notices or license headers. Choose a preset or write custom text.\n * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.\n *\n * @default 'simple'\n * @example\n * ```ts\n * defaultBanner: 'simple' // \"This file was autogenerated by Kubb\"\n * defaultBanner: 'full' // adds source, title, description, API version\n * defaultBanner: false // no banner\n * ```\n */\n defaultBanner?: 'simple' | 'full' | false\n /**\n * When `true`, overwrites existing files. When `false`, skips generated files that already exist.\n *\n * Individual plugins can override this setting. This is useful for preventing accidental data loss\n * when re-generating while you have local edits in the output folder.\n *\n * @default false\n * @example\n * ```ts\n * override: true // regenerate everything, even existing files\n * override: false // skip files that already exist\n * ```\n */\n override?: boolean\n } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>\n /**\n * Storage backend that controls where and how generated files are persisted.\n *\n * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,\n * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.\n *\n * @default fsStorage()\n * @example\n * ```ts\n * import { memoryStorage } from '@kubb/core'\n *\n * // Keep generated files in memory (useful for testing, CI pipelines)\n * storage: memoryStorage()\n *\n * // Use custom S3 storage\n * storage: myS3Storage()\n * ```\n *\n * @see {@link Storage} interface for implementing custom backends.\n */\n storage: Storage\n /**\n * Plugins that execute during the build to generate code and transform the AST.\n *\n * Each plugin processes the AST produced by the adapter and can emit files for different\n * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).\n * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.\n *\n * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.\n *\n * @example\n * ```ts\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n *\n * plugins: [\n * pluginTs({ output: { path: './src/gen' } }),\n * pluginZod({ output: { path: './src/gen' } }),\n * ]\n * ```\n */\n plugins: Array<Plugin>\n /**\n * Middleware instances that observe build events and post-process generated code.\n *\n * Middleware fires AFTER all plugins for each event. Perfect for tasks like:\n * - Auditing what was generated\n * - Adding barrel/index files\n * - Validating output\n * - Running custom transformations\n *\n * @example\n * ```ts\n * import { middlewareBarrel } from '@kubb/middleware-barrel'\n *\n * middleware: [middlewareBarrel()]\n * ```\n *\n * @see {@link defineMiddleware} to create custom middleware.\n */\n middleware?: Array<Middleware>\n /**\n * Renderer that converts generated AST nodes to code strings.\n *\n * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support\n * different output formats (template engines, code generation DSLs, etc.).\n *\n * @default rendererJsx() // from @kubb/renderer-jsx\n * @example\n * ```ts\n * import { rendererJsx } from '@kubb/renderer-jsx'\n * renderer: rendererJsx()\n * ```\n *\n * @see {@link Renderer} to implement a custom renderer.\n */\n renderer?: RendererFactory\n /**\n * Kubb Studio cloud integration settings.\n *\n * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.\n * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.\n *\n * @default false // disabled by default\n * @example\n * ```ts\n * devtools: true // use default Kubb Studio\n * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance\n * ```\n */\n devtools?:\n | true\n | {\n /**\n * Override the Kubb Studio base URL.\n * @default 'https://kubb.studio'\n */\n studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})\n }\n /**\n * Lifecycle hooks that execute during or after the build process.\n *\n * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.\n * Currently supports the `done` hook which fires after all plugins and middleware complete.\n *\n * @example\n * ```ts\n * hooks: {\n * done: 'prettier --write \"./src/gen\"', // auto-format generated files\n * // or multiple commands:\n * done: ['prettier --write \"./src/gen\"', 'eslint --fix \"./src/gen\"']\n * }\n * ```\n */\n hooks?: {\n /**\n * Command(s) to run after all plugins and middleware complete generation.\n *\n * Useful for post-processing: formatting, linting, copying files, or custom validation.\n * Pass a single command string or array of command strings to run sequentially.\n * Commands are executed relative to the `root` directory.\n *\n * @example\n * ```ts\n * done: 'prettier --write \"./src/gen\"'\n * done: ['prettier --write \"./src/gen\"', 'eslint --fix \"./src/gen\"']\n * ```\n */\n done?: string | Array<string>\n }\n}\n\n/**\n * Partial `Config` for user-facing entry points with sensible defaults.\n *\n * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`\n * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,\n * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * input: { path: './petstore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs(), pluginZod()],\n * })\n * ```\n */\nexport type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage'> & {\n /**\n * Project root directory, absolute or relative to the config file location.\n * @default process.cwd()\n */\n root?: string\n /**\n * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).\n * @default [parserTs] // from `@kubb/parser-ts`\n */\n parsers?: Array<Parser>\n /**\n * Adapter that parses your API specification into Kubb's universal AST.\n * When omitted, Kubb runs in plugin-only mode.\n */\n adapter?: Adapter\n /**\n * Plugins that execute during the build to generate code and transform the AST.\n * @default []\n */\n plugins?: Array<Plugin>\n /**\n * Storage backend that controls where and how generated files are persisted.\n * @default fsStorage()\n */\n storage?: Storage\n}\n\ndeclare global {\n namespace Kubb {\n /**\n * Registry that maps plugin names to their `PluginFactoryOptions`.\n * Augment this interface in each plugin's `types.ts` to enable automatic\n * typing for `getPlugin` and `requirePlugin`.\n *\n * @example\n * ```ts\n * // packages/plugin-ts/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface PluginRegistry {\n * 'plugin-ts': PluginTs\n * }\n * }\n * }\n * ```\n */\n interface PluginRegistry {}\n\n /**\n * Extension point for root `Config['output']` options.\n * Augment the `output` key in middleware or plugin packages to add extra fields\n * to the global output configuration without touching core types.\n *\n * @example\n * ```ts\n * // packages/middleware-barrel/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface ConfigOptionsRegistry {\n * output: {\n * barrel?: import('./types.ts').BarrelConfig | false\n * }\n * }\n * }\n * }\n * ```\n */\n interface ConfigOptionsRegistry {}\n\n /**\n * Extension point for per-plugin `Output` options.\n * Augment the `output` key in middleware or plugin packages to add extra fields\n * to the per-plugin output configuration without touching core types.\n *\n * @example\n * ```ts\n * // packages/middleware-barrel/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface PluginOptionsRegistry {\n * output: {\n * barrel?: import('./types.ts').PluginBarrelConfig | false\n * }\n * }\n * }\n * }\n * ```\n */\n interface PluginOptionsRegistry {}\n }\n}\n\n/**\n * Lifecycle events emitted during Kubb code generation.\n * Use these for logging, progress tracking, and custom integrations.\n *\n * @example\n * ```typescript\n * import type { AsyncEventEmitter } from '@internals/utils'\n * import type { KubbHooks } from '@kubb/core'\n *\n * const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()\n *\n * hooks.on('kubb:lifecycle:start', () => {\n * console.log('Starting Kubb generation')\n * })\n *\n * hooks.on('kubb:plugin:end', ({ plugin, duration }) => {\n * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)\n * })\n * ```\n */\nexport interface KubbHooks {\n 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext]\n 'kubb:lifecycle:end': []\n 'kubb:config:start': []\n 'kubb:config:end': [ctx: KubbConfigEndContext]\n 'kubb:generation:start': [ctx: KubbGenerationStartContext]\n 'kubb:generation:end': [ctx: KubbGenerationEndContext]\n 'kubb:generation:summary': [ctx: KubbGenerationSummaryContext]\n 'kubb:format:start': []\n 'kubb:format:end': []\n 'kubb:lint:start': []\n 'kubb:lint:end': []\n 'kubb:hooks:start': []\n 'kubb:hooks:end': []\n 'kubb:hook:start': [ctx: KubbHookStartContext]\n 'kubb:hook:end': [ctx: KubbHookEndContext]\n 'kubb:version:new': [ctx: KubbVersionNewContext]\n 'kubb:info': [ctx: KubbInfoContext]\n 'kubb:error': [ctx: KubbErrorContext]\n 'kubb:success': [ctx: KubbSuccessContext]\n 'kubb:warn': [ctx: KubbWarnContext]\n 'kubb:debug': [ctx: KubbDebugContext]\n 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext]\n 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext]\n 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext]\n 'kubb:plugin:start': [ctx: KubbPluginStartContext]\n 'kubb:plugin:end': [ctx: KubbPluginEndContext]\n 'kubb:plugin:setup': [ctx: KubbPluginSetupContext]\n 'kubb:build:start': [ctx: KubbBuildStartContext]\n 'kubb:plugins:end': [ctx: KubbPluginsEndContext]\n 'kubb:build:end': [ctx: KubbBuildEndContext]\n 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext]\n 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext]\n 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext]\n}\n\nexport type KubbBuildStartContext = {\n config: Config\n adapter: Adapter\n inputNode: InputNode\n getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin(name: string): Plugin | undefined\n readonly files: ReadonlyArray<FileNode>\n upsertFile: (...files: Array<FileNode>) => void\n}\n\nexport type KubbPluginsEndContext = {\n config: Config\n readonly files: ReadonlyArray<FileNode>\n upsertFile: (...files: Array<FileNode>) => void\n}\n\nexport type KubbBuildEndContext = {\n files: Array<FileNode>\n config: Config\n outputDir: string\n}\n\nexport type KubbLifecycleStartContext = {\n version: string\n}\n\nexport type KubbConfigEndContext = {\n configs: Array<Config>\n}\n\nexport type KubbGenerationStartContext = {\n config: Config\n}\n\nexport type KubbGenerationEndContext = {\n config: Config\n /**\n * Read-only view of the files Kubb wrote during this build.\n *\n * Keys are scoped to this run; files from earlier builds are not included.\n * Reads go directly to `config.storage`, so nothing is buffered in memory.\n *\n * @example Read a generated file\n * ```ts\n * const code = await storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example Walk every generated file\n * ```ts\n * for (const path of await storage.getKeys()) {\n * const code = await storage.getItem(path)\n * }\n * ```\n */\n storage: Storage\n}\n\nexport type KubbGenerationSummaryContext = {\n config: Config\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n status: 'success' | 'failed'\n hrStart: [number, number]\n filesCreated: number\n pluginTimings?: Map<Plugin['name'], number>\n}\n\nexport type KubbVersionNewContext = {\n currentVersion: string\n latestVersion: string\n}\n\nexport type KubbInfoContext = {\n message: string\n info?: string\n}\n\nexport type KubbErrorContext = {\n error: Error\n meta?: Record<string, unknown>\n}\n\nexport type KubbSuccessContext = {\n message: string\n info?: string\n}\n\nexport type KubbWarnContext = {\n message: string\n info?: string\n}\n\nexport type KubbDebugContext = {\n date: Date\n logs: Array<string>\n fileName?: string\n}\n\nexport type KubbFilesProcessingStartContext = {\n files: Array<FileNode>\n}\n\nexport type KubbFileProcessingUpdateContext = {\n processed: number\n total: number\n percentage: number\n source?: string\n file: FileNode\n config: Config\n}\n\nexport type KubbFilesProcessingEndContext = {\n files: Array<FileNode>\n}\n\nexport type KubbHookStartContext = {\n id?: string\n command: string\n args?: readonly string[]\n}\n\nexport type KubbHookEndContext = {\n id?: string\n command: string\n args?: readonly string[]\n success: boolean\n error: Error | null\n}\n\n/**\n * CLI options derived from command-line flags.\n */\nexport type CLIOptions = {\n config?: string\n watch?: boolean\n /** @default 'silent' */\n logLevel?: 'silent' | 'info' | 'debug'\n}\n\n/**\n * All accepted forms of a Kubb configuration.\n * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`.\n */\nexport type PossibleConfig<TCliOptions = undefined> =\n | PossiblePromise<Config | Config[]>\n | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)\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 * Read-only view of every file written during this build.\n *\n * Keys are limited to this run. Reads go straight to `config.storage`,\n * so nothing extra is held in memory.\n *\n * @example Read a generated file\n * ```ts\n * const code = await buildOutput.storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example List all generated file paths\n * ```ts\n * const paths = await buildOutput.storage.getKeys()\n * ```\n */\n storage: Storage\n}\n\n/**\n * Kubb code generation instance returned by {@link createKubb}.\n *\n * Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.\n * For a single one-off build, chain directly: `await createKubb(config).build()`.\n */\nexport type Kubb = {\n /**\n * Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.\n */\n readonly hooks: AsyncEventEmitter<KubbHooks>\n /**\n * Read-only view of the files from the most recent `build()` or `safeBuild()` call.\n * Only populated after the build completes.\n *\n * Keys are scoped to the current run. Reads go straight to `config.storage`,\n * so nothing extra is held in memory.\n *\n * @example Read a generated file\n * ```ts\n * const { storage } = await kubb.safeBuild()\n * const code = await storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example Walk every generated file\n * ```ts\n * for (const path of await kubb.storage.getKeys()) {\n * const code = await kubb.storage.getItem(path)\n * }\n * ```\n */\n readonly storage: Storage\n /**\n * Plugin driver managing all plugins. Available after `setup()` completes.\n */\n readonly driver: PluginDriver\n /**\n * Resolved configuration with defaults applied. Available after `setup()` completes.\n */\n readonly config: Config\n /**\n * Resolves config and initializes the driver. `build()` calls this automatically.\n */\n setup(): Promise<void>\n /**\n * Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.\n */\n build(): Promise<BuildOutput>\n /**\n * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.\n */\n safeBuild(): Promise<BuildOutput>\n}\n\ntype SetupResult = {\n hooks: AsyncEventEmitter<KubbHooks>\n driver: PluginDriver\n storage: Storage\n config: Config\n dispose: () => void\n}\n\n/**\n * Builds a `Storage` view scoped to the file paths produced by the current build.\n *\n * Reads delegate to the underlying `storage` (typically `fsStorage()`) so source bytes\n * stay where they were written instead of being held in an extra in-memory map.\n * Writing via `setItem` stores the content in the underlying storage and registers the\n * key so subsequent reads and `getKeys` are scoped to this build's output.\n */\nfunction createSourcesView(storage: Storage): Storage {\n const paths = new Set<string>()\n return createStorage(() => ({\n name: `${storage.name}:sources`,\n async hasItem(key: string) {\n return paths.has(key) && (await storage.hasItem(key))\n },\n async getItem(key: string) {\n return paths.has(key) ? storage.getItem(key) : null\n },\n async setItem(key: string, value: string) {\n paths.add(key)\n await storage.setItem(key, value)\n },\n async removeItem(key: string) {\n paths.delete(key)\n await storage.removeItem(key)\n },\n async getKeys(base?: string) {\n if (!base) return [...paths]\n const result: Array<string> = []\n for (const key of paths) {\n if (key.startsWith(base)) result.push(key)\n }\n return result\n },\n async clear() {\n paths.clear()\n await storage.clear()\n },\n }))()\n}\n\nasync function setup(userConfig: UserConfig, options: SetupOptions = {}): Promise<SetupResult> {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\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 extension: DEFAULT_EXTENSION,\n defaultBanner: DEFAULT_BANNER,\n ...userConfig.output,\n },\n storage: userConfig.storage ?? fsStorage(),\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 const driver = new PluginDriver(config, {\n hooks,\n })\n const storage: Storage = createSourcesView(config.storage)\n const diagnosticInfo = getDiagnosticInfo()\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: ${config.storage.name}`,\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 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 config.storage.clear(resolve(config.root, config.output.path))\n }\n\n // Register middleware hooks after all plugin hooks are registered.\n // Because AsyncEventEmitter calls listeners in registration order,\n // middleware hooks for any event fire after all plugin hooks for that event.\n // Handlers are tracked so they can be removed after each build (disposeMiddleware),\n // preventing accumulation when multiple configs share the same hooks instance.\n const middlewareListeners: Array<[keyof KubbHooks & string, (...args: never[]) => void | Promise<void>]> = []\n\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 middlewareListeners.push([event, handler as (...args: never[]) => void | Promise<void>])\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\n if (config.adapter.count && config.adapter.stream) {\n const { schemas: schemaCount, operations: operationCount } = await config.adapter.count(source)\n\n if (schemaCount > STREAM_SCHEMA_THRESHOLD) {\n driver.inputStreamNode = await config.adapter.stream(source)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n `✓ Adapter '${config.adapter.name}' streaming InputStreamNode`,\n ` • Schemas: ${schemaCount} (threshold: ${STREAM_SCHEMA_THRESHOLD})`,\n ` • Operations: ${operationCount}`,\n ],\n })\n } else {\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 } else {\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\n return {\n config,\n hooks,\n driver,\n storage,\n dispose: () => {\n driver.dispose()\n for (const [event, handler] of middlewareListeners) {\n hooks.off(event, handler as never)\n }\n },\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 */\ntype PluginStreamEntry = {\n plugin: NormalizedPlugin\n context: GeneratorContext\n hrStart: ReturnType<typeof process.hrtime>\n}\n\n/**\n * Single-pass fan-out for streaming mode.\n *\n * Iterates `inputStreamNode.schemas` and `.operations` exactly once, distributing each\n * node to every plugin in parallel. This replaces the N-pass-per-plugin pattern (where\n * each plugin got its own `for await` iterator) with a single parse pass fanned to all\n * plugins — eliminating the N×parse-time overhead for multi-plugin builds.\n *\n * Each plugin still gets independent `plugin:start` / `plugin:end` events and its own\n * timing, but the schema and operation nodes are parsed only once total.\n */\nasync function runPluginStreamHooks(\n inputStreamNode: InputStreamNode,\n entries: PluginStreamEntry[],\n driver: PluginDriver,\n hooks: AsyncEventEmitter<KubbHooks>,\n config: Config,\n pluginTimings: Map<string, number>,\n failedPlugins: Set<{ plugin: Plugin; error: Error }>,\n flushPendingFiles: () => Promise<void>,\n): Promise<void> {\n type PluginState = {\n plugin: NormalizedPlugin\n generatorContext: GeneratorContext\n generators: Generator[]\n hrStart: ReturnType<typeof process.hrtime>\n failed: boolean\n error: Error | undefined\n }\n\n function resolveRendererFor(gen: Generator, state: PluginState): RendererFactory | undefined {\n return gen.renderer === null ? undefined : (gen.renderer ?? state.plugin.renderer ?? state.generatorContext.config.renderer)\n }\n\n const states: PluginState[] = entries.map(({ plugin, context, hrStart }) => ({\n plugin,\n generatorContext: { ...context, resolver: driver.getResolver(plugin.name) },\n generators: plugin.generators ?? [],\n hrStart,\n failed: false,\n error: undefined,\n }))\n\n let schemasProcessed = 0\n for await (const node of inputStreamNode.schemas) {\n for (const state of states) {\n if (state.failed) continue\n try {\n const { plugin, generatorContext, generators } = state\n const { exclude, include, override } = plugin.options\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = generatorContext.resolver.resolveOptions(transformedNode, { options: plugin.options, exclude, include, override })\n if (options === null) continue\n\n const ctx = { ...generatorContext, options }\n for (const gen of generators) {\n if (!gen.schema) continue\n const result = await gen.schema(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:schema', transformedNode, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n schemasProcessed++\n if (schemasProcessed % STREAM_FLUSH_EVERY === 0) {\n await flushPendingFiles()\n }\n }\n\n const collectedOperations: OperationNode[] = []\n for await (const node of inputStreamNode.operations) {\n collectedOperations.push(node)\n for (const state of states) {\n if (state.failed) continue\n try {\n const { plugin, generatorContext, generators } = state\n const { exclude, include, override } = plugin.options\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = generatorContext.resolver.resolveOptions(transformedNode, { options: plugin.options, exclude, include, override })\n if (options === null) continue\n\n const ctx = { ...generatorContext, options }\n for (const gen of generators) {\n if (!gen.operation) continue\n const result = await gen.operation(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:operation', transformedNode, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n }\n\n // After stream: gen.operations for each plugin, then emit plugin:end\n for (const state of states) {\n if (!state.failed) {\n try {\n const { plugin, generatorContext, generators } = state\n const ctx = { ...generatorContext, options: plugin.options }\n for (const gen of generators) {\n if (!gen.operations) continue\n const result = await gen.operations(collectedOperations, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:operations', collectedOperations, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n\n const duration = getElapsedMs(state.hrStart)\n pluginTimings.set(state.plugin.name, duration)\n\n await hooks.emit('kubb:plugin:end', {\n plugin: state.plugin,\n duration,\n success: !state.failed,\n ...(state.failed && state.error ? { error: state.error } : {}),\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n if (state.failed && state.error) {\n failedPlugins.add({ plugin: state.plugin, error: state.error })\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [state.failed ? '✗ Plugin start failed' : `✓ Plugin started successfully (${formatMs(duration)})`],\n })\n }\n\n await flushPendingFiles()\n}\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. adapterOas()) 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 // ── BATCH PATH ────────────────────────────────────────────────────────────\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 await Promise.all(\n generators\n .filter((gen) => gen.schema)\n .map((gen) => Promise.resolve(gen.schema!(transformedNode, ctx)).then((result) => 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 await Promise.all(\n generators\n .filter((gen) => gen.operation)\n .map((gen) => Promise.resolve(gen.operation!(transformedNode, ctx)).then((result) => 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, 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 const writtenPaths = new Set<string>()\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 const fileProcessor = new FileProcessor()\n\n async function flushPendingFiles(snapshot?: ReadonlySet<string>): Promise<void> {\n const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path) && (!snapshot || !snapshot.has(f.path)))\n if (files.length === 0) {\n return\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Writing ${files.length} files...`],\n })\n\n await hooks.emit('kubb:files:processing:start', { files })\n\n const stream = fileProcessor.stream(files, { parsers: parsersMap, extension: config.output.extension })\n\n for await (const { file, source, processed, total, percentage } of stream) {\n await hooks.emit('kubb:file:processing:update', { file, source, processed, total, percentage, config })\n if (source) {\n await storage.setItem(file.path, source)\n }\n writtenPaths.add(file.path)\n }\n\n await hooks.emit('kubb:files:processing:end', { files })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ File write process completed for ${files.length} files`],\n })\n }\n\n try {\n await driver.emitSetupHooks()\n\n if (driver.adapter && (driver.inputNode || driver.inputStreamNode)) {\n await hooks.emit('kubb:build:start', {\n config,\n adapter: driver.adapter,\n inputNode: driver.inputNode ?? { kind: 'Input' as const, schemas: [], operations: [], meta: driver.inputStreamNode?.meta },\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 const inputStreamNode = driver.inputStreamNode\n if (inputStreamNode) {\n // ── STREAMING: fan-out single-pass ────────────────────────────────────\n // Emit plugin:start for all plugins up front, collect generator-plugins\n // for the fan-out pass, then handle non-generator plugins immediately.\n const streamPluginEntries: PluginStreamEntry[] = []\n\n for (const plugin of driver.plugins.values()) {\n const context = driver.getContext(plugin)\n const hrStart = process.hrtime()\n\n await hooks.emit('kubb:plugin:start', { plugin })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: ['Starting plugin...', ` • Plugin Name: ${plugin.name}`],\n })\n\n if (plugin.generators?.length || driver.hasRegisteredGenerators(plugin.name)) {\n streamPluginEntries.push({ plugin, context, hrStart })\n } else {\n // No generators: plugin ran via setup hooks; finish it now.\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\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 await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Plugin started successfully (${formatMs(duration)})`],\n })\n }\n }\n\n if (streamPluginEntries.length > 0) {\n await runPluginStreamHooks(inputStreamNode, streamPluginEntries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles)\n }\n } else {\n // ── BATCH: existing per-plugin sequential loop ────────────────────────\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 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 await flushPendingFiles()\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 await flushPendingFiles()\n\n const files = driver.fileManager.files\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 storage,\n }\n } catch (error) {\n return {\n failedPlugins,\n files: [],\n driver,\n pluginTimings,\n error: error as Error,\n storage,\n }\n } finally {\n setupResult.dispose()\n }\n}\n\nasync function build(setupResult: SetupResult): Promise<BuildOutput> {\n const { files, driver, failedPlugins, pluginTimings, error, storage } = 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 storage,\n }\n}\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\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\nfunction inputToAdapterSource(config: Config): AdapterSource {\n const input = config.input\n if (!input) {\n throw new Error('[kubb] input is required when using an adapter. Provide input.path or input.data in your config.')\n }\n\n if ('data' in input) {\n return { type: 'data', data: input.data }\n }\n\n if (new URLPath(input.path).isURL) {\n return { type: 'path', path: input.path }\n }\n\n const resolved = resolve(config.root, input.path)\n\n return { type: 'path', path: resolved }\n}\n\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`, `storage`, `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 storage() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing storage')\n }\n return setupResult.storage\n },\n get driver() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing driver')\n }\n return setupResult.driver\n },\n get config() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing config')\n }\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 { AsyncEventEmitter, PossiblePromise } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode, Visitor } from '@kubb/ast'\nimport type { Adapter } from './createAdapter.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { KubbHooks } from './types.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\nimport type { Plugin, PluginFactoryOptions } from './definePlugin.ts'\nimport type { Resolver } from './defineResolver.ts'\nimport type { Config, DevtoolsOptions } from './types.ts'\n\n/**\n * Context object passed to generator `schema`, `operation`, and `operations` methods.\n *\n * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks\n * are needed. `ctx.options` carries resolved per-node options after exclude/include/override\n * filtering for individual schema/operation calls, or plugin-level options for operations.\n */\nexport type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n config: Config\n /**\n * Absolute path to the current plugin's output directory.\n */\n root: string\n /**\n * Determine output mode based on the output config.\n * Returns `'single'` when `output.path` is a file, `'split'` for a directory.\n */\n getMode: (output: { path: string }) => 'single' | 'split'\n driver: PluginDriver\n /**\n * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.\n */\n getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin(name: string): Plugin | undefined\n /**\n * Get a plugin by name, throws an error if not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin(name: string): Plugin\n /**\n * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver(name: string): Resolver\n /**\n * Add files only if they don't exist.\n */\n addFile: (...file: Array<FileNode>) => Promise<void>\n /**\n * Merge sources into the same output file.\n */\n upsertFile: (...file: Array<FileNode>) => Promise<void>\n hooks: AsyncEventEmitter<KubbHooks>\n /**\n * The current plugin instance.\n */\n plugin: Plugin<TOptions>\n /**\n * The current plugin's resolver.\n */\n resolver: TOptions['resolver']\n /**\n * The current plugin's transformer.\n */\n transformer: Visitor | undefined\n /**\n * Emit a warning.\n */\n warn: (message: string) => void\n /**\n * Emit an error.\n */\n error: (error: string | Error) => void\n /**\n * Emit an info message.\n */\n info: (message: string) => void\n /**\n * Open the current input node in Kubb Studio.\n */\n openInStudio: (options?: DevtoolsOptions) => Promise<void>\n /**\n * The configured adapter instance.\n */\n adapter: Adapter\n /**\n * The universal `InputNode` produced by the adapter.\n */\n inputNode: InputNode\n /**\n * Resolved options after exclude/include/override filtering.\n */\n options: TOptions['resolvedOptions']\n}\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 { AsyncEventEmitter } from '@internals/utils'\nimport type { logLevel } from './constants.ts'\nimport type { KubbHooks } from './types.ts'\n\nexport type LoggerOptions = {\n /**\n * Log level for output verbosity.\n * @default 3\n */\n logLevel: (typeof logLevel)[keyof typeof logLevel]\n}\n\n/**\n * Shared context passed to plugins, parsers, and other internals.\n */\nexport type LoggerContext = AsyncEventEmitter<KubbHooks>\n\nexport type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {\n name: string\n install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>\n}\n\nexport type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>\n\n/**\n * Wraps a logger definition into a typed {@link Logger}.\n *\n * The optional second type parameter `TInstallReturn` allows loggers to return\n * a value from `install` — for example, a sink factory that the caller can\n * forward to hook execution.\n *\n * @example Basic logger\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 *\n * @example Logger that returns a hook sink factory\n * ```ts\n * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({\n * name: 'my-logger',\n * install(context, options) {\n * // … register event handlers …\n * return (commandWithArgs) => ({ onStdout: console.log })\n * },\n * })\n * ```\n */\nexport function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(\n logger: UserLogger<Options, TInstallReturn>,\n): Logger<Options, TInstallReturn> {\n return logger\n}\n","import type { KubbHooks } from './types.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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YAAY,SAAiB,SAAkD;EAC7E,MAAM,SAAS,EAAE,OAAO,QAAQ,OAAO,CAAC;EACxC,KAAK,OAAO;EACZ,KAAK,SAAS,QAAQ;;;;;;;;;;;;;;AAe1B,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;;;;;ACZlE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;EAC5B,KAAKA,SAAS,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,cAAkB;;;;;;;;;;CAWjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,KA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;;;;;;;;;;;;;;;;;;;;;;;;ACxHT,SAAgB,aACd,QACiC;CACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACGT,SAAgB,iBAAmD,SAAgF;CACjJ,QAAQ,YAAY,QAAQ,WAAY,EAAE,CAAc;;;;;;;;;;;;;;;;;;;;;;;ACnB1D,SAAgB,aAAyC,QAAsC;CAC7F,OAAO;;;;;;;;;;;;;;;;;;;;;;;ACrBT,MAAa,gBAAgB,oBAAoB;CAC/C,MAAM,wBAAQ,IAAI,KAAqB;CAEvC,OAAO;EACL,MAAM;EACN,MAAM,QAAQ,KAAa;GACzB,OAAO,MAAM,IAAI,IAAI;;EAEvB,MAAM,QAAQ,KAAa;GACzB,OAAO,MAAM,IAAI,IAAI,IAAI;;EAE3B,MAAM,QAAQ,KAAa,OAAe;GACxC,MAAM,IAAI,KAAK,MAAM;;EAEvB,MAAM,WAAW,KAAa;GAC5B,MAAM,OAAO,IAAI;;EAEnB,MAAM,QAAQ,MAAe;GAC3B,MAAM,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;GAC9B,OAAO,OAAO,KAAK,QAAQ,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG;;EAEzD,MAAM,MAAM,MAAe;GACzB,IAAI,CAAC,MAAM;IACT,MAAM,OAAO;IACb;;GAEF,KAAK,MAAM,OAAO,MAAM,MAAM,EAC5B,IAAI,IAAI,WAAW,KAAK,EACtB,MAAM,OAAO,IAAI;;EAIxB;EACD"}
1
+ {"version":3,"file":"index.js","names":["#emitter","NodeEventEmitter","#options","#transformParam","#eachParam"],"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","../package.json","../src/createStorage.ts","../src/FileProcessor.ts","../src/storages/fsStorage.ts","../src/createKubb.ts","../src/createRenderer.ts","../src/defineGenerator.ts","../src/defineLogger.ts","../src/defineMiddleware.ts","../src/defineParser.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 { PossiblePromise } from '@internals/utils'\nimport type { ImportNode, InputNode, InputStreamNode, SchemaNode } from '@kubb/ast'\n\n/**\n * Source data passed to an adapter's `parse` function.\n * Mirrors the config input shape with paths resolved to absolute.\n */\nexport type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }\n\n/**\n * Generic type parameters for an adapter definition.\n *\n * - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)\n * - `TOptions` — user-facing options passed to the adapter factory\n * - `TResolvedOptions` — options after defaults applied\n * - `TDocument` — type of the parsed source document\n */\nexport type AdapterFactoryOptions<\n TName extends string = string,\n TOptions extends object = object,\n TResolvedOptions extends object = TOptions,\n TDocument = unknown,\n> = {\n name: TName\n options: TOptions\n resolvedOptions: TResolvedOptions\n document: TDocument\n}\n\n/**\n * Adapter that converts input files or data into an `InputNode`.\n *\n * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's\n * universal intermediate representation that all plugins consume.\n *\n * @example\n * ```ts\n * import { adapterOas } from '@kubb/adapter-oas'\n *\n * export default defineConfig({\n * adapter: adapterOas(),\n * input: { path: './openapi.yaml' },\n * plugins: [pluginTs(), pluginZod()],\n * })\n * ```\n */\nexport type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {\n /**\n * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).\n */\n name: TOptions['name']\n /**\n * Resolved adapter options after defaults have been applied.\n */\n options: TOptions['resolvedOptions']\n /**\n * Parsed source document after the first `parse()` call. `null` before parsing.\n */\n document: TOptions['document'] | null\n /**\n * Parse the source into a universal `InputNode`.\n */\n parse: (source: AdapterSource) => PossiblePromise<InputNode>\n /**\n * Extract `ImportNode` entries for a schema tree.\n * Returns an empty array before the first `parse()` call.\n *\n * The `resolve` callback receives the collision-corrected schema name and must\n * return `{ name, path }` for the import, or `undefined` to skip it.\n */\n getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>\n /**\n * Validate the document at the given path or URL.\n */\n validate: (input: string, options?: { throwOnError?: boolean }) => Promise<void>\n /**\n * Lightweight pre-flight count of schemas and operations without parsing AST nodes.\n * The adapter should cache the loaded document so subsequent `parse()` or `stream()` calls\n * do not reload it.\n *\n * Used by the core to decide whether to use `parse()` or `stream()`.\n */\n count?: (source: AdapterSource) => Promise<{ schemas: number; operations: number }>\n /**\n * Memory-efficient streaming variant of `parse()`.\n *\n * Returns an `InputStreamNode` whose `schemas` and `operations` are `AsyncIterable`.\n * Each `for await` loop creates a fresh parse pass over the cached in-memory document —\n * no pre-built arrays are held in memory.\n */\n stream?: (source: AdapterSource) => Promise<InputStreamNode>\n}\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","","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 { CodeNode, FileNode } from '@kubb/ast'\nimport { extractStringsFromNodes } from '@kubb/ast'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport type { Parser } from './defineParser.ts'\n\ntype ParseOptions = {\n parsers?: Map<FileNode['extname'], Parser>\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n}\n\nexport type FileProcessorEvents = {\n start: [files: Array<FileNode>]\n update: [params: { file: FileNode; source?: string; processed: number; total: number; percentage: number }]\n end: [files: Array<FileNode>]\n}\n\nexport type ParsedFile = {\n file: FileNode\n source: string\n processed: number\n total: number\n percentage: number\n}\n\nfunction joinSources(file: FileNode): string {\n 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 events = new AsyncEventEmitter<FileProcessorEvents>()\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 /**\n * Streams parsed files one at a time as each is processed.\n *\n * Unlike `run()`, files are yielded immediately after parsing rather than batched.\n * Storage writes can begin as soon as the first file is ready, keeping peak\n * memory proportional to one file at a time instead of the full batch.\n */\n async *stream(files: ReadonlyArray<FileNode>, options: ParseOptions = {}): AsyncGenerator<ParsedFile> {\n const total = files.length\n let processed = 0\n\n for (const file of files) {\n const source = await this.parse(file, options)\n processed++\n yield { file, source, processed, total, percentage: (processed / total) * 100 }\n }\n }\n\n async run(files: Array<FileNode>, options: ParseOptions = {}): Promise<Array<FileNode>> {\n await this.events.emit('start', files)\n\n for await (const { file, source, processed, total, percentage } of this.stream(files, options)) {\n await this.events.emit('update', { file, source, processed, percentage, total })\n }\n\n await this.events.emit('end', files)\n\n return files\n }\n}\n","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 * 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 return false\n }\n },\n async getItem(key: string) {\n try {\n return await readFile(resolve(key), 'utf8')\n } catch (_error) {\n return null\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 resolvedBase = resolve(base ?? process.cwd())\n\n async function* walk(dir: string, prefix: string): AsyncGenerator<string, void, undefined> {\n let entries: Array<Dirent>\n try {\n entries = (await readdir(dir, {\n withFileTypes: true,\n })) as Array<Dirent>\n } catch (_error) {\n return\n }\n for (const entry of entries) {\n const rel = prefix ? `${prefix}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n yield* walk(join(dir, entry.name), rel)\n } else {\n yield rel\n }\n }\n }\n\n const keys: Array<string> = []\n for await (const key of walk(resolvedBase, '')) {\n keys.push(key)\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 { resolve } from 'node:path'\nimport { version as nodeVersion } from 'node:process'\nimport type { PossiblePromise } from '@internals/utils'\nimport { AsyncEventEmitter, BuildError, exists, formatMs, getElapsedMs, URLPath } from '@internals/utils'\nimport type { FileNode, InputNode, InputStreamNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { collectUsedSchemaNames, transform, walk } from '@kubb/ast'\nimport { version as KubbVersion } from '../package.json'\nimport { DEFAULT_BANNER, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL, STREAM_FLUSH_EVERY, STREAM_SCHEMA_THRESHOLD } from './constants.ts'\nimport type { Adapter, AdapterSource } from './createAdapter.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport { createStorage, type Storage } from './createStorage.ts'\nimport type { GeneratorContext, Generator } from './defineGenerator.ts'\nimport type { Middleware } from './defineMiddleware.ts'\nimport type { Parser } from './defineParser.ts'\nimport type { KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NormalizedPlugin, Plugin } from './definePlugin.ts'\nimport { FileProcessor } from './FileProcessor.ts'\nimport { applyHookResult, PluginDriver } from './PluginDriver.ts'\nimport { fsStorage } from './storages/fsStorage.ts'\n\n/**\n * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.\n * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`\n * without requiring changes to core.\n *\n * @internal\n */\ntype ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}\n\n/**\n * Reference to an input file to generate code from.\n *\n * Specify an absolute path or a path relative to the config file location.\n * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.\n */\nexport type InputPath = {\n /**\n * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.\n *\n * @example\n * ```ts\n * { path: './petstore.yaml' }\n * { path: '/absolute/path/to/openapi.json' }\n * ```\n */\n path: string\n}\n\n/**\n * Inline input data to generate code from.\n *\n * Useful when you want to pass the specification directly instead of from a file.\n * Can be a string (YAML/JSON) or a parsed object.\n */\nexport type InputData = {\n /**\n * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.\n *\n * @example\n * ```ts\n * { data: fs.readFileSync('./openapi.yaml', 'utf8') }\n * { data: { openapi: '3.1.0', info: { ... } } }\n * ```\n */\n data: string | unknown\n}\n\ntype Input = InputPath | InputData\n\n/**\n * Build configuration for Kubb code generation.\n *\n * The Config is the main entry point for customizing how Kubb generates code. It specifies:\n * - What to generate from (adapter + input)\n * - Where to output generated code (output)\n * - How to generate (plugins + middleware)\n * - Runtime details (parsers, storage, renderer)\n *\n * See `UserConfig` for a relaxed version with sensible defaults.\n *\n * @private\n */\nexport type Config<TInput = Input> = {\n /**\n * Display name for this configuration in CLI output and logs.\n * Useful when running multiple builds with `defineConfig` arrays.\n *\n * @example\n * ```ts\n * name: 'api-client'\n * ```\n */\n name?: string\n /**\n * Project root directory, absolute or relative to the config file.\n * @default process.cwd()\n */\n root: string\n /**\n * Parsers that convert generated files to strings.\n * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).\n * A fallback parser is appended for unhandled extensions.\n * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.\n *\n * @default [parserTs] from `@kubb/parser-ts`\n * @example\n * ```ts\n * import { parserTs, tsxParser } from '@kubb/parser-ts'\n * export default defineConfig({\n * parsers: [parserTs, tsxParser],\n * })\n * ```\n */\n parsers: Array<Parser>\n /**\n * Adapter that parses input files into the universal `InputNode` representation.\n * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.\n *\n * When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files\n * injected via `injectFile` are written, but no AST walk occurs and generator hooks\n * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.\n *\n * @example\n * ```ts\n * import { adapterOas } from '@kubb/adapter-oas'\n * export default defineConfig({\n * adapter: adapterOas(),\n * input: { path: './petstore.yaml' },\n * })\n * ```\n */\n adapter?: Adapter\n /**\n * Source file or data to generate code from.\n * Use `input.path` for a file path or `input.data` for inline data.\n * Required when an adapter is configured; omit when running in plugin-only mode.\n */\n input?: TInput\n output: {\n /**\n * Output directory for generated files, absolute or relative to `root`.\n *\n * All generated files will be written under this directory. Subdirectories can be created\n * by plugins based on grouping strategy (by tag, path, etc.).\n *\n * @example\n * ```ts\n * output: {\n * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.\n * }\n * ```\n */\n path: string\n /**\n * Remove all files from the output directory before starting the build.\n *\n * Useful to ensure old generated files aren't mixed with new ones.\n * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.\n *\n * @default false\n * @example\n * ```ts\n * clean: true // wipes ./src/gen/* before generating\n * ```\n */\n clean?: boolean\n /**\n * Auto-format generated files after code generation completes.\n *\n * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter\n * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).\n *\n * @default false\n * @example\n * ```ts\n * format: 'auto' // auto-detect prettier, biome, or oxfmt\n * format: 'prettier' // force prettier\n * format: false // skip formatting\n * ```\n */\n format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false\n /**\n * Auto-lint generated files after code generation completes.\n *\n * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter\n * is available on your system. Pass `false` to skip linting.\n *\n * @default false\n * @example\n * ```ts\n * lint: 'auto' // auto-detect oxlint, biome, or eslint\n * lint: 'eslint' // force eslint\n * lint: false // skip linting\n * ```\n */\n lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false\n /**\n * Map file extensions to different output extensions.\n *\n * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).\n * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.\n *\n * @default { '.ts': '.ts' }\n * @example\n * ```ts\n * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'\n * extension: { '.ts': '', '.tsx': '.jsx' }\n * ```\n */\n extension?: Record<FileNode['extname'], FileNode['extname'] | ''>\n /**\n * Banner text prepended to every generated file.\n *\n * Useful for auto-generation notices or license headers. Choose a preset or write custom text.\n * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.\n *\n * @default 'simple'\n * @example\n * ```ts\n * defaultBanner: 'simple' // \"This file was autogenerated by Kubb\"\n * defaultBanner: 'full' // adds source, title, description, API version\n * defaultBanner: false // no banner\n * ```\n */\n defaultBanner?: 'simple' | 'full' | false\n /**\n * When `true`, overwrites existing files. When `false`, skips generated files that already exist.\n *\n * Individual plugins can override this setting. This is useful for preventing accidental data loss\n * when re-generating while you have local edits in the output folder.\n *\n * @default false\n * @example\n * ```ts\n * override: true // regenerate everything, even existing files\n * override: false // skip files that already exist\n * ```\n */\n override?: boolean\n } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>\n /**\n * Storage backend that controls where and how generated files are persisted.\n *\n * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,\n * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.\n *\n * @default fsStorage()\n * @example\n * ```ts\n * import { memoryStorage } from '@kubb/core'\n *\n * // Keep generated files in memory (useful for testing, CI pipelines)\n * storage: memoryStorage()\n *\n * // Use custom S3 storage\n * storage: myS3Storage()\n * ```\n *\n * @see {@link Storage} interface for implementing custom backends.\n */\n storage: Storage\n /**\n * Plugins that execute during the build to generate code and transform the AST.\n *\n * Each plugin processes the AST produced by the adapter and can emit files for different\n * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).\n * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.\n *\n * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.\n *\n * @example\n * ```ts\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginZod } from '@kubb/plugin-zod'\n *\n * plugins: [\n * pluginTs({ output: { path: './src/gen' } }),\n * pluginZod({ output: { path: './src/gen' } }),\n * ]\n * ```\n */\n plugins: Array<Plugin>\n /**\n * Middleware instances that observe build events and post-process generated code.\n *\n * Middleware fires AFTER all plugins for each event. Perfect for tasks like:\n * - Auditing what was generated\n * - Adding barrel/index files\n * - Validating output\n * - Running custom transformations\n *\n * @example\n * ```ts\n * import { middlewareBarrel } from '@kubb/middleware-barrel'\n *\n * middleware: [middlewareBarrel()]\n * ```\n *\n * @see {@link defineMiddleware} to create custom middleware.\n */\n middleware?: Array<Middleware>\n /**\n * Renderer that converts generated AST nodes to code strings.\n *\n * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support\n * different output formats (template engines, code generation DSLs, etc.).\n *\n * @default rendererJsx() // from @kubb/renderer-jsx\n * @example\n * ```ts\n * import { rendererJsx } from '@kubb/renderer-jsx'\n * renderer: rendererJsx()\n * ```\n *\n * @see {@link Renderer} to implement a custom renderer.\n */\n renderer?: RendererFactory\n /**\n * Kubb Studio cloud integration settings.\n *\n * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.\n * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.\n *\n * @default false // disabled by default\n * @example\n * ```ts\n * devtools: true // use default Kubb Studio\n * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance\n * ```\n */\n devtools?:\n | true\n | {\n /**\n * Override the Kubb Studio base URL.\n * @default 'https://kubb.studio'\n */\n studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})\n }\n /**\n * Lifecycle hooks that execute during or after the build process.\n *\n * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.\n * Currently supports the `done` hook which fires after all plugins and middleware complete.\n *\n * @example\n * ```ts\n * hooks: {\n * done: 'prettier --write \"./src/gen\"', // auto-format generated files\n * // or multiple commands:\n * done: ['prettier --write \"./src/gen\"', 'eslint --fix \"./src/gen\"']\n * }\n * ```\n */\n hooks?: {\n /**\n * Command(s) to run after all plugins and middleware complete generation.\n *\n * Useful for post-processing: formatting, linting, copying files, or custom validation.\n * Pass a single command string or array of command strings to run sequentially.\n * Commands are executed relative to the `root` directory.\n *\n * @example\n * ```ts\n * done: 'prettier --write \"./src/gen\"'\n * done: ['prettier --write \"./src/gen\"', 'eslint --fix \"./src/gen\"']\n * ```\n */\n done?: string | Array<string>\n }\n}\n\n/**\n * Partial `Config` for user-facing entry points with sensible defaults.\n *\n * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`\n * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,\n * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * input: { path: './petstore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs(), pluginZod()],\n * })\n * ```\n */\nexport type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage'> & {\n /**\n * Project root directory, absolute or relative to the config file location.\n * @default process.cwd()\n */\n root?: string\n /**\n * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).\n * @default [parserTs] // from `@kubb/parser-ts`\n */\n parsers?: Array<Parser>\n /**\n * Adapter that parses your API specification into Kubb's universal AST.\n * When omitted, Kubb runs in plugin-only mode.\n */\n adapter?: Adapter\n /**\n * Plugins that execute during the build to generate code and transform the AST.\n * @default []\n */\n plugins?: Array<Plugin>\n /**\n * Storage backend that controls where and how generated files are persisted.\n * @default fsStorage()\n */\n storage?: Storage\n}\n\ndeclare global {\n namespace Kubb {\n /**\n * Registry that maps plugin names to their `PluginFactoryOptions`.\n * Augment this interface in each plugin's `types.ts` to enable automatic\n * typing for `getPlugin` and `requirePlugin`.\n *\n * @example\n * ```ts\n * // packages/plugin-ts/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface PluginRegistry {\n * 'plugin-ts': PluginTs\n * }\n * }\n * }\n * ```\n */\n interface PluginRegistry {}\n\n /**\n * Extension point for root `Config['output']` options.\n * Augment the `output` key in middleware or plugin packages to add extra fields\n * to the global output configuration without touching core types.\n *\n * @example\n * ```ts\n * // packages/middleware-barrel/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface ConfigOptionsRegistry {\n * output: {\n * barrel?: import('./types.ts').BarrelConfig | false\n * }\n * }\n * }\n * }\n * ```\n */\n interface ConfigOptionsRegistry {}\n\n /**\n * Extension point for per-plugin `Output` options.\n * Augment the `output` key in middleware or plugin packages to add extra fields\n * to the per-plugin output configuration without touching core types.\n *\n * @example\n * ```ts\n * // packages/middleware-barrel/src/types.ts\n * declare global {\n * namespace Kubb {\n * interface PluginOptionsRegistry {\n * output: {\n * barrel?: import('./types.ts').PluginBarrelConfig | false\n * }\n * }\n * }\n * }\n * ```\n */\n interface PluginOptionsRegistry {}\n }\n}\n\n/**\n * Lifecycle events emitted during Kubb code generation.\n * Use these for logging, progress tracking, and custom integrations.\n *\n * @example\n * ```typescript\n * import type { AsyncEventEmitter } from '@internals/utils'\n * import type { KubbHooks } from '@kubb/core'\n *\n * const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()\n *\n * hooks.on('kubb:lifecycle:start', () => {\n * console.log('Starting Kubb generation')\n * })\n *\n * hooks.on('kubb:plugin:end', ({ plugin, duration }) => {\n * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)\n * })\n * ```\n */\nexport interface KubbHooks {\n 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext]\n 'kubb:lifecycle:end': []\n 'kubb:config:start': []\n 'kubb:config:end': [ctx: KubbConfigEndContext]\n 'kubb:generation:start': [ctx: KubbGenerationStartContext]\n 'kubb:generation:end': [ctx: KubbGenerationEndContext]\n 'kubb:generation:summary': [ctx: KubbGenerationSummaryContext]\n 'kubb:format:start': []\n 'kubb:format:end': []\n 'kubb:lint:start': []\n 'kubb:lint:end': []\n 'kubb:hooks:start': []\n 'kubb:hooks:end': []\n 'kubb:hook:start': [ctx: KubbHookStartContext]\n 'kubb:hook:end': [ctx: KubbHookEndContext]\n 'kubb:version:new': [ctx: KubbVersionNewContext]\n 'kubb:info': [ctx: KubbInfoContext]\n 'kubb:error': [ctx: KubbErrorContext]\n 'kubb:success': [ctx: KubbSuccessContext]\n 'kubb:warn': [ctx: KubbWarnContext]\n 'kubb:debug': [ctx: KubbDebugContext]\n 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext]\n 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext]\n 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext]\n 'kubb:plugin:start': [ctx: KubbPluginStartContext]\n 'kubb:plugin:end': [ctx: KubbPluginEndContext]\n 'kubb:plugin:setup': [ctx: KubbPluginSetupContext]\n 'kubb:build:start': [ctx: KubbBuildStartContext]\n 'kubb:plugins:end': [ctx: KubbPluginsEndContext]\n 'kubb:build:end': [ctx: KubbBuildEndContext]\n 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext]\n 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext]\n 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext]\n}\n\nexport type KubbBuildStartContext = {\n config: Config\n adapter: Adapter\n inputNode: InputNode\n getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin(name: string): Plugin | undefined\n readonly files: ReadonlyArray<FileNode>\n upsertFile: (...files: Array<FileNode>) => void\n}\n\nexport type KubbPluginsEndContext = {\n config: Config\n readonly files: ReadonlyArray<FileNode>\n upsertFile: (...files: Array<FileNode>) => void\n}\n\nexport type KubbBuildEndContext = {\n files: Array<FileNode>\n config: Config\n outputDir: string\n}\n\nexport type KubbLifecycleStartContext = {\n version: string\n}\n\nexport type KubbConfigEndContext = {\n configs: Array<Config>\n}\n\nexport type KubbGenerationStartContext = {\n config: Config\n}\n\nexport type KubbGenerationEndContext = {\n config: Config\n /**\n * Read-only view of the files Kubb wrote during this build.\n *\n * Keys are scoped to this run; files from earlier builds are not included.\n * Reads go directly to `config.storage`, so nothing is buffered in memory.\n *\n * @example Read a generated file\n * ```ts\n * const code = await storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example Walk every generated file\n * ```ts\n * for (const path of await storage.getKeys()) {\n * const code = await storage.getItem(path)\n * }\n * ```\n */\n storage: Storage\n}\n\nexport type KubbGenerationSummaryContext = {\n config: Config\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n status: 'success' | 'failed'\n hrStart: [number, number]\n filesCreated: number\n pluginTimings?: Map<Plugin['name'], number>\n}\n\nexport type KubbVersionNewContext = {\n currentVersion: string\n latestVersion: string\n}\n\nexport type KubbInfoContext = {\n message: string\n info?: string\n}\n\nexport type KubbErrorContext = {\n error: Error\n meta?: Record<string, unknown>\n}\n\nexport type KubbSuccessContext = {\n message: string\n info?: string\n}\n\nexport type KubbWarnContext = {\n message: string\n info?: string\n}\n\nexport type KubbDebugContext = {\n date: Date\n logs: Array<string>\n fileName?: string\n}\n\nexport type KubbFilesProcessingStartContext = {\n files: Array<FileNode>\n}\n\nexport type KubbFileProcessingUpdateContext = {\n processed: number\n total: number\n percentage: number\n source?: string\n file: FileNode\n config: Config\n}\n\nexport type KubbFilesProcessingEndContext = {\n files: Array<FileNode>\n}\n\nexport type KubbHookStartContext = {\n id?: string\n command: string\n args?: readonly string[]\n}\n\nexport type KubbHookEndContext = {\n id?: string\n command: string\n args?: readonly string[]\n success: boolean\n error: Error | null\n}\n\n/**\n * CLI options derived from command-line flags.\n */\nexport type CLIOptions = {\n config?: string\n watch?: boolean\n /** @default 'silent' */\n logLevel?: 'silent' | 'info' | 'debug'\n}\n\n/**\n * All accepted forms of a Kubb configuration.\n * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`.\n */\nexport type PossibleConfig<TCliOptions = undefined> =\n | PossiblePromise<Config | Config[]>\n | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)\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 * Read-only view of every file written during this build.\n *\n * Keys are limited to this run. Reads go straight to `config.storage`,\n * so nothing extra is held in memory.\n *\n * @example Read a generated file\n * ```ts\n * const code = await buildOutput.storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example List all generated file paths\n * ```ts\n * const paths = await buildOutput.storage.getKeys()\n * ```\n */\n storage: Storage\n}\n\n/**\n * Kubb code generation instance returned by {@link createKubb}.\n *\n * Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.\n * For a single one-off build, chain directly: `await createKubb(config).build()`.\n */\nexport type Kubb = {\n /**\n * Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.\n */\n readonly hooks: AsyncEventEmitter<KubbHooks>\n /**\n * Read-only view of the files from the most recent `build()` or `safeBuild()` call.\n * Only populated after the build completes.\n *\n * Keys are scoped to the current run. Reads go straight to `config.storage`,\n * so nothing extra is held in memory.\n *\n * @example Read a generated file\n * ```ts\n * const { storage } = await kubb.safeBuild()\n * const code = await storage.getItem('/src/gen/pet.ts')\n * ```\n *\n * @example Walk every generated file\n * ```ts\n * for (const path of await kubb.storage.getKeys()) {\n * const code = await kubb.storage.getItem(path)\n * }\n * ```\n */\n readonly storage: Storage\n /**\n * Plugin driver managing all plugins. Available after `setup()` completes.\n */\n readonly driver: PluginDriver\n /**\n * Resolved configuration with defaults applied. Available after `setup()` completes.\n */\n readonly config: Config\n /**\n * Resolves config and initializes the driver. `build()` calls this automatically.\n */\n setup(): Promise<void>\n /**\n * Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.\n */\n build(): Promise<BuildOutput>\n /**\n * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.\n */\n safeBuild(): Promise<BuildOutput>\n}\n\ntype SetupResult = {\n hooks: AsyncEventEmitter<KubbHooks>\n driver: PluginDriver\n storage: Storage\n config: Config\n dispose: () => void\n [Symbol.dispose](): void\n}\n\n/**\n * Builds a `Storage` view scoped to the file paths produced by the current build.\n *\n * Reads delegate to the underlying `storage` (typically `fsStorage()`) so source bytes\n * stay where they were written instead of being held in an extra in-memory map.\n * Writing via `setItem` stores the content in the underlying storage and registers the\n * key so subsequent reads and `getKeys` are scoped to this build's output.\n */\nfunction createSourcesView(storage: Storage): Storage {\n const paths = new Set<string>()\n return createStorage(() => ({\n name: `${storage.name}:sources`,\n async hasItem(key: string) {\n return paths.has(key) && (await storage.hasItem(key))\n },\n async getItem(key: string) {\n return paths.has(key) ? storage.getItem(key) : null\n },\n async setItem(key: string, value: string) {\n paths.add(key)\n await storage.setItem(key, value)\n },\n async removeItem(key: string) {\n paths.delete(key)\n await storage.removeItem(key)\n },\n async getKeys(base?: string) {\n if (!base) return [...paths]\n const result: Array<string> = []\n for (const key of paths) {\n if (key.startsWith(base)) result.push(key)\n }\n return result\n },\n async clear() {\n paths.clear()\n await storage.clear()\n },\n }))()\n}\n\nasync function setup(userConfig: UserConfig, options: SetupOptions = {}): Promise<SetupResult> {\n const hooks = options.hooks ?? new AsyncEventEmitter<KubbHooks>()\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 extension: DEFAULT_EXTENSION,\n defaultBanner: DEFAULT_BANNER,\n ...userConfig.output,\n },\n storage: userConfig.storage ?? fsStorage(),\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 const driver = new PluginDriver(config, {\n hooks,\n })\n const storage: Storage = createSourcesView(config.storage)\n const diagnosticInfo = getDiagnosticInfo()\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: ${config.storage.name}`,\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 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 config.storage.clear(resolve(config.root, config.output.path))\n }\n\n // Register middleware hooks after all plugin hooks are registered.\n // Because AsyncEventEmitter calls listeners in registration order,\n // middleware hooks for any event fire after all plugin hooks for that event.\n // Handlers are tracked so they can be removed after each build (disposeMiddleware),\n // preventing accumulation when multiple configs share the same hooks instance.\n const middlewareListeners: Array<[keyof KubbHooks & string, (...args: never[]) => void | Promise<void>]> = []\n\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 middlewareListeners.push([event, handler as (...args: never[]) => void | Promise<void>])\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\n if (config.adapter.count && config.adapter.stream) {\n const { schemas: schemaCount, operations: operationCount } = await config.adapter.count(source)\n\n if (schemaCount > STREAM_SCHEMA_THRESHOLD) {\n driver.inputStreamNode = await config.adapter.stream(source)\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [\n `✓ Adapter '${config.adapter.name}' streaming InputStreamNode`,\n ` • Schemas: ${schemaCount} (threshold: ${STREAM_SCHEMA_THRESHOLD})`,\n ` • Operations: ${operationCount}`,\n ],\n })\n } else {\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 } else {\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\n return {\n config,\n hooks,\n driver,\n storage,\n dispose,\n [Symbol.dispose]: dispose,\n }\n\n function dispose() {\n driver.dispose()\n for (const [event, handler] of middlewareListeners) {\n hooks.off(event, handler as never)\n }\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 */\ntype PluginStreamEntry = {\n plugin: NormalizedPlugin\n context: GeneratorContext\n hrStart: ReturnType<typeof process.hrtime>\n}\n\n/**\n * Single-pass fan-out for streaming mode.\n *\n * Iterates `inputStreamNode.schemas` and `.operations` exactly once, distributing each\n * node to every plugin in parallel. This replaces the N-pass-per-plugin pattern (where\n * each plugin got its own `for await` iterator) with a single parse pass fanned to all\n * plugins — eliminating the N×parse-time overhead for multi-plugin builds.\n *\n * Each plugin still gets independent `plugin:start` / `plugin:end` events and its own\n * timing, but the schema and operation nodes are parsed only once total.\n */\nasync function runPluginStreamHooks(\n inputStreamNode: InputStreamNode,\n entries: PluginStreamEntry[],\n driver: PluginDriver,\n hooks: AsyncEventEmitter<KubbHooks>,\n config: Config,\n pluginTimings: Map<string, number>,\n failedPlugins: Set<{ plugin: Plugin; error: Error }>,\n flushPendingFiles: () => Promise<void>,\n): Promise<void> {\n type PluginState = {\n plugin: NormalizedPlugin\n generatorContext: GeneratorContext\n generators: Generator[]\n hrStart: ReturnType<typeof process.hrtime>\n failed: boolean\n error: Error | undefined\n }\n\n function resolveRendererFor(gen: Generator, state: PluginState): RendererFactory | undefined {\n return gen.renderer === null ? undefined : (gen.renderer ?? state.plugin.renderer ?? state.generatorContext.config.renderer)\n }\n\n const states: PluginState[] = entries.map(({ plugin, context, hrStart }) => ({\n plugin,\n generatorContext: { ...context, resolver: driver.getResolver(plugin.name) },\n generators: plugin.generators ?? [],\n hrStart,\n failed: false,\n error: undefined,\n }))\n\n let schemasProcessed = 0\n for await (const node of inputStreamNode.schemas) {\n for (const state of states) {\n if (state.failed) continue\n try {\n const { plugin, generatorContext, generators } = state\n const { exclude, include, override } = plugin.options\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = generatorContext.resolver.resolveOptions(transformedNode, { options: plugin.options, exclude, include, override })\n if (options === null) continue\n\n const ctx = { ...generatorContext, options }\n for (const gen of generators) {\n if (!gen.schema) continue\n const result = await gen.schema(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:schema', transformedNode, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n schemasProcessed++\n if (schemasProcessed % STREAM_FLUSH_EVERY === 0) {\n await flushPendingFiles()\n }\n }\n\n const collectedOperations: OperationNode[] = []\n for await (const node of inputStreamNode.operations) {\n collectedOperations.push(node)\n for (const state of states) {\n if (state.failed) continue\n try {\n const { plugin, generatorContext, generators } = state\n const { exclude, include, override } = plugin.options\n const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node\n const options = generatorContext.resolver.resolveOptions(transformedNode, { options: plugin.options, exclude, include, override })\n if (options === null) continue\n\n const ctx = { ...generatorContext, options }\n for (const gen of generators) {\n if (!gen.operation) continue\n const result = await gen.operation(transformedNode, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:operation', transformedNode, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n }\n\n // After stream: gen.operations for each plugin, then emit plugin:end\n for (const state of states) {\n if (!state.failed) {\n try {\n const { plugin, generatorContext, generators } = state\n const ctx = { ...generatorContext, options: plugin.options }\n for (const gen of generators) {\n if (!gen.operations) continue\n const result = await gen.operations(collectedOperations, ctx)\n await applyHookResult(result, driver, resolveRendererFor(gen, state))\n }\n await driver.hooks.emit('kubb:generate:operations', collectedOperations, ctx)\n } catch (caughtError) {\n state.failed = true\n state.error = caughtError as Error\n }\n }\n\n const duration = getElapsedMs(state.hrStart)\n pluginTimings.set(state.plugin.name, duration)\n\n await hooks.emit('kubb:plugin:end', {\n plugin: state.plugin,\n duration,\n success: !state.failed,\n ...(state.failed && state.error ? { error: state.error } : {}),\n config,\n get files() {\n return driver.fileManager.files\n },\n upsertFile: (...files) => driver.fileManager.upsert(...files),\n })\n\n if (state.failed && state.error) {\n failedPlugins.add({ plugin: state.plugin, error: state.error })\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [state.failed ? '✗ Plugin start failed' : `✓ Plugin started successfully (${formatMs(duration)})`],\n })\n }\n\n await flushPendingFiles()\n}\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. adapterOas()) 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 // ── BATCH PATH ────────────────────────────────────────────────────────────\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 await Promise.all(\n generators\n .filter((gen) => gen.schema)\n .map(async (gen) => {\n const result = await gen.schema!(transformedNode, ctx)\n return applyHookResult(result, driver, resolveRenderer(gen))\n }),\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 await Promise.all(\n generators\n .filter((gen) => gen.operation)\n .map(async (gen) => {\n const result = await gen.operation!(transformedNode, ctx)\n return applyHookResult(result, driver, resolveRenderer(gen))\n }),\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 using _cleanup = setupResult\n const { driver, hooks, 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 const writtenPaths = new Set<string>()\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 const fileProcessor = new FileProcessor()\n\n async function flushPendingFiles(snapshot?: ReadonlySet<string>): Promise<void> {\n const files = driver.fileManager.files.filter((f) => !writtenPaths.has(f.path) && (!snapshot || !snapshot.has(f.path)))\n if (files.length === 0) {\n return\n }\n\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`Writing ${files.length} files...`],\n })\n\n await hooks.emit('kubb:files:processing:start', { files })\n\n const stream = fileProcessor.stream(files, { parsers: parsersMap, extension: config.output.extension })\n\n for await (const { file, source, processed, total, percentage } of stream) {\n await hooks.emit('kubb:file:processing:update', { file, source, processed, total, percentage, config })\n if (source) {\n await storage.setItem(file.path, source)\n }\n writtenPaths.add(file.path)\n }\n\n await hooks.emit('kubb:files:processing:end', { files })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ File write process completed for ${files.length} files`],\n })\n }\n\n try {\n await driver.emitSetupHooks()\n\n if (driver.adapter && (driver.inputNode || driver.inputStreamNode)) {\n await hooks.emit('kubb:build:start', {\n config,\n adapter: driver.adapter,\n inputNode: driver.inputNode ?? { kind: 'Input' as const, schemas: [], operations: [], meta: driver.inputStreamNode?.meta },\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 const inputStreamNode = driver.inputStreamNode\n if (inputStreamNode) {\n // ── STREAMING: fan-out single-pass ────────────────────────────────────\n // Emit plugin:start for all plugins up front, collect generator-plugins\n // for the fan-out pass, then handle non-generator plugins immediately.\n const streamPluginEntries: PluginStreamEntry[] = []\n\n for (const plugin of driver.plugins.values()) {\n const context = driver.getContext(plugin)\n const hrStart = process.hrtime()\n\n await hooks.emit('kubb:plugin:start', { plugin })\n await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: ['Starting plugin...', ` • Plugin Name: ${plugin.name}`],\n })\n\n if (plugin.generators?.length || driver.hasRegisteredGenerators(plugin.name)) {\n streamPluginEntries.push({ plugin, context, hrStart })\n } else {\n // No generators: plugin ran via setup hooks; finish it now.\n const duration = getElapsedMs(hrStart)\n pluginTimings.set(plugin.name, duration)\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 await hooks.emit('kubb:debug', {\n date: new Date(),\n logs: [`✓ Plugin started successfully (${formatMs(duration)})`],\n })\n }\n }\n\n if (streamPluginEntries.length > 0) {\n await runPluginStreamHooks(inputStreamNode, streamPluginEntries, driver, hooks, config, pluginTimings, failedPlugins, flushPendingFiles)\n }\n } else {\n // ── BATCH: existing per-plugin sequential loop ────────────────────────\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 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 await flushPendingFiles()\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 await flushPendingFiles()\n\n const files = driver.fileManager.files\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 storage,\n }\n } catch (error) {\n return {\n failedPlugins,\n files: [],\n driver,\n pluginTimings,\n error: error as Error,\n storage,\n }\n }\n}\n\nasync function build(setupResult: SetupResult): Promise<BuildOutput> {\n const { files, driver, failedPlugins, pluginTimings, error, storage } = 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 storage,\n }\n}\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\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\nfunction inputToAdapterSource(config: Config): AdapterSource {\n const input = config.input\n if (!input) {\n throw new Error('[kubb] input is required when using an adapter. Provide input.path or input.data in your config.')\n }\n\n if ('data' in input) {\n return { type: 'data', data: input.data }\n }\n\n if (new URLPath(input.path).isURL) {\n return { type: 'path', path: input.path }\n }\n\n const resolved = resolve(config.root, input.path)\n\n return { type: 'path', path: resolved }\n}\n\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`, `storage`, `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 storage() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing storage')\n }\n return setupResult.storage\n },\n get driver() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing driver')\n }\n return setupResult.driver\n },\n get config() {\n if (!setupResult) {\n throw new Error('[kubb] setup() must be called before accessing config')\n }\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 * `TElement` is the type the renderer accepts, for example `KubbReactElement`\n * for `@kubb/renderer-jsx` or a custom type for your own renderer. Defaults to\n * `unknown` so generators that don't care about the element type work without\n * specifying it.\n */\nexport type Renderer<TElement = unknown> = {\n /**\n * Renders `element` and populates {@link files} with the resulting {@link FileNode} objects.\n * Called once per render cycle; must resolve before {@link files} is read.\n */\n render(element: TElement): Promise<void>\n /**\n * Tears down the renderer and releases any held resources.\n * Pass an `Error` to signal a failure, a number for an exit code, or omit for a clean shutdown.\n */\n unmount(error?: Error | number | null): void\n /**\n * Accumulated {@link FileNode} results produced by the last {@link render} call.\n * Not populated when {@link stream} is implemented.\n */\n readonly files: Array<FileNode>\n /**\n * When present, core calls this instead of {@link render} and {@link files},\n * forwarding each file to `FileManager` as soon as it is ready.\n * Implementing this method enables per-file streaming without buffering the full result set.\n */\n stream?(element: TElement): AsyncIterable<FileNode>\n}\n\n/**\n * A factory function that produces a fresh {@link Renderer} per render cycle.\n *\n * Generators use this to declare which renderer handles their output.\n */\nexport type RendererFactory<TElement = unknown> = () => Renderer<TElement>\n\n/**\n * Wraps a renderer factory for use in generator definitions.\n *\n * @example\n * ```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 */\nexport function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement> {\n return factory\n}\n","import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'\nimport type { FileNode, InputNode, OperationNode, SchemaNode, Visitor } from '@kubb/ast'\nimport type { Adapter } from './createAdapter.ts'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { KubbHooks } from './types.ts'\nimport type { PluginDriver } from './PluginDriver.ts'\nimport type { Plugin, PluginFactoryOptions } from './definePlugin.ts'\nimport type { Resolver } from './defineResolver.ts'\nimport type { Config, DevtoolsOptions } from './types.ts'\n\n/**\n * Context object passed to generator `schema`, `operation`, and `operations` methods.\n *\n * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks\n * are needed. `ctx.options` carries resolved per-node options after exclude/include/override\n * filtering for individual schema/operation calls, or plugin-level options for operations.\n */\nexport type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n config: Config\n /**\n * Absolute path to the current plugin's output directory.\n */\n root: string\n /**\n * Determine output mode based on the output config.\n * Returns `'single'` when `output.path` is a file, `'split'` for a directory.\n */\n getMode: (output: { path: string }) => 'single' | 'split'\n driver: PluginDriver\n /**\n * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.\n */\n getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin(name: string): Plugin | undefined\n /**\n * Get a plugin by name, throws an error if not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin(name: string): Plugin\n /**\n * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver(name: string): Resolver\n /**\n * Add files only if they don't exist.\n */\n addFile: (...file: Array<FileNode>) => Promise<void>\n /**\n * Merge sources into the same output file.\n */\n upsertFile: (...file: Array<FileNode>) => Promise<void>\n hooks: AsyncEventEmitter<KubbHooks>\n /**\n * The current plugin instance.\n */\n plugin: Plugin<TOptions>\n /**\n * The current plugin's resolver.\n */\n resolver: TOptions['resolver']\n /**\n * The current plugin's transformer.\n */\n transformer: Visitor | undefined\n /**\n * Emit a warning.\n */\n warn: (message: string) => void\n /**\n * Emit an error.\n */\n error: (error: string | Error) => void\n /**\n * Emit an info message.\n */\n info: (message: string) => void\n /**\n * Open the current input node in Kubb Studio.\n */\n openInStudio: (options?: DevtoolsOptions) => Promise<void>\n /**\n * The configured adapter instance.\n */\n adapter: Adapter\n /**\n * The universal `InputNode` produced by the adapter.\n */\n inputNode: InputNode\n /**\n * Resolved options after exclude/include/override filtering.\n */\n options: TOptions['resolvedOptions']\n}\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 { AsyncEventEmitter } from '@internals/utils'\nimport type { logLevel } from './constants.ts'\nimport type { KubbHooks } from './types.ts'\n\nexport type LoggerOptions = {\n /**\n * Log level for output verbosity.\n * @default 3\n */\n logLevel: (typeof logLevel)[keyof typeof logLevel]\n}\n\n/**\n * Shared context passed to plugins, parsers, and other internals.\n */\nexport type LoggerContext = AsyncEventEmitter<KubbHooks>\n\nexport type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {\n name: string\n install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>\n}\n\nexport type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>\n\n/**\n * Wraps a logger definition into a typed {@link Logger}.\n *\n * The optional second type parameter `TInstallReturn` allows loggers to return\n * a value from `install` — for example, a sink factory that the caller can\n * forward to hook execution.\n *\n * @example Basic logger\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 *\n * @example Logger that returns a hook sink factory\n * ```ts\n * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({\n * name: 'my-logger',\n * install(context, options) {\n * // … register event handlers …\n * return (commandWithArgs) => ({ onStdout: console.log })\n * },\n * })\n * ```\n */\nexport function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(\n logger: UserLogger<Options, TInstallReturn>,\n): Logger<Options, TInstallReturn> {\n return logger\n}\n","import type { KubbHooks } from './types.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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAa,aAAb,cAAgC,MAAM;CACpC;CAEA,YAAY,SAAiB,SAAkD;EAC7E,MAAM,SAAS,EAAE,OAAO,QAAQ,OAAO,CAAC;EACxC,KAAK,OAAO;EACZ,KAAK,SAAS,QAAQ;;;;;;;;;;;;;;AAe1B,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;;;;;ACZlE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;EAC5B,KAAKA,SAAS,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,cAAkB;;;;;;;;;;CAWjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,KAAKD,SAAS,UAAU,UAAU;EAEpD,IAAI,UAAU,WAAW,GACvB;EAGF,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,MAAM,SAAS,GAAG,UAAU;WACrB,KAAK;GACZ,IAAI;GACJ,IAAI;IACF,iBAAiB,KAAK,UAAU,UAAU;WACpC;IACN,iBAAiB,OAAO,UAAU;;GAEpC,MAAM,IAAI,MAAM,gCAAgC,UAAU,mBAAmB,kBAAkB,EAAE,OAAO,QAAQ,IAAI,EAAE,CAAC;;;;;;;;;;;CAa7H,GAA8C,WAAuB,SAAmD;EACtH,KAAKA,SAAS,GAAG,WAAW,QAAoC;;;;;;;;;;CA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