@kubb/core 5.0.0-beta.89 → 5.0.0-beta.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,35 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as Include, A as KubbHookStartContext, At as Reporter, B as Kubb, C as KubbFilesProcessingEndContext, Ct as ResolverPathParams, D as KubbGenerationStartContext, Dt as Storage, E as KubbGenerationEndContext, Et as createRenderer, F as KubbSuccessContext, Ft as logLevel, G as KubbDriver, H as Generator, I as KubbWarnContext, It as Adapter, J as Parser, K as FileManagerHooks, L as PossibleConfig, Lt as AdapterFactoryOptions, M as KubbInfoContext, Mt as ReporterName, N as KubbLifecycleStartContext, Nt as UserReporter, O as KubbHookEndContext, Ot as createStorage, P as KubbPluginsEndContext, Pt as createReporter, Q as Group, R as UserConfig, Rt as AdapterSource, S as KubbFileProcessingUpdate, St as ResolverPatch, T as KubbFilesProcessingUpdateContext, Tt as RendererFactory, U as GeneratorContext, V as createKubb, W as defineGenerator, X as Exclude, Y as defineParser, Z as Filter, _ as InputPath, _t as Resolver, a as DiagnosticLocation, at as OutputMode, b as KubbDiagnosticContext, bt as ResolverFileParams, c as PerformanceDiagnostic, ct as Plugin, d as SerializedDiagnostic, dt as BannerMeta, et as KubbPluginEndContext, f as UpdateDiagnostic, ft as ResolveBannerContext, g as InputData, gt as ResolvePathOptions, h as Config, ht as ResolveOptionsContext, i as DiagnosticKind, it as Output, j as KubbHooks, jt as ReporterContext, k as KubbHookLineContext, kt as GenerationResult, l as ProblemCode, lt as PluginFactoryOptions, m as CLIOptions, mt as ResolveFileOptions, n as DiagnosticByCode, nt as KubbPluginStartContext, o as DiagnosticSeverity, ot as OutputOptions, p as BuildOutput, pt as ResolveBannerFile, q as Hookable, r as DiagnosticDoc, rt as NormalizedPlugin, s as Diagnostics, st as Override, t as Diagnostic, tt as KubbPluginSetupContext, u as ProblemDiagnostic, ut as definePlugin, v as KubbBuildEndContext, vt as ResolverDefault, w as KubbFilesProcessingStartContext, wt as Renderer, x as KubbErrorContext, xt as ResolverFilePathParams, y as KubbBuildStartContext, yt as ResolverFile, z as CreateKubbOptions, zt as createAdapter } from "./Diagnostics-CM0-Ae30.js";
2
+ import { $ as ResolveBannerFile, A as GeneratorContext, At as ProblemCode, B as KubbPluginEndContext, C as KubbWarnContext, Ct as DiagnosticByCode, D as Kubb, Dt as DiagnosticSeverity, E as CreateKubbOptions, Et as DiagnosticLocation, F as defineParser, Ft as Adapter, G as OutputMode, H as KubbPluginStartContext, I as Exclude, It as AdapterFactoryOptions, J as Plugin, K as OutputOptions, L as Filter, Lt as AdapterSource, M as KubbDriver, Mt as SerializedDiagnostic, N as FileManagerHooks, Nt as UpdateDiagnostic, O as createKubb, Ot as Diagnostics, P as Parser, Pt as Hookable, Q as ResolveBannerContext, R as Group, Rt as createAdapter, S as KubbSuccessContext, St as Diagnostic, T as UserConfig, Tt as DiagnosticKind, U as NormalizedPlugin, V as KubbPluginSetupContext, W as Output, X as definePlugin, Y as PluginFactoryOptions, Z as BannerMeta, _ as KubbHookStartContext, _t as ReporterContext, a as KubbBuildEndContext, at as ResolverFile, b as KubbLifecycleStartContext, bt as createReporter, c as KubbErrorContext, ct as ResolverPatch, d as KubbFilesProcessingStartContext, dt as RendererFactory, et as ResolveFileOptions, f as KubbFilesProcessingUpdateContext, ft as createRenderer, g as KubbHookLineContext, gt as Reporter, h as KubbHookEndContext, ht as GenerationResult, i as Input, it as ResolverDefault, j as defineGenerator, jt as ProblemDiagnostic, k as Generator, kt as PerformanceDiagnostic, l as KubbFileProcessingUpdate, lt as ResolverPathParams, m as KubbGenerationStartContext, mt as createStorage, n as CLIOptions, nt as ResolvePathOptions, o as KubbBuildStartContext, ot as ResolverFileParams, p as KubbGenerationEndContext, pt as Storage, q as Override, r as Config, rt as Resolver, s as KubbDiagnosticContext, st as ResolverFilePathParams, t as BuildOutput, tt as ResolveOptionsContext, u as KubbFilesProcessingEndContext, ut as Renderer, v as KubbHooks, vt as ReporterName, w as PossibleConfig, wt as DiagnosticDoc, x as KubbPluginsEndContext, xt as logLevel, y as KubbInfoContext, yt as UserReporter, z as Include } from "./types-aNebW3Ui.js";
3
3
 
