@kubb/core 5.0.0-beta.61 → 5.0.0-beta.62

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/dist/mocks.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { At as Adapter, G as Generator, J as KubbDriver, U as Parser, h as Config, jt as AdapterFactoryOptions, st as PluginFactoryOptions, tt as NormalizedPlugin } from "./diagnostics-DiaUv_iK.js";
2
+ import { At as Adapter, G as Generator, J as KubbDriver, U as Parser, h as Config, jt as AdapterFactoryOptions, st as PluginFactoryOptions, tt as NormalizedPlugin } from "./diagnostics-D0G07LHG.js";
3
3
  import { FileNode, InputMeta, Macro, OperationNode, SchemaNode } from "@kubb/ast";
4
4
 
5
5
  //#region src/mocks.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "5.0.0-beta.61",
3
+ "version": "5.0.0-beta.62",
4
4
  "description": "Core engine for Kubb's plugin-based code generation system. Provides the plugin driver, file manager, defineConfig, and build orchestration used by every Kubb plugin.",
5
5
  "keywords": [
6
6
  "code-generator",
@@ -56,14 +56,14 @@
56
56
  "registry": "https://registry.npmjs.org/"
57
57
  },
58
58
  "dependencies": {
59
- "@kubb/ast": "5.0.0-beta.61"
59
+ "@kubb/ast": "5.0.0-beta.62"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@internals/utils": "0.0.0",
63
- "@kubb/renderer-jsx": "5.0.0-beta.61"
63
+ "@kubb/renderer-jsx": "5.0.0-beta.62"
64
64
  },
65
65
  "peerDependencies": {
66
- "@kubb/renderer-jsx": "5.0.0-beta.61"
66
+ "@kubb/renderer-jsx": "5.0.0-beta.62"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=22"
package/src/KubbDriver.ts CHANGED
@@ -2,7 +2,7 @@ import { resolve } from 'node:path'
2
2
  import { arrayToAsyncIterable, type AsyncEventEmitter, forBatches, getElapsedMs, isPromise, memoize, Url } from '@internals/utils'
3
3
  import * as factory from '@kubb/ast/factory'
4
4
  import { collectUsedSchemaNames } from '@kubb/ast/utils'
5
- import type { FileNode, InputMeta, InputNode, OperationNode, SchemaNode } from '@kubb/ast'
5
+ import type { Enforce, FileNode, InputMeta, InputNode, OperationNode, SchemaNode } from '@kubb/ast'
6
6
  import { OPERATION_FILTER_TYPES, SCHEMA_PARALLEL } from './constants.ts'
7
7
  import { type Diagnostic, Diagnostics, type ProblemDiagnostic } from './diagnostics.ts'
8
8
  import type { RendererFactory } from './createRenderer.ts'
@@ -45,7 +45,7 @@ type RequirePluginContext = {
45
45
  requiredBy?: string
46
46
  }
47
47
 
48
- function enforceOrder(enforce: 'pre' | 'post' | undefined): number {
48
+ function enforceOrder(enforce: Enforce | undefined): number {
49
49
  return enforce === 'pre' ? -1 : enforce === 'post' ? 1 : 0
50
50
  }
51
51
 
@@ -282,37 +282,21 @@ export class KubbDriver {
282
282
  * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
283
283
  */
284
284
  registerGenerator(pluginName: string, generator: Generator): void {
285
- if (generator.schema) {
286
- const schemaHandler = async (node: SchemaNode, ctx: GeneratorContext) => {
287
- if (ctx.plugin.name !== pluginName) return
288
- const result = await generator.schema!(node, ctx)
289
-
290
- await this.dispatch({ result, renderer: generator.renderer })
291
- }
285
+ const register = <TNode>(event: keyof KubbHooks & string, method: ((node: TNode, ctx: GeneratorContext) => unknown) | undefined): void => {
286
+ if (!method) return
292
287
 
293
- this.#trackListener('kubb:generate:schema', schemaHandler)
294
- }
295
-
296
- if (generator.operation) {
297
- const operationHandler = async (node: OperationNode, ctx: GeneratorContext) => {
288
+ const handler = async (node: TNode, ctx: GeneratorContext) => {
298
289
  if (ctx.plugin.name !== pluginName) return
299
-
300
- const result = await generator.operation!(node, ctx)
290
+ const result = await method(node, ctx)
301
291
  await this.dispatch({ result, renderer: generator.renderer })
302
292
  }
303
293
 
304
- this.#trackListener('kubb:generate:operation', operationHandler)
294
+ this.#trackListener(event, handler as HookListener<KubbHooks[typeof event], unknown>)
305
295
  }
306
296
 
307
- if (generator.operations) {
308
- const operationsHandler = async (nodes: Array<OperationNode>, ctx: GeneratorContext) => {
309
- if (ctx.plugin.name !== pluginName) return
310
- const result = await generator.operations!(nodes, ctx)
311
- await this.dispatch({ result, renderer: generator.renderer })
312
- }
313
-
314
- this.#trackListener('kubb:generate:operations', operationsHandler)
315
- }
297
+ register('kubb:generate:schema', generator.schema)
298
+ register('kubb:generate:operation', generator.operation)
299
+ register('kubb:generate:operations', generator.operations)
316
300
 
317
301
  this.#eventGeneratorPlugins.add(pluginName)
318
302
  }
@@ -1,4 +1,4 @@
1
- import type { FileNode, HttpMethod, Macro, UserFileNode } from '@kubb/ast'
1
+ import type { Enforce, FileNode, HttpMethod, Macro, UserFileNode } from '@kubb/ast'
2
2
  import { diagnosticCode } from './constants.ts'
3
3
  import type { Generator } from './defineGenerator.ts'
4
4
  import type { BannerMeta, Resolver } from './defineResolver.ts'
@@ -351,7 +351,7 @@ export type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>
351
351
  *
352
352
  * Dependency constraints always take precedence over `enforce`.
353
353
  */
354
- enforce?: 'pre' | 'post'
354
+ enforce?: Enforce
355
355
  /**
356
356
  * The options passed by the user when calling the plugin factory.
357
357
  */