@kubb/core 5.0.0-beta.62 → 5.0.0-beta.64
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/{diagnostics-D0G07LHG.d.ts → diagnostics-BqiNAWVS.d.ts} +47 -40
- package/dist/index.cjs +47 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.js +49 -54
- package/dist/index.js.map +1 -1
- package/dist/{memoryStorage-CWFzAz4o.js → memoryStorage-DWnhqUf2.js} +3 -3
- package/dist/memoryStorage-DWnhqUf2.js.map +1 -0
- package/dist/{memoryStorage-CUj1hrxa.cjs → memoryStorage-mojU6pbA.cjs} +2 -2
- package/dist/memoryStorage-mojU6pbA.cjs.map +1 -0
- package/dist/mocks.cjs +2 -2
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +3 -3
- package/dist/mocks.js +3 -3
- package/dist/mocks.js.map +1 -1
- package/package.json +4 -5
- package/dist/memoryStorage-CUj1hrxa.cjs.map +0 -1
- package/dist/memoryStorage-CWFzAz4o.js.map +0 -1
- package/src/FileManager.ts +0 -137
- package/src/FileProcessor.ts +0 -212
- package/src/KubbDriver.ts +0 -893
- package/src/Transform.ts +0 -105
- package/src/constants.ts +0 -126
- package/src/createAdapter.ts +0 -127
- package/src/createKubb.ts +0 -196
- package/src/createRenderer.ts +0 -72
- package/src/createReporter.ts +0 -134
- package/src/createStorage.ts +0 -83
- package/src/defineGenerator.ts +0 -210
- package/src/defineParser.ts +0 -62
- package/src/definePlugin.ts +0 -437
- package/src/defineResolver.ts +0 -711
- package/src/diagnostics.ts +0 -662
- package/src/index.ts +0 -20
- package/src/mocks.ts +0 -249
- package/src/reporters/cliReporter.ts +0 -89
- package/src/reporters/fileReporter.ts +0 -103
- package/src/reporters/jsonReporter.ts +0 -20
- package/src/reporters/report.ts +0 -85
- package/src/storages/fsStorage.ts +0 -82
- package/src/storages/memoryStorage.ts +0 -55
- package/src/types.ts +0 -829
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/definePlugin.ts
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import type { Enforce, FileNode, HttpMethod, Macro, UserFileNode } from '@kubb/ast'
|
|
2
|
-
import { diagnosticCode } from './constants.ts'
|
|
3
|
-
import type { Generator } from './defineGenerator.ts'
|
|
4
|
-
import type { BannerMeta, Resolver } from './defineResolver.ts'
|
|
5
|
-
import { Diagnostics } from './diagnostics.ts'
|
|
6
|
-
import type { Config, KubbHooks } from './types.ts'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads a type from a registry, falling back to `{}` when the key is absent. Lets
|
|
10
|
-
* `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry` be augmented without
|
|
11
|
-
* touching core.
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* How a plugin consolidates its generated code into files.
|
|
19
|
-
* - `'directory'` writes one file per operation or schema under `path`.
|
|
20
|
-
* - `'file'` writes everything into a single file.
|
|
21
|
-
*/
|
|
22
|
-
export type OutputMode = 'directory' | 'file'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Output configuration shared by every plugin. Each plugin extends this with
|
|
26
|
-
* its own keys via the `Kubb.PluginOptionsRegistry.output` interface merge.
|
|
27
|
-
*/
|
|
28
|
-
export type Output<_TOptions = unknown> = {
|
|
29
|
-
/**
|
|
30
|
-
* Directory where the plugin writes its generated code, resolved against the global
|
|
31
|
-
* `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file
|
|
32
|
-
* path and must include the extension (e.g. `'types.ts'`, `'models.py'`).
|
|
33
|
-
*/
|
|
34
|
-
path: string
|
|
35
|
-
/**
|
|
36
|
-
* How generated code is consolidated into files.
|
|
37
|
-
* - `'directory'` writes one file per operation or schema under `path`.
|
|
38
|
-
* - `'file'` writes everything into a single file. The `path` must include the file extension.
|
|
39
|
-
*
|
|
40
|
-
* @default 'directory'
|
|
41
|
-
*/
|
|
42
|
-
mode?: OutputMode
|
|
43
|
-
/**
|
|
44
|
-
* Text prepended to every generated file. Useful for license headers,
|
|
45
|
-
* lint disables, or `@ts-nocheck` directives.
|
|
46
|
-
*
|
|
47
|
-
* A string is applied to every file (including barrel and aggregation re-export files).
|
|
48
|
-
* Pass a function to compute the banner from the file's `BannerMeta` document metadata
|
|
49
|
-
* plus per-file context (`isBarrel`, `isAggregation`, `filePath`, `baseName`), so you can
|
|
50
|
-
* skip the banner on specific files.
|
|
51
|
-
*
|
|
52
|
-
* @example Add a directive to source files but not re-export files
|
|
53
|
-
* `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : "'use server'"`
|
|
54
|
-
*/
|
|
55
|
-
banner?: string | ((meta: BannerMeta) => string)
|
|
56
|
-
/**
|
|
57
|
-
* Text appended at the end of every generated file. Mirror of `banner`.
|
|
58
|
-
* Pass a function to compute the footer from the file's `BannerMeta`.
|
|
59
|
-
*/
|
|
60
|
-
footer?: string | ((meta: BannerMeta) => string)
|
|
61
|
-
/**
|
|
62
|
-
* Allows the plugin to overwrite hand-written files at the same path.
|
|
63
|
-
* Defaults to `false` to protect manual edits.
|
|
64
|
-
*
|
|
65
|
-
* @default false
|
|
66
|
-
*/
|
|
67
|
-
override?: boolean
|
|
68
|
-
} & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Groups generated files into subdirectories based on an OpenAPI tag or path
|
|
72
|
-
* segment.
|
|
73
|
-
*/
|
|
74
|
-
export type Group = {
|
|
75
|
-
/**
|
|
76
|
-
* Property used to assign each operation to a group.
|
|
77
|
-
* - `'tag'` uses the first tag (`operation.getTags().at(0)?.name`).
|
|
78
|
-
* - `'path'` uses the first segment of the operation's URL.
|
|
79
|
-
*/
|
|
80
|
-
type: 'tag' | 'path'
|
|
81
|
-
/**
|
|
82
|
-
* Returns the subdirectory name from the group key. Defaults to the
|
|
83
|
-
* camelCased tag for `tag` groups, or the first path segment for `path` groups.
|
|
84
|
-
*/
|
|
85
|
-
name?: (context: { group: string }) => string
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Couples `output.mode` with the plugin's `group` option at the type level.
|
|
90
|
-
* - `mode: 'file'` forbids `group` (a single file has nothing to group).
|
|
91
|
-
* - `mode: 'directory'` (or no mode) allows an optional `group` to organize
|
|
92
|
-
* files into per-group subdirectories.
|
|
93
|
-
*
|
|
94
|
-
* Intersect into a plugin's `Options` type instead of declaring `output` and
|
|
95
|
-
* `group` directly, since `mode` lives inside `output` while `group` is its sibling.
|
|
96
|
-
* The generic keeps a plugin's extended `Output` shape intact.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* export type Options = OutputOptions & {
|
|
101
|
-
* exclude?: Array<Exclude>
|
|
102
|
-
* }
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export type OutputOptions<TOutput extends Output = Output> =
|
|
106
|
-
| {
|
|
107
|
-
output?: TOutput & { mode?: 'directory' }
|
|
108
|
-
group?: Group
|
|
109
|
-
}
|
|
110
|
-
| {
|
|
111
|
-
output: TOutput & { mode: 'file' }
|
|
112
|
-
group?: never
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Merges the `output.mode` default into the output config and validates the combination.
|
|
117
|
-
* Throws `KUBB_INVALID_PLUGIN_OPTIONS` when `mode: 'file'` is paired with a `group` option,
|
|
118
|
-
* since a single-file output has nothing to group.
|
|
119
|
-
*/
|
|
120
|
-
export function normalizeOutput({ output, group, pluginName }: { output: Output; group?: Group | null; pluginName: string }): Output {
|
|
121
|
-
const mode = output.mode ?? 'directory'
|
|
122
|
-
|
|
123
|
-
if (mode === 'file' && group) {
|
|
124
|
-
throw new Diagnostics.Error({
|
|
125
|
-
code: diagnosticCode.invalidPluginOptions,
|
|
126
|
-
severity: 'error',
|
|
127
|
-
message: `Plugin "${pluginName}" sets \`output.mode: 'file'\` but also configures a \`group\` option.`,
|
|
128
|
-
help: "A single-file output has nothing to group. Remove the `group` option, or use `output.mode: 'directory'` to organize files into subdirectories.",
|
|
129
|
-
location: { kind: 'config' },
|
|
130
|
-
plugin: pluginName,
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return { ...output, mode }
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
type ByTag = {
|
|
138
|
-
/**
|
|
139
|
-
* Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
|
|
140
|
-
*/
|
|
141
|
-
type: 'tag'
|
|
142
|
-
/**
|
|
143
|
-
* Tag name to match (case-sensitive). Can be a literal string or regex pattern.
|
|
144
|
-
*/
|
|
145
|
-
pattern: string | RegExp
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
type ByOperationId = {
|
|
149
|
-
/**
|
|
150
|
-
* Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
|
|
151
|
-
*/
|
|
152
|
-
type: 'operationId'
|
|
153
|
-
/**
|
|
154
|
-
* Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
|
|
155
|
-
*/
|
|
156
|
-
pattern: string | RegExp
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
type ByPath = {
|
|
160
|
-
/**
|
|
161
|
-
* Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
|
|
162
|
-
*/
|
|
163
|
-
type: 'path'
|
|
164
|
-
/**
|
|
165
|
-
* URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
|
|
166
|
-
*/
|
|
167
|
-
pattern: string | RegExp
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
type ByMethod = {
|
|
171
|
-
/**
|
|
172
|
-
* Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
|
|
173
|
-
*/
|
|
174
|
-
type: 'method'
|
|
175
|
-
/**
|
|
176
|
-
* HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
|
|
177
|
-
*/
|
|
178
|
-
pattern: HttpMethod | RegExp
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
type BySchemaName = {
|
|
182
|
-
/**
|
|
183
|
-
* Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
|
|
184
|
-
*/
|
|
185
|
-
type: 'schemaName'
|
|
186
|
-
/**
|
|
187
|
-
* Schema name to match (case-sensitive). Can be a literal string or regex pattern.
|
|
188
|
-
*/
|
|
189
|
-
pattern: string | RegExp
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
type ByContentType = {
|
|
193
|
-
/**
|
|
194
|
-
* Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
|
|
195
|
-
*/
|
|
196
|
-
type: 'contentType'
|
|
197
|
-
/**
|
|
198
|
-
* Content type to match (case-sensitive). Can be a literal string or regex pattern.
|
|
199
|
-
*/
|
|
200
|
-
pattern: string | RegExp
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Filter that skips matching operations or schemas during generation, for example
|
|
205
|
-
* deprecated endpoints or internal-only schemas.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```ts
|
|
209
|
-
* exclude: [
|
|
210
|
-
* { type: 'tag', pattern: 'internal' },
|
|
211
|
-
* { type: 'path', pattern: /^\/admin/ },
|
|
212
|
-
* { type: 'operationId', pattern: /^deprecated_/ },
|
|
213
|
-
* ]
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Filter that restricts generation to operations or schemas matching at least
|
|
220
|
-
* one entry. Useful for partial builds (one tag, one API version).
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* include: [
|
|
225
|
-
* { type: 'tag', pattern: 'public' },
|
|
226
|
-
* { type: 'path', pattern: /^\/api\/v1/ },
|
|
227
|
-
* ]
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Filter paired with a partial options object. When the filter matches, the
|
|
234
|
-
* options are merged on top of the plugin defaults for that operation only.
|
|
235
|
-
* Useful for "this one tag goes to a different folder" rules.
|
|
236
|
-
*
|
|
237
|
-
* Entries are evaluated top to bottom. The first matching entry wins.
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```ts
|
|
241
|
-
* override: [
|
|
242
|
-
* {
|
|
243
|
-
* type: 'tag',
|
|
244
|
-
* pattern: 'admin',
|
|
245
|
-
* options: { output: { path: './src/gen/admin' } },
|
|
246
|
-
* },
|
|
247
|
-
* {
|
|
248
|
-
* type: 'operationId',
|
|
249
|
-
* pattern: 'listPets',
|
|
250
|
-
* options: { enumType: 'literal' },
|
|
251
|
-
* },
|
|
252
|
-
* ]
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
256
|
-
options: Omit<Partial<TOptions>, 'override'>
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export type PluginFactoryOptions<
|
|
260
|
-
/**
|
|
261
|
-
* Unique plugin name.
|
|
262
|
-
*/
|
|
263
|
-
TName extends string = string,
|
|
264
|
-
/**
|
|
265
|
-
* User-facing plugin options.
|
|
266
|
-
*/
|
|
267
|
-
TOptions extends object = object,
|
|
268
|
-
/**
|
|
269
|
-
* Plugin options after defaults are applied.
|
|
270
|
-
*/
|
|
271
|
-
TResolvedOptions extends object = TOptions,
|
|
272
|
-
/**
|
|
273
|
-
* Resolver that encapsulates naming and path-resolution helpers.
|
|
274
|
-
* Define with `defineResolver` and export alongside the plugin.
|
|
275
|
-
*/
|
|
276
|
-
TResolver extends Resolver = Resolver,
|
|
277
|
-
> = {
|
|
278
|
-
name: TName
|
|
279
|
-
options: TOptions
|
|
280
|
-
resolvedOptions: TResolvedOptions
|
|
281
|
-
resolver: TResolver
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Context passed to a plugin's `kubb:plugin:setup` handler, where it registers generators and
|
|
286
|
-
* sets its resolver, transformer, and options.
|
|
287
|
-
*/
|
|
288
|
-
export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
289
|
-
/**
|
|
290
|
-
* Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
|
|
291
|
-
* just like generators declared statically on `createPlugin`.
|
|
292
|
-
*/
|
|
293
|
-
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
|
|
294
|
-
/**
|
|
295
|
-
* Set or override the resolver for this plugin.
|
|
296
|
-
* The resolver controls file naming and path resolution.
|
|
297
|
-
*/
|
|
298
|
-
setResolver(resolver: Partial<TFactory['resolver']>): void
|
|
299
|
-
/**
|
|
300
|
-
* Add a macro that rewrites AST nodes before they reach generators. Macros run in the order they
|
|
301
|
-
* are added, after any macros from earlier `addMacro` calls.
|
|
302
|
-
*/
|
|
303
|
-
addMacro(macro: Macro): void
|
|
304
|
-
/**
|
|
305
|
-
* Replace this plugin's macros with `macros`.
|
|
306
|
-
*/
|
|
307
|
-
setMacros(macros: ReadonlyArray<Macro>): void
|
|
308
|
-
/**
|
|
309
|
-
* Set resolved options merged into the normalized plugin's `options`.
|
|
310
|
-
* Call this in `kubb:plugin:setup` to provide options generators need.
|
|
311
|
-
*/
|
|
312
|
-
setOptions(options: TFactory['resolvedOptions']): void
|
|
313
|
-
/**
|
|
314
|
-
* Inject a raw file into the build output, bypassing the generation pipeline.
|
|
315
|
-
*/
|
|
316
|
-
injectFile(userFileNode: UserFileNode): void
|
|
317
|
-
/**
|
|
318
|
-
* Merge a partial config update into the current build configuration.
|
|
319
|
-
*/
|
|
320
|
-
updateConfig(config: Partial<Config>): void
|
|
321
|
-
/**
|
|
322
|
-
* The resolved build configuration at setup time.
|
|
323
|
-
*/
|
|
324
|
-
config: Config
|
|
325
|
-
/**
|
|
326
|
-
* The plugin's user-provided options.
|
|
327
|
-
*/
|
|
328
|
-
options: TFactory['options']
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* A plugin object produced by `definePlugin`. Its lifecycle handlers live under a single
|
|
333
|
-
* `hooks` property rather than flat methods.
|
|
334
|
-
*/
|
|
335
|
-
export type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
336
|
-
/**
|
|
337
|
-
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
338
|
-
*/
|
|
339
|
-
name: string
|
|
340
|
-
/**
|
|
341
|
-
* Plugins that must be registered before this plugin executes.
|
|
342
|
-
* An error is thrown at startup when any listed dependency is missing.
|
|
343
|
-
*/
|
|
344
|
-
dependencies?: Array<string>
|
|
345
|
-
/**
|
|
346
|
-
* Controls the execution order of this plugin relative to others.
|
|
347
|
-
*
|
|
348
|
-
* - `'pre'` runs before all normal plugins.
|
|
349
|
-
* - `'post'` runs after all normal plugins.
|
|
350
|
-
* - `undefined` (default), runs in declaration order among normal plugins.
|
|
351
|
-
*
|
|
352
|
-
* Dependency constraints always take precedence over `enforce`.
|
|
353
|
-
*/
|
|
354
|
-
enforce?: Enforce
|
|
355
|
-
/**
|
|
356
|
-
* The options passed by the user when calling the plugin factory.
|
|
357
|
-
*/
|
|
358
|
-
options?: TFactory['options']
|
|
359
|
-
/**
|
|
360
|
-
* Lifecycle event handlers for this plugin.
|
|
361
|
-
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
362
|
-
*/
|
|
363
|
-
hooks: {
|
|
364
|
-
[K in keyof KubbHooks as K extends 'kubb:plugin:setup' ? never : K]?: (...args: KubbHooks[K]) => void | Promise<void>
|
|
365
|
-
} & {
|
|
366
|
-
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Normalized plugin after setup, with runtime fields populated. Internal only. Plugins use the
|
|
372
|
-
* public `Plugin` type.
|
|
373
|
-
*
|
|
374
|
-
* @internal
|
|
375
|
-
*/
|
|
376
|
-
export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
|
|
377
|
-
options: TOptions['resolvedOptions'] & {
|
|
378
|
-
output: Output
|
|
379
|
-
include?: Array<Include>
|
|
380
|
-
exclude: Array<Exclude>
|
|
381
|
-
override: Array<Override<TOptions['resolvedOptions']>>
|
|
382
|
-
}
|
|
383
|
-
resolver: TOptions['resolver']
|
|
384
|
-
macros?: Array<Macro>
|
|
385
|
-
generators?: Array<Generator>
|
|
386
|
-
apply?: (config: Config) => boolean
|
|
387
|
-
version?: string
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export type KubbPluginStartContext = {
|
|
391
|
-
plugin: NormalizedPlugin
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export type KubbPluginEndContext = {
|
|
395
|
-
plugin: NormalizedPlugin
|
|
396
|
-
duration: number
|
|
397
|
-
success: boolean
|
|
398
|
-
error?: Error
|
|
399
|
-
config: Config
|
|
400
|
-
/**
|
|
401
|
-
* Returns all files currently in the file manager (lazy snapshot).
|
|
402
|
-
* Includes files added by plugins that have already run.
|
|
403
|
-
*/
|
|
404
|
-
readonly files: ReadonlyArray<FileNode>
|
|
405
|
-
/**
|
|
406
|
-
* Upsert one or more files into the file manager.
|
|
407
|
-
*/
|
|
408
|
-
upsertFile: (...files: Array<FileNode>) => void
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Wraps a plugin factory and returns a function that accepts user options and
|
|
413
|
-
* yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
|
|
414
|
-
*
|
|
415
|
-
* Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
|
|
416
|
-
* `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
|
|
417
|
-
* convention (`plugin-react-query`, `plugin-zod`, ...).
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* import { definePlugin } from '@kubb/core'
|
|
422
|
-
*
|
|
423
|
-
* export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
|
|
424
|
-
* name: 'plugin-ts',
|
|
425
|
-
* hooks: {
|
|
426
|
-
* 'kubb:plugin:setup'(ctx) {
|
|
427
|
-
* ctx.setResolver(resolverTs)
|
|
428
|
-
* },
|
|
429
|
-
* },
|
|
430
|
-
* }))
|
|
431
|
-
* ```
|
|
432
|
-
*/
|
|
433
|
-
export function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(
|
|
434
|
-
factory: (options: TFactory['options']) => Plugin<TFactory>,
|
|
435
|
-
): (options?: TFactory['options']) => Plugin<TFactory> {
|
|
436
|
-
return (options) => factory(options ?? ({} as TFactory['options']))
|
|
437
|
-
}
|