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