@kubb/core 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (55) hide show
  1. package/dist/{types-B7eZvqwD.d.ts → PluginDriver-CEQPafXV.d.ts} +687 -298
  2. package/dist/hooks.cjs +15 -9
  3. package/dist/hooks.cjs.map +1 -1
  4. package/dist/hooks.d.ts +11 -5
  5. package/dist/hooks.js +16 -10
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.cjs +1131 -536
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +674 -89
  10. package/dist/index.js +1114 -532
  11. package/dist/index.js.map +1 -1
  12. package/package.json +6 -6
  13. package/src/Kubb.ts +37 -55
  14. package/src/{PluginManager.ts → PluginDriver.ts} +51 -40
  15. package/src/build.ts +74 -29
  16. package/src/config.ts +9 -8
  17. package/src/constants.ts +44 -1
  18. package/src/createAdapter.ts +25 -0
  19. package/src/createPlugin.ts +28 -0
  20. package/src/createStorage.ts +58 -0
  21. package/src/defineBuilder.ts +26 -0
  22. package/src/defineGenerator.ts +137 -0
  23. package/src/defineLogger.ts +13 -3
  24. package/src/definePreset.ts +27 -0
  25. package/src/definePresets.ts +16 -0
  26. package/src/defineResolver.ts +448 -0
  27. package/src/hooks/index.ts +1 -1
  28. package/src/hooks/useDriver.ts +8 -0
  29. package/src/hooks/useMode.ts +5 -2
  30. package/src/hooks/usePlugin.ts +5 -2
  31. package/src/index.ts +21 -6
  32. package/src/renderNode.tsx +105 -0
  33. package/src/storages/fsStorage.ts +2 -2
  34. package/src/storages/memoryStorage.ts +2 -2
  35. package/src/types.ts +342 -42
  36. package/src/utils/FunctionParams.ts +2 -2
  37. package/src/utils/TreeNode.ts +24 -1
  38. package/src/utils/diagnostics.ts +4 -1
  39. package/src/utils/executeStrategies.ts +23 -10
  40. package/src/utils/formatters.ts +10 -21
  41. package/src/utils/getBarrelFiles.ts +79 -9
  42. package/src/utils/getConfigs.ts +8 -22
  43. package/src/utils/getPreset.ts +52 -0
  44. package/src/utils/linters.ts +23 -3
  45. package/src/utils/mergeResolvers.ts +8 -0
  46. package/src/utils/packageJSON.ts +76 -0
  47. package/src/BarrelManager.ts +0 -74
  48. package/src/PackageManager.ts +0 -180
  49. package/src/PromiseManager.ts +0 -40
  50. package/src/defineAdapter.ts +0 -22
  51. package/src/definePlugin.ts +0 -12
  52. package/src/defineStorage.ts +0 -56
  53. package/src/errors.ts +0 -1
  54. package/src/hooks/usePluginManager.ts +0 -8
  55. package/src/utils/getPlugins.ts +0 -23
@@ -1,40 +0,0 @@
1
- import type { Strategy, StrategySwitch } from './utils/executeStrategies.ts'
2
- import { hookFirst, hookParallel, hookSeq } from './utils/executeStrategies.ts'
3
-
4
- type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2
5
-
6
- type Options<TState = unknown> = {
7
- nullCheck?: (state: TState) => boolean
8
- }
9
-
10
- export class PromiseManager<TState = unknown> {
11
- #options: Options<TState> = {}
12
-
13
- constructor(options: Options<TState> = {}) {
14
- this.#options = options
15
- }
16
-
17
- run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(
18
- strategy: TStrategy,
19
- promises: TInput,
20
- { concurrency = Number.POSITIVE_INFINITY }: { concurrency?: number } = {},
21
- ): TOutput {
22
- if (strategy === 'seq') {
23
- return hookSeq<TInput, TValue, TOutput>(promises)
24
- }
25
-
26
- if (strategy === 'first') {
27
- return hookFirst<TInput, TValue, TOutput>(promises, this.#options.nullCheck as ((state: unknown) => boolean) | undefined)
28
- }
29
-
30
- if (strategy === 'parallel') {
31
- return hookParallel<TInput, TValue, TOutput>(promises, concurrency)
32
- }
33
-
34
- throw new Error(`${strategy} not implemented`)
35
- }
36
- }
37
-
38
- export function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {
39
- return result.status === 'rejected'
40
- }
@@ -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,12 +0,0 @@
1
- import type { PluginFactoryOptions, UserPluginWithLifeCycle } from './types.ts'
2
-
3
- type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>
4
-
5
- /**
6
- * Wraps a plugin builder to make the options parameter optional.
7
- */
8
- export function definePlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(
9
- build: PluginBuilder<T>,
10
- ): (options?: T['options']) => UserPluginWithLifeCycle<T> {
11
- return (options) => build(options ?? ({} as T['options']))
12
- }
@@ -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
- import { useApp } from '@kubb/react-fabric'
2
- import type { PluginManager } from '../PluginManager.ts'
3
-
4
- export function usePluginManager(): PluginManager {
5
- const { meta } = useApp<{ pluginManager: PluginManager }>()
6
-
7
- return meta.pluginManager
8
- }
@@ -1,23 +0,0 @@
1
- import type { UnknownUserPlugin, UserConfig } from '../types.ts'
2
-
3
- type PluginsArray = Array<Omit<UnknownUserPlugin, 'inject'>>
4
-
5
- function isJSONPlugins(plugins: UserConfig['plugins']): boolean {
6
- return Array.isArray(plugins) && plugins.some((plugin) => Array.isArray(plugin) && typeof (plugin as unknown[])[0] === 'string')
7
- }
8
-
9
- function isObjectPlugins(plugins: UserConfig['plugins']): boolean {
10
- return plugins instanceof Object && !Array.isArray(plugins)
11
- }
12
-
13
- export function getPlugins(plugins: UserConfig['plugins']): Promise<PluginsArray | undefined> {
14
- if (isObjectPlugins(plugins)) {
15
- throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')
16
- }
17
-
18
- if (isJSONPlugins(plugins)) {
19
- throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')
20
- }
21
-
22
- return Promise.resolve(plugins)
23
- }