@kubb/core 5.0.0-alpha.20 → 5.0.0-alpha.21
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-BkSenc-R.d.ts → PluginDriver-CEQPafXV.d.ts} +271 -104
- package/dist/hooks.cjs +7 -94
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -79
- package/dist/hooks.js +6 -91
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +313 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +260 -24
- package/dist/index.js +308 -33
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/defineBuilder.ts +26 -0
- package/src/defineGenerator.ts +3 -0
- package/src/definePreset.ts +9 -5
- package/src/defineResolver.ts +333 -16
- package/src/hooks/index.ts +1 -2
- package/src/hooks/{usePluginDriver.ts → useDriver.ts} +1 -4
- package/src/hooks/useMode.ts +1 -1
- package/src/hooks/usePlugin.ts +1 -1
- package/src/index.ts +10 -1
- package/src/renderNode.tsx +10 -13
- package/src/types.ts +204 -16
- package/src/utils/getBarrelFiles.ts +1 -1
- package/src/utils/getPreset.ts +17 -6
- package/src/hooks/useKubb.ts +0 -160
package/dist/hooks.d.ts
CHANGED
|
@@ -1,94 +1,21 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
3
|
-
import { RootNode } from "@kubb/ast/types";
|
|
2
|
+
import { C as PluginFactoryOptions, t as PluginDriver, x as Plugin } from "./PluginDriver-CEQPafXV.js";
|
|
4
3
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
5
4
|
|
|
6
|
-
//#region src/hooks/
|
|
7
|
-
|
|
8
|
-
pluginName?: string;
|
|
9
|
-
group?: {
|
|
10
|
-
tag?: string;
|
|
11
|
-
path?: string;
|
|
12
|
-
};
|
|
13
|
-
type?: ResolveNameParams['type'];
|
|
14
|
-
};
|
|
15
|
-
type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
16
|
-
plugin: Plugin<TOptions>;
|
|
17
|
-
mode: KubbFile.Mode;
|
|
18
|
-
config: Config;
|
|
19
|
-
/**
|
|
20
|
-
* Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.
|
|
21
|
-
*/
|
|
22
|
-
getPluginByName: (pluginName?: string) => Plugin | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Resolves a file reference, defaulting `pluginName` to the current plugin.
|
|
25
|
-
*/
|
|
26
|
-
getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & {
|
|
27
|
-
pluginName?: string;
|
|
28
|
-
}) => KubbFile.File<{
|
|
29
|
-
pluginName: string;
|
|
30
|
-
}>;
|
|
31
|
-
/**
|
|
32
|
-
* Resolves a name, defaulting `pluginName` to the current plugin.
|
|
33
|
-
* @deprecated user `resolver` from options instead
|
|
34
|
-
*/
|
|
35
|
-
resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & {
|
|
36
|
-
pluginName?: string;
|
|
37
|
-
}) => string;
|
|
38
|
-
/**
|
|
39
|
-
* Resolves a path, defaulting `pluginName` to the current plugin.
|
|
40
|
-
*/
|
|
41
|
-
resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & {
|
|
42
|
-
pluginName?: string;
|
|
43
|
-
}) => KubbFile.Path;
|
|
44
|
-
/**
|
|
45
|
-
* Resolves the banner using the plugin's `output.banner` option.
|
|
46
|
-
* Falls back to the default "Generated by Kubb" banner when `output.banner` is unset.
|
|
47
|
-
* When `output.banner` is a function and no node is provided, returns the default banner.
|
|
48
|
-
*/
|
|
49
|
-
resolveBanner: (node?: RootNode) => string | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Resolves the footer using the plugin's `output.footer` option.
|
|
52
|
-
* Returns `undefined` when no footer is configured.
|
|
53
|
-
* When `output.footer` is a function and no node is provided, returns `undefined`.
|
|
54
|
-
*/
|
|
55
|
-
resolveFooter: (node?: RootNode) => string | undefined;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* React-Fabric hook that exposes the current plugin context inside a generator component.
|
|
59
|
-
*
|
|
60
|
-
* Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers
|
|
61
|
-
* (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that
|
|
62
|
-
* all default to the current plugin when no explicit `pluginName` is provided.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* function Operation({ node }: OperationProps) {
|
|
67
|
-
* const { config, resolvePath } = useKubb()
|
|
68
|
-
* const filePath = resolvePath({ baseName: node.operationId })
|
|
69
|
-
* return <File path={filePath}>...</File>
|
|
70
|
-
* }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions>;
|
|
5
|
+
//#region src/hooks/useDriver.d.ts
|
|
6
|
+
declare function useDriver(): PluginDriver;
|
|
74
7
|
//#endregion
|
|
75
8
|
//#region src/hooks/useMode.d.ts
|
|
76
9
|
/**
|
|
77
|
-
* @deprecated use `
|
|
10
|
+
* @deprecated use `mode` from the generator component props instead
|
|
78
11
|
*/
|
|
79
12
|
declare function useMode(): KubbFile.Mode;
|
|
80
13
|
//#endregion
|
|
81
14
|
//#region src/hooks/usePlugin.d.ts
|
|
82
15
|
/**
|
|
83
|
-
* @deprecated use
|
|
16
|
+
* @deprecated use `plugin` from the generator component props instead
|
|
84
17
|
*/
|
|
85
18
|
declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
|
|
86
19
|
//#endregion
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @deprecated use `useKubb` instead
|
|
90
|
-
*/
|
|
91
|
-
declare function usePluginDriver(): PluginDriver;
|
|
92
|
-
//#endregion
|
|
93
|
-
export { useKubb, useMode, usePlugin, usePluginDriver };
|
|
20
|
+
export { useDriver, useMode, usePlugin };
|
|
94
21
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.js
CHANGED
|
@@ -1,90 +1,14 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import { useFabric } from "@kubb/react-fabric";
|
|
4
|
-
//#region src/hooks/
|
|
5
|
-
|
|
6
|
-
* Generates the default "Generated by Kubb" banner from node metadata.
|
|
7
|
-
*/
|
|
8
|
-
function buildDefaultBanner({ title, description, version, config }) {
|
|
9
|
-
try {
|
|
10
|
-
let source = "";
|
|
11
|
-
if (Array.isArray(config.input)) {
|
|
12
|
-
const first = config.input[0];
|
|
13
|
-
if (first && "path" in first) source = path.basename(first.path);
|
|
14
|
-
} else if ("path" in config.input) source = path.basename(config.input.path);
|
|
15
|
-
else if ("data" in config.input) source = "text content";
|
|
16
|
-
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
17
|
-
if (config.output.defaultBanner === "simple") {
|
|
18
|
-
banner += "*/\n";
|
|
19
|
-
return banner;
|
|
20
|
-
}
|
|
21
|
-
if (source) banner += `* Source: ${source}\n`;
|
|
22
|
-
if (title) banner += `* Title: ${title}\n`;
|
|
23
|
-
if (description) {
|
|
24
|
-
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
25
|
-
banner += `* Description: ${formattedDescription}\n`;
|
|
26
|
-
}
|
|
27
|
-
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
28
|
-
banner += "*/\n";
|
|
29
|
-
return banner;
|
|
30
|
-
} catch (_error) {
|
|
31
|
-
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* React-Fabric hook that exposes the current plugin context inside a generator component.
|
|
36
|
-
*
|
|
37
|
-
* Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers
|
|
38
|
-
* (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that
|
|
39
|
-
* all default to the current plugin when no explicit `pluginName` is provided.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* function Operation({ node }: OperationProps) {
|
|
44
|
-
* const { config, resolvePath } = useKubb()
|
|
45
|
-
* const filePath = resolvePath({ baseName: node.operationId })
|
|
46
|
-
* return <File path={filePath}>...</File>
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
function useKubb() {
|
|
3
|
+
//#region src/hooks/useDriver.ts
|
|
4
|
+
function useDriver() {
|
|
51
5
|
const { meta } = useFabric();
|
|
52
|
-
|
|
53
|
-
const defaultPluginName = meta.plugin.name;
|
|
54
|
-
const output = meta.plugin.options?.output;
|
|
55
|
-
return {
|
|
56
|
-
plugin: meta.plugin,
|
|
57
|
-
mode: meta.mode,
|
|
58
|
-
config,
|
|
59
|
-
getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),
|
|
60
|
-
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, {
|
|
61
|
-
pluginName,
|
|
62
|
-
...rest
|
|
63
|
-
}),
|
|
64
|
-
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, {
|
|
65
|
-
pluginName,
|
|
66
|
-
...rest
|
|
67
|
-
}),
|
|
68
|
-
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, {
|
|
69
|
-
pluginName,
|
|
70
|
-
...rest
|
|
71
|
-
}),
|
|
72
|
-
resolveBanner: (node) => {
|
|
73
|
-
if (typeof output?.banner === "function") return node ? output.banner(node) : buildDefaultBanner({ config });
|
|
74
|
-
if (typeof output?.banner === "string") return output.banner;
|
|
75
|
-
if (config.output.defaultBanner === false) return;
|
|
76
|
-
return buildDefaultBanner({ config });
|
|
77
|
-
},
|
|
78
|
-
resolveFooter: (node) => {
|
|
79
|
-
if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
|
|
80
|
-
if (typeof output?.footer === "string") return output.footer;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
6
|
+
return meta.driver;
|
|
83
7
|
}
|
|
84
8
|
//#endregion
|
|
85
9
|
//#region src/hooks/useMode.ts
|
|
86
10
|
/**
|
|
87
|
-
* @deprecated use `
|
|
11
|
+
* @deprecated use `mode` from the generator component props instead
|
|
88
12
|
*/
|
|
89
13
|
function useMode() {
|
|
90
14
|
const { meta } = useFabric();
|
|
@@ -93,22 +17,13 @@ function useMode() {
|
|
|
93
17
|
//#endregion
|
|
94
18
|
//#region src/hooks/usePlugin.ts
|
|
95
19
|
/**
|
|
96
|
-
* @deprecated use
|
|
20
|
+
* @deprecated use `plugin` from the generator component props instead
|
|
97
21
|
*/
|
|
98
22
|
function usePlugin() {
|
|
99
23
|
const { meta } = useFabric();
|
|
100
24
|
return meta.plugin;
|
|
101
25
|
}
|
|
102
26
|
//#endregion
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @deprecated use `useKubb` instead
|
|
106
|
-
*/
|
|
107
|
-
function usePluginDriver() {
|
|
108
|
-
const { meta } = useFabric();
|
|
109
|
-
return meta.driver;
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
|
-
export { useKubb, useMode, usePlugin, usePluginDriver };
|
|
27
|
+
export { useDriver, useMode, usePlugin };
|
|
113
28
|
|
|
114
29
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useDriver.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts"],"sourcesContent":["import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\nexport function useDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `mode` from the generator component props instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use `plugin` from the generator component props instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n"],"mappings":";;;AAGA,SAAgB,YAA0B;CACxC,MAAM,EAAE,SAAS,WAAqC;AAEtD,QAAO,KAAK;;;;;;;ACAd,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,WAAoC;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,WAAyC;AAE1D,QAAO,KAAK"}
|