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

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.
@@ -201,10 +201,9 @@ function matchesSchemaPattern(node, type, pattern) {
201
201
  * - `camelCase` for everything else.
202
202
  */
203
203
  function defaultResolver(name, type) {
204
- let resolvedName = camelCase(name);
205
- if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
206
- if (type === "type") resolvedName = pascalCase(name);
207
- return resolvedName;
204
+ if (type === "file" || type === "function") return camelCase(name, { isFile: type === "file" });
205
+ if (type === "type") return pascalCase(name);
206
+ return camelCase(name);
208
207
  }
209
208
  /**
210
209
  * Default option resolver — applies include/exclude filters and merges matching override options.
@@ -229,7 +228,8 @@ function defaultResolver(name, type) {
229
228
  * // → { enumType: 'enum' } when operationId matches
230
229
  * ```
231
230
  */
232
- function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
231
+ const resolveOptionsCache = /* @__PURE__ */ new WeakMap();
232
+ function computeOptions(node, options, exclude, include, override) {
233
233
  if ((0, _kubb_ast.isOperationNode)(node)) {
234
234
  if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
235
235
  if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
@@ -253,6 +253,19 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
253
253
  }
254
254
  return options;
255
255
  }
256
+ function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
257
+ const optionsKey = options;
258
+ let byOptions = resolveOptionsCache.get(optionsKey);
259
+ if (!byOptions) {
260
+ byOptions = /* @__PURE__ */ new WeakMap();
261
+ resolveOptionsCache.set(optionsKey, byOptions);
262
+ }
263
+ const cached = byOptions.get(node);
264
+ if (cached !== void 0) return cached.value;
265
+ const result = computeOptions(node, options, exclude, include, override);
266
+ byOptions.set(node, { value: result });
267
+ return result;
268
+ }
256
269
  /**
257
270
  * Default path resolver used by `defineResolver`.
258
271
  *
@@ -299,16 +312,18 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
299
312
  */
300
313
  function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
301
314
  if ((pathMode ?? getMode(node_path.default.resolve(root, output.path))) === "single") return node_path.default.resolve(root, output.path);
302
- let result;
303
- if (group && (groupPath || tag)) {
304
- const groupValue = group.type === "path" ? groupPath : tag;
305
- const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
306
- const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
307
- return segment ? camelCase(segment) : "";
308
- };
309
- const resolveName = group.name ?? defaultName;
310
- result = node_path.default.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
311
- } else result = node_path.default.resolve(root, output.path, baseName);
315
+ const result = (() => {
316
+ if (group && (groupPath || tag)) {
317
+ const groupValue = group.type === "path" ? groupPath : tag;
318
+ const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
319
+ const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
320
+ return segment ? camelCase(segment) : "";
321
+ };
322
+ const resolveName = group.name ?? defaultName;
323
+ return node_path.default.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
324
+ }
325
+ return node_path.default.resolve(root, output.path, baseName);
326
+ })();
312
327
  const outputDir = node_path.default.resolve(root, output.path);
313
328
  const outputDirWithSep = outputDir.endsWith(node_path.default.sep) ? outputDir : `${outputDir}${node_path.default.sep}`;
314
329
  if (result !== outputDir && !result.startsWith(outputDirWithSep)) throw new Error(`[Kubb] Resolved path "${result}" is outside the output directory "${outputDir}". This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.`);
@@ -366,12 +381,16 @@ function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
366
381
  */
