@kubb/core 5.0.0-beta.106 → 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-Dor0Mj1s.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";
@@ -150,7 +150,7 @@ function randomCliColor(text) {
150
150
  }
151
151
  //#endregion
152
152
  //#region package.json
153
- var version = "5.0.0-beta.106";
153
+ var version = "5.0.0-beta.107";
154
154
  //#endregion
155
155
  //#region src/constants.ts
156
156
  /**
@@ -184,6 +184,16 @@ const diagnosticCode = {
184
184
  */
185
185
  inputRequired: "KUBB_INPUT_REQUIRED",
186
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
+ /**
187
197
  * A `$ref` (or equivalent reference) could not be resolved in the source document.
188
198
  */
189
199
  refNotFound: "KUBB_REF_NOT_FOUND",
@@ -330,6 +340,16 @@ const diagnosticCatalog = {
330
340
  cause: "An adapter is configured but no `input` was provided.",
331
341
  fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
332
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
+ },
333
353
  [diagnosticCode.refNotFound]: {
334
354
  title: "Reference not found",
335
355
  cause: "A `$ref` could not be resolved in the source document.",
@@ -728,6 +748,23 @@ function getInputKind(input) {
728
748
  return "file";
729
749
  }
730
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
+ /**
731
768
  * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
732
769
  *
733
770
  * A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
@@ -735,6 +772,13 @@ function getInputKind(input) {
735
772
  */
736
773
  function inputToAdapterSource(config) {
737
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
+ });
738
782
  if (!input) throw new Diagnostics.Error({
739
783
  code: Diagnostics.code.inputRequired,
740
784
  severity: "error",
@@ -1926,23 +1970,23 @@ var KubbDriver = class {
1926
1970
  *
1927
1971
  * return {
1928
1972
  * name: 'memory',
1929
- * async hasItem(key) {
1973
+ * async existsItem(key) {
1930
1974
  * return store.has(key)
1931
1975
  * },
1932
- * async getItem(key) {
1976
+ * async readItem(key) {
1933
1977
  * return store.get(key) ?? null
1934
1978
  * },
1935
- * async setItem(key, value) {
1979
+ * async writeItem(key, value) {
1936
1980
  * store.set(key, value)
1937
1981
  * },
1938
1982
  * async removeItem(key) {
1939
1983
  * store.delete(key)
1940
1984
  * },
1941
- * async getKeys(base) {
1985
+ * async readKeys(base) {
1942
1986
  * const keys = [...store.keys()]
1943
1987
  * return base ? keys.filter((k) => k.startsWith(base)) : keys
1944
1988
  * },
1945
- * async clear(base) {
1989
+ * async empty(base) {
1946
1990
  * if (!base) store.clear()
1947
1991
  * },
1948
1992
  * }
@@ -1989,7 +2033,7 @@ function createLimiter(concurrency) {
1989
2033
  * - the write is skipped when the file content is already identical
1990
2034
  * - missing parent directories are created automatically
1991
2035
  * - Bun's native file API is used when running under Bun
1992
- * - 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
1993
2037
  * can fire every file's write without pacing itself
1994
2038
  *
1995
2039
  * @example
@@ -2008,7 +2052,7 @@ const fsStorage = createStorage(() => {
2008
2052
  const limit = createLimiter(WRITE_CONCURRENCY);
2009
2053
  return {
2010
2054
  name: "fs",
2011
- async hasItem(key) {
2055
+ async existsItem(key) {
2012
2056
  try {
2013
2057
  await access(resolve(key));
2014
2058
  return true;
@@ -2016,20 +2060,20 @@ const fsStorage = createStorage(() => {
2016
2060
  return false;
2017
2061
  }
2018
2062
  },
2019
- async getItem(key) {
2063
+ async readItem(key) {
2020
2064
  try {
2021
2065
  return await readFile(resolve(key), "utf8");
2022
2066
  } catch (_error) {
2023
2067
  return null;
2024
2068
  }
2025
2069
  },
2026
- async setItem(key, value) {
2070
+ async writeItem(key, value) {
2027
2071
  await limit(() => write(resolve(key), value, { sanity: false }));
2028
2072
  },
2029
2073
  async removeItem(key) {
2030
2074
  await rm(resolve(key), { force: true });
2031
2075
  },
2032
- async getKeys(base) {
2076
+ async readKeys(base) {
2033
2077
  const resolvedBase = resolve(base ?? process.cwd());
2034
2078
  const keys = [];
2035
2079
  try {
@@ -2040,7 +2084,7 @@ const fsStorage = createStorage(() => {
2040
2084
  } catch (_error) {}
2041
2085
  return keys;
2042
2086
  },
2043
- async clear(base) {
2087
+ async empty(base) {
2044
2088
  if (!base) return;
2045
2089
  await clean(resolve(base));
2046
2090
  }
@@ -2114,7 +2158,7 @@ var Kubb = class {
2114
2158
  help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2115
2159
  location: { kind: "config" }
2116
2160
  });
2117
- await config.storage.clear(cleanPath);
2161
+ await config.storage.empty(cleanPath);
2118
2162
  }
2119
2163
  await driver.setup();
2120
2164
  this.#driver = driver;
@@ -2619,23 +2663,23 @@ const memoryStorage = createStorage(() => {
2619
2663
  const store = /* @__PURE__ */ new Map();
2620
2664
  return {
2621
2665
  name: "memory",
2622
- async hasItem(key) {
2666
+ async existsItem(key) {
2623
2667
  return store.has(key);
2624
2668
  },
2625
- async getItem(key) {
2669
+ async readItem(key) {
2626
2670
  return store.get(key) ?? null;
2627
2671
  },
2628
- async setItem(key, value) {
2672
+ async writeItem(key, value) {
2629
2673
  store.set(key, value);
2630
2674
  },
2631
2675
  async removeItem(key) {
2632
2676
  store.delete(key);
2633
2677
  },
2634
- async getKeys(base) {
2678
+ async readKeys(base) {
2635
2679
  const keys = [...store.keys()];
2636
2680
  return base ? keys.filter((k) => k.startsWith(base)) : keys;
2637
2681
  },
2638
- async clear(base) {
2682
+ async empty(base) {
2639
2683
  if (!base) {
2640
2684
  store.clear();
2641
2685
  return;