@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.
Files changed (62) hide show
  1. package/README.md +13 -40
  2. package/dist/PluginDriver-Cu1Kj9S-.cjs +1075 -0
  3. package/dist/PluginDriver-Cu1Kj9S-.cjs.map +1 -0
  4. package/dist/PluginDriver-D8Z0Htid.js +978 -0
  5. package/dist/PluginDriver-D8Z0Htid.js.map +1 -0
  6. package/dist/createKubb-ALdb8lmq.d.ts +2082 -0
  7. package/dist/index.cjs +747 -1667
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +175 -269
  10. package/dist/index.js +734 -1638
  11. package/dist/index.js.map +1 -1
  12. package/dist/mocks.cjs +145 -0
  13. package/dist/mocks.cjs.map +1 -0
  14. package/dist/mocks.d.ts +80 -0
  15. package/dist/mocks.js +140 -0
  16. package/dist/mocks.js.map +1 -0
  17. package/package.json +47 -60
  18. package/src/FileManager.ts +115 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/PluginDriver.ts +355 -561
  21. package/src/constants.ts +21 -48
  22. package/src/createAdapter.ts +88 -5
  23. package/src/createKubb.ts +1266 -0
  24. package/src/createRenderer.ts +57 -0
  25. package/src/createStorage.ts +13 -1
  26. package/src/defineGenerator.ts +160 -119
  27. package/src/defineLogger.ts +46 -5
  28. package/src/defineMiddleware.ts +62 -0
  29. package/src/defineParser.ts +44 -0
  30. package/src/definePlugin.ts +379 -0
  31. package/src/defineResolver.ts +548 -25
  32. package/src/devtools.ts +22 -15
  33. package/src/index.ts +13 -15
  34. package/src/mocks.ts +177 -0
  35. package/src/storages/fsStorage.ts +13 -8
  36. package/src/storages/memoryStorage.ts +4 -2
  37. package/src/types.ts +40 -547
  38. package/dist/PluginDriver-BkFepPdm.d.ts +0 -1054
  39. package/dist/chunk-ByKO4r7w.cjs +0 -38
  40. package/dist/hooks.cjs +0 -103
  41. package/dist/hooks.cjs.map +0 -1
  42. package/dist/hooks.d.ts +0 -77
  43. package/dist/hooks.js +0 -98
  44. package/dist/hooks.js.map +0 -1
  45. package/src/Kubb.ts +0 -224
  46. package/src/build.ts +0 -418
  47. package/src/config.ts +0 -56
  48. package/src/createPlugin.ts +0 -28
  49. package/src/hooks/index.ts +0 -4
  50. package/src/hooks/useKubb.ts +0 -143
  51. package/src/hooks/useMode.ts +0 -11
  52. package/src/hooks/usePlugin.ts +0 -11
  53. package/src/hooks/usePluginDriver.ts +0 -11
  54. package/src/utils/FunctionParams.ts +0 -155
  55. package/src/utils/TreeNode.ts +0 -215
  56. package/src/utils/diagnostics.ts +0 -15
  57. package/src/utils/executeStrategies.ts +0 -81
  58. package/src/utils/formatters.ts +0 -56
  59. package/src/utils/getBarrelFiles.ts +0 -141
  60. package/src/utils/getConfigs.ts +0 -12
  61. package/src/utils/linters.ts +0 -25
  62. package/src/utils/packageJSON.ts +0 -61
package/src/constants.ts CHANGED
@@ -1,21 +1,30 @@
1
- import type { KubbFile } from '@kubb/fabric-core/types'
1
+ import type { FileNode } from '@kubb/ast'
2
2
 
3
- export const DEFAULT_STUDIO_URL = 'https://studio.kubb.dev' as const
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
- export const CORE_PLUGIN_NAME = 'core' as const
6
-
7
- export const DEFAULT_MAX_LISTENERS = 100
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
- export const DEFAULT_EXTENSION: Record<KubbFile.Extname, KubbFile.Extname | ''> = { '.ts': '.ts' }
16
-
17
- export const PATH_SEPARATORS = new Set(['/', '\\'] as const)
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
@@ -1,24 +1,107 @@
1
- import type { Adapter, AdapterFactoryOptions } from './types.ts'
1
+ import type { PossiblePromise } from '@internals/utils'
2
+ import type { ImportNode, InputNode, SchemaNode } from '@kubb/ast'
2
3
 
3
4
  /**
4
- * Builder type for an {@link Adapter} — takes options and returns the adapter instance.
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
- * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
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
- * // instantiate
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']))