@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/hooks.d.ts CHANGED
@@ -1,94 +1,21 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { b as PluginFactoryOptions, j as ResolvePathParams, k as ResolveNameParams, l as Config, n as PluginDriver, t as GetFileOptions, v as Plugin } from "./PluginDriver-BkSenc-R.js";
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/useKubb.d.ts
7
- type ResolvePathOptions = {
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 `useKubb` instead
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 useKubb instead
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
- //#region src/hooks/usePluginDriver.d.ts
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/useKubb.ts
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
- const config = meta.driver.config;
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 `useKubb` instead
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 useKubb instead
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
- //#region src/hooks/usePluginDriver.ts
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/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n * @deprecated user `resolver` from options instead\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner using the plugin's `output.banner` option.\n * Falls back to the default \"Generated by Kubb\" banner when `output.banner` is unset.\n * When `output.banner` is a function and no node is provided, returns the default banner.\n */\n resolveBanner: (node?: RootNode) => string | undefined\n /**\n * Resolves the footer using the plugin's `output.footer` option.\n * Returns `undefined` when no footer is configured.\n * When `output.footer` is a function and no node is provided, returns `undefined`.\n */\n resolveFooter: (node?: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\n/**\n * React-Fabric hook that exposes the current plugin context inside a generator component.\n *\n * Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers\n * (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that\n * all default to the current plugin when no explicit `pluginName` is provided.\n *\n * @example\n * ```ts\n * function Operation({ node }: OperationProps) {\n * const { config, resolvePath } = useKubb()\n * const filePath = resolvePath({ baseName: node.operationId })\n * return <File path={filePath}>...</File>\n * }\n * ```\n */\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node?: RootNode) => {\n if (typeof output?.banner === 'function') {\n return node ? output.banner(node) : buildDefaultBanner({ config })\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n if (config.output.defaultBanner === false) {\n return undefined\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node?: RootNode) => {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` 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 useKubb 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","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\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G,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,gBAAgB,SAAoB;AAClC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,OAAO,KAAK,GAAG,mBAAmB,EAAE,QAAQ,CAAC;AAEpE,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;AAEhB,OAAI,OAAO,OAAO,kBAAkB,MAClC;AAEF,UAAO,mBAAmB,EAAE,QAAQ,CAAC;;EAEvC,gBAAgB,SAAoB;AAClC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,OAAO,KAAK,GAAG,KAAA;AAEtC,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;;EAInB;;;;;;;ACxJH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,WAAoC;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,WAAyC;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,SAAS,WAAqC;AAEtD,QAAO,KAAK"}
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"}