@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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { camelCase, pascalCase } from '@internals/utils'
|
|
2
|
+
import { isOperationNode, isSchemaNode } from '@kubb/ast'
|
|
3
|
+
import type { Node, OperationNode, SchemaNode } from '@kubb/ast/types'
|
|
4
|
+
import type { PluginFactoryOptions, ResolveNameParams, ResolveOptionsContext } from './types.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Builder type for the plugin-specific resolver fields.
|
|
8
|
+
* `default`, `resolveOptions`, and `name` are optional — built-in fallbacks are used when omitted.
|
|
9
|
+
*/
|
|
10
|
+
type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions' | 'name'> &
|
|
11
|
+
Partial<Pick<T['resolver'], 'default' | 'resolveOptions'>> & { name: string } & ThisType<T['resolver']>
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
|
|
15
|
+
*/
|
|
16
|
+
function matchesOperationPattern(node: OperationNode, type: string, pattern: string | RegExp): boolean {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'tag':
|
|
19
|
+
return node.tags.some((tag) => !!tag.match(pattern))
|
|
20
|
+
case 'operationId':
|
|
21
|
+
return !!node.operationId.match(pattern)
|
|
22
|
+
case 'path':
|
|
23
|
+
return !!node.path.match(pattern)
|
|
24
|
+
case 'method':
|
|
25
|
+
return !!(node.method.toLowerCase() as string).match(pattern)
|
|
26
|
+
default:
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a schema matches a pattern for a given filter type (`schemaName`).
|
|
33
|
+
* Returns `null` when the filter type doesn't apply to schemas.
|
|
34
|
+
*/
|
|
35
|
+
function matchesSchemaPattern(node: SchemaNode, type: string, pattern: string | RegExp): boolean | null {
|
|
36
|
+
switch (type) {
|
|
37
|
+
case 'schemaName':
|
|
38
|
+
return node.name ? !!node.name.match(pattern) : false
|
|
39
|
+
default:
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Default name resolver — `camelCase` for most types, `PascalCase` for `type`.
|
|
46
|
+
*/
|
|
47
|
+
function defaultResolver(name: ResolveNameParams['name'], type: ResolveNameParams['type']): string {
|
|
48
|
+
let resolvedName = camelCase(name)
|
|
49
|
+
|
|
50
|
+
if (type === 'file' || type === 'function') {
|
|
51
|
+
resolvedName = camelCase(name, {
|
|
52
|
+
isFile: type === 'file',
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (type === 'type') {
|
|
57
|
+
resolvedName = pascalCase(name)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return resolvedName
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Default option resolver — applies include/exclude filters and merges any matching override options.
|
|
65
|
+
* Returns `null` when the node is filtered out.
|
|
66
|
+
*/
|
|
67
|
+
export function defaultResolveOptions<TOptions>(
|
|
68
|
+
node: Node,
|
|
69
|
+
{ options, exclude = [], include, override = [] }: ResolveOptionsContext<TOptions>,
|
|
70
|
+
): TOptions | null {
|
|
71
|
+
if (isOperationNode(node)) {
|
|
72
|
+
const isExcluded = exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))
|
|
73
|
+
if (isExcluded) {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options
|
|
82
|
+
|
|
83
|
+
return { ...options, ...overrideOptions }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isSchemaNode(node)) {
|
|
87
|
+
if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) {
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (include) {
|
|
92
|
+
const results = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern))
|
|
93
|
+
const applicable = results.filter((r) => r !== null)
|
|
94
|
+
if (applicable.length > 0 && !applicable.includes(true)) {
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options
|
|
100
|
+
|
|
101
|
+
return { ...options, ...overrideOptions }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return options
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
|
|
109
|
+
* Override `default` or `resolveOptions` in the builder to customize the behavior.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
113
|
+
* name: 'default',
|
|
114
|
+
* resolveName(name) {
|
|
115
|
+
* return this.default(name, 'function')
|
|
116
|
+
* },
|
|
117
|
+
* resolveTypedName(name) {
|
|
118
|
+
* return this.default(name, 'type')
|
|
119
|
+
* },
|
|
120
|
+
* resolveParamName(node, param) {
|
|
121
|
+
* return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
|
|
122
|
+
* },
|
|
123
|
+
* }))
|
|
124
|
+
*/
|
|
125
|
+
export function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'] {
|
|
126
|
+
return {
|
|
127
|
+
default: defaultResolver,
|
|
128
|
+
resolveOptions: defaultResolveOptions,
|
|
129
|
+
...build(),
|
|
130
|
+
} as T['resolver']
|
|
131
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import type { RootNode } from '@kubb/ast/types'
|
|
3
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
5
|
+
import type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'
|
|
6
|
+
import type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'
|
|
7
|
+
|
|
8
|
+
type ResolvePathOptions = {
|
|
9
|
+
pluginName?: string
|
|
10
|
+
group?: {
|
|
11
|
+
tag?: string
|
|
12
|
+
path?: string
|
|
13
|
+
}
|
|
14
|
+
type?: ResolveNameParams['type']
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
18
|
+
plugin: Plugin<TOptions>
|
|
19
|
+
mode: KubbFile.Mode
|
|
20
|
+
config: Config
|
|
21
|
+
/**
|
|
22
|
+
* Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.
|
|
23
|
+
*/
|
|
24
|
+
getPluginByName: (pluginName?: string) => Plugin | undefined
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a file reference, defaulting `pluginName` to the current plugin.
|
|
27
|
+
*/
|
|
28
|
+
getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>
|
|
29
|
+
/**
|
|
30
|
+
* Resolves a name, defaulting `pluginName` to the current plugin.
|
|
31
|
+
* @deprecated user `resolver` from options instead
|
|
32
|
+
*/
|
|
33
|
+
resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a path, defaulting `pluginName` to the current plugin.
|
|
36
|
+
*/
|
|
37
|
+
resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path
|
|
38
|
+
/**
|
|
39
|
+
* Resolves the banner using the plugin's `output.banner` option.
|
|
40
|
+
* Falls back to the default "Generated by Kubb" banner when `output.banner` is unset.
|
|
41
|
+
* When `output.banner` is a function and no node is provided, returns the default banner.
|
|
42
|
+
*/
|
|
43
|
+
resolveBanner: (node?: RootNode) => string | undefined
|
|
44
|
+
/**
|
|
45
|
+
* Resolves the footer using the plugin's `output.footer` option.
|
|
46
|
+
* Returns `undefined` when no footer is configured.
|
|
47
|
+
* When `output.footer` is a function and no node is provided, returns `undefined`.
|
|
48
|
+
*/
|
|
49
|
+
resolveFooter: (node?: RootNode) => string | undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates the default "Generated by Kubb" banner from node metadata.
|
|
54
|
+
*/
|
|
55
|
+
function buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {
|
|
56
|
+
try {
|
|
57
|
+
let source = ''
|
|
58
|
+
if (Array.isArray(config.input)) {
|
|
59
|
+
const first = config.input[0]
|
|
60
|
+
if (first && 'path' in first) {
|
|
61
|
+
source = path.basename(first.path)
|
|
62
|
+
}
|
|
63
|
+
} else if ('path' in config.input) {
|
|
64
|
+
source = path.basename(config.input.path)
|
|
65
|
+
} else if ('data' in config.input) {
|
|
66
|
+
source = 'text content'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let banner = '/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n'
|
|
70
|
+
|
|
71
|
+
if (config.output.defaultBanner === 'simple') {
|
|
72
|
+
banner += '*/\n'
|
|
73
|
+
return banner
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (source) {
|
|
77
|
+
banner += `* Source: ${source}\n`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (title) {
|
|
81
|
+
banner += `* Title: ${title}\n`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (description) {
|
|
85
|
+
const formattedDescription = description.replace(/\n/gm, '\n* ')
|
|
86
|
+
banner += `* Description: ${formattedDescription}\n`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (version) {
|
|
90
|
+
banner += `* OpenAPI spec version: ${version}\n`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
banner += '*/\n'
|
|
94
|
+
return banner
|
|
95
|
+
} catch (_error) {
|
|
96
|
+
return '/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* React-Fabric hook that exposes the current plugin context inside a generator component.
|
|
102
|
+
*
|
|
103
|
+
* Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers
|
|
104
|
+
* (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that
|
|
105
|
+
* all default to the current plugin when no explicit `pluginName` is provided.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* function Operation({ node }: OperationProps) {
|
|
110
|
+
* const { config, resolvePath } = useKubb()
|
|
111
|
+
* const filePath = resolvePath({ baseName: node.operationId })
|
|
112
|
+
* return <File path={filePath}>...</File>
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {
|
|
117
|
+
const { meta } = useFabric<{
|
|
118
|
+
plugin: Plugin<TOptions>
|
|
119
|
+
mode: KubbFile.Mode
|
|
120
|
+
driver: PluginDriver
|
|
121
|
+
}>()
|
|
122
|
+
|
|
123
|
+
const config = meta.driver.config
|
|
124
|
+
const defaultPluginName = meta.plugin.name
|
|
125
|
+
|
|
126
|
+
const output = (
|
|
127
|
+
meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined
|
|
128
|
+
)?.output
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
plugin: meta.plugin as Plugin<TOptions>,
|
|
132
|
+
mode: meta.mode,
|
|
133
|
+
config,
|
|
134
|
+
getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),
|
|
135
|
+
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),
|
|
136
|
+
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),
|
|
137
|
+
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),
|
|
138
|
+
resolveBanner: (node?: RootNode) => {
|
|
139
|
+
if (typeof output?.banner === 'function') {
|
|
140
|
+
return node ? output.banner(node) : buildDefaultBanner({ config })
|
|
141
|
+
}
|
|
142
|
+
if (typeof output?.banner === 'string') {
|
|
143
|
+
return output.banner
|
|
144
|
+
}
|
|
145
|
+
if (config.output.defaultBanner === false) {
|
|
146
|
+
return undefined
|
|
147
|
+
}
|
|
148
|
+
return buildDefaultBanner({ config })
|
|
149
|
+
},
|
|
150
|
+
resolveFooter: (node?: RootNode) => {
|
|
151
|
+
if (typeof output?.footer === 'function') {
|
|
152
|
+
return node ? output.footer(node) : undefined
|
|
153
|
+
}
|
|
154
|
+
if (typeof output?.footer === 'string') {
|
|
155
|
+
return output.footer
|
|
156
|
+
}
|
|
157
|
+
return undefined
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/hooks/useMode.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import {
|
|
2
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use `useKubb` instead
|
|
6
|
+
*/
|
|
4
7
|
export function useMode(): KubbFile.Mode {
|
|
5
|
-
const { meta } =
|
|
8
|
+
const { meta } = useFabric<{ mode: KubbFile.Mode }>()
|
|
6
9
|
|
|
7
10
|
return meta.mode
|
|
8
11
|
}
|
package/src/hooks/usePlugin.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
2
2
|
import type { Plugin, PluginFactoryOptions } from '../types.ts'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use useKubb instead
|
|
6
|
+
*/
|
|
4
7
|
export function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {
|
|
5
|
-
const { meta } =
|
|
8
|
+
const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()
|
|
6
9
|
|
|
7
10
|
return meta.plugin
|
|
8
11
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useFabric } from '@kubb/react-fabric'
|
|
2
|
+
import type { PluginDriver } from '../PluginDriver.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use `useKubb` instead
|
|
6
|
+
*/
|
|
7
|
+
export function usePluginDriver(): PluginDriver {
|
|
8
|
+
const { meta } = useFabric<{ driver: PluginDriver }>()
|
|
9
|
+
|
|
10
|
+
return meta.driver
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,13 +3,16 @@ export { definePrinter } from '@kubb/ast'
|
|
|
3
3
|
export { build, build as default, safeBuild, setup } from './build.ts'
|
|
4
4
|
export { type CLIOptions, type ConfigInput, defineConfig, isInputPath } from './config.ts'
|
|
5
5
|
export { formatters, linters, logLevel } from './constants.ts'
|
|
6
|
-
export {
|
|
6
|
+
export { createAdapter } from './createAdapter.ts'
|
|
7
|
+
export { createPlugin } from './createPlugin.ts'
|
|
8
|
+
export { createStorage } from './createStorage.ts'
|
|
9
|
+
export { defineGenerator } from './defineGenerator.ts'
|
|
7
10
|
export { defineLogger } from './defineLogger.ts'
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export { getMode,
|
|
12
|
-
export {
|
|
11
|
+
export { definePreset } from './definePreset.ts'
|
|
12
|
+
export { definePresets } from './definePresets.ts'
|
|
13
|
+
export { defaultResolveOptions, defineResolver } from './defineResolver.ts'
|
|
14
|
+
export { getMode, PluginDriver } from './PluginDriver.ts'
|
|
15
|
+
export { renderOperation, renderOperations, renderSchema } from './renderNode.tsx'
|
|
13
16
|
export { fsStorage } from './storages/fsStorage.ts'
|
|
14
17
|
export { memoryStorage } from './storages/memoryStorage.ts'
|
|
15
18
|
export * from './types.ts'
|
|
@@ -19,4 +22,7 @@ export { detectFormatter } from './utils/formatters.ts'
|
|
|
19
22
|
export type { FileMetaBase } from './utils/getBarrelFiles.ts'
|
|
20
23
|
export { getBarrelFiles } from './utils/getBarrelFiles.ts'
|
|
21
24
|
export { getConfigs } from './utils/getConfigs.ts'
|
|
25
|
+
export { getPreset } from './utils/getPreset.ts'
|
|
22
26
|
export { detectLinter } from './utils/linters.ts'
|
|
27
|
+
export { mergeResolvers } from './utils/mergeResolvers.ts'
|
|
28
|
+
export { satisfiesDependency } from './utils/packageJSON.ts'
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { OperationNode, SchemaNode } from '@kubb/ast/types'
|
|
2
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
+
import { createReactFabric, Fabric } from '@kubb/react-fabric'
|
|
4
|
+
import type { Fabric as FabricType } from '@kubb/react-fabric/types'
|
|
5
|
+
import type { PluginDriver } from './PluginDriver.ts'
|
|
6
|
+
import type { Adapter, Config, Plugin, PluginFactoryOptions, ReactGeneratorV2 } from './types.ts'
|
|
7
|
+
|
|
8
|
+
type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = {
|
|
9
|
+
config: Config
|
|
10
|
+
fabric: FabricType
|
|
11
|
+
plugin: Plugin<TOptions>
|
|
12
|
+
Component: ReactGeneratorV2<TOptions>['Operations'] | undefined
|
|
13
|
+
adapter: Adapter
|
|
14
|
+
driver: PluginDriver
|
|
15
|
+
mode: KubbFile.Mode
|
|
16
|
+
options: TOptions['resolvedOptions']
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Renders a React component for a list of operation nodes (V2 generators).
|
|
21
|
+
*/
|
|
22
|
+
export async function renderOperations<TOptions extends PluginFactoryOptions>(
|
|
23
|
+
nodes: Array<OperationNode>,
|
|
24
|
+
options: BuildOperationsV2Options<TOptions>,
|
|
25
|
+
): Promise<void> {
|
|
26
|
+
const { config, fabric, plugin, Component, adapter } = options
|
|
27
|
+
|
|
28
|
+
if (!Component) {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const fabricChild = createReactFabric()
|
|
33
|
+
|
|
34
|
+
await fabricChild.render(
|
|
35
|
+
<Fabric meta={{ plugin }}>
|
|
36
|
+
<Component config={config} adapter={adapter} nodes={nodes} options={options.options} />
|
|
37
|
+
</Fabric>,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
41
|
+
fabricChild.unmount()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = {
|
|
45
|
+
config: Config
|
|
46
|
+
fabric: FabricType
|
|
47
|
+
plugin: Plugin<TOptions>
|
|
48
|
+
Component: ReactGeneratorV2<TOptions>['Operation'] | undefined
|
|
49
|
+
adapter: Adapter
|
|
50
|
+
driver: PluginDriver
|
|
51
|
+
mode: KubbFile.Mode
|
|
52
|
+
options: TOptions['resolvedOptions']
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Renders a React component for a single operation node (V2 generators).
|
|
57
|
+
*/
|
|
58
|
+
export async function renderOperation<TOptions extends PluginFactoryOptions>(node: OperationNode, options: BuildOperationV2Options<TOptions>): Promise<void> {
|
|
59
|
+
const { config, fabric, plugin, Component, adapter, driver, mode } = options
|
|
60
|
+
|
|
61
|
+
if (!Component) {
|
|
62
|
+
return undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fabricChild = createReactFabric()
|
|
66
|
+
|
|
67
|
+
await fabricChild.render(
|
|
68
|
+
<Fabric meta={{ plugin, driver, mode }}>
|
|
69
|
+
<Component config={config} adapter={adapter} node={node} options={options.options} />
|
|
70
|
+
</Fabric>,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
74
|
+
fabricChild.unmount()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = {
|
|
78
|
+
config: Config
|
|
79
|
+
fabric: FabricType
|
|
80
|
+
plugin: Plugin<TOptions>
|
|
81
|
+
Component: ReactGeneratorV2<TOptions>['Schema'] | undefined
|
|
82
|
+
adapter: Adapter
|
|
83
|
+
driver: PluginDriver
|
|
84
|
+
mode: KubbFile.Mode
|
|
85
|
+
options: TOptions['resolvedOptions']
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Renders a React component for a single schema node (V2 generators).
|
|
90
|
+
*/
|
|
91
|
+
export async function renderSchema<TOptions extends PluginFactoryOptions>(node: SchemaNode, options: BuildSchemaV2Options<TOptions>): Promise<void> {
|
|
92
|
+
const { config, fabric, plugin, Component, adapter, driver, mode } = options
|
|
93
|
+
|
|
94
|
+
if (!Component) {
|
|
95
|
+
return undefined
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const fabricChild = createReactFabric()
|
|
99
|
+
|
|
100
|
+
await fabricChild.render(
|
|
101
|
+
<Fabric meta={{ plugin, driver, mode }}>
|
|
102
|
+
<Component config={config} adapter={adapter} node={node} options={options.options} />
|
|
103
|
+
</Fabric>,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
107
|
+
fabricChild.unmount()
|
|
108
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { Dirent } from 'node:fs'
|
|
|
2
2
|
import { access, readdir, readFile, rm } from 'node:fs/promises'
|
|
3
3
|
import { join, resolve } from 'node:path'
|
|
4
4
|
import { clean, write } from '@internals/utils'
|
|
5
|
-
import {
|
|
5
|
+
import { createStorage } from '../createStorage.ts'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Built-in filesystem storage driver.
|
|
@@ -27,7 +27,7 @@ import { defineStorage } from '../defineStorage.ts'
|
|
|
27
27
|
* })
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export const fsStorage =
|
|
30
|
+
export const fsStorage = createStorage(() => ({
|
|
31
31
|
name: 'fs',
|
|
32
32
|
async hasItem(key: string) {
|
|
33
33
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStorage } from '../createStorage.ts'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* In-memory storage driver. Useful for testing and dry-run scenarios where
|
|
@@ -17,7 +17,7 @@ import { defineStorage } from '../defineStorage.ts'
|
|
|
17
17
|
* })
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export const memoryStorage =
|
|
20
|
+
export const memoryStorage = createStorage(() => {
|
|
21
21
|
const store = new Map<string, string>()
|
|
22
22
|
|
|
23
23
|
return {
|