@kubb/core 5.0.0-beta.105 → 5.0.0-beta.107

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-D116CBzm.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-Dtisidv5.js";
3
3
  //#region src/applyConfigDefaults.d.ts
4
4
  type ApplyConfigDefaultsOptions<TOutput> = {
5
5
  defaultAdapter: Adapter;
@@ -144,7 +144,7 @@ declare function getInputKind(input: NonNullable<Input>): InputKind;
144
144
  * - the write is skipped when the file content is already identical
145
145
  * - missing parent directories are created automatically
146
146
  * - Bun's native file API is used when running under Bun
147
- * - concurrent `setItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
147
+ * - concurrent `writeItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
148
148
  * can fire every file's write without pacing itself
149
149
  *
150
150
  * @example
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { a as clean, c as toPosixPath, d as getErrorMessage, f as toError, i as Hookable, l as write, n as createNodeCache, o as isPathInside, p as camelCase, r as FileManager, s as toFilePath, t as _usingCtx, u as BuildError } from "./usingCtx-C24YU3KM.js";
2
+ import { a as clean, c as toPosixPath, d as getErrorMessage, f as toError, i as Hookable, l as write, n as createNodeCache, o as isPathInside, p as camelCase, r as FileManager, s as toFilePath, t as _usingCtx, u as BuildError } from "./usingCtx-D9_Ee6kn.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { stripVTControlCharacters, styleText } from "node:util";
5
5
  import { hash } from "node:crypto";
@@ -145,11 +145,12 @@ const randomColors = [
145
145
  function randomCliColor(text) {
146
146
  if (!text) return "";
147
147
  const index = hash("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
148
- return styleText(randomColors[index] ?? "white", text);
148
+ const color = randomColors[index] ?? "white";
149
+ return styleText(color, text);
149
150
  }
150
151
  //#endregion
151
152
  //#region package.json
152
- var version = "5.0.0-beta.105";
153
+ var version = "5.0.0-beta.107";
153
154
  //#endregion
154
155
  //#region src/constants.ts
155
156
  /**
@@ -183,6 +184,16 @@ const diagnosticCode = {
183
184
  */
184
185
  inputRequired: "KUBB_INPUT_REQUIRED",
185
186
  /**
187
+ * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed
188
+ * document instead of a pointer to one.
189
+ */
190
+ legacyInput: "KUBB_LEGACY_INPUT",
191
+ /**
192
+ * The parsed `input` carries no `openapi` or `swagger` version, so it is not a
193
+ * document the adapter can read.
194
+ */
195
+ invalidDocument: "KUBB_INVALID_DOCUMENT",
196
+ /**
186
197
  * A `$ref` (or equivalent reference) could not be resolved in the source document.
187
198
  */
188
199
  refNotFound: "KUBB_REF_NOT_FOUND",
@@ -329,6 +340,16 @@ const diagnosticCatalog = {
329
340
  cause: "An adapter is configured but no `input` was provided.",
330
341
  fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
331
342
  },
343
+ [diagnosticCode.legacyInput]: {
344
+ title: "Legacy input shape",
345
+ cause: "`input` is a `{ path }` or `{ data }` wrapper, which v4 used to point at a document and v5 reads as the document itself.",
346
+ fix: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`."
347
+ },
348
+ [diagnosticCode.invalidDocument]: {
349
+ title: "Invalid document",
350
+ cause: "The parsed `input` has no `openapi` or `swagger` version field, so it is not an OpenAPI or Swagger document.",
351
+ fix: "Point `input` at a document that declares `openapi` or `swagger`, and check that a passed object is the spec itself rather than a wrapper around it."
352
+ },
332
353
  [diagnosticCode.refNotFound]: {
333
354
  title: "Reference not found",
334
355
  cause: "A `$ref` could not be resolved in the source document.",
@@ -727,6 +748,23 @@ function getInputKind(input) {
727
748
  return "file";
728
749
  }
729
750
  /**
751
+ * The v4 `input` wrapper keys. v4 typed `input` as `{ path }` or `{ data }`; v5 takes the value
752
+ * directly, so the wrapper now matches the "already-parsed document" branch and silently yields
753
+ * an empty build.
754
+ */
755
+ const legacyInputKeys = ["path", "data"];
756
+ /**
757
+ * Detects the v4 `{ path }` / `{ data }` wrapper so it fails loudly instead of being read as a
758
+ * document. A real spec always carries more than these keys, so an object whose keys are drawn
759
+ * only from them is the old shape rather than a document that happens to have a `path` property.
760
+ */
761
+ function isLegacyInput(input) {
762
+ if (Array.isArray(input)) return input.some(isLegacyInput);
763
+ if (typeof input !== "object" || input === null) return false;
764
+ const keys = Object.keys(input);
765
+ return keys.length > 0 && keys.every((key) => legacyInputKeys.includes(key));
766
+ }
767
+ /**
730
768
  * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
731
769
  *
732
770
  * A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
@@ -734,6 +772,13 @@ function getInputKind(input) {
734
772
  */
735
773
  function inputToAdapterSource(config) {
736
774
  const input = config.input;
775
+ if (input && isLegacyInput(input)) throw new Diagnostics.Error({
776
+ code: Diagnostics.code.legacyInput,
777
+ severity: "error",
778
+ message: "The `input` option uses the v4 `{ path }` / `{ data }` wrapper.",
779
+ help: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`.",
780
+ location: { kind: "config" }
781
+ });
737
782
  if (!input) throw new Diagnostics.Error({
738
783
  code: Diagnostics.code.inputRequired,
739
784
  severity: "error",
@@ -1925,23 +1970,23 @@ var KubbDriver = class {
1925
1970
  *
1926
1971
  * return {
1927
1972
  * name: 'memory',
1928
- * async hasItem(key) {
1973
+ * async existsItem(key) {
1929
1974
  * return store.has(key)
1930
1975
  * },
1931
- * async getItem(key) {
1976
+ * async readItem(key) {
1932
1977
  * return store.get(key) ?? null
1933
1978
  * },
1934
- * async setItem(key, value) {
1979
+ * async writeItem(key, value) {
1935
1980
  * store.set(key, value)
1936
1981
  * },
1937
1982
  * async removeItem(key) {
1938
1983
  * store.delete(key)
1939
1984
  * },
1940
- * async getKeys(base) {
1985
+ * async readKeys(base) {
1941
1986
  * const keys = [...store.keys()]
1942
1987
  * return base ? keys.filter((k) => k.startsWith(base)) : keys
1943
1988
  * },
1944
- * async clear(base) {
1989
+ * async empty(base) {
1945
1990
  * if (!base) store.clear()
1946
1991
  * },
1947
1992
  * }
@@ -1988,7 +2033,7 @@ function createLimiter(concurrency) {
1988
2033
  * - the write is skipped when the file content is already identical
1989
2034
  * - missing parent directories are created automatically
1990
2035
  * - Bun's native file API is used when running under Bun
1991
- * - concurrent `setItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
2036
+ * - concurrent `writeItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
1992
2037
  * can fire every file's write without pacing itself
1993
2038
  *
1994
2039
  * @example
@@ -2007,7 +2052,7 @@ const fsStorage = createStorage(() => {
2007
2052
  const limit = createLimiter(WRITE_CONCURRENCY);
2008
2053
  return {
2009
2054
  name: "fs",
2010
- async hasItem(key) {
2055
+ async existsItem(key) {
2011
2056
  try {
2012
2057
  await access(resolve(key));
2013
2058
  return true;
@@ -2015,20 +2060,20 @@ const fsStorage = createStorage(() => {
2015
2060
  return false;
2016
2061
  }
2017
2062
  },
2018
- async getItem(key) {
2063
+ async readItem(key) {
2019
2064
  try {
2020
2065
  return await readFile(resolve(key), "utf8");
2021
2066
  } catch (_error) {
2022
2067
  return null;
2023
2068
  }
2024
2069
  },
2025
- async setItem(key, value) {
2070
+ async writeItem(key, value) {
2026
2071
  await limit(() => write(resolve(key), value, { sanity: false }));
2027
2072
  },
2028
2073
  async removeItem(key) {
2029
2074
  await rm(resolve(key), { force: true });
2030
2075
  },
2031
- async getKeys(base) {
2076
+ async readKeys(base) {
2032
2077
  const resolvedBase = resolve(base ?? process.cwd());
2033
2078
  const keys = [];
2034
2079
  try {
@@ -2039,7 +2084,7 @@ const fsStorage = createStorage(() => {
2039
2084
  } catch (_error) {}
2040
2085
  return keys;
2041
2086
  },
2042
- async clear(base) {
2087
+ async empty(base) {
2043
2088
  if (!base) return;
2044
2089
  await clean(resolve(base));
2045
2090
  }
@@ -2113,7 +2158,7 @@ var Kubb = class {
2113
2158
  help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2114
2159
  location: { kind: "config" }
2115
2160
  });
2116
- await config.storage.clear(cleanPath);
2161
+ await config.storage.empty(cleanPath);
2117
2162
  }
2118
2163
  await driver.setup();
2119
2164
  this.#driver = driver;
@@ -2459,11 +2504,13 @@ const fileReporter = createReporter({
2459
2504
  const { diagnostics, config } = result;
2460
2505
  if (diagnostics.length === 0) return;
2461
2506
  const report = buildReport(result);
2462
- const content = stripVTControlCharacters([config.name ? `# ${config.name} — ${(/* @__PURE__ */ new Date()).toISOString()}` : `# ${(/* @__PURE__ */ new Date()).toISOString()}`, ...[
2507
+ const header = config.name ? `# ${config.name} — ${(/* @__PURE__ */ new Date()).toISOString()}` : `# ${(/* @__PURE__ */ new Date()).toISOString()}`;
2508
+ const sections = [
2463
2509
  buildSummarySection(report),
2464
2510
  buildProblemSection(diagnostics),
2465
2511
  buildTimingSection(report)
2466
- ].filter((section) => section.length > 0).map((section) => section.join("\n"))].join("\n\n"));
2512
+ ].filter((section) => section.length > 0);
2513
+ const content = stripVTControlCharacters([header, ...sections.map((section) => section.join("\n"))].join("\n\n"));
2467
2514
  const baseName = `${[
2468
2515
  "kubb",
2469
2516
  config.name,
@@ -2616,23 +2663,23 @@ const memoryStorage = createStorage(() => {
2616
2663
  const store = /* @__PURE__ */ new Map();
2617
2664
  return {
2618
2665
  name: "memory",
2619
- async hasItem(key) {
2666
+ async existsItem(key) {
2620
2667
  return store.has(key);
2621
2668
  },
2622
- async getItem(key) {
2669
+ async readItem(key) {
2623
2670
  return store.get(key) ?? null;
2624
2671
  },
2625
- async setItem(key, value) {
2672
+ async writeItem(key, value) {
2626
2673
  store.set(key, value);
2627
2674
  },
2628
2675
  async removeItem(key) {
2629
2676
  store.delete(key);
2630
2677
  },
2631
- async getKeys(base) {
2678
+ async readKeys(base) {
2632
2679
  const keys = [...store.keys()];
2633
2680
  return base ? keys.filter((k) => k.startsWith(base)) : keys;
2634
2681
  },
2635
- async clear(base) {
2682
+ async empty(base) {
2636
2683
  if (!base) {
2637
2684
  store.clear();
2638
2685
  return;