@kubb/core 5.18.6 → 5.18.7
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 +82 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -10
- package/dist/index.d.ts +30 -10
- package/dist/index.js +93 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ let node_readline = require("node:readline");
|
|
|
45
45
|
let node_url = require("node:url");
|
|
46
46
|
let node_module = require("node:module");
|
|
47
47
|
// package.json
|
|
48
|
-
var version = "5.18.
|
|
48
|
+
var version = "5.18.7";
|
|
49
49
|
// ../../internals/utils/src/casing.ts
|
|
50
50
|
/**
|
|
51
51
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -573,7 +573,7 @@ const diagnosticCatalog = {
|
|
|
573
573
|
code: "KUBB_INVALID_DOCUMENT",
|
|
574
574
|
title: "Invalid document",
|
|
575
575
|
cause: "The `input` cannot be read as an OpenAPI or Swagger document: its JSON or YAML has a syntax error, it declares no `openapi` or `swagger` version field, or its version cannot be upgraded to OpenAPI 3.1.",
|
|
576
|
-
fix: "Fix the syntax at the reported line, and check that `input` points at the spec and not an HTML page. Point `input` at a Swagger 2.0
|
|
576
|
+
fix: "Fix the syntax at the reported line, and check that `input` points at the spec and not an HTML page. Point `input` at a Swagger 2.0 or OpenAPI 3.0, 3.1, or 3.2 document, and check that a passed object is the spec itself rather than a wrapper around it."
|
|
577
577
|
},
|
|
578
578
|
invalidSpec: {
|
|
579
579
|
code: "KUBB_INVALID_SPEC",
|
|
@@ -698,8 +698,8 @@ const diagnosticCatalog = {
|
|
|
698
698
|
invalidPluginOptions: {
|
|
699
699
|
code: "KUBB_INVALID_PLUGIN_OPTIONS",
|
|
700
700
|
title: "Invalid plugin options",
|
|
701
|
-
cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
|
|
702
|
-
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or
|
|
701
|
+
cause: "A plugin was configured with options that cannot be honored, for example a single-file output (`output.mode: 'file'`, or an `output.path` with a file extension) paired with a `group` option.",
|
|
702
|
+
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option, give `output.path` a directory name, or set `output.mode: 'directory'`."
|
|
703
703
|
},
|
|
704
704
|
postGenerateFailed: {
|
|
705
705
|
code: "KUBB_POST_GENERATE_FAILED",
|
|
@@ -1742,11 +1742,16 @@ function inputToAdapterSource(config) {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
// src/resolveOptions.ts
|
|
1744
1744
|
const patterns = /* @__PURE__ */ new Map();
|
|
1745
|
+
const methodPatterns = /* @__PURE__ */ new Map();
|
|
1745
1746
|
const nodeCaches = /* @__PURE__ */ new WeakMap();
|
|
1746
1747
|
function testPattern(value, pattern) {
|
|
1747
1748
|
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1748
1749
|
return value.match(pattern) !== null;
|
|
1749
1750
|
}
|
|
1751
|
+
function testMethod(method, pattern) {
|
|
1752
|
+
if (typeof pattern === "string") return memo$1(methodPatterns, pattern, () => new RegExp(pattern, "i")).test(method);
|
|
1753
|
+
return method.match(pattern.ignoreCase ? pattern : new RegExp(pattern.source, `${pattern.flags}i`)) !== null;
|
|
1754
|
+
}
|
|
1750
1755
|
function matchesOperation(node, filter) {
|
|
1751
1756
|
if (filter.type === "extension") {
|
|
1752
1757
|
const { extensions } = node;
|
|
@@ -1756,7 +1761,7 @@ function matchesOperation(node, filter) {
|
|
|
1756
1761
|
if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
|
|
1757
1762
|
if (type === "operationId") return testPattern(node.operationId, pattern);
|
|
1758
1763
|
if (type === "path") return node.path !== void 0 && testPattern(node.path, pattern);
|
|
1759
|
-
if (type === "method") return node.method !== void 0 &&
|
|
1764
|
+
if (type === "method") return node.method !== void 0 && testMethod(node.method, pattern);
|
|
1760
1765
|
if (type === "contentType") return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false;
|
|
1761
1766
|
return false;
|
|
1762
1767
|
}
|
|
@@ -2059,15 +2064,15 @@ var Resolver = class Resolver {
|
|
|
2059
2064
|
/**
|
|
2060
2065
|
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
2061
2066
|
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
2062
|
-
* spec-derived values from writing outside the
|
|
2067
|
+
* spec-derived values from writing outside the output directory.
|
|
2063
2068
|
*/
|
|
2064
2069
|
#resolveOverridePath(filePath, root) {
|
|
2065
2070
|
const resolved = node_path.default.resolve(root, filePath);
|
|
2066
2071
|
assertInside({
|
|
2067
2072
|
target: resolved,
|
|
2068
2073
|
parent: root,
|
|
2069
|
-
message: `Resolved path "${resolved}" is outside the
|
|
2070
|
-
help: "A resolver `file.path` must return a path inside the
|
|
2074
|
+
message: `Resolved path "${resolved}" is outside the output directory "${root}".`,
|
|
2075
|
+
help: "A resolver `file.path` must return a path inside the output directory (`config.output.path`)."
|
|
2071
2076
|
});
|
|
2072
2077
|
return resolved;
|
|
2073
2078
|
}
|
|
@@ -2210,7 +2215,7 @@ var Resolver = class Resolver {
|
|
|
2210
2215
|
function createResolver(options) {
|
|
2211
2216
|
return new Resolver(options);
|
|
2212
2217
|
}
|
|
2213
|
-
// \0@oxc-project+runtime@0.
|
|
2218
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/usingCtx.js
|
|
2214
2219
|
function _usingCtx() {
|
|
2215
2220
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
2216
2221
|
var n = Error();
|
|
@@ -2580,6 +2585,22 @@ function normalizePluginOptions(rawOptions, pluginName) {
|
|
|
2580
2585
|
group,
|
|
2581
2586
|
pluginName
|
|
2582
2587
|
});
|
|
2588
|
+
options.override = options.override?.map((entry) => {
|
|
2589
|
+
const { output } = entry.options;
|
|
2590
|
+
if (!output) return entry;
|
|
2591
|
+
const entryGroup = "group" in entry.options ? entry.options.group : group;
|
|
2592
|
+
return {
|
|
2593
|
+
...entry,
|
|
2594
|
+
options: {
|
|
2595
|
+
...entry.options,
|
|
2596
|
+
output: normalizeOutput({
|
|
2597
|
+
output,
|
|
2598
|
+
group: entryGroup,
|
|
2599
|
+
pluginName
|
|
2600
|
+
})
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
});
|
|
2583
2604
|
return options;
|
|
2584
2605
|
}
|
|
2585
2606
|
/**
|
|
@@ -3810,7 +3831,7 @@ function hasOutputPasses({ output, storage }) {
|
|
|
3810
3831
|
* const { files, diagnostics } = await kubb.safeBuild()
|
|
3811
3832
|
* ```
|
|
3812
3833
|
*/
|
|
3813
|
-
var Kubb = class {
|
|
3834
|
+
var Kubb = class Kubb {
|
|
3814
3835
|
hooks;
|
|
3815
3836
|
config;
|
|
3816
3837
|
#driver = null;
|
|
@@ -3821,6 +3842,34 @@ var Kubb = class {
|
|
|
3821
3842
|
this.hooks = options.hooks ?? new Hookable();
|
|
3822
3843
|
this.#signal = options.signal;
|
|
3823
3844
|
}
|
|
3845
|
+
/**
|
|
3846
|
+
* Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
|
|
3847
|
+
* memory holds one config at a time. A config that fails does not stop the others. Only an aborted `signal` rejects.
|
|
3848
|
+
*/
|
|
3849
|
+
static async *generate(configs, { hooks = new Hookable(), signal } = {}) {
|
|
3850
|
+
for (const config of configs) {
|
|
3851
|
+
const kubb = new Kubb(config, {
|
|
3852
|
+
hooks,
|
|
3853
|
+
signal
|
|
3854
|
+
});
|
|
3855
|
+
try {
|
|
3856
|
+
yield {
|
|
3857
|
+
...await kubb.generate(),
|
|
3858
|
+
kubb
|
|
3859
|
+
};
|
|
3860
|
+
} catch (error) {
|
|
3861
|
+
if (signal?.aborted) throw error;
|
|
3862
|
+
yield {
|
|
3863
|
+
success: false,
|
|
3864
|
+
files: [],
|
|
3865
|
+
diagnostics: [Diagnostics.from(error)],
|
|
3866
|
+
input: null,
|
|
3867
|
+
kubb,
|
|
3868
|
+
error
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3824
3873
|
get storage() {
|
|
3825
3874
|
return this.config.storage;
|
|
3826
3875
|
}
|
|
@@ -3891,7 +3940,8 @@ var Kubb = class {
|
|
|
3891
3940
|
diagnostics,
|
|
3892
3941
|
files: driver.fileManager.files,
|
|
3893
3942
|
driver,
|
|
3894
|
-
storage
|
|
3943
|
+
storage,
|
|
3944
|
+
input: driver.inputNode
|
|
3895
3945
|
};
|
|
3896
3946
|
} catch (_) {
|
|
3897
3947
|
_usingCtx$1.e = _;
|
|
@@ -3927,15 +3977,16 @@ var Kubb = class {
|
|
|
3927
3977
|
if (signal?.aborted) throw caughtError;
|
|
3928
3978
|
output = {
|
|
3929
3979
|
files: [],
|
|
3930
|
-
diagnostics: [Diagnostics.from(caughtError)]
|
|
3980
|
+
diagnostics: [Diagnostics.from(caughtError)],
|
|
3981
|
+
input: null
|
|
3931
3982
|
};
|
|
3932
3983
|
}
|
|
3933
|
-
const { files, diagnostics } = output;
|
|
3984
|
+
const { files, diagnostics, input } = output;
|
|
3934
3985
|
const storage = this.storage;
|
|
3935
3986
|
signal?.throwIfAborted();
|
|
3936
3987
|
for (const diagnostic of diagnostics) if (Diagnostics.isProblem(diagnostic)) await Diagnostics.emit(hooks, diagnostic);
|
|
3937
3988
|
if (Diagnostics.hasError(diagnostics)) {
|
|
3938
|
-
await
|
|
3989
|
+
await this.#end({
|
|
3939
3990
|
config,
|
|
3940
3991
|
storage,
|
|
3941
3992
|
diagnostics,
|
|
@@ -3946,7 +3997,8 @@ var Kubb = class {
|
|
|
3946
3997
|
return {
|
|
3947
3998
|
success: false,
|
|
3948
3999
|
files,
|
|
3949
|
-
diagnostics
|
|
4000
|
+
diagnostics,
|
|
4001
|
+
input
|
|
3950
4002
|
};
|
|
3951
4003
|
}
|
|
3952
4004
|
const processOutput = options.processOutput ?? runOutputPasses;
|
|
@@ -3959,7 +4011,7 @@ var Kubb = class {
|
|
|
3959
4011
|
const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
|
|
3960
4012
|
const failed = Diagnostics.hasError(outputDiagnostics);
|
|
3961
4013
|
if (!failed) await this.#manifest?.commit();
|
|
3962
|
-
await
|
|
4014
|
+
await this.#end({
|
|
3963
4015
|
config,
|
|
3964
4016
|
storage,
|
|
3965
4017
|
diagnostics: finalDiagnostics,
|
|
@@ -3970,11 +4022,23 @@ var Kubb = class {
|
|
|
3970
4022
|
return {
|
|
3971
4023
|
success: !failed,
|
|
3972
4024
|
files,
|
|
3973
|
-
diagnostics: finalDiagnostics
|
|
4025
|
+
diagnostics: finalDiagnostics,
|
|
4026
|
+
input
|
|
3974
4027
|
};
|
|
3975
4028
|
}
|
|
4029
|
+
/** Ends a run: `kubb:generation:end`, then the totals on `kubb:generation:summary`. */
|
|
4030
|
+
async #end(ctx) {
|
|
4031
|
+
await this.hooks.callHook("kubb:generation:end", ctx);
|
|
4032
|
+
await this.hooks.callHook("kubb:generation:summary", {
|
|
4033
|
+
duration: Math.round(getElapsedMs(ctx.hrStart)),
|
|
4034
|
+
fileCount: ctx.filesCreated,
|
|
4035
|
+
failedPlugins: Diagnostics.failedPlugins(ctx.diagnostics).length,
|
|
4036
|
+
status: ctx.status
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
3976
4039
|
dispose() {
|
|
3977
4040
|
this.#driver?.dispose();
|
|
4041
|
+
this.#driver = null;
|
|
3978
4042
|
}
|
|
3979
4043
|
[Symbol.dispose]() {
|
|
3980
4044
|
this.dispose();
|
|
@@ -4583,6 +4647,7 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4583
4647
|
}
|
|
4584
4648
|
exports.Diagnostics = Diagnostics;
|
|
4585
4649
|
exports.Hookable = Hookable;
|
|
4650
|
+
exports.Kubb = Kubb;
|
|
4586
4651
|
exports.KubbDriver = KubbDriver;
|
|
4587
4652
|
exports.Resolver = Resolver;
|
|
4588
4653
|
exports.addGenerator = addGenerator;
|