@kubb/plugin-oas 5.0.0-alpha.1 → 5.0.0-alpha.11

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 (47) hide show
  1. package/dist/{createGenerator-CBXpHeVY.d.ts → createGenerator-Cl7uTbJt.d.ts} +67 -61
  2. package/dist/{generators-CyWd3UXA.cjs → generators-BfTTScuN.cjs} +7 -7
  3. package/dist/generators-BfTTScuN.cjs.map +1 -0
  4. package/dist/{generators-D7C3CXsN.js → generators-BjsINk-u.js} +7 -7
  5. package/dist/generators-BjsINk-u.js.map +1 -0
  6. package/dist/generators.cjs +1 -1
  7. package/dist/generators.d.ts +2 -2
  8. package/dist/generators.js +1 -1
  9. package/dist/hooks.cjs +44 -63
  10. package/dist/hooks.cjs.map +1 -1
  11. package/dist/hooks.d.ts +15 -32
  12. package/dist/hooks.js +47 -65
  13. package/dist/hooks.js.map +1 -1
  14. package/dist/index.cjs +15 -15
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +22 -38
  17. package/dist/index.js +14 -14
  18. package/dist/index.js.map +1 -1
  19. package/dist/{requestBody-mUXoBwsu.js → requestBody-BK5uH1dh.js} +80 -119
  20. package/dist/requestBody-BK5uH1dh.js.map +1 -0
  21. package/dist/{requestBody-DIM-iDpM.cjs → requestBody-tngRbzVa.cjs} +90 -129
  22. package/dist/requestBody-tngRbzVa.cjs.map +1 -0
  23. package/dist/utils.cjs +1 -1
  24. package/dist/utils.cjs.map +1 -1
  25. package/dist/utils.d.ts +1 -1
  26. package/dist/utils.js +1 -1
  27. package/dist/utils.js.map +1 -1
  28. package/package.json +7 -7
  29. package/src/OperationGenerator.ts +15 -15
  30. package/src/SchemaGenerator.ts +21 -24
  31. package/src/generators/createGenerator.ts +12 -15
  32. package/src/generators/createReactGenerator.ts +12 -15
  33. package/src/generators/jsonGenerator.ts +4 -4
  34. package/src/generators/types.ts +5 -40
  35. package/src/hooks/index.ts +0 -1
  36. package/src/hooks/useOas.ts +5 -2
  37. package/src/hooks/useOperationManager.ts +36 -35
  38. package/src/hooks/useSchemaManager.ts +16 -15
  39. package/src/index.ts +2 -2
  40. package/src/plugin.ts +6 -6
  41. package/src/types.ts +7 -6
  42. package/src/utils.tsx +50 -137
  43. package/dist/generators-CyWd3UXA.cjs.map +0 -1
  44. package/dist/generators-D7C3CXsN.js.map +0 -1
  45. package/dist/requestBody-DIM-iDpM.cjs.map +0 -1
  46. package/dist/requestBody-mUXoBwsu.js.map +0 -1
  47. package/src/hooks/useRootNode.ts +0 -25
@@ -1,12 +1,39 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import { i as SchemaKeywordMapper, t as Schema } from "./SchemaMapper-SneuY1wg.js";
3
3
  import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
4
- import { Fabric } from "@kubb/react-fabric";
5
- import { AsyncEventEmitter, Config, FileMetaBase, Group, KubbEvents, Output, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from "@kubb/core";
6
- import { KubbFile } from "@kubb/fabric-core/types";
7
- import { OperationNode, SchemaNode } from "@kubb/ast/types";
4
+ import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
5
+ import { Fabric, KubbFile } from "@kubb/fabric-core/types";
8
6
  import { FabricReactNode } from "@kubb/react-fabric/types";
9
7
 
8
+ //#region ../../internals/utils/src/asyncEventEmitter.d.ts
9
+ /** A function that can be registered as an event listener, synchronous or async. */
10
+ type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
11
+ /**
12
+ * A typed EventEmitter that awaits all async listeners before resolving.
13
+ * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
14
+ */
15
+ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
16
+ #private;
17
+ /**
18
+ * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
19
+ * @default 10
20
+ */
21
+ constructor(maxListener?: number);
22
+ /**
23
+ * Emits an event and awaits all registered listeners in parallel.
24
+ * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
25
+ */
26
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
27
+ /** Registers a persistent listener for the given event. */
28
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
29
+ /** Registers a one-shot listener that removes itself after the first invocation. */
30
+ onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
31
+ /** Removes a previously registered listener. */
32
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
33
+ /** Removes all listeners from every event channel. */
34
+ removeAll(): void;
35
+ }
36
+ //#endregion
10
37
  //#region src/types.d.ts