4
+ //#region src/applyConfigDefaults.d.ts
5
+ type ApplyConfigDefaultsOptions<TOutput> = {
6
+ defaultAdapter: Adapter;
7
+ barrelPlugin: Plugin;
8
+ barrelPluginName: string; /** Output fields to fill in when the user's config leaves them unset. */
9
+ defaultOutput: Partial<TOutput>;
10
+ };
11
+ /**
12
+ * Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
13
+ * adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
14
+ * registered. Both entry points construct their own adapter, barrel plugin, and output defaults
15
+ * (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
16
+ * so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
17
+ */
18
+ declare function applyConfigDefaults<TOutput extends Config['output'] = Config['output']>(config: {
19
+ adapter?: Adapter;
20
+ output: TOutput;
21
+ plugins?: Array<Plugin>;
22
+ }, {
23
+ defaultAdapter,
24
+ barrelPlugin,
25
+ barrelPluginName,
26
+ defaultOutput
27
+ }: ApplyConfigDefaultsOptions<TOutput>): {
28
+ adapter: Adapter;
29
+ output: TOutput;
30
+ plugins: Array<Plugin>;
31
+ };
32
+ //#endregion
4
33
  //#region src/reporters/cliReporter.d.ts
5
34
  /**
6
35
  * The default `cli` reporter. Renders the {@link Report} for each config as it finishes, independent
@@ -88,6 +117,25 @@ type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof
88
117
  */
89
118
  declare function createResolver<T extends PluginFactoryOptions>(options: ResolverOptions<T>): T['resolver'];
90
119
  //#endregion
120
+ //#region src/input.d.ts
121
+ /**
122
+ * What an `input` value points at, once Kubb has looked at it.
123
+ *
124
+ * - `file` is a local file path, absolute or relative to the config file.
125
+ * - `url` is a remote document to fetch.
126
+ * - `inline` is OpenAPI content held in the string itself (JSON or YAML).
127
+ * - `object` is an already-parsed spec.
128
+ */
129
+ type InputKind = 'file' | 'url' | 'inline' | 'object';
130
+ /**
131
+ * Classifies an `input` value so callers branch on it once instead of repeating the checks.
132
+ *
133
+ * A non-string is a parsed spec (`object`). A string is `inline` when it holds OpenAPI content,
134
+ * meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
135
+ * `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
136
+ */
137
+ declare function getInputKind(input: NonNullable<Input>): InputKind;
138
+ //#endregion
91
139
  //#region src/storages/fsStorage.d.ts
92
140
  /**
93
141
  * Built-in filesystem storage driver.
@@ -110,7 +158,7 @@ declare function createResolver<T extends PluginFactoryOptions>(options: Resolve
110
158
  * import { defineConfig } from 'kubb'
111
159
  *
112
160
  * export default defineConfig({
113
- * input: { path: './petStore.yaml' },
161
+ * input: './petStore.yaml',
114
162
  * output: { path: './src/gen' },
115
163
  * storage: fsStorage(),
116
164
  * })
@@ -132,7 +180,7 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
132
180
  * import { defineConfig } from 'kubb'
133
181
  *
134
182
  * export default defineConfig({
135
- * input: { path: './petStore.yaml' },
183
+ * input: './petStore.yaml',
136
184
  * output: { path: './src/gen' },
137
185
  * storage: memoryStorage(),
138
186
  * })
@@ -140,5 +188,5 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
140
188
  */
141
189
  declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
142
190
  //#endregion
