@kubb/core 5.0.0-alpha.32 → 5.0.0-alpha.33
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-nm7tvGs9.d.ts → PluginDriver-BBi_41VF.d.ts} +16 -36
- package/dist/hooks.cjs +4 -7
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +4 -7
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +132 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +56 -5
- package/dist/index.js +132 -95
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/FileProcessor.ts +4 -3
- package/src/Kubb.ts +1 -1
- package/src/build.ts +0 -1
- package/src/defineGenerator.ts +4 -8
- package/src/defineParser.ts +4 -17
- package/src/hooks/useDriver.ts +2 -4
- package/src/hooks/useMode.ts +2 -4
- package/src/hooks/usePlugin.ts +2 -4
- package/src/index.ts +3 -1
- package/src/renderNode.tsx +11 -9
- package/src/types.ts +8 -8
- package/src/utils/getBarrelFiles.ts +0 -2
- package/src/utils/getFunctionParams.ts +247 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as FunctionParamsAST, A as Preset, B as Resolver, C as Plugin, D as PluginLifecycleHooks, E as PluginLifecycle, F as ResolveBannerContext, G as UserConfig, H as ResolverFileParams, I as ResolveNameParams, J as UserPlugin, K as UserGroup, L as ResolveOptionsContext, M as Printer, N as PrinterFactoryOptions, O as PluginParameter, P as PrinterPartial, Q as getBarrelFiles, R as ResolvePathOptions, S as Override, T as PluginFactoryOptions, U as ResolverPathParams, V as ResolverContext, W as SchemaHook, X as UserResolver, Y as UserPluginWithLifeCycle, Z as FileMetaBase, _ as LoggerContext, a as AdapterSource, at as defineParser, b as OperationsHook, c as Config, ct as mergeGenerators, d as GeneratorContext, dt as formatters, et as CLIOptions, f as Group, ft as linters, g as Logger, h as InputPath, i as AdapterFactoryOptions, it as Parser, j as Presets, k as PluginWithLifeCycle, l as DevtoolsOptions, lt as Storage, m as InputData, mt as AsyncEventEmitter, n as getMode, nt as defineConfig, o as BarrelType, ot as Generator, p as Include, pt as logLevel, q as UserLogger, r as Adapter, rt as KubbEvents, s as CompatibilityPreset, st as defineGenerator, t as PluginDriver, tt as ConfigInput, u as Exclude, ut as createStorage, v as LoggerOptions, w as PluginContext, x as Output, y as OperationHook, z as ResolvePathParams } from "./PluginDriver-BBi_41VF.js";
|
|
3
3
|
import { composeTransformers, definePrinter } from "@kubb/ast";
|
|
4
4
|
import { FileNode, InputNode, Node, Visitor } from "@kubb/ast/types";
|
|
5
5
|
|
|
@@ -33,7 +33,7 @@ type ObjectOptions = {
|
|
|
33
33
|
* Supported identifier casing strategies for path parameters.
|
|
34
34
|
*/
|
|
35
35
|
type PathCasing = 'camelcase';
|
|
36
|
-
type Options = {
|
|
36
|
+
type Options$1 = {
|
|
37
37
|
/**
|
|
38
38
|
* Casing strategy applied to path parameter names.
|
|
39
39
|
* @default undefined (original identifier preserved)
|
|
@@ -54,7 +54,7 @@ declare class URLPath {
|
|
|
54
54
|
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
55
55
|
*/
|
|
56
56
|
path: string;
|
|
57
|
-
constructor(path: string, options?: Options);
|
|
57
|
+
constructor(path: string, options?: Options$1);
|
|
58
58
|
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
@@ -182,7 +182,6 @@ type SetupResult = {
|
|
|
182
182
|
*
|
|
183
183
|
* - Validates the input path (when applicable).
|
|
184
184
|
* - Applies config defaults (`root`, `output.*`, `devtools`).
|
|
185
|
-
* - Creates the Fabric instance and wires storage, format, and lint hooks.
|
|
186
185
|
* - Runs the adapter (if configured) to produce the universal `InputNode`.
|
|
187
186
|
* When no adapter is supplied and `@kubb/adapter-oas` is installed as an
|
|
188
187
|
*
|
|
@@ -612,6 +611,58 @@ declare function detectFormatter(): Promise<Formatter | null>;
|
|
|
612
611
|
*/
|
|
613
612
|
declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
|
|
614
613
|
//#endregion
|
|
614
|
+
//#region src/utils/getFunctionParams.d.ts
|
|
615
|
+
type Param = {
|
|
616
|
+
/**
|
|
617
|
+
* `object` will return the pathParams as an object.
|
|
618
|
+
*
|
|
619
|
+
* `inline` will return the pathParams as comma separated params.
|
|
620
|
+
* @default `'inline'`
|
|
621
|
+
* @private
|
|
622
|
+
*/
|
|
623
|
+
mode?: 'object' | 'inline' | 'inlineSpread';
|
|
624
|
+
type?: 'string' | 'number' | (string & {});
|
|
625
|
+
optional?: boolean;
|
|
626
|
+
/**
|
|
627
|
+
* @example test = "default"
|
|
628
|
+
*/
|
|
629
|
+
default?: string;
|
|
630
|
+
/**
|
|
631
|
+
* Used for no TypeScript(with mode object)
|
|
632
|
+
* @example test: "default"
|
|
633
|
+
*/
|
|
634
|
+
value?: string;
|
|
635
|
+
children?: Params;
|
|
636
|
+
};
|
|
637
|
+
type Params = Record<string, Param | undefined>;
|
|
638
|
+
type Options = {
|
|
639
|
+
type: 'constructor' | 'call' | 'object' | 'objectValue';
|
|
640
|
+
transformName?: (name: string) => string;
|
|
641
|
+
transformType?: (type: string) => string;
|
|
642
|
+
};
|
|
643
|
+
declare function getFunctionParams(params: Params, options: Options): string;
|
|
644
|
+
/**
|
|
645
|
+
* @deprecated use @kubb/ast
|
|
646
|
+
*/
|
|
647
|
+
declare function createFunctionParams(params: Params): Params;
|
|
648
|
+
/**
|
|
649
|
+
* @deprecated use @kubb/ast
|
|
650
|
+
*/
|
|
651
|
+
declare class FunctionParams {
|
|
652
|
+
#private;
|
|
653
|
+
static factory(params: Params): FunctionParams;
|
|
654
|
+
constructor(params: Params);
|
|
655
|
+
get params(): Params;
|
|
656
|
+
get flatParams(): Params;
|
|
657
|
+
toCall({
|
|
658
|
+
transformName,
|
|
659
|
+
transformType
|
|
660
|
+
}?: Pick<Options, 'transformName' | 'transformType'>): string;
|
|
661
|
+
toObject(): string;
|
|
662
|
+
toObjectValue(): string;
|
|
663
|
+
toConstructor(): string;
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
615
666
|
//#region src/utils/getPreset.d.ts
|
|
616
667
|
type GetPresetParams<TResolver extends Resolver> = {
|
|
617
668
|
preset: CompatibilityPreset;
|
|
@@ -690,5 +741,5 @@ type DependencyVersion = string;
|
|
|
690
741
|
*/
|
|
691
742
|
declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
|
|
692
743
|
//#endregion
|
|
693
|
-
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, CLIOptions, CompatibilityPreset, Config, ConfigInput, DevtoolsOptions, Exclude, FileMetaBase, FunctionParams, FunctionParamsAST, Generator, GeneratorContext, Group, Include, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, OperationHook, OperationsHook, Output, Override, Parser, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, PrinterPartial, ResolveBannerContext, ResolveNameParams, ResolveOptionsContext, ResolvePathOptions, ResolvePathParams, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, SchemaHook, Storage, URLPath, UserConfig, UserGroup, UserLogger,
|
|
744
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, CLIOptions, CompatibilityPreset, Config, ConfigInput, DevtoolsOptions, Exclude, FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, GeneratorContext, Group, Include, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, OperationHook, OperationsHook, Output, Override, type Param, type Params, Parser, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, PrinterPartial, ResolveBannerContext, ResolveNameParams, ResolveOptionsContext, ResolvePathOptions, ResolvePathParams, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, SchemaHook, Storage, URLPath, UserConfig, UserGroup, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, buildDefaultBanner, composeTransformers, createAdapter, createFunctionParams, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, defineParser, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getFunctionParams, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeGenerators, safeBuild, satisfiesDependency, setup };
|
|
694
745
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import { EventEmitter } from "node:events";
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import path, { basename, dirname, extname, join, posix, resolve } from "node:path";
|
|
6
|
-
import { composeTransformers, composeTransformers as composeTransformers$1, createExport, createFile, createSource, definePrinter, isOperationNode, isSchemaNode, transform, walk } from "@kubb/ast";
|
|
6
|
+
import { composeTransformers, composeTransformers as composeTransformers$1, createExport, createFile, createSource, definePrinter, extractStringsFromNodes, isOperationNode, isSchemaNode, transform, walk } from "@kubb/ast";
|
|
7
7
|
import { performance } from "node:perf_hooks";
|
|
8
8
|
import { deflateSync } from "fflate";
|
|
9
9
|
import { x } from "tinyexec";
|
|
10
|
-
import {
|
|
11
|
-
import { jsx } from "@kubb/
|
|
10
|
+
import { createRenderer } from "@kubb/renderer-jsx";
|
|
11
|
+
import { Fragment, jsx } from "@kubb/renderer-jsx/jsx-runtime";
|
|
12
12
|
import { version } from "node:process";
|
|
13
13
|
import { sortBy } from "remeda";
|
|
14
14
|
import * as pkg from "empathic/package";
|
|
@@ -851,7 +851,7 @@ function validateConcurrency(concurrency) {
|
|
|
851
851
|
//#endregion
|
|
852
852
|
//#region src/FileProcessor.ts
|
|
853
853
|
function joinSources(file) {
|
|
854
|
-
return file.sources.map((item) => item.
|
|
854
|
+
return file.sources.map((item) => extractStringsFromNodes(item.nodes)).filter(Boolean).join("\n\n");
|
|
855
855
|
}
|
|
856
856
|
/**
|
|
857
857
|
* Converts a single file to a string using the registered parsers.
|
|
@@ -1504,7 +1504,7 @@ var PluginDriver = class {
|
|
|
1504
1504
|
/**
|
|
1505
1505
|
* Handles the return value of a plugin AST hook or generator method.
|
|
1506
1506
|
*
|
|
1507
|
-
* - React element → rendered via
|
|
1507
|
+
* - React element → rendered via renderer-jsx, files stored in `driver.fileManager`
|
|
1508
1508
|
* - `Array<FileNode>` → upserted directly into `driver.fileManager`
|
|
1509
1509
|
* - `void` / `null` / `undefined` → no-op (plugin handled it via `this.upsertFile`)
|
|
1510
1510
|
*/
|
|
@@ -1514,10 +1514,10 @@ async function applyHookResult(result, driver) {
|
|
|
1514
1514
|
driver.fileManager.upsert(...result);
|
|
1515
1515
|
return;
|
|
1516
1516
|
}
|
|
1517
|
-
const
|
|
1518
|
-
await
|
|
1519
|
-
driver.fileManager.upsert(...
|
|
1520
|
-
|
|
1517
|
+
const renderer = createRenderer();
|
|
1518
|
+
await renderer.render(/* @__PURE__ */ jsx(Fragment, { children: result }));
|
|
1519
|
+
driver.fileManager.upsert(...renderer.files);
|
|
1520
|
+
renderer.unmount();
|
|
1521
1521
|
}
|
|
1522
1522
|
//#endregion
|
|
1523
1523
|
//#region src/createStorage.ts
|
|
@@ -1617,7 +1617,7 @@ const fsStorage = createStorage(() => ({
|
|
|
1617
1617
|
}));
|
|
1618
1618
|
//#endregion
|
|
1619
1619
|
//#region package.json
|
|
1620
|
-
var version$1 = "5.0.0-alpha.
|
|
1620
|
+
var version$1 = "5.0.0-alpha.33";
|
|
1621
1621
|
//#endregion
|
|
1622
1622
|
//#region src/utils/diagnostics.ts
|
|
1623
1623
|
/**
|
|
@@ -1821,7 +1821,6 @@ function getBarrelFilesByRoot(root, files) {
|
|
|
1821
1821
|
barrelFile.sources.push(createSource({
|
|
1822
1822
|
name: source.name,
|
|
1823
1823
|
isTypeOnly: source.isTypeOnly,
|
|
1824
|
-
value: "",
|
|
1825
1824
|
isExportable: false,
|
|
1826
1825
|
isIndexable: false
|
|
1827
1826
|
}));
|
|
@@ -1885,7 +1884,6 @@ function isInputPath(config) {
|
|
|
1885
1884
|
*
|
|
1886
1885
|
* - Validates the input path (when applicable).
|
|
1887
1886
|
* - Applies config defaults (`root`, `output.*`, `devtools`).
|
|
1888
|
-
* - Creates the Fabric instance and wires storage, format, and lint hooks.
|
|
1889
1887
|
* - Runs the adapter (if configured) to produce the universal `InputNode`.
|
|
1890
1888
|
* When no adapter is supplied and `@kubb/adapter-oas` is installed as an
|
|
1891
1889
|
*
|
|
@@ -2399,17 +2397,14 @@ function defineLogger(logger) {
|
|
|
2399
2397
|
* name: 'json',
|
|
2400
2398
|
* extNames: ['.json'],
|
|
2401
2399
|
* parse(file) {
|
|
2402
|
-
*
|
|
2400
|
+
* const { extractStringsFromNodes } = await import('@kubb/ast')
|
|
2401
|
+
* return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
|
|
2403
2402
|
* },
|
|
2404
2403
|
* })
|
|
2405
2404
|
* ```
|
|
2406
2405
|
*/
|
|
2407
2406
|
function defineParser(parser) {
|
|
2408
|
-
return
|
|
2409
|
-
install() {},
|
|
2410
|
-
type: "parser",
|
|
2411
|
-
...parser
|
|
2412
|
-
};
|
|
2407
|
+
return parser;
|
|
2413
2408
|
}
|
|
2414
2409
|
//#endregion
|
|
2415
2410
|
//#region src/definePresets.ts
|
|
@@ -2813,82 +2808,6 @@ const memoryStorage = createStorage(() => {
|
|
|
2813
2808
|
};
|
|
2814
2809
|
});
|
|
2815
2810
|
//#endregion
|
|
2816
|
-
//#region src/utils/FunctionParams.ts
|
|
2817
|
-
/**
|
|
2818
|
-
* @deprecated use ast package instead
|
|
2819
|
-
*/
|
|
2820
|
-
var FunctionParams = class FunctionParams {
|
|
2821
|
-
#items = [];
|
|
2822
|
-
get items() {
|
|
2823
|
-
return this.#items.flat();
|
|
2824
|
-
}
|
|
2825
|
-
add(item) {
|
|
2826
|
-
if (!item) return this;
|
|
2827
|
-
if (Array.isArray(item)) {
|
|
2828
|
-
item.filter((x) => x !== void 0).forEach((it) => {
|
|
2829
|
-
this.#items.push(it);
|
|
2830
|
-
});
|
|
2831
|
-
return this;
|
|
2832
|
-
}
|
|
2833
|
-
this.#items.push(item);
|
|
2834
|
-
return this;
|
|
2835
|
-
}
|
|
2836
|
-
static #orderItems(items) {
|
|
2837
|
-
return sortBy(items.filter(Boolean), [(item) => Array.isArray(item), "desc"], [(item) => !Array.isArray(item) && item.default !== void 0, "asc"], [(item) => Array.isArray(item) || (item.required ?? true), "desc"]);
|
|
2838
|
-
}
|
|
2839
|
-
static #addParams(acc, item) {
|
|
2840
|
-
const { enabled = true, name, type, required = true, ...rest } = item;
|
|
2841
|
-
if (!enabled) return acc;
|
|
2842
|
-
if (!name) {
|
|
2843
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
2844
|
-
return acc;
|
|
2845
|
-
}
|
|
2846
|
-
const parameterName = name.startsWith("{") ? name : camelCase(name);
|
|
2847
|
-
if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
2848
|
-
else acc.push(`${parameterName}?: ${type}`);
|
|
2849
|
-
else acc.push(`${parameterName}`);
|
|
2850
|
-
return acc;
|
|
2851
|
-
}
|
|
2852
|
-
static toObject(items) {
|
|
2853
|
-
let type = [];
|
|
2854
|
-
let name = [];
|
|
2855
|
-
const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
|
|
2856
|
-
const required = items.every((item) => item.required) ?? true;
|
|
2857
|
-
items.forEach((item) => {
|
|
2858
|
-
name = FunctionParams.#addParams(name, {
|
|
2859
|
-
...item,
|
|
2860
|
-
type: void 0
|
|
2861
|
-
});
|
|
2862
|
-
if (items.some((item) => item.type)) type = FunctionParams.#addParams(type, item);
|
|
2863
|
-
});
|
|
2864
|
-
return {
|
|
2865
|
-
name: `{ ${name.join(", ")} }`,
|
|
2866
|
-
type: type.length ? `{ ${type.join("; ")} }` : void 0,
|
|
2867
|
-
enabled,
|
|
2868
|
-
required
|
|
2869
|
-
};
|
|
2870
|
-
}
|
|
2871
|
-
toObject() {
|
|
2872
|
-
const items = FunctionParams.#orderItems(this.#items).flat();
|
|
2873
|
-
return FunctionParams.toObject(items);
|
|
2874
|
-
}
|
|
2875
|
-
static toString(items) {
|
|
2876
|
-
return FunctionParams.#orderItems(items).reduce((acc, item) => {
|
|
2877
|
-
if (Array.isArray(item)) {
|
|
2878
|
-
if (item.length <= 0) return acc;
|
|
2879
|
-
const subItems = FunctionParams.#orderItems(item);
|
|
2880
|
-
const objectItem = FunctionParams.toObject(subItems);
|
|
2881
|
-
return FunctionParams.#addParams(acc, objectItem);
|
|
2882
|
-
}
|
|
2883
|
-
return FunctionParams.#addParams(acc, item);
|
|
2884
|
-
}, []).join(", ");
|
|
2885
|
-
}
|
|
2886
|
-
toString() {
|
|
2887
|
-
const items = FunctionParams.#orderItems(this.#items);
|
|
2888
|
-
return FunctionParams.toString(items);
|
|
2889
|
-
}
|
|
2890
|
-
};
|
|
2891
|
-
//#endregion
|
|
2892
2811
|
//#region src/utils/formatters.ts
|
|
2893
2812
|
/**
|
|
2894
2813
|
* Returns `true` when the given formatter is installed and callable.
|
|
@@ -2944,6 +2863,124 @@ async function getConfigs(config, args) {
|
|
|
2944
2863
|
}));
|
|
2945
2864
|
}
|
|
2946
2865
|
//#endregion
|
|
2866
|
+
//#region src/utils/getFunctionParams.ts
|
|
2867
|
+
function order(items) {
|
|
2868
|
+
return sortBy(items.filter(Boolean), ([_key, item]) => {
|
|
2869
|
+
if (item?.children) return 0;
|
|
2870
|
+
if (item?.optional) return 1;
|
|
2871
|
+
if (item?.default) return 2;
|
|
2872
|
+
return 0;
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
function parseChild(key, item, options) {
|
|
2876
|
+
const entries = order(Object.entries(item.children));
|
|
2877
|
+
const types = [];
|
|
2878
|
+
const names = [];
|
|
2879
|
+
const optional = entries.every(([_key, item]) => item?.optional || !!item?.default);
|
|
2880
|
+
entries.forEach(([key, entryItem]) => {
|
|
2881
|
+
if (entryItem) {
|
|
2882
|
+
const name = parseItem(key, {
|
|
2883
|
+
...entryItem,
|
|
2884
|
+
type: void 0
|
|
2885
|
+
}, options);
|
|
2886
|
+
if (entryItem.children) {
|
|
2887
|
+
const subTypes = Object.entries(entryItem.children).map(([key]) => {
|
|
2888
|
+
return key;
|
|
2889
|
+
}).join(", ");
|
|
2890
|
+
if (subTypes) names.push(`${name}: { ${subTypes} }`);
|
|
2891
|
+
else names.push(name);
|
|
2892
|
+
} else if (options.type === "call" && options.transformName) names.push(`${key}: ${name}`);
|
|
2893
|
+
else names.push(name);
|
|
2894
|
+
if (entries.some(([_key, item]) => item?.type)) types.push(parseItem(key, {
|
|
2895
|
+
...entryItem,
|
|
2896
|
+
default: void 0
|
|
2897
|
+
}, options));
|
|
2898
|
+
}
|
|
2899
|
+
});
|
|
2900
|
+
const name = item.mode === "inline" ? key : names.length ? `{ ${names.join(", ")} }` : void 0;
|
|
2901
|
+
const type = item.type ? item.type : types.length ? `{ ${types.join("; ")} }` : void 0;
|
|
2902
|
+
if (!name) return null;
|
|
2903
|
+
return parseItem(name, {
|
|
2904
|
+
type,
|
|
2905
|
+
default: item.default,
|
|
2906
|
+
optional: !item.default ? optional : void 0
|
|
2907
|
+
}, options);
|
|
2908
|
+
}
|
|
2909
|
+
function parseItem(name, item, options) {
|
|
2910
|
+
const acc = [];
|
|
2911
|
+
const transformedName = options.transformName ? options.transformName(name) : name;
|
|
2912
|
+
const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type;
|
|
2913
|
+
if (options.type === "object") return transformedName;
|
|
2914
|
+
if (options.type === "objectValue") return item.value ? `${transformedName}: ${item.value}` : transformedName;
|
|
2915
|
+
if (item.type && options.type === "constructor") if (item.optional) if (transformedName.startsWith("{")) acc.push(`${transformedName}: ${transformedType} = {}`);
|
|
2916
|
+
else acc.push(`${transformedName}?: ${transformedType}`);
|
|
2917
|
+
else acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ""}`);
|
|
2918
|
+
else if (item.default && options.type === "constructor") acc.push(`${transformedName} = ${item.default}`);
|
|
2919
|
+
else if (item.value) acc.push(`${transformedName} : ${item.value}`);
|
|
2920
|
+
else if (item.mode === "inlineSpread") acc.push(`... ${transformedName}`);
|
|
2921
|
+
else acc.push(transformedName);
|
|
2922
|
+
return acc[0];
|
|
2923
|
+
}
|
|
2924
|
+
function getFunctionParams(params, options) {
|
|
2925
|
+
return order(Object.entries(params)).reduce((acc, [key, item]) => {
|
|
2926
|
+
if (!item) return acc;
|
|
2927
|
+
if (item.children) {
|
|
2928
|
+
if (Object.keys(item.children).length === 0) return acc;
|
|
2929
|
+
if (item.mode === "inlineSpread") return [...acc, getFunctionParams(item.children, options)];
|
|
2930
|
+
const parsedItem = parseChild(key, item, options);
|
|
2931
|
+
if (!parsedItem) return acc;
|
|
2932
|
+
return [...acc, parsedItem];
|
|
2933
|
+
}
|
|
2934
|
+
const parsedItem = parseItem(key, item, options);
|
|
2935
|
+
return [...acc, parsedItem];
|
|
2936
|
+
}, []).join(", ");
|
|
2937
|
+
}
|
|
2938
|
+
/**
|
|
2939
|
+
* @deprecated use @kubb/ast
|
|
2940
|
+
*/
|
|
2941
|
+
function createFunctionParams(params) {
|
|
2942
|
+
return params;
|
|
2943
|
+
}
|
|
2944
|
+
/**
|
|
2945
|
+
* @deprecated use @kubb/ast
|
|
2946
|
+
*/
|
|
2947
|
+
var FunctionParams = class FunctionParams {
|
|
2948
|
+
#params;
|
|
2949
|
+
static factory(params) {
|
|
2950
|
+
return new FunctionParams(params);
|
|
2951
|
+
}
|
|
2952
|
+
constructor(params) {
|
|
2953
|
+
this.#params = params;
|
|
2954
|
+
}
|
|
2955
|
+
get params() {
|
|
2956
|
+
return this.#params;
|
|
2957
|
+
}
|
|
2958
|
+
get flatParams() {
|
|
2959
|
+
const flatter = (acc, [key, item]) => {
|
|
2960
|
+
if (item?.children) return Object.entries(item.children).reduce(flatter, acc);
|
|
2961
|
+
if (item) acc[key] = item;
|
|
2962
|
+
return acc;
|
|
2963
|
+
};
|
|
2964
|
+
return Object.entries(this.#params).reduce(flatter, {});
|
|
2965
|
+
}
|
|
2966
|
+
toCall({ transformName, transformType } = {}) {
|
|
2967
|
+
return getFunctionParams(this.#params, {
|
|
2968
|
+
type: "call",
|
|
2969
|
+
transformName,
|
|
2970
|
+
transformType
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
toObject() {
|
|
2974
|
+
return getFunctionParams(this.#params, { type: "object" });
|
|
2975
|
+
}
|
|
2976
|
+
toObjectValue() {
|
|
2977
|
+
return getFunctionParams(this.#params, { type: "objectValue" });
|
|
2978
|
+
}
|
|
2979
|
+
toConstructor() {
|
|
2980
|
+
return getFunctionParams(this.#params, { type: "constructor" });
|
|
2981
|
+
}
|
|
2982
|
+
};
|
|
2983
|
+
//#endregion
|
|
2947
2984
|
//#region src/utils/getPreset.ts
|
|
2948
2985
|
/**
|
|
2949
2986
|
* Returns a copy of `defaults` where each function in `userOverrides` is wrapped
|
|
@@ -3067,6 +3104,6 @@ function satisfiesDependency(dependency, version, cwd) {
|
|
|
3067
3104
|
return satisfies(semVer, version);
|
|
3068
3105
|
}
|
|
3069
3106
|
//#endregion
|
|
3070
|
-
export { AsyncEventEmitter, FunctionParams, PluginDriver, URLPath, build, build as default, buildDefaultBanner, composeTransformers, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, defineParser, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeGenerators, safeBuild, satisfiesDependency, setup };
|
|
3107
|
+
export { AsyncEventEmitter, FunctionParams, PluginDriver, URLPath, build, build as default, buildDefaultBanner, composeTransformers, createAdapter, createFunctionParams, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, defineParser, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getFunctionParams, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeGenerators, safeBuild, satisfiesDependency, setup };
|
|
3071
3108
|
|
|
3072
3109
|
//# sourceMappingURL=index.js.map
|