11
38
  type GetOasOptions = {
12
39
  validate?: boolean;
@@ -21,7 +48,7 @@ declare global {
21
48
  }
22
49
  }
23
50
  type ResolvePathOptions = {
24
- pluginKey?: Plugin['key'];
51
+ pluginName?: string;
25
52
  group?: {
26
53
  tag?: string;
27
54
  path?: string;
@@ -97,7 +124,7 @@ type Options = {
97
124
  /**
98
125
  * Define some generators next to the JSON generation
99
126
  */
100
- generators?: Array<Generator<PluginOas>>;
127
+ generators?: Array<Generator$1<PluginOas>>;
101
128
  /**
102
129
  * Resolve name collisions when schemas from different components share the same name (case-insensitive).
103
130
  *
@@ -135,14 +162,14 @@ type Options = {
135
162
  *
136
163
  * `originalName` is the original name used(in PascalCase), only used to remove duplicates
137
164
  *
138
- * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
165
+ * `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
139
166
  * @example import a type(plugin-ts) for a mock file(swagger-faker)
140
167
  */
141
168
  type Ref = {
142
169
  propertyName: string;
143
170
  originalName: string;
144
171
  path: KubbFile.Path;
145
- pluginKey?: Plugin['key'];
172
+ pluginName?: string;
146
173
  };
147
174
  type Refs = Record<string, Ref>;
148
175
  type Resolver = {
@@ -210,8 +237,8 @@ type ByContentType = {
210
237
  type: 'contentType';
211
238
  pattern: string | RegExp;
212
239
  };
213
- type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
214
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
240
+ type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
241
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
215
242
  type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
216
243
  options: Partial<TOptions>;
217
244
  };
@@ -229,7 +256,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
229
256
  include: Array<Include> | undefined;
230
257
  override: Array<Override<TOptions>> | undefined;
231
258
  contentType: contentType | undefined;
232
- pluginManager: PluginManager;
259
+ driver: PluginDriver;
233
260
  events?: AsyncEventEmitter<KubbEvents>;
234
261
  /**
235
262
  * Current plugin
@@ -255,7 +282,7 @@ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = P
255
282
  method: HttpMethod;
256
283
  operation: Operation;
257
284
  }>>;
258
- build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>>;
285
+ build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
259
286
  }
260
287
  //#endregion
261
288
  //#region src/SchemaGenerator.d.ts
@@ -264,7 +291,7 @@ type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<
264
291
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
265
292
  fabric: Fabric;
266
293
  oas: Oas;
267
- pluginManager: PluginManager;
294
+ driver: PluginDriver;
268
295
  events?: AsyncEventEmitter<KubbEvents>;
269
296
  /**
270
297
  * Current plugin
@@ -327,24 +354,23 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
327
354
  static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
328
355
  static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
329
356
  static combineObjects(tree: Schema[] | undefined): Schema[];
330
- build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>>;
357
+ build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
331
358
  }
332
359
  //#endregion
333
360
  //#region src/generators/createReactGenerator.d.ts
334
- type UserGenerator$1<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
361
+ type UserGenerator$1<TOptions extends PluginFactoryOptions> = {
335
362
  name: string;
336
- version?: TVersion;
337
- Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode;
338
- Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode;
339
- Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode;
363
+ Operations?: (props: OperationsProps<TOptions>) => FabricReactNode;
364
+ Operation?: (props: OperationProps<TOptions>) => FabricReactNode;
365
+ Schema?: (props: SchemaProps<TOptions>) => FabricReactNode;
340
366
  };
341
- type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
367
+ type ReactGenerator<TOptions extends PluginFactoryOptions> = {
342
368
  name: string;
343
369
  type: 'react';
344
- version: TVersion;
345
- Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode;
346
- Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode;
347
- Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode;
370
+ version: '1';
371
+ Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
372
+ Operation: (props: OperationProps<TOptions>) => FabricReactNode;
373
+ Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
348
374
  };
349
375
  /****
350
376
  * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
@@ -353,35 +379,22 @@ type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Vers
353
379
  *
354
380
  * @returns A generator object with async methods for operations, operation, and schema file generation.
355
381
  */
356
- declare function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(generator: UserGenerator$1<TOptions, TVersion>): ReactGenerator<TOptions, TVersion>;
382
+ declare function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator$1<TOptions>): ReactGenerator<TOptions>;
357
383
  //#endregion
358
384
  //#region src/generators/types.d.ts
359
- type Version = '1' | '2';
360
- type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
385
+ type OperationsProps<TOptions extends PluginFactoryOptions> = {
361
386
  config: Config;
362
387
  generator: Omit<OperationGenerator<TOptions>, 'build'>;
363
388
  plugin: Plugin<TOptions>;
364
389
  operations: Array<Operation>;
365
390
  };
366
- type OperationsV2Props<TOptions extends PluginFactoryOptions> = {
367
- config: Config;
368
- plugin: Plugin<TOptions>;
369
- nodes: Array<OperationNode>;
370
- };
371
- type OperationV1Props<TOptions extends PluginFactoryOptions> = {
391
+ type OperationProps<TOptions extends PluginFactoryOptions> = {
372
392
  config: Config;
373
393
  generator: Omit<OperationGenerator<TOptions>, 'build'>;
374
394
  plugin: Plugin<TOptions>;
375
395
  operation: Operation;
376
396
  };
377
- type OperationV2Props<TOptions extends PluginFactoryOptions> = {
378
- config: Config;
379
- plugin: Plugin<TOptions>;
380
- node: OperationNode;
381
- };
382
- type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationsV2Props<TOptions> : OperationsV1Props<TOptions>;
383
- type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationV2Props<TOptions> : OperationV1Props<TOptions>;
384
- type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
397
+ type SchemaProps<TOptions extends PluginFactoryOptions> = {
385
398
  config: Config;
386
399
  generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
387
400
  plugin: Plugin<TOptions>;
@@ -391,31 +404,24 @@ type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
391
404
  value: SchemaObject;
392
405
  };
393
406
  };
394
- type SchemaV2Props<TOptions extends PluginFactoryOptions> = {
395
- config: Config;
396
- plugin: Plugin<TOptions>;
397
- node: SchemaNode;
398
- };
399
- type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? SchemaV2Props<TOptions> : SchemaV1Props<TOptions>;
400
- type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> = CoreGenerator<TOptions, TVersion> | ReactGenerator<TOptions, TVersion>;
407
+ type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
401
408
  //#endregion
402
409
  //#region src/generators/createGenerator.d.ts
403
- type UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
410
+ type UserGenerator<TOptions extends PluginFactoryOptions> = {
404
411
  name: string;
405
- version?: TVersion;
406
- operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
407
- operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
408
- schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
412
+ operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
413
+ operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
414
+ schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
409
415
  };
410
- type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
416
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
411
417
  name: string;
412
418
  type: 'core';
413
- version: TVersion;
414
- operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
415
- operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
416
- schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
419
+ version: '1';
420
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
421
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
422
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
417
423
  };
418
- declare function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(generator: UserGenerator<TOptions, TVersion>): CoreGenerator<TOptions, TVersion>;
424
+ declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
419
425
  //#endregion
420
- export { ResolvePathOptions as C, Refs as S, OperationSchemas as _, ReactGenerator as a, PluginOas as b, SchemaGenerator as c, SchemaMethodResult as d, OperationGenerator as f, OperationSchema as g, Include as h, Version as i, SchemaGeneratorBuildOptions as l, Exclude as m, createGenerator as n, createReactGenerator as o, OperationMethodResult as p, Generator as r, GetSchemaGeneratorOptions as s, CoreGenerator as t, SchemaGeneratorOptions as u, Options as v, Resolver as w, Ref as x, Override as y };
421
- //# sourceMappingURL=createGenerator-CBXpHeVY.d.ts.map
426
+ export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator$1 as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, Refs as x, PluginOas as y };
427
+ //# sourceMappingURL=createGenerator-Cl7uTbJt.d.ts.map
@@ -4,7 +4,7 @@ const require_getFooter = require("./getFooter-BBzsC616.cjs");
4
4
  function createGenerator(generator) {
5
5
  return {
6
6
  type: "core",
7
- version: generator.version ?? "1",
7
+ version: "1",
8
8
  async operations() {
9
9
  return [];
10
10
  },
@@ -29,7 +29,7 @@ function createGenerator(generator) {
29
29
  function createReactGenerator(generator) {
30
30
  return {
31
31
  type: "react",
32
- version: generator.version ?? "1",
32
+ version: "1",
33
33
  Operations() {
34
34
  return null;
35
35
  },
@@ -47,13 +47,13 @@ function createReactGenerator(generator) {
47
47
  const jsonGenerator = createGenerator({
48
48
  name: "plugin-oas",
49
49
  async schema({ schema, generator }) {
50
- const { pluginManager, plugin } = generator.context;
50
+ const { driver, plugin } = generator.context;
51
51
  return [{
52
- ...pluginManager.getFile({
52
+ ...driver.getFile({
53
53
  name: require_getFooter.camelCase(schema.name),
54
54
  extname: ".json",
55
55
  mode: "split",
56
- pluginKey: plugin.key
56
+ pluginName: plugin.name
57
57
  }),
58
58
  sources: [{
59
59
  name: require_getFooter.camelCase(schema.name),
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
64
64
  banner: require_getFooter.getBanner({
65
65
  oas: generator.context.oas,
66
66
  output: plugin.options.output,
67
- config: pluginManager.config
67
+ config: driver.config
68
68
  }),
69
69
  format: require_getFooter.getFooter({
70
70
  oas: generator.context.oas,
@@ -93,4 +93,4 @@ Object.defineProperty(exports, "jsonGenerator", {
93
93
  }
94
94
  });
95
95
 
96
- //# sourceMappingURL=generators-CyWd3UXA.cjs.map
96
+ //# sourceMappingURL=generators-BfTTScuN.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-BfTTScuN.cjs","names":["camelCase","getBanner","getFooter"],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,kBAAAA,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQC,kBAAAA,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
@@ -4,7 +4,7 @@ import { n as getBanner, r as camelCase, t as getFooter } from "./getFooter-Pw3t
4
4
  function createGenerator(generator) {
5
5
  return {
6
6
  type: "core",
7
- version: generator.version ?? "1",
7
+ version: "1",
8
8
  async operations() {
9
9
  return [];
10
10
  },
@@ -29,7 +29,7 @@ function createGenerator(generator) {
29
29
  function createReactGenerator(generator) {
30
30
  return {
31
31
  type: "react",
32
- version: generator.version ?? "1",
32
+ version: "1",
33
33
  Operations() {
34
34
  return null;
35
35
  },
@@ -47,13 +47,13 @@ function createReactGenerator(generator) {
47
47
  const jsonGenerator = createGenerator({
48
48
  name: "plugin-oas",
49
49
  async schema({ schema, generator }) {
50
- const { pluginManager, plugin } = generator.context;
50
+ const { driver, plugin } = generator.context;
51
51
  return [{
52
- ...pluginManager.getFile({
52
+ ...driver.getFile({
53
53
  name: camelCase(schema.name),
54
54
  extname: ".json",
55
55
  mode: "split",
56
- pluginKey: plugin.key
56
+ pluginName: plugin.name
57
57
  }),
58
58
  sources: [{
59
59
  name: camelCase(schema.name),
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
64
64
  banner: getBanner({
65
65
  oas: generator.context.oas,
66
66
  output: plugin.options.output,
67
- config: pluginManager.config
67
+ config: driver.config
68
68
  }),
69
69
  format: getFooter({
70
70
  oas: generator.context.oas,
@@ -76,4 +76,4 @@ const jsonGenerator = createGenerator({
76
76
  //#endregion
77
77
  export { createReactGenerator as n, createGenerator as r, jsonGenerator as t };
78
78
 
79
- //# sourceMappingURL=generators-D7C3CXsN.js.map
79
+ //# sourceMappingURL=generators-BjsINk-u.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-BjsINk-u.js","names":[],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAM,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQ,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generators = require("./generators-CyWd3UXA.cjs");
2
+ const require_generators = require("./generators-BfTTScuN.cjs");
3
3
  exports.createGenerator = require_generators.createGenerator;
4
4
  exports.createReactGenerator = require_generators.createReactGenerator;
5
5
  exports.jsonGenerator = require_generators.jsonGenerator;
@@ -1,7 +1,7 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { b as PluginOas, n as createGenerator, o as createReactGenerator, r as Generator, t as CoreGenerator } from "./createGenerator-CBXpHeVY.js";
2
+ import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-Cl7uTbJt.js";
3
3
  //#region src/generators/jsonGenerator.d.ts
4
- declare const jsonGenerator: CoreGenerator<PluginOas, "1">;
4
+ declare const jsonGenerator: CoreGenerator<PluginOas>;
5
5
  //#endregion
6
6
  export { type Generator, createGenerator, createReactGenerator, jsonGenerator };
7
7
  //# sourceMappingURL=generators.d.ts.map
@@ -1,2 +1,2 @@
1
- import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-D7C3CXsN.js";
1
+ import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-BjsINk-u.js";
2
2
  export { createGenerator, createReactGenerator, jsonGenerator };
package/dist/hooks.cjs CHANGED
@@ -3,8 +3,11 @@ require("./chunk-ByKO4r7w.cjs");
3
3
  let _kubb_react_fabric = require("@kubb/react-fabric");
4
4
  let _kubb_core_hooks = require("@kubb/core/hooks");
5
5
  //#region src/hooks/useOas.ts
6
+ /**
7
+ * @deprecated use schemaNode or operationNode instead
8
+ */
6
9
  function useOas() {
7
- const { meta } = (0, _kubb_react_fabric.useApp)();
10
+ const { meta } = (0, _kubb_react_fabric.useFabric)();
8
11
  return meta.oas;
9
12
  }
10
13
  //#endregion
@@ -14,11 +17,12 @@ function useOas() {
14
17
  */
15
18
  function useOperationManager(generator) {
16
19
  const plugin = (0, _kubb_core_hooks.usePlugin)();
17
- const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
18
- const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
19
- return pluginManager.resolveName({
20
+ const driver = (0, _kubb_core_hooks.usePluginDriver)();
21
+ const defaultPluginName = plugin.name;
22
+ const getName = (operation, { prefix = "", suffix = "", pluginName = defaultPluginName, type }) => {
23
+ return driver.resolveName({
20
24
  name: `${prefix} ${operation.getOperationId()} ${suffix}`,
21
- pluginKey,
25
+ pluginName,
22
26
  type
23
27
  });
24
28
  };
@@ -30,27 +34,27 @@ function useOperationManager(generator) {
30
34
  };
31
35
  const getSchemas = (operation, params) => {
32
36
  if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
33
- return generator.getSchemas(operation, { resolveName: (name) => pluginManager.resolveName({
37
+ return generator.getSchemas(operation, { resolveName: (name) => driver.resolveName({
34
38
  name,
35
- pluginKey: params?.pluginKey,
39
+ pluginName: params?.pluginName ?? defaultPluginName,
36
40
  type: params?.type
37
41
  }) });
38
42
  };
39
- const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, extname = ".ts" } = {}) => {
43
+ const getFile = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = ".ts" } = {}) => {
40
44
  const name = getName(operation, {
41
45
  type: "file",
42
- pluginKey,
46
+ pluginName,
43
47
  prefix,
44
48
  suffix
45
49
  });
46
50
  const group = getGroup(operation);
47
- const file = pluginManager.getFile({
51
+ const file = driver.getFile({
48
52
  name,
49
53
  extname,
50
- pluginKey,
54
+ pluginName,
51
55
  options: {
52
56
  type: "file",
53
- pluginKey,
57
+ pluginName,
54
58
  group
55
59
  }
56
60
  });
@@ -59,60 +63,60 @@ function useOperationManager(generator) {
59
63
  meta: {
60
64
  ...file.meta,
61
65
  name,
62
- pluginKey,
66
+ pluginName,
63
67
  group
64
68
  }
65
69
  };
66
70
  };
67
- const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
71
+ const groupSchemasByName = (operation, { pluginName = defaultPluginName, type }) => {
68
72
  if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
69
- const schemas = generator.getSchemas(operation);
73
+ const schemas = getSchemas(operation);
70
74
  const errors = (schemas.errors || []).reduce((prev, acc) => {
71
75
  if (!acc.statusCode) return prev;
72
- prev[acc.statusCode] = pluginManager.resolveName({
76
+ prev[acc.statusCode] = driver.resolveName({
73
77
  name: acc.name,
74
- pluginKey,
78
+ pluginName,
75
79
  type
76
80
  });
77
81
  return prev;
78
82
  }, {});
79
83
  const responses = (schemas.responses || []).reduce((prev, acc) => {
80
84
  if (!acc.statusCode) return prev;
81
- prev[acc.statusCode] = pluginManager.resolveName({
85
+ prev[acc.statusCode] = driver.resolveName({
82
86
  name: acc.name,
83
- pluginKey,
87
+ pluginName,
84
88
  type
85
89
  });
86
90
  return prev;
87
91
  }, {});
88
92
  return {
89
- request: schemas.request?.name ? pluginManager.resolveName({
93
+ request: schemas.request?.name ? driver.resolveName({
90
94
  name: schemas.request.name,
91
- pluginKey,
95
+ pluginName,
92
96
  type
93
97
  }) : void 0,
94
98
  parameters: {
95
- path: schemas.pathParams?.name ? pluginManager.resolveName({
99
+ path: schemas.pathParams?.name ? driver.resolveName({
96
100
  name: schemas.pathParams.name,
97
- pluginKey,
101
+ pluginName,
98
102
  type
99
103
  }) : void 0,
100
- query: schemas.queryParams?.name ? pluginManager.resolveName({
104
+ query: schemas.queryParams?.name ? driver.resolveName({
101
105
  name: schemas.queryParams.name,
102
- pluginKey,
106
+ pluginName,
103
107
  type
104
108
  }) : void 0,
105
- header: schemas.headerParams?.name ? pluginManager.resolveName({
109
+ header: schemas.headerParams?.name ? driver.resolveName({
106
110
  name: schemas.headerParams.name,
107
- pluginKey,
111
+ pluginName,
108
112
  type
109
113
  }) : void 0
110
114
  },
111
115
  responses: {
112
116
  ...responses,
113
- ["default"]: pluginManager.resolveName({
117
+ ["default"]: driver.resolveName({
114
118
  name: schemas.response.name,
115
- pluginKey,
119
+ pluginName,
116
120
  type
117
121
  }),
118
122
  ...errors
@@ -129,55 +133,33 @@ function useOperationManager(generator) {
129
133
  };
130
134
  }
131
135
  //#endregion
132
- //#region src/hooks/useRootNode.ts
133
- /**
134
- * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
135
- *
136
- * Use this hook inside generator components when you want to consume the
137
- * format-agnostic AST directly instead of going through `useOas()`.
138
- *
139
- * Returns `undefined` when no adapter was configured (legacy OAS-only mode).
140
- *
141
- * @example
142
- * ```tsx
143
- * function MyComponent() {
144
- * const rootNode = useRootNode()
145
- * if (!rootNode) return null
146
- * return <>{rootNode.schemas.map(s => <Schema key={s.name} node={s} />)}</>
147
- * }
148
- * ```
149
- */
150
- function useRootNode() {
151
- const { meta } = (0, _kubb_react_fabric.useApp)();
152
- return meta.pluginManager?.rootNode;
153
- }
154
- //#endregion
155
136
  //#region src/hooks/useSchemaManager.ts
156
137
  /**
157
138
  * `useSchemaManager` returns helper functions to get the schema file and schema name.
139
+ * @deprecated
158
140
  */
159
141
  function useSchemaManager() {
160
142
  const plugin = (0, _kubb_core_hooks.usePlugin)();
161
- const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
162
- const getName = (name, { pluginKey = plugin.key, type }) => {
163
- return pluginManager.resolveName({
143
+ const driver = (0, _kubb_core_hooks.usePluginDriver)();
144
+ const getName = (name, { pluginName = plugin.name, type }) => {
145
+ return driver.resolveName({
164
146
  name,
165
- pluginKey,
147
+ pluginName,
166
148
  type
167
149
  });
168
150
  };
169
- const getFile = (name, { mode = "split", pluginKey = plugin.key, extname = ".ts", group } = {}) => {
151
+ const getFile = (name, { mode = "split", pluginName = plugin.name, extname = ".ts", group } = {}) => {
170
152
  const resolvedName = mode === "single" ? "" : getName(name, {
171
153
  type: "file",
172
- pluginKey
154
+ pluginName
173
155
  });
174
- const file = pluginManager.getFile({
156
+ const file = driver.getFile({
175
157
  name: resolvedName,
176
158
  extname,
177
- pluginKey,
159
+ pluginName,
178
160
  options: {
179
161
  type: "file",
180
- pluginKey,
162
+ pluginName,
181
163
  group
182
164
  }
183
165
  });
@@ -186,7 +168,7 @@ function useSchemaManager() {
186
168
  meta: {
187
169
  ...file.meta,
188
170
  name: resolvedName,
189
- pluginKey
171
+ pluginName
190
172
  }
191
173
  };
192
174
  };
@@ -198,7 +180,6 @@ function useSchemaManager() {
198
180
  //#endregion
199
181
  exports.useOas = useOas;
200
182
  exports.useOperationManager = useOperationManager;
201
- exports.useRootNode = useRootNode;
202
183
  exports.useSchemaManager = useSchemaManager;
203
184
 
204
185
  //# sourceMappingURL=hooks.cjs.map