@kubb/core 5.18.4 → 5.18.6
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 +23 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -10
- package/dist/index.d.ts +18 -10
- package/dist/index.js +24 -18
- 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.6";
|
|
49
49
|
// ../../internals/utils/src/casing.ts
|
|
50
50
|
/**
|
|
51
51
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -1765,7 +1765,7 @@ function matchesSchema(node, filter) {
|
|
|
1765
1765
|
return null;
|
|
1766
1766
|
}
|
|
1767
1767
|
function computeOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1768
|
-
if (node.kind === _kubb_ast.ast.
|
|
1768
|
+
if (node.kind === _kubb_ast.ast.node.kinds.operation) {
|
|
1769
1769
|
if (exclude.some((filter) => matchesOperation(node, filter))) return null;
|
|
1770
1770
|
if (include && !include.some((filter) => matchesOperation(node, filter))) return null;
|
|
1771
1771
|
return {
|
|
@@ -1773,7 +1773,7 @@ function computeOptions(node, { options, exclude = [], include, override = [] })
|
|
|
1773
1773
|
...override.find((filter) => matchesOperation(node, filter))?.options
|
|
1774
1774
|
};
|
|
1775
1775
|
}
|
|
1776
|
-
if (node.kind === _kubb_ast.ast.
|
|
1776
|
+
if (node.kind === _kubb_ast.ast.node.kinds.schema) {
|
|
1777
1777
|
if (exclude.some((filter) => matchesSchema(node, filter) === true)) return null;
|
|
1778
1778
|
if (include) {
|
|
1779
1779
|
const applicable = include.map((filter) => matchesSchema(node, filter)).filter((result) => result !== null);
|
|
@@ -1952,19 +1952,19 @@ var Resolver = class Resolver {
|
|
|
1952
1952
|
}
|
|
1953
1953
|
/**
|
|
1954
1954
|
* Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
|
|
1955
|
-
* order. Each ref's target resolves through `
|
|
1955
|
+
* order. Each ref's target resolves through `ast.ref.getName`, so collision- or macro-renamed
|
|
1956
1956
|
* schemas (`targetName`) import the emitted name. Names and paths go through the top-level
|
|
1957
1957
|
* `name` and `file`, so import entries follow the plugin's conventions, and a per-call
|
|
1958
1958
|
* `name` override wins over both.
|
|
1959
1959
|
*
|
|
1960
|
-
* The subtree scan runs through `
|
|
1960
|
+
* The subtree scan runs through `ast.graph.getImportedNames`, which memoizes by node identity, so a
|
|
1961
1961
|
* schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
|
|
1962
1962
|
* reads the same ref set instead of re-scanning it per plugin.
|
|
1963
1963
|
*/
|
|
1964
1964
|
imports(options) {
|
|
1965
1965
|
const { node, root, output, group, extname = ".ts", name, checks } = options;
|
|
1966
1966
|
const resolveName = name ?? ((schemaName) => this.name(schemaName));
|
|
1967
|
-
return
|
|
1967
|
+
return _kubb_ast.ast.graph.getImportedNames(node, { checks }).map((schemaName) => _kubb_ast.ast.factory.createImport({
|
|
1968
1968
|
name: [resolveName(schemaName)],
|
|
1969
1969
|
path: this.#resolveFilePath({
|
|
1970
1970
|
name: schemaName,
|
|
@@ -2018,11 +2018,17 @@ var Resolver = class Resolver {
|
|
|
2018
2018
|
}
|
|
2019
2019
|
}
|
|
2020
2020
|
/**
|
|
2021
|
-
* A custom `group.name` wins; otherwise `tag`
|
|
2022
|
-
* folders of its `parent` tags, and `path` groups use the first
|
|
2023
|
-
* when none remain, placing the file in the output root, kept safe by the caller's
|
|
2021
|
+
* The folder a group puts a file in, relative to the output directory. A custom `group.name` wins; otherwise `tag`
|
|
2022
|
+
* groups use the camelCased tag, nested in the folders of its `parent` tags, and `path` groups use the first
|
|
2023
|
+
* non-traversal segment (`''` when none remain, placing the file in the output root, kept safe by the caller's
|
|
2024
|
+
* boundary check).
|
|
2025
|
+
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```ts
|
|
2028
|
+
* resolver.groupDir({ type: 'tag' }, 'pet store') // 'petStore'
|
|
2029
|
+
* ```
|
|
2024
2030
|
*/
|
|
2025
|
-
|
|
2031
|
+
groupDir(group, groupValue) {
|
|
2026
2032
|
if (group.name) return group.name({ group: groupValue });
|
|
2027
2033
|
if (group.type === "tag") {
|
|
2028
2034
|
const chain = [groupValue];
|
|
@@ -2041,7 +2047,7 @@ var Resolver = class Resolver {
|
|
|
2041
2047
|
if (output.mode !== "directory") return node_path.default.resolve(root, output.path);
|
|
2042
2048
|
const outputDir = node_path.default.resolve(root, output.path);
|
|
2043
2049
|
const groupValue = group?.type === "path" ? groupPath : tag;
|
|
2044
|
-
const result = group && groupValue ? node_path.default.resolve(outputDir, this
|
|
2050
|
+
const result = group && groupValue ? node_path.default.resolve(outputDir, this.groupDir(group, groupValue), baseName) : node_path.default.resolve(outputDir, baseName);
|
|
2045
2051
|
assertInside({
|
|
2046
2052
|
target: result,
|
|
2047
2053
|
parent: outputDir,
|
|
@@ -2264,7 +2270,7 @@ function _usingCtx() {
|
|
|
2264
2270
|
};
|
|
2265
2271
|
}
|
|
2266
2272
|
function joinSources(file) {
|
|
2267
|
-
return file.sources.map((source) =>
|
|
2273
|
+
return file.sources.map((source) => _kubb_ast.ast.node.getText(source.nodes)).filter(Boolean).join("\n\n");
|
|
2268
2274
|
}
|
|
2269
2275
|
/** Runs a parser call and turns a crash into a `KUBB_PARSER_FAILED` diagnostic that names the parser. */
|
|
2270
2276
|
function runParser(parser, print) {
|
|
@@ -2596,7 +2602,7 @@ function assertPluginEntry(entry, index) {
|
|
|
2596
2602
|
* pointer into the input.
|
|
2597
2603
|
*/
|
|
2598
2604
|
function getCrashSite(node) {
|
|
2599
|
-
if (node.kind === _kubb_ast.ast.
|
|
2605
|
+
if (node.kind === _kubb_ast.ast.node.kinds.schema) return {
|
|
2600
2606
|
label: node.name ? `schema "${node.name}"` : "an inline schema",
|
|
2601
2607
|
location: node.pointer ? {
|
|
2602
2608
|
kind: "schema",
|
|
@@ -2696,7 +2702,7 @@ var KubbDriver = class {
|
|
|
2696
2702
|
* config are ignored here and surface later through `requirePlugin`.
|
|
2697
2703
|
*/
|
|
2698
2704
|
#sortPlugins(plugins) {
|
|
2699
|
-
const queue = [...plugins].sort((a, b) =>
|
|
2705
|
+
const queue = [...plugins].sort((a, b) => _kubb_ast.ast.macro.compareOrder(a.enforce, b.enforce));
|
|
2700
2706
|
const names = new Set(queue.map((plugin) => plugin.name));
|
|
2701
2707
|
const blockedBy = new Map(queue.map((plugin) => {
|
|
2702
2708
|
const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
|
|
@@ -2904,7 +2910,7 @@ var KubbDriver = class {
|
|
|
2904
2910
|
* (`kubb:plugins:end`) and the write see them.
|
|
2905
2911
|
*/
|
|
2906
2912
|
#inlineFiles(parsers) {
|
|
2907
|
-
const { files, virtualPaths, problems } = _kubb_ast.ast.
|
|
2913
|
+
const { files, virtualPaths, problems } = _kubb_ast.ast.file.inline(this.fileManager.files, { language: (file) => parsers.get(file.extname)?.inline });
|
|
2908
2914
|
if (virtualPaths.length === 0) return;
|
|
2909
2915
|
this.fileManager.add(...files);
|
|
2910
2916
|
this.fileManager.delete(...virtualPaths);
|
|
@@ -2991,7 +2997,7 @@ var KubbDriver = class {
|
|
|
2991
2997
|
include,
|
|
2992
2998
|
override
|
|
2993
2999
|
}) !== null);
|
|
2994
|
-
allowedSchemaNamesByPlugin.set(plugin.name,
|
|
3000
|
+
allowedSchemaNamesByPlugin.set(plugin.name, _kubb_ast.ast.graph.getUsedNames(includedOps, schemas));
|
|
2995
3001
|
}
|
|
2996
3002
|
const states = entries.map(({ plugin, context, hrStart }) => {
|
|
2997
3003
|
const generatorContext = {
|
|
@@ -3019,7 +3025,7 @@ var KubbDriver = class {
|
|
|
3019
3025
|
};
|
|
3020
3026
|
});
|
|
3021
3027
|
const resolveForPlugin = (state, node) => {
|
|
3022
|
-
const transformedNode = _kubb_ast.ast.
|
|
3028
|
+
const transformedNode = _kubb_ast.ast.macro.apply(node, state.plugin.macros ?? []);
|
|
3023
3029
|
if (state.optionsAreStatic) return {
|
|
3024
3030
|
transformedNode,
|
|
3025
3031
|
options: state.plugin.options
|