@kubb/core 4.36.1 → 5.0.0-alpha.10
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-D30QAz2y.d.ts → PluginDriver-BkFepPdm.d.ts} +354 -291
- package/dist/hooks.cjs +85 -8
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +66 -4
- package/dist/hooks.js +83 -8
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +346 -315
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +91 -77
- package/dist/index.js +338 -305
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Kubb.ts +27 -55
- package/src/{PluginManager.ts → PluginDriver.ts} +69 -82
- package/src/build.ts +32 -33
- package/src/constants.ts +1 -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/defineResolver.ts +131 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useKubb.ts +143 -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 +7 -7
- package/src/storages/fsStorage.ts +2 -2
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +94 -48
- package/src/utils/FunctionParams.ts +2 -2
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/formatters.ts +1 -1
- package/src/utils/getBarrelFiles.ts +73 -11
- package/src/utils/getConfigs.ts +3 -21
- package/src/utils/linters.ts +1 -1
- package/src/utils/packageJSON.ts +61 -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,8 +1,8 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as UserConfig, B as Storage, C as PluginWithLifeCycle, D as ResolveOptionsContext, E as ResolveNameParams, F as CoreGeneratorV2, G as AsyncEventEmitter, H as formatters, I as Generator, L as ReactGeneratorV2, M as UserPlugin, N as UserPluginWithLifeCycle, O as ResolvePathParams, P as UserResolver, R as defineGenerator, S as PluginParameter, T as PrinterFactoryOptions, U as linters, V as createStorage, W as logLevel, _ as Plugin, a as AdapterFactoryOptions, b as PluginLifecycle, c as Config, d as InputData, f as InputPath, g as Output, h as LoggerOptions, i as Adapter, j as UserLogger, k as Resolver, l as DevtoolsOptions, m as LoggerContext, n as PluginDriver, o as AdapterSource, p as Logger, r as getMode, s as BarrelType, u as Group, v as PluginContext, w as Printer, x as PluginLifecycleHooks, y as PluginFactoryOptions, z as KubbEvents } from "./PluginDriver-BkFepPdm.js";
|
|
3
3
|
import { definePrinter } from "@kubb/ast";
|
|
4
|
-
import {
|
|
5
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
|
+
import { Node } from "@kubb/ast/types";
|
|
5
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
6
6
|
|
|
7
7
|
//#region src/build.d.ts
|
|
8
8
|
type BuildOptions = {
|
|
@@ -16,7 +16,7 @@ type BuildOutput = {
|
|
|
16
16
|
}>;
|
|
17
17
|
fabric: Fabric;
|
|
18
18
|
files: Array<KubbFile.ResolvedFile>;
|
|
19
|
-
|
|
19
|
+
driver: PluginDriver;
|
|
20
20
|
pluginTimings: Map<string, number>;
|
|
21
21
|
error?: Error;
|
|
22
22
|
sources: Map<KubbFile.Path, string>;
|
|
@@ -24,7 +24,7 @@ type BuildOutput = {
|
|
|
24
24
|
type SetupResult = {
|
|
25
25
|
events: AsyncEventEmitter<KubbEvents>;
|
|
26
26
|
fabric: Fabric;
|
|
27
|
-
|
|
27
|
+
driver: PluginDriver;
|
|
28
28
|
sources: Map<KubbFile.Path, string>;
|
|
29
29
|
};
|
|
30
30
|
declare function setup(options: BuildOptions): Promise<SetupResult>;
|
|
@@ -72,91 +72,100 @@ declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>
|
|
|
72
72
|
*/
|
|
73
73
|
declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>;
|
|
74
74
|
//#endregion
|
|
75
|
-
//#region src/
|
|
75
|
+
//#region src/createAdapter.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* Builder type for an {@link Adapter} — takes options and returns the adapter instance.
|
|
78
|
+
*/
|
|
76
79
|
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
|
|
77
80
|
/**
|
|
78
|
-
*
|
|
81
|
+
* Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
|
|
79
82
|
*
|
|
80
83
|
* @example
|
|
81
|
-
*
|
|
82
|
-
* export const adapterOas = defineAdapter<OasAdapter>((options) => {
|
|
83
|
-
* const { validate = true, dateType = 'string' } = options
|
|
84
|
+
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
84
85
|
* return {
|
|
85
|
-
* name:
|
|
86
|
-
* options
|
|
87
|
-
* parse(source) { ... },
|
|
86
|
+
* name: 'my-adapter',
|
|
87
|
+
* options,
|
|
88
|
+
* async parse(source) { ... },
|
|
88
89
|
* }
|
|
89
90
|
* })
|
|
90
|
-
*
|
|
91
|
+
*
|
|
92
|
+
* // instantiate
|
|
93
|
+
* const adapter = myAdapter({ validate: true })
|
|
91
94
|
*/
|
|
92
|
-
declare function
|
|
95
|
+
declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
|
|
93
96
|
//#endregion
|
|
94
|
-
//#region src/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
//#region src/createPlugin.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Builder type for a {@link UserPluginWithLifeCycle} — takes options and returns the plugin instance.
|
|
100
|
+
*/
|
|
98
101
|
type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
|
|
99
102
|
/**
|
|
100
|
-
*
|
|
103
|
+
* Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* export const myPlugin = createPlugin<MyPlugin>((options) => {
|
|
107
|
+
* return {
|
|
108
|
+
* name: 'my-plugin',
|
|
109
|
+
* options,
|
|
110
|
+
* resolvePath(baseName) { ... },
|
|
111
|
+
* resolveName(name, type) { ... },
|
|
112
|
+
* }
|
|
113
|
+
* })
|
|
114
|
+
*
|
|
115
|
+
* // instantiate
|
|
116
|
+
* const plugin = myPlugin({ output: { path: 'src/gen' } })
|
|
101
117
|
*/
|
|
102
|
-
declare function
|
|
118
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
|
|
103
119
|
//#endregion
|
|
104
|
-
//#region src/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
}
|
|
120
|
+
//#region src/defineLogger.d.ts
|
|
121
|
+
/**
|
|
122
|
+
* Wraps a logger definition into a typed {@link Logger}.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* export const myLogger = defineLogger({
|
|
126
|
+
* name: 'my-logger',
|
|
127
|
+
* install(context, options) {
|
|
128
|
+
* context.on('info', (message) => console.log('ℹ', message))
|
|
129
|
+
* context.on('error', (error) => console.error('✗', error.message))
|
|
130
|
+
* },
|
|
131
|
+
* })
|
|
132
|
+
*/
|
|
133
|
+
declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options>;
|
|
127
134
|
//#endregion
|
|
128
|
-
//#region src/
|
|
129
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
130
|
-
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
131
|
-
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<Array<Awaited<ValueOfPromiseFuncArray<TInput>>>>;
|
|
135
|
+
//#region src/defineResolver.d.ts
|
|
132
136
|
/**
|
|
133
|
-
*
|
|
137
|
+
* Builder type for the plugin-specific resolver fields.
|
|
138
|
+
* `default` and `resolveOptions` are optional — built-in fallbacks are used when omitted.
|
|
134
139
|
*/
|
|
135
|
-
type
|
|
140
|
+
type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions'>> & ThisType<T['resolver']>;
|
|
136
141
|
/**
|
|
137
|
-
*
|
|
142
|
+
* Default option resolver — applies include/exclude filters and merges any matching override options.
|
|
143
|
+
* Returns `null` when the node is filtered out.
|
|
138
144
|
*/
|
|
139
|
-
|
|
145
|
+
declare function defaultResolveOptions<TOptions>(node: Node, {
|
|
146
|
+
options,
|
|
147
|
+
exclude,
|
|
148
|
+
include,
|
|
149
|
+
override
|
|
150
|
+
}: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
140
151
|
/**
|
|
141
|
-
*
|
|
152
|
+
* Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
|
|
153
|
+
* Override `default` or `resolveOptions` in the builder to customize the behavior.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
157
|
+
* resolveName(name) {
|
|
158
|
+
* return this.default(name, 'function')
|
|
159
|
+
* },
|
|
160
|
+
* resolveTypedName(name) {
|
|
161
|
+
* return this.default(name, 'type')
|
|
162
|
+
* },
|
|
163
|
+
* resolveParamName(node, param) {
|
|
164
|
+
* return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
|
|
165
|
+
* },
|
|
166
|
+
* }))
|
|
142
167
|
*/
|
|
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;
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/PromiseManager.d.ts
|
|
147
|
-
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
148
|
-
type Options<TState = unknown> = {
|
|
149
|
-
nullCheck?: (state: TState) => boolean;
|
|
150
|
-
};
|
|
151
|
-
declare class PromiseManager<TState = unknown> {
|
|
152
|
-
#private;
|
|
153
|
-
constructor(options?: Options<TState>);
|
|
154
|
-
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput, {
|
|
155
|
-
concurrency
|
|
156
|
-
}?: {
|
|
157
|
-
concurrency?: number;
|
|
158
|
-
}): TOutput;
|
|
159
|
-
}
|
|
168
|
+
declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
|
|
160
169
|
//#endregion
|
|
161
170
|
//#region src/storages/fsStorage.d.ts
|
|
162
171
|
/**
|
|
@@ -182,7 +191,7 @@ declare class PromiseManager<TState = unknown> {
|
|
|
182
191
|
* })
|
|
183
192
|
* ```
|
|
184
193
|
*/
|
|
185
|
-
declare const fsStorage: (options?: Record<string, never> | undefined) =>
|
|
194
|
+
declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
186
195
|
//#endregion
|
|
187
196
|
//#region src/storages/memoryStorage.d.ts
|
|
188
197
|
/**
|
|
@@ -202,7 +211,7 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Define
|
|
|
202
211
|
* })
|
|
203
212
|
* ```
|
|
204
213
|
*/
|
|
205
|
-
declare const memoryStorage: (options?: Record<string, never> | undefined) =>
|
|
214
|
+
declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
|
|
206
215
|
//#endregion
|
|
207
216
|
//#region src/utils/FunctionParams.d.ts
|
|
208
217
|
type FunctionParamsASTWithoutType = {
|
|
@@ -232,11 +241,11 @@ type FunctionParamsASTWithType = {
|
|
|
232
241
|
default?: string;
|
|
233
242
|
};
|
|
234
243
|
/**
|
|
235
|
-
* @deprecated
|
|
244
|
+
* @deprecated use ast package instead
|
|
236
245
|
*/
|
|
237
246
|
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
238
247
|
/**
|
|
239
|
-
* @deprecated
|
|
248
|
+
* @deprecated use ast package instead
|
|
240
249
|
*/
|
|
241
250
|
declare class FunctionParams {
|
|
242
251
|
#private;
|
|
@@ -274,7 +283,7 @@ declare function detectFormatter(): Promise<Formatter | undefined>;
|
|
|
274
283
|
//#endregion
|
|
275
284
|
//#region src/utils/getBarrelFiles.d.ts
|
|
276
285
|
type FileMetaBase = {
|
|
277
|
-
|
|
286
|
+
pluginName?: string;
|
|
278
287
|
};
|
|
279
288
|
type AddIndexesProps = {
|
|
280
289
|
type: BarrelType | false | undefined;
|
|
@@ -299,7 +308,7 @@ declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
|
|
|
299
308
|
meta,
|
|
300
309
|
root,
|
|
301
310
|
output
|
|
302
|
-
}: AddIndexesProps): Promise<KubbFile.File
|
|
311
|
+
}: AddIndexesProps): Promise<Array<KubbFile.File>>;
|
|
303
312
|
//#endregion
|
|
304
313
|
//#region src/utils/getConfigs.d.ts
|
|
305
314
|
/**
|
|
@@ -311,5 +320,10 @@ declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions):
|
|
|
311
320
|
type Linter = keyof typeof linters;
|
|
312
321
|
declare function detectLinter(): Promise<Linter | undefined>;
|
|
313
322
|
//#endregion
|
|
314
|
-
|
|
323
|
+
//#region src/utils/packageJSON.d.ts
|
|
324
|
+
type DependencyName = string;
|
|
325
|
+
type DependencyVersion = string;
|
|
326
|
+
declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
|
|
327
|
+
//#endregion
|
|
328
|
+
export { Adapter, AdapterFactoryOptions, AdapterSource, BarrelType, type CLIOptions, 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, Printer, PrinterFactoryOptions, ReactGeneratorV2, ResolveNameParams, ResolveOptionsContext, ResolvePathParams, Resolver, Storage, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, createAdapter, createPlugin, createStorage, defaultResolveOptions, defineConfig, defineGenerator, defineLogger, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, satisfiesDependency, setup };
|
|
315
329
|
//# sourceMappingURL=index.d.ts.map
|