@kubb/core 5.0.0-alpha.5 → 5.0.0-alpha.50
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 +3 -2
- package/dist/PluginDriver-DtwggkXg.cjs +1082 -0
- package/dist/PluginDriver-DtwggkXg.cjs.map +1 -0
- package/dist/PluginDriver-mXeqWp-U.js +979 -0
- package/dist/PluginDriver-mXeqWp-U.js.map +1 -0
- package/dist/index.cjs +1013 -1829
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +274 -265
- package/dist/index.js +1003 -1799
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +138 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +133 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-DfEv9d_c.d.ts +1721 -0
- package/package.json +51 -57
- package/src/FileManager.ts +133 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +154 -101
- package/src/PluginDriver.ts +418 -0
- package/src/constants.ts +43 -47
- package/src/createAdapter.ts +25 -0
- package/src/createKubb.ts +614 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +88 -100
- package/src/defineLogger.ts +13 -3
- package/src/defineParser.ts +45 -0
- package/src/definePlugin.ts +68 -7
- package/src/defineResolver.ts +501 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +12 -17
- package/src/mocks.ts +171 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +40 -11
- package/src/storages/memoryStorage.ts +4 -3
- package/src/types.ts +575 -205
- package/src/utils/TreeNode.ts +47 -9
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/getBarrelFiles.ts +94 -16
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +99 -0
- package/dist/PluginManager-vZodFEMe.d.ts +0 -1056
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -60
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -56
- package/dist/hooks.js +0 -56
- package/dist/hooks.js.map +0 -1
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PluginManager.ts +0 -667
- package/src/PromiseManager.ts +0 -40
- package/src/build.ts +0 -419
- package/src/config.ts +0 -56
- package/src/defineAdapter.ts +0 -22
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -46
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getConfigs.ts +0 -30
- package/src/utils/getPlugins.ts +0 -23
- package/src/utils/linters.ts +0 -25
- package/src/utils/resolveOptions.ts +0 -93
package/src/build.ts
DELETED
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
import { dirname, relative, resolve } from 'node:path'
|
|
2
|
-
import { AsyncEventEmitter, exists, formatMs, getElapsedMs, getRelativePath, URLPath } from '@internals/utils'
|
|
3
|
-
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
4
|
-
import { createFabric } from '@kubb/react-fabric'
|
|
5
|
-
import { typescriptParser } from '@kubb/react-fabric/parsers'
|
|
6
|
-
import { fsPlugin } from '@kubb/react-fabric/plugins'
|
|
7
|
-
import { isInputPath } from './config.ts'
|
|
8
|
-
import { BARREL_FILENAME, DEFAULT_BANNER, DEFAULT_CONCURRENCY, DEFAULT_EXTENSION, DEFAULT_STUDIO_URL } from './constants.ts'
|
|
9
|
-
import { BuildError } from './errors.ts'
|
|
10
|
-
import { PluginManager } from './PluginManager.ts'
|
|
11
|
-
import { fsStorage } from './storages/fsStorage.ts'
|
|
12
|
-
import type { AdapterSource, Config, DefineStorage, KubbEvents, Output, Plugin, UserConfig } from './types.ts'
|
|
13
|
-
import { getDiagnosticInfo } from './utils/diagnostics.ts'
|
|
14
|
-
import type { FileMetaBase } from './utils/getBarrelFiles.ts'
|
|
15
|
-
|
|
16
|
-
type BuildOptions = {
|
|
17
|
-
config: UserConfig
|
|
18
|
-
events?: AsyncEventEmitter<KubbEvents>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type BuildOutput = {
|
|
22
|
-
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
23
|
-
fabric: FabricType
|
|
24
|
-
files: Array<KubbFile.ResolvedFile>
|
|
25
|
-
pluginManager: PluginManager
|
|
26
|
-
pluginTimings: Map<string, number>
|
|
27
|
-
error?: Error
|
|
28
|
-
sources: Map<KubbFile.Path, string>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type SetupResult = {
|
|
32
|
-
events: AsyncEventEmitter<KubbEvents>
|
|
33
|
-
fabric: FabricType
|
|
34
|
-
pluginManager: PluginManager
|
|
35
|
-
sources: Map<KubbFile.Path, string>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function setup(options: BuildOptions): Promise<SetupResult> {
|
|
39
|
-
const { config: userConfig, events = new AsyncEventEmitter<KubbEvents>() } = options
|
|
40
|
-
|
|
41
|
-
const sources: Map<KubbFile.Path, string> = new Map<KubbFile.Path, string>()
|
|
42
|
-
const diagnosticInfo = getDiagnosticInfo()
|
|
43
|
-
|
|
44
|
-
if (Array.isArray(userConfig.input)) {
|
|
45
|
-
await events.emit('warn', 'This feature is still under development — use with caution')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
await events.emit('debug', {
|
|
49
|
-
date: new Date(),
|
|
50
|
-
logs: [
|
|
51
|
-
'Configuration:',
|
|
52
|
-
` • Name: ${userConfig.name || 'unnamed'}`,
|
|
53
|
-
` • Root: ${userConfig.root || process.cwd()}`,
|
|
54
|
-
` • Output: ${userConfig.output?.path || 'not specified'}`,
|
|
55
|
-
` • Plugins: ${userConfig.plugins?.length || 0}`,
|
|
56
|
-
'Output Settings:',
|
|
57
|
-
` • Storage: ${userConfig.output?.storage ? `custom(${userConfig.output.storage.name})` : userConfig.output?.write === false ? 'disabled' : 'filesystem (default)'}`,
|
|
58
|
-
` • Formatter: ${userConfig.output?.format || 'none'}`,
|
|
59
|
-
` • Linter: ${userConfig.output?.lint || 'none'}`,
|
|
60
|
-
'Environment:',
|
|
61
|
-
Object.entries(diagnosticInfo)
|
|
62
|
-
.map(([key, value]) => ` • ${key}: ${value}`)
|
|
63
|
-
.join('\n'),
|
|
64
|
-
],
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
if (isInputPath(userConfig) && !new URLPath(userConfig.input.path).isURL) {
|
|
69
|
-
await exists(userConfig.input.path)
|
|
70
|
-
|
|
71
|
-
await events.emit('debug', {
|
|
72
|
-
date: new Date(),
|
|
73
|
-
logs: [`✓ Input file validated: ${userConfig.input.path}`],
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
} catch (caughtError) {
|
|
77
|
-
if (isInputPath(userConfig)) {
|
|
78
|
-
const error = caughtError as Error
|
|
79
|
-
|
|
80
|
-
throw new Error(
|
|
81
|
-
`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`,
|
|
82
|
-
{
|
|
83
|
-
cause: error,
|
|
84
|
-
},
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const definedConfig: Config = {
|
|
90
|
-
root: userConfig.root || process.cwd(),
|
|
91
|
-
...userConfig,
|
|
92
|
-
output: {
|
|
93
|
-
write: true,
|
|
94
|
-
barrelType: 'named',
|
|
95
|
-
extension: DEFAULT_EXTENSION,
|
|
96
|
-
defaultBanner: DEFAULT_BANNER,
|
|
97
|
-
...userConfig.output,
|
|
98
|
-
},
|
|
99
|
-
devtools: userConfig.devtools
|
|
100
|
-
? {
|
|
101
|
-
studioUrl: DEFAULT_STUDIO_URL,
|
|
102
|
-
...(typeof userConfig.devtools === 'boolean' ? {} : userConfig.devtools),
|
|
103
|
-
}
|
|
104
|
-
: undefined,
|
|
105
|
-
plugins: userConfig.plugins as Config['plugins'],
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// write: false is the explicit dry-run opt-out; otherwise use the provided
|
|
109
|
-
// storage or fall back to fsStorage (backwards-compatible default).
|
|
110
|
-
// Keys are root-relative (e.g. `src/gen/api/getPets.ts`) so fsStorage()
|
|
111
|
-
// needs no configuration — it resolves them against process.cwd().
|
|
112
|
-
const storage: DefineStorage | null = definedConfig.output.write === false ? null : (definedConfig.output.storage ?? fsStorage())
|
|
113
|
-
|
|
114
|
-
if (definedConfig.output.clean) {
|
|
115
|
-
await events.emit('debug', {
|
|
116
|
-
date: new Date(),
|
|
117
|
-
logs: ['Cleaning output directories', ` • Output: ${definedConfig.output.path}`],
|
|
118
|
-
})
|
|
119
|
-
await storage?.clear(resolve(definedConfig.root, definedConfig.output.path))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const fabric = createFabric()
|
|
123
|
-
fabric.use(fsPlugin)
|
|
124
|
-
fabric.use(typescriptParser)
|
|
125
|
-
|
|
126
|
-
fabric.context.on('files:processing:start', (files) => {
|
|
127
|
-
events.emit('files:processing:start', files)
|
|
128
|
-
events.emit('debug', {
|
|
129
|
-
date: new Date(),
|
|
130
|
-
logs: [`Writing ${files.length} files...`],
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
fabric.context.on('file:processing:update', async (params) => {
|
|
135
|
-
const { file, source } = params
|
|
136
|
-
await events.emit('file:processing:update', {
|
|
137
|
-
...params,
|
|
138
|
-
config: definedConfig,
|
|
139
|
-
source,
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
if (source) {
|
|
143
|
-
// Key is root-relative so it's meaningful for any backend (fs, S3, Redis…)
|
|
144
|
-
const key = relative(resolve(definedConfig.root), file.path)
|
|
145
|
-
await storage?.setItem(key, source)
|
|
146
|
-
sources.set(file.path, source)
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
fabric.context.on('files:processing:end', async (files) => {
|
|
151
|
-
await events.emit('files:processing:end', files)
|
|
152
|
-
await events.emit('debug', {
|
|
153
|
-
date: new Date(),
|
|
154
|
-
logs: [`✓ File write process completed for ${files.length} files`],
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
await events.emit('debug', {
|
|
159
|
-
date: new Date(),
|
|
160
|
-
logs: [
|
|
161
|
-
'✓ Fabric initialized',
|
|
162
|
-
` • Storage: ${storage ? storage.name : 'disabled (dry-run)'}`,
|
|
163
|
-
` • Barrel type: ${definedConfig.output.barrelType || 'none'}`,
|
|
164
|
-
],
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
const pluginManager = new PluginManager(definedConfig, {
|
|
168
|
-
fabric,
|
|
169
|
-
events,
|
|
170
|
-
concurrency: DEFAULT_CONCURRENCY,
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
// Run the adapter (if provided) to produce the universal RootNode
|
|
174
|
-
if (definedConfig.adapter) {
|
|
175
|
-
const source = inputToAdapterSource(definedConfig)
|
|
176
|
-
|
|
177
|
-
await events.emit('debug', {
|
|
178
|
-
date: new Date(),
|
|
179
|
-
logs: [`Running adapter: ${definedConfig.adapter.name}`],
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
pluginManager.adapter = definedConfig.adapter
|
|
183
|
-
pluginManager.rootNode = await definedConfig.adapter.parse(source)
|
|
184
|
-
|
|
185
|
-
await events.emit('debug', {
|
|
186
|
-
date: new Date(),
|
|
187
|
-
logs: [
|
|
188
|
-
`✓ Adapter '${definedConfig.adapter.name}' resolved RootNode`,
|
|
189
|
-
` • Schemas: ${pluginManager.rootNode.schemas.length}`,
|
|
190
|
-
` • Operations: ${pluginManager.rootNode.operations.length}`,
|
|
191
|
-
],
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
events,
|
|
197
|
-
fabric,
|
|
198
|
-
pluginManager,
|
|
199
|
-
sources,
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput> {
|
|
204
|
-
const { fabric, files, pluginManager, failedPlugins, pluginTimings, error, sources } = await safeBuild(options, overrides)
|
|
205
|
-
|
|
206
|
-
if (error) {
|
|
207
|
-
throw error
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (failedPlugins.size > 0) {
|
|
211
|
-
const errors = [...failedPlugins].map(({ error }) => error)
|
|
212
|
-
|
|
213
|
-
throw new BuildError(`Build Error with ${failedPlugins.size} failed plugins`, { errors })
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
failedPlugins,
|
|
218
|
-
fabric,
|
|
219
|
-
files,
|
|
220
|
-
pluginManager,
|
|
221
|
-
pluginTimings,
|
|
222
|
-
error: undefined,
|
|
223
|
-
sources,
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export async function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput> {
|
|
228
|
-
const { fabric, pluginManager, events, sources } = overrides ? overrides : await setup(options)
|
|
229
|
-
|
|
230
|
-
const failedPlugins = new Set<{ plugin: Plugin; error: Error }>()
|
|
231
|
-
// in ms
|
|
232
|
-
const pluginTimings = new Map<string, number>()
|
|
233
|
-
const config = pluginManager.config
|
|
234
|
-
|
|
235
|
-
try {
|
|
236
|
-
for (const plugin of pluginManager.plugins) {
|
|
237
|
-
const context = pluginManager.getContext(plugin)
|
|
238
|
-
const hrStart = process.hrtime()
|
|
239
|
-
|
|
240
|
-
const installer = plugin.install.bind(context)
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
const timestamp = new Date()
|
|
244
|
-
|
|
245
|
-
await events.emit('plugin:start', plugin)
|
|
246
|
-
|
|
247
|
-
await events.emit('debug', {
|
|
248
|
-
date: timestamp,
|
|
249
|
-
logs: ['Installing plugin...', ` • Plugin Name: ${plugin.name}`],
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
await installer(context)
|
|
253
|
-
|
|
254
|
-
const duration = getElapsedMs(hrStart)
|
|
255
|
-
pluginTimings.set(plugin.name, duration)
|
|
256
|
-
|
|
257
|
-
await events.emit('plugin:end', plugin, { duration, success: true })
|
|
258
|
-
|
|
259
|
-
await events.emit('debug', {
|
|
260
|
-
date: new Date(),
|
|
261
|
-
logs: [`✓ Plugin installed successfully (${formatMs(duration)})`],
|
|
262
|
-
})
|
|
263
|
-
} catch (caughtError) {
|
|
264
|
-
const error = caughtError as Error
|
|
265
|
-
const errorTimestamp = new Date()
|
|
266
|
-
const duration = getElapsedMs(hrStart)
|
|
267
|
-
|
|
268
|
-
await events.emit('plugin:end', plugin, {
|
|
269
|
-
duration,
|
|
270
|
-
success: false,
|
|
271
|
-
error,
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
await events.emit('debug', {
|
|
275
|
-
date: errorTimestamp,
|
|
276
|
-
logs: [
|
|
277
|
-
'✗ Plugin installation failed',
|
|
278
|
-
` • Plugin Name: ${plugin.name}`,
|
|
279
|
-
` • Error: ${error.constructor.name} - ${error.message}`,
|
|
280
|
-
' • Stack Trace:',
|
|
281
|
-
error.stack || 'No stack trace available',
|
|
282
|
-
],
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
failedPlugins.add({ plugin, error })
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (config.output.barrelType) {
|
|
290
|
-
const root = resolve(config.root)
|
|
291
|
-
const rootPath = resolve(root, config.output.path, BARREL_FILENAME)
|
|
292
|
-
const rootDir = dirname(rootPath)
|
|
293
|
-
|
|
294
|
-
await events.emit('debug', {
|
|
295
|
-
date: new Date(),
|
|
296
|
-
logs: ['Generating barrel file', ` • Type: ${config.output.barrelType}`, ` • Path: ${rootPath}`],
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
const barrelFiles = fabric.files.filter((file) => {
|
|
300
|
-
return file.sources.some((source) => source.isIndexable)
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
await events.emit('debug', {
|
|
304
|
-
date: new Date(),
|
|
305
|
-
logs: [`Found ${barrelFiles.length} indexable files for barrel export`],
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
const existingBarrel = fabric.files.find((f) => f.path === rootPath)
|
|
309
|
-
const existingExports = new Set(
|
|
310
|
-
existingBarrel?.exports?.flatMap((e) => (Array.isArray(e.name) ? e.name : [e.name])).filter((n): n is string => Boolean(n)) ?? [],
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
const rootFile: KubbFile.File = {
|
|
314
|
-
path: rootPath,
|
|
315
|
-
baseName: BARREL_FILENAME,
|
|
316
|
-
exports: buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }),
|
|
317
|
-
sources: [],
|
|
318
|
-
imports: [],
|
|
319
|
-
meta: {},
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
await fabric.upsertFile(rootFile)
|
|
323
|
-
|
|
324
|
-
await events.emit('debug', {
|
|
325
|
-
date: new Date(),
|
|
326
|
-
logs: [`✓ Generated barrel file (${rootFile.exports?.length || 0} exports)`],
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const files = [...fabric.files]
|
|
331
|
-
|
|
332
|
-
await fabric.write({ extension: config.output.extension })
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
failedPlugins,
|
|
336
|
-
fabric,
|
|
337
|
-
files,
|
|
338
|
-
pluginManager,
|
|
339
|
-
pluginTimings,
|
|
340
|
-
sources,
|
|
341
|
-
}
|
|
342
|
-
} catch (error) {
|
|
343
|
-
return {
|
|
344
|
-
failedPlugins,
|
|
345
|
-
fabric,
|
|
346
|
-
files: [],
|
|
347
|
-
pluginManager,
|
|
348
|
-
pluginTimings,
|
|
349
|
-
error: error as Error,
|
|
350
|
-
sources,
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
type BuildBarrelExportsParams = {
|
|
356
|
-
barrelFiles: KubbFile.ResolvedFile[]
|
|
357
|
-
rootDir: string
|
|
358
|
-
existingExports: Set<string>
|
|
359
|
-
config: Config
|
|
360
|
-
pluginManager: PluginManager
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function buildBarrelExports({ barrelFiles, rootDir, existingExports, config, pluginManager }: BuildBarrelExportsParams): KubbFile.Export[] {
|
|
364
|
-
const pluginNameMap = new Map<string, Plugin>()
|
|
365
|
-
for (const plugin of pluginManager.plugins) {
|
|
366
|
-
pluginNameMap.set(plugin.name, plugin)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return barrelFiles.flatMap((file) => {
|
|
370
|
-
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly)
|
|
371
|
-
|
|
372
|
-
return (file.sources ?? []).flatMap((source) => {
|
|
373
|
-
if (!file.path || !source.isIndexable) {
|
|
374
|
-
return []
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const meta = file.meta as FileMetaBase | undefined
|
|
378
|
-
const plugin = meta?.pluginName ? pluginNameMap.get(meta.pluginName) : undefined
|
|
379
|
-
const pluginOptions = plugin?.options as { output?: Output<unknown> } | undefined
|
|
380
|
-
|
|
381
|
-
if (!pluginOptions || pluginOptions.output?.barrelType === false) {
|
|
382
|
-
return []
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const exportName = config.output.barrelType === 'all' ? undefined : source.name ? [source.name] : undefined
|
|
386
|
-
if (exportName?.some((n) => existingExports.has(n))) {
|
|
387
|
-
return []
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return [
|
|
391
|
-
{
|
|
392
|
-
name: exportName,
|
|
393
|
-
path: getRelativePath(rootDir, file.path),
|
|
394
|
-
isTypeOnly: config.output.barrelType === 'all' ? containsOnlyTypes : source.isTypeOnly,
|
|
395
|
-
} satisfies KubbFile.Export,
|
|
396
|
-
]
|
|
397
|
-
})
|
|
398
|
-
})
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Maps the resolved `Config['input']` shape into an `AdapterSource` that
|
|
403
|
-
* the adapter's `parse()` can consume.
|
|
404
|
-
*/
|
|
405
|
-
function inputToAdapterSource(config: Config): AdapterSource {
|
|
406
|
-
if (Array.isArray(config.input)) {
|
|
407
|
-
return {
|
|
408
|
-
type: 'paths',
|
|
409
|
-
paths: config.input.map((i) => resolve(config.root, i.path)),
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if ('data' in config.input) {
|
|
414
|
-
return { type: 'data', data: config.input.data }
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const resolved = resolve(config.root, config.input.path)
|
|
418
|
-
return { type: 'path', path: resolved }
|
|
419
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { PossiblePromise } from '@internals/utils'
|
|
2
|
-
import type { InputPath, UserConfig } from './types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CLI options derived from command-line flags.
|
|
6
|
-
*/
|
|
7
|
-
export type CLIOptions = {
|
|
8
|
-
/** Path to `kubb.config.js` */
|
|
9
|
-
config?: string
|
|
10
|
-
|
|
11
|
-
/** Enable watch mode for input files */
|
|
12
|
-
watch?: boolean
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Logging verbosity for CLI usage.
|
|
16
|
-
*
|
|
17
|
-
* - `silent`: hide non-essential logs
|
|
18
|
-
* - `info`: show general logs (non-plugin-related)
|
|
19
|
-
* - `debug`: include detailed plugin lifecycle logs
|
|
20
|
-
* @default 'silent'
|
|
21
|
-
*/
|
|
22
|
-
logLevel?: 'silent' | 'info' | 'debug'
|
|
23
|
-
|
|
24
|
-
/** Run Kubb with Bun */
|
|
25
|
-
bun?: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** All accepted forms of a Kubb configuration. */
|
|
29
|
-
export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Helper for defining a Kubb configuration.
|
|
33
|
-
*
|
|
34
|
-
* Accepts either:
|
|
35
|
-
* - A config object or array of configs
|
|
36
|
-
* - A function returning the config(s), optionally async,
|
|
37
|
-
* receiving the CLI options as argument
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* export default defineConfig(({ logLevel }) => ({
|
|
41
|
-
* root: 'src',
|
|
42
|
-
* plugins: [myPlugin()],
|
|
43
|
-
* }))
|
|
44
|
-
*/
|
|
45
|
-
export function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
46
|
-
export function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config
|
|
47
|
-
export function defineConfig(config: ConfigInput): ConfigInput {
|
|
48
|
-
return config
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Type guard to check if a given config has an `input.path`.
|
|
53
|
-
*/
|
|
54
|
-
export function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> {
|
|
55
|
-
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
56
|
-
}
|
package/src/defineAdapter.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Adapter, AdapterFactoryOptions } from './types.ts'
|
|
2
|
-
|
|
3
|
-
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Wraps an adapter builder to make the options parameter optional.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* export const adapterOas = defineAdapter<OasAdapter>((options) => {
|
|
11
|
-
* const { validate = true, dateType = 'string' } = options
|
|
12
|
-
* return {
|
|
13
|
-
* name: adapterOasName,
|
|
14
|
-
* options: { validate, dateType, ... },
|
|
15
|
-
* parse(source) { ... },
|
|
16
|
-
* }
|
|
17
|
-
* })
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function defineAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T> {
|
|
21
|
-
return (options) => build(options ?? ({} as T['options']))
|
|
22
|
-
}
|
package/src/defineStorage.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storage interface for persisting Kubb output.
|
|
3
|
-
*
|
|
4
|
-
* Keys are root-relative forward-slash paths (e.g. `src/gen/api/getPets.ts`).
|
|
5
|
-
* Implement this interface to route generated files to any backend — filesystem,
|
|
6
|
-
* S3, Redis, in-memory, etc.
|
|
7
|
-
*
|
|
8
|
-
* Use `defineStorage` to create a typed storage driver.
|
|
9
|
-
*/
|
|
10
|
-
export interface DefineStorage {
|
|
11
|
-
/** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */
|
|
12
|
-
readonly name: string
|
|
13
|
-
/** Returns `true` when an entry for `key` exists in storage. */
|
|
14
|
-
hasItem(key: string): Promise<boolean>
|
|
15
|
-
/** Returns the stored string value, or `null` when `key` does not exist. */
|
|
16
|
-
getItem(key: string): Promise<string | null>
|
|
17
|
-
/** Persists `value` under `key`, creating any required structure. */
|
|
18
|
-
setItem(key: string, value: string): Promise<void>
|
|
19
|
-
/** Removes the entry for `key`. No-ops when the key does not exist. */
|
|
20
|
-
removeItem(key: string): Promise<void>
|
|
21
|
-
/** Returns all keys, optionally filtered to those starting with `base`. */
|
|
22
|
-
getKeys(base?: string): Promise<Array<string>>
|
|
23
|
-
/** Removes all entries, optionally scoped to those starting with `base`. */
|
|
24
|
-
clear(base?: string): Promise<void>
|
|
25
|
-
/** Optional teardown hook called after the build completes. */
|
|
26
|
-
dispose?(): Promise<void>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Wraps a storage builder so the `options` argument is optional, following the
|
|
31
|
-
* same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
|
|
32
|
-
*
|
|
33
|
-
* The builder receives the resolved options object and must return a
|
|
34
|
-
* `DefineStorage`-compatible object that includes a `name` string.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* import { defineStorage } from '@kubb/core'
|
|
39
|
-
*
|
|
40
|
-
* export const memoryStorage = defineStorage((_options) => {
|
|
41
|
-
* const store = new Map<string, string>()
|
|
42
|
-
* return {
|
|
43
|
-
* name: 'memory',
|
|
44
|
-
* async hasItem(key) { return store.has(key) },
|
|
45
|
-
* async getItem(key) { return store.get(key) ?? null },
|
|
46
|
-
* async setItem(key, value) { store.set(key, value) },
|
|
47
|
-
* async removeItem(key) { store.delete(key) },
|
|
48
|
-
* async getKeys() { return [...store.keys()] },
|
|
49
|
-
* async clear() { store.clear() },
|
|
50
|
-
* }
|
|
51
|
-
* })
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export function defineStorage<TOptions = Record<string, never>>(build: (options: TOptions) => DefineStorage): (options?: TOptions) => DefineStorage {
|
|
55
|
-
return (options) => build(options ?? ({} as TOptions))
|
|
56
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BuildError, ValidationPluginError } from '@internals/utils'
|
package/src/hooks/index.ts
DELETED
package/src/hooks/useKubb.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import { useFabric } from '@kubb/react-fabric'
|
|
3
|
-
import type { GetFileOptions, PluginManager } from '../PluginManager.ts'
|
|
4
|
-
import type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'
|
|
5
|
-
|
|
6
|
-
type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
7
|
-
plugin: Plugin<TOptions>
|
|
8
|
-
mode: KubbFile.Mode
|
|
9
|
-
config: Config
|
|
10
|
-
/**
|
|
11
|
-
* Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.
|
|
12
|
-
*/
|
|
13
|
-
getPluginByName: (pluginName?: string) => Plugin | undefined
|
|
14
|
-
/**
|
|
15
|
-
* Resolves a file reference, defaulting `pluginName` to the current plugin.
|
|
16
|
-
*/
|
|
17
|
-
getFile: <TFileOptions = object>(params: Omit<GetFileOptions<TFileOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a name, defaulting `pluginName` to the current plugin.
|
|
20
|
-
*/
|
|
21
|
-
resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string
|
|
22
|
-
/**
|
|
23
|
-
* Resolves a path, defaulting `pluginName` to the current plugin.
|
|
24
|
-
*/
|
|
25
|
-
resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {
|
|
29
|
-
const { meta } = useFabric<{
|
|
30
|
-
plugin: Plugin<TOptions>
|
|
31
|
-
mode: KubbFile.Mode
|
|
32
|
-
pluginManager: PluginManager
|
|
33
|
-
}>()
|
|
34
|
-
|
|
35
|
-
const defaultPluginName = meta.plugin.name
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
plugin: meta.plugin as Plugin<TOptions>,
|
|
39
|
-
mode: meta.mode,
|
|
40
|
-
config: meta.pluginManager.config,
|
|
41
|
-
getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),
|
|
42
|
-
getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, { pluginName, ...rest }),
|
|
43
|
-
resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, { pluginName, ...rest }),
|
|
44
|
-
resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, { pluginName, ...rest }),
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/hooks/useMode.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
2
|
-
import { useFabric } from '@kubb/react-fabric'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated use `useKubb` instead
|
|
6
|
-
*/
|
|
7
|
-
export function useMode(): KubbFile.Mode {
|
|
8
|
-
const { meta } = useFabric<{ mode: KubbFile.Mode }>()
|
|
9
|
-
|
|
10
|
-
return meta.mode
|
|
11
|
-
}
|
package/src/hooks/usePlugin.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useFabric } from '@kubb/react-fabric'
|
|
2
|
-
import type { Plugin, PluginFactoryOptions } from '../types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated use useKubb instead
|
|
6
|
-
*/
|
|
7
|
-
export function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {
|
|
8
|
-
const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()
|
|
9
|
-
|
|
10
|
-
return meta.plugin
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useFabric } from '@kubb/react-fabric'
|
|
2
|
-
import type { PluginManager } from '../PluginManager.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated use `useKubb` instead
|
|
6
|
-
*/
|
|
7
|
-
export function usePluginManager(): PluginManager {
|
|
8
|
-
const { meta } = useFabric<{ pluginManager: PluginManager }>()
|
|
9
|
-
|
|
10
|
-
return meta.pluginManager
|
|
11
|
-
}
|