@kubb/core 5.1.0 → 5.2.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { $ as PluginFactoryOptions, A as Kubb, At as DiagnosticDoc, B as Exclude, Bt as Hookable, C as KubbWarnContext, Ct as Reporter, D as CreateKubbOptions, Dt as createReporter, E as UserConfig, Et as UserReporter, F as NodeCache, Ft as PerformanceDiagnostic, G as KubbPluginSetupContext, H as Group, Ht as AdapterFactoryOptions, I as KubbDriver, It as ProblemCode, J as Output, K as KubbPluginStartContext, L as FileManagerHooks, Lt as ProblemDiagnostic, M as Generator, Mt as DiagnosticLocation, N as GeneratorContext, Nt as DiagnosticSeverity, O as GenerateOptions, Ot as logLevel, P as defineGenerator, Pt as Diagnostics, Q as Plugin, R as Parser, Rt as SerializedDiagnostic, S as KubbSuccessContext, St as GenerationResult, T as PostGenerateCommand, Tt as ReporterName, U as Include, Ut as AdapterSource, V as Filter, Vt as Adapter, W as KubbPluginEndContext, Wt as createAdapter, X as OutputOptions, Y as OutputMode, Z as Override, _ as KubbHookStartContext, _t as Renderer, a as KubbBuildEndContext, at as ResolveBannerFile, b as KubbLifecycleStartContext, bt as Storage, c as KubbErrorContext, ct as ResolveOptionsContext, d as KubbFilesProcessingStartContext, dt as ResolverDefault, et as PluginName, f as KubbFilesProcessingUpdateContext, ft as ResolverFile, g as KubbHookLineContext, gt as ResolverPathParams, h as KubbHookEndContext, ht as ResolverPatch, i as Input, it as ResolveBannerContext, j as createKubb, jt as DiagnosticKind, k as GenerateResult, kt as Diagnostic, l as KubbFileProcessingUpdate, lt as ResolvePathOptions, m as KubbGenerationStartContext, mt as ResolverFilePathParams, n as CLIOptions, nt as definePlugin, o as KubbBuildStartContext, ot as ResolveFileOptions, p as KubbGenerationEndContext, pt as ResolverFileParams, q as NormalizedPlugin, r as Config, rt as BannerMeta, s as KubbDiagnosticContext, st as ResolveImportsOptions, t as BuildOutput, tt as ResolvePluginOptions, u as KubbFilesProcessingEndContext, ut as Resolver, v as KubbHooks, vt as RendererFactory, w as PossibleConfig, wt as ReporterContext, x as KubbPluginsEndContext, xt as createStorage, y as KubbInfoContext, yt as createRenderer, z as defineParser, zt as UpdateDiagnostic } from "./types-QndGMAwn.js";
2
+ import { $ as PluginFactoryOptions, A as Kubb, At as DiagnosticDoc, B as Exclude, Bt as Hookable, C as KubbWarnContext, Ct as Reporter, D as CreateKubbOptions, Dt as createReporter, E as UserConfig, Et as UserReporter, F as NodeCache, Ft as PerformanceDiagnostic, G as KubbPluginSetupContext, H as Group, Ht as AdapterFactoryOptions, I as KubbDriver, It as ProblemCode, J as Output, K as KubbPluginStartContext, L as FileManagerHooks, Lt as ProblemDiagnostic, M as Generator, Mt as DiagnosticLocation, N as GeneratorContext, Nt as DiagnosticSeverity, O as GenerateOptions, Ot as logLevel, P as defineGenerator, Pt as Diagnostics, Q as Plugin, R as Parser, Rt as SerializedDiagnostic, S as KubbSuccessContext, St as GenerationResult, T as PostGenerateCommand, Tt as ReporterName, U as Include, Ut as AdapterSource, V as Filter, Vt as Adapter, W as KubbPluginEndContext, Wt as createAdapter, X as OutputOptions, Y as OutputMode, Z as Override, _ as KubbHookStartContext, _t as Renderer, a as KubbBuildEndContext, at as ResolveBannerFile, b as KubbLifecycleStartContext, bt as Storage, c as KubbErrorContext, ct as ResolveOptionsContext, d as KubbFilesProcessingStartContext, dt as ResolverDefault, et as PluginName, f as KubbFilesProcessingUpdateContext, ft as ResolverFile, g as KubbHookLineContext, gt as ResolverPathParams, h as KubbHookEndContext, ht as ResolverPatch, i as Input, it as ResolveBannerContext, j as createKubb, jt as DiagnosticKind, k as GenerateResult, kt as Diagnostic, l as KubbFileProcessingUpdate, lt as ResolvePathOptions, m as KubbGenerationStartContext, mt as ResolverFilePathParams, n as CLIOptions, nt as definePlugin, o as KubbBuildStartContext, ot as ResolveFileOptions, p as KubbGenerationEndContext, pt as ResolverFileParams, q as NormalizedPlugin, r as Config, rt as BannerMeta, s as KubbDiagnosticContext, st as ResolveImportsOptions, t as BuildOutput, tt as ResolvePluginOptions, u as KubbFilesProcessingEndContext, ut as Resolver, v as KubbHooks, vt as RendererFactory, w as PossibleConfig, wt as ReporterContext, x as KubbPluginsEndContext, xt as createStorage, y as KubbInfoContext, yt as createRenderer, z as defineParser, zt as UpdateDiagnostic } from "./types-D6fWCd9O.js";
3
3
  //#region src/applyConfigDefaults.d.ts