367
382
  function buildDefaultBanner({ title, description, version, config }) {
368
383
  try {
369
- let source = "";
370
- if (Array.isArray(config.input)) {
371
- const first = config.input[0];
372
- if (first && "path" in first) source = node_path.default.basename(first.path);
373
- } else if (config.input && "path" in config.input) source = node_path.default.basename(config.input.path);
374
- else if (config.input && "data" in config.input) source = "text content";
384
+ const source = (() => {
385
+ if (Array.isArray(config.input)) {
386
+ const first = config.input[0];
387
+ if (first && "path" in first) return node_path.default.basename(first.path);
388
+ return "";
389
+ }
390
+ if (config.input && "path" in config.input) return node_path.default.basename(config.input.path);
391
+ if (config.input && "data" in config.input) return "text content";
392
+ return "";
393
+ })();
375
394
  let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
376
395
  if (config.output.defaultBanner === "simple") {
377
396
  banner += "*/\n";
@@ -850,7 +869,11 @@ var PluginDriver = class PluginDriver {
850
869
  if (gen.schema) {
851
870
  const schemaHandler = async (node, ctx) => {
852
871
  if (ctx.plugin.name !== pluginName) return;
853
- await applyHookResult(await gen.schema(node, ctx), this, resolveRenderer());
872
+ await applyHookResult({
873
+ result: await gen.schema(node, ctx),
874
+ driver: this,
875
+ rendererFactory: resolveRenderer()
876
+ });
854
877
  };
855
878
  this.hooks.on("kubb:generate:schema", schemaHandler);
856
879
  this.#trackHookListener("kubb:generate:schema", schemaHandler);
@@ -858,7 +881,11 @@ var PluginDriver = class PluginDriver {
858
881
  if (gen.operation) {
859
882
  const operationHandler = async (node, ctx) => {
860
883
  if (ctx.plugin.name !== pluginName) return;
861
- await applyHookResult(await gen.operation(node, ctx), this, resolveRenderer());
884
+ await applyHookResult({
885
+ result: await gen.operation(node, ctx),
886
+ driver: this,
887
+ rendererFactory: resolveRenderer()
888
+ });
862
889
  };
863
890
  this.hooks.on("kubb:generate:operation", operationHandler);
864
891
  this.#trackHookListener("kubb:generate:operation", operationHandler);
@@ -866,7 +893,11 @@ var PluginDriver = class PluginDriver {
866
893
  if (gen.operations) {
867
894
  const operationsHandler = async (nodes, ctx) => {
868
895
  if (ctx.plugin.name !== pluginName) return;
869
- await applyHookResult(await gen.operations(nodes, ctx), this, resolveRenderer());
896
+ await applyHookResult({
897
+ result: await gen.operations(nodes, ctx),
898
+ driver: this,
899
+ rendererFactory: resolveRenderer()
900
+ });
870
901
  };
871
902
  this.hooks.on("kubb:generate:operations", operationsHandler);
872
903
  this.#trackHookListener("kubb:generate:operations", operationsHandler);
@@ -960,7 +991,8 @@ var PluginDriver = class PluginDriver {
960
991
  driver.fileManager.upsert(...files);
961
992
  },
962
993
  get inputNode() {
963
- return driver.inputNode ?? {
994
+ if (driver.inputNode) return driver.inputNode;
995
+ return {
964
996
  kind: "Input",
965
997
  schemas: [],
966
998
  operations: [],
@@ -1014,7 +1046,7 @@ var PluginDriver = class PluginDriver {
1014
1046
  * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result
1015
1047
  * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.
1016
1048
  */
1017
- async function applyHookResult(result, driver, rendererFactory) {
1049
+ function applyHookResult({ result, driver, rendererFactory }) {
1018
1050
  if (!result) return;
1019
1051
  if (Array.isArray(result)) {
1020
1052
  driver.fileManager.upsert(...result);
@@ -1022,11 +1054,20 @@ async function applyHookResult(result, driver, rendererFactory) {
1022
1054
  }
1023
1055
  if (!rendererFactory) return;
1024
1056
  const renderer = rendererFactory();
1025
- if (renderer.stream) for await (const file of renderer.stream(result)) driver.fileManager.upsert(file);
1026
- else {
1027
- await renderer.render(result);
1028
- driver.fileManager.upsert(...renderer.files);
1057
+ if (renderer.stream) {
1058
+ for (const file of renderer.stream(result)) driver.fileManager.upsert(file);
1059
+ renderer.unmount();
1060
+ return;
1029
1061
  }
1062
+ return applyAsyncRender({
1063
+ renderer,
1064
+ result,
1065
+ driver
1066
+ });
1067
+ }
1068
+ async function applyAsyncRender({ renderer, result, driver }) {
1069
+ await renderer.render(result);
1070
+ driver.fileManager.upsert(...renderer.files);
1030
1071
  renderer.unmount();
1031
1072
  }
1032
1073
  //#endregion
@@ -1103,4 +1144,4 @@ Object.defineProperty(exports, "logLevel", {
1103
1144
  }
1104
1145
  });
1105
1146
 
1106
- //# sourceMappingURL=PluginDriver-Bc-k8EUQ.cjs.map
1147
+ //# sourceMappingURL=PluginDriver-DXp767s2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginDriver-DXp767s2.cjs","names":["path","#cache","#store","#filesCache","#pluginsWithEventGenerators","#resolvers","#defaultResolvers","#hookListeners","#normalizePlugin","#trackHookListener","#createDefaultResolver","#studioIsOpen","openInStudioFn"],"sources":["../../../internals/utils/src/casing.ts","../src/constants.ts","../src/definePlugin.ts","../src/defineResolver.ts","../src/devtools.ts","../src/FileManager.ts","../src/PluginDriver.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n *\n * Empty segments are filtered before joining. They arise when the text starts with\n * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`\n * and `'..'` transforms to an empty string). Without this filter the join would produce\n * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing\n * generated files to escape the configured output directory.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => transformPart(part, i === parts.length - 1))\n .filter(Boolean)\n .join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","import type { FileNode } from '@kubb/ast'\n\n/**\n * Base URL for the Kubb Studio web app.\n */\nexport const DEFAULT_STUDIO_URL = 'https://kubb.studio' as const\n\n/**\n * Default banner style written at the top of every generated file.\n */\nexport const DEFAULT_BANNER = 'simple' as const\n\n/**\n * Default file-extension mapping used when no explicit mapping is configured.\n */\nexport const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }\n\n/**\n * Schema count above which the adapter's `stream()` path is used instead of `parse()`.\n */\nexport const STREAM_SCHEMA_THRESHOLD = 100\n\n/**\n * In streaming mode, flush generated files to disk every N schemas to bound in-memory file buffers.\n */\nexport const STREAM_FLUSH_EVERY = 50\n\n/**\n * Numeric log-level thresholds used internally to compare verbosity.\n *\n * Higher numbers are more verbose.\n */\nexport const logLevel = {\n silent: Number.NEGATIVE_INFINITY,\n error: 0,\n warn: 1,\n info: 3,\n verbose: 4,\n debug: 5,\n} as const\n","import { extname } from 'node:path'\nimport type { FileNode, HttpMethod, InputNode, UserFileNode, Visitor } from '@kubb/ast'\nimport type { RendererFactory } from './createRenderer.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Resolver } from './defineResolver.ts'\nimport type { Config, KubbHooks } from './types.ts'\n\n/**\n * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.\n * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`\n * without requiring changes to core.\n *\n * @internal\n */\ntype ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}\n\n/**\n * Output configuration for generated files.\n */\nexport type Output<_TOptions = unknown> = {\n /**\n * Output folder or file path for generated code.\n */\n path: string\n /**\n * Text or function prepended to every generated file.\n * When a function, receives the current `InputNode` and returns a string.\n */\n banner?: string | ((node?: InputNode) => string)\n /**\n * Text or function appended to every generated file.\n * When a function, receives the current `InputNode` and returns a string.\n */\n footer?: string | ((node?: InputNode) => string)\n /**\n * Whether to override existing external files if they already exist.\n * @default false\n */\n override?: boolean\n} & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>\n\nexport type Group = {\n /**\n * How to group files into subdirectories.\n * - `'tag'` — group by OpenAPI tags\n * - `'path'` — group by OpenAPI paths\n */\n type: 'tag' | 'path'\n /**\n * Function that returns the subdirectory name for a group value.\n * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.\n */\n name?: (context: { group: string }) => string\n}\n\ntype ByTag = {\n /**\n * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.\n */\n type: 'tag'\n /**\n * Tag name to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByOperationId = {\n /**\n * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.\n */\n type: 'operationId'\n /**\n * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByPath = {\n /**\n * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.\n */\n type: 'path'\n /**\n * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.\n */\n pattern: string | RegExp\n}\n\ntype ByMethod = {\n /**\n * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.\n */\n type: 'method'\n /**\n * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).\n */\n pattern: HttpMethod | RegExp\n}\n// TODO implement as alternative for ByMethod\n// type ByMethods = {\n// type: 'methods'\n// pattern: Array<HttpMethod>\n// }\n\ntype BySchemaName = {\n /**\n * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.\n */\n type: 'schemaName'\n /**\n * Schema name to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\ntype ByContentType = {\n /**\n * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.\n */\n type: 'contentType'\n /**\n * Content type to match (case-sensitive). Can be a literal string or regex pattern.\n */\n pattern: string | RegExp\n}\n\n/**\n * A pattern filter that prevents matching nodes from being generated.\n *\n * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints\n * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.\n *\n * @example\n * ```ts\n * exclude: [\n * { type: 'tag', pattern: 'internal' }, // skip \"internal\" tag\n * { type: 'path', pattern: /^\\/admin/ }, // skip all /admin endpoints\n * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern\n * ]\n * ```\n */\nexport type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName\n\n/**\n * A pattern filter that restricts generation to only matching nodes.\n *\n * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service\n * tag or only for \"production\" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.\n *\n * @example\n * ```ts\n * include: [\n * { type: 'tag', pattern: 'public' }, // generate only \"public\" tag\n * { type: 'path', pattern: /^\\/api\\/v1/ }, // generate only v1 endpoints\n * ]\n * ```\n */\nexport type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName\n\n/**\n * A pattern filter paired with partial option overrides applied when the pattern matches.\n *\n * Use to customize generation for specific operations or schemas. For example, apply different output paths\n * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,\n * HTTP method, schema name, or content type.\n *\n * @example\n * ```ts\n * override: [\n * {\n * type: 'tag',\n * pattern: 'admin',\n * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder\n * },\n * {\n * type: 'operationId',\n * pattern: 'listPets',\n * options: { exclude: true } // skip this specific operation\n * }\n * ]\n * ```\n */\nexport type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {\n //TODO should be options: Omit<Partial<TOptions>, 'override'>\n options: Partial<TOptions>\n}\n\nexport type PluginFactoryOptions<\n /**\n * Unique plugin name.\n */\n TName extends string = string,\n /**\n * User-facing plugin options.\n */\n TOptions extends object = object,\n /**\n * Plugin options after defaults are applied.\n */\n TResolvedOptions extends object = TOptions,\n /**\n * Resolver that encapsulates naming and path-resolution helpers.\n * Define with `defineResolver` and export alongside the plugin.\n */\n TResolver extends Resolver = Resolver,\n> = {\n name: TName\n options: TOptions\n resolvedOptions: TResolvedOptions\n resolver: TResolver\n}\n\n/**\n * Context for hook-style plugin `kubb:plugin:setup` handler.\n * Provides methods to register generators, configure resolvers, transformers, and renderers.\n */\nexport type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {\n /**\n * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)\n * just like generators declared statically on `createPlugin`.\n */\n addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void\n /**\n * Set or override the resolver for this plugin.\n * The resolver controls file naming and path resolution.\n */\n setResolver(resolver: Partial<TFactory['resolver']>): void\n /**\n * Set the AST transformer to pre-process nodes before they reach generators.\n */\n setTransformer(visitor: Visitor): void\n /**\n * Set the renderer factory to process JSX elements from generators.\n */\n setRenderer(renderer: RendererFactory): void\n /**\n * Set resolved options merged into the normalized plugin's `options`.\n * Call this in `kubb:plugin:setup` to provide options generators need.\n */\n setOptions(options: TFactory['resolvedOptions']): void\n /**\n * Inject a raw file into the build output, bypassing the generation pipeline.\n */\n injectFile(userFileNode: UserFileNode): void\n /**\n * Merge a partial config update into the current build configuration.\n */\n updateConfig(config: Partial<Config>): void\n /**\n * The resolved build configuration at setup time.\n */\n config: Config\n /**\n * The plugin's user-provided options.\n */\n options: TFactory['options']\n}\n\n/**\n * A plugin object produced by `definePlugin`.\n * Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property\n * (matching Astro's integration naming convention).\n *\n * @template TFactory - The plugin's `PluginFactoryOptions` type.\n */\nexport type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {\n /**\n * Unique name for the plugin, following the same naming convention as `createPlugin`.\n */\n name: string\n /**\n * Plugins that must be registered before this plugin executes.\n * An error is thrown at startup when any listed dependency is missing.\n */\n dependencies?: Array<string>\n /**\n * Controls the execution order of this plugin relative to others.\n *\n * - `'pre'` — runs before all normal plugins.\n * - `'post'` — runs after all normal plugins.\n * - `undefined` (default) — runs in declaration order among normal plugins.\n *\n * Dependency constraints always take precedence over `enforce`.\n */\n enforce?: 'pre' | 'post'\n /**\n * The options passed by the user when calling the plugin factory.\n */\n options?: TFactory['options']\n /**\n * Lifecycle event handlers for this plugin.\n * Any event from the global `KubbHooks` map can be subscribed to here.\n */\n hooks: {\n [K in keyof KubbHooks as K extends 'kubb:plugin:setup' ? never : K]?: (...args: KubbHooks[K]) => void | Promise<void>\n } & {\n 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>\n }\n}\n\n/**\n * Normalized plugin after setup, with runtime fields populated.\n * For internal use only — plugins use the public `Plugin` type externally.\n *\n * @internal\n */\nexport type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {\n options: TOptions['resolvedOptions'] & {\n output: Output\n include?: Array<Include>\n exclude: Array<Exclude>\n override: Array<Override<TOptions['resolvedOptions']>>\n }\n resolver: TOptions['resolver']\n transformer?: Visitor\n renderer?: RendererFactory\n generators?: Array<Generator>\n apply?: (config: Config) => boolean\n version?: string\n}\n\nexport type KubbPluginStartContext = {\n plugin: NormalizedPlugin\n}\n\nexport type KubbPluginEndContext = {\n plugin: NormalizedPlugin\n duration: number\n success: boolean\n error?: Error\n config: Config\n /**\n * Returns all files currently in the file manager (lazy snapshot).\n * Includes files added by plugins that have already run.\n */\n readonly files: ReadonlyArray<FileNode>\n /**\n * Upsert one or more files into the file manager.\n */\n upsertFile: (...files: Array<FileNode>) => void\n}\n\n/**\n * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.\n *\n * Handlers live in a single `hooks` object (inspired by Astro integrations).\n * All lifecycle events from `KubbHooks` are available for subscription.\n *\n * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.\n * Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).\n *\n * @example\n * ```ts\n * import { definePlugin } from '@kubb/core'\n *\n * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({\n * name: 'plugin-ts',\n * hooks: {\n * 'kubb:plugin:setup'(ctx) {\n * ctx.setResolver(resolverTs)\n * },\n * },\n * }))\n * ```\n */\nexport function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(\n factory: (options: TFactory['options']) => Plugin<TFactory>,\n): (options?: TFactory['options']) => Plugin<TFactory> {\n return (options) => factory(options ?? ({} as TFactory['options']))\n}\n\n/**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n * Used to determine whether an output path targets a single file or a directory.\n */\nexport function getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n if (!fileOrFolder) return 'split'\n return extname(fileOrFolder) ? 'single' : 'split'\n}\n","import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'\nimport type { PluginFactoryOptions } from './definePlugin.ts'\nimport { getMode } from './definePlugin.ts'\nimport type { Config, Group, Output } from './types.ts'\n\n/**\n * Type/string pattern filter for include/exclude/override matching.\n */\ntype PatternFilter = {\n type: string\n pattern: string | RegExp\n}\n\n/**\n * Pattern filter with partial option overrides applied when the pattern matches.\n */\ntype PatternOverride<TOptions> = PatternFilter & {\n options: Omit<Partial<TOptions>, 'override'>\n}\n\n/**\n * Context for resolving filtered options for a given operation or schema node.\n *\n * @internal\n */\nexport type ResolveOptionsContext<TOptions> = {\n options: TOptions\n exclude?: Array<PatternFilter>\n include?: Array<PatternFilter>\n override?: Array<PatternOverride<TOptions>>\n}\n\n/**\n * Base constraint for all plugin resolver objects.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.\n *\n * @example\n * ```ts\n * type MyResolver = Resolver & {\n * resolveName(node: SchemaNode): string\n * resolveTypedName(node: SchemaNode): string\n * }\n * ```\n */\nexport type Resolver = {\n name: string\n pluginName: string\n default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string\n resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null\n resolvePath(params: ResolverPathParams, context: ResolverContext): string\n resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode\n resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined\n resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined\n}\n\n/**\n * File-specific parameters for `Resolver.resolvePath`.\n *\n * Pass alongside a `ResolverContext` to identify which file to resolve.\n * Provide `tag` for tag-based grouping or `path` for path-based grouping.\n *\n * @example\n * ```ts\n * resolver.resolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n */\nexport type ResolverPathParams = {\n baseName: FileNode['baseName']\n pathMode?: 'single' | 'split'\n /**\n * Tag value used when `group.type === 'tag'`.\n */\n tag?: string\n /**\n * Path value used when `group.type === 'path'`.\n */\n path?: string\n}\n\n/**\n * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.\n *\n * Describes where on disk output is rooted, which output config is active, and the optional\n * grouping strategy that controls subdirectory layout.\n *\n * @example\n * ```ts\n * const context: ResolverContext = {\n * root: config.root,\n * output,\n * group,\n * }\n * ```\n */\nexport type ResolverContext = {\n root: string\n output: Output\n group?: Group\n /**\n * Plugin name used to populate `meta.pluginName` on the resolved file.\n */\n pluginName?: string\n}\n\n/**\n * File-specific parameters for `Resolver.resolveFile`.\n *\n * Pass alongside a `ResolverContext` to fully describe the file to resolve.\n * `tag` and `path` are used only when a matching `group` is present in the context.\n *\n * @example\n * ```ts\n * resolver.resolveFile(\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport type ResolverFileParams = {\n name: string\n extname: FileNode['extname']\n /**\n * Tag value used when `group.type === 'tag'`.\n */\n tag?: string\n /**\n * Path value used when `group.type === 'path'`.\n */\n path?: string\n}\n\n/**\n * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.\n *\n * `output` is optional — not every plugin configures a banner/footer.\n * `config` carries the global Kubb config, used to derive the default Kubb banner.\n *\n * @example\n * ```ts\n * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })\n * // → '// generated'\n * ```\n */\nexport type ResolveBannerContext = {\n output?: Pick<Output, 'banner' | 'footer'>\n config: Config\n}\n\n/**\n * Builder type for the plugin-specific resolver fields.\n *\n * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`\n * are optional — built-in fallbacks are injected when omitted.\n *\n * Methods in the returned object can call sibling resolver methods via `this`.\n */\ntype ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<\n T['resolver'],\n 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'\n> &\n Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {\n name: string\n pluginName: T['name']\n } & ThisType<T['resolver']>\n\n// String patterns are compiled lazily and cached — the same filter is reused for every node.\nconst stringPatternCache = new Map<string, RegExp>()\n\nfunction testPattern(value: string, pattern: string | RegExp): boolean {\n if (typeof pattern === 'string') {\n let regex = stringPatternCache.get(pattern)\n if (!regex) {\n regex = new RegExp(pattern)\n stringPatternCache.set(pattern, regex)\n }\n return regex.test(value)\n }\n // Use .match() for user-supplied RegExp to preserve semantics regardless of `g`/`y` flags.\n return value.match(pattern) !== null\n}\n\n/**\n * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).\n */\nfunction matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {\n switch (type) {\n case 'tag':\n return node.tags.some((tag) => testPattern(tag, pattern))\n case 'operationId':\n return testPattern(node.operationId, pattern)\n case 'path':\n return testPattern(node.path, pattern)\n case 'method':\n return testPattern(node.method.toLowerCase(), pattern)\n case 'contentType':\n return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false\n default:\n return false\n }\n}\n\n/**\n * Checks if a schema matches a pattern for a given filter type (`schemaName`).\n *\n * Returns `null` when the filter type doesn't apply to schemas.\n */\nfunction matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {\n switch (type) {\n case 'schemaName':\n return node.name ? testPattern(node.name, pattern) : false\n default:\n return null\n }\n}\n\n/**\n * Default name resolver used by `defineResolver`.\n *\n * - `camelCase` for `function` and `file` types.\n * - `PascalCase` for `type`.\n * - `camelCase` for everything else.\n */\nfunction defaultResolver(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n if (type === 'file' || type === 'function') return camelCase(name, { isFile: type === 'file' })\n if (type === 'type') return pascalCase(name)\n return camelCase(name)\n}\n\n/**\n * Default option resolver — applies include/exclude filters and merges matching override options.\n *\n * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.\n *\n * @example Include/exclude filtering\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { output: 'types' },\n * exclude: [{ type: 'tag', pattern: 'internal' }],\n * })\n * // → null when node has tag 'internal'\n * ```\n *\n * @example Override merging\n * ```ts\n * const options = defaultResolveOptions(operationNode, {\n * options: { enumType: 'asConst' },\n * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],\n * })\n * // → { enumType: 'enum' } when operationId matches\n * ```\n */\nconst resolveOptionsCache = new WeakMap<object, WeakMap<Node, { value: unknown }>>()\n\nfunction computeOptions<TOptions>(\n node: Node,\n options: TOptions,\n exclude: Array<PatternFilter>,\n include: Array<PatternFilter> | undefined,\n override: Array<PatternOverride<TOptions>>,\n): TOptions | null {\n if (isOperationNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null\n if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null\n\n const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options\n\n return { ...options, ...overrideOptions }\n }\n\n if (isSchemaNode(node)) {\n if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null\n if (include) {\n const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))\n const applicable = results.filter((r) => r !== null)\n\n if (applicable.length > 0 && !applicable.includes(true)) return null\n }\n const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options\n\n return { ...options, ...overrideOptions }\n }\n\n return options\n}\n\nexport function defaultResolveOptions<TOptions>(\n node: Node,\n { options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,\n): TOptions | null {\n const optionsKey = options as object\n let byOptions = resolveOptionsCache.get(optionsKey)\n if (!byOptions) {\n byOptions = new WeakMap()\n resolveOptionsCache.set(optionsKey, byOptions)\n }\n const cached = byOptions.get(node)\n if (cached !== undefined) return cached.value as TOptions | null\n\n const result = computeOptions(node, options, exclude, include, override)\n\n byOptions.set(node, { value: result })\n\n return result\n}\n\n/**\n * Default path resolver used by `defineResolver`.\n *\n * - Returns the output directory in `single` mode.\n * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.\n * - Falls back to a flat `output/baseName` path otherwise.\n *\n * A custom `group.name` function overrides the default subdirectory naming.\n * For `tag` groups the default is `${camelCase(tag)}Controller`.\n * For `path` groups the default is the first path segment after `/`.\n *\n * @example Flat output\n * ```ts\n * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })\n * // → '/src/types/petTypes.ts'\n * ```\n *\n * @example Tag-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → '/src/types/petsController/petTypes.ts'\n * ```\n *\n * @example Path-based grouping\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', path: '/pets/list' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },\n * )\n * // → '/src/types/pets/petTypes.ts'\n * ```\n *\n * @example Single-file mode\n * ```ts\n * defaultResolvePath(\n * { baseName: 'petTypes.ts', pathMode: 'single' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → '/src/types'\n * ```\n */\nexport function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n return path.resolve(root, output.path)\n }\n\n const result: string = (() => {\n if (group && (groupPath || tag)) {\n const groupValue = group.type === 'path' ? groupPath! : tag!\n const defaultName =\n group.type === 'tag'\n ? ({ group: g }: { group: string }) => `${camelCase(g)}Controller`\n : ({ group: g }: { group: string }) => {\n // Strip traversal components (empty, '.', '..') before taking the first meaningful segment.\n // When every segment is a traversal component (e.g. '../../') we fall back to '' so the\n // file is placed directly in the output root — the boundary check below ensures safety.\n const segment = g.split('/').filter((s) => s !== '' && s !== '.' && s !== '..')[0]\n return segment ? camelCase(segment) : ''\n }\n const resolveName = group.name ?? defaultName\n return path.resolve(root, output.path, resolveName({ group: groupValue }), baseName)\n }\n return path.resolve(root, output.path, baseName)\n })()\n\n // Ensure the resolved path stays within the configured output directory.\n // This prevents path traversal from malicious OpenAPI specs or custom group.name functions.\n // `result === outputDir` is intentionally permitted: it matches single-file mode paths and\n // edge cases where baseName resolves to the output directory itself.\n const outputDir = path.resolve(root, output.path)\n const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`\n if (result !== outputDir && !result.startsWith(outputDirWithSep)) {\n throw new Error(\n `[Kubb] Resolved path \"${result}\" is outside the output directory \"${outputDir}\". ` +\n 'This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.',\n )\n }\n\n return result\n}\n\n/**\n * Default file resolver used by `defineResolver`.\n *\n * Resolves a `FileNode` by combining name resolution (`resolver.default`) with\n * path resolution (`resolver.resolvePath`). The resolved file always has empty\n * `sources`, `imports`, and `exports` arrays — consumers populate those separately.\n *\n * In `single` mode the name is omitted and the file sits directly in the output directory.\n *\n * @example Resolve a schema file\n * ```ts\n * const file = defaultResolveFile.call(\n * resolver,\n * { name: 'pet', extname: '.ts' },\n * { root: '/src', output: { path: 'types' } },\n * )\n * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }\n * ```\n *\n * @example Resolve an operation file with tag grouping\n * ```ts\n * const file = defaultResolveFile.call(\n * resolver,\n * { name: 'listPets', extname: '.ts', tag: 'pets' },\n * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },\n * )\n * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }\n * ```\n */\nexport function defaultResolveFile(this: Resolver, { name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext): FileNode {\n const pathMode = getMode(path.resolve(context.root, context.output.path))\n const resolvedName = pathMode === 'single' ? '' : this.default(name, 'file')\n const baseName = `${resolvedName}${extname}` as FileNode['baseName']\n const filePath = this.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)\n\n return createFile({\n path: filePath,\n baseName: path.basename(filePath) as `${string}.${string}`,\n meta: {\n pluginName: this.pluginName,\n },\n sources: [],\n imports: [],\n exports: [],\n })\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from config and optional node metadata.\n */\nexport function buildDefaultBanner({\n title,\n description,\n version,\n config,\n}: {\n title?: string\n description?: string\n version?: string\n config: Config\n}): string {\n try {\n const source = (() => {\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) return path.basename(first.path)\n return ''\n }\n if (config.input && 'path' in config.input) return path.basename(config.input.path)\n if (config.input && 'data' in config.input) return 'text content'\n return ''\n })()\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * Default banner resolver — returns the banner string for a generated file.\n *\n * A user-supplied `output.banner` overrides the default Kubb \"Generated by Kubb\" notice.\n * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`\n * from the OAS spec when a `node` is provided).\n *\n * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.\n * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.\n * - When `output.banner` is a string, returns it directly.\n * - When `config.output.defaultBanner` is `false`, returns `undefined`.\n * - Otherwise returns the Kubb \"Generated by Kubb\" notice.\n *\n * @example String banner overrides default\n * ```ts\n * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })\n * // → '// my banner'\n * ```\n *\n * @example Function banner with node\n * ```ts\n * defaultResolveBanner(inputNode, { output: { banner: (node) => `// v${node.version}` }, config })\n * // → '// v3.0.0'\n * ```\n *\n * @example No user banner — Kubb notice with OAS metadata\n * ```ts\n * defaultResolveBanner(inputNode, { config })\n * // → '/** Generated by Kubb ... Title: Pet Store ... *\\/'\n * ```\n *\n * @example Disabled default banner\n * ```ts\n * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })\n * // → undefined\n * ```\n */\nexport function defaultResolveBanner(node: InputNode | undefined, { output, config }: ResolveBannerContext): string | undefined {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n\n if (config.output.defaultBanner === false) {\n return undefined\n }\n\n return buildDefaultBanner({\n title: node?.meta?.title,\n version: node?.meta?.version,\n config,\n })\n}\n\n/**\n * Default footer resolver — returns the footer string for a generated file.\n *\n * - When `output.footer` is a function and `node` is provided, calls it with the node.\n * - When `output.footer` is a function and `node` is absent, returns `undefined`.\n * - When `output.footer` is a string, returns it directly.\n * - Otherwise returns `undefined`.\n *\n * @example String footer\n * ```ts\n * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })\n * // → '// end of file'\n * ```\n *\n * @example Function footer with node\n * ```ts\n * defaultResolveFooter(inputNode, { output: { footer: (node) => `// ${node.title}` }, config })\n * // → '// Pet Store'\n * ```\n */\nexport function defaultResolveFooter(node: InputNode | undefined, { output }: ResolveBannerContext): string | undefined {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n}\n\n/**\n * Defines a resolver for a plugin, injecting built-in defaults for name casing,\n * include/exclude/override filtering, path resolution, and file construction.\n *\n * All four defaults can be overridden by providing them in the builder function:\n * - `default` — name casing strategy (camelCase / PascalCase)\n * - `resolveOptions` — include/exclude/override filtering\n * - `resolvePath` — output path computation\n * - `resolveFile` — full `FileNode` construction\n *\n * Methods in the returned object can call sibling resolver methods via `this`.\n *\n * @example Basic resolver with naming helpers\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveName(node) {\n * return this.default(node.name, 'function')\n * },\n * resolveTypedName(node) {\n * return this.default(node.name, 'type')\n * },\n * }))\n * ```\n *\n * @example Override resolvePath for a custom output structure\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'custom',\n * resolvePath({ baseName }, { root, output }) {\n * return path.resolve(root, output.path, 'generated', baseName)\n * },\n * }))\n * ```\n *\n * @example Use this.default inside a helper\n * ```ts\n * export const resolver = defineResolver<PluginTs>(() => ({\n * name: 'default',\n * resolveParamName(node, param) {\n * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')\n * },\n * }))\n * ```\n */\nexport function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {\n // `resolver` is kept so the default `resolveFile` wrapper can reference the fully assembled\n // object via `.call(resolver, ...)` at call-time, after the result is assigned below.\n let resolver: T['resolver']\n\n const result = {\n default: defaultResolver,\n resolveOptions: defaultResolveOptions,\n resolvePath: defaultResolvePath,\n resolveFile: (params: ResolverFileParams, context: ResolverContext) => defaultResolveFile.call(resolver as Resolver, params, context),\n resolveBanner: defaultResolveBanner,\n resolveFooter: defaultResolveFooter,\n ...build(),\n } as T['resolver']\n\n resolver = result\n\n return resolver\n}\n","import type { InputNode } from '@kubb/ast'\nimport { deflateSync, inflateSync } from 'fflate'\nimport { x } from 'tinyexec'\n\nexport type DevtoolsOptions = {\n /**\n * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.\n * @default false\n */\n ast?: boolean\n}\n\n/**\n * Encodes an `InputNode` as a compressed, URL-safe string.\n *\n * The JSON representation is deflate-compressed with {@link deflateSync} before\n * base64url encoding, which typically reduces payload size by 70–80 % and\n * keeps URLs well within browser and server path-length limits.\n *\n * Use {@link decodeAst} to reverse.\n */\nexport function encodeAst(input: InputNode): string {\n const compressed = deflateSync(new TextEncoder().encode(JSON.stringify(input)))\n return Buffer.from(compressed).toString('base64url')\n}\n\n/**\n * Decodes an `InputNode` from a string produced by {@link encodeAst}.\n *\n * Works in both Node.js and the browser — no streaming APIs required.\n */\nexport function decodeAst(encoded: string): InputNode {\n const bytes = Buffer.from(encoded, 'base64url')\n return JSON.parse(new TextDecoder().decode(inflateSync(bytes))) as InputNode\n}\n\n/**\n * Constructs the Kubb Studio URL for the given `InputNode`.\n * When `options.ast` is `true`, navigates to the AST inspector (`/ast`).\n * The `input` is encoded and attached as the `?root=` query parameter so Studio\n * can decode and render it without a round-trip to any server.\n */\nexport function getStudioUrl(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): string {\n const baseUrl = studioUrl.replace(/\\/$/, '')\n const path = options.ast ? '/ast' : ''\n\n return `${baseUrl}${path}?root=${encodeAst(input)}`\n}\n\n/**\n * Opens the Kubb Studio URL for the given `InputNode` in the default browser —\n *\n * Falls back to printing the URL if the browser cannot be launched.\n */\nexport async function openInStudio(input: InputNode, studioUrl: string, options: DevtoolsOptions = {}): Promise<void> {\n const url = getStudioUrl(input, studioUrl, options)\n\n const cmd = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open'\n const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url]\n\n try {\n await x(cmd, args)\n } catch {\n console.log(`\\n ${url}\\n`)\n }\n}\n","import type { FileNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\n\nfunction mergeFile<TMeta extends object = object>(a: FileNode<TMeta>, b: FileNode<TMeta>): FileNode<TMeta> {\n return {\n ...a,\n // Incoming file (b) takes precedence for banner/footer so that barrel files,\n // which never carry a banner, can clear banners set by plugin-generated files\n // at the same path.\n banner: b.banner,\n footer: b.footer,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\n/**\n * Collapses a list of files so that duplicates sharing the same `path` are merged\n * in arrival order. Keeps the original order of first occurrence.\n */\nfunction mergeFilesByPath(files: ReadonlyArray<FileNode>): Map<string, FileNode> {\n const merged = new Map<string, FileNode>()\n for (const file of files) {\n const existing = merged.get(file.path)\n merged.set(file.path, existing ? mergeFile(existing, file) : file)\n }\n return merged\n}\n\n/**\n * In-memory file store for generated files.\n *\n * Files with the same `path` are merged — sources, imports, and exports are concatenated.\n * The `files` getter returns all stored files sorted by path length (shortest first).\n *\n * @example\n * ```ts\n * import { FileManager } from '@kubb/core'\n *\n * const manager = new FileManager()\n * manager.upsert(myFile)\n * console.log(manager.files) // all stored files\n * ```\n */\nexport class FileManager {\n readonly #cache = new Map<string, FileNode>()\n #filesCache: Array<FileNode> | null = null\n\n /**\n * Adds one or more files. Incoming files with the same path are merged\n * (sources/imports/exports concatenated), but existing cache entries are\n * replaced — use {@link upsert} when you want to merge into the cache too.\n */\n add(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, false)\n }\n\n /**\n * Adds or merges one or more files.\n * If a file with the same path already exists in the cache, its\n * sources/imports/exports are merged into the incoming file.\n */\n upsert(...files: Array<FileNode>): Array<FileNode> {\n return this.#store(files, true)\n }\n\n #store(files: ReadonlyArray<FileNode>, mergeExisting: boolean): Array<FileNode> {\n const resolvedFiles: Array<FileNode> = []\n for (const file of mergeFilesByPath(files).values()) {\n const existing = mergeExisting ? this.#cache.get(file.path) : undefined\n const resolvedFile = createFile(existing ? mergeFile(existing, file) : file)\n this.#cache.set(resolvedFile.path, resolvedFile)\n resolvedFiles.push(resolvedFile)\n }\n this.#filesCache = null\n return resolvedFiles\n }\n\n getByPath(path: string): FileNode | null {\n return this.#cache.get(path) ?? null\n }\n\n deleteByPath(path: string): void {\n this.#cache.delete(path)\n this.#filesCache = null\n }\n\n clear(): void {\n this.#cache.clear()\n this.#filesCache = null\n }\n\n /**\n * Releases all stored files. Called by the core after `kubb:build:end` to\n * free the per-plugin FileNode caches for the rest of the process lifetime.\n */\n dispose(): void {\n this.clear()\n }\n\n [Symbol.dispose](): void {\n this.dispose()\n }\n\n /**\n * All stored files, sorted by path length (shorter paths first).\n */\n get files(): Array<FileNode> {\n if (this.#filesCache) {\n return this.#filesCache\n }\n\n this.#filesCache = [...this.#cache.values()].sort((a, b) => {\n const lenDiff = a.path.length - b.path.length\n if (lenDiff !== 0) return lenDiff\n // Within the same length bucket, index.ts barrel files go last so other\n // files are always processed before their barrel file.\n const aIsIndex = a.path.endsWith('/index.ts') || a.path === 'index.ts'\n const bIsIndex = b.path.endsWith('/index.ts') || b.path === 'index.ts'\n if (aIsIndex && !bIsIndex) return 1\n if (!aIsIndex && bIsIndex) return -1\n return 0\n })\n return this.#filesCache\n }\n}\n","import { resolve } from 'node:path'\nimport type { AsyncEventEmitter } from '@internals/utils'\nimport type { FileNode, InputNode, InputStreamNode, OperationNode, SchemaNode } from '@kubb/ast'\nimport { createFile } from '@kubb/ast'\nimport { DEFAULT_STUDIO_URL } from './constants.ts'\nimport type { Generator } from './defineGenerator.ts'\nimport type { Plugin } from './definePlugin.ts'\nimport { getMode } from './definePlugin.ts'\nimport { defineResolver } from './defineResolver.ts'\nimport { openInStudio as openInStudioFn } from './devtools.ts'\nimport { FileManager } from './FileManager.ts'\nimport type { RendererFactory } from './createRenderer.ts'\n\nimport type {\n Adapter,\n Config,\n DevtoolsOptions,\n GeneratorContext,\n KubbHooks,\n KubbPluginSetupContext,\n NormalizedPlugin,\n PluginFactoryOptions,\n Resolver,\n} from './types.ts'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\ntype Options = {\n hooks: AsyncEventEmitter<KubbHooks>\n}\n\nfunction enforceOrder(enforce: 'pre' | 'post' | undefined): number {\n return enforce === 'pre' ? -1 : enforce === 'post' ? 1 : 0\n}\n\nexport class PluginDriver {\n readonly config: Config\n readonly options: Options\n\n /**\n * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.\n *\n * @example\n * ```ts\n * PluginDriver.getMode('src/gen/types.ts') // 'single'\n * PluginDriver.getMode('src/gen/types') // 'split'\n * ```\n */\n static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {\n return getMode(fileOrFolder)\n }\n\n /**\n * The universal `@kubb/ast` `InputNode` produced by the adapter, set by\n * the build pipeline after the adapter's `parse()` resolves.\n */\n inputNode: InputNode | undefined = undefined\n /**\n * Set when the adapter returns a streaming `InputStreamNode` (large specs).\n * Mutually exclusive with `inputNode` — exactly one is set after adapter setup.\n */\n inputStreamNode: InputStreamNode | undefined = undefined\n adapter: Adapter | undefined = undefined\n #studioIsOpen = false\n\n /**\n * Central file store for all generated files.\n * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to\n * add files; this property gives direct read/write access when needed.\n */\n readonly fileManager = new FileManager()\n\n readonly plugins = new Map<string, NormalizedPlugin>()\n\n /**\n * Tracks which plugins have generators registered via `addGenerator()` (event-based path).\n * Used by the build loop to decide whether to emit generator events for a given plugin.\n */\n readonly #pluginsWithEventGenerators = new Set<string>()\n readonly #resolvers = new Map<string, Resolver>()\n readonly #defaultResolvers = new Map<string, Resolver>()\n readonly #hookListeners = new Map<keyof KubbHooks, Set<(...args: never[]) => void | Promise<void>>>()\n\n constructor(config: Config, options: Options) {\n this.config = config\n this.options = options\n config.plugins\n .map((rawPlugin) => this.#normalizePlugin(rawPlugin as Plugin))\n .filter((plugin) => {\n if (typeof plugin.apply === 'function') {\n return plugin.apply(config)\n }\n return true\n })\n .sort((a, b) => {\n if (b.dependencies?.includes(a.name)) return -1\n if (a.dependencies?.includes(b.name)) return 1\n // enforce: 'pre' plugins run first, 'post' plugins run last\n return enforceOrder(a.enforce) - enforceOrder(b.enforce)\n })\n .forEach((plugin) => {\n this.plugins.set(plugin.name, plugin)\n })\n }\n\n get hooks() {\n return this.options.hooks\n }\n\n /**\n * Creates an `NormalizedPlugin` from a hook-style plugin and registers\n * its lifecycle handlers on the `AsyncEventEmitter`.\n */\n #normalizePlugin(hookPlugin: Plugin): NormalizedPlugin {\n const normalizedPlugin = {\n name: hookPlugin.name,\n dependencies: hookPlugin.dependencies,\n enforce: hookPlugin.enforce,\n options: { output: { path: '.' }, exclude: [], override: [] },\n } as unknown as NormalizedPlugin\n\n this.registerPluginHooks(hookPlugin, normalizedPlugin)\n return normalizedPlugin\n }\n\n /**\n * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.\n *\n * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a\n * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and\n * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.\n *\n * All other hooks are iterated and registered directly as pass-through listeners.\n * Any event key present in the global `KubbHooks` interface can be subscribed to.\n *\n * External tooling can subscribe to any of these events via `hooks.on(...)` to observe\n * the plugin lifecycle without modifying plugin behavior.\n *\n * @internal\n */\n registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void {\n const { hooks } = hookPlugin\n\n if (!hooks) return\n\n // kubb:plugin:setup gets special treatment: the globally emitted context is wrapped with\n // plugin-specific implementations so that addGenerator / setResolver / etc. target\n // this plugin's normalizedPlugin entry rather than being no-ops.\n if (hooks['kubb:plugin:setup']) {\n const setupHandler = (globalCtx: KubbPluginSetupContext) => {\n const pluginCtx: KubbPluginSetupContext = {\n ...globalCtx,\n options: hookPlugin.options ?? {},\n addGenerator: (gen) => {\n this.registerGenerator(normalizedPlugin.name, gen)\n },\n setResolver: (resolver) => {\n this.setPluginResolver(normalizedPlugin.name, resolver)\n },\n setTransformer: (visitor) => {\n normalizedPlugin.transformer = visitor\n },\n setRenderer: (renderer) => {\n normalizedPlugin.renderer = renderer\n },\n setOptions: (opts) => {\n normalizedPlugin.options = { ...normalizedPlugin.options, ...opts }\n },\n injectFile: (userFileNode) => {\n this.fileManager.add(createFile(userFileNode))\n },\n }\n return hooks['kubb:plugin:setup']!(pluginCtx)\n }\n\n this.hooks.on('kubb:plugin:setup', setupHandler)\n this.#trackHookListener('kubb:plugin:setup', setupHandler as (...args: never[]) => void | Promise<void>)\n }\n\n // All other hooks are registered as direct pass-through listeners on the shared emitter.\n for (const [event, handler] of Object.entries(hooks) as Array<[keyof KubbHooks, ((...args: never[]) => void | Promise<void>) | undefined]>) {\n if (event === 'kubb:plugin:setup' || !handler) continue\n\n this.hooks.on(event, handler as never)\n this.#trackHookListener(event, handler as (...args: never[]) => void | Promise<void>)\n }\n }\n\n /**\n * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners\n * can configure generators, resolvers, transformers and renderers before `buildStart` runs.\n *\n * Call this once from `safeBuild` before the plugin execution loop begins.\n */\n async emitSetupHooks(): Promise<void> {\n const noop = () => {}\n\n await this.hooks.emit('kubb:plugin:setup', {\n config: this.config,\n options: {},\n addGenerator: noop,\n setResolver: noop,\n setTransformer: noop,\n setRenderer: noop,\n setOptions: noop,\n injectFile: noop,\n updateConfig: noop,\n })\n }\n\n /**\n * Registers a generator for the given plugin on the shared event emitter.\n *\n * The generator's `schema`, `operation`, and `operations` methods are registered as\n * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`\n * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check\n * so that generators from different plugins do not cross-fire.\n *\n * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.\n * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin\n * declares a renderer.\n *\n * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.\n */\n registerGenerator(pluginName: string, gen: Generator): void {\n const resolveRenderer = () => {\n const plugin = this.plugins.get(pluginName)\n return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)\n }\n\n if (gen.schema) {\n const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.schema!(node, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:schema', schemaHandler)\n this.#trackHookListener('kubb:generate:schema', schemaHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operation) {\n const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operation!(node, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:operation', operationHandler)\n this.#trackHookListener('kubb:generate:operation', operationHandler as (...args: never[]) => void | Promise<void>)\n }\n\n if (gen.operations) {\n const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {\n if (ctx.plugin.name !== pluginName) return\n const result = await gen.operations!(nodes, ctx)\n await applyHookResult({ result, driver: this, rendererFactory: resolveRenderer() })\n }\n\n this.hooks.on('kubb:generate:operations', operationsHandler)\n this.#trackHookListener('kubb:generate:operations', operationsHandler as (...args: never[]) => void | Promise<void>)\n }\n\n this.#pluginsWithEventGenerators.add(pluginName)\n }\n\n /**\n * Returns `true` when at least one generator was registered for the given plugin\n * via `addGenerator()` in `kubb:plugin:setup` (event-based path).\n *\n * Used by the build loop to decide whether to walk the AST and emit generator events\n * for a plugin that has no static `plugin.generators`.\n */\n hasRegisteredGenerators(pluginName: string): boolean {\n return this.#pluginsWithEventGenerators.has(pluginName)\n }\n\n /**\n * Unregisters all plugin lifecycle listeners from the shared event emitter.\n * Called at the end of a build to prevent listener leaks across repeated builds.\n *\n * @internal\n */\n dispose(): void {\n for (const [event, handlers] of this.#hookListeners) {\n for (const handler of handlers) {\n this.hooks.off(event, handler as never)\n }\n }\n this.#hookListeners.clear()\n this.#pluginsWithEventGenerators.clear()\n // Release resolver closures — the driver is rebuilt for each build() call\n // so there is no value in retaining these maps after disposal.\n this.#resolvers.clear()\n this.#defaultResolvers.clear()\n // Release the parsed adapter graph and the FileNode cache once the build\n // has finished; the returned `BuildOutput.files` array still references\n // any FileNodes the caller needs to inspect.\n this.fileManager.dispose()\n this.inputNode = undefined\n this.inputStreamNode = undefined\n }\n\n [Symbol.dispose](): void {\n this.dispose()\n }\n\n #trackHookListener(event: keyof KubbHooks, handler: (...args: never[]) => void | Promise<void>): void {\n let handlers = this.#hookListeners.get(event)\n if (!handlers) {\n handlers = new Set()\n this.#hookListeners.set(event, handlers)\n }\n handlers.add(handler)\n }\n\n #createDefaultResolver(pluginName: string): Resolver {\n const existingResolver = this.#defaultResolvers.get(pluginName)\n if (existingResolver) {\n return existingResolver\n }\n\n const resolver = defineResolver<PluginFactoryOptions>(() => ({\n name: 'default',\n pluginName,\n }))\n this.#defaultResolvers.set(pluginName, resolver)\n return resolver\n }\n\n /**\n * Merges `partial` with the plugin's default resolver and stores the result.\n * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`\n * get the up-to-date resolver without going through `getResolver()`.\n */\n setPluginResolver(pluginName: string, partial: Partial<Resolver>): void {\n const defaultResolver = this.#createDefaultResolver(pluginName)\n const merged = { ...defaultResolver, ...partial }\n this.#resolvers.set(pluginName, merged)\n const plugin = this.plugins.get(pluginName)\n if (plugin) {\n plugin.resolver = merged\n }\n }\n\n /**\n * Returns the resolver for the given plugin.\n *\n * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the\n * plugin → lazily created default resolver (identity name, no path transforms).\n */\n getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver']\n getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver\n getResolver(pluginName: string): Resolver {\n return this.#resolvers.get(pluginName) ?? this.plugins.get(pluginName)?.resolver ?? this.#createDefaultResolver(pluginName)\n }\n\n getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown> {\n const driver = this\n\n const baseContext = {\n config: driver.config,\n get root(): string {\n return resolve(driver.config.root, driver.config.output.path)\n },\n getMode(output: { path: string }): 'single' | 'split' {\n return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))\n },\n hooks: driver.hooks,\n plugin,\n getPlugin: driver.getPlugin.bind(driver),\n requirePlugin: driver.requirePlugin.bind(driver),\n getResolver: driver.getResolver.bind(driver),\n driver,\n addFile: async (...files: Array<FileNode>) => {\n driver.fileManager.add(...files)\n },\n upsertFile: async (...files: Array<FileNode>) => {\n driver.fileManager.upsert(...files)\n },\n get inputNode(): InputNode {\n if (driver.inputNode) return driver.inputNode\n return { kind: 'Input' as const, schemas: [], operations: [], meta: driver.inputStreamNode?.meta }\n },\n get adapter(): Adapter | undefined {\n return driver.adapter\n },\n get resolver() {\n return driver.getResolver(plugin.name)\n },\n get transformer() {\n return plugin.transformer\n },\n warn(message: string) {\n driver.hooks.emit('kubb:warn', { message })\n },\n error(error: string | Error) {\n driver.hooks.emit('kubb:error', { error: typeof error === 'string' ? new Error(error) : error })\n },\n info(message: string) {\n driver.hooks.emit('kubb:info', { message })\n },\n openInStudio(options?: DevtoolsOptions) {\n if (!driver.config.devtools || driver.#studioIsOpen) {\n return\n }\n\n if (typeof driver.config.devtools !== 'object') {\n throw new Error('Devtools must be an object')\n }\n\n if (!driver.inputNode || !driver.adapter) {\n throw new Error('adapter is not defined, make sure you have set the parser in kubb.config.ts')\n }\n\n driver.#studioIsOpen = true\n\n const studioUrl = driver.config.devtools?.studioUrl ?? DEFAULT_STUDIO_URL\n\n return openInStudioFn(driver.inputNode, studioUrl, options)\n },\n } as unknown as GeneratorContext<TOptions>\n\n return baseContext\n }\n\n getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined\n getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined\n getPlugin(pluginName: string): Plugin | undefined {\n return this.plugins.get(pluginName)\n }\n\n /**\n * Like `getPlugin` but throws a descriptive error when the plugin is not found.\n */\n requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>\n requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>\n requirePlugin(pluginName: string): Plugin {\n const plugin = this.plugins.get(pluginName)\n if (!plugin) {\n throw new Error(`[kubb] Plugin \"${pluginName}\" is required but not found. Make sure it is included in your Kubb config.`)\n }\n return plugin\n }\n}\n\n/**\n * Handles the return value of a plugin AST hook or generator method.\n *\n * - Renderer output → rendered via the provided `rendererFactory` (e.g. JSX), files stored in `driver.fileManager`\n * - `Array<FileNode>` → added directly into `driver.fileManager`\n * - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)\n *\n * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result\n * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.\n */\nexport function applyHookResult<TElement = unknown>({\n result,\n driver,\n rendererFactory,\n}: {\n result: TElement | Array<FileNode> | void\n driver: PluginDriver\n rendererFactory?: RendererFactory<TElement>\n}): void | Promise<void> {\n if (!result) return\n\n if (Array.isArray(result)) {\n driver.fileManager.upsert(...(result as Array<FileNode>))\n return\n }\n\n if (!rendererFactory) {\n return\n }\n\n const renderer = rendererFactory()\n if (renderer.stream) {\n for (const file of renderer.stream(result)) {\n driver.fileManager.upsert(file)\n }\n renderer.unmount()\n return\n }\n return applyAsyncRender({ renderer, result, driver })\n}\n\nasync function applyAsyncRender<TElement>({\n renderer,\n result,\n driver,\n}: {\n renderer: { render(el: TElement): Promise<void>; files: ReadonlyArray<FileNode>; unmount(): void }\n result: TElement\n driver: PluginDriver\n}): Promise<void> {\n await renderer.render(result)\n driver.fileManager.upsert(...renderer.files)\n renderer.unmount()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;CAS9D,OARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;EAEhB,IADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,EACjD,OAAO;EACrB,IAAI,MAAM,KAAK,CAAC,QAAQ,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;EAC3E,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;;;;;;;AAiBjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;CAC1C,OAAO,MACJ,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAC7D,OAAO,QAAQ,CACf,KAAK,IAAI;;;;;;;;;;AAWd,SAAgB,U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AAa,EAAE,SAAS,CAAC;;GAE7C,aAAa,SAA2B;IACtC,IAAI,CAAC,OAAO,OAAO,YAAY,OAAOC,eACpC;IAGF,IAAI,OAAO,OAAO,OAAO,aAAa,UACpC,MAAM,IAAI,MAAM,6BAA6B;IAG/C,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,SAC/B,MAAM,IAAI,MAAM,8EAA8E;IAGhG,OAAOA,gBAAgB;IAEvB,MAAM,YAAY,OAAO,OAAO,UAAU,aAAA;IAE1C,OAAOC,aAAe,OAAO,WAAW,WAAW,QAAQ;;GAI7C;;CAKpB,UAAU,YAAwC;EAChD,OAAO,KAAK,QAAQ,IAAI,WAAW;;CAQrC,cAAc,YAA4B;EACxC,MAAM,SAAS,KAAK,QAAQ,IAAI,WAAW;EAC3C,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,kBAAkB,WAAW,4EAA4E;EAE3H,OAAO;;;;;;;;;;;;;AAcX,SAAgB,gBAAoC,EAClD,QACA,QACA,mBAKuB;CACvB,IAAI,CAAC,QAAQ;CAEb,IAAI,MAAM,QAAQ,OAAO,EAAE;EACzB,OAAO,YAAY,OAAO,GAAI,OAA2B;EACzD;;CAGF,IAAI,CAAC,iBACH;CAGF,MAAM,WAAW,iBAAiB;CAClC,IAAI,SAAS,QAAQ;EACnB,KAAK,MAAM,QAAQ,SAAS,OAAO,OAAO,EACxC,OAAO,YAAY,OAAO,KAAK;EAEjC,SAAS,SAAS;EAClB;;CAEF,OAAO,iBAAiB;EAAE;EAAU;EAAQ;EAAQ,CAAC;;AAGvD,eAAe,iBAA2B,EACxC,UACA,QACA,UAKgB;CAChB,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO,YAAY,OAAO,GAAG,SAAS,MAAM;CAC5C,SAAS,SAAS"}
@@ -175,10 +175,9 @@ function matchesSchemaPattern(node, type, pattern) {
175
175
  * - `camelCase` for everything else.
176
176
  */
177
177
  function defaultResolver(name, type) {
178
- let resolvedName = camelCase(name);
179
- if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
180
- if (type === "type") resolvedName = pascalCase(name);
181
- return resolvedName;
178
+ if (type === "file" || type === "function") return camelCase(name, { isFile: type === "file" });
179
+ if (type === "type") return pascalCase(name);
180
+ return camelCase(name);
182
181
  }
183
182
  /**
184
183
  * Default option resolver — applies include/exclude filters and merges matching override options.
@@ -203,7 +202,8 @@ function defaultResolver(name, type) {
203
202
  * // → { enumType: 'enum' } when operationId matches
204
203
  * ```
205
204
  */
206
- function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
205
+ const resolveOptionsCache = /* @__PURE__ */ new WeakMap();
206
+ function computeOptions(node, options, exclude, include, override) {
207
207
  if (isOperationNode(node)) {
208
208
  if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
209
209
  if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
@@ -227,6 +227,19 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
227
227
  }
228
228
  return options;
229
229
  }
230
+ function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
231
+ const optionsKey = options;
232
+ let byOptions = resolveOptionsCache.get(optionsKey);
233
+ if (!byOptions) {
234
+ byOptions = /* @__PURE__ */ new WeakMap();
235
+ resolveOptionsCache.set(optionsKey, byOptions);
236
+ }
237
+ const cached = byOptions.get(node);
238
+ if (cached !== void 0) return cached.value;
239
+ const result = computeOptions(node, options, exclude, include, override);
240
+ byOptions.set(node, { value: result });
241
+ return result;
242
+ }
230
243
  /**
231
244
  * Default path resolver used by `defineResolver`.
232
245
  *
@@ -273,16 +286,18 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
273
286
  */
274
287
  function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }, { root, output, group }) {
275
288
  if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single") return path.resolve(root, output.path);
276
- let result;
277
- if (group && (groupPath || tag)) {
278
- const groupValue = group.type === "path" ? groupPath : tag;
279
- const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
280
- const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
281
- return segment ? camelCase(segment) : "";
282
- };
283
- const resolveName = group.name ?? defaultName;
284
- result = path.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
285
- } else result = path.resolve(root, output.path, baseName);
289
+ const result = (() => {
290
+ if (group && (groupPath || tag)) {
291
+ const groupValue = group.type === "path" ? groupPath : tag;
292
+ const defaultName = group.type === "tag" ? ({ group: g }) => `${camelCase(g)}Controller` : ({ group: g }) => {
293
+ const segment = g.split("/").filter((s) => s !== "" && s !== "." && s !== "..")[0];
294
+ return segment ? camelCase(segment) : "";
295
+ };
296
+ const resolveName = group.name ?? defaultName;
297
+ return path.resolve(root, output.path, resolveName({ group: groupValue }), baseName);
298
+ }
299
+ return path.resolve(root, output.path, baseName);
300
+ })();
286
301
  const outputDir = path.resolve(root, output.path);
287
302
  const outputDirWithSep = outputDir.endsWith(path.sep) ? outputDir : `${outputDir}${path.sep}`;
288
303
  if (result !== outputDir && !result.startsWith(outputDirWithSep)) throw new Error(`[Kubb] Resolved path "${result}" is outside the output directory "${outputDir}". This may indicate a path traversal attempt in the OpenAPI specification or a misconfigured group.name function.`);
@@ -340,12 +355,16 @@ function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
340
355
  */
341
356
  function buildDefaultBanner({ title, description, version, config }) {
342
357
  try {
343
- let source = "";
344
- if (Array.isArray(config.input)) {
345
- const first = config.input[0];
346
- if (first && "path" in first) source = path.basename(first.path);
347
- } else if (config.input && "path" in config.input) source = path.basename(config.input.path);
348
- else if (config.input && "data" in config.input) source = "text content";
358
+ const source = (() => {
359
+ if (Array.isArray(config.input)) {
360
+ const first = config.input[0];
361
+ if (first && "path" in first) return path.basename(first.path);
362
+ return "";
363
+ }
364
+ if (config.input && "path" in config.input) return path.basename(config.input.path);
365
+ if (config.input && "data" in config.input) return "text content";
366
+ return "";
367
+ })();
349
368
  let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
350
369
  if (config.output.defaultBanner === "simple") {
351
370
  banner += "*/\n";
@@ -824,7 +843,11 @@ var PluginDriver = class PluginDriver {
824
843
  if (gen.schema) {
825
844
  const schemaHandler = async (node, ctx) => {
826
845
  if (ctx.plugin.name !== pluginName) return;
827
- await applyHookResult(await gen.schema(node, ctx), this, resolveRenderer());
846
+ await applyHookResult({
847
+ result: await gen.schema(node, ctx),
848
+ driver: this,
849
+ rendererFactory: resolveRenderer()
850
+ });
828
851
  };
829
852
  this.hooks.on("kubb:generate:schema", schemaHandler);
830
853
  this.#trackHookListener("kubb:generate:schema", schemaHandler);
@@ -832,7 +855,11 @@ var PluginDriver = class PluginDriver {
832
855
  if (gen.operation) {
833
856
  const operationHandler = async (node, ctx) => {
834
857
  if (ctx.plugin.name !== pluginName) return;
835
- await applyHookResult(await gen.operation(node, ctx), this, resolveRenderer());
858
+ await applyHookResult({
859
+ result: await gen.operation(node, ctx),
860
+ driver: this,
861
+ rendererFactory: resolveRenderer()
862
+ });
836
863
  };
837
864
  this.hooks.on("kubb:generate:operation", operationHandler);
838
865
  this.#trackHookListener("kubb:generate:operation", operationHandler);
@@ -840,7 +867,11 @@ var PluginDriver = class PluginDriver {
840
867
  if (gen.operations) {
841
868
  const operationsHandler = async (nodes, ctx) => {
842
869
  if (ctx.plugin.name !== pluginName) return;
843
- await applyHookResult(await gen.operations(nodes, ctx), this, resolveRenderer());
870
+ await applyHookResult({
871
+ result: await gen.operations(nodes, ctx),
872
+ driver: this,
873
+ rendererFactory: resolveRenderer()
874
+ });
844
875
  };
845
876
  this.hooks.on("kubb:generate:operations", operationsHandler);
846
877
  this.#trackHookListener("kubb:generate:operations", operationsHandler);
@@ -934,7 +965,8 @@ var PluginDriver = class PluginDriver {
934
965
  driver.fileManager.upsert(...files);
935
966
  },
936
967
  get inputNode() {
937
- return driver.inputNode ?? {
968
+ if (driver.inputNode) return driver.inputNode;
969
+ return {
938
970
  kind: "Input",
939
971
  schemas: [],
940
972
  operations: [],
@@ -988,7 +1020,7 @@ var PluginDriver = class PluginDriver {
988
1020
  * Pass a `rendererFactory` (e.g. `jsxRenderer` from `@kubb/renderer-jsx`) when the result
989
1021
  * may be a renderer element. Generators that only return `Array<FileNode>` do not need one.
990
1022
  */
991
- async function applyHookResult(result, driver, rendererFactory) {
1023
+ function applyHookResult({ result, driver, rendererFactory }) {
992
1024
  if (!result) return;
993
1025
  if (Array.isArray(result)) {
994
1026
  driver.fileManager.upsert(...result);
@@ -996,14 +1028,23 @@ async function applyHookResult(result, driver, rendererFactory) {
996
1028
  }
997
1029
  if (!rendererFactory) return;
998
1030
  const renderer = rendererFactory();
999
- if (renderer.stream) for await (const file of renderer.stream(result)) driver.fileManager.upsert(file);
1000
- else {
1001
- await renderer.render(result);
1002
- driver.fileManager.upsert(...renderer.files);
1031
+ if (renderer.stream) {
1032
+ for (const file of renderer.stream(result)) driver.fileManager.upsert(file);
1033
+ renderer.unmount();
1034
+ return;
1003
1035
  }
1036
+ return applyAsyncRender({
1037
+ renderer,
1038
+ result,
1039
+ driver
1040
+ });
1041
+ }
1042
+ async function applyAsyncRender({ renderer, result, driver }) {
1043
+ await renderer.render(result);
1044
+ driver.fileManager.upsert(...renderer.files);
1004
1045
  renderer.unmount();
1005
1046
  }
1006
1047
  //#endregion
1007
1048
  export { definePlugin as a, DEFAULT_STUDIO_URL as c, defineResolver as i, logLevel as l, applyHookResult as n, DEFAULT_BANNER as o, FileManager as r, DEFAULT_EXTENSION as s, PluginDriver as t, camelCase as u };
1008
1049
 
1009
- //# sourceMappingURL=PluginDriver-T4-THx8t.js.map
1050
+ //# sourceMappingURL=PluginDriver-uNex0SAr.js.map