@kubb/core 5.0.0-alpha.9 → 5.0.0-beta.10
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/README.md +13 -40
- package/dist/PluginDriver-Cu1Kj9S-.cjs +1075 -0
- package/dist/PluginDriver-Cu1Kj9S-.cjs.map +1 -0
- package/dist/PluginDriver-D8Z0Htid.js +978 -0
- package/dist/PluginDriver-D8Z0Htid.js.map +1 -0
- package/dist/createKubb-ALdb8lmq.d.ts +2082 -0
- package/dist/index.cjs +747 -1667
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +175 -269
- package/dist/index.js +734 -1638
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +145 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +80 -0
- package/dist/mocks.js +140 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +47 -60
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/PluginDriver.ts +355 -561
- package/src/constants.ts +21 -48
- package/src/createAdapter.ts +88 -5
- package/src/createKubb.ts +1266 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +13 -1
- package/src/defineGenerator.ts +160 -119
- package/src/defineLogger.ts +46 -5
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +379 -0
- package/src/defineResolver.ts +548 -25
- package/src/devtools.ts +22 -15
- package/src/index.ts +13 -15
- package/src/mocks.ts +177 -0
- package/src/storages/fsStorage.ts +13 -8
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +40 -547
- package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -103
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -77
- package/dist/hooks.js +0 -98
- package/dist/hooks.js.map +0 -1
- package/src/Kubb.ts +0 -224
- package/src/build.ts +0 -418
- package/src/config.ts +0 -56
- package/src/createPlugin.ts +0 -28
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -143
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginDriver.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/TreeNode.ts +0 -215
- package/src/utils/diagnostics.ts +0 -15
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getBarrelFiles.ts +0 -141
- package/src/utils/getConfigs.ts +0 -12
- package/src/utils/linters.ts +0 -25
- package/src/utils/packageJSON.ts +0 -61
package/src/constants.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FileNode } from '@kubb/ast'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Base URL for the Kubb Studio web app.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_STUDIO_URL = 'https://kubb.studio' as const
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const DEFAULT_CONCURRENCY = 15
|
|
10
|
-
|
|
11
|
-
export const BARREL_FILENAME = 'index.ts' as const
|
|
8
|
+
/**
|
|
9
|
+
* Maximum number of files processed in parallel by FileProcessor.
|
|
10
|
+
*/
|
|
11
|
+
export const PARALLEL_CONCURRENCY_LIMIT = 100
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Default banner style written at the top of every generated file.
|
|
15
|
+
*/
|
|
13
16
|
export const DEFAULT_BANNER = 'simple' as const
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Default file-extension mapping used when no explicit mapping is configured.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_EXTENSION: Record<FileNode['extname'], FileNode['extname'] | ''> = { '.ts': '.ts' }
|
|
18
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Numeric log-level thresholds used internally to compare verbosity.
|
|
25
|
+
*
|
|
26
|
+
* Higher numbers are more verbose.
|
|
27
|
+
*/
|
|
19
28
|
export const logLevel = {
|
|
20
29
|
silent: Number.NEGATIVE_INFINITY,
|
|
21
30
|
error: 0,
|
|
@@ -24,39 +33,3 @@ export const logLevel = {
|
|
|
24
33
|
verbose: 4,
|
|
25
34
|
debug: 5,
|
|
26
35
|
} as const
|
|
27
|
-
|
|
28
|
-
export const linters = {
|
|
29
|
-
eslint: {
|
|
30
|
-
command: 'eslint',
|
|
31
|
-
args: (outputPath: string) => [outputPath, '--fix'],
|
|
32
|
-
errorMessage: 'Eslint not found',
|
|
33
|
-
},
|
|
34
|
-
biome: {
|
|
35
|
-
command: 'biome',
|
|
36
|
-
args: (outputPath: string) => ['lint', '--fix', outputPath],
|
|
37
|
-
errorMessage: 'Biome not found',
|
|
38
|
-
},
|
|
39
|
-
oxlint: {
|
|
40
|
-
command: 'oxlint',
|
|
41
|
-
args: (outputPath: string) => ['--fix', outputPath],
|
|
42
|
-
errorMessage: 'Oxlint not found',
|
|
43
|
-
},
|
|
44
|
-
} as const
|
|
45
|
-
|
|
46
|
-
export const formatters = {
|
|
47
|
-
prettier: {
|
|
48
|
-
command: 'prettier',
|
|
49
|
-
args: (outputPath: string) => ['--ignore-unknown', '--write', outputPath],
|
|
50
|
-
errorMessage: 'Prettier not found',
|
|
51
|
-
},
|
|
52
|
-
biome: {
|
|
53
|
-
command: 'biome',
|
|
54
|
-
args: (outputPath: string) => ['format', '--write', outputPath],
|
|
55
|
-
errorMessage: 'Biome not found',
|
|
56
|
-
},
|
|
57
|
-
oxfmt: {
|
|
58
|
-
command: 'oxfmt',
|
|
59
|
-
args: (outputPath: string) => [outputPath],
|
|
60
|
-
errorMessage: 'Oxfmt not found',
|
|
61
|
-
},
|
|
62
|
-
} as const
|
package/src/createAdapter.ts
CHANGED
|
@@ -1,24 +1,107 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PossiblePromise } from '@internals/utils'
|
|
2
|
+
import type { ImportNode, InputNode, SchemaNode } from '@kubb/ast'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Source data passed to an adapter's `parse` function.
|
|
6
|
+
* Mirrors the config input shape with paths resolved to absolute.
|
|
5
7
|
*/
|
|
8
|
+
export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generic type parameters for an adapter definition.
|
|
12
|
+
*
|
|
13
|
+
* - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
14
|
+
* - `TOptions` — user-facing options passed to the adapter factory
|
|
15
|
+
* - `TResolvedOptions` — options after defaults applied
|
|
16
|
+
* - `TDocument` — type of the parsed source document
|
|
17
|
+
*/
|
|
18
|
+
export type AdapterFactoryOptions<
|
|
19
|
+
TName extends string = string,
|
|
20
|
+
TOptions extends object = object,
|
|
21
|
+
TResolvedOptions extends object = TOptions,
|
|
22
|
+
TDocument = unknown,
|
|
23
|
+
> = {
|
|
24
|
+
name: TName
|
|
25
|
+
options: TOptions
|
|
26
|
+
resolvedOptions: TResolvedOptions
|
|
27
|
+
document: TDocument
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Adapter that converts input files or data into an `InputNode`.
|
|
32
|
+
*
|
|
33
|
+
* Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
|
|
34
|
+
* universal intermediate representation that all plugins consume.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
39
|
+
*
|
|
40
|
+
* export default defineConfig({
|
|
41
|
+
* adapter: adapterOas(),
|
|
42
|
+
* input: { path: './openapi.yaml' },
|
|
43
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
48
|
+
/**
|
|
49
|
+
* Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
|
|
50
|
+
*/
|
|
51
|
+
name: TOptions['name']
|
|
52
|
+
/**
|
|
53
|
+
* Resolved adapter options after defaults have been applied.
|
|
54
|
+
*/
|
|
55
|
+
options: TOptions['resolvedOptions']
|
|
56
|
+
/**
|
|
57
|
+
* Parsed source document after the first `parse()` call. `null` before parsing.
|
|
58
|
+
*/
|
|
59
|
+
document: TOptions['document'] | null
|
|
60
|
+
inputNode: InputNode | null
|
|
61
|
+
/**
|
|
62
|
+
* Parse the source into a universal `InputNode`.
|
|
63
|
+
*/
|
|
64
|
+
parse: (source: AdapterSource) => PossiblePromise<InputNode>
|
|
65
|
+
/**
|
|
66
|
+
* Extract `ImportNode` entries for a schema tree.
|
|
67
|
+
* Returns an empty array before the first `parse()` call.
|
|
68
|
+
*
|
|
69
|
+
* The `resolve` callback receives the collision-corrected schema name and must
|
|
70
|
+
* return `{ name, path }` for the import, or `undefined` to skip it.
|
|
71
|
+
*/
|
|
72
|
+
getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
|
|
73
|
+
/**
|
|
74
|
+
* Validate the document at the given path or URL.
|
|
75
|
+
*/
|
|
76
|
+
validate: (input: string, options?: { throwOnError?: boolean }) => Promise<void>
|
|
77
|
+
}
|
|
78
|
+
|
|
6
79
|
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>
|
|
7
80
|
|
|
8
81
|
/**
|
|
9
|
-
*
|
|
82
|
+
* Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.
|
|
83
|
+
*
|
|
84
|
+
* Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.
|
|
85
|
+
* Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.
|
|
86
|
+
*
|
|
87
|
+
* @note Adapters must parse their input format to Kubb's `InputNode` structure.
|
|
10
88
|
*
|
|
11
89
|
* @example
|
|
90
|
+
* ```ts
|
|
12
91
|
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
13
92
|
* return {
|
|
14
93
|
* name: 'my-adapter',
|
|
15
94
|
* options,
|
|
16
|
-
* async parse(source) {
|
|
95
|
+
* async parse(source) {
|
|
96
|
+
* // Transform source format to InputNode
|
|
97
|
+
* return { ... }
|
|
98
|
+
* },
|
|
17
99
|
* }
|
|
18
100
|
* })
|
|
19
101
|
*
|
|
20
|
-
* //
|
|
102
|
+
* // Instantiate:
|
|
21
103
|
* const adapter = myAdapter({ validate: true })
|
|
104
|
+
* ```
|
|
22
105
|
*/
|
|
23
106
|
export function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T> {
|
|
24
107
|
return (options) => build(options ?? ({} as T['options']))
|