143
- export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticByCode, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, InputData, InputPath, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, PossibleConfig, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveOptionsContext, type ResolvePathOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, jsonReporter, logLevel, memoryStorage };
191
+ export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticByCode, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerationResult, type Generator, type GeneratorContext, type Group, Hookable, type Include, Input, type InputKind, type Kubb, KubbBuildEndContext, KubbBuildStartContext, KubbDiagnosticContext, KubbDriver, KubbErrorContext, KubbFileProcessingUpdate, KubbFilesProcessingEndContext, KubbFilesProcessingStartContext, KubbFilesProcessingUpdateContext, KubbGenerationEndContext, KubbGenerationStartContext, KubbHookEndContext, KubbHookLineContext, KubbHookStartContext, KubbHooks, KubbInfoContext, KubbLifecycleStartContext, type KubbPluginEndContext, type KubbPluginSetupContext, type KubbPluginStartContext, KubbPluginsEndContext, KubbSuccessContext, KubbWarnContext, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, PossibleConfig, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveOptionsContext, type ResolvePathOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
144
192
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { a as toFilePath, c as BuildError, d as camelCase, i as clean, l as getErrorMessage, n as FileManager, o as toPosixPath, r as Hookable, s as write, t as _usingCtx, u as toError } from "./usingCtx-Cnrm3TcM.js";
2
+ import { a as toFilePath, c as BuildError, d as camelCase, i as clean, l as getErrorMessage, n as FileManager, o as toPosixPath, r as Hookable, s as write, t as _usingCtx, u as toError } from "./usingCtx-BriKju-v.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { hash } from "node:crypto";
@@ -42,6 +42,26 @@ function createAdapter(build) {
42
42
  return (options) => build(options ?? {});
43
43
  }
44
44
  //#endregion
45
+ //#region src/applyConfigDefaults.ts
46
+ /**
47
+ * Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
48
+ * adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
49
+ * registered. Both entry points construct their own adapter, barrel plugin, and output defaults
50
+ * (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
51
+ * so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
52
+ */
53
+ function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
54
+ const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
55
+ return {
56
+ adapter: config.adapter ?? defaultAdapter,
57
+ plugins,
58
+ output: {
59
+ ...defaultOutput,
60
+ ...config.output
61
+ }
62
+ };
63
+ }
64
+ //#endregion
45
65
  //#region ../../internals/utils/src/time.ts
46
66
  /**
47
67
  * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
@@ -170,7 +190,7 @@ function memoize(store, factory) {
170
190
  }
171
191
  //#endregion
172
192
  //#region package.json
173
- var version = "5.0.0-beta.89";
193
+ var version = "5.0.0-beta.91";
174
194
  //#endregion
175
195
  //#region src/constants.ts
176
196
  /**
@@ -196,7 +216,7 @@ const diagnosticCode = {
196
216
  */
197
217
  unknown: "KUBB_UNKNOWN",
198
218
  /**
199
- * The `input.path` file or URL could not be read.
219
+ * The file or URL set as `input` could not be read.
200
220
  */
201
221
  inputNotFound: "KUBB_INPUT_NOT_FOUND",
202
222
  /**
@@ -351,13 +371,13 @@ const diagnosticCatalog = {
351
371
  },
352
372
  [diagnosticCode.inputNotFound]: {
353
373
  title: "Input not found",
354
- cause: "The file or URL set in `input.path` (or passed as `kubb generate PATH`) could not be read.",
355
- fix: "Check that the path or URL exists and is readable, then set it in `input.path` or pass it on the CLI."
374
+ cause: "The file or URL set as `input` (or passed as `kubb generate PATH`) could not be read.",
375
+ fix: "Check that the path or URL exists and is readable, then set it as `input` or pass it on the CLI."
356
376
  },
357
377
  [diagnosticCode.inputRequired]: {
358
378
  title: "Input required",
359
379
  cause: "An adapter is configured but no `input` was provided.",
360
- fix: "Set `input.path` (a file or URL) or `input.data` (an inline spec) in your Kubb config."
380
+ fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
361
381
  },
362
382
  [diagnosticCode.refNotFound]: {
363
383
  title: "Reference not found",
@@ -740,6 +760,55 @@ function definePlugin(factory) {
740
760
  return (options) => factory(options ?? {});
741
761
  }
742
762
  //#endregion
763
+ //#region src/input.ts
764
+ /**
765
+ * Classifies an `input` value so callers branch on it once instead of repeating the checks.
766
+ *
767
+ * A non-string is a parsed spec (`object`). A string is `inline` when it holds OpenAPI content,
768
+ * meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
769
+ * `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
770
+ */
771
+ function getInputKind(input) {
772
+ if (typeof input !== "string") return "object";
773
+ const trimmed = input.trimStart();
774
+ if (trimmed.startsWith("{") || trimmed.startsWith("[") || input.includes("\n") || /^(openapi|swagger)\s*:/i.test(trimmed)) return "inline";
775
+ if (URL.canParse(input)) return "url";
776
+ return "file";
777
+ }
778
+ /**
779
+ * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
780
+ *
781
+ * A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
782
+ * local path is resolved against `config.root`, both as `{ type: 'path' }`.
783
+ */
784
+ function inputToAdapterSource(config) {
785
+ const input = config.input;
786
+ if (!input) throw new Diagnostics.Error({
787
+ code: Diagnostics.code.inputRequired,
788
+ severity: "error",
789
+ message: "An adapter is configured without an input.",
790
+ help: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config.",
791
+ location: { kind: "config" }
792
+ });
793
+ if (typeof input !== "string") return {
794
+ type: "data",
795
+ data: input
796
+ };
797
+ const kind = getInputKind(input);
798
+ if (kind === "inline") return {
799
+ type: "data",
800
+ data: input
801
+ };
802
+ if (kind === "url") return {
803
+ type: "path",
804
+ path: input
805
+ };
806
+ return {
807
+ type: "path",
808
+ path: resolve(config.root, input)
809
+ };
810
+ }
811
+ //#endregion
743
812
  //#region src/Resolver.ts
