@kubb/core 5.8.4 → 5.9.1

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/mocks.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_KubbDriver = require("./KubbDriver-Iv2StSPa.cjs");
2
+ const require_KubbDriver = require("./KubbDriver-Cd01FAa0.cjs");
3
3
  let node_path = require("node:path");
4
4
  node_path = require_KubbDriver.__toESM(node_path, 1);
5
5
  let _kubb_ast = require("@kubb/ast");
@@ -19,8 +19,7 @@ function createMockedPluginDriver(options = {}) {
19
19
  return options?.plugin;
20
20
  },
21
21
  getResolver: (_pluginName) => options?.plugin?.resolver,
22
- fileManager,
23
- dispatch: (params) => fileManager.dispatch(params)
22
+ fileManager
24
23
  };
25
24
  }
26
25
  /** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */
@@ -109,7 +108,7 @@ async function renderNode({ generator, node, opts, generate }) {
109
108
  };
110
109
  const transformedNode = opts.plugin.macros?.length ? (0, _kubb_ast.applyMacros)(node, opts.plugin.macros) : node;
111
110
  if (!(generator.match ? await generator.match(transformedNode, ctx) : true)) return;
112
- await opts.driver.dispatch({
111
+ await opts.driver.fileManager.dispatch({
113
112
  result: await generate(transformedNode, ctx),
114
113
  renderer: generator.renderer
115
114
  });
@@ -167,7 +166,7 @@ async function renderGeneratorOperations(generator, nodes, opts) {
167
166
  ...context,
168
167
  options: opts.options
169
168
  });
170
- await opts.driver.dispatch({
169
+ await opts.driver.fileManager.dispatch({
171
170
  result,
172
171
  renderer: generator.renderer
173
172
  });
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.cjs","names":["FileManager","vi","pluginNotFoundError","ast","resolve","createNodeCache","Hookable","applyMacros","path","camelCase","expect"],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginFactoryOptions } from './definePlugin.ts'\nimport type { RendererFactory } from './createRenderer.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n dispatch: (params: { result: unknown; renderer?: RendererFactory | null }) => fileManager.dispatch(params),\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginFactoryOptions>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginFactoryOptions, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAIA,mBAAAA,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB,SAAS,QAAQ;EACvD;EACA,WAAW,WAAmE,YAAY,SAAS,MAAM;CAC3G;AACF;;AAGA,SAAgB,yBAAuF,EACrG,UAAU,CAAC,GACX,UAAU,CAAC,MACmD,CAAC,GAAqC;CACpG,MAAM,aAAa,QAAQ,KAAK,UAAU,EAAE,KAAK,EAAuB;CAExE,OAAO;EACL,QAAQ,EAAE,SAAS,WAAW;EAC9B;EACA,cAAcC,OAAAA,GAAG,GAAG;EACpB,aAAaA,OAAAA,GAAG,GAAG;EACnB,UAAUA,OAAAA,GAAG,GAAG;EAChB,WAAWA,OAAAA,GAAG,GAAG;EACjB,YAAYA,OAAAA,GAAG,GAAG;EAClB,YAAYA,OAAAA,GAAG,GAAG;EAClB,eAAeA,OAAAA,GAAG,IAAI,eAAuB;GAC3C,MAAM,SAAS,WAAW,MAAM,UAAU,MAAM,SAAS,UAAU;GACnE,IAAI,CAAC,QAAQ,MAAMC,mBAAAA,oBAAoB,EAAE,WAAW,CAAC;GACrD,OAAO;EACT,CAAC;CACH;AACF;;;;;AAMA,SAAgB,oBACd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O,QAAQ;CAEpB,MAAM,EAAE,0BAAU,IAAI,IAAI,GAAG,QAAQ,QAAQ;CAC7C,MAAM,cAAc,IAAIP,mBAAAA,YAAY;CACpC,MAAM,4BAAY,IAAI,IAAoB;CAE1C,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,MAAM,QAAQ,UAAU,IAAI,KAAK,IAAI,GACxC;EAGF,MAAM,SAAS,MAAM,YAAY,MAAM,MAAM,EAAE,QAAQ,CAAC;EACxD,MAAM,OAAO,KAAK,SAAS,SAAS,OAAO,KAAK,CAAC,SAAS,SAAS,MAAM,OAAO,MAAM;EAEtF,UAAU,IAAI,KAAK,MAAM,IAAI;EAE7B,MAAM,eAAeQ,UAAAA,QAAK,KAAK,iBAAiB,GAAI,MAAM,CAACC,mBAAAA,UAAU,GAAG,CAAC,IAAI,CAAC,GAAI,KAAK,QAAQ;EAC/F,OAAA,GAAMC,OAAAA,OAAAA,CAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"mocks.cjs","names":["FileManager","vi","pluginNotFoundError","ast","resolve","createNodeCache","Hookable","applyMacros","path","camelCase","expect"],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginType } from './definePlugin.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginType = PluginType>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginType> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginType>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginType, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.fileManager.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.fileManager.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAIA,mBAAAA,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB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,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
package/dist/mocks.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
2
- import { C as NormalizedPlugin, Nt as KubbDriver, Z as Generator, i as AdapterFactoryOptions, j as PluginFactoryOptions, on as Parser, rt as Config, t as Adapter, x as KubbPluginSetupContext } from "./createAdapter-BpJYvJTw.js";
2
+ import { C as NormalizedPlugin, M as PluginType, Mt as KubbDriver, X as Generator, an as Parser, i as AdapterFactoryOptions, nt as Config, t as Adapter, x as KubbPluginSetupContext } from "./createAdapter-DfbfcqcJ.js";
3
3
  import { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from "@kubb/ast";
4
4
  //#region src/mocks.d.ts
5
5
  /**
@@ -11,7 +11,7 @@ export declare function createMockedPluginDriver(options?: {
11
11
  config?: Config;
12
12
  }): KubbDriver;
13
13
  /** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */
14
- export declare function createMockedSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions>({ plugins, options }?: {
14
+ export declare function createMockedSetupContext<TFactory extends PluginType = PluginType>({ plugins, options }?: {
15
15
  plugins?: Array<string>;
16
16
  options?: TFactory['options'];
17
17
  }): KubbPluginSetupContext<TFactory>;
@@ -30,14 +30,14 @@ export declare function createMockedAdapter<TOptions extends AdapterFactoryOptio
30
30
  * @example
31
31
  * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`
32
32
  */
33
- export declare function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {
33
+ export declare function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {
34
34
  name: TOptions['name'];
35
35
  options: TOptions['resolvedOptions'];
36
36
  resolver?: TOptions['resolver'];
37
37
  macros?: Array<Macro>;
38
38
  dependencies?: Array<string>;
39
39
  }): NormalizedPlugin<TOptions>;
40
- type RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {
40
+ type RenderGeneratorOptions<TOptions extends PluginType> = {
41
41
  config: Config;
42
42
  adapter: Adapter;
43
43
  meta?: InputMeta;
@@ -55,7 +55,7 @@ type RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {
55
55
  * await matchFiles(driver.fileManager.files)
56
56
  * ```
57
57
  */
58
- export declare function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, node: SchemaNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
58
+ export declare function renderGeneratorSchema<TOptions extends PluginType>(generator: Generator<TOptions>, node: SchemaNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
59
59
  /**
60
60
  * Renders a generator's `operation` method in a test context.
61
61
  *
@@ -65,7 +65,7 @@ export declare function renderGeneratorSchema<TOptions extends PluginFactoryOpti
65
65
  * await matchFiles(driver.fileManager.files)
66
66
  * ```
67
67
  */
68
- export declare function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, node: OperationNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
68
+ export declare function renderGeneratorOperation<TOptions extends PluginType>(generator: Generator<TOptions>, node: OperationNode, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
69
69
  /**
70
70
  * Renders a generator's `operations` method in a test context.
71
71
  *
@@ -75,7 +75,7 @@ export declare function renderGeneratorOperation<TOptions extends PluginFactoryO
75
75
  * await matchFiles(driver.fileManager.files)
76
76
  * ```
77
77
  */
78
- export declare function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(generator: Generator<TOptions>, nodes: Array<OperationNode>, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
78
+ export declare function renderGeneratorOperations<TOptions extends PluginType>(generator: Generator<TOptions>, nodes: Array<OperationNode>, opts: RenderGeneratorOptions<TOptions>): Promise<void>;
79
79
  type MatchFilesOptions = {
80
80
  /**
81
81
  * Parsers indexed by file extension, used to render each `FileNode` to source.
package/dist/mocks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-CRm0XQPb.js";
2
- import { i as FileManager, n as pluginNotFoundError, o as Hookable, r as createNodeCache, z as camelCase } from "./KubbDriver-DbOEJvzz.js";
2
+ import { i as FileManager, n as pluginNotFoundError, o as Hookable, r as createNodeCache, z as camelCase } from "./KubbDriver-GBBjs4Pb.js";
3
3
  import path, { resolve } from "node:path";
4
4
  import { applyMacros, ast } from "@kubb/ast";
5
5
  import { expect, vi } from "vitest";
@@ -18,8 +18,7 @@ function createMockedPluginDriver(options = {}) {
18
18
  return options?.plugin;
19
19
  },
20
20
  getResolver: (_pluginName) => options?.plugin?.resolver,
21
- fileManager,
22
- dispatch: (params) => fileManager.dispatch(params)
21
+ fileManager
23
22
  };
24
23
  }
25
24
  /** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */
@@ -108,7 +107,7 @@ async function renderNode({ generator, node, opts, generate }) {
108
107
  };
109
108
  const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node;
110
109
  if (!(generator.match ? await generator.match(transformedNode, ctx) : true)) return;
111
- await opts.driver.dispatch({
110
+ await opts.driver.fileManager.dispatch({
112
111
  result: await generate(transformedNode, ctx),
113
112
  renderer: generator.renderer
114
113
  });
@@ -166,7 +165,7 @@ async function renderGeneratorOperations(generator, nodes, opts) {
166
165
  ...context,
167
166
  options: opts.options
168
167
  });
169
- await opts.driver.dispatch({
168
+ await opts.driver.fileManager.dispatch({
170
169
  result,
171
170
  renderer: generator.renderer
172
171
  });
package/dist/mocks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.js","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginFactoryOptions } from './definePlugin.ts'\nimport type { RendererFactory } from './createRenderer.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n dispatch: (params: { result: unknown; renderer?: RendererFactory | null }) => fileManager.dispatch(params),\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginFactoryOptions>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginFactoryOptions, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAI,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB,SAAS,QAAQ;EACvD;EACA,WAAW,WAAmE,YAAY,SAAS,MAAM;CAC3G;AACF;;AAGA,SAAgB,yBAAuF,EACrG,UAAU,CAAC,GACX,UAAU,CAAC,MACmD,CAAC,GAAqC;CACpG,MAAM,aAAa,QAAQ,KAAK,UAAU,EAAE,KAAK,EAAuB;CAExE,OAAO;EACL,QAAQ,EAAE,SAAS,WAAW;EAC9B;EACA,cAAc,GAAG,GAAG;EACpB,aAAa,GAAG,GAAG;EACnB,UAAU,GAAG,GAAG;EAChB,WAAW,GAAG,GAAG;EACjB,YAAY,GAAG,GAAG;EAClB,YAAY,GAAG,GAAG;EAClB,eAAe,GAAG,IAAI,eAAuB;GAC3C,MAAM,SAAS,WAAW,MAAM,UAAU,MAAM,SAAS,UAAU;GACnE,IAAI,CAAC,QAAQ,MAAM,oBAAoB,EAAE,WAAW,CAAC;GACrD,OAAO;EACT,CAAC;CACH;AACF;;;;;AAMA,SAAgB,oBACd,UAII,CAAC,GACc;CAQnB,OAAO;EANL,MAAO,QAAQ,QAAQ;EACvB,SAAU,QAAQ,mBAAmB,CAAC;EACtC,UAAU;EACV,OAAO,QAAQ,UAAU,YAAY,IAAI,QAAQ,YAAY;EAC7D,UAAU,YAAY,CAAC;CAEZ;AACf;;;;;;;AAQA,SAAgB,mB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SAAS,SAAS,OAAO,KAAK,CAAC,SAAS,SAAS,MAAM,OAAO,MAAM;EAEtF,UAAU,IAAI,KAAK,MAAM,IAAI;EAE7B,MAAM,eAAe,KAAK,KAAK,iBAAiB,GAAI,MAAM,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,GAAI,KAAK,QAAQ;EAC/F,MAAM,OAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"mocks.js","names":[],"sources":["../src/mocks.ts"],"sourcesContent":["import path, { resolve } from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport type { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from '@kubb/ast'\nimport { applyMacros, ast } from '@kubb/ast'\nimport { expect, vi } from 'vitest'\nimport type { Parser } from './defineParser.ts'\nimport { FileManager } from './FileManager.ts'\nimport { Hookable } from './Hookable.ts'\nimport { createNodeCache } from './nodeCache.ts'\nimport { type KubbDriver, pluginNotFoundError } from './KubbDriver.ts'\nimport type { Config, KubbHooks } from './types.ts'\nimport type { Adapter, AdapterFactoryOptions } from './createAdapter.ts'\nimport type { Generator, GeneratorContext } from './defineGenerator.ts'\nimport type { KubbPluginSetupContext, NormalizedPlugin, Plugin, PluginType } from './definePlugin.ts'\n\n/**\n * Creates a minimal `KubbDriver` mock for unit tests.\n */\nexport function createMockedPluginDriver(options: { name?: string; plugin?: NormalizedPlugin; config?: Config } = {}): KubbDriver {\n const fileManager = new FileManager()\n\n return {\n config: options?.config ?? {\n root: '.',\n output: {\n path: './path',\n },\n },\n getPlugin(_pluginName: string): NormalizedPlugin | undefined {\n return options?.plugin\n },\n getResolver: (_pluginName: string) => options?.plugin?.resolver,\n fileManager,\n } as unknown as KubbDriver\n}\n\n/** Creates a `kubb:plugin:setup` context for unit tests. `requirePlugin` fails for names `plugins` does not list. */\nexport function createMockedSetupContext<TFactory extends PluginType = PluginType>({\n plugins = [],\n options = {} as TFactory['options'],\n}: { plugins?: Array<string>; options?: TFactory['options'] } = {}): KubbPluginSetupContext<TFactory> {\n const registered = plugins.map((name) => ({ name }) as unknown as Plugin)\n\n return {\n config: { plugins: registered } as unknown as Config,\n options,\n addGenerator: vi.fn(),\n setResolver: vi.fn(),\n addMacro: vi.fn(),\n setMacros: vi.fn(),\n setOptions: vi.fn(),\n injectFile: vi.fn(),\n requirePlugin: vi.fn((pluginName: string) => {\n const plugin = registered.find((entry) => entry.name === pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName })\n return plugin\n }) as KubbPluginSetupContext<TFactory>['requirePlugin'],\n }\n}\n\n/**\n * Creates a minimal `Adapter` mock for unit tests.\n * `parse` returns an empty `InputNode` by default. Override via `options.parse`.\n */\nexport function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(\n options: {\n name?: TOptions['name']\n resolvedOptions?: TOptions['resolvedOptions']\n parse?: Adapter<TOptions>['parse']\n } = {},\n): Adapter<TOptions> {\n const adapter: Adapter<TOptions> = {\n name: (options.name ?? 'oas') as TOptions['name'],\n options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],\n document: null,\n parse: options.parse ?? (async () => ast.factory.createInput()),\n validate: async () => {},\n }\n return adapter\n}\n\n/**\n * Creates a minimal plugin mock for unit tests.\n *\n * @example\n * `const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })`\n */\nexport function createMockedPlugin<TOptions extends PluginType = PluginType>(params: {\n name: TOptions['name']\n options: TOptions['resolvedOptions']\n resolver?: TOptions['resolver']\n macros?: Array<Macro>\n dependencies?: Array<string>\n}): NormalizedPlugin<TOptions> {\n return {\n name: params.name,\n options: params.options,\n resolver: params.resolver,\n macros: params.macros,\n dependencies: params.dependencies,\n hooks: {},\n } as unknown as NormalizedPlugin<TOptions>\n}\n\ntype RenderGeneratorOptions<TOptions extends PluginType> = {\n config: Config\n adapter: Adapter\n meta?: InputMeta\n driver: KubbDriver\n plugin: NormalizedPlugin<TOptions>\n options: TOptions['resolvedOptions']\n resolver: TOptions['resolver']\n}\n\nfunction createMockedPluginContext<TOptions extends PluginType>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {\n const root = resolve(opts.config.root, opts.config.output.path)\n\n return {\n config: opts.config,\n root,\n adapter: opts.adapter,\n resolver: opts.resolver,\n plugin: opts.plugin,\n driver: opts.driver,\n getResolver: (name: string) => opts.driver.getResolver(name),\n requirePlugin: (pluginName: string) => {\n const plugin = opts.driver.getPlugin(pluginName)\n if (!plugin) throw pluginNotFoundError({ pluginName, requiredBy: opts.plugin.name })\n return plugin\n },\n meta: opts.meta ?? { circularNames: [], enumNames: [] },\n cache: createNodeCache(),\n addFile: async (...files: Array<FileNode>) => opts.driver.fileManager.add(...files),\n upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),\n hooks: opts.driver.hooks ?? new Hookable<KubbHooks>(),\n warn: (msg: string) => console.warn(msg),\n error: (msg: string) => console.error(msg),\n info: (msg: string) => console.info(msg),\n } as unknown as Omit<GeneratorContext<TOptions>, 'options'>\n}\n\nasync function renderNode<TOptions extends PluginType, TNode extends SchemaNode | OperationNode>({\n generator,\n node,\n opts,\n generate,\n}: {\n generator: Generator<TOptions>\n node: TNode\n opts: RenderGeneratorOptions<TOptions>\n generate: (node: TNode, ctx: GeneratorContext<TOptions>) => ReturnType<NonNullable<Generator<TOptions>['schema']>>\n}): Promise<void> {\n const ctx = { ...createMockedPluginContext(opts), options: opts.options }\n const transformedNode = opts.plugin.macros?.length ? applyMacros(node, opts.plugin.macros) : node\n const matches = generator.match ? await generator.match(transformedNode, ctx) : true\n if (!matches) return\n await opts.driver.fileManager.dispatch({ result: await generate(transformedNode, ctx), renderer: generator.renderer })\n}\n\n/**\n * Renders a generator's `schema` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorSchema<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: SchemaNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.schema) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.schema!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operation` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperation<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n node: OperationNode,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operation) return\n await renderNode({ generator, node, opts, generate: (transformedNode, ctx) => generator.operation!(transformedNode, ctx) })\n}\n\n/**\n * Renders a generator's `operations` method in a test context.\n *\n * @example\n * ```ts\n * await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files)\n * ```\n */\nexport async function renderGeneratorOperations<TOptions extends PluginType>(\n generator: Generator<TOptions>,\n nodes: Array<OperationNode>,\n opts: RenderGeneratorOptions<TOptions>,\n): Promise<void> {\n if (!generator.operations) return\n const context = createMockedPluginContext(opts)\n const transformedNodes = opts.plugin.macros?.length ? nodes.map((n) => applyMacros(n, opts.plugin.macros!)) : nodes\n const result = await generator.operations(transformedNodes, {\n ...context,\n options: opts.options,\n })\n await opts.driver.fileManager.dispatch({ result, renderer: generator.renderer })\n}\n\ntype MatchFilesOptions = {\n /**\n * Parsers indexed by file extension, used to render each `FileNode` to source.\n * Without a matching parser the file's raw content is used.\n */\n parsers?: Map<FileNode['extname'], Parser>\n /**\n * Formatter applied to non-JSON output before snapshotting, e.g. prettier. When\n * omitted the parsed source is snapshotted as-is.\n */\n format?: (source?: string) => string | Promise<string>\n /**\n * Subfolder under `__snapshots__`, camelCased. Useful to keep variant snapshots apart.\n */\n pre?: string\n}\n\n/**\n * Renders the driver's collected `FileNode`s to source and asserts each against a file snapshot.\n * Pair it with the `renderGenerator*` helpers to snapshot a generator's output.\n *\n * @example\n * ```ts\n * await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })\n * await matchFiles(driver.fileManager.files, { parsers, format })\n * ```\n */\nexport async function matchFiles(files: Array<FileNode> | undefined, options: MatchFilesOptions = {}): Promise<Map<string, string> | undefined> {\n if (!files?.length) return\n\n const { parsers = new Map(), format, pre } = options\n const fileManager = new FileManager()\n const processed = new Map<string, string>()\n\n for (const file of files) {\n if (!file?.path || processed.has(file.path)) {\n continue\n }\n\n const parsed = await fileManager.parse(file, { parsers })\n const code = file.baseName.endsWith('.json') || !format ? parsed : await format(parsed)\n\n processed.set(file.path, code)\n\n const snapshotPath = path.join('__snapshots__', ...(pre ? [camelCase(pre)] : []), file.baseName)\n await expect(code).toMatchFileSnapshot(snapshotPath)\n }\n\n return processed\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,yBAAyB,UAAyE,CAAC,GAAe;CAChI,MAAM,cAAc,IAAI,YAAY;CAEpC,OAAO;EACL,QAAQ,SAAS,UAAU;GACzB,MAAM;GACN,QAAQ,EACN,MAAM,SACR;EACF;EACA,UAAU,aAAmD;GAC3D,OAAO,SAAS;EAClB;EACA,cAAc,gBAAwB,SAAS,QAAQ;EACvD;CACF;AACF;;AAGA,SAAgB,yBAAmE,EACjF,UAAU,CAAC,GACX,UAAU,CAAC,MACmD,CAAC,GAAqC;CACpG,MAAM,aAAa,QAAQ,KAAK,UAAU,EAAE,KAAK,EAAuB;CAExE,OAAO;EACL,QAAQ,EAAE,SAAS,WAAW;EAC9B;EACA,cAAc,GAAG,GAAG;EACpB,aAAa,GAAG,GAAG;EACnB,UAAU,GAAG,GAAG;EAChB,WAAW,GAAG,GAAG;EACjB,YAAY,GAAG,GAAG;EAClB,YAAY,GAAG,GAAG;EAClB,eAAe,GAAG,IAAI,eAAuB;GAC3C,MAAM,SAAS,WAAW,MAAM,UAAU,MAAM,SAAS,U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AA6C;CAC9I,IAAI,CAAC,OAAO,QAAQ;CAEpB,MAAM,EAAE,0BAAU,IAAI,IAAI,GAAG,QAAQ,QAAQ;CAC7C,MAAM,cAAc,IAAI,YAAY;CACpC,MAAM,4BAAY,IAAI,IAAoB;CAE1C,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,MAAM,QAAQ,UAAU,IAAI,KAAK,IAAI,GACxC;EAGF,MAAM,SAAS,MAAM,YAAY,MAAM,MAAM,EAAE,QAAQ,CAAC;EACxD,MAAM,OAAO,KAAK,SAAS,SAAS,OAAO,KAAK,CAAC,SAAS,SAAS,MAAM,OAAO,MAAM;EAEtF,UAAU,IAAI,KAAK,MAAM,IAAI;EAE7B,MAAM,eAAe,KAAK,KAAK,iBAAiB,GAAI,MAAM,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,GAAI,KAAK,QAAQ;EAC/F,MAAM,OAAO,IAAI,CAAC,CAAC,oBAAoB,YAAY;CACrD;CAEA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "5.8.4",
3
+ "version": "5.9.1",
4
4
  "description": "Core engine for Kubb. Provides the plugin driver, file manager and build orchestration used by every Kubb plugin.",
5
5
  "keywords": [
6
6
  "code-generator",
@@ -73,7 +73,7 @@
73
73
  "registry": "https://registry.npmjs.org/"
74
74
  },
75
75
  "dependencies": {
76
- "@kubb/ast": "5.8.4",
76
+ "@kubb/ast": "5.9.1",
77
77
  "tinyexec": "^1.3.1",
78
78
  "unstorage": "^1.17.5",
79
79
  "verkit": "^0.5.0"
@@ -81,6 +81,11 @@
81
81
  "description": "Names of the extensions that must be in the same config, e.g. ['plugin-ts'].",
82
82
  "items": { "type": "string", "maxLength": 214, "pattern": "^(?:@[a-z0-9~][a-z0-9._~-]*/)?[a-z0-9~][a-z0-9._~-]*$" }
83
83
  },
84
+ "optionalDependencies": {
85
+ "type": "array",
86
+ "description": "Names of the extensions used when they are in the same config, or needed only for some option values, e.g. ['plugin-faker'] for plugin-msw's parser: 'faker'.",
87
+ "items": { "type": "string", "maxLength": 214, "pattern": "^(?:@[a-z0-9~][a-z0-9._~-]*/)?[a-z0-9~][a-z0-9._~-]*$" }
88
+ },
84
89
  "compatibility": {
85
90
  "type": "object",
86
91
  "description": "Version ranges the extension supports. Only these two keys are allowed, so a typo cannot skip a check.",