@kubb/core 5.0.0-alpha.22 → 5.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PluginDriver-DZdEyCoa.d.ts → PluginDriver-P920mak9.d.ts} +50 -23
- package/dist/hooks.cjs +1 -3
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +2 -4
- package/dist/hooks.js +1 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +99 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -58
- package/dist/index.js +100 -223
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PluginDriver.ts +81 -145
- package/src/build.ts +2 -2
- package/src/constants.ts +0 -10
- package/src/defineGenerator.ts +7 -0
- package/src/defineResolver.ts +1 -10
- package/src/hooks/useDriver.ts +1 -3
- package/src/index.ts +0 -2
- package/src/renderNode.tsx +9 -6
- package/src/types.ts +29 -18
- package/src/utils/getConfigs.ts +1 -1
- package/src/utils/getPreset.ts +3 -3
- package/src/defineBuilder.ts +0 -26
- package/src/definePreset.ts +0 -27
package/src/types.ts
CHANGED
|
@@ -254,7 +254,7 @@ export type Config<TInput = Input> = {
|
|
|
254
254
|
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
255
255
|
* If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
|
|
256
256
|
*/
|
|
257
|
-
plugins
|
|
257
|
+
plugins: Array<Plugin>
|
|
258
258
|
/**
|
|
259
259
|
* Devtools configuration for Kubb Studio integration.
|
|
260
260
|
*/
|
|
@@ -349,15 +349,6 @@ export type Resolver = {
|
|
|
349
349
|
*/
|
|
350
350
|
export type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>
|
|
351
351
|
|
|
352
|
-
/**
|
|
353
|
-
* Base type for plugin builder objects.
|
|
354
|
-
* Concrete plugin builder types extend this with their own schema-building helpers.
|
|
355
|
-
* Use `defineBuilder` to define a builder object and export it alongside the plugin.
|
|
356
|
-
*/
|
|
357
|
-
export type Builder = {
|
|
358
|
-
name: string
|
|
359
|
-
}
|
|
360
|
-
|
|
361
352
|
export type PluginFactoryOptions<
|
|
362
353
|
/**
|
|
363
354
|
* Name to be used for the plugin.
|
|
@@ -384,11 +375,6 @@ export type PluginFactoryOptions<
|
|
|
384
375
|
* Use `defineResolver` to define the resolver object and export it alongside the plugin.
|
|
385
376
|
*/
|
|
386
377
|
TResolver extends Resolver = Resolver,
|
|
387
|
-
/**
|
|
388
|
-
* Builder object that encapsulates the schema-building helpers used by this plugin.
|
|
389
|
-
* Use `defineBuilder` to define the builder object and export it alongside the plugin.
|
|
390
|
-
*/
|
|
391
|
-
TBuilder extends Builder = Builder,
|
|
392
378
|
> = {
|
|
393
379
|
name: TName
|
|
394
380
|
options: TOptions
|
|
@@ -396,7 +382,6 @@ export type PluginFactoryOptions<
|
|
|
396
382
|
context: TContext
|
|
397
383
|
resolvePathOptions: TResolvePathOptions
|
|
398
384
|
resolver: TResolver
|
|
399
|
-
builder: TBuilder
|
|
400
385
|
}
|
|
401
386
|
|
|
402
387
|
export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
@@ -410,6 +395,10 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
410
395
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
411
396
|
*/
|
|
412
397
|
options: TOptions['resolvedOptions']
|
|
398
|
+
/**
|
|
399
|
+
* The resolver for this plugin, accessible via `driver.getPluginByName(name)?.resolver`.
|
|
400
|
+
*/
|
|
401
|
+
resolver?: TOptions['resolver']
|
|
413
402
|
/**
|
|
414
403
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
415
404
|
* Can be used to validate dependent plugins.
|
|
@@ -445,6 +434,10 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
445
434
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
446
435
|
*/
|
|
447
436
|
options: TOptions['resolvedOptions']
|
|
437
|
+
/**
|
|
438
|
+
* The resolver for this plugin, accessible via `driver.getPluginByName(name)?.resolver`.
|
|
439
|
+
*/
|
|
440
|
+
resolver: TOptions['resolver']
|
|
448
441
|
|
|
449
442
|
install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>
|
|
450
443
|
/**
|
|
@@ -516,6 +509,7 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
516
509
|
fabric: FabricType
|
|
517
510
|
config: Config
|
|
518
511
|
driver: PluginDriver
|
|
512
|
+
getPlugin: PluginDriver['getPlugin']
|
|
519
513
|
/**
|
|
520
514
|
* Only add when the file does not exist yet
|
|
521
515
|
*/
|
|
@@ -525,11 +519,14 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
525
519
|
*/
|
|
526
520
|
upsertFile: (...file: Array<FabricFile.File>) => Promise<void>
|
|
527
521
|
events: AsyncEventEmitter<KubbEvents>
|
|
528
|
-
mode: FabricFile.Mode
|
|
529
522
|
/**
|
|
530
523
|
* Current plugin
|
|
531
524
|
*/
|
|
532
525
|
plugin: Plugin<TOptions>
|
|
526
|
+
/**
|
|
527
|
+
* Resolver for the current plugin. Shorthand for `plugin.resolver`.
|
|
528
|
+
*/
|
|
529
|
+
resolver: TOptions['resolver']
|
|
533
530
|
|
|
534
531
|
/**
|
|
535
532
|
* Opens the Kubb Studio URL for the current `rootNode` in the default browser.
|
|
@@ -583,7 +580,7 @@ export type Output<_TOptions = unknown> = {
|
|
|
583
580
|
override?: boolean
|
|
584
581
|
}
|
|
585
582
|
|
|
586
|
-
export type
|
|
583
|
+
export type UserGroup = {
|
|
587
584
|
/**
|
|
588
585
|
* Defines the type where to group the files.
|
|
589
586
|
* - 'tag' groups files by OpenAPI tags.
|
|
@@ -597,6 +594,20 @@ export type Group = {
|
|
|
597
594
|
name?: (context: { group: string }) => string
|
|
598
595
|
}
|
|
599
596
|
|
|
597
|
+
export type Group = {
|
|
598
|
+
/**
|
|
599
|
+
* Defines the type where to group the files.
|
|
600
|
+
* - 'tag' groups files by OpenAPI tags.
|
|
601
|
+
* - 'path' groups files by OpenAPI paths.
|
|
602
|
+
* @default undefined
|
|
603
|
+
*/
|
|
604
|
+
type: 'tag' | 'path'
|
|
605
|
+
/**
|
|
606
|
+
* Return the name of a group based on the group name, this is used for the file and name generation.
|
|
607
|
+
*/
|
|
608
|
+
name: (context: { group: string }) => string
|
|
609
|
+
}
|
|
610
|
+
|
|
600
611
|
export type LoggerOptions = {
|
|
601
612
|
/**
|
|
602
613
|
* @default 3
|
package/src/utils/getConfigs.ts
CHANGED
|
@@ -12,5 +12,5 @@ export async function getConfigs(config: ConfigInput | UserConfig, args: CLIOpti
|
|
|
12
12
|
const resolved = await (typeof config === 'function' ? config(args as CLIOptions) : config)
|
|
13
13
|
const userConfigs = Array.isArray(resolved) ? resolved : [resolved]
|
|
14
14
|
|
|
15
|
-
return userConfigs.map((item) => ({ ...item }) as Config)
|
|
15
|
+
return userConfigs.map((item) => ({ plugins: [], ...item }) as Config)
|
|
16
16
|
}
|
package/src/utils/getPreset.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { mergeResolvers } from './mergeResolvers.ts'
|
|
|
5
5
|
type GetPresetParams<TResolver extends Resolver> = {
|
|
6
6
|
preset: CompatibilityPreset
|
|
7
7
|
presets: Presets<TResolver>
|
|
8
|
-
resolvers
|
|
8
|
+
resolvers?: Array<TResolver>
|
|
9
9
|
/**
|
|
10
10
|
* User-supplied generators to append after the preset's generators.
|
|
11
11
|
*/
|
|
12
|
-
generators
|
|
12
|
+
generators?: Array<Generator<any>>
|
|
13
13
|
transformers?: Array<Visitor>
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -29,7 +29,7 @@ type GetPresetResult<TResolver extends Resolver> = {
|
|
|
29
29
|
* - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
|
|
30
30
|
*/
|
|
31
31
|
export function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver> {
|
|
32
|
-
const { preset: presetName, presets, resolvers, transformers: userTransformers, generators: userGenerators } = params
|
|
32
|
+
const { preset: presetName, presets, resolvers = [], transformers: userTransformers = [], generators: userGenerators = [] } = params
|
|
33
33
|
const [defaultResolver, ...userResolvers] = resolvers
|
|
34
34
|
const preset = presets[presetName]
|
|
35
35
|
|
package/src/defineBuilder.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { PluginFactoryOptions } from './types.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Builder type for the plugin-specific builder fields.
|
|
5
|
-
* `name` is required; all other methods are defined by the concrete plugin builder type.
|
|
6
|
-
*/
|
|
7
|
-
type BuilderBuilder<T extends PluginFactoryOptions> = () => T['builder'] & ThisType<T['builder']>
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Defines a builder for a plugin — a named collection of schema-building helpers that
|
|
11
|
-
* can be exported alongside the plugin and imported by other plugins or generators.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* export const builder = defineBuilder<PluginTs>(() => ({
|
|
15
|
-
* name: 'default',
|
|
16
|
-
* buildParamsSchema({ params, node, resolver }) {
|
|
17
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
18
|
-
* },
|
|
19
|
-
* buildDataSchemaNode({ node, resolver }) {
|
|
20
|
-
* return createSchema({ type: 'object', properties: [] })
|
|
21
|
-
* },
|
|
22
|
-
* }))
|
|
23
|
-
*/
|
|
24
|
-
export function defineBuilder<T extends PluginFactoryOptions>(build: BuilderBuilder<T>): T['builder'] {
|
|
25
|
-
return build() as T['builder']
|
|
26
|
-
}
|
package/src/definePreset.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Visitor } from '@kubb/ast/types'
|
|
2
|
-
import type { Generator, Preset, Resolver } from './types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a typed preset object that bundles a name, resolvers, optional
|
|
6
|
-
* transformers, and optional generators — the building block for composable plugin presets.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* import { definePreset } from '@kubb/core'
|
|
10
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
11
|
-
*
|
|
12
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy] })
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // With custom transformers
|
|
16
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], transformers: [myTransformer] })
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // With generators
|
|
20
|
-
* export const myPreset = definePreset('myPreset', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] })
|
|
21
|
-
*/
|
|
22
|
-
export function definePreset<TResolver extends Resolver = Resolver, TName extends string = string>(
|
|
23
|
-
name: TName,
|
|
24
|
-
{ resolvers, transformers, generators }: { resolvers: Array<TResolver>; transformers?: Array<Visitor>; generators?: Array<Generator<any>> },
|
|
25
|
-
): Preset<TResolver> & { name: TName } {
|
|
26
|
-
return { name, resolvers, transformers, generators }
|
|
27
|
-
}
|