@kubb/core 5.0.0-beta.106 → 5.0.0-beta.108

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-C_JCC5Dl.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.108";
154
154
  //#endregion
155
155
  //#region src/constants.ts
156
156
  /**
@@ -180,10 +180,30 @@ const diagnosticCode = {
180
180
  */
181
181
  inputNotFound: "KUBB_INPUT_NOT_FOUND",
182
182
  /**
183
+ * A URL set as `input` (or referenced by a `$ref`) answered with a 4xx or 5xx status
184
+ * instead of the document.
185
+ */
186
+ inputRequestFailed: "KUBB_INPUT_REQUEST_FAILED",
187
+ /**
188
+ * A URL set as `input` (or referenced by a `$ref`) never answered, so the request failed
189
+ * before a status was returned.
190
+ */
191
+ inputUnreachable: "KUBB_INPUT_UNREACHABLE",
192
+ /**
183
193
  * An adapter was configured without an `input`.
184
194
  */
185
195
  inputRequired: "KUBB_INPUT_REQUIRED",
186
196
  /**
197
+ * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed
198
+ * document instead of a pointer to one.
199
+ */
200
+ legacyInput: "KUBB_LEGACY_INPUT",
201
+ /**
202
+ * The parsed `input` carries no `openapi` or `swagger` version, so it is not a
203
+ * document the adapter can read.
204
+ */
205
+ invalidDocument: "KUBB_INVALID_DOCUMENT",
206
+ /**
187
207
  * A `$ref` (or equivalent reference) could not be resolved in the source document.
188
208
  */
189
209
  refNotFound: "KUBB_REF_NOT_FOUND",
@@ -322,14 +342,34 @@ const diagnosticCatalog = {
322
342
  },
323
343
  [diagnosticCode.inputNotFound]: {
324
344
  title: "Input not found",
325
- cause: "The file or URL set as `input` (or passed as `kubb generate PATH`) could not be read.",
326
- fix: "Check that the path or URL exists and is readable, then set it as `input` or pass it on the CLI."
345
+ cause: "The file set as `input` (or passed as `kubb generate PATH`) could not be read. A URL reports `KUBB_INPUT_REQUEST_FAILED` or `KUBB_INPUT_UNREACHABLE` instead.",
346
+ fix: "Check that the path exists and is readable, then set it as `input` or pass it on the CLI."
347
+ },
348
+ [diagnosticCode.inputRequestFailed]: {
349
+ title: "Input request failed",
350
+ cause: "A URL set as `input` (or reached through a `$ref`) answered with a 4xx or 5xx status instead of the document.",
351
+ fix: "Open the URL to see what the server returns. A 401 or 403 needs credentials Kubb does not send, so download the document and point `input` at the local file. A 404 means the path is wrong, and a 5xx means the server itself failed."
352
+ },
353
+ [diagnosticCode.inputUnreachable]: {
354
+ title: "Input unreachable",
355
+ cause: "A URL set as `input` (or reached through a `$ref`) never answered, so the request failed before a status came back. A refused connection, an unknown host, an expired certificate, and a timeout all land here.",
356
+ fix: "Check that the host is running and reachable from this machine. For a local server, start it and confirm the port matches the one in `input`."
327
357
  },
328
358
  [diagnosticCode.inputRequired]: {
329
359
  title: "Input required",
330
360
  cause: "An adapter is configured but no `input` was provided.",
331
361
  fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
332
362
  },
