@kubb/core 5.0.0-beta.89 → 5.0.0-beta.91
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 +98 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +52 -4
- package/dist/index.js +97 -48
- 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/{Diagnostics-CM0-Ae30.d.ts → types-aNebW3Ui.d.ts} +692 -731
- package/dist/{usingCtx-Cnrm3TcM.js → usingCtx-BriKju-v.js} +5 -9
- package/dist/{usingCtx-Cnrm3TcM.js.map → usingCtx-BriKju-v.js.map} +1 -1
- package/dist/{usingCtx-BN2OKJRx.cjs → usingCtx-eyNeehd2.cjs} +5 -9
- package/dist/{usingCtx-BN2OKJRx.cjs.map → usingCtx-eyNeehd2.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-eyNeehd2.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");
|
|
@@ -44,6 +44,26 @@ function createAdapter(build) {
|
|
|
44
44
|
return (options) => build(options ?? {});
|
|
45
45
|
}
|
|
46
46
|
//#endregion
|
|
47
|
+
//#region src/applyConfigDefaults.ts
|
|
48
|
+
/**
|
|
49
|
+
* Fills in the config defaults shared by `defineConfig` and the unplugin factory: the fallback
|
|
50
|
+
* adapter, `defaultOutput`'s fields, and appending the barrel plugin when it's not already
|
|
51
|
+
* registered. Both entry points construct their own adapter, barrel plugin, and output defaults
|
|
52
|
+
* (`barrel` is a `@kubb/plugin-barrel` extension field core doesn't know about) and pass them in,
|
|
53
|
+
* so `@kubb/core` doesn't need to depend on `@kubb/adapter-oas` or `@kubb/plugin-barrel`.
|
|
54
|
+
*/
|
|
55
|
+
function applyConfigDefaults(config, { defaultAdapter, barrelPlugin, barrelPluginName, defaultOutput }) {
|
|
56
|
+
const plugins = config.plugins?.some((plugin) => plugin.name === barrelPluginName) ? config.plugins ?? [] : [...config.plugins ?? [], barrelPlugin];
|
|
57
|
+
return {
|
|
58
|
+
adapter: config.adapter ?? defaultAdapter,
|
|
59
|
+
plugins,
|
|
60
|
+
output: {
|
|
61
|
+
...defaultOutput,
|
|
62
|
+
...config.output
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
47
67
|
//#region ../../internals/utils/src/time.ts
|
|
48
68
|
/**
|
|
49
69
|
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
@@ -172,7 +192,7 @@ function memoize(store, factory) {
|
|
|
172
192
|
}
|
|
173
193
|
//#endregion
|
|
174
194
|
//#region package.json
|
|
175
|
-
var version = "5.0.0-beta.
|
|
195
|
+
var version = "5.0.0-beta.91";
|
|
176
196
|
//#endregion
|
|
177
197
|
//#region src/constants.ts
|
|
178
198
|
/**
|
|
@@ -198,7 +218,7 @@ const diagnosticCode = {
|
|
|
198
218
|
*/
|
|
199
219
|
unknown: "KUBB_UNKNOWN",
|
|
200
220
|
/**
|
|
201
|
-
* The
|
|
221
|
+
* The file or URL set as `input` could not be read.
|
|
202
222
|
*/
|
|
203
223
|
inputNotFound: "KUBB_INPUT_NOT_FOUND",
|
|
204
224
|
/**
|
|
@@ -353,13 +373,13 @@ const diagnosticCatalog = {
|
|
|
353
373
|
},
|
|
354
374
|
[diagnosticCode.inputNotFound]: {
|
|
355
375
|
title: "Input not found",
|
|
356
|
-
cause: "The file or URL set
|
|
357
|
-
fix: "Check that the path or URL exists and is readable, then set it
|
|
376
|
+
cause: "The file or URL set as `input` (or passed as `kubb generate PATH`) could not be read.",
|
|
377
|
+
fix: "Check that the path or URL exists and is readable, then set it as `input` or pass it on the CLI."
|
|
358
378
|
},
|
|
359
379
|
[diagnosticCode.inputRequired]: {
|
|
360
380
|
title: "Input required",
|
|
361
381
|
cause: "An adapter is configured but no `input` was provided.",
|
|
362
|
-
fix: "Set `input
|
|
382
|
+
fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
|
|
363
383
|
},
|
|
364
384
|
[diagnosticCode.refNotFound]: {
|
|
365
385
|
title: "Reference not found",
|
|
@@ -742,6 +762,55 @@ function definePlugin(factory) {
|
|
|
742
762
|
return (options) => factory(options ?? {});
|
|
743
763
|
}
|
|
744
764
|
//#endregion
|
|
765
|
+
//#region src/input.ts
|
|
766
|
+
/**
|
|
767
|
+
* Classifies an `input` value so callers branch on it once instead of repeating the checks.
|
|
768
|
+
*
|
|
769
|
+
* A non-string is a parsed spec (`object`). A string is `inline` when it holds OpenAPI content,
|
|
770
|
+
* meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
|
|
771
|
+
* `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
|
|
772
|
+
*/
|
|
773
|
+
function getInputKind(input) {
|
|
774
|
+
if (typeof input !== "string") return "object";
|
|
775
|
+
const trimmed = input.trimStart();
|
|
776
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[") || input.includes("\n") || /^(openapi|swagger)\s*:/i.test(trimmed)) return "inline";
|
|
777
|
+
if (URL.canParse(input)) return "url";
|
|
778
|
+
return "file";
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Normalizes `config.input` into an `AdapterSource` the adapter can parse.
|
|
782
|
+
*
|
|
783
|
+
* A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
|
|
784
|
+
* local path is resolved against `config.root`, both as `{ type: 'path' }`.
|
|
785
|
+
*/
|
|
786
|
+
function inputToAdapterSource(config) {
|
|
787
|
+
const input = config.input;
|
|
788
|
+
if (!input) throw new Diagnostics.Error({
|
|
789
|
+
code: Diagnostics.code.inputRequired,
|
|
790
|
+
severity: "error",
|
|
791
|
+
message: "An adapter is configured without an input.",
|
|
792
|
+
help: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config.",
|
|
793
|
+
location: { kind: "config" }
|
|
794
|
+
});
|
|
795
|
+
if (typeof input !== "string") return {
|
|
796
|
+
type: "data",
|
|
797
|
+
data: input
|
|
798
|
+
};
|
|
799
|
+
const kind = getInputKind(input);
|
|
800
|
+
if (kind === "inline") return {
|
|
801
|
+
type: "data",
|
|
802
|
+
data: input
|
|
803
|
+
};
|
|
804
|
+
if (kind === "url") return {
|
|
805
|
+
type: "path",
|
|
806
|
+
path: input
|
|
807
|
+
};
|
|
808
|
+
return {
|
|
809
|
+
type: "path",
|
|
810
|
+
path: (0, node_path.resolve)(config.root, input)
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
//#endregion
|
|
745
814
|
//#region src/Resolver.ts
|
|
746
815
|
function isNamespace(value) {
|
|
747
816
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1030,8 +1099,10 @@ var Resolver = class Resolver {
|
|
|
1030
1099
|
"* Do not edit manually."
|
|
1031
1100
|
];
|
|
1032
1101
|
if (config.output.defaultBanner !== "simple") {
|
|
1033
|
-
const input =
|
|
1034
|
-
|
|
1102
|
+
const input = config.input;
|
|
1103
|
+
let source = "";
|
|
1104
|
+
if (typeof input === "string") source = getInputKind(input) === "inline" ? "text content" : node_path.default.basename(input);
|
|
1105
|
+
else if (input) source = "text content";
|
|
1035
1106
|
if (source) lines.push(`* Source: ${source}`);
|
|
1036
1107
|
if (title) lines.push(`* Title: ${title}`);
|
|
1037
1108
|
if (version) lines.push(`* OpenAPI spec version: ${version}`);
|
|
@@ -1320,14 +1391,12 @@ var KubbDriver = class {
|
|
|
1320
1391
|
* plugins can configure generators, resolvers, macros, and options before `buildStart`.
|
|
1321
1392
|
*/
|
|
1322
1393
|
async setupHooks() {
|
|
1323
|
-
const noop = () => {};
|
|
1324
1394
|
for (const plugin of this.plugins.values()) {
|
|
1325
1395
|
const setup = plugin.hooks?.["kubb:plugin:setup"];
|
|
1326
1396
|
if (!setup) continue;
|
|
1327
1397
|
await setup({
|
|
1328
1398
|
config: this.config,
|
|
1329
1399
|
options: plugin.options ?? {},
|
|
1330
|
-
updateConfig: noop,
|
|
1331
1400
|
addGenerator: (...generators) => {
|
|
1332
1401
|
for (const generator of generators) this.registerGenerator(plugin.name, generator);
|
|
1333
1402
|
},
|
|
@@ -1491,8 +1560,7 @@ var KubbDriver = class {
|
|
|
1491
1560
|
await hooks.callHook("kubb:plugins:end", Object.assign({ config }, this.#filesPayload()));
|
|
1492
1561
|
await fileManager.write(fileManager.files, {
|
|
1493
1562
|
storage: config.storage,
|
|
1494
|
-
parsers: parsersMap
|
|
1495
|
-
extension: config.output.extension
|
|
1563
|
+
parsers: parsersMap
|
|
1496
1564
|
});
|
|
1497
1565
|
await hooks.callHook("kubb:build:end", {
|
|
1498
1566
|
files: this.fileManager.files,
|
|
@@ -1810,28 +1878,6 @@ var KubbDriver = class {
|
|
|
1810
1878
|
});
|
|
1811
1879
|
}
|
|
1812
1880
|
};
|
|
1813
|
-
function inputToAdapterSource(config) {
|
|
1814
|
-
const input = config.input;
|
|
1815
|
-
if (!input) throw new Diagnostics.Error({
|
|
1816
|
-
code: Diagnostics.code.inputRequired,
|
|
1817
|
-
severity: "error",
|
|
1818
|
-
message: "An adapter is configured without an input.",
|
|
1819
|
-
help: "Provide `input.path` (a file or URL) or `input.data` (an inline spec) in your Kubb config.",
|
|
1820
|
-
location: { kind: "config" }
|
|
1821
|
-
});
|
|
1822
|
-
if ("data" in input) return {
|
|
1823
|
-
type: "data",
|
|
1824
|
-
data: input.data
|
|
1825
|
-
};
|
|
1826
|
-
if (URL.canParse(input.path)) return {
|
|
1827
|
-
type: "path",
|
|
1828
|
-
path: input.path
|
|
1829
|
-
};
|
|
1830
|
-
return {
|
|
1831
|
-
type: "path",
|
|
1832
|
-
path: (0, node_path.resolve)(config.root, input.path)
|
|
1833
|
-
};
|
|
1834
|
-
}
|
|
1835
1881
|
//#endregion
|
|
1836
1882
|
//#region src/createStorage.ts
|
|
1837
1883
|
/**
|
|
@@ -1921,7 +1967,7 @@ function createLimiter(concurrency) {
|
|
|
1921
1967
|
* import { defineConfig } from 'kubb'
|
|
1922
1968
|
*
|
|
1923
1969
|
* export default defineConfig({
|
|
1924
|
-
* input:
|
|
1970
|
+
* input: './petStore.yaml',
|
|
1925
1971
|
* output: { path: './src/gen' },
|
|
1926
1972
|
* storage: fsStorage(),
|
|
1927
1973
|
* })
|
|
@@ -1979,7 +2025,6 @@ function resolveConfig(userConfig) {
|
|
|
1979
2025
|
output: {
|
|
1980
2026
|
format: false,
|
|
1981
2027
|
lint: false,
|
|
1982
|
-
extension: { ".ts": ".ts" },
|
|
1983
2028
|
defaultBanner: "simple",
|
|
1984
2029
|
...userConfig.output
|
|
1985
2030
|
},
|
|
@@ -2089,7 +2134,7 @@ var Kubb = class {
|
|
|
2089
2134
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
2090
2135
|
*
|
|
2091
2136
|
* const kubb = createKubb({
|
|
2092
|
-
* input:
|
|
2137
|
+
* input: './petStore.yaml',
|
|
2093
2138
|
* output: { path: './src/gen' },
|
|
2094
2139
|
* adapter: adapterOas(),
|
|
2095
2140
|
* plugins: [pluginTs()],
|
|
@@ -2414,30 +2459,34 @@ function defineGenerator(generator) {
|
|
|
2414
2459
|
//#endregion
|
|
2415
2460
|
//#region src/defineParser.ts
|
|
2416
2461
|
/**
|
|
2417
|
-
*
|
|
2418
|
-
*
|
|
2462
|
+
* Wraps a parser factory and returns a function that accepts user options and
|
|
2463
|
+
* yields a typed {@link Parser}. Mirrors {@link definePlugin}: the factory
|
|
2464
|
+
* receives the caller's options, and calling the returned function without
|
|
2465
|
+
* options passes an empty object.
|
|
2466
|
+
*
|
|
2467
|
+
* Register the result in the `parsers` array on `defineConfig`, calling it to
|
|
2468
|
+
* apply options (`parserTs({ extension: { '.ts': '.js' } })`).
|
|
2419
2469
|
*
|
|
2420
2470
|
* @example
|
|
2421
2471
|
* ```ts
|
|
2422
2472
|
* import { defineParser } from '@kubb/core'
|
|
2423
2473
|
* import { extractStringsFromNodes } from '@kubb/ast'
|
|
2424
2474
|
*
|
|
2425
|
-
* export const
|
|
2475
|
+
* export const parserJson = defineParser((options: { pretty?: boolean } = {}) => ({
|
|
2426
2476
|
* name: 'json',
|
|
2427
2477
|
* extNames: ['.json'],
|
|
2428
2478
|
* parse(file) {
|
|
2429
|
-
*
|
|
2430
|
-
*
|
|
2431
|
-
* .join('\n')
|
|
2479
|
+
* const source = file.sources.map((source) => extractStringsFromNodes(source.nodes ?? [])).join('\n')
|
|
2480
|
+
* return options.pretty ? JSON.stringify(JSON.parse(source), null, 2) : source
|
|
2432
2481
|
* },
|
|
2433
2482
|
* print(...nodes) {
|
|
2434
2483
|
* return nodes.map(String).join('\n')
|
|
2435
2484
|
* },
|
|
2436
|
-
* })
|
|
2485
|
+
* }))
|
|
2437
2486
|
* ```
|
|
2438
2487
|
*/
|
|
2439
|
-
function defineParser(
|
|
2440
|
-
return
|
|
2488
|
+
function defineParser(factory) {
|
|
2489
|
+
return (options) => factory(options ?? {});
|
|
2441
2490
|
}
|
|
2442
2491
|
//#endregion
|
|
2443
2492
|
//#region src/storages/memoryStorage.ts
|
|
@@ -2454,7 +2503,7 @@ function defineParser(parser) {
|
|
|
2454
2503
|
* import { defineConfig } from 'kubb'
|
|
2455
2504
|
*
|
|
2456
2505
|
* export default defineConfig({
|
|
2457
|
-
* input:
|
|
2506
|
+
* input: './petStore.yaml',
|
|
2458
2507
|
* output: { path: './src/gen' },
|
|
2459
2508
|
* storage: memoryStorage(),
|
|
2460
2509
|
* })
|
|
@@ -2494,6 +2543,7 @@ exports.Diagnostics = Diagnostics;
|
|
|
2494
2543
|
exports.Hookable = require_usingCtx.Hookable;
|
|
2495
2544
|
exports.KubbDriver = KubbDriver;
|
|
2496
2545
|
exports.Resolver = Resolver;
|
|
2546
|
+
exports.applyConfigDefaults = applyConfigDefaults;
|
|
2497
2547
|
exports.cliReporter = cliReporter;
|
|
2498
2548
|
exports.createAdapter = createAdapter;
|
|
2499
2549
|
exports.createKubb = createKubb;
|
|
@@ -2506,6 +2556,7 @@ exports.defineParser = defineParser;
|
|
|
2506
2556
|
exports.definePlugin = definePlugin;
|
|
2507
2557
|
exports.fileReporter = fileReporter;
|
|
2508
2558
|
exports.fsStorage = fsStorage;
|
|
2559
|
+
exports.getInputKind = getInputKind;
|
|
2509
2560
|
exports.jsonReporter = jsonReporter;
|
|
2510
2561
|
exports.logLevel = logLevel;
|
|
2511
2562
|
exports.memoryStorage = memoryStorage;
|