744
813
  function isNamespace(value) {
745
814
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1028,8 +1097,10 @@ var Resolver = class Resolver {
1028
1097
  "* Do not edit manually."
1029
1098
  ];
1030
1099
  if (config.output.defaultBanner !== "simple") {
1031
- const input = Array.isArray(config.input) ? config.input[0] : config.input;
1032
- const source = input && "path" in input ? path.basename(input.path) : input && "data" in input ? "text content" : "";
1100
+ const input = config.input;
1101
+ let source = "";
1102
+ if (typeof input === "string") source = getInputKind(input) === "inline" ? "text content" : path.basename(input);
1103
+ else if (input) source = "text content";
1033
1104
  if (source) lines.push(`* Source: ${source}`);
1034
1105
  if (title) lines.push(`* Title: ${title}`);
1035
1106
  if (version) lines.push(`* OpenAPI spec version: ${version}`);
@@ -1318,14 +1389,12 @@ var KubbDriver = class {
1318
1389
  * plugins can configure generators, resolvers, macros, and options before `buildStart`.
1319
1390
  */
1320
1391
  async setupHooks() {
1321
- const noop = () => {};
1322
1392
  for (const plugin of this.plugins.values()) {
1323
1393
  const setup = plugin.hooks?.["kubb:plugin:setup"];
1324
1394
  if (!setup) continue;
1325
1395
  await setup({
1326
1396
  config: this.config,
1327
1397
  options: plugin.options ?? {},
1328
- updateConfig: noop,
1329
1398
  addGenerator: (...generators) => {
1330
1399
  for (const generator of generators) this.registerGenerator(plugin.name, generator);
1331
1400
  },
@@ -1489,8 +1558,7 @@ var KubbDriver = class {
1489
1558
  await hooks.callHook("kubb:plugins:end", Object.assign({ config }, this.#filesPayload()));
1490
1559
  await fileManager.write(fileManager.files, {
1491
1560
  storage: config.storage,
1492
- parsers: parsersMap,
1493
- extension: config.output.extension
1561
+ parsers: parsersMap
1494
1562
  });
1495
1563
  await hooks.callHook("kubb:build:end", {
1496
1564
  files: this.fileManager.files,
@@ -1808,28 +1876,6 @@ var KubbDriver = class {
1808
1876
  });
1809
1877
  }
1810
1878
  };
1811
- function inputToAdapterSource(config) {
1812
- const input = config.input;
1813
- if (!input) throw new Diagnostics.Error({
1814
- code: Diagnostics.code.inputRequired,
1815
- severity: "error",
1816
- message: "An adapter is configured without an input.",
1817
- help: "Provide `input.path` (a file or URL) or `input.data` (an inline spec) in your Kubb config.",
1818
- location: { kind: "config" }
1819
- });
1820
- if ("data" in input) return {
1821
- type: "data",
1822
- data: input.data
1823
- };
1824
- if (URL.canParse(input.path)) return {
1825
- type: "path",
1826
- path: input.path
1827
- };
1828
- return {
1829
- type: "path",
1830
- path: resolve(config.root, input.path)
1831
- };
1832
- }
1833
1879
  //#endregion
1834
1880
  //#region src/createStorage.ts
1835
1881
  /**
@@ -1919,7 +1965,7 @@ function createLimiter(concurrency) {
1919
1965
  * import { defineConfig } from 'kubb'
1920
1966
  *
1921
1967
  * export default defineConfig({
1922
- * input: { path: './petStore.yaml' },
1968
+ * input: './petStore.yaml',
1923
1969
  * output: { path: './src/gen' },
1924
1970
  * storage: fsStorage(),
1925
1971
  * })
@@ -1977,7 +2023,6 @@ function resolveConfig(userConfig) {
1977
2023
  output: {
1978
2024
  format: false,
1979
2025
  lint: false,
1980
- extension: { ".ts": ".ts" },
1981
2026
  defaultBanner: "simple",
1982
2027
  ...userConfig.output
1983
2028
  },
@@ -2087,7 +2132,7 @@ var Kubb = class {
2087
2132
  * import { pluginTs } from '@kubb/plugin-ts'
2088
2133
  *
2089
2134
  * const kubb = createKubb({
2090
- * input: { path: './petStore.yaml' },
2135
+ * input: './petStore.yaml',
2091
2136
  * output: { path: './src/gen' },
2092
2137
  * adapter: adapterOas(),
2093
2138
  * plugins: [pluginTs()],
@@ -2412,30 +2457,34 @@ function defineGenerator(generator) {
2412
2457
  //#endregion
2413
2458
  //#region src/defineParser.ts
2414
2459
  /**
2415
- * Defines a parser with type-safe `this`. Used to register handlers for new
2416
- * file extensions or to plug a non-TypeScript output into the build.
2460
+ * Wraps a parser factory and returns a function that accepts user options and
2461
+ * yields a typed {@link Parser}. Mirrors {@link definePlugin}: the factory
2462
+ * receives the caller's options, and calling the returned function without
2463
+ * options passes an empty object.
2464
+ *
2465
+ * Register the result in the `parsers` array on `defineConfig`, calling it to
2466
+ * apply options (`parserTs({ extension: { '.ts': '.js' } })`).
2417
2467
  *
2418
2468
  * @example
2419
2469
  * ```ts
2420
2470
  * import { defineParser } from '@kubb/core'
2421
2471
  * import { extractStringsFromNodes } from '@kubb/ast'
2422
2472
  *
2423
- * export const jsonParser = defineParser({
2473
+ * export const parserJson = defineParser((options: { pretty?: boolean } = {}) => ({
2424
2474
  * name: 'json',
2425
2475
  * extNames: ['.json'],
2426
2476
  * parse(file) {
2427
- * return file.sources
2428
- * .map((source) => extractStringsFromNodes(source.nodes ?? []))
2429
- * .join('\n')
2477
+ * const source = file.sources.map((source) => extractStringsFromNodes(source.nodes ?? [])).join('\n')
2478
+ * return options.pretty ? JSON.stringify(JSON.parse(source), null, 2) : source
2430
2479
  * },
2431
2480
  * print(...nodes) {
2432
2481
  * return nodes.map(String).join('\n')
2433
2482
  * },
2434
- * })
2483
+ * }))
2435
2484
  * ```
2436
2485
  */
2437
- function defineParser(parser) {
2438
- return parser;
2486
+ function defineParser(factory) {
2487
+ return (options) => factory(options ?? {});
2439
2488
  }
2440
2489
  //#endregion
2441
2490
  //#region src/storages/memoryStorage.ts
@@ -2452,7 +2501,7 @@ function defineParser(parser) {
2452
2501
  * import { defineConfig } from 'kubb'
2453
2502
  *
2454
2503
  * export default defineConfig({
2455
- * input: { path: './petStore.yaml' },
2504
+ * input: './petStore.yaml',
2456
2505
  * output: { path: './src/gen' },
2457
2506
  * storage: memoryStorage(),
2458
2507
  * })
@@ -2488,6 +2537,6 @@ const memoryStorage = createStorage(() => {
2488
2537
  };
2489
2538
  });
2490
2539
  //#endregion
2491
- export { Diagnostics, Hookable, KubbDriver, Resolver, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, jsonReporter, logLevel, memoryStorage };
2540
+ export { Diagnostics, Hookable, KubbDriver, Resolver, applyConfigDefaults, cliReporter, createAdapter, createKubb, createRenderer, createReporter, createResolver, createStorage, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, jsonReporter, logLevel, memoryStorage };
2492
2541
 
2493
2542
  //# sourceMappingURL=index.js.map