@kubb/core 5.0.0-alpha.17 → 5.0.0-alpha.18
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-CNKhDf-w.d.ts → PluginDriver-BRTrzfiD.d.ts} +135 -27
- package/dist/hooks.cjs +16 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +17 -1
- package/dist/hooks.js +16 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +396 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +246 -19
- package/dist/index.js +394 -273
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/Kubb.ts +15 -5
- package/src/build.ts +42 -0
- package/src/config.ts +9 -8
- package/src/constants.ts +43 -0
- package/src/hooks/useKubb.ts +16 -0
- package/src/index.ts +1 -0
- package/src/types.ts +9 -3
- package/src/utils/TreeNode.ts +23 -0
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/executeStrategies.ts +16 -3
- package/src/utils/formatters.ts +9 -20
- package/src/utils/getBarrelFiles.ts +8 -0
- package/src/utils/getConfigs.ts +5 -1
- package/src/utils/getPreset.ts +7 -0
- package/src/utils/linters.ts +22 -2
- package/src/utils/packageJSON.ts +21 -6
|
@@ -1,31 +1,101 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { EventEmitter } from "node:events";
|
|
3
2
|
import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
4
3
|
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
5
4
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
5
|
|
|
7
|
-
//#region ../../internals/utils/
|
|
6
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
8
7
|
/**
|
|
9
|
-
* A
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
* A function that can be registered as an event listener, synchronous or async.
|
|
9
|
+
*/
|
|
10
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
13
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
18
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
19
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
23
|
+
#private;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
26
|
+
* @default 10
|
|
27
|
+
*/
|
|
28
|
+
constructor(maxListener?: number);
|
|
29
|
+
/**
|
|
30
|
+
* Emits `eventName` and awaits all registered listeners in parallel.
|
|
31
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* await emitter.emit('build', 'petstore')
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Registers a persistent listener for `eventName`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
57
|
+
/**
|
|
58
|
+
* Removes a previously registered listener.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* emitter.off('build', handler)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Removes all listeners from every event channel.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* emitter.removeAll()
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
removeAll(): void;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../../internals/utils/src/promise.d.ts
|
|
78
|
+
/** A value that may already be resolved or still pending.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* function load(id: string): PossiblePromise<string> {
|
|
83
|
+
* return cache.get(id) ?? fetchRemote(id)
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
26
88
|
//#endregion
|
|
27
89
|
//#region src/constants.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Base URL for the Kubb Studio web app.
|
|
92
|
+
*/
|
|
28
93
|
declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
|
|
94
|
+
/**
|
|
95
|
+
* Numeric log-level thresholds used internally to compare verbosity.
|
|
96
|
+
*
|
|
97
|
+
* Higher numbers are more verbose.
|
|
98
|
+
*/
|
|
29
99
|
declare const logLevel: {
|
|
30
100
|
readonly silent: number;
|
|
31
101
|
readonly error: 0;
|
|
@@ -34,6 +104,13 @@ declare const logLevel: {
|
|
|
34
104
|
readonly verbose: 4;
|
|
35
105
|
readonly debug: 5;
|
|
36
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* CLI command descriptors for each supported linter.
|
|
109
|
+
*
|
|
110
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
111
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
112
|
+
* the linter is not found.
|
|
113
|
+
*/
|
|
37
114
|
declare const linters: {
|
|
38
115
|
readonly eslint: {
|
|
39
116
|
readonly command: "eslint";
|
|
@@ -51,6 +128,13 @@ declare const linters: {
|
|
|
51
128
|
readonly errorMessage: "Oxlint not found";
|
|
52
129
|
};
|
|
53
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* CLI command descriptors for each supported code formatter.
|
|
133
|
+
*
|
|
134
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
135
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
136
|
+
* the formatter is not found.
|
|
137
|
+
*/
|
|
54
138
|
declare const formatters: {
|
|
55
139
|
readonly prettier: {
|
|
56
140
|
readonly command: "prettier";
|
|
@@ -288,10 +372,25 @@ interface KubbEvents {
|
|
|
288
372
|
* Contains processed count, total count, percentage, and file details.
|
|
289
373
|
*/
|
|
290
374
|
'file:processing:update': [{
|
|
291
|
-
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
375
|
+
/**
|
|
376
|
+
* Number of files processed so far.
|
|
377
|
+
*/
|
|
378
|
+
processed: number;
|
|
379
|
+
/**
|
|
380
|
+
* Total number of files to process.
|
|
381
|
+
*/
|
|
382
|
+
total: number;
|
|
383
|
+
/**
|
|
384
|
+
* Processing percentage (0–100).
|
|
385
|
+
*/
|
|
386
|
+
percentage: number;
|
|
387
|
+
/**
|
|
388
|
+
* Optional source identifier.
|
|
389
|
+
*/
|
|
390
|
+
source?: string;
|
|
391
|
+
/**
|
|
392
|
+
* The file being processed.
|
|
393
|
+
*/
|
|
295
394
|
file: KubbFile.ResolvedFile;
|
|
296
395
|
/**
|
|
297
396
|
* Kubb configuration (not present in Fabric).
|
|
@@ -511,8 +610,17 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
511
610
|
* ```
|
|
512
611
|
*/
|
|
513
612
|
type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
514
|
-
/**
|
|
515
|
-
|
|
613
|
+
/**
|
|
614
|
+
* Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
|
|
615
|
+
*/
|
|
616
|
+
name: TOptions['name'];
|
|
617
|
+
/**
|
|
618
|
+
* Resolved options (after defaults have been applied).
|
|
619
|
+
*/
|
|
620
|
+
options: TOptions['resolvedOptions'];
|
|
621
|
+
/**
|
|
622
|
+
* Convert the raw source into a universal `RootNode`.
|
|
623
|
+
*/
|
|
516
624
|
parse: (source: AdapterSource) => PossiblePromise<RootNode>;
|
|
517
625
|
/**
|
|
518
626
|
* Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
|
|
@@ -1084,5 +1192,5 @@ declare class PluginDriver {
|
|
|
1084
1192
|
getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
|
|
1085
1193
|
}
|
|
1086
1194
|
//#endregion
|
|
1087
|
-
export { ResolveOptionsContext as A, ReactGeneratorV2 as B, PluginParameter as C, Printer as D, Presets as E, UserPlugin as F, formatters as G, KubbEvents as H, UserPluginWithLifeCycle as I,
|
|
1088
|
-
//# sourceMappingURL=PluginDriver-
|
|
1195
|
+
export { ResolveOptionsContext as A, ReactGeneratorV2 as B, PluginParameter as C, Printer as D, Presets as E, UserPlugin as F, formatters as G, KubbEvents as H, UserPluginWithLifeCycle as I, PossiblePromise as J, linters as K, UserResolver as L, Resolver as M, UserConfig as N, PrinterFactoryOptions as O, UserLogger as P, CoreGeneratorV2 as R, PluginLifecycleHooks as S, Preset as T, Storage as U, defineGenerator as V, createStorage as W, AsyncEventEmitter as Y, Output as _, AdapterFactoryOptions as a, PluginFactoryOptions as b, CompatibilityPreset as c, Group as d, InputData as f, LoggerOptions as g, LoggerContext as h, Adapter as i, ResolvePathParams as j, ResolveNameParams as k, Config as l, Logger as m, PluginDriver as n, AdapterSource as o, InputPath as p, logLevel as q, getMode as r, BarrelType as s, GetFileOptions as t, DevtoolsOptions as u, Plugin as v, PluginWithLifeCycle as w, PluginLifecycle as x, PluginContext as y, Generator as z };
|
|
1196
|
+
//# sourceMappingURL=PluginDriver-BRTrzfiD.d.ts.map
|
package/dist/hooks.cjs
CHANGED
|
@@ -33,6 +33,22 @@ function buildDefaultBanner({ title, description, version, config }) {
|
|
|
33
33
|
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* React-Fabric hook that exposes the current plugin context inside a generator component.
|
|
38
|
+
*
|
|
39
|
+
* Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers
|
|
40
|
+
* (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that
|
|
41
|
+
* all default to the current plugin when no explicit `pluginName` is provided.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* function Operation({ node }: OperationProps) {
|
|
46
|
+
* const { config, resolvePath } = useKubb()
|
|
47
|
+
* const filePath = resolvePath({ baseName: node.operationId })
|
|
48
|
+
* return <File path={filePath}>...</File>
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
36
52
|
function useKubb() {
|
|
37
53
|
const { meta } = (0, _kubb_react_fabric.useFabric)();
|
|
38
54
|
const config = meta.driver.config;
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":["path"],"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\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\n}\n"],"mappings":";;;;;;;;;AAsDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAASA,UAAAA,QAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["path"],"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\n}\n"],"mappings":";;;;;;;;;AAsDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAASA,UAAAA,QAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO;;;;;;;;;;;;;;;;;;;AAoBX,SAAgB,UAAiG;CAC/G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAIJ;CAEJ,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,oBAAoB,KAAK,OAAO;CAEtC,MAAM,SACJ,KAAK,OAAO,SACX;AAEH,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX;EACA,kBAAkB,aAAa,sBAAsB,KAAK,OAAO,gBAAgB,KAAK,KAAK,QAAQ,WAAW;EAC9G,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EACxH,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,cAAc,EAAE,aAAa,mBAAmB,GAAG,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,UAAA,GAAA,mBAAA,YAA6C;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkD;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA8C;AAEtD,QAAO,KAAK"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
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-BRTrzfiD.js";
|
|
3
3
|
import { RootNode } from "@kubb/ast/types";
|
|
4
4
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
5
5
|
|
|
@@ -54,6 +54,22 @@ type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
54
54
|
*/
|
|
55
55
|
resolveFooter: (node?: RootNode) => string | undefined;
|
|
56
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
|
+
*/
|
|
57
73
|
declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions>;
|
|
58
74
|
//#endregion
|
|
59
75
|
//#region src/hooks/useMode.d.ts
|
package/dist/hooks.js
CHANGED
|
@@ -31,6 +31,22 @@ function buildDefaultBanner({ title, description, version, config }) {
|
|
|
31
31
|
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
32
32
|
}
|
|
33
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
|
+
*/
|
|
34
50
|
function useKubb() {
|
|
35
51
|
const { meta } = useFabric();
|
|
36
52
|
const config = meta.driver.config;
|
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\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\n}\n"],"mappings":";;;;;;;AAsDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAAS,KAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO
|
|
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\n}\n"],"mappings":";;;;;;;AAsDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAAS,KAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO;;;;;;;;;;;;;;;;;;;AAoBX,SAAgB,UAAiG;CAC/G,MAAM,EAAE,SAAS,WAIb;CAEJ,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,oBAAoB,KAAK,OAAO;CAEtC,MAAM,SACJ,KAAK,OAAO,SACX;AAEH,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX;EACA,kBAAkB,aAAa,sBAAsB,KAAK,OAAO,gBAAgB,KAAK,KAAK,QAAQ,WAAW;EAC9G,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EACxH,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,cAAc,EAAE,aAAa,mBAAmB,GAAG,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"}
|