@kubb/core 5.0.0-alpha.2 → 5.0.0-alpha.20
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/{types-B7eZvqwD.d.ts → PluginDriver-BkSenc-R.d.ts} +521 -299
- package/dist/hooks.cjs +101 -8
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +83 -4
- package/dist/hooks.js +99 -8
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +850 -536
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +438 -89
- package/dist/index.js +839 -532
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/Kubb.ts +37 -55
- package/src/{PluginManager.ts → PluginDriver.ts} +51 -40
- package/src/build.ts +74 -29
- package/src/config.ts +9 -8
- package/src/constants.ts +44 -1
- package/src/createAdapter.ts +25 -0
- package/src/createPlugin.ts +28 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +134 -0
- package/src/defineLogger.ts +13 -3
- package/src/definePreset.ts +23 -0
- package/src/definePresets.ts +16 -0
- package/src/defineResolver.ts +131 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useKubb.ts +160 -0
- package/src/hooks/useMode.ts +5 -2
- package/src/hooks/usePlugin.ts +5 -2
- package/src/hooks/usePluginDriver.ts +11 -0
- package/src/index.ts +12 -6
- package/src/renderNode.tsx +108 -0
- package/src/storages/fsStorage.ts +2 -2
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +150 -38
- package/src/utils/FunctionParams.ts +2 -2
- package/src/utils/TreeNode.ts +24 -1
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/executeStrategies.ts +23 -10
- package/src/utils/formatters.ts +10 -21
- package/src/utils/getBarrelFiles.ts +79 -9
- package/src/utils/getConfigs.ts +8 -22
- package/src/utils/getPreset.ts +41 -0
- package/src/utils/linters.ts +23 -3
- package/src/utils/mergeResolvers.ts +8 -0
- package/src/utils/packageJSON.ts +76 -0
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PromiseManager.ts +0 -40
- package/src/defineAdapter.ts +0 -22
- package/src/definePlugin.ts +0 -12
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/usePluginManager.ts +0 -8
- package/src/utils/getPlugins.ts +0 -23
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,213 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as ResolveOptionsContext, B as ReactGeneratorV2, C as PluginParameter, D as Printer, E as Presets, F as UserPlugin, G as formatters, H as KubbEvents, I as UserPluginWithLifeCycle, J as PossiblePromise, K as linters, L as UserResolver, M as Resolver, N as UserConfig, O as PrinterFactoryOptions, P as UserLogger, R as CoreGeneratorV2, S as PluginLifecycleHooks, T as Preset, U as Storage, V as defineGenerator, W as createStorage, Y as AsyncEventEmitter, _ as Output, a as AdapterFactoryOptions, b as PluginFactoryOptions, c as CompatibilityPreset, d as Group, f as InputData, g as LoggerOptions, h as LoggerContext, i as Adapter, j as ResolvePathParams, k as ResolveNameParams, l as Config, m as Logger, n as PluginDriver, o as AdapterSource, p as InputPath, q as logLevel, r as getMode, s as BarrelType, u as DevtoolsOptions, v as Plugin, w as PluginWithLifeCycle, x as PluginLifecycle, y as PluginContext, z as Generator } from "./PluginDriver-BkSenc-R.js";
|
|
3
3
|
import { definePrinter } from "@kubb/ast";
|
|
4
|
-
import {
|
|
5
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
|
+
import { Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
5
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
6
|
+
import { Fabric as Fabric$1 } from "@kubb/react-fabric/types";
|
|
6
7
|
|
|
8
|
+
//#region ../../internals/utils/src/urlPath.d.ts
|
|
9
|
+
type URLObject = {
|
|
10
|
+
/**
|
|
11
|
+
* The resolved URL string (Express-style or template literal, depending on context).
|
|
12
|
+
*/
|
|
13
|
+
url: string;
|
|
14
|
+
/**
|
|
15
|
+
* Extracted path parameters as a key-value map, or `undefined` when the path has none.
|
|
16
|
+
*/
|
|
17
|
+
params?: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
type ObjectOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* Controls whether the `url` is rendered as an Express path or a template literal.
|
|
22
|
+
* @default 'path'
|
|
23
|
+
*/
|
|
24
|
+
type?: 'path' | 'template';
|
|
25
|
+
/**
|
|
26
|
+
* Optional transform applied to each extracted parameter name.
|
|
27
|
+
*/
|
|
28
|
+
replacer?: (pathParam: string) => string;
|
|
29
|
+
/**
|
|
30
|
+
* When `true`, the result is serialized to a string expression instead of a plain object.
|
|
31
|
+
*/
|
|
32
|
+
stringify?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Supported identifier casing strategies for path parameters.
|
|
36
|
+
*/
|
|
37
|
+
type PathCasing = 'camelcase';
|
|
38
|
+
type Options = {
|
|
39
|
+
/**
|
|
40
|
+
* Casing strategy applied to path parameter names.
|
|
41
|
+
* @default undefined (original identifier preserved)
|
|
42
|
+
*/
|
|
43
|
+
casing?: PathCasing;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const p = new URLPath('/pet/{petId}')
|
|
50
|
+
* p.URL // '/pet/:petId'
|
|
51
|
+
* p.template // '`/pet/${petId}`'
|
|
52
|
+
*/
|
|
53
|
+
declare class URLPath {
|
|
54
|
+
#private;
|
|
55
|
+
/**
|
|
56
|
+
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
57
|
+
*/
|
|
58
|
+
path: string;
|
|
59
|
+
constructor(path: string, options?: Options);
|
|
60
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
get URL(): string;
|
|
68
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
73
|
+
* new URLPath('/pet/{petId}').isURL // false
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
get isURL(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
82
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
83
|
+
*/
|
|
84
|
+
get template(): string;
|
|
85
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* new URLPath('/pet/{petId}').object
|
|
90
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
get object(): URLObject | string;
|
|
94
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
99
|
+
* new URLPath('/pet').params // undefined
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
get params(): Record<string, string> | undefined;
|
|
103
|
+
toObject({
|
|
104
|
+
type,
|
|
105
|
+
replacer,
|
|
106
|
+
stringify
|
|
107
|
+
}?: ObjectOptions): URLObject | string;
|
|
108
|
+
/**
|
|
109
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
110
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
114
|
+
*/
|
|
115
|
+
toTemplateString({
|
|
116
|
+
prefix,
|
|
117
|
+
replacer
|
|
118
|
+
}?: {
|
|
119
|
+
prefix?: string;
|
|
120
|
+
replacer?: (pathParam: string) => string;
|
|
121
|
+
}): string;
|
|
122
|
+
/**
|
|
123
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
124
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
125
|
+
* Returns `undefined` when no path parameters are found.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').getParams()
|
|
130
|
+
* // { petId: 'petId', tagId: 'tagId' }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
|
|
134
|
+
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
toURLPath(): string;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
7
144
|
//#region src/build.d.ts
|
|
8
145
|
type BuildOptions = {
|
|
9
146
|
config: UserConfig;
|
|
10
147
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
11
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Full output produced by a successful or failed build.
|
|
151
|
+
*/
|
|
12
152
|
type BuildOutput = {
|
|
153
|
+
/**
|
|
154
|
+
* Plugins that threw during installation, paired with the caught error.
|
|
155
|
+
*/
|
|
13
156
|
failedPlugins: Set<{
|
|
14
157
|
plugin: Plugin;
|
|
15
158
|
error: Error;
|
|
16
159
|
}>;
|
|
17
160
|
fabric: Fabric;
|
|
18
161
|
files: Array<KubbFile.ResolvedFile>;
|
|
19
|
-
|
|
162
|
+
driver: PluginDriver;
|
|
163
|
+
/**
|
|
164
|
+
* Elapsed time in milliseconds for each plugin, keyed by plugin name.
|
|
165
|
+
*/
|
|
20
166
|
pluginTimings: Map<string, number>;
|
|
21
167
|
error?: Error;
|
|
168
|
+
/**
|
|
169
|
+
* Raw generated source, keyed by absolute file path.
|
|
170
|
+
*/
|
|
22
171
|
sources: Map<KubbFile.Path, string>;
|
|
23
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* Intermediate result returned by {@link setup} and accepted by {@link safeBuild}.
|
|
175
|
+
*/
|
|
24
176
|
type SetupResult = {
|
|
25
177
|
events: AsyncEventEmitter<KubbEvents>;
|
|
26
178
|
fabric: Fabric;
|
|
27
|
-
|
|
179
|
+
driver: PluginDriver;
|
|
28
180
|
sources: Map<KubbFile.Path, string>;
|
|
29
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* Initializes all Kubb infrastructure for a build without executing any plugins.
|
|
184
|
+
*
|
|
185
|
+
* - Validates the input path (when applicable).
|
|
186
|
+
* - Applies config defaults (`root`, `output.*`, `devtools`).
|
|
187
|
+
* - Creates the Fabric instance and wires storage, format, and lint hooks.
|
|
188
|
+
* - Runs the adapter (if configured) to produce the universal `RootNode`.
|
|
189
|
+
*
|
|
190
|
+
* Pass the returned {@link SetupResult} directly to {@link safeBuild} or {@link build}
|
|
191
|
+
* via the `overrides` argument to reuse the same infrastructure across multiple runs.
|
|
192
|
+
*/
|
|
30
193
|
declare function setup(options: BuildOptions): Promise<SetupResult>;
|
|
194
|
+
/**
|
|
195
|
+
* Runs a full Kubb build and throws on any error or plugin failure.
|
|
196
|
+
*
|
|
197
|
+
* Internally delegates to {@link safeBuild} and rethrows collected errors.
|
|
198
|
+
* Pass an existing {@link SetupResult} via `overrides` to skip the setup phase.
|
|
199
|
+
*/
|
|
31
200
|
declare function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
|
|
201
|
+
/**
|
|
202
|
+
* Runs a full Kubb build and captures errors instead of throwing.
|
|
203
|
+
*
|
|
204
|
+
* - Installs each plugin in order, recording failures in `failedPlugins`.
|
|
205
|
+
* - Generates the root barrel file when `output.barrelType` is set.
|
|
206
|
+
* - Writes all files through Fabric.
|
|
207
|
+
*
|
|
208
|
+
* Returns a {@link BuildOutput} even on failure — inspect `error` and
|
|
209
|
+
* `failedPlugins` to determine whether the build succeeded.
|
|
210
|
+
*/
|
|
32
211
|
declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
|
|
33
212
|
//#endregion
|
|
34
213
|
//#region src/config.d.ts
|
|
@@ -36,7 +215,13 @@ declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Prom
|
|
|
36
215
|
* CLI options derived from command-line flags.
|
|
37
216
|
*/
|
|
38
217
|
type CLIOptions = {
|
|
39
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Path to `kubb.config.js`.
|
|
220
|
+
*/
|
|
221
|
+
config?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Enable watch mode for input files.
|
|
224
|
+
*/
|
|
40
225
|
watch?: boolean;
|
|
41
226
|
/**
|
|
42
227
|
* Logging verbosity for CLI usage.
|
|
@@ -46,10 +231,11 @@ type CLIOptions = {
|
|
|
46
231
|
* - `debug`: include detailed plugin lifecycle logs
|
|
47
232
|
* @default 'silent'
|
|
48
233
|
*/
|
|
49
|
-
logLevel?: 'silent' | 'info' | 'debug';
|
|
50
|
-
bun?: boolean;
|
|
234
|
+
logLevel?: 'silent' | 'info' | 'debug';
|
|
51
235
|
};
|
|
52
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* All accepted forms of a Kubb configuration.
|
|
238
|
+
*/
|
|
53
239
|
type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
|
|
54
240
|
/**
|
|
55
241
|
* Helper for defining a Kubb configuration.
|
|
@@ -72,91 +258,186 @@ declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>
|
|
|
72
258
|
*/
|
|
73
259
|
declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>;
|
|
74
260
|
//#endregion
|
|
75
|
-
//#region src/
|
|
261
|
+
//#region src/createAdapter.d.ts
|
|
262
|
+
/**
|
|
263
|
+
* Builder type for an {@link Adapter} — takes options and returns the adapter instance.
|
|
264
|
+
*/
|
|
76
265
|
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
|
|
77
266
|
/**
|
|
78
|
-
*
|
|
267
|
+
* Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
|
|
79
268
|
*
|
|
80
269
|
* @example
|
|
81
|
-
*
|
|
82
|
-
* export const adapterOas = defineAdapter<OasAdapter>((options) => {
|
|
83
|
-
* const { validate = true, dateType = 'string' } = options
|
|
270
|
+
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
84
271
|
* return {
|
|
85
|
-
* name:
|
|
86
|
-
* options
|
|
87
|
-
* parse(source) { ... },
|
|
272
|
+
* name: 'my-adapter',
|
|
273
|
+
* options,
|
|
274
|
+
* async parse(source) { ... },
|
|
88
275
|
* }
|
|
89
276
|
* })
|
|
90
|
-
*
|
|
277
|
+
*
|
|
278
|
+
* // instantiate
|
|
279
|
+
* const adapter = myAdapter({ validate: true })
|
|
280
|
+
*/
|
|
281
|
+
declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/createPlugin.d.ts
|
|
284
|
+
/**
|
|
285
|
+
* Builder type for a {@link UserPluginWithLifeCycle} — takes options and returns the plugin instance.
|
|
286
|
+
*/
|
|
287
|
+
type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
|
|
288
|
+
/**
|
|
289
|
+
* Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* export const myPlugin = createPlugin<MyPlugin>((options) => {
|
|
293
|
+
* return {
|
|
294
|
+
* name: 'my-plugin',
|
|
295
|
+
* options,
|
|
296
|
+
* resolvePath(baseName) { ... },
|
|
297
|
+
* resolveName(name, type) { ... },
|
|
298
|
+
* }
|
|
299
|
+
* })
|
|
300
|
+
*
|
|
301
|
+
* // instantiate
|
|
302
|
+
* const plugin = myPlugin({ output: { path: 'src/gen' } })
|
|
91
303
|
*/
|
|
92
|
-
declare function
|
|
304
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
|
|
93
305
|
//#endregion
|
|
94
306
|
//#region src/defineLogger.d.ts
|
|
307
|
+
/**
|
|
308
|
+
* Wraps a logger definition into a typed {@link Logger}.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* export const myLogger = defineLogger({
|
|
312
|
+
* name: 'my-logger',
|
|
313
|
+
* install(context, options) {
|
|
314
|
+
* context.on('info', (message) => console.log('ℹ', message))
|
|
315
|
+
* context.on('error', (error) => console.error('✗', error.message))
|
|
316
|
+
* },
|
|
317
|
+
* })
|
|
318
|
+
*/
|
|
95
319
|
declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options>;
|
|
96
320
|
//#endregion
|
|
97
|
-
//#region src/
|
|
98
|
-
type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
|
|
321
|
+
//#region src/definePreset.d.ts
|
|
99
322
|
/**
|
|
100
|
-
*
|
|
323
|
+
* Creates a typed preset object that bundles a name, resolvers, and optional
|
|
324
|
+
* transformers — the building block for composable plugin presets.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* import { definePreset } from '@kubb/core'
|
|
328
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
329
|
+
*
|
|
330
|
+
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy] })
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* // With custom transformers
|
|
334
|
+
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
101
335
|
*/
|
|
102
|
-
declare function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
336
|
+
declare function definePreset<TResolver extends Resolver = Resolver, TName extends string = string>(name: TName, {
|
|
337
|
+
resolvers,
|
|
338
|
+
transformers
|
|
339
|
+
}: {
|
|
340
|
+
resolvers: Array<TResolver>;
|
|
341
|
+
transformers?: Array<Visitor>;
|
|
342
|
+
}): Preset<TResolver> & {
|
|
343
|
+
name: TName;
|
|
108
344
|
};
|
|
109
|
-
type DependencyName = string;
|
|
110
|
-
type DependencyVersion = string;
|
|
111
|
-
declare class PackageManager {
|
|
112
|
-
#private;
|
|
113
|
-
constructor(workspace?: string);
|
|
114
|
-
set workspace(workspace: string);
|
|
115
|
-
get workspace(): string | undefined;
|
|
116
|
-
normalizeDirectory(directory: string): string;
|
|
117
|
-
getLocation(path: string): string;
|
|
118
|
-
import(path: string): Promise<unknown>;
|
|
119
|
-
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
120
|
-
getPackageJSONSync(): PackageJSON | undefined;
|
|
121
|
-
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
122
|
-
getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
|
|
123
|
-
getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
|
|
124
|
-
isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
|
|
125
|
-
isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
|
|
126
|
-
}
|
|
127
345
|
//#endregion
|
|
128
|
-
//#region src/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
346
|
+
//#region src/definePresets.d.ts
|
|
347
|
+
/**
|
|
348
|
+
* Creates a typed presets registry object — a named collection of {@link Preset} entries.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* import { definePreset, definePresets } from '@kubb/core'
|
|
352
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
353
|
+
*
|
|
354
|
+
* export const myPresets = definePresets({
|
|
355
|
+
* kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy] }),
|
|
356
|
+
* })
|
|
357
|
+
*/
|
|
358
|
+
declare function definePresets<TResolver extends Resolver = Resolver>(presets: Presets<TResolver>): Presets<TResolver>;
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/defineResolver.d.ts
|
|
132
361
|
/**
|
|
133
|
-
*
|
|
362
|
+
* Builder type for the plugin-specific resolver fields.
|
|
363
|
+
* `default`, `resolveOptions`, and `name` are optional — built-in fallbacks are used when omitted.
|
|
134
364
|
*/
|
|
135
|
-
type
|
|
365
|
+
type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions' | 'name'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions'>> & {
|
|
366
|
+
name: string;
|
|
367
|
+
} & ThisType<T['resolver']>;
|
|
136
368
|
/**
|
|
137
|
-
*
|
|
369
|
+
* Default option resolver — applies include/exclude filters and merges any matching override options.
|
|
370
|
+
* Returns `null` when the node is filtered out.
|
|
138
371
|
*/
|
|
139
|
-
|
|
372
|
+
declare function defaultResolveOptions<TOptions>(node: Node, {
|
|
373
|
+
options,
|
|
374
|
+
exclude,
|
|
375
|
+
include,
|
|
376
|
+
override
|
|
377
|
+
}: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
140
378
|
/**
|
|
141
|
-
*
|
|
379
|
+
* Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
|
|
380
|
+
* Override `default` or `resolveOptions` in the builder to customize the behavior.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
384
|
+
* name: 'default',
|
|
385
|
+
* resolveName(name) {
|
|
386
|
+
* return this.default(name, 'function')
|
|
387
|
+
* },
|
|
388
|
+
* resolveTypedName(name) {
|
|
389
|
+
* return this.default(name, 'type')
|
|
390
|
+
* },
|
|
391
|
+
* resolveParamName(node, param) {
|
|
392
|
+
* return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
|
|
393
|
+
* },
|
|
394
|
+
* }))
|
|
142
395
|
*/
|
|
143
|
-
|
|
144
|
-
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
396
|
+
declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
|
|
145
397
|
//#endregion
|
|
146
|
-
//#region src/
|
|
147
|
-
type
|
|
148
|
-
|
|
149
|
-
|
|
398
|
+
//#region src/renderNode.d.ts
|
|
399
|
+
type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = {
|
|
400
|
+
config: Config;
|
|
401
|
+
fabric: Fabric$1;
|
|
402
|
+
plugin: Plugin<TOptions>;
|
|
403
|
+
Component: ReactGeneratorV2<TOptions>['Operations'] | undefined;
|
|
404
|
+
adapter: Adapter;
|
|
405
|
+
driver: PluginDriver;
|
|
406
|
+
mode: KubbFile.Mode;
|
|
407
|
+
options: TOptions['resolvedOptions'];
|
|
150
408
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
409
|
+
/**
|
|
410
|
+
* Renders a React component for a list of operation nodes (V2 generators).
|
|
411
|
+
*/
|
|
412
|
+
declare function renderOperations<TOptions extends PluginFactoryOptions>(nodes: Array<OperationNode>, options: BuildOperationsV2Options<TOptions>): Promise<void>;
|
|
413
|
+
type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = {
|
|
414
|
+
config: Config;
|
|
415
|
+
fabric: Fabric$1;
|
|
416
|
+
plugin: Plugin<TOptions>;
|
|
417
|
+
Component: ReactGeneratorV2<TOptions>['Operation'] | undefined;
|
|
418
|
+
adapter: Adapter;
|
|
419
|
+
driver: PluginDriver;
|
|
420
|
+
mode: KubbFile.Mode;
|
|
421
|
+
options: TOptions['resolvedOptions'];
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Renders a React component for a single operation node (V2 generators).
|
|
425
|
+
*/
|
|
426
|
+
declare function renderOperation<TOptions extends PluginFactoryOptions>(node: OperationNode, options: BuildOperationV2Options<TOptions>): Promise<void>;
|
|
427
|
+
type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = {
|
|
428
|
+
config: Config;
|
|
429
|
+
fabric: Fabric$1;
|
|
430
|
+
plugin: Plugin<TOptions>;
|
|
431
|
+
Component: ReactGeneratorV2<TOptions>['Schema'] | undefined;
|
|
432
|
+
adapter: Adapter;
|
|
433
|
+
driver: PluginDriver;
|
|
434
|
+
mode: KubbFile.Mode;
|
|
435
|
+
options: TOptions['resolvedOptions'];
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* Renders a React component for a single schema node (V2 generators).
|
|
439
|
+
*/
|
|
440
|
+
declare function renderSchema<TOptions extends PluginFactoryOptions>(node: SchemaNode, options: BuildSchemaV2Options<TOptions>): Promise<void>;
|
|
160
441
|
//#endregion
|
|
161
442
|
//#region src/storages/fsStorage.d.ts
|
|
162
443
|
/**
|
|
@@ -182,7 +463,7 @@ declare class PromiseManager<TState = unknown> {
|
|
|
182
463
|
* })
|
|
183
464
|
* ```
|
|
184
465
|
*/
|
|
185
|
-
declare const fsStorage: (options?: Record<string, never> | undefined) =>
|
|
466
|
+
declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
186
467
|
//#endregion
|
|
187
468
|
//#region src/storages/memoryStorage.d.ts
|
|
188
469
|
/**
|
|
@@ -202,7 +483,7 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Define
|
|
|
202
483
|
* })
|
|
203
484
|
* ```
|
|
204
485
|
*/
|
|
205
|
-
declare const memoryStorage: (options?: Record<string, never> | undefined) =>
|
|
486
|
+
declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
206
487
|
//#endregion
|
|
207
488
|
//#region src/utils/FunctionParams.d.ts
|
|
208
489
|
type FunctionParamsASTWithoutType = {
|
|
@@ -232,11 +513,11 @@ type FunctionParamsASTWithType = {
|
|
|
232
513
|
default?: string;
|
|
233
514
|
};
|
|
234
515
|
/**
|
|
235
|
-
* @deprecated
|
|
516
|
+
* @deprecated use ast package instead
|
|
236
517
|
*/
|
|
237
518
|
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
238
519
|
/**
|
|
239
|
-
* @deprecated
|
|
520
|
+
* @deprecated use ast package instead
|
|
240
521
|
*/
|
|
241
522
|
declare class FunctionParams {
|
|
242
523
|
#private;
|
|
@@ -251,26 +532,20 @@ declare class FunctionParams {
|
|
|
251
532
|
//#region src/utils/formatters.d.ts
|
|
252
533
|
type Formatter = keyof typeof formatters;
|
|
253
534
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* @returns Promise that resolves to the first available formatter or undefined if none are found
|
|
535
|
+
* Detects the first available code formatter on the current system.
|
|
257
536
|
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* Uses the `--version` flag to detect if each formatter command is available.
|
|
261
|
-
* This is a reliable method as all supported formatters implement this flag.
|
|
537
|
+
* - Checks in preference order: `biome`, `oxfmt`, `prettier`.
|
|
538
|
+
* - Returns `null` when none are found.
|
|
262
539
|
*
|
|
263
540
|
* @example
|
|
264
|
-
* ```
|
|
541
|
+
* ```ts
|
|
265
542
|
* const formatter = await detectFormatter()
|
|
266
543
|
* if (formatter) {
|
|
267
544
|
* console.log(`Using ${formatter} for formatting`)
|
|
268
|
-
* } else {
|
|
269
|
-
* console.log('No formatter found')
|
|
270
545
|
* }
|
|
271
546
|
* ```
|
|
272
547
|
*/
|
|
273
|
-
declare function detectFormatter(): Promise<Formatter |
|
|
548
|
+
declare function detectFormatter(): Promise<Formatter | null>;
|
|
274
549
|
//#endregion
|
|
275
550
|
//#region src/utils/getBarrelFiles.d.ts
|
|
276
551
|
type FileMetaBase = {
|
|
@@ -294,22 +569,96 @@ type AddIndexesProps = {
|
|
|
294
569
|
};
|
|
295
570
|
meta?: FileMetaBase;
|
|
296
571
|
};
|
|
572
|
+
/**
|
|
573
|
+
* Generates `index.ts` barrel files for all directories under `root/output.path`.
|
|
574
|
+
*
|
|
575
|
+
* - Returns an empty array when `type` is falsy or `'propagate'`.
|
|
576
|
+
* - Skips generation when the output path itself ends with `index` (already a barrel).
|
|
577
|
+
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
578
|
+
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
579
|
+
*/
|
|
297
580
|
declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
|
|
298
581
|
type,
|
|
299
582
|
meta,
|
|
300
583
|
root,
|
|
301
584
|
output
|
|
302
|
-
}: AddIndexesProps): Promise<KubbFile.File
|
|
585
|
+
}: AddIndexesProps): Promise<Array<KubbFile.File>>;
|
|
303
586
|
//#endregion
|
|
304
587
|
//#region src/utils/getConfigs.d.ts
|
|
305
588
|
/**
|
|
306
|
-
*
|
|
589
|
+
* Resolves a {@link ConfigInput} into a normalized array of {@link Config} objects.
|
|
590
|
+
*
|
|
591
|
+
* - Awaits the config when it is a `Promise`.
|
|
592
|
+
* - Calls the factory function with `args` when the config is a function.
|
|
593
|
+
* - Wraps a single config object in an array for uniform downstream handling.
|
|
307
594
|
*/
|
|
308
595
|
declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
|
|
309
596
|
//#endregion
|
|
597
|
+
//#region src/utils/getPreset.d.ts
|
|
598
|
+
type GetPresetParams<TResolver extends Resolver> = {
|
|
599
|
+
preset: CompatibilityPreset;
|
|
600
|
+
presets: Presets<TResolver>;
|
|
601
|
+
resolvers: Array<TResolver>;
|
|
602
|
+
transformers?: Array<Visitor>;
|
|
603
|
+
};
|
|
604
|
+
type GetPresetResult<TResolver extends Resolver> = {
|
|
605
|
+
baseResolver: TResolver;
|
|
606
|
+
resolver: TResolver;
|
|
607
|
+
transformers: Array<Visitor>;
|
|
608
|
+
preset: Preset<TResolver> | undefined;
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Resolves a named preset into merged resolvers and transformers.
|
|
612
|
+
*
|
|
613
|
+
* - Merges the preset's resolvers on top of the first (default) resolver to produce `baseResolver`.
|
|
614
|
+
* - Merges any additional user-supplied resolvers on top of that to produce the final `resolver`.
|
|
615
|
+
* - Concatenates preset transformers before user-supplied transformers.
|
|
616
|
+
*/
|
|
617
|
+
declare function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver>;
|
|
618
|
+
//#endregion
|
|
310
619
|
//#region src/utils/linters.d.ts
|
|
311
620
|
type Linter = keyof typeof linters;
|
|
312
|
-
|
|
621
|
+
/**
|
|
622
|
+
* Detects the first available linter on the current system.
|
|
623
|
+
*
|
|
624
|
+
* - Checks in preference order: `biome`, `oxlint`, `eslint`.
|
|
625
|
+
* - Returns `null` when none are found.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* const linter = await detectLinter()
|
|
630
|
+
* if (linter) {
|
|
631
|
+
* console.log(`Using ${linter} for linting`)
|
|
632
|
+
* }
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
declare function detectLinter(): Promise<Linter | null>;
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/utils/mergeResolvers.d.ts
|
|
638
|
+
/**
|
|
639
|
+
* Merges an array of resolvers into a single resolver. Later entries override earlier ones (last wins).
|
|
640
|
+
*/
|
|
641
|
+
declare function mergeResolvers<T extends Resolver>(...resolvers: Array<T>): T;
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/utils/packageJSON.d.ts
|
|
644
|
+
type DependencyName = string;
|
|
645
|
+
type DependencyVersion = string;
|
|
646
|
+
/**
|
|
647
|
+
* Returns `true` when the nearest `package.json` declares a dependency that
|
|
648
|
+
* satisfies the given semver range.
|
|
649
|
+
*
|
|
650
|
+
* - Searches both `dependencies` and `devDependencies`.
|
|
651
|
+
* - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
|
|
652
|
+
* - Uses `semver.satisfies` for range comparison; returns `false` when the
|
|
653
|
+
* version string cannot be coerced into a valid semver.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* satisfiesDependency('react', '>=18') // true when react@18.x is installed
|
|
658
|
+
* satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
|
|
313
662
|
//#endregion
|
|
314
|
-
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, Config, type ConfigInput,
|
|
663
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, CompatibilityPreset, Config, type ConfigInput, CoreGeneratorV2, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, ReactGeneratorV2, ResolveNameParams, ResolveOptionsContext, ResolvePathParams, Resolver, Storage, URLPath, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, createAdapter, createPlugin, createStorage, defaultResolveOptions, defineConfig, defineGenerator, defineLogger, definePreset, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeResolvers, renderOperation, renderOperations, renderSchema, safeBuild, satisfiesDependency, setup };
|
|
315
664
|
//# sourceMappingURL=index.d.ts.map
|