363
+ [diagnosticCode.legacyInput]: {
364
+ title: "Legacy input shape",
365
+ cause: "`input` is a `{ path }` or `{ data }` wrapper, which v4 used to point at a document and v5 reads as the document itself.",
366
+ fix: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`."
367
+ },
368
+ [diagnosticCode.invalidDocument]: {
369
+ title: "Invalid document",
370
+ cause: "The parsed `input` has no `openapi` or `swagger` version field, so it is not an OpenAPI or Swagger document.",
371
+ 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."
372
+ },
333
373
  [diagnosticCode.refNotFound]: {
334
374
  title: "Reference not found",
335
375
  cause: "A `$ref` could not be resolved in the source document.",
@@ -728,6 +768,23 @@ function getInputKind(input) {
728
768
  return "file";
729
769
  }
730
770
  /**
771
+ * The v4 `input` wrapper keys. v4 typed `input` as `{ path }` or `{ data }`; v5 takes the value
772
+ * directly, so the wrapper now matches the "already-parsed document" branch and silently yields
773
+ * an empty build.
774
+ */
775
+ const legacyInputKeys = ["path", "data"];
776
+ /**
777
+ * Detects the v4 `{ path }` / `{ data }` wrapper so it fails loudly instead of being read as a
778
+ * document. A real spec always carries more than these keys, so an object whose keys are drawn
779
+ * only from them is the old shape rather than a document that happens to have a `path` property.
780
+ */
781
+ function isLegacyInput(input) {
782
+ if (Array.isArray(input)) return input.some(isLegacyInput);
783
+ if (typeof input !== "object" || input === null) return false;
784
+ const keys = Object.keys(input);
785
+ return keys.length > 0 && keys.every((key) => legacyInputKeys.includes(key));
786
+ }
787
+ /**
731
788
  * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
732
789
  *
733
790
  * A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
@@ -735,6 +792,13 @@ function getInputKind(input) {
735
792
  */
736
793
  function inputToAdapterSource(config) {
737
794
  const input = config.input;
795
+ if (input && isLegacyInput(input)) throw new Diagnostics.Error({
796
+ code: Diagnostics.code.legacyInput,
797
+ severity: "error",
798
+ message: "The `input` option uses the v4 `{ path }` / `{ data }` wrapper.",
799
+ help: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`.",
800
+ location: { kind: "config" }
801
+ });
738
802
  if (!input) throw new Diagnostics.Error({
739
803
  code: Diagnostics.code.inputRequired,
740
804
  severity: "error",
@@ -1926,23 +1990,23 @@ var KubbDriver = class {
1926
1990
  *
1927
1991
  * return {
1928
1992
  * name: 'memory',
1929
- * async hasItem(key) {
1993
+ * async existsItem(key) {
1930
1994
  * return store.has(key)
1931
1995
  * },
1932
- * async getItem(key) {
1996
+ * async readItem(key) {
1933
1997
  * return store.get(key) ?? null
1934
1998
  * },
1935
- * async setItem(key, value) {
1999
+ * async writeItem(key, value) {
1936
2000
  * store.set(key, value)
1937
2001
  * },
1938
2002
  * async removeItem(key) {
1939
2003
  * store.delete(key)
1940
2004
  * },
1941
- * async getKeys(base) {
2005
+ * async readKeys(base) {
1942
2006
  * const keys = [...store.keys()]
1943
2007
  * return base ? keys.filter((k) => k.startsWith(base)) : keys
1944
2008
  * },
1945
- * async clear(base) {
2009
+ * async empty(base) {
1946
2010
  * if (!base) store.clear()
1947
2011
  * },
1948
2012
  * }
@@ -1989,7 +2053,7 @@ function createLimiter(concurrency) {
1989
2053
  * - the write is skipped when the file content is already identical
1990
2054
  * - missing parent directories are created automatically
1991
2055
  * - 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
2056
+ * - concurrent `writeItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
1993
2057
  * can fire every file's write without pacing itself
1994
2058
  *
1995
2059
  * @example
@@ -2008,7 +2072,7 @@ const fsStorage = createStorage(() => {
2008
2072
  const limit = createLimiter(WRITE_CONCURRENCY);
2009
2073
  return {
2010
2074
  name: "fs",
2011
- async hasItem(key) {
2075
+ async existsItem(key) {
2012
2076
  try {
2013
2077
  await access(resolve(key));
2014
2078
  return true;
@@ -2016,20 +2080,20 @@ const fsStorage = createStorage(() => {
2016
2080
  return false;
2017
2081
  }
2018
2082
  },
2019
- async getItem(key) {
2083
+ async readItem(key) {
2020
2084
  try {
2021
2085
  return await readFile(resolve(key), "utf8");
2022
2086
  } catch (_error) {
2023
2087
  return null;
2024
2088
  }
2025
2089
  },
2026
- async setItem(key, value) {
2090
+ async writeItem(key, value) {
2027
2091
  await limit(() => write(resolve(key), value, { sanity: false }));
2028
2092
  },
2029
2093
  async removeItem(key) {
2030
2094
  await rm(resolve(key), { force: true });
2031
2095
  },
2032
- async getKeys(base) {
2096
+ async readKeys(base) {
2033
2097
  const resolvedBase = resolve(base ?? process.cwd());
2034
2098
  const keys = [];
2035
2099
  try {
@@ -2040,7 +2104,7 @@ const fsStorage = createStorage(() => {
2040
2104
  } catch (_error) {}
2041
2105
  return keys;
2042
2106
  },
2043
- async clear(base) {
2107
+ async empty(base) {
2044
2108
  if (!base) return;
2045
2109
  await clean(resolve(base));
2046
2110
  }
@@ -2114,7 +2178,7 @@ var Kubb = class {
2114
2178
  help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2115
2179
  location: { kind: "config" }
2116
2180
  });
2117
- await config.storage.clear(cleanPath);
2181
+ await config.storage.empty(cleanPath);
2118
2182
  }
2119
2183
  await driver.setup();
2120
2184
  this.#driver = driver;
@@ -2619,23 +2683,23 @@ const memoryStorage = createStorage(() => {
2619
2683
  const store = /* @__PURE__ */ new Map();
2620
2684
  return {
2621
2685
  name: "memory",
2622
- async hasItem(key) {
2686
+ async existsItem(key) {
2623
2687
  return store.has(key);
2624
2688
  },
2625
- async getItem(key) {
2689
+ async readItem(key) {
2626
2690
  return store.get(key) ?? null;
2627
2691
  },
2628
- async setItem(key, value) {
2692
+ async writeItem(key, value) {
2629
2693
  store.set(key, value);
2630
2694
  },
2631
2695
  async removeItem(key) {
2632
2696
  store.delete(key);
2633
2697
  },
2634
- async getKeys(base) {
2698
+ async readKeys(base) {
2635
2699
  const keys = [...store.keys()];
2636
2700
  return base ? keys.filter((k) => k.startsWith(base)) : keys;
2637
2701
  },
2638
- async clear(base) {
2702
+ async empty(base) {
2639
2703
  if (!base) {
2640
2704
  store.clear();
2641
2705
  return;