@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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_usingCtx = require("./usingCtx-BojKaby2.cjs");
2
+ const require_usingCtx = require("./usingCtx-lve4tKsy.cjs");
3
3
  let node_async_hooks = require("node:async_hooks");
4
4
  let node_util = require("node:util");
5
5
  let node_crypto = require("node:crypto");
@@ -152,7 +152,7 @@ function randomCliColor(text) {
152
152
  }
153
153
  //#endregion
154
154
  //#region package.json
155
- var version = "5.0.0-beta.106";
155
+ var version = "5.0.0-beta.107";
156
156
  //#endregion
157
157
  //#region src/constants.ts
158
158
  /**
@@ -186,6 +186,16 @@ const diagnosticCode = {
186
186
  */
187
187
  inputRequired: "KUBB_INPUT_REQUIRED",
188
188
  /**
189
+ * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed
190
+ * document instead of a pointer to one.
191
+ */
192
+ legacyInput: "KUBB_LEGACY_INPUT",
193
+ /**
194
+ * The parsed `input` carries no `openapi` or `swagger` version, so it is not a
195
+ * document the adapter can read.
196
+ */
197
+ invalidDocument: "KUBB_INVALID_DOCUMENT",
198
+ /**
189
199
  * A `$ref` (or equivalent reference) could not be resolved in the source document.
190
200
  */
191
201
  refNotFound: "KUBB_REF_NOT_FOUND",
@@ -332,6 +342,16 @@ const diagnosticCatalog = {
332
342
  cause: "An adapter is configured but no `input` was provided.",
333
343
  fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
334
344
  },
