@kubb/core 4.33.5 → 4.35.0
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/hooks.d.ts +1 -1
- package/dist/index.cjs +143 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.js +135 -9
- package/dist/index.js.map +1 -1
- package/dist/{types-DfjjJb2r.d.ts → types-7DgxNmCG.d.ts} +106 -2
- package/package.json +6 -4
- package/src/PluginManager.ts +35 -1
- package/src/build.ts +49 -2
- package/src/constants.ts +2 -0
- package/src/defineAdapter.ts +22 -0
- package/src/devtools.ts +59 -0
- package/src/index.ts +3 -0
- package/src/types.ts +101 -1
- package/src/utils/FunctionParams.ts +1 -0
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
2
|
+
import { M as PluginManager, _ as PluginFactoryOptions, h as Plugin } from "./types-7DgxNmCG.js";
|
|
3
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useMode.d.ts
|
package/dist/index.cjs
CHANGED
|
@@ -3,16 +3,19 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_chunk.__toESM(node_path);
|
|
8
6
|
let node_events = require("node:events");
|
|
9
7
|
let node_util = require("node:util");
|
|
10
8
|
let node_fs = require("node:fs");
|
|
11
9
|
let node_fs_promises = require("node:fs/promises");
|
|
10
|
+
let node_path = require("node:path");
|
|
11
|
+
node_path = require_chunk.__toESM(node_path);
|
|
12
|
+
let _kubb_ast = require("@kubb/ast");
|
|
12
13
|
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
13
14
|
let _kubb_react_fabric_parsers = require("@kubb/react-fabric/parsers");
|
|
14
15
|
let _kubb_react_fabric_plugins = require("@kubb/react-fabric/plugins");
|
|
15
16
|
let node_perf_hooks = require("node:perf_hooks");
|
|
17
|
+
let fflate = require("fflate");
|
|
18
|
+
let tinyexec = require("tinyexec");
|
|
16
19
|
let node_process = require("node:process");
|
|
17
20
|
let node_module = require("node:module");
|
|
18
21
|
node_module = require_chunk.__toESM(node_module);
|
|
@@ -23,7 +26,6 @@ let empathic_package = require("empathic/package");
|
|
|
23
26
|
empathic_package = require_chunk.__toESM(empathic_package);
|
|
24
27
|
let semver = require("semver");
|
|
25
28
|
let remeda = require("remeda");
|
|
26
|
-
let tinyexec = require("tinyexec");
|
|
27
29
|
//#region ../../internals/utils/dist/index.js
|
|
28
30
|
/** Thrown when a plugin's configuration or input fails validation. */
|
|
29
31
|
var ValidationPluginError = class extends Error {};
|
|
@@ -670,6 +672,9 @@ function defineConfig(config) {
|
|
|
670
672
|
function isInputPath(config) {
|
|
671
673
|
return typeof config?.input === "object" && config.input !== null && "path" in config.input;
|
|
672
674
|
}
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/constants.ts
|
|
677
|
+
const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
|
|
673
678
|
const BARREL_FILENAME = "index.ts";
|
|
674
679
|
const DEFAULT_BANNER = "simple";
|
|
675
680
|
const DEFAULT_EXTENSION = { ".ts": ".ts" };
|
|
@@ -729,6 +734,50 @@ const formatters = {
|
|
|
729
734
|
}
|
|
730
735
|
};
|
|
731
736
|
//#endregion
|
|
737
|
+
//#region src/devtools.ts
|
|
738
|
+
/**
|
|
739
|
+
* Encodes a `RootNode` as a compressed, URL-safe string.
|
|
740
|
+
*
|
|
741
|
+
* The JSON representation is deflate-compressed with {@link deflateSync} before
|
|
742
|
+
* base64url encoding, which typically reduces payload size by 70–80 % and
|
|
743
|
+
* keeps URLs well within browser and server path-length limits.
|
|
744
|
+
*
|
|
745
|
+
* Use {@link decodeAst} to reverse.
|
|
746
|
+
*/
|
|
747
|
+
function encodeAst(root) {
|
|
748
|
+
const compressed = (0, fflate.deflateSync)(new TextEncoder().encode(JSON.stringify(root)));
|
|
749
|
+
return Buffer.from(compressed).toString("base64url");
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Constructs the Kubb Studio URL for the given `RootNode`.
|
|
753
|
+
* When `options.ast` is `true`, navigates to the AST inspector (`/ast`).
|
|
754
|
+
* The `root` is encoded and attached as the `?root=` query parameter so Studio
|
|
755
|
+
* can decode and render it without a round-trip to any server.
|
|
756
|
+
*/
|
|
757
|
+
function getStudioUrl(root, studioUrl, options = {}) {
|
|
758
|
+
return `${studioUrl.replace(/\/$/, "")}${options.ast ? "/ast" : ""}?root=${encodeAst(root)}`;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Opens the Kubb Studio URL for the given `RootNode` in the default browser —
|
|
762
|
+
*
|
|
763
|
+
* Falls back to printing the URL if the browser cannot be launched.
|
|
764
|
+
*/
|
|
765
|
+
async function openInStudio(root, studioUrl, options = {}) {
|
|
766
|
+
const url = getStudioUrl(root, studioUrl, options);
|
|
767
|
+
const cmd = process.platform === "win32" ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
768
|
+
const args = process.platform === "win32" ? [
|
|
769
|
+
"/c",
|
|
770
|
+
"start",
|
|
771
|
+
"",
|
|
772
|
+
url
|
|
773
|
+
] : [url];
|
|
774
|
+
try {
|
|
775
|
+
await (0, tinyexec.x)(cmd, args);
|
|
776
|
+
} catch {
|
|
777
|
+
console.log(`\n ${url}\n`);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
//#endregion
|
|
732
781
|
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
733
782
|
var Node = class {
|
|
734
783
|
value;
|
|
@@ -915,6 +964,12 @@ function getMode(fileOrFolder) {
|
|
|
915
964
|
var PluginManager = class {
|
|
916
965
|
config;
|
|
917
966
|
options;
|
|
967
|
+
/**
|
|
968
|
+
* The universal `@kubb/ast` `RootNode` produced by the adapter, set by
|
|
969
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
970
|
+
*/
|
|
971
|
+
rootNode = void 0;
|
|
972
|
+
#studioIsOpen = false;
|
|
918
973
|
#plugins = /* @__PURE__ */ new Set();
|
|
919
974
|
#usedPluginNames = {};
|
|
920
975
|
#promiseManager;
|
|
@@ -932,6 +987,7 @@ var PluginManager = class {
|
|
|
932
987
|
}
|
|
933
988
|
getContext(plugin) {
|
|
934
989
|
const plugins = [...this.#plugins];
|
|
990
|
+
const pluginManager = this;
|
|
935
991
|
const baseContext = {
|
|
936
992
|
fabric: this.options.fabric,
|
|
937
993
|
config: this.config,
|
|
@@ -944,6 +1000,17 @@ var PluginManager = class {
|
|
|
944
1000
|
},
|
|
945
1001
|
upsertFile: async (...files) => {
|
|
946
1002
|
await this.options.fabric.upsertFile(...files);
|
|
1003
|
+
},
|
|
1004
|
+
get rootNode() {
|
|
1005
|
+
return pluginManager.rootNode;
|
|
1006
|
+
},
|
|
1007
|
+
openInStudio(options) {
|
|
1008
|
+
if (typeof pluginManager.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
1009
|
+
if (!pluginManager.rootNode) throw new Error("RootNode is not defined, make sure you have set the parser in kubb.config.ts");
|
|
1010
|
+
if (pluginManager.#studioIsOpen) return;
|
|
1011
|
+
pluginManager.#studioIsOpen = true;
|
|
1012
|
+
const studioUrl = pluginManager.config.devtools?.studioUrl ?? "https://studio.kubb.dev";
|
|
1013
|
+
return openInStudio(pluginManager.rootNode, studioUrl, options);
|
|
947
1014
|
}
|
|
948
1015
|
};
|
|
949
1016
|
const mergedExtras = {};
|
|
@@ -1301,7 +1368,7 @@ var PluginManager = class {
|
|
|
1301
1368
|
};
|
|
1302
1369
|
//#endregion
|
|
1303
1370
|
//#region package.json
|
|
1304
|
-
var version = "4.
|
|
1371
|
+
var version = "4.35.0";
|
|
1305
1372
|
//#endregion
|
|
1306
1373
|
//#region src/utils/diagnostics.ts
|
|
1307
1374
|
/**
|
|
@@ -1363,6 +1430,10 @@ async function setup(options) {
|
|
|
1363
1430
|
defaultBanner: DEFAULT_BANNER,
|
|
1364
1431
|
...userConfig.output
|
|
1365
1432
|
},
|
|
1433
|
+
devtools: userConfig.devtools ? {
|
|
1434
|
+
studioUrl: DEFAULT_STUDIO_URL,
|
|
1435
|
+
...typeof userConfig.devtools === "boolean" ? {} : userConfig.devtools
|
|
1436
|
+
} : void 0,
|
|
1366
1437
|
plugins: userConfig.plugins
|
|
1367
1438
|
};
|
|
1368
1439
|
if (definedConfig.output.clean) {
|
|
@@ -1409,14 +1480,31 @@ async function setup(options) {
|
|
|
1409
1480
|
` • Barrel type: ${definedConfig.output.barrelType || "none"}`
|
|
1410
1481
|
]
|
|
1411
1482
|
});
|
|
1483
|
+
const pluginManager = new PluginManager(definedConfig, {
|
|
1484
|
+
fabric,
|
|
1485
|
+
events,
|
|
1486
|
+
concurrency: 15
|
|
1487
|
+
});
|
|
1488
|
+
if (definedConfig.adapter) {
|
|
1489
|
+
const source = inputToAdapterSource(definedConfig);
|
|
1490
|
+
await events.emit("debug", {
|
|
1491
|
+
date: /* @__PURE__ */ new Date(),
|
|
1492
|
+
logs: [`Running adapter: ${definedConfig.adapter.name}`]
|
|
1493
|
+
});
|
|
1494
|
+
pluginManager.rootNode = await definedConfig.adapter.parse(source);
|
|
1495
|
+
await events.emit("debug", {
|
|
1496
|
+
date: /* @__PURE__ */ new Date(),
|
|
1497
|
+
logs: [
|
|
1498
|
+
`✓ Adapter '${definedConfig.adapter.name}' resolved RootNode`,
|
|
1499
|
+
` • Schemas: ${pluginManager.rootNode.schemas.length}`,
|
|
1500
|
+
` • Operations: ${pluginManager.rootNode.operations.length}`
|
|
1501
|
+
]
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1412
1504
|
return {
|
|
1413
1505
|
events,
|
|
1414
1506
|
fabric,
|
|
1415
|
-
pluginManager
|
|
1416
|
-
fabric,
|
|
1417
|
-
events,
|
|
1418
|
-
concurrency: 15
|
|
1419
|
-
}),
|
|
1507
|
+
pluginManager,
|
|
1420
1508
|
sources
|
|
1421
1509
|
};
|
|
1422
1510
|
}
|
|
@@ -1571,6 +1659,44 @@ function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, plu
|
|
|
1571
1659
|
});
|
|
1572
1660
|
});
|
|
1573
1661
|
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Maps the resolved `Config['input']` shape into an `AdapterSource` that
|
|
1664
|
+
* the adapter's `parse()` can consume.
|
|
1665
|
+
*/
|
|
1666
|
+
function inputToAdapterSource(config) {
|
|
1667
|
+
if (Array.isArray(config.input)) return {
|
|
1668
|
+
type: "paths",
|
|
1669
|
+
paths: config.input.map((i) => (0, node_path.resolve)(config.root, i.path))
|
|
1670
|
+
};
|
|
1671
|
+
if ("data" in config.input) return {
|
|
1672
|
+
type: "data",
|
|
1673
|
+
data: config.input.data
|
|
1674
|
+
};
|
|
1675
|
+
return {
|
|
1676
|
+
type: "path",
|
|
1677
|
+
path: (0, node_path.resolve)(config.root, config.input.path)
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
//#endregion
|
|
1681
|
+
//#region src/defineAdapter.ts
|
|
1682
|
+
/**
|
|
1683
|
+
* Wraps an adapter builder to make the options parameter optional.
|
|
1684
|
+
*
|
|
1685
|
+
* @example
|
|
1686
|
+
* ```ts
|
|
1687
|
+
* export const adapterOas = defineAdapter<OasAdapter>((options) => {
|
|
1688
|
+
* const { validate = true, dateType = 'string' } = options
|
|
1689
|
+
* return {
|
|
1690
|
+
* name: adapterOasName,
|
|
1691
|
+
* options: { validate, dateType, ... },
|
|
1692
|
+
* parse(source) { ... },
|
|
1693
|
+
* }
|
|
1694
|
+
* })
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1697
|
+
function defineAdapter(build) {
|
|
1698
|
+
return (options) => build(options ?? {});
|
|
1699
|
+
}
|
|
1574
1700
|
//#endregion
|
|
1575
1701
|
//#region src/defineLogger.ts
|
|
1576
1702
|
function defineLogger(logger) {
|
|
@@ -2037,15 +2163,23 @@ async function detectLinter() {
|
|
|
2037
2163
|
]) if (await isLinterAvailable(linter)) return linter;
|
|
2038
2164
|
}
|
|
2039
2165
|
//#endregion
|
|
2166
|
+
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
2040
2167
|
exports.FunctionParams = FunctionParams;
|
|
2041
2168
|
exports.PackageManager = PackageManager;
|
|
2042
2169
|
exports.PluginManager = PluginManager;
|
|
2043
2170
|
exports.PromiseManager = PromiseManager;
|
|
2044
2171
|
exports.build = build;
|
|
2045
2172
|
exports.default = build;
|
|
2173
|
+
exports.defineAdapter = defineAdapter;
|
|
2046
2174
|
exports.defineConfig = defineConfig;
|
|
2047
2175
|
exports.defineLogger = defineLogger;
|
|
2048
2176
|
exports.definePlugin = definePlugin;
|
|
2177
|
+
Object.defineProperty(exports, "definePrinter", {
|
|
2178
|
+
enumerable: true,
|
|
2179
|
+
get: function() {
|
|
2180
|
+
return _kubb_ast.definePrinter;
|
|
2181
|
+
}
|
|
2182
|
+
});
|
|
2049
2183
|
exports.detectFormatter = detectFormatter;
|
|
2050
2184
|
exports.detectLinter = detectLinter;
|
|
2051
2185
|
exports.formatters = formatters;
|