@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
|
@@ -1,100 +1,101 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Fabric } from "@kubb/
|
|
4
|
-
import {
|
|
5
|
-
import { Printer, PrinterFactoryOptions, RootNode } from "@kubb/ast/types";
|
|
2
|
+
import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
3
|
+
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
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
|
-
declare var AsyncEventEmitter: {
|
|
13
|
-
new (maxListener?: number): {
|
|
14
|
-
"__#private@#emitter": EventEmitter<[never]>;
|
|
15
|
-
/**
|
|
16
|
-
* Emits an event and awaits all registered listeners in parallel.
|
|
17
|
-
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
18
|
-
*/
|
|
19
|
-
emit(eventName: any, ...eventArgs: any[]): Promise<void>; /** Registers a persistent listener for the given event. */
|
|
20
|
-
on(eventName: any, handler: any): void; /** Registers a one-shot listener that removes itself after the first invocation. */
|
|
21
|
-
onOnce(eventName: any, handler: any): void; /** Removes a previously registered listener. */
|
|
22
|
-
off(eventName: any, handler: any): void; /** Removes all listeners from every event channel. */
|
|
23
|
-
removeAll(): void;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const p = new URLPath('/pet/{petId}')
|
|
31
|
-
* p.URL // '/pet/:petId'
|
|
32
|
-
* p.template // '`/pet/${petId}`'
|
|
33
|
-
*/
|
|
34
|
-
declare var URLPath: {
|
|
35
|
-
new (path: any, options?: {}): {
|
|
36
|
-
/** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */path: any;
|
|
37
|
-
"__#private@#options": {}; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
38
|
-
get URL(): any; /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
|
|
39
|
-
get isURL(): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
45
|
-
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
46
|
-
*/
|
|
47
|
-
get template(): string; /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
|
|
48
|
-
get object(): string | {
|
|
49
|
-
url: any;
|
|
50
|
-
params: {} | undefined;
|
|
51
|
-
}; /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
|
|
52
|
-
get params(): {} | undefined;
|
|
53
|
-
"__#private@#transformParam"(raw: any): any; /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
|
|
54
|
-
"__#private@#eachParam"(fn: any): void;
|
|
55
|
-
toObject({
|
|
56
|
-
type,
|
|
57
|
-
replacer,
|
|
58
|
-
stringify
|
|
59
|
-
}?: {
|
|
60
|
-
type?: string | undefined;
|
|
61
|
-
}): string | {
|
|
62
|
-
url: any;
|
|
63
|
-
params: {} | undefined;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
67
|
-
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
71
|
-
*/
|
|
72
|
-
toTemplateString({
|
|
73
|
-
prefix,
|
|
74
|
-
replacer
|
|
75
|
-
}?: {
|
|
76
|
-
prefix?: string | undefined;
|
|
77
|
-
}): string;
|
|
78
|
-
/**
|
|
79
|
-
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
80
|
-
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
81
|
-
* Returns `undefined` when no path parameters are found.
|
|
82
|
-
*/
|
|
83
|
-
getParams(replacer: any): {} | undefined; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
84
|
-
toURLPath(): any;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
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>;
|
|
87
11
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
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;
|
|
95
88
|
//#endregion
|
|
96
89
|
//#region src/constants.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Base URL for the Kubb Studio web app.
|
|
92
|
+
*/
|
|
97
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
|
+
*/
|
|
98
99
|
declare const logLevel: {
|
|
99
100
|
readonly silent: number;
|
|
100
101
|
readonly error: 0;
|
|
@@ -103,6 +104,13 @@ declare const logLevel: {
|
|
|
103
104
|
readonly verbose: 4;
|
|
104
105
|
readonly debug: 5;
|
|
105
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
|
+
*/
|
|
106
114
|
declare const linters: {
|
|
107
115
|
readonly eslint: {
|
|
108
116
|
readonly command: "eslint";
|
|
@@ -120,6 +128,13 @@ declare const linters: {
|
|
|
120
128
|
readonly errorMessage: "Oxlint not found";
|
|
121
129
|
};
|
|
122
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
|
+
*/
|
|
123
138
|
declare const formatters: {
|
|
124
139
|
readonly prettier: {
|
|
125
140
|
readonly command: "prettier";
|
|
@@ -138,46 +153,46 @@ declare const formatters: {
|
|
|
138
153
|
};
|
|
139
154
|
};
|
|
140
155
|
//#endregion
|
|
141
|
-
//#region src/
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
* Implement this interface to route generated files to any backend — filesystem,
|
|
147
|
-
* S3, Redis, in-memory, etc.
|
|
148
|
-
*
|
|
149
|
-
* Use `defineStorage` to create a typed storage driver.
|
|
150
|
-
*/
|
|
151
|
-
interface DefineStorage {
|
|
152
|
-
/** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */
|
|
156
|
+
//#region src/createStorage.d.ts
|
|
157
|
+
type Storage = {
|
|
158
|
+
/**
|
|
159
|
+
* Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
|
|
160
|
+
*/
|
|
153
161
|
readonly name: string;
|
|
154
|
-
/**
|
|
162
|
+
/**
|
|
163
|
+
* Returns `true` when an entry for `key` exists in storage.
|
|
164
|
+
*/
|
|
155
165
|
hasItem(key: string): Promise<boolean>;
|
|
156
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Returns the stored string value, or `null` when `key` does not exist.
|
|
168
|
+
*/
|
|
157
169
|
getItem(key: string): Promise<string | null>;
|
|
158
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Persists `value` under `key`, creating any required structure.
|
|
172
|
+
*/
|
|
159
173
|
setItem(key: string, value: string): Promise<void>;
|
|
160
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Removes the entry for `key`. No-ops when the key does not exist.
|
|
176
|
+
*/
|
|
161
177
|
removeItem(key: string): Promise<void>;
|
|
162
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Returns all keys, optionally filtered to those starting with `base`.
|
|
180
|
+
*/
|
|
163
181
|
getKeys(base?: string): Promise<Array<string>>;
|
|
164
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Removes all entries, optionally scoped to those starting with `base`.
|
|
184
|
+
*/
|
|
165
185
|
clear(base?: string): Promise<void>;
|
|
166
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Optional teardown hook called after the build completes.
|
|
188
|
+
*/
|
|
167
189
|
dispose?(): Promise<void>;
|
|
168
|
-
}
|
|
190
|
+
};
|
|
169
191
|
/**
|
|
170
|
-
*
|
|
171
|
-
* same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
|
|
172
|
-
*
|
|
173
|
-
* The builder receives the resolved options object and must return a
|
|
174
|
-
* `DefineStorage`-compatible object that includes a `name` string.
|
|
192
|
+
* Creates a storage factory. Call the returned function with optional options to get the storage instance.
|
|
175
193
|
*
|
|
176
194
|
* @example
|
|
177
|
-
*
|
|
178
|
-
* import { defineStorage } from '@kubb/core'
|
|
179
|
-
*
|
|
180
|
-
* export const memoryStorage = defineStorage((_options) => {
|
|
195
|
+
* export const memoryStorage = createStorage(() => {
|
|
181
196
|
* const store = new Map<string, string>()
|
|
182
197
|
* return {
|
|
183
198
|
* name: 'memory',
|
|
@@ -185,160 +200,39 @@ interface DefineStorage {
|
|
|
185
200
|
* async getItem(key) { return store.get(key) ?? null },
|
|
186
201
|
* async setItem(key, value) { store.set(key, value) },
|
|
187
202
|
* async removeItem(key) { store.delete(key) },
|
|
188
|
-
* async getKeys() {
|
|
189
|
-
*
|
|
203
|
+
* async getKeys(base) {
|
|
204
|
+
* const keys = [...store.keys()]
|
|
205
|
+
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
206
|
+
* },
|
|
207
|
+
* async clear(base) { if (!base) store.clear() },
|
|
190
208
|
* }
|
|
191
209
|
* })
|
|
192
|
-
* ```
|
|
193
210
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/PluginManager.d.ts
|
|
197
|
-
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
198
|
-
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
199
|
-
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
200
|
-
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
201
|
-
result: Result;
|
|
202
|
-
plugin: Plugin;
|
|
203
|
-
};
|
|
204
|
-
type Options = {
|
|
205
|
-
fabric: Fabric;
|
|
206
|
-
events: AsyncEventEmitter<KubbEvents>;
|
|
207
|
-
/**
|
|
208
|
-
* @default Number.POSITIVE_INFINITY
|
|
209
|
-
*/
|
|
210
|
-
concurrency?: number;
|
|
211
|
-
};
|
|
212
|
-
type GetFileProps<TOptions = object> = {
|
|
213
|
-
name: string;
|
|
214
|
-
mode?: KubbFile.Mode;
|
|
215
|
-
extname: KubbFile.Extname;
|
|
216
|
-
pluginName: string;
|
|
217
|
-
options?: TOptions;
|
|
218
|
-
};
|
|
219
|
-
declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
|
|
220
|
-
declare class PluginManager {
|
|
221
|
-
#private;
|
|
222
|
-
readonly config: Config;
|
|
223
|
-
readonly options: Options;
|
|
224
|
-
/**
|
|
225
|
-
* The universal `@kubb/ast` `RootNode` produced by the adapter, set by
|
|
226
|
-
* the build pipeline after the adapter's `parse()` resolves.
|
|
227
|
-
*/
|
|
228
|
-
rootNode: RootNode | undefined;
|
|
229
|
-
constructor(config: Config, options: Options);
|
|
230
|
-
get events(): AsyncEventEmitter<KubbEvents>;
|
|
231
|
-
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
232
|
-
get plugins(): Array<Plugin>;
|
|
233
|
-
getFile<TOptions = object>({
|
|
234
|
-
name,
|
|
235
|
-
mode,
|
|
236
|
-
extname,
|
|
237
|
-
pluginName,
|
|
238
|
-
options
|
|
239
|
-
}: GetFileProps<TOptions>): KubbFile.File<{
|
|
240
|
-
pluginName: string;
|
|
241
|
-
}>;
|
|
242
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
243
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
244
|
-
/**
|
|
245
|
-
* Run a specific hookName for plugin x.
|
|
246
|
-
*/
|
|
247
|
-
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
248
|
-
pluginName,
|
|
249
|
-
hookName,
|
|
250
|
-
parameters
|
|
251
|
-
}: {
|
|
252
|
-
pluginName: string;
|
|
253
|
-
hookName: H;
|
|
254
|
-
parameters: PluginParameter<H>;
|
|
255
|
-
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
256
|
-
/**
|
|
257
|
-
* Run a specific hookName for plugin x.
|
|
258
|
-
*/
|
|
259
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
260
|
-
pluginName,
|
|
261
|
-
hookName,
|
|
262
|
-
parameters
|
|
263
|
-
}: {
|
|
264
|
-
pluginName: string;
|
|
265
|
-
hookName: H;
|
|
266
|
-
parameters: PluginParameter<H>;
|
|
267
|
-
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
268
|
-
/**
|
|
269
|
-
* Returns the first non-null result.
|
|
270
|
-
*/
|
|
271
|
-
hookFirst<H extends PluginLifecycleHooks>({
|
|
272
|
-
hookName,
|
|
273
|
-
parameters,
|
|
274
|
-
skipped
|
|
275
|
-
}: {
|
|
276
|
-
hookName: H;
|
|
277
|
-
parameters: PluginParameter<H>;
|
|
278
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
279
|
-
}): Promise<SafeParseResult<H>>;
|
|
280
|
-
/**
|
|
281
|
-
* Returns the first non-null result.
|
|
282
|
-
*/
|
|
283
|
-
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
284
|
-
hookName,
|
|
285
|
-
parameters,
|
|
286
|
-
skipped
|
|
287
|
-
}: {
|
|
288
|
-
hookName: H;
|
|
289
|
-
parameters: PluginParameter<H>;
|
|
290
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
291
|
-
}): SafeParseResult<H> | null;
|
|
292
|
-
/**
|
|
293
|
-
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
294
|
-
*/
|
|
295
|
-
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
296
|
-
hookName,
|
|
297
|
-
parameters
|
|
298
|
-
}: {
|
|
299
|
-
hookName: H;
|
|
300
|
-
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
301
|
-
}): Promise<Awaited<TOutput>[]>;
|
|
302
|
-
/**
|
|
303
|
-
* Chains plugins
|
|
304
|
-
*/
|
|
305
|
-
hookSeq<H extends PluginLifecycleHooks>({
|
|
306
|
-
hookName,
|
|
307
|
-
parameters
|
|
308
|
-
}: {
|
|
309
|
-
hookName: H;
|
|
310
|
-
parameters?: PluginParameter<H>;
|
|
311
|
-
}): Promise<void>;
|
|
312
|
-
getPluginByName(pluginName: string): Plugin | undefined;
|
|
313
|
-
getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
|
|
314
|
-
}
|
|
211
|
+
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
315
212
|
//#endregion
|
|
316
213
|
//#region src/Kubb.d.ts
|
|
317
|
-
type
|
|
214
|
+
type DebugInfo = {
|
|
318
215
|
date: Date;
|
|
319
|
-
logs: string
|
|
216
|
+
logs: Array<string>;
|
|
320
217
|
fileName?: string;
|
|
321
218
|
};
|
|
322
|
-
type
|
|
219
|
+
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
323
220
|
hookName: H;
|
|
324
221
|
plugins: Array<Plugin>;
|
|
325
222
|
};
|
|
326
|
-
type
|
|
327
|
-
hookName: H;
|
|
328
|
-
};
|
|
329
|
-
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
223
|
+
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
330
224
|
strategy: Strategy;
|
|
331
225
|
hookName: H;
|
|
332
226
|
plugin: Plugin;
|
|
333
|
-
parameters?: unknown
|
|
227
|
+
parameters?: Array<unknown>;
|
|
334
228
|
output?: unknown;
|
|
335
229
|
};
|
|
336
|
-
type
|
|
230
|
+
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
337
231
|
duration: number;
|
|
338
232
|
strategy: Strategy;
|
|
339
233
|
hookName: H;
|
|
340
234
|
plugin: Plugin;
|
|
341
|
-
parameters?: unknown
|
|
235
|
+
parameters?: Array<unknown>;
|
|
342
236
|
output?: unknown;
|
|
343
237
|
};
|
|
344
238
|
/**
|
|
@@ -347,7 +241,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
347
241
|
*
|
|
348
242
|
* @example
|
|
349
243
|
* ```typescript
|
|
350
|
-
* import type { AsyncEventEmitter } from '@
|
|
244
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
351
245
|
* import type { KubbEvents } from '@kubb/core'
|
|
352
246
|
*
|
|
353
247
|
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
@@ -385,12 +279,12 @@ interface KubbEvents {
|
|
|
385
279
|
/**
|
|
386
280
|
* Emitted when code generation phase completes.
|
|
387
281
|
*/
|
|
388
|
-
'generation:end': [
|
|
282
|
+
'generation:end': [config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>];
|
|
389
283
|
/**
|
|
390
284
|
* Emitted with a summary of the generation results.
|
|
391
285
|
* Contains summary lines, title, and success status.
|
|
392
286
|
*/
|
|
393
|
-
'generation:summary': [
|
|
287
|
+
'generation:summary': [config: Config, {
|
|
394
288
|
failedPlugins: Set<{
|
|
395
289
|
plugin: Plugin;
|
|
396
290
|
error: Error;
|
|
@@ -398,7 +292,7 @@ interface KubbEvents {
|
|
|
398
292
|
status: 'success' | 'failed';
|
|
399
293
|
hrStart: [number, number];
|
|
400
294
|
filesCreated: number;
|
|
401
|
-
pluginTimings?: Map<
|
|
295
|
+
pluginTimings?: Map<Plugin['name'], number>;
|
|
402
296
|
}];
|
|
403
297
|
/**
|
|
404
298
|
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
@@ -425,7 +319,7 @@ interface KubbEvents {
|
|
|
425
319
|
*/
|
|
426
320
|
'hooks:end': [];
|
|
427
321
|
/**
|
|
428
|
-
* Emitted when a single hook execution starts
|
|
322
|
+
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
429
323
|
* The callback should be invoked when the command completes.
|
|
430
324
|
*/
|
|
431
325
|
'hook:start': [{
|
|
@@ -467,7 +361,7 @@ interface KubbEvents {
|
|
|
467
361
|
* Debug event for detailed logging.
|
|
468
362
|
* Contains timestamp, log messages, and optional filename.
|
|
469
363
|
*/
|
|
470
|
-
debug: [
|
|
364
|
+
debug: [info: DebugInfo];
|
|
471
365
|
/**
|
|
472
366
|
* Emitted when file processing starts.
|
|
473
367
|
* Contains the list of files to be processed.
|
|
@@ -478,10 +372,25 @@ interface KubbEvents {
|
|
|
478
372
|
* Contains processed count, total count, percentage, and file details.
|
|
479
373
|
*/
|
|
480
374
|
'file:processing:update': [{
|
|
481
|
-
/**
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
+
*/
|
|
485
394
|
file: KubbFile.ResolvedFile;
|
|
486
395
|
/**
|
|
487
396
|
* Kubb configuration (not present in Fabric).
|
|
@@ -493,16 +402,16 @@ interface KubbEvents {
|
|
|
493
402
|
* Emitted when file processing completes.
|
|
494
403
|
* Contains the list of processed files.
|
|
495
404
|
*/
|
|
496
|
-
'files:processing:end': [files: KubbFile.ResolvedFile
|
|
405
|
+
'files:processing:end': [files: Array<KubbFile.ResolvedFile>];
|
|
497
406
|
/**
|
|
498
407
|
* Emitted when a plugin starts executing.
|
|
499
408
|
*/
|
|
500
409
|
'plugin:start': [plugin: Plugin];
|
|
501
410
|
/**
|
|
502
411
|
* Emitted when a plugin completes execution.
|
|
503
|
-
* Duration in ms
|
|
412
|
+
* Duration in ms.
|
|
504
413
|
*/
|
|
505
|
-
'plugin:end': [plugin: Plugin,
|
|
414
|
+
'plugin:end': [plugin: Plugin, result: {
|
|
506
415
|
duration: number;
|
|
507
416
|
success: boolean;
|
|
508
417
|
error?: Error;
|
|
@@ -511,24 +420,111 @@ interface KubbEvents {
|
|
|
511
420
|
* Emitted when plugin hook progress tracking starts.
|
|
512
421
|
* Contains the hook name and list of plugins to execute.
|
|
513
422
|
*/
|
|
514
|
-
'plugins:hook:progress:start': [
|
|
423
|
+
'plugins:hook:progress:start': [progress: HookProgress];
|
|
515
424
|
/**
|
|
516
425
|
* Emitted when plugin hook progress tracking ends.
|
|
517
426
|
* Contains the hook name that completed.
|
|
518
427
|
*/
|
|
519
|
-
'plugins:hook:progress:end': [
|
|
428
|
+
'plugins:hook:progress:end': [{
|
|
429
|
+
hookName: PluginLifecycleHooks;
|
|
430
|
+
}];
|
|
520
431
|
/**
|
|
521
432
|
* Emitted when a plugin hook starts processing.
|
|
522
433
|
* Contains strategy, hook name, plugin, parameters, and output.
|
|
523
434
|
*/
|
|
524
|
-
'plugins:hook:processing:start': [
|
|
435
|
+
'plugins:hook:processing:start': [execution: HookExecution];
|
|
525
436
|
/**
|
|
526
437
|
* Emitted when a plugin hook completes processing.
|
|
527
438
|
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
528
439
|
*/
|
|
529
|
-
'plugins:hook:processing:end': [
|
|
440
|
+
'plugins:hook:processing:end': [result: HookResult];
|
|
530
441
|
}
|
|
531
442
|
//#endregion
|
|
443
|
+
//#region src/defineGenerator.d.ts
|
|
444
|
+
/**
|
|
445
|
+
* Props for the `operations` lifecycle — receives all operation nodes at once.
|
|
446
|
+
*/
|
|
447
|
+
type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
448
|
+
config: Config;
|
|
449
|
+
adapter: Adapter;
|
|
450
|
+
options: Plugin<TPlugin>['options'];
|
|
451
|
+
nodes: Array<OperationNode>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Props for the `operation` lifecycle — receives a single operation node.
|
|
455
|
+
*/
|
|
456
|
+
type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
457
|
+
config: Config;
|
|
458
|
+
adapter: Adapter;
|
|
459
|
+
options: Plugin<TPlugin>['options'];
|
|
460
|
+
node: OperationNode;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Props for the `schema` lifecycle — receives a single schema node.
|
|
464
|
+
*/
|
|
465
|
+
type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
466
|
+
config: Config;
|
|
467
|
+
adapter: Adapter;
|
|
468
|
+
options: Plugin<TPlugin>['options'];
|
|
469
|
+
node: SchemaNode;
|
|
470
|
+
};
|
|
471
|
+
type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
472
|
+
name: string;
|
|
473
|
+
type: 'core';
|
|
474
|
+
version?: '2';
|
|
475
|
+
operations?(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
476
|
+
operation?(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
477
|
+
schema?(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
478
|
+
};
|
|
479
|
+
type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
|
|
480
|
+
name: string;
|
|
481
|
+
type: 'react';
|
|
482
|
+
version?: '2';
|
|
483
|
+
Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode;
|
|
484
|
+
Operation?(props: OperationV2Props<TPlugin>): FabricReactNode;
|
|
485
|
+
Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode;
|
|
486
|
+
};
|
|
487
|
+
type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
488
|
+
name: string;
|
|
489
|
+
type: 'core';
|
|
490
|
+
version: '2';
|
|
491
|
+
operations(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
492
|
+
operation(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
493
|
+
schema(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
|
|
494
|
+
};
|
|
495
|
+
type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
496
|
+
name: string;
|
|
497
|
+
type: 'react';
|
|
498
|
+
version: '2';
|
|
499
|
+
Operations(props: OperationsV2Props<TPlugin>): FabricReactNode;
|
|
500
|
+
Operation(props: OperationV2Props<TPlugin>): FabricReactNode;
|
|
501
|
+
Schema(props: SchemaV2Props<TPlugin>): FabricReactNode;
|
|
502
|
+
};
|
|
503
|
+
type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>;
|
|
504
|
+
/**
|
|
505
|
+
* Defines a generator with no-op defaults for any omitted lifecycle methods.
|
|
506
|
+
* Works for both `core` (async file output) and `react` (JSX component) generators.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* // react generator
|
|
510
|
+
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
511
|
+
* name: 'typescript',
|
|
512
|
+
* type: 'react',
|
|
513
|
+
* Operation({ node, options }) { return <File>...</File> },
|
|
514
|
+
* Schema({ node, options }) { return <File>...</File> },
|
|
515
|
+
* })
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* // core generator
|
|
519
|
+
* export const myGenerator = defineGenerator<MyPlugin>({
|
|
520
|
+
* name: 'my-generator',
|
|
521
|
+
* type: 'core',
|
|
522
|
+
* async operation({ node, options }) { return [{ path: '...', content: '...' }] },
|
|
523
|
+
* })
|
|
524
|
+
*/
|
|
525
|
+
declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserReactGeneratorV2<TPlugin>): ReactGeneratorV2<TPlugin>;
|
|
526
|
+
declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>;
|
|
527
|
+
//#endregion
|
|
532
528
|
//#region src/types.d.ts
|
|
533
529
|
declare global {
|
|
534
530
|
namespace Kubb {
|
|
@@ -589,11 +585,13 @@ type AdapterSource = {
|
|
|
589
585
|
* - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
590
586
|
* - `TOptions` — raw user-facing options passed to the adapter factory
|
|
591
587
|
* - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
|
|
588
|
+
* - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
|
|
592
589
|
*/
|
|
593
|
-
type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = {
|
|
590
|
+
type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
|
|
594
591
|
name: TName;
|
|
595
592
|
options: TOptions;
|
|
596
593
|
resolvedOptions: TResolvedOptions;
|
|
594
|
+
document: TDocument;
|
|
597
595
|
};
|
|
598
596
|
/**
|
|
599
597
|
* An adapter converts a source file or data into a `@kubb/ast` `RootNode`.
|
|
@@ -614,9 +612,34 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
614
612
|
* ```
|
|
615
613
|
*/
|
|
616
614
|
type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
617
|
-
/**
|
|
618
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
|
|
617
|
+
*/
|
|
618
|
+
name: TOptions['name'];
|
|
619
|
+
/**
|
|
620
|
+
* Resolved options (after defaults have been applied).
|
|
621
|
+
*/
|
|
622
|
+
options: TOptions['resolvedOptions'];
|
|
623
|
+
/**
|
|
624
|
+
* The raw source document produced after the first `parse()` call.
|
|
625
|
+
* `undefined` before parsing; typed by the adapter's `TDocument` generic.
|
|
626
|
+
*/
|
|
627
|
+
document?: TOptions['document'];
|
|
628
|
+
/**
|
|
629
|
+
* Convert the raw source into a universal `RootNode`.
|
|
630
|
+
*/
|
|
619
631
|
parse: (source: AdapterSource) => PossiblePromise<RootNode>;
|
|
632
|
+
/**
|
|
633
|
+
* Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
|
|
634
|
+
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
635
|
+
*
|
|
636
|
+
* The `resolve` callback receives the collision-corrected schema name and must
|
|
637
|
+
* return the `{ name, path }` pair for the import, or `undefined` to skip it.
|
|
638
|
+
*/
|
|
639
|
+
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
640
|
+
name: string;
|
|
641
|
+
path: string;
|
|
642
|
+
}) => Array<KubbFile.Import>;
|
|
620
643
|
};
|
|
621
644
|
type BarrelType = 'all' | 'named' | 'propagate';
|
|
622
645
|
type DevtoolsOptions = {
|
|
@@ -681,16 +704,16 @@ type Config<TInput = Input> = {
|
|
|
681
704
|
/**
|
|
682
705
|
* Storage backend for generated files.
|
|
683
706
|
* Defaults to `fsStorage()` — the built-in filesystem driver.
|
|
684
|
-
* Accepts any object implementing the {@link
|
|
707
|
+
* Accepts any object implementing the {@link Storage} interface.
|
|
685
708
|
* Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
|
|
686
709
|
* @default fsStorage()
|
|
687
710
|
* @example
|
|
688
711
|
* ```ts
|
|
689
|
-
* import {
|
|
690
|
-
* storage:
|
|
712
|
+
* import { memoryStorage } from '@kubb/core'
|
|
713
|
+
* storage: memoryStorage()
|
|
691
714
|
* ```
|
|
692
715
|
*/
|
|
693
|
-
storage?:
|
|
716
|
+
storage?: Storage;
|
|
694
717
|
/**
|
|
695
718
|
* Specifies the formatting tool to be used.
|
|
696
719
|
* - 'auto' automatically detects and uses biome or prettier (in that order of preference).
|
|
@@ -764,6 +787,40 @@ type Config<TInput = Input> = {
|
|
|
764
787
|
done?: string | Array<string>;
|
|
765
788
|
};
|
|
766
789
|
};
|
|
790
|
+
type PatternFilter = {
|
|
791
|
+
type: string;
|
|
792
|
+
pattern: string | RegExp;
|
|
793
|
+
};
|
|
794
|
+
type PatternOverride<TOptions> = PatternFilter & {
|
|
795
|
+
options: Omit<Partial<TOptions>, 'override'>;
|
|
796
|
+
};
|
|
797
|
+
type ResolveOptionsContext<TOptions> = {
|
|
798
|
+
options: TOptions;
|
|
799
|
+
exclude?: Array<PatternFilter>;
|
|
800
|
+
include?: Array<PatternFilter>;
|
|
801
|
+
override?: Array<PatternOverride<TOptions>>;
|
|
802
|
+
};
|
|
803
|
+
/**
|
|
804
|
+
* Base constraint for all plugin resolver objects.
|
|
805
|
+
*
|
|
806
|
+
* `default` and `resolveOptions` are injected automatically by `defineResolver` — plugin
|
|
807
|
+
* authors may override them but never need to implement them from scratch.
|
|
808
|
+
* Concrete plugin resolver types extend this with their own helper methods.
|
|
809
|
+
*/
|
|
810
|
+
type Resolver = {
|
|
811
|
+
name: string;
|
|
812
|
+
default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
|
|
813
|
+
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* The user-facing subset of a `Resolver` — everything except the methods injected by
|
|
817
|
+
* `defineResolver` (`default` and `resolveOptions`).
|
|
818
|
+
*
|
|
819
|
+
* When you pass a `UserResolver` to `defineResolver`, the standard `default` and
|
|
820
|
+
* `resolveOptions` implementations are injected automatically so plugin authors never
|
|
821
|
+
* need to define them by hand. Both can still be overridden by providing them explicitly.
|
|
822
|
+
*/
|
|
823
|
+
type UserResolver = Omit<Resolver, 'default' | 'resolveOptions'>;
|
|
767
824
|
type PluginFactoryOptions<
|
|
768
825
|
/**
|
|
769
826
|
* Name to be used for the plugin.
|
|
@@ -784,14 +841,19 @@ TContext = unknown,
|
|
|
784
841
|
/**
|
|
785
842
|
* When calling `resolvePath` you can specify better types.
|
|
786
843
|
*/
|
|
787
|
-
TResolvePathOptions extends object = object
|
|
844
|
+
TResolvePathOptions extends object = object,
|
|
845
|
+
/**
|
|
846
|
+
* Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
|
|
847
|
+
* Use `defineResolver` to define the resolver object and export it alongside the plugin.
|
|
848
|
+
*/
|
|
849
|
+
TResolver extends Resolver = Resolver> = {
|
|
788
850
|
name: TName;
|
|
789
851
|
options: TOptions;
|
|
790
852
|
resolvedOptions: TResolvedOptions;
|
|
791
853
|
context: TContext;
|
|
792
854
|
resolvePathOptions: TResolvePathOptions;
|
|
855
|
+
resolver: TResolver;
|
|
793
856
|
};
|
|
794
|
-
type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
|
|
795
857
|
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
796
858
|
/**
|
|
797
859
|
* Unique name used for the plugin
|
|
@@ -815,7 +877,7 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
815
877
|
inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
816
878
|
};
|
|
817
879
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
818
|
-
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<
|
|
880
|
+
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
|
|
819
881
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
820
882
|
/**
|
|
821
883
|
* Unique name used for the plugin
|
|
@@ -837,7 +899,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
837
899
|
options: TOptions['resolvedOptions'];
|
|
838
900
|
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
839
901
|
/**
|
|
840
|
-
*
|
|
902
|
+
* Defines a context that can be used by other plugins, see `PluginDriver` where we convert from `UserPlugin` to `Plugin` (used when calling `createPlugin`).
|
|
841
903
|
*/
|
|
842
904
|
inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
|
|
843
905
|
};
|
|
@@ -890,7 +952,7 @@ type ResolveNameParams = {
|
|
|
890
952
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
891
953
|
fabric: Fabric;
|
|
892
954
|
config: Config;
|
|
893
|
-
|
|
955
|
+
driver: PluginDriver;
|
|
894
956
|
/**
|
|
895
957
|
* Only add when the file does not exist yet
|
|
896
958
|
*/
|
|
@@ -905,18 +967,26 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
905
967
|
* Current plugin
|
|
906
968
|
*/
|
|
907
969
|
plugin: Plugin<TOptions>;
|
|
908
|
-
/**
|
|
909
|
-
* Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
|
|
910
|
-
* Returns `undefined` when no adapter was set (legacy OAS-only usage).
|
|
911
|
-
*/
|
|
912
|
-
rootNode: RootNode | undefined;
|
|
913
970
|
/**
|
|
914
971
|
* Opens the Kubb Studio URL for the current `rootNode` in the default browser.
|
|
915
972
|
* Falls back to printing the URL if the browser cannot be launched.
|
|
916
973
|
* No-ops silently when no adapter has set a `rootNode`.
|
|
917
974
|
*/
|
|
918
975
|
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
919
|
-
} &
|
|
976
|
+
} & ({
|
|
977
|
+
/**
|
|
978
|
+
* Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
|
|
979
|
+
* Returns `undefined` when no adapter was set (legacy OAS-only usage).
|
|
980
|
+
*/
|
|
981
|
+
rootNode: RootNode;
|
|
982
|
+
/**
|
|
983
|
+
* Return the adapter from `@kubb/ast`
|
|
984
|
+
*/
|
|
985
|
+
adapter: Adapter;
|
|
986
|
+
} | {
|
|
987
|
+
rootNode?: never;
|
|
988
|
+
adapter?: never;
|
|
989
|
+
}) & Kubb.PluginContext;
|
|
920
990
|
/**
|
|
921
991
|
* Specify the export location for the files and define the behavior of the output
|
|
922
992
|
*/
|
|
@@ -944,9 +1014,6 @@ type Output<TOptions> = {
|
|
|
944
1014
|
*/
|
|
945
1015
|
override?: boolean;
|
|
946
1016
|
};
|
|
947
|
-
type GroupContext = {
|
|
948
|
-
group: string;
|
|
949
|
-
};
|
|
950
1017
|
type Group = {
|
|
951
1018
|
/**
|
|
952
1019
|
* Defines the type where to group the files.
|
|
@@ -956,9 +1023,11 @@ type Group = {
|
|
|
956
1023
|
*/
|
|
957
1024
|
type: 'tag' | 'path';
|
|
958
1025
|
/**
|
|
959
|
-
* Return the name of a group based on the group name, this used for the file and name generation
|
|
1026
|
+
* Return the name of a group based on the group name, this is used for the file and name generation.
|
|
960
1027
|
*/
|
|
961
|
-
name?: (context:
|
|
1028
|
+
name?: (context: {
|
|
1029
|
+
group: string;
|
|
1030
|
+
}) => string;
|
|
962
1031
|
};
|
|
963
1032
|
type LoggerOptions = {
|
|
964
1033
|
/**
|
|
@@ -969,13 +1038,166 @@ type LoggerOptions = {
|
|
|
969
1038
|
/**
|
|
970
1039
|
* Shared context passed to all plugins, parsers, and Fabric internals.
|
|
971
1040
|
*/
|
|
972
|
-
|
|
973
|
-
type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
1041
|
+
type LoggerContext = AsyncEventEmitter<KubbEvents>;
|
|
974
1042
|
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
975
1043
|
name: string;
|
|
976
|
-
install:
|
|
1044
|
+
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
977
1045
|
};
|
|
978
|
-
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> =
|
|
1046
|
+
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Compatibility preset for code generation tools.
|
|
1049
|
+
* - `'default'` – no compatibility adjustments (default behavior).
|
|
1050
|
+
* - `'kubbV4'` – align generated names and structures with Kubb v4 output.
|
|
1051
|
+
*/
|
|
1052
|
+
type CompatibilityPreset = 'default' | 'kubbV4';
|
|
1053
|
+
/**
|
|
1054
|
+
* A preset bundles a name, one or more resolvers, and optional AST transformers
|
|
1055
|
+
* into a single reusable configuration object.
|
|
1056
|
+
*
|
|
1057
|
+
* @template TResolver - The concrete resolver type for this preset.
|
|
1058
|
+
*/
|
|
1059
|
+
type Preset<TResolver extends Resolver = Resolver> = {
|
|
1060
|
+
/**
|
|
1061
|
+
* Unique identifier for this preset.
|
|
1062
|
+
*/
|
|
1063
|
+
name: string;
|
|
1064
|
+
/**
|
|
1065
|
+
* Ordered list of resolvers applied by this preset (last entry wins on merge).
|
|
1066
|
+
*/
|
|
1067
|
+
resolvers: Array<TResolver>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Optional AST visitors / transformers applied after resolving.
|
|
1070
|
+
*/
|
|
1071
|
+
transformers?: Array<Visitor>;
|
|
1072
|
+
};
|
|
1073
|
+
/**
|
|
1074
|
+
* A named registry of presets, keyed by preset name.
|
|
1075
|
+
*
|
|
1076
|
+
* @template TResolver - The concrete resolver type shared by all presets in this registry.
|
|
1077
|
+
* @template TName - The union of valid preset name keys.
|
|
1078
|
+
*/
|
|
1079
|
+
type Presets<TResolver extends Resolver = Resolver> = Record<CompatibilityPreset, Preset<TResolver>>;
|
|
1080
|
+
//#endregion
|
|
1081
|
+
//#region src/PluginDriver.d.ts
|
|
1082
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
1083
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
1084
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
1085
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
1086
|
+
result: Result;
|
|
1087
|
+
plugin: Plugin;
|
|
1088
|
+
};
|
|
1089
|
+
type Options = {
|
|
1090
|
+
fabric: Fabric;
|
|
1091
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
1092
|
+
/**
|
|
1093
|
+
* @default Number.POSITIVE_INFINITY
|
|
1094
|
+
*/
|
|
1095
|
+
concurrency?: number;
|
|
1096
|
+
};
|
|
1097
|
+
type GetFileOptions<TOptions = object> = {
|
|
1098
|
+
name: string;
|
|
1099
|
+
mode?: KubbFile.Mode;
|
|
1100
|
+
extname: KubbFile.Extname;
|
|
1101
|
+
pluginName: string;
|
|
1102
|
+
options?: TOptions;
|
|
1103
|
+
};
|
|
1104
|
+
declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
|
|
1105
|
+
declare class PluginDriver {
|
|
1106
|
+
#private;
|
|
1107
|
+
readonly config: Config;
|
|
1108
|
+
readonly options: Options;
|
|
1109
|
+
/**
|
|
1110
|
+
* The universal `@kubb/ast` `RootNode` produced by the adapter, set by
|
|
1111
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
1112
|
+
*/
|
|
1113
|
+
rootNode: RootNode | undefined;
|
|
1114
|
+
adapter: Adapter | undefined;
|
|
1115
|
+
constructor(config: Config, options: Options);
|
|
1116
|
+
get events(): AsyncEventEmitter<KubbEvents>;
|
|
1117
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
1118
|
+
get plugins(): Array<Plugin>;
|
|
1119
|
+
getFile<TOptions = object>({
|
|
1120
|
+
name,
|
|
1121
|
+
mode,
|
|
1122
|
+
extname,
|
|
1123
|
+
pluginName,
|
|
1124
|
+
options
|
|
1125
|
+
}: GetFileOptions<TOptions>): KubbFile.File<{
|
|
1126
|
+
pluginName: string;
|
|
1127
|
+
}>;
|
|
1128
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
1129
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
1130
|
+
/**
|
|
1131
|
+
* Run a specific hookName for plugin x.
|
|
1132
|
+
*/
|
|
1133
|
+
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
1134
|
+
pluginName,
|
|
1135
|
+
hookName,
|
|
1136
|
+
parameters
|
|
1137
|
+
}: {
|
|
1138
|
+
pluginName: string;
|
|
1139
|
+
hookName: H;
|
|
1140
|
+
parameters: PluginParameter<H>;
|
|
1141
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
1142
|
+
/**
|
|
1143
|
+
* Run a specific hookName for plugin x.
|
|
1144
|
+
*/
|
|
1145
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
1146
|
+
pluginName,
|
|
1147
|
+
hookName,
|
|
1148
|
+
parameters
|
|
1149
|
+
}: {
|
|
1150
|
+
pluginName: string;
|
|
1151
|
+
hookName: H;
|
|
1152
|
+
parameters: PluginParameter<H>;
|
|
1153
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
1154
|
+
/**
|
|
1155
|
+
* Returns the first non-null result.
|
|
1156
|
+
*/
|
|
1157
|
+
hookFirst<H extends PluginLifecycleHooks>({
|
|
1158
|
+
hookName,
|
|
1159
|
+
parameters,
|
|
1160
|
+
skipped
|
|
1161
|
+
}: {
|
|
1162
|
+
hookName: H;
|
|
1163
|
+
parameters: PluginParameter<H>;
|
|
1164
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
1165
|
+
}): Promise<SafeParseResult<H>>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Returns the first non-null result.
|
|
1168
|
+
*/
|
|
1169
|
+
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
1170
|
+
hookName,
|
|
1171
|
+
parameters,
|
|
1172
|
+
skipped
|
|
1173
|
+
}: {
|
|
1174
|
+
hookName: H;
|
|
1175
|
+
parameters: PluginParameter<H>;
|
|
1176
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
1177
|
+
}): SafeParseResult<H> | null;
|
|
1178
|
+
/**
|
|
1179
|
+
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
1180
|
+
*/
|
|
1181
|
+
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
1182
|
+
hookName,
|
|
1183
|
+
parameters
|
|
1184
|
+
}: {
|
|
1185
|
+
hookName: H;
|
|
1186
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
1187
|
+
}): Promise<Awaited<TOutput>[]>;
|
|
1188
|
+
/**
|
|
1189
|
+
* Chains plugins
|
|
1190
|
+
*/
|
|
1191
|
+
hookSeq<H extends PluginLifecycleHooks>({
|
|
1192
|
+
hookName,
|
|
1193
|
+
parameters
|
|
1194
|
+
}: {
|
|
1195
|
+
hookName: H;
|
|
1196
|
+
parameters?: PluginParameter<H>;
|
|
1197
|
+
}): Promise<void>;
|
|
1198
|
+
getPluginByName(pluginName: string): Plugin | undefined;
|
|
1199
|
+
getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
|
|
1200
|
+
}
|
|
979
1201
|
//#endregion
|
|
980
|
-
export {
|
|
981
|
-
//# sourceMappingURL=
|
|
1202
|
+
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 };
|
|
1203
|
+
//# sourceMappingURL=PluginDriver-BkSenc-R.d.ts.map
|