@kubb/core 5.0.0-alpha.4 → 5.0.0-alpha.41

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