@kubb/core 5.0.0-alpha.24 → 5.0.0-alpha.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "5.0.0-alpha.24",
3
+ "version": "5.0.0-alpha.26",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -68,10 +68,10 @@
68
68
  "@kubb/react-fabric": "0.15.1",
69
69
  "empathic": "^2.0.0",
70
70
  "fflate": "^0.8.2",
71
- "remeda": "^2.33.6",
71
+ "remeda": "^2.33.7",
72
72
  "semver": "^7.7.4",
73
73
  "tinyexec": "^1.0.4",
74
- "@kubb/ast": "5.0.0-alpha.24"
74
+ "@kubb/ast": "5.0.0-alpha.26"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/semver": "^7.7.1",
package/src/index.ts CHANGED
@@ -19,7 +19,7 @@ export {
19
19
  defineResolver,
20
20
  } from './defineResolver.ts'
21
21
  export { getMode, PluginDriver } from './PluginDriver.ts'
22
- export { renderOperation, renderOperations, renderSchema } from './renderNode.tsx'
22
+ export { renderOperation, renderOperations, renderSchema, runGeneratorOperation, runGeneratorOperations, runGeneratorSchema } from './renderNode.tsx'
23
23
  export { fsStorage } from './storages/fsStorage.ts'
24
24
  export { memoryStorage } from './storages/memoryStorage.ts'
25
25
  export * from './types.ts'
@@ -2,7 +2,7 @@ import type { OperationNode, SchemaNode } from '@kubb/ast/types'
2
2
  import { createReactFabric, Fabric } from '@kubb/react-fabric'
3
3
  import type { Fabric as FabricType } from '@kubb/react-fabric/types'
4
4
  import type { PluginDriver } from './PluginDriver.ts'
5
- import type { Adapter, Config, Plugin, PluginFactoryOptions, ReactGeneratorV2 } from './types.ts'
5
+ import type { Adapter, Config, Exclude, Generator, Include, Override, Plugin, PluginFactoryOptions, ReactGeneratorV2 } from './types.ts'
6
6
 
7
7
  type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = {
8
8
  config: Config
@@ -106,3 +106,92 @@ export async function renderSchema<TOptions extends PluginFactoryOptions>(node:
106
106
 
107
107
  fabricChild.unmount()
108
108
  }
109
+
110
+ /**
111
+ * Shared context passed to every `runGenerator*` helper.
112
+ * Contains everything a generator needs to produce and write files.
113
+ */
114
+ type RunGeneratorContext<TOptions extends PluginFactoryOptions> = {
115
+ generators: Array<Generator<TOptions>>
116
+ plugin: Plugin<TOptions>
117
+ resolver: TOptions['resolver']
118
+ exclude: Array<Exclude>
119
+ include: Array<Include> | undefined
120
+ override: Array<Override<TOptions['resolvedOptions']>>
121
+ fabric: FabricType
122
+ adapter: Adapter
123
+ config: Config
124
+ driver: PluginDriver
125
+ }
126
+
127
+ /**
128
+ * Dispatches a single schema node to all generators (react + core).
129
+ * Resolves options per generator and skips excluded nodes.
130
+ */
131
+ export async function runGeneratorSchema<TOptions extends PluginFactoryOptions>(node: SchemaNode, ctx: RunGeneratorContext<TOptions>): Promise<void> {
132
+ const { generators, plugin, resolver, exclude, include, override, fabric, adapter, config, driver } = ctx
133
+
134
+ for (const generator of generators) {
135
+ const options = resolver.resolveOptions(node, { options: plugin.options, exclude, include, override })
136
+
137
+ if (options === null) {
138
+ continue
139
+ }
140
+
141
+ if (generator.type === 'react' && generator.version === '2') {
142
+ await renderSchema(node, { options, resolver, adapter, config, fabric, Component: generator.Schema, plugin, driver })
143
+ }
144
+
145
+ if (generator.type === 'core' && generator.version === '2') {
146
+ const files = (await generator.schema?.({ node, options, resolver, adapter, config, plugin, driver })) ?? []
147
+ await fabric.upsertFile(...files)
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Dispatches a single operation node to all generators (react + core).
154
+ * Resolves options per generator and skips excluded nodes.
155
+ */
156
+ export async function runGeneratorOperation<TOptions extends PluginFactoryOptions>(node: OperationNode, ctx: RunGeneratorContext<TOptions>): Promise<void> {
157
+ const { generators, plugin, resolver, exclude, include, override, fabric, adapter, config, driver } = ctx
158
+
159
+ for (const generator of generators) {
160
+ const options = resolver.resolveOptions(node, { options: plugin.options, exclude, include, override })
161
+
162
+ if (options === null) {
163
+ continue
164
+ }
165
+
166
+ if (generator.type === 'react' && generator.version === '2') {
167
+ await renderOperation(node, { options, resolver, adapter, config, fabric, Component: generator.Operation, plugin, driver })
168
+ }
169
+
170
+ if (generator.type === 'core' && generator.version === '2') {
171
+ const files = (await generator.operation?.({ node, options, resolver, adapter, config, plugin, driver })) ?? []
172
+ await fabric.upsertFile(...files)
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Batch-dispatches all collected operation nodes to every generator (react + core).
179
+ * Uses `plugin.options` directly — no per-node option resolution.
180
+ */
181
+ export async function runGeneratorOperations<TOptions extends PluginFactoryOptions>(
182
+ nodes: Array<OperationNode>,
183
+ ctx: Omit<RunGeneratorContext<TOptions>, 'exclude' | 'include' | 'override'>,
184
+ ): Promise<void> {
185
+ const { generators, plugin, resolver, fabric, adapter, config, driver } = ctx
186
+
187
+ for (const generator of generators) {
188
+ if (generator.type === 'react' && generator.version === '2') {
189
+ await renderOperations(nodes, { options: plugin.options, resolver, adapter, config, fabric, Component: generator.Operations, plugin, driver })
190
+ }
191
+
192
+ if (generator.type === 'core' && generator.version === '2') {
193
+ const files = (await generator.operations?.({ nodes, options: plugin.options, resolver, adapter, config, plugin, driver })) ?? []
194
+ await fabric.upsertFile(...files)
195
+ }
196
+ }
197
+ }