@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.cjs +69 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +69 -22
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{types-D116CBzm.d.ts → types-Dtisidv5.d.ts} +35 -20
- package/dist/{usingCtx-C24YU3KM.js → usingCtx-D9_Ee6kn.js} +6 -6
- package/dist/{usingCtx-C24YU3KM.js.map → usingCtx-D9_Ee6kn.js.map} +1 -1
- package/dist/{usingCtx-BYOZEkiy.cjs → usingCtx-lve4tKsy.cjs} +7 -7
- package/dist/usingCtx-lve4tKsy.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/usingCtx-BYOZEkiy.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_usingCtx = require("./usingCtx-
|
|
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");
|
|
@@ -147,11 +147,12 @@ const randomColors = [
|
|
|
147
147
|
function randomCliColor(text) {
|
|
148
148
|
if (!text) return "";
|
|
149
149
|
const index = (0, node_crypto.hash)("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
|
|
150
|
-
|
|
150
|
+
const color = randomColors[index] ?? "white";
|
|
151
|
+
return (0, node_util.styleText)(color, text);
|
|
151
152
|
}
|
|
152
153
|
//#endregion
|
|
153
154
|
//#region package.json
|
|
154
|
-
var version = "5.0.0-beta.
|
|
155
|
+
var version = "5.0.0-beta.107";
|
|
155
156
|
//#endregion
|
|
156
157
|
//#region src/constants.ts
|
|
157
158
|
/**
|
|
@@ -185,6 +186,16 @@ const diagnosticCode = {
|
|
|
185
186
|
*/
|
|
186
187
|
inputRequired: "KUBB_INPUT_REQUIRED",
|
|
187
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
|
+
/**
|
|
188
199
|
* A `$ref` (or equivalent reference) could not be resolved in the source document.
|
|
189
200
|
*/
|
|
190
201
|
refNotFound: "KUBB_REF_NOT_FOUND",
|
|
@@ -331,6 +342,16 @@ const diagnosticCatalog = {
|
|
|
331
342
|
cause: "An adapter is configured but no `input` was provided.",
|
|
332
343
|
fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
|
|
333
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
|
+
},
|
|
334
355
|
[diagnosticCode.refNotFound]: {
|
|
335
356
|
title: "Reference not found",
|
|
336
357
|
cause: "A `$ref` could not be resolved in the source document.",
|
|
@@ -729,6 +750,23 @@ function getInputKind(input) {
|
|
|
729
750
|
return "file";
|
|
730
751
|
}
|
|
731
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
|
+
/**
|
|
732
770
|
* Normalizes `config.input` into an `AdapterSource` the adapter can parse.
|
|
733
771
|
*
|
|
734
772
|
* A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
|
|
@@ -736,6 +774,13 @@ function getInputKind(input) {
|
|
|
736
774
|
*/
|
|
737
775
|
function inputToAdapterSource(config) {
|
|
738
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
|
+
});
|
|
739
784
|
if (!input) throw new Diagnostics.Error({
|
|
740
785
|
code: Diagnostics.code.inputRequired,
|
|
741
786
|
severity: "error",
|
|
@@ -1927,23 +1972,23 @@ var KubbDriver = class {
|
|
|
1927
1972
|
*
|
|
1928
1973
|
* return {
|
|
1929
1974
|
* name: 'memory',
|
|
1930
|
-
* async
|
|
1975
|
+
* async existsItem(key) {
|
|
1931
1976
|
* return store.has(key)
|
|
1932
1977
|
* },
|
|
1933
|
-
* async
|
|
1978
|
+
* async readItem(key) {
|
|
1934
1979
|
* return store.get(key) ?? null
|
|
1935
1980
|
* },
|
|
1936
|
-
* async
|
|
1981
|
+
* async writeItem(key, value) {
|
|
1937
1982
|
* store.set(key, value)
|
|
1938
1983
|
* },
|
|
1939
1984
|
* async removeItem(key) {
|
|
1940
1985
|
* store.delete(key)
|
|
1941
1986
|
* },
|
|
1942
|
-
* async
|
|
1987
|
+
* async readKeys(base) {
|
|
1943
1988
|
* const keys = [...store.keys()]
|
|
1944
1989
|
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
1945
1990
|
* },
|
|
1946
|
-
* async
|
|
1991
|
+
* async empty(base) {
|
|
1947
1992
|
* if (!base) store.clear()
|
|
1948
1993
|
* },
|
|
1949
1994
|
* }
|
|
@@ -1990,7 +2035,7 @@ function createLimiter(concurrency) {
|
|
|
1990
2035
|
* - the write is skipped when the file content is already identical
|
|
1991
2036
|
* - missing parent directories are created automatically
|
|
1992
2037
|
* - Bun's native file API is used when running under Bun
|
|
1993
|
-
* - concurrent `
|
|
2038
|
+
* - concurrent `writeItem` calls are capped at {@link WRITE_CONCURRENCY} in flight, so a caller
|
|
1994
2039
|
* can fire every file's write without pacing itself
|
|
1995
2040
|
*
|
|
1996
2041
|
* @example
|
|
@@ -2009,7 +2054,7 @@ const fsStorage = createStorage(() => {
|
|
|
2009
2054
|
const limit = createLimiter(WRITE_CONCURRENCY);
|
|
2010
2055
|
return {
|
|
2011
2056
|
name: "fs",
|
|
2012
|
-
async
|
|
2057
|
+
async existsItem(key) {
|
|
2013
2058
|
try {
|
|
2014
2059
|
await (0, node_fs_promises.access)((0, node_path.resolve)(key));
|
|
2015
2060
|
return true;
|
|
@@ -2017,20 +2062,20 @@ const fsStorage = createStorage(() => {
|
|
|
2017
2062
|
return false;
|
|
2018
2063
|
}
|
|
2019
2064
|
},
|
|
2020
|
-
async
|
|
2065
|
+
async readItem(key) {
|
|
2021
2066
|
try {
|
|
2022
2067
|
return await (0, node_fs_promises.readFile)((0, node_path.resolve)(key), "utf8");
|
|
2023
2068
|
} catch (_error) {
|
|
2024
2069
|
return null;
|
|
2025
2070
|
}
|
|
2026
2071
|
},
|
|
2027
|
-
async
|
|
2072
|
+
async writeItem(key, value) {
|
|
2028
2073
|
await limit(() => require_usingCtx.write((0, node_path.resolve)(key), value, { sanity: false }));
|
|
2029
2074
|
},
|
|
2030
2075
|
async removeItem(key) {
|
|
2031
2076
|
await (0, node_fs_promises.rm)((0, node_path.resolve)(key), { force: true });
|
|
2032
2077
|
},
|
|
2033
|
-
async
|
|
2078
|
+
async readKeys(base) {
|
|
2034
2079
|
const resolvedBase = (0, node_path.resolve)(base ?? process.cwd());
|
|
2035
2080
|
const keys = [];
|
|
2036
2081
|
try {
|
|
@@ -2041,7 +2086,7 @@ const fsStorage = createStorage(() => {
|
|
|
2041
2086
|
} catch (_error) {}
|
|
2042
2087
|
return keys;
|
|
2043
2088
|
},
|
|
2044
|
-
async
|
|
2089
|
+
async empty(base) {
|
|
2045
2090
|
if (!base) return;
|
|
2046
2091
|
await require_usingCtx.clean((0, node_path.resolve)(base));
|
|
2047
2092
|
}
|
|
@@ -2115,7 +2160,7 @@ var Kubb = class {
|
|
|
2115
2160
|
help: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code.",
|
|
2116
2161
|
location: { kind: "config" }
|
|
2117
2162
|
});
|
|
2118
|
-
await config.storage.
|
|
2163
|
+
await config.storage.empty(cleanPath);
|
|
2119
2164
|
}
|
|
2120
2165
|
await driver.setup();
|
|
2121
2166
|
this.#driver = driver;
|
|
@@ -2461,11 +2506,13 @@ const fileReporter = createReporter({
|
|
|
2461
2506
|
const { diagnostics, config } = result;
|
|
2462
2507
|
if (diagnostics.length === 0) return;
|
|
2463
2508
|
const report = buildReport(result);
|
|
2464
|
-
const
|
|
2509
|
+
const header = config.name ? `# ${config.name} — ${(/* @__PURE__ */ new Date()).toISOString()}` : `# ${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
2510
|
+
const sections = [
|
|
2465
2511
|
buildSummarySection(report),
|
|
2466
2512
|
buildProblemSection(diagnostics),
|
|
2467
2513
|
buildTimingSection(report)
|
|
2468
|
-
].filter((section) => section.length > 0)
|
|
2514
|
+
].filter((section) => section.length > 0);
|
|
2515
|
+
const content = (0, node_util.stripVTControlCharacters)([header, ...sections.map((section) => section.join("\n"))].join("\n\n"));
|
|
2469
2516
|
const baseName = `${[
|
|
2470
2517
|
"kubb",
|
|
2471
2518
|
config.name,
|
|
@@ -2618,23 +2665,23 @@ const memoryStorage = createStorage(() => {
|
|
|
2618
2665
|
const store = /* @__PURE__ */ new Map();
|
|
2619
2666
|
return {
|
|
2620
2667
|
name: "memory",
|
|
2621
|
-
async
|
|
2668
|
+
async existsItem(key) {
|
|
2622
2669
|
return store.has(key);
|
|
2623
2670
|
},
|
|
2624
|
-
async
|
|
2671
|
+
async readItem(key) {
|
|
2625
2672
|
return store.get(key) ?? null;
|
|
2626
2673
|
},
|
|
2627
|
-
async
|
|
2674
|
+
async writeItem(key, value) {
|
|
2628
2675
|
store.set(key, value);
|
|
2629
2676
|
},
|
|
2630
2677
|
async removeItem(key) {
|
|
2631
2678
|
store.delete(key);
|
|
2632
2679
|
},
|
|
2633
|
-
async
|
|
2680
|
+
async readKeys(base) {
|
|
2634
2681
|
const keys = [...store.keys()];
|
|
2635
2682
|
return base ? keys.filter((k) => k.startsWith(base)) : keys;
|
|
2636
2683
|
},
|
|
2637
|
-
async
|
|
2684
|
+
async empty(base) {
|
|
2638
2685
|
if (!base) {
|
|
2639
2686
|
store.clear();
|
|
2640
2687
|
return;
|