@kubb/core 5.0.0-alpha.26 → 5.0.0-alpha.28
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/{PluginDriver-BGRDpPpK.d.ts → PluginDriver-B12z6KO-.d.ts} +32 -8
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +35 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -24
- package/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PluginDriver.ts +3 -0
- package/src/index.ts +1 -2
- package/src/types.ts +31 -7
- package/src/utils/getPreset.ts +50 -24
- package/src/utils/mergeResolvers.ts +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
2
|
+
import { Node, OperationNode, Printer, Printer as Printer$1, PrinterFactoryOptions, PrinterPartial, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
3
3
|
import { Fabric, FabricFile } from "@kubb/fabric-core/types";
|
|
4
4
|
import { HttpMethod } from "@kubb/oas";
|
|
5
5
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
@@ -921,9 +921,16 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
921
921
|
*/
|
|
922
922
|
options: TOptions['resolvedOptions'];
|
|
923
923
|
/**
|
|
924
|
-
* The resolver for this plugin
|
|
924
|
+
* The resolver for this plugin.
|
|
925
|
+
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
925
926
|
*/
|
|
926
927
|
resolver?: TOptions['resolver'];
|
|
928
|
+
/**
|
|
929
|
+
* The composed transformer for this plugin.
|
|
930
|
+
* Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
|
|
931
|
+
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
932
|
+
*/
|
|
933
|
+
transformer?: Visitor;
|
|
927
934
|
/**
|
|
928
935
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
929
936
|
* Can be used to validate dependent plugins.
|
|
@@ -957,9 +964,16 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
957
964
|
*/
|
|
958
965
|
options: TOptions['resolvedOptions'];
|
|
959
966
|
/**
|
|
960
|
-
* The resolver for this plugin
|
|
967
|
+
* The resolver for this plugin.
|
|
968
|
+
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
961
969
|
*/
|
|
962
970
|
resolver: TOptions['resolver'];
|
|
971
|
+
/**
|
|
972
|
+
* The composed transformer for this plugin. Accessible via `context.transformer`.
|
|
973
|
+
* Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
|
|
974
|
+
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
975
|
+
*/
|
|
976
|
+
transformer?: Visitor;
|
|
963
977
|
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
964
978
|
/**
|
|
965
979
|
* Defines a context that can be used by other plugins, see `PluginDriver` where we convert from `UserPlugin` to `Plugin` (used when calling `createPlugin`).
|
|
@@ -1036,6 +1050,11 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1036
1050
|
* Resolver for the current plugin. Shorthand for `plugin.resolver`.
|
|
1037
1051
|
*/
|
|
1038
1052
|
resolver: TOptions['resolver'];
|
|
1053
|
+
/**
|
|
1054
|
+
* Composed transformer for the current plugin. Shorthand for `plugin.transformer`.
|
|
1055
|
+
* Apply with `transform(node, context.transformer)` to pre-process AST nodes before printing.
|
|
1056
|
+
*/
|
|
1057
|
+
transformer: Visitor | undefined;
|
|
1039
1058
|
/**
|
|
1040
1059
|
* Opens the Kubb Studio URL for the current `rootNode` in the default browser.
|
|
1041
1060
|
* Falls back to printing the URL if the browser cannot be launched.
|
|
@@ -1135,7 +1154,7 @@ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOption
|
|
|
1135
1154
|
*/
|
|
1136
1155
|
type CompatibilityPreset = 'default' | 'kubbV4';
|
|
1137
1156
|
/**
|
|
1138
|
-
* A preset bundles a name,
|
|
1157
|
+
* A preset bundles a name, a resolver, optional AST transformers,
|
|
1139
1158
|
* and optional generators into a single reusable configuration object.
|
|
1140
1159
|
*
|
|
1141
1160
|
* @template TResolver - The concrete resolver type for this preset.
|
|
@@ -1146,9 +1165,9 @@ type Preset<TResolver extends Resolver = Resolver> = {
|
|
|
1146
1165
|
*/
|
|
1147
1166
|
name: string;
|
|
1148
1167
|
/**
|
|
1149
|
-
*
|
|
1168
|
+
* The resolver used by this preset.
|
|
1150
1169
|
*/
|
|
1151
|
-
|
|
1170
|
+
resolver: TResolver;
|
|
1152
1171
|
/**
|
|
1153
1172
|
* Optional AST visitors / transformers applied after resolving.
|
|
1154
1173
|
*/
|
|
@@ -1158,6 +1177,11 @@ type Preset<TResolver extends Resolver = Resolver> = {
|
|
|
1158
1177
|
* to their concrete generator type.
|
|
1159
1178
|
*/
|
|
1160
1179
|
generators?: Array<Generator<any>>;
|
|
1180
|
+
/**
|
|
1181
|
+
* Optional printer factory used by this preset.
|
|
1182
|
+
* The generator calls this function at render-time to produce a configured printer instance.
|
|
1183
|
+
*/
|
|
1184
|
+
printer?: (options: any) => Printer;
|
|
1161
1185
|
};
|
|
1162
1186
|
/**
|
|
1163
1187
|
* A named registry of presets, keyed by preset name.
|
|
@@ -1447,5 +1471,5 @@ declare class PluginDriver {
|
|
|
1447
1471
|
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
1448
1472
|
}
|
|
1449
1473
|
//#endregion
|
|
1450
|
-
export {
|
|
1451
|
-
//# sourceMappingURL=PluginDriver-
|
|
1474
|
+
export { createStorage as $, PrinterFactoryOptions as A, ResolverPathParams as B, PluginLifecycle as C, Preset as D, PluginWithLifeCycle as E, ResolvePathOptions as F, UserPluginWithLifeCycle as G, UserGroup as H, ResolvePathParams as I, CoreGeneratorV2 as J, UserResolver as K, Resolver as L, ResolveBannerContext as M, ResolveNameParams as N, Presets as O, ResolveOptionsContext as P, Storage as Q, ResolverContext as R, PluginFactoryOptions as S, PluginParameter as T, UserLogger as U, UserConfig as V, UserPlugin as W, ReactGeneratorV2 as X, Generator as Y, defineGenerator as Z, LoggerOptions as _, AdapterSource as a, Plugin as b, Config as c, Group as d, formatters as et, Include as f, LoggerContext as g, Logger as h, AdapterFactoryOptions as i, AsyncEventEmitter as it, PrinterPartial as j, Printer$1 as k, DevtoolsOptions as l, InputPath as m, getMode as n, logLevel as nt, BarrelType as o, InputData as p, KubbEvents as q, Adapter as r, PossiblePromise as rt, CompatibilityPreset as s, PluginDriver as t, linters as tt, Exclude as u, Output as v, PluginLifecycleHooks as w, PluginContext as x, Override as y, ResolverFileParams as z };
|
|
1475
|
+
//# sourceMappingURL=PluginDriver-B12z6KO-.d.ts.map
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { S as PluginFactoryOptions, b as Plugin, t as PluginDriver } from "./PluginDriver-
|
|
2
|
+
import { S as PluginFactoryOptions, b as Plugin, t as PluginDriver } from "./PluginDriver-B12z6KO-.js";
|
|
3
3
|
import { FabricFile } from "@kubb/fabric-core/types";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useDriver.d.ts
|
package/dist/index.cjs
CHANGED
|
@@ -1002,6 +1002,9 @@ var PluginDriver = class {
|
|
|
1002
1002
|
get resolver() {
|
|
1003
1003
|
return plugin.resolver;
|
|
1004
1004
|
},
|
|
1005
|
+
get transformer() {
|
|
1006
|
+
return plugin.transformer;
|
|
1007
|
+
},
|
|
1005
1008
|
openInStudio(options) {
|
|
1006
1009
|
if (!driver.config.devtools || driver.#studioIsOpen) return;
|
|
1007
1010
|
if (typeof driver.config.devtools !== "object") throw new Error("Devtools must be an object");
|
|
@@ -1416,7 +1419,7 @@ const fsStorage = createStorage(() => ({
|
|
|
1416
1419
|
}));
|
|
1417
1420
|
//#endregion
|
|
1418
1421
|
//#region package.json
|
|
1419
|
-
var version = "5.0.0-alpha.
|
|
1422
|
+
var version = "5.0.0-alpha.28";
|
|
1420
1423
|
//#endregion
|
|
1421
1424
|
//#region src/utils/diagnostics.ts
|
|
1422
1425
|
/**
|
|
@@ -2769,46 +2772,43 @@ async function getConfigs(config, args) {
|
|
|
2769
2772
|
}));
|
|
2770
2773
|
}
|
|
2771
2774
|
//#endregion
|
|
2772
|
-
//#region src/utils/
|
|
2775
|
+
//#region src/utils/getPreset.ts
|
|
2773
2776
|
/**
|
|
2774
|
-
*
|
|
2775
|
-
*
|
|
2776
|
-
*
|
|
2777
|
-
*
|
|
2778
|
-
* @example
|
|
2779
|
-
* ```ts
|
|
2780
|
-
* const resolver = mergeResolvers(resolverTs, resolverTsLegacy)
|
|
2781
|
-
* // resolverTsLegacy methods override resolverTs where they overlap
|
|
2782
|
-
* ```
|
|
2777
|
+
* Returns a copy of `defaults` where each function in `userOverrides` is wrapped
|
|
2778
|
+
* so a `null`/`undefined` return falls back to the original. Non-function values
|
|
2779
|
+
* are assigned directly. All calls use the merged object as `this`.
|
|
2783
2780
|
*/
|
|
2784
|
-
function
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2781
|
+
function withFallback(defaults, userOverrides) {
|
|
2782
|
+
const merged = { ...defaults };
|
|
2783
|
+
for (const key of Object.keys(userOverrides)) {
|
|
2784
|
+
const userVal = userOverrides[key];
|
|
2785
|
+
const defaultVal = defaults[key];
|
|
2786
|
+
if (typeof userVal === "function" && typeof defaultVal === "function") merged[key] = (...args) => userVal.apply(merged, args) ?? defaultVal.apply(merged, args);
|
|
2787
|
+
else if (userVal !== void 0) merged[key] = userVal;
|
|
2788
|
+
}
|
|
2789
|
+
return merged;
|
|
2789
2790
|
}
|
|
2790
|
-
//#endregion
|
|
2791
|
-
//#region src/utils/getPreset.ts
|
|
2792
2791
|
/**
|
|
2793
|
-
* Resolves a named preset into
|
|
2792
|
+
* Resolves a named preset into a resolver, transformer, and generators.
|
|
2794
2793
|
*
|
|
2795
|
-
* -
|
|
2796
|
-
* -
|
|
2797
|
-
* - Concatenates preset transformers before user-supplied transformers.
|
|
2794
|
+
* - Selects the preset resolver; wraps it with user overrides using null/undefined fallback.
|
|
2795
|
+
* - Composes the preset's transformers into a single visitor; wraps it with the user transformer using null/undefined fallback.
|
|
2798
2796
|
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
2799
2797
|
*/
|
|
2800
2798
|
function getPreset(params) {
|
|
2801
|
-
const { preset: presetName, presets,
|
|
2802
|
-
const [defaultResolver, ...userResolvers] = resolvers;
|
|
2799
|
+
const { preset: presetName, presets, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = params;
|
|
2803
2800
|
const preset = presets[presetName];
|
|
2804
|
-
const
|
|
2805
|
-
const
|
|
2801
|
+
const presetResolver = preset?.resolver ?? presets["default"].resolver;
|
|
2802
|
+
const resolver = userResolver ? withFallback(presetResolver, userResolver) : presetResolver;
|
|
2803
|
+
const presetTransformers = preset?.transformers ?? [];
|
|
2804
|
+
const presetTransformer = presetTransformers.length > 0 ? (0, _kubb_ast.composeTransformers)(...presetTransformers) : void 0;
|
|
2805
|
+
const transformer = presetTransformer && userTransformer ? withFallback(presetTransformer, userTransformer) : userTransformer ?? presetTransformer;
|
|
2806
2806
|
const presetGenerators = preset?.generators ?? [];
|
|
2807
|
-
const
|
|
2807
|
+
const defaultGenerators = presets["default"]?.generators ?? [];
|
|
2808
2808
|
return {
|
|
2809
2809
|
resolver,
|
|
2810
|
-
|
|
2811
|
-
generators: presetGenerators.length > 0 || userGenerators.length ? [...presetGenerators, ...userGenerators] :
|
|
2810
|
+
transformer,
|
|
2811
|
+
generators: presetGenerators.length > 0 || userGenerators.length > 0 ? [...presetGenerators, ...userGenerators] : defaultGenerators,
|
|
2812
2812
|
preset
|
|
2813
2813
|
};
|
|
2814
2814
|
}
|
|
@@ -2901,6 +2901,12 @@ exports.PluginDriver = PluginDriver;
|
|
|
2901
2901
|
exports.URLPath = URLPath;
|
|
2902
2902
|
exports.build = build;
|
|
2903
2903
|
exports.buildDefaultBanner = buildDefaultBanner;
|
|
2904
|
+
Object.defineProperty(exports, "composeTransformers", {
|
|
2905
|
+
enumerable: true,
|
|
2906
|
+
get: function() {
|
|
2907
|
+
return _kubb_ast.composeTransformers;
|
|
2908
|
+
}
|
|
2909
|
+
});
|
|
2904
2910
|
exports.createAdapter = createAdapter;
|
|
2905
2911
|
exports.createPlugin = createPlugin;
|
|
2906
2912
|
exports.createStorage = createStorage;
|
|
@@ -2933,7 +2939,6 @@ exports.isInputPath = isInputPath;
|
|
|
2933
2939
|
exports.linters = linters;
|
|
2934
2940
|
exports.logLevel = logLevel;
|
|
2935
2941
|
exports.memoryStorage = memoryStorage;
|
|
2936
|
-
exports.mergeResolvers = mergeResolvers;
|
|
2937
2942
|
exports.renderOperation = renderOperation;
|
|
2938
2943
|
exports.renderOperations = renderOperations;
|
|
2939
2944
|
exports.renderSchema = renderSchema;
|