4
4
  type ApplyConfigDefaultsOptions<TOutput> = {
5
5
  defaultAdapter: Adapter;
@@ -15,7 +15,7 @@ type ApplyConfigDefaultsOptions<TOutput> = {
15
15
  * (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
16
16
  * so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
17
17
  */
18
- declare function applyConfigDefaults<TOutput extends Config['output'] = Config['output']>(config: {
18
+ export declare function applyConfigDefaults<TOutput extends Config['output'] = Config['output']>(config: {
19
19
  adapter?: Adapter;
20
20
  output: TOutput;
21
21
  plugins?: Array<Plugin>;
@@ -30,7 +30,7 @@ declare function applyConfigDefaults<TOutput extends Config['output'] = Config['
30
30
  * The default `cli` reporter. Renders the {@link Report} for each config as it finishes, independent
31
31
  * of the live logger view. Suppressed at `silent`. The `verbose` level adds the per-plugin timings.
32
32
  */
33
- declare const cliReporter: Reporter;
33
+ export declare const cliReporter: Reporter;
34
34
  //#endregion
35
35
  //#region src/reporters/fileReporter.d.ts
36
36
  /**
@@ -43,7 +43,7 @@ declare const cliReporter: Reporter;
43
43
  * `kubb:info`/`kubb:plugin` hook stream. Color is stripped so the file stays plain text even when
44
44
  * the run is attached to a TTY.
45
45
  */
46
- declare const fileReporter: Reporter;
46
+ export declare const fileReporter: Reporter;
47
47
  //#endregion
48
48
  //#region src/reporters/jsonReporter.d.ts
49
49
  /**
@@ -53,7 +53,7 @@ declare const fileReporter: Reporter;
53
53
  * objects that would break `jq .`. The terminal reporter is suppressed while `json` is active so
54
54
  * stdout stays valid JSON.
55
55
  */
56
- declare const jsonReporter: Reporter;
56
+ export declare const jsonReporter: Reporter;
57
57
  //#endregion
58
58
  //#region src/createResolver.d.ts
59
59
  /**
@@ -110,7 +110,7 @@ type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof
110
110
  * })
111
111
  * ```
112
112
  */
113
- declare function createResolver<T extends PluginFactoryOptions>(options: ResolverOptions<T>): T['resolver'];
113
+ export declare function createResolver<T extends PluginFactoryOptions>(options: ResolverOptions<T>): T['resolver'];
114
114
  //#endregion
115
115
  //#region src/input.d.ts
116
116
  /**
@@ -129,7 +129,7 @@ type InputKind = 'file' | 'url' | 'inline' | 'object';
129
129
  * meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
130
130
  * `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
131
131
  */
132
- declare function getInputKind(input: NonNullable<Input>): InputKind;
132
+ export declare function getInputKind(input: NonNullable<Input>): InputKind;
133
133
  //#endregion
134
134
  //#region src/storages/fsStorage.d.ts
135
135
  /**
@@ -160,7 +160,7 @@ declare function getInputKind(input: NonNullable<Input>): InputKind;
160
160
  * })
161
161
  * ```
162
162
  */
163
- declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
163
+ export declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
164
164
  //#endregion
165
165
  //#region src/storages/memoryStorage.d.ts
166
166
  /**
@@ -182,7 +182,7 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Storag
182
182
  * })
183
183
  * ```
184
184
  */
185
- declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
185
+ export declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
186
186
  //#endregion
187
- export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerateOptions, type GenerateResult, 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 NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, 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 };
187
+ export { type Adapter, type AdapterFactoryOptions, type AdapterSource, type BannerMeta, BuildOutput, CLIOptions, Config, type CreateKubbOptions, type Diagnostic, type DiagnosticDoc, type DiagnosticKind, type DiagnosticLocation, type DiagnosticSeverity, Diagnostics, type Exclude, type FileManagerHooks, type Filter, type GenerateOptions, type GenerateResult, 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 NodeCache, type NormalizedPlugin, type Output, type OutputMode, type OutputOptions, type Override, type Parser, type PerformanceDiagnostic, type Plugin, type PluginFactoryOptions, type PluginName, PossibleConfig, PostGenerateCommand, type ProblemCode, type ProblemDiagnostic, type Renderer, type RendererFactory, type Reporter, type ReporterContext, type ReporterName, type ResolveBannerContext, type ResolveBannerFile, type ResolveFileOptions, type ResolveImportsOptions, type ResolveOptionsContext, type ResolvePathOptions, type ResolvePluginOptions, Resolver, type ResolverDefault, type ResolverFile, type ResolverFileParams, type ResolverFilePathParams, type ResolverPatch, type ResolverPathParams, type SerializedDiagnostic, type Storage, type UpdateDiagnostic, UserConfig, type UserReporter, createAdapter, createKubb, createRenderer, createReporter, createStorage, defineGenerator, defineParser, definePlugin, logLevel };
188
188
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { a as OPERATION_FILTER_TYPES, c as clean, d as toPosixPath, f as write, g as camelCase, h as toError, i as Hookable, l as isPathInside, m as getErrorMessage, n as createNodeCache, o as diagnosticCode, p as BuildError, r as FileManager, s as inParallel, t as _usingCtx, u as toFilePath } from "./usingCtx-2r6N3STL.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
+ import { a as OPERATION_FILTER_TYPES, c as clean, d as write, f as getErrorMessage, i as Hookable, l as isPathInside, m as camelCase, n as createNodeCache, o as diagnosticCode, p as toError, r as FileManager, s as inParallel, t as _usingCtx, u as toPosixPath } from "./usingCtx-xMZZh-09.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { stripVTControlCharacters, styleText } from "node:util";
5
- import { createHash, hash } from "node:crypto";
6
5
  import { access, glob, readFile, rm } from "node:fs/promises";
7
6
  import path, { join, relative, resolve } from "node:path";
8
7
  import { ast, collectImportedRefNames, collectUsedSchemaNames, composeMacros, operationDef, schemaDef, transform } from "@kubb/ast";
8
+ import { hash } from "node:crypto";
9
9
  import { existsSync } from "node:fs";
10
10
  import { tmpdir } from "node:os";
11
11
  import process$1 from "node:process";
@@ -96,66 +96,11 @@ function formatMs(ms) {
96
96
  return `${Math.round(ms)}ms`;
97
97
  }
98
98
  //#endregion
99
- //#region ../../internals/utils/src/colors.ts
100
- /**
101
- * Parses a CSS hex color string (`#RGB`) into its RGB channels.
102
- * Falls back to `255` for any channel that cannot be parsed.
103
- */
104
- function parseHex(color) {
105
- const int = Number.parseInt(color.replace("#", ""), 16);
106
- return Number.isNaN(int) ? {
107
- r: 255,
108
- g: 255,
109
- b: 255
110
- } : {
111
- r: int >> 16 & 255,
112
- g: int >> 8 & 255,
113
- b: int & 255
114
- };
115
- }
116
- /**
117
- * Returns a function that wraps a string in a 24-bit ANSI true-color escape sequence
118
- * for the given hex color.
119
- */
120
- function hex(color) {
121
- const { r, g, b } = parseHex(color);
122
- return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
123
- }
124
- hex("#F55A17"), hex("#F5A217"), hex("#F58517"), hex("#B45309"), hex("#FFFFFF"), hex("#adadc6"), hex("#FDA4AF");
125
- /**
126
- * ANSI color names used by {@link randomCliColor} for deterministic terminal coloring.
127
- */
128
- const randomColors = [
129
- "black",
130
- "red",
131
- "green",
132
- "yellow",
133
- "blue",
134
- "white",
135
- "magenta",
136
- "cyan",
137
- "gray"
138
- ];
139
- /**
140
- * Wraps `text` in a deterministic ANSI color derived from the text's SHA-256 hash.
141
- *
142
- * @example
143
- * ```ts
144
- * randomCliColor('petstore') // '\x1b[33m' + 'petstore' + '\x1b[39m' (always the same color for 'petstore')
145
- * ```
146
- */
147
- function randomCliColor(text) {
148
- if (!text) return "";
149
- const index = hash("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
150
- const color = randomColors[index] ?? "white";
151
- return styleText(color, text);
152
- }
153
- //#endregion
154
99
  //#region src/Diagnostics.ts
155
100
  /**
156
101
  * Docs major version, derived from the package version so the link tracks the published major.
157
102
  */
158
- const docsMajor = "5.1.0".split(".")[0] ?? "5";
103
+ const docsMajor = "5.2.1".split(".")[0] ?? "5";
159
104
  /**
160
105
  * Builds a type guard that narrows a {@link Diagnostic} to the variant for `kind`. A diagnostic
161
106
  * with no `kind` is treated as a `problem`.
@@ -714,6 +659,29 @@ function isNamespace(value) {
714
659
  */
715
660
  const resolverOptions = Symbol.for("@kubb/core/resolver/options");
716
661
  /**
662
+ * Builds a nested file path from a dotted name. Splits on dots that precede a letter
663
+ * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
664
+ * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
665
+ *
666
+ * Empty segments are dropped before joining. They arise when the name starts with a dot
667
+ * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
668
+ * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
669
+ * absolute path, letting generated files escape the configured output directory.
670
+ *
671
+ * @example Nested path from a dotted name
672
+ * `toFilePath('pet.petId') // 'pet/petId'`
673
+ *
674
+ * @example PascalCase the final segment
675
+ * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
676
+ *
677
+ * @example Suffix applied to the final segment only
678
+ * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
679
+ */
680
+ function toFilePath(name, caseLast = camelCase) {
681
+ const parts = name.split(/\.(?=[a-zA-Z])/);
682
+ return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
683
+ }
684
+ /**
717
685
  * Built-in `file.baseName`: casts the identifier with `toFilePath` and appends the extension.
718
686
  */
719
687
  function toBaseName({ name, extname }) {
@@ -1860,10 +1828,6 @@ var KubbDriver = class {
1860
1828
  * Bumped when the stored shape changes, so an older cache is discarded instead of misread.
1861
1829
  */
1862
1830
  const VERSION = 1;
1863
- function hash$1(value) {
1864
- return createHash("sha256").update(value).digest("hex");
1865
- }
1866
- __name(hash$1, "hash");
1867
1831
  const MANIFEST_KEY = "output-manifest.json";
1868
1832
  async function loadEntries({ cache }) {
1869
1833
  try {
@@ -1893,10 +1857,10 @@ async function createOutputManifest({ storage, cache }) {
1893
1857
  isUpToDate({ key, source, disk }) {
1894
1858
  const entry = entries[key];
1895
1859
  if (!entry) return false;
1896
- return entry.source === hash$1(source) && entry.output === hash$1(disk);
1860
+ return entry.source === hash("sha256", source) && entry.output === hash("sha256", disk);
1897
1861
  },
1898
1862
  track({ key, source }) {
1899
- tracked.set(key, hash$1(source));
1863
+ tracked.set(key, hash("sha256", source));
1900
1864
  },
1901
1865
  async commit() {
1902
1866
  try {
@@ -1909,7 +1873,7 @@ async function createOutputManifest({ storage, cache }) {
1909
1873
  if (stored === null) return;
1910
1874
  next[key] = {
1911
1875
  source,
1912
- output: hash$1(stored)
1876
+ output: hash("sha256", stored)
1913
1877
  };
1914
1878
  }
1915
1879
  });
@@ -2076,7 +2040,7 @@ const fsStorage = createStorage(() => {
2076
2040
  function resolveCacheDir(root) {
2077
2041
  const nodeModules = join(root, "node_modules");
2078
2042
  if (existsSync(nodeModules)) return join(nodeModules, ".cache", "kubb");
2079
- return join(tmpdir(), "kubb", createHash("sha256").update(root).digest("hex").slice(0, 16));
2043
+ return join(tmpdir(), "kubb", hash("sha256", root).slice(0, 16));
2080
2044
  }
2081
2045
  /**
2082
2046
  * Filesystem storage for build caches rather than generated code. Keys are plain names resolved
@@ -2214,7 +2178,7 @@ var Kubb = class {
2214
2178
  const out = await this.safeBuild();
2215
2179
  if (Diagnostics.hasError(out.diagnostics)) {
2216
2180
  const errors = out.diagnostics.filter(Diagnostics.isProblem).filter((diagnostic) => diagnostic.severity === "error").map((diagnostic) => diagnostic.cause ?? new Diagnostics.Error(diagnostic));
2217
- throw new BuildError(`Build failed with ${errors.length} ${errors.length === 1 ? "error" : "errors"}`, { errors });
2181
+ throw new AggregateError(errors, `Build failed with ${errors.length} ${errors.length === 1 ? "error" : "errors"}`);
2218
2182
  }
2219
2183
  return out;
2220
2184
  }
@@ -2390,6 +2354,36 @@ function createReporter(reporter) {
2390
2354
  };
2391
2355
  }
2392
2356
  //#endregion
2357
+ //#region src/reporters/colors.ts
2358
+ /**
2359
+ * ANSI color names used by {@link randomCliColor} for deterministic terminal coloring.
2360
+ */
2361
+ const randomColors = [
2362
+ "black",
2363
+ "red",
2364
+ "green",
2365
+ "yellow",
2366
+ "blue",
2367
+ "white",
2368
+ "magenta",
2369
+ "cyan",
2370
+ "gray"
2371
+ ];
2372
+ /**
2373
+ * Wraps `text` in a deterministic ANSI color derived from the text's SHA-256 hash.
2374
+ *
2375
+ * @example
2376
+ * ```ts
2377
+ * randomCliColor('petstore') // '\x1b[33m' + 'petstore' + '\x1b[39m' (always the same color for 'petstore')
2378
+ * ```
2379
+ */
2380
+ function randomCliColor(text) {
2381
+ if (!text) return "";
2382
+ const index = hash("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
2383
+ const color = randomColors[index] ?? "white";
2384
+ return styleText(color, text);
2385
+ }
2386
+ //#endregion
2393
2387
  //#region src/reporters/report.ts
2394
2388
  /**
2395
2389
  * Builds the normalized {@link Report} for one config from its {@link GenerationResult}. Splits the