345
+ [diagnosticCode.legacyInput]: {
346
+ title: "Legacy input shape",
347
+ cause: "`input` is a `{ path }` or `{ data }` wrapper, which v4 used to point at a document and v5 reads as the document itself.",
348
+ fix: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`."
349
+ },
350
+ [diagnosticCode.invalidDocument]: {
351
+ title: "Invalid document",
352
+ cause: "The parsed `input` has no `openapi` or `swagger` version field, so it is not an OpenAPI or Swagger document.",
353
+ 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."
354
+ },
335
355
  [diagnosticCode.refNotFound]: {
336
356
  title: "Reference not found",
337
357
  cause: "A `$ref` could not be resolved in the source document.",
@@ -730,6 +750,23 @@ function getInputKind(input) {
730
750
  return "file";
731
751
  }
732
752
  /**
753
+ * The v4 `input` wrapper keys. v4 typed `input` as `{ path }` or `{ data }`; v5 takes the value
754
+ * directly, so the wrapper now matches the "already-parsed document" branch and silently yields
755
+ * an empty build.
756
+ */
757
+ const legacyInputKeys = ["path", "data"];
758
+ /**
759
+ * Detects the v4 `{ path }` / `{ data }` wrapper so it fails loudly instead of being read as a
760
+ * document. A real spec always carries more than these keys, so an object whose keys are drawn
761
+ * only from them is the old shape rather than a document that happens to have a `path` property.
762
+ */
763
+ function isLegacyInput(input) {
764
+ if (Array.isArray(input)) return input.some(isLegacyInput);
765
+ if (typeof input !== "object" || input === null) return false;
766
+ const keys = Object.keys(input);
767
+ return keys.length > 0 && keys.every((key) => legacyInputKeys.includes(key));
768
+ }
769
+ /**
733
770
  * Normalizes `config.input` into an `AdapterSource` the adapter can parse.
734
771
  *
735
772
  * A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
@@ -737,6 +774,13 @@ function getInputKind(input) {
737
774
  */
738
775
  function inputToAdapterSource(config) {
739
776
  const input = config.input;
777
+ if (input && isLegacyInput(input)) throw new Diagnostics.Error({
778
+ code: Diagnostics.code.legacyInput,
779
+ severity: "error",
780
+ message: "The `input` option uses the v4 `{ path }` / `{ data }` wrapper.",
781
+ help: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`.",
782
+ location: { kind: "config" }
783
+ });
740
784
  if (!input) throw new Diagnostics.Error({
741
785
  code: Diagnostics.code.inputRequired,
742
786
  severity: "error",
@@ -1928,23 +1972,23 @@ var KubbDriver = class {
1928
1972
  *
1929
1973
  * return {
1930
1974
  * name: 'memory',
1931
- * async hasItem(key) {
1975
+ * async existsItem(key) {
1932
1976
  * return store.has(key)
1933
1977
  * },
1934
- * async getItem(key) {
1978
+ * async readItem(key) {
1935
1979
  * return store.get(key) ?? null
1936
1980
  * },
1937
- * async setItem(key, value) {
1981
+ * async writeItem(key, value) {
1938
1982
  * store.set(key, value)
1939
1983
  * },
1940
1984
  * async removeItem(key) {
1941
1985
  * store.delete(key)
1942
1986
  * },
1943
- * async getKeys(base) {
1987
+ * async readKeys(base) {
1944
1988
  * const keys = [...store.keys()]
1945
1989
  * return base ? keys.filter((k) => k.startsWith(base)) : keys
1946
1990
  * },
1947
- * async clear(base) {
1991
+ * async empty(base) {
1948
1992
  * if (!base) store.clear()
1949
1993
  * },
1950
1994
  * }
@@ -1991,7 +2035,7 @@ function createLimiter(concurrency) {
1991
2035
  * - the write is skipped when the file content is already identical
1992
2036
  * - missing parent directories are created automatically
1993
2037
  * - Bun's native file API is used when running under Bun
1994
- * - concurrent `setItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
2038
+ * - concurrent `writeItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
1995
2039
  * can fire every file's write without pacing itself
1996
2040
  *
1997
2041
  * @example
@@ -2010,7 +2054,7 @@ const fsStorage = createStorage(() => {
2010
2054
  const limit = createLimiter(WRITE_CONCURRENCY);
2011
2055
  return {
2012
2056
  name: "fs",
2013
- async hasItem(key) {
2057
+ async existsItem(key) {
2014
2058
  try {
2015
2059
  await (0, node_fs_promises.access)((0, node_path.resolve)(key));
2016
2060
  return true;
@@ -2018,20 +2062,20 @@ const fsStorage = createStorage(() => {
2018
2062
  return false;
2019
2063
  }
2020
2064
  },
2021
- async getItem(key) {
2065
+ async readItem(key) {
2022
2066
  try {
2023
2067
  return await (0, node_fs_promises.readFile)((0, node_path.resolve)(key), "utf8");
2024
2068
  } catch (_error) {
2025
2069
  return null;
2026
2070
  }
2027
2071
  },
2028
- async setItem(key, value) {
2072
+ async writeItem(key, value) {
2029
2073
  await limit(() => require_usingCtx.write((0, node_path.resolve)(key), value, { sanity: false }));
2030
2074
  },
2031
2075
  async removeItem(key) {
2032
2076
  await (0, node_fs_promises.rm)((0, node_path.resolve)(key), { force: true });
2033
2077
  },
2034
- async getKeys(base) {
2078
+ async readKeys(base) {
2035
2079
  const resolvedBase = (0, node_path.resolve)(base ?? process.cwd());
2036
2080
  const keys = [];
2037
2081
  try {
@@ -2042,7 +2086,7 @@ const fsStorage = createStorage(() => {
2042
2086
  } catch (_error) {}
2043
2087
  return keys;
2044
2088
  },
2045
- async clear(base) {
2089
+ async empty(base) {
2046
2090
  if (!base) return;
2047
2091
  await require_usingCtx.clean((0, node_path.resolve)(base));
2048
2092
  }
@@ -2116,7 +2160,7 @@ var Kubb = class {
2116
2160
  help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
2117
2161
  location: { kind: "config" }
2118
2162
  });
2119
- await config.storage.clear(cleanPath);
2163
+ await config.storage.empty(cleanPath);
2120
2164
  }
2121
2165
  await driver.setup();
2122
2166
  this.#driver = driver;
@@ -2621,23 +2665,23 @@ const memoryStorage = createStorage(() => {
2621
2665
  const store = /* @__PURE__ */ new Map();
2622
2666
  return {
2623
2667
  name: "memory",
2624
- async hasItem(key) {
2668
+ async existsItem(key) {
2625
2669
  return store.has(key);
2626
2670
  },
2627
- async getItem(key) {
2671
+ async readItem(key) {
2628
2672
  return store.get(key) ?? null;
2629
2673
  },
2630
- async setItem(key, value) {
2674
+ async writeItem(key, value) {
2631
2675
  store.set(key, value);
2632
2676
  },
2633
2677
  async removeItem(key) {
2634
2678
  store.delete(key);
2635
2679
  },
2636
- async getKeys(base) {
2680
+ async readKeys(base) {
2637
2681
  const keys = [...store.keys()];
2638
2682
  return base ? keys.filter((k) => k.startsWith(base)) : keys;
2639
2683
  },
2640
- async clear(base) {
2684
+ async empty(base) {
2641
2685
  if (!base) {
2642
2686
  store.clear();
2643
2687
  return;