@kubb/core 5.0.0-alpha.35 → 5.0.0-alpha.38
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-BQwm8hDd.cjs +1729 -0
- package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
- package/dist/PluginDriver-CgXFtmNP.js +1617 -0
- package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
- package/dist/index.cjs +149 -2142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -317
- package/dist/index.js +142 -2110
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +164 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/dist/{PluginDriver-D8lWvtUg.d.ts → types-DUc5lEUp.d.ts} +597 -716
- package/package.json +9 -9
- package/src/PluginDriver.ts +18 -17
- package/src/constants.ts +0 -48
- package/src/createKubb.ts +1 -1
- package/src/defineResolver.ts +3 -3
- package/src/index.ts +5 -20
- package/src/mocks.ts +234 -0
- package/src/types.ts +4 -13
- package/src/utils/TreeNode.ts +3 -3
- package/src/utils/executeStrategies.ts +0 -16
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -32
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -23
- package/dist/hooks.js +0 -29
- package/dist/hooks.js.map +0 -1
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useDriver.ts +0 -9
- package/src/hooks/useMode.ts +0 -8
- package/src/hooks/usePlugin.ts +0 -9
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/formatters.ts +0 -45
- package/src/utils/getFunctionParams.ts +0 -254
- package/src/utils/linters.ts +0 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.38",
|
|
4
4
|
"description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"import": "./dist/index.js",
|
|
32
32
|
"require": "./dist/index.cjs"
|
|
33
33
|
},
|
|
34
|
-
"./
|
|
35
|
-
"import": "./dist/
|
|
36
|
-
"require": "./dist/
|
|
34
|
+
"./mocks": {
|
|
35
|
+
"import": "./dist/mocks.js",
|
|
36
|
+
"require": "./dist/mocks.cjs"
|
|
37
37
|
},
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"types": "./dist/index.d.ts",
|
|
41
41
|
"typesVersions": {
|
|
42
42
|
"*": {
|
|
43
|
-
"
|
|
44
|
-
"./dist/
|
|
43
|
+
"mocks": [
|
|
44
|
+
"./dist/mocks.d.ts"
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"remeda": "^2.33.7",
|
|
69
69
|
"semver": "^7.7.4",
|
|
70
70
|
"tinyexec": "^1.1.1",
|
|
71
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
72
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
71
|
+
"@kubb/ast": "5.0.0-alpha.38",
|
|
72
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.38"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/semver": "^7.7.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@internals/utils": "0.0.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@kubb/renderer-jsx": "5.0.0-alpha.
|
|
80
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.38"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=22"
|
package/src/PluginDriver.ts
CHANGED
|
@@ -73,21 +73,6 @@ export type GetFileOptions<TOptions = object> = {
|
|
|
73
73
|
options?: TOptions
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/**
|
|
77
|
-
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* getMode('src/gen/types.ts') // 'single'
|
|
82
|
-
* getMode('src/gen/types') // 'split'
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export function getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {
|
|
86
|
-
if (!fileOrFolder) {
|
|
87
|
-
return 'split'
|
|
88
|
-
}
|
|
89
|
-
return extname(fileOrFolder) ? 'single' : 'split'
|
|
90
|
-
}
|
|
91
76
|
|
|
92
77
|
const hookFirstNullCheck = (state: unknown) => !!(state as SafeParseResult<'resolveName'> | null)?.result
|
|
93
78
|
|
|
@@ -95,6 +80,22 @@ export class PluginDriver {
|
|
|
95
80
|
readonly config: Config
|
|
96
81
|
readonly options: Options
|
|
97
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* PluginDriver.getMode('src/gen/types.ts') // 'single'
|
|
89
|
+
* PluginDriver.getMode('src/gen/types') // 'split'
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
static getMode(fileOrFolder: string | undefined | null): 'single' | 'split' {
|
|
93
|
+
if (!fileOrFolder) {
|
|
94
|
+
return 'split'
|
|
95
|
+
}
|
|
96
|
+
return extname(fileOrFolder) ? 'single' : 'split'
|
|
97
|
+
}
|
|
98
|
+
|
|
98
99
|
/**
|
|
99
100
|
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
100
101
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
@@ -301,7 +302,7 @@ export class PluginDriver {
|
|
|
301
302
|
*
|
|
302
303
|
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
303
304
|
*/
|
|
304
|
-
registerGenerator(pluginName: string, gen: Generator
|
|
305
|
+
registerGenerator(pluginName: string, gen: Generator): void {
|
|
305
306
|
const resolveRenderer = () => {
|
|
306
307
|
const plugin = this.plugins.get(pluginName)
|
|
307
308
|
return gen.renderer === null ? undefined : (gen.renderer ?? plugin?.renderer ?? this.config.renderer)
|
|
@@ -422,7 +423,7 @@ export class PluginDriver {
|
|
|
422
423
|
return resolve(driver.config.root, driver.config.output.path)
|
|
423
424
|
},
|
|
424
425
|
getMode(output: { path: string }): 'single' | 'split' {
|
|
425
|
-
return getMode(resolve(driver.config.root, driver.config.output.path, output.path))
|
|
426
|
+
return PluginDriver.getMode(resolve(driver.config.root, driver.config.output.path, output.path))
|
|
426
427
|
},
|
|
427
428
|
hooks: driver.hooks,
|
|
428
429
|
plugin,
|
package/src/constants.ts
CHANGED
|
@@ -49,52 +49,4 @@ export const logLevel = {
|
|
|
49
49
|
debug: 5,
|
|
50
50
|
} as const
|
|
51
51
|
|
|
52
|
-
/**
|
|
53
|
-
* CLI command descriptors for each supported linter.
|
|
54
|
-
*
|
|
55
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
56
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
57
|
-
* the linter is not found.
|
|
58
|
-
*/
|
|
59
|
-
export const linters = {
|
|
60
|
-
eslint: {
|
|
61
|
-
command: 'eslint',
|
|
62
|
-
args: (outputPath: string) => [outputPath, '--fix'],
|
|
63
|
-
errorMessage: 'Eslint not found',
|
|
64
|
-
},
|
|
65
|
-
biome: {
|
|
66
|
-
command: 'biome',
|
|
67
|
-
args: (outputPath: string) => ['lint', '--fix', outputPath],
|
|
68
|
-
errorMessage: 'Biome not found',
|
|
69
|
-
},
|
|
70
|
-
oxlint: {
|
|
71
|
-
command: 'oxlint',
|
|
72
|
-
args: (outputPath: string) => ['--fix', outputPath],
|
|
73
|
-
errorMessage: 'Oxlint not found',
|
|
74
|
-
},
|
|
75
|
-
} as const
|
|
76
52
|
|
|
77
|
-
/**
|
|
78
|
-
* CLI command descriptors for each supported code formatter.
|
|
79
|
-
*
|
|
80
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
81
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
82
|
-
* the formatter is not found.
|
|
83
|
-
*/
|
|
84
|
-
export const formatters = {
|
|
85
|
-
prettier: {
|
|
86
|
-
command: 'prettier',
|
|
87
|
-
args: (outputPath: string) => ['--ignore-unknown', '--write', outputPath],
|
|
88
|
-
errorMessage: 'Prettier not found',
|
|
89
|
-
},
|
|
90
|
-
biome: {
|
|
91
|
-
command: 'biome',
|
|
92
|
-
args: (outputPath: string) => ['format', '--write', outputPath],
|
|
93
|
-
errorMessage: 'Biome not found',
|
|
94
|
-
},
|
|
95
|
-
oxfmt: {
|
|
96
|
-
command: 'oxfmt',
|
|
97
|
-
args: (outputPath: string) => [outputPath],
|
|
98
|
-
errorMessage: 'Oxfmt not found',
|
|
99
|
-
},
|
|
100
|
-
} as const
|
package/src/createKubb.ts
CHANGED
|
@@ -187,7 +187,7 @@ async function runPluginAstHooks(plugin: Plugin, context: PluginContext): Promis
|
|
|
187
187
|
throw new Error(`[${plugin.name}] No adapter found. Add an OAS adapter (e.g. pluginOas()) before this plugin in your Kubb config.`)
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
function resolveRenderer(gen: Generator
|
|
190
|
+
function resolveRenderer(gen: Generator): RendererFactory | undefined {
|
|
191
191
|
return gen.renderer === null ? undefined : (gen.renderer ?? plugin.renderer ?? context.config.renderer)
|
|
192
192
|
}
|
|
193
193
|
|
package/src/defineResolver.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path'
|
|
|
2
2
|
import { camelCase, pascalCase } from '@internals/utils'
|
|
3
3
|
import type { FileNode, InputNode, Node, OperationNode, SchemaNode } from '@kubb/ast'
|
|
4
4
|
import { createFile, isOperationNode, isSchemaNode } from '@kubb/ast'
|
|
5
|
-
import {
|
|
5
|
+
import { PluginDriver } from './PluginDriver.ts'
|
|
6
6
|
import type {
|
|
7
7
|
Config,
|
|
8
8
|
PluginFactoryOptions,
|
|
@@ -195,7 +195,7 @@ export function defaultResolveOptions<TOptions>(
|
|
|
195
195
|
* ```
|
|
196
196
|
*/
|
|
197
197
|
export function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }: ResolverPathParams, { root, output, group }: ResolverContext): string {
|
|
198
|
-
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
198
|
+
const mode = pathMode ?? PluginDriver.getMode(path.resolve(root, output.path))
|
|
199
199
|
|
|
200
200
|
if (mode === 'single') {
|
|
201
201
|
return path.resolve(root, output.path)
|
|
@@ -236,7 +236,7 @@ export function defaultResolvePath({ baseName, pathMode, tag, path: groupPath }:
|
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
238
|
export function defaultResolveFile(this: Resolver, { name, extname, tag, path: groupPath }: ResolverFileParams, context: ResolverContext): FileNode {
|
|
239
|
-
const pathMode = getMode(path.resolve(context.root, context.output.path))
|
|
239
|
+
const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))
|
|
240
240
|
const resolvedName = pathMode === 'single' ? '' : this.default(name, 'file')
|
|
241
241
|
const baseName = `${resolvedName}${extname}` as FileNode['baseName']
|
|
242
242
|
const filePath = this.resolvePath({ baseName, pathMode, tag, path: groupPath }, context)
|
package/src/index.ts
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
export { AsyncEventEmitter, URLPath } from '@internals/utils'
|
|
2
2
|
export * as ast from '@kubb/ast'
|
|
3
|
-
export {
|
|
4
|
-
export { formatters, linters, logLevel } from './constants.ts'
|
|
3
|
+
export { logLevel } from './constants.ts'
|
|
5
4
|
export { createAdapter } from './createAdapter.ts'
|
|
6
5
|
export { createKubb } from './createKubb.ts'
|
|
7
|
-
export { createPlugin } from './createPlugin.ts'
|
|
8
6
|
export { createRenderer } from './createRenderer.ts'
|
|
9
7
|
export { createStorage } from './createStorage.ts'
|
|
10
8
|
export { defineGenerator } from './defineGenerator.ts'
|
|
11
9
|
export { defineLogger } from './defineLogger.ts'
|
|
12
10
|
export { defineParser } from './defineParser.ts'
|
|
13
11
|
export { definePlugin } from './definePlugin.ts'
|
|
14
|
-
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
defaultResolveFooter,
|
|
19
|
-
defaultResolveOptions,
|
|
20
|
-
defaultResolvePath,
|
|
21
|
-
defineResolver,
|
|
22
|
-
} from './defineResolver.ts'
|
|
23
|
-
export { getMode, PluginDriver } from './PluginDriver.ts'
|
|
12
|
+
export { defineResolver } from './defineResolver.ts'
|
|
13
|
+
export { FileManager } from './FileManager.ts'
|
|
14
|
+
export { FileProcessor } from './FileProcessor.ts'
|
|
15
|
+
export { PluginDriver } from './PluginDriver.ts'
|
|
24
16
|
export { fsStorage } from './storages/fsStorage.ts'
|
|
25
17
|
export { memoryStorage } from './storages/memoryStorage.ts'
|
|
26
18
|
export * from './types.ts'
|
|
27
|
-
export type { FunctionParamsAST } from './utils/FunctionParams.ts'
|
|
28
|
-
export { detectFormatter } from './utils/formatters.ts'
|
|
29
|
-
export { getBarrelFiles } from './utils/getBarrelFiles.ts'
|
|
30
|
-
export type { Param, Params } from './utils/getFunctionParams.ts'
|
|
31
|
-
export { createFunctionParams, FunctionParams, getFunctionParams } from './utils/getFunctionParams.ts'
|
|
32
19
|
export { isInputPath } from './utils/isInputPath.ts'
|
|
33
|
-
export { detectLinter } from './utils/linters.ts'
|
|
34
|
-
export { satisfiesDependency } from './utils/packageJSON.ts'
|
package/src/mocks.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import type { FileNode, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
|
|
3
|
+
import { transform } from '@kubb/ast'
|
|
4
|
+
import { FileManager } from './FileManager.ts'
|
|
5
|
+
import { PluginDriver } from './PluginDriver.ts'
|
|
6
|
+
import { applyHookResult } from './renderNode.ts'
|
|
7
|
+
import type {
|
|
8
|
+
Adapter,
|
|
9
|
+
AdapterFactoryOptions,
|
|
10
|
+
Config,
|
|
11
|
+
Generator,
|
|
12
|
+
GeneratorContext,
|
|
13
|
+
Plugin,
|
|
14
|
+
PluginFactoryOptions,
|
|
15
|
+
ResolveNameParams,
|
|
16
|
+
ResolvePathParams,
|
|
17
|
+
} from './types.ts'
|
|
18
|
+
|
|
19
|
+
function toCamelOrPascal(text: string, pascal: boolean): string {
|
|
20
|
+
const normalized = text
|
|
21
|
+
.trim()
|
|
22
|
+
.replace(/([a-z\d])([A-Z])/g, '$1 $2')
|
|
23
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
24
|
+
.replace(/(\d)([a-z])/g, '$1 $2')
|
|
25
|
+
|
|
26
|
+
const words = normalized.split(/[\s\-_./\\:]+/).filter(Boolean)
|
|
27
|
+
|
|
28
|
+
return words
|
|
29
|
+
.map((word, i) => {
|
|
30
|
+
const allUpper = word.length > 1 && word === word.toUpperCase()
|
|
31
|
+
if (allUpper) return word
|
|
32
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)
|
|
33
|
+
return word.charAt(0).toUpperCase() + word.slice(1)
|
|
34
|
+
})
|
|
35
|
+
.join('')
|
|
36
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function camelCase(text: string): string {
|
|
40
|
+
return toCamelOrPascal(text, false)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pascalCase(text: string): string {
|
|
44
|
+
return toCamelOrPascal(text, true)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a minimal `PluginDriver` mock suitable for unit tests.
|
|
49
|
+
*/
|
|
50
|
+
export function createMockedPluginDriver(options: { name?: string; plugin?: Plugin; config?: Config } = {}): PluginDriver {
|
|
51
|
+
return {
|
|
52
|
+
resolveName: (result: ResolveNameParams) => {
|
|
53
|
+
if (result.type === 'file') {
|
|
54
|
+
return camelCase(options?.name || result.name)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (result.type === 'type') {
|
|
58
|
+
return pascalCase(result.name)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (result.type === 'function') {
|
|
62
|
+
return camelCase(result.name)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return camelCase(result.name)
|
|
66
|
+
},
|
|
67
|
+
config: options?.config ?? {
|
|
68
|
+
root: '.',
|
|
69
|
+
output: {
|
|
70
|
+
path: './path',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
resolvePath: ({ baseName }: ResolvePathParams) => baseName,
|
|
74
|
+
getFile: ({
|
|
75
|
+
name,
|
|
76
|
+
extname,
|
|
77
|
+
pluginName,
|
|
78
|
+
options: fileOptions,
|
|
79
|
+
}: {
|
|
80
|
+
name: string
|
|
81
|
+
extname: `.${string}`
|
|
82
|
+
pluginName: string
|
|
83
|
+
options?: { group?: { tag?: string; path?: string } }
|
|
84
|
+
}) => {
|
|
85
|
+
const baseName = `${name}${extname}`
|
|
86
|
+
const groupDir = fileOptions?.group?.tag ?? fileOptions?.group?.path?.split('/').filter(Boolean)[0]
|
|
87
|
+
const filePath = groupDir ? `${groupDir}/${baseName}` : baseName
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
path: filePath,
|
|
91
|
+
baseName,
|
|
92
|
+
meta: { pluginName },
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
getPlugin(_pluginName: Plugin['name']): Plugin | undefined {
|
|
96
|
+
return options?.plugin
|
|
97
|
+
},
|
|
98
|
+
fileManager: new FileManager(),
|
|
99
|
+
} as unknown as PluginDriver
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Creates a minimal `Adapter` mock suitable for unit tests.
|
|
104
|
+
*
|
|
105
|
+
* - `parse` returns an empty `InputNode` by default; override via `options.parse`.
|
|
106
|
+
* - `getImports` returns `[]` by default (single-file mode, no cross-file imports).
|
|
107
|
+
*/
|
|
108
|
+
export function createMockedAdapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions>(
|
|
109
|
+
options: {
|
|
110
|
+
name?: TOptions['name']
|
|
111
|
+
resolvedOptions?: TOptions['resolvedOptions']
|
|
112
|
+
inputNode?: Adapter<TOptions>['inputNode']
|
|
113
|
+
parse?: Adapter<TOptions>['parse']
|
|
114
|
+
getImports?: Adapter<TOptions>['getImports']
|
|
115
|
+
} = {},
|
|
116
|
+
): Adapter<TOptions> {
|
|
117
|
+
return {
|
|
118
|
+
name: (options.name ?? 'oas') as TOptions['name'],
|
|
119
|
+
options: (options.resolvedOptions ?? {}) as TOptions['resolvedOptions'],
|
|
120
|
+
inputNode: options.inputNode ?? null,
|
|
121
|
+
parse: options.parse ?? (async () => ({ kind: 'Input' as const, schemas: [], operations: [] })),
|
|
122
|
+
getImports: options.getImports ?? ((_node: SchemaNode, _resolve: (schemaName: string) => { name: string; path: string }) => []),
|
|
123
|
+
} as Adapter<TOptions>
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a minimal `Plugin` mock suitable for unit tests.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const plugin = createMockedPlugin<PluginTs>({ name: '@kubb/plugin-ts', options })
|
|
131
|
+
*/
|
|
132
|
+
export function createMockedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(params: {
|
|
133
|
+
name: TOptions['name']
|
|
134
|
+
options: TOptions['resolvedOptions']
|
|
135
|
+
resolver?: TOptions['resolver']
|
|
136
|
+
transformer?: Visitor
|
|
137
|
+
dependencies?: Array<string>
|
|
138
|
+
}): Plugin<TOptions> {
|
|
139
|
+
return {
|
|
140
|
+
name: params.name,
|
|
141
|
+
options: params.options,
|
|
142
|
+
resolver: params.resolver,
|
|
143
|
+
transformer: params.transformer,
|
|
144
|
+
dependencies: params.dependencies,
|
|
145
|
+
install: () => {},
|
|
146
|
+
inject: () => undefined as TOptions['context'],
|
|
147
|
+
} as unknown as Plugin<TOptions>
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type RenderGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
151
|
+
config: Config
|
|
152
|
+
adapter: Adapter
|
|
153
|
+
driver: PluginDriver
|
|
154
|
+
plugin: Plugin<TOptions>
|
|
155
|
+
options: TOptions['resolvedOptions']
|
|
156
|
+
resolver: TOptions['resolver']
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function createMockedPluginContext<TOptions extends PluginFactoryOptions>(opts: RenderGeneratorOptions<TOptions>): Omit<GeneratorContext<TOptions>, 'options'> {
|
|
160
|
+
const root = resolve(opts.config.root, opts.config.output.path)
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
config: opts.config,
|
|
164
|
+
root,
|
|
165
|
+
getMode: (output: { path: string }) => PluginDriver.getMode(resolve(root, output.path)),
|
|
166
|
+
adapter: opts.adapter,
|
|
167
|
+
resolver: opts.resolver,
|
|
168
|
+
plugin: opts.plugin,
|
|
169
|
+
driver: opts.driver,
|
|
170
|
+
inputNode: { kind: 'Input', schemas: [], operations: [] },
|
|
171
|
+
upsertFile: async (...files: Array<FileNode>) => opts.driver.fileManager.upsert(...files),
|
|
172
|
+
warn: (msg: string) => console.warn(msg),
|
|
173
|
+
error: (msg: string) => console.error(msg),
|
|
174
|
+
info: (msg: string) => console.info(msg),
|
|
175
|
+
openInStudio: async () => {},
|
|
176
|
+
} as unknown as Omit<GeneratorContext<TOptions>, 'options'>
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Renders a generator's `schema` method in a test context.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* await renderGeneratorSchema(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
184
|
+
* await matchFiles(driver.fileManager.files)
|
|
185
|
+
*/
|
|
186
|
+
export async function renderGeneratorSchema<TOptions extends PluginFactoryOptions>(
|
|
187
|
+
generator: Generator<TOptions>,
|
|
188
|
+
node: SchemaNode,
|
|
189
|
+
opts: RenderGeneratorOptions<TOptions>,
|
|
190
|
+
): Promise<void> {
|
|
191
|
+
if (!generator.schema) return
|
|
192
|
+
const context = createMockedPluginContext(opts)
|
|
193
|
+
const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node
|
|
194
|
+
const result = await generator.schema(transformedNode, { ...context, options: opts.options })
|
|
195
|
+
await applyHookResult(result, opts.driver, generator.renderer ?? undefined)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Renders a generator's `operation` method in a test context.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* await renderGeneratorOperation(typeGenerator, node, { config, adapter, driver, plugin, options, resolver })
|
|
203
|
+
* await matchFiles(driver.fileManager.files)
|
|
204
|
+
*/
|
|
205
|
+
export async function renderGeneratorOperation<TOptions extends PluginFactoryOptions>(
|
|
206
|
+
generator: Generator<TOptions>,
|
|
207
|
+
node: OperationNode,
|
|
208
|
+
opts: RenderGeneratorOptions<TOptions>,
|
|
209
|
+
): Promise<void> {
|
|
210
|
+
if (!generator.operation) return
|
|
211
|
+
const context = createMockedPluginContext(opts)
|
|
212
|
+
const transformedNode = opts.plugin.transformer ? transform(node, opts.plugin.transformer) : node
|
|
213
|
+
const result = await generator.operation(transformedNode, { ...context, options: opts.options })
|
|
214
|
+
await applyHookResult(result, opts.driver, generator.renderer ?? undefined)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Renders a generator's `operations` method in a test context.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* await renderGeneratorOperations(classClientGenerator, nodes, { config, adapter, driver, plugin, options, resolver })
|
|
222
|
+
* await matchFiles(driver.fileManager.files)
|
|
223
|
+
*/
|
|
224
|
+
export async function renderGeneratorOperations<TOptions extends PluginFactoryOptions>(
|
|
225
|
+
generator: Generator<TOptions>,
|
|
226
|
+
nodes: Array<OperationNode>,
|
|
227
|
+
opts: RenderGeneratorOptions<TOptions>,
|
|
228
|
+
): Promise<void> {
|
|
229
|
+
if (!generator.operations) return
|
|
230
|
+
const context = createMockedPluginContext(opts)
|
|
231
|
+
const transformedNodes = opts.plugin.transformer ? nodes.map((n) => transform(n, opts.plugin.transformer!)) : nodes
|
|
232
|
+
const result = await generator.operations(transformedNodes, { ...context, options: opts.options })
|
|
233
|
+
await applyHookResult(result, opts.driver, generator.renderer ?? undefined)
|
|
234
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
|
|
2
|
-
import type { FileNode, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
|
|
3
|
-
import type { HttpMethod } from '@kubb/oas'
|
|
2
|
+
import type { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
|
|
4
3
|
import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
|
|
5
4
|
import type { RendererFactory } from './createRenderer.ts'
|
|
6
5
|
import type { Storage } from './createStorage.ts'
|
|
@@ -436,7 +435,7 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
436
435
|
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
437
436
|
* when the plugin declares a renderer.
|
|
438
437
|
*/
|
|
439
|
-
generators?: Array<Generator
|
|
438
|
+
generators?: Array<Generator>
|
|
440
439
|
/**
|
|
441
440
|
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
442
441
|
* An error is returned if any required dependency plugin is missing.
|
|
@@ -556,7 +555,7 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
556
555
|
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
557
556
|
* when the plugin declares a renderer.
|
|
558
557
|
*/
|
|
559
|
-
generators?: Array<Generator
|
|
558
|
+
generators?: Array<Generator>
|
|
560
559
|
|
|
561
560
|
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>
|
|
562
561
|
/**
|
|
@@ -697,7 +696,7 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
697
696
|
/**
|
|
698
697
|
* Returns the output mode for the given output config.
|
|
699
698
|
* Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
|
|
700
|
-
* Shorthand for `getMode(path.resolve(this.root, output.path))`.
|
|
699
|
+
* Shorthand for `PluginDriver.getMode(path.resolve(this.root, output.path))`.
|
|
701
700
|
*/
|
|
702
701
|
getMode: (output: { path: string }) => 'single' | 'split'
|
|
703
702
|
driver: PluginDriver
|
|
@@ -1149,14 +1148,6 @@ export type PossibleConfig<TCliOptions = undefined> =
|
|
|
1149
1148
|
| PossiblePromise<Config | Config[]>
|
|
1150
1149
|
| ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
|
|
1151
1150
|
|
|
1152
|
-
/**
|
|
1153
|
-
* All accepted forms of a Kubb configuration.
|
|
1154
|
-
* @deprecated
|
|
1155
|
-
* Kept for backward compatibility. Prefer `PossibleConfig<CLIOptions>` in new code.
|
|
1156
|
-
*/
|
|
1157
|
-
export type ConfigInput = PossibleConfig<CLIOptions>
|
|
1158
|
-
|
|
1159
1151
|
export type { BuildOutput } from './createKubb.ts'
|
|
1160
1152
|
export type { Parser } from './defineParser.ts'
|
|
1161
|
-
export type { FunctionParamsAST } from './utils/FunctionParams.ts'
|
|
1162
1153
|
export type { FileMetaBase } from './utils/getBarrelFiles.ts'
|
package/src/utils/TreeNode.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import type { FileNode } from '@kubb/ast'
|
|
3
|
-
import {
|
|
3
|
+
import { PluginDriver } from '../PluginDriver.ts'
|
|
4
4
|
|
|
5
5
|
type BarrelData = {
|
|
6
6
|
file?: FileNode
|
|
@@ -155,7 +155,7 @@ export class TreeNode {
|
|
|
155
155
|
name: filteredTree.name,
|
|
156
156
|
path: filteredTree.path,
|
|
157
157
|
file: filteredTree.file,
|
|
158
|
-
type: getMode(filteredTree.path),
|
|
158
|
+
type: PluginDriver.getMode(filteredTree.path),
|
|
159
159
|
})
|
|
160
160
|
|
|
161
161
|
const recurse = (node: typeof treeNode, item: DirectoryTree) => {
|
|
@@ -163,7 +163,7 @@ export class TreeNode {
|
|
|
163
163
|
name: item.name,
|
|
164
164
|
path: item.path,
|
|
165
165
|
file: item.file,
|
|
166
|
-
type: getMode(item.path),
|
|
166
|
+
type: PluginDriver.getMode(item.path),
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
if (item.children?.length) {
|
|
@@ -82,19 +82,3 @@ export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TV
|
|
|
82
82
|
|
|
83
83
|
return Promise.allSettled(tasks) as TOutput
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Execution strategy used when dispatching plugin hook calls.
|
|
88
|
-
* @deprecated
|
|
89
|
-
*/
|
|
90
|
-
export type Strategy = 'seq' | 'first' | 'parallel'
|
|
91
|
-
|
|
92
|
-
type StrategyOutputMap<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = {
|
|
93
|
-
first: HookFirstOutput<TInput, TValue>
|
|
94
|
-
seq: SeqOutput<TInput, TValue>
|
|
95
|
-
parallel: HookParallelOutput<TInput, TValue>
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @deprecated
|
|
99
|
-
*/
|
|
100
|
-
export type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc<TValue, null>>, TValue> = StrategyOutputMap<TInput, TValue>[TStrategy]
|
package/dist/chunk-ByKO4r7w.cjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
-
value,
|
|
6
|
-
configurable: true
|
|
7
|
-
});
|
|
8
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
-
key = keys[i];
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: ((k) => from[k]).bind(null, key),
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
|
-
Object.defineProperty(exports, "__name", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function() {
|
|
30
|
-
return __name;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "__toESM", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function() {
|
|
36
|
-
return __toESM;
|
|
37
|
-
}
|
|
38
|
-
});
|
package/dist/hooks.cjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./chunk-ByKO4r7w.cjs");
|
|
3
|
-
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
4
|
-
//#region src/hooks/useDriver.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated use `driver` from the generator component props instead
|
|
7
|
-
*/
|
|
8
|
-
function useDriver() {
|
|
9
|
-
return (0, _kubb_renderer_jsx.inject)(_kubb_renderer_jsx.KubbContext).driver;
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/hooks/useMode.ts
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated use `mode` from the generator component props instead
|
|
15
|
-
*/
|
|
16
|
-
function useMode() {
|
|
17
|
-
return (0, _kubb_renderer_jsx.inject)(_kubb_renderer_jsx.KubbContext).mode;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/hooks/usePlugin.ts
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated use `plugin` from the generator component props instead
|
|
23
|
-
*/
|
|
24
|
-
function usePlugin() {
|
|
25
|
-
return (0, _kubb_renderer_jsx.inject)(_kubb_renderer_jsx.KubbContext).plugin;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
exports.useDriver = useDriver;
|
|
29
|
-
exports.useMode = useMode;
|
|
30
|
-
exports.usePlugin = usePlugin;
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=hooks.cjs.map
|
package/dist/hooks.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":["KubbContext","KubbContext","KubbContext"],"sources":["../src/hooks/useDriver.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts"],"sourcesContent":["import { inject, KubbContext } from '@kubb/renderer-jsx'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `driver` from the generator component props instead\n */\nexport function useDriver(): PluginDriver {\n return inject(KubbContext)!.driver as PluginDriver\n}\n","import { inject, KubbContext } from '@kubb/renderer-jsx'\n\n/**\n * @deprecated use `mode` from the generator component props instead\n */\nexport function useMode(): 'single' | 'split' {\n return inject(KubbContext)!.mode\n}\n","import { inject, KubbContext } from '@kubb/renderer-jsx'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use `plugin` from the generator component props instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n return inject(KubbContext)!.plugin as Plugin<TOptions>\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,YAA0B;AACxC,SAAA,GAAA,mBAAA,QAAcA,mBAAAA,YAAY,CAAE;;;;;;;ACF9B,SAAgB,UAA8B;AAC5C,SAAA,GAAA,mBAAA,QAAcC,mBAAAA,YAAY,CAAE;;;;;;;ACA9B,SAAgB,YAA4F;AAC1G,SAAA,GAAA,mBAAA,QAAcC,mBAAAA,YAAY,CAAE"}
|
package/dist/hooks.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as Plugin, M as PluginFactoryOptions, t as PluginDriver } from "./PluginDriver-D8lWvtUg.js";
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/useDriver.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated use `driver` from the generator component props instead
|
|
7
|
-
*/
|
|
8
|
-
declare function useDriver(): PluginDriver;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/hooks/useMode.d.ts
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated use `mode` from the generator component props instead
|
|
13
|
-
*/
|
|
14
|
-
declare function useMode(): 'single' | 'split';
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/hooks/usePlugin.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated use `plugin` from the generator component props instead
|
|
19
|
-
*/
|
|
20
|
-
declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { useDriver, useMode, usePlugin };
|
|
23
|
-
//# sourceMappingURL=hooks.d.ts.map
|