@kubb/oas 4.5.0 → 4.5.2

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/index.d.cts CHANGED
@@ -5,9 +5,12 @@ import { Operation as Operation$1 } from "oas/operation";
5
5
  import { OpenAPIV3 as OpenAPIV3$1, OpenAPIV3_1 as OpenAPIV3_1$1 } from "openapi-types";
6
6
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
7
  import BaseOas from "oas";
8
+ import { KubbFile } from "@kubb/fabric-core/types";
9
+ import { Fabric } from "@kubb/react-fabric";
10
+ import { ConsolaInstance, LogLevel } from "consola";
8
11
 
9
12
  //#region src/Oas.d.ts
10
- type Options = {
13
+ type Options$1 = {
11
14
  contentType?: contentType;
12
15
  discriminator?: 'strict' | 'inherit';
13
16
  };
@@ -21,8 +24,8 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
21
24
  oas: TOAS | OASDocument | string;
22
25
  user?: User;
23
26
  });
24
- setOptions(options: Options): void;
25
- get options(): Options;
27
+ setOptions(options: Options$1): void;
28
+ get options(): Options$1;
26
29
  get($ref: string): any;
27
30
  getKey($ref: string): string | undefined;
28
31
  set($ref: string, value: unknown): false | undefined;
@@ -34,6 +37,439 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
34
37
  valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
35
38
  }
36
39
  //#endregion
40
+ //#region ../core/src/utils/EventEmitter.d.ts
41
+ declare class EventEmitter<TEvents extends Record<string, any>> {
42
+ #private;
43
+ constructor();
44
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
45
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
46
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
47
+ removeAll(): void;
48
+ }
49
+ //#endregion
50
+ //#region ../core/src/logger.d.ts
51
+ type DebugEvent = {
52
+ date: Date;
53
+ logs: string[];
54
+ fileName?: string;
55
+ };
56
+ type Events$1 = {
57
+ start: [message: string];
58
+ success: [message: string];
59
+ error: [message: string, cause: Error];
60
+ warning: [message: string];
61
+ debug: [DebugEvent];
62
+ info: [message: string];
63
+ progress_start: [{
64
+ id: string;
65
+ size: number;
66
+ message?: string;
67
+ }];
68
+ progressed: [{
69
+ id: string;
70
+ message?: string;
71
+ }];
72
+ progress_stop: [{
73
+ id: string;
74
+ }];
75
+ };
76
+ type Logger = {
77
+ /**
78
+ * Optional config name to show in CLI output
79
+ */
80
+ name?: string;
81
+ logLevel: LogLevel;
82
+ consola?: ConsolaInstance;
83
+ on: EventEmitter<Events$1>['on'];
84
+ emit: EventEmitter<Events$1>['emit'];
85
+ writeLogs: () => Promise<string[]>;
86
+ };
87
+ //#endregion
88
+ //#region ../core/src/utils/types.d.ts
89
+ type PossiblePromise<T> = Promise<T> | T;
90
+ //#endregion
91
+ //#region ../core/src/types.d.ts
92
+ declare global {
93
+ namespace Kubb {
94
+ interface PluginContext {}
95
+ }
96
+ }
97
+ /**
98
+ * Config used in `kubb.config.ts`
99
+ *
100
+ * @example
101
+ * import { defineConfig } from '@kubb/core'
102
+ * export default defineConfig({
103
+ * ...
104
+ * })
105
+ */
106
+
107
+ type InputPath = {
108
+ /**
109
+ * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
110
+ */
111
+ path: string;
112
+ };
113
+ type InputData = {
114
+ /**
115
+ * A `string` or `object` that contains your Swagger/OpenAPI data.
116
+ */
117
+ data: string | unknown;
118
+ };
119
+ type Input = InputPath | InputData | Array<InputPath>;
120
+ type BarrelType = 'all' | 'named' | 'propagate';
121
+ /**
122
+ * @private
123
+ */
124
+ type Config<TInput = Input> = {
125
+ /**
126
+ * The name to display in the CLI output.
127
+ */
128
+ name?: string;
129
+ /**
130
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
131
+ * @default process.cwd()
132
+ */
133
+ root: string;
134
+ /**
135
+ * You can use either `input.path` or `input.data`, depending on your specific needs.
136
+ */
137
+ input: TInput;
138
+ output: {
139
+ /**
140
+ * The path where all generated files will be exported.
141
+ * This can be an absolute path or a path relative to the specified root option.
142
+ */
143
+ path: string;
144
+ /**
145
+ * Clean the output directory before each build.
146
+ */
147
+ clean?: boolean;
148
+ /**
149
+ * Save files to the file system.
150
+ * @default true
151
+ */
152
+ write?: boolean;
153
+ /**
154
+ * Specifies the formatting tool to be used.
155
+ * @default prettier
156
+ *
157
+ * Possible values:
158
+ * - 'prettier': Uses Prettier for code formatting.
159
+ * - 'biome': Uses Biome for code formatting.
160
+ *
161
+ */
162
+ format?: 'prettier' | 'biome' | false;
163
+ /**
164
+ * Specifies the linter that should be used to analyze the code.
165
+ * The accepted values indicate different linting tools.
166
+ *
167
+ * Possible values:
168
+ * - 'eslint': Represents the use of ESLint, a widely used JavaScript linter.
169
+ * - 'biome': Represents the Biome linter, a modern tool for code scanning.
170
+ * - 'oxlint': Represents the Oxlint tool for linting purposes.
171
+ *
172
+ */
173
+ lint?: 'eslint' | 'biome' | 'oxlint' | false;
174
+ /**
175
+ * Override the extension to the generated imports and exports, by default each plugin will add an extension
176
+ * @default { '.ts': '.ts'}
177
+ */
178
+ extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
179
+ /**
180
+ * Specify how `index.ts` files should be created. You can also disable the generation of barrel files here. While each plugin has its own `barrelType` option, this setting controls the creation of the root barrel file, such as` src/gen/index.ts`.
181
+ * @default 'named'
182
+ */
183
+ barrelType?: Exclude<BarrelType, 'propagate'> | false;
184
+ /**
185
+ * Add a default banner to the beginning of every generated file. This makes it clear that the file was generated by Kubb.
186
+ * - 'simple': will only add banner with link to Kubb
187
+ * - 'full': will add source, title, description and the OpenAPI version used
188
+ * @default 'simple'
189
+ */
190
+ defaultBanner?: 'simple' | 'full' | false;
191
+ };
192
+ /**
193
+ * An array of Kubb plugins that will be used in the generation.
194
+ * Each plugin may include additional configurable options(defined in the plugin itself).
195
+ * If a plugin depends on another plugin, an error will be returned if the required dependency is missing. See pre for more details.
196
+ */
197
+ plugins?: Array<Plugin>;
198
+ /**
199
+ * Hooks that will be called when a specific action is triggered in Kubb.
200
+ */
201
+ hooks?: {
202
+ /**
203
+ * Hook that will be triggered at the end of all executions.
204
+ * Useful for running Prettier or ESLint to format/lint your code.
205
+ */
206
+ done?: string | Array<string>;
207
+ };
208
+ };
209
+ type PluginFactoryOptions<
210
+ /**
211
+ * Name to be used for the plugin, this will also be used for they key.
212
+ */
213
+ TName extends string = string,
214
+ /**
215
+ * Options of the plugin.
216
+ */
217
+ TOptions extends object = object,
218
+ /**
219
+ * Options of the plugin that can be used later on, see `options` inside your plugin config.
220
+ */
221
+ TResolvedOptions extends object = TOptions,
222
+ /**
223
+ * Context that you want to expose to other plugins.
224
+ */
225
+ TContext = any,
226
+ /**
227
+ * When calling `resolvePath` you can specify better types.
228
+ */
229
+ TResolvePathOptions extends object = object> = {
230
+ name: TName;
231
+ /**
232
+ * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
233
+ */
234
+ key: PluginKey<TName | string>;
235
+ options: TOptions;
236
+ resolvedOptions: TResolvedOptions;
237
+ context: TContext;
238
+ resolvePathOptions: TResolvePathOptions;
239
+ };
240
+ type PluginKey<TName> = [name: TName, identifier?: string | number];
241
+ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
242
+ /**
243
+ * Unique name used for the plugin
244
+ * @example @kubb/typescript
245
+ */
246
+ name: TOptions['name'];
247
+ /**
248
+ * Internal key used when a developer uses more than one of the same plugin
249
+ * @private
250
+ */
251
+ key: TOptions['key'];
252
+ /**
253
+ * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
254
+ * Can be used to validate dependent plugins.
255
+ */
256
+ pre?: Array<string>;
257
+ /**
258
+ * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
259
+ */
260
+ post?: Array<string>;
261
+ /**
262
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
263
+ */
264
+ options: TOptions['resolvedOptions'];
265
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
266
+ /**
267
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
268
+ */
269
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
270
+ };
271
+ type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
272
+ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
273
+ /**
274
+ * Start of the lifecycle of a plugin.
275
+ * @type hookParallel
276
+ */
277
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
278
+ /**
279
+ * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
280
+ * Options can als be included.
281
+ * @type hookFirst
282
+ * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
283
+ */
284
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
285
+ /**
286
+ * Resolve to a name based on a string.
287
+ * Useful when converting to PascalCase or camelCase.
288
+ * @type hookFirst
289
+ * @example ('pet') => 'Pet'
290
+ */
291
+ resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
292
+ };
293
+ type PluginLifecycleHooks = keyof PluginLifecycle;
294
+ type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
295
+ type ResolvePathParams<TOptions = object> = {
296
+ pluginKey?: Plugin['key'];
297
+ baseName: KubbFile.BaseName;
298
+ mode?: KubbFile.Mode;
299
+ /**
300
+ * Options to be passed to 'resolvePath' 3th parameter
301
+ */
302
+ options?: TOptions;
303
+ };
304
+ type ResolveNameParams = {
305
+ name: string;
306
+ pluginKey?: Plugin['key'];
307
+ /**
308
+ * `file` will be used to customize the name of the created file(use of camelCase)
309
+ * `function` can be used to customize the exported functions(use of camelCase)
310
+ * `type` is a special type for TypeScript(use of PascalCase)
311
+ * `const` can be used for variables(use of camelCase)
312
+ */
313
+ type?: 'file' | 'function' | 'type' | 'const';
314
+ };
315
+ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
316
+ fabric: Fabric;
317
+ config: Config;
318
+ pluginManager: PluginManager;
319
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
320
+ logger: Logger;
321
+ mode: KubbFile.Mode;
322
+ /**
323
+ * Current plugin
324
+ */
325
+ plugin: Plugin<TOptions>;
326
+ } & Kubb.PluginContext;
327
+ //#endregion
328
+ //#region ../core/src/PluginManager.d.ts
329
+ type RequiredPluginLifecycle = Required<PluginLifecycle>;
330
+ type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
331
+ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
332
+ message: string;
333
+ strategy: Strategy;
334
+ hookName: H;
335
+ plugin: Plugin;
336
+ parameters?: unknown[] | undefined;
337
+ output?: unknown;
338
+ };
339
+ type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
340
+ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
341
+ result: Result;
342
+ plugin: Plugin;
343
+ };
344
+ type Options = {
345
+ fabric: Fabric;
346
+ logger: Logger;
347
+ /**
348
+ * @default Number.POSITIVE_INFINITY
349
+ */
350
+ concurrency?: number;
351
+ };
352
+ type Events = {
353
+ executing: [executer: Executer];
354
+ executed: [executer: Executer];
355
+ error: [error: Error];
356
+ };
357
+ type GetFileProps<TOptions = object> = {
358
+ name: string;
359
+ mode?: KubbFile.Mode;
360
+ extname: KubbFile.Extname;
361
+ pluginKey: Plugin['key'];
362
+ options?: TOptions;
363
+ };
364
+ declare class PluginManager {
365
+ #private;
366
+ readonly events: EventEmitter<Events>;
367
+ readonly config: Config;
368
+ readonly executed: Array<Executer>;
369
+ readonly logger: Logger;
370
+ readonly options: Options;
371
+ constructor(config: Config, options: Options);
372
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
373
+ get plugins(): Array<Plugin>;
374
+ getFile<TOptions = object>({
375
+ name,
376
+ mode,
377
+ extname,
378
+ pluginKey,
379
+ options
380
+ }: GetFileProps<TOptions>): KubbFile.File<{
381
+ pluginKey: Plugin['key'];
382
+ }>;
383
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
384
+ resolveName: (params: ResolveNameParams) => string;
385
+ /**
386
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
387
+ */
388
+ on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
389
+ /**
390
+ * Run a specific hookName for plugin x.
391
+ */
392
+ hookForPlugin<H extends PluginLifecycleHooks>({
393
+ pluginKey,
394
+ hookName,
395
+ parameters,
396
+ message
397
+ }: {
398
+ pluginKey: Plugin['key'];
399
+ hookName: H;
400
+ parameters: PluginParameter<H>;
401
+ message: string;
402
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
403
+ /**
404
+ * Run a specific hookName for plugin x.
405
+ */
406
+ hookForPluginSync<H extends PluginLifecycleHooks>({
407
+ pluginKey,
408
+ hookName,
409
+ parameters,
410
+ message
411
+ }: {
412
+ pluginKey: Plugin['key'];
413
+ hookName: H;
414
+ parameters: PluginParameter<H>;
415
+ message: string;
416
+ }): Array<ReturnType<ParseResult<H>>> | null;
417
+ /**
418
+ * First non-null result stops and will return it's value.
419
+ */
420
+ hookFirst<H extends PluginLifecycleHooks>({
421
+ hookName,
422
+ parameters,
423
+ skipped,
424
+ message
425
+ }: {
426
+ hookName: H;
427
+ parameters: PluginParameter<H>;
428
+ skipped?: ReadonlySet<Plugin> | null;
429
+ message: string;
430
+ }): Promise<SafeParseResult<H>>;
431
+ /**
432
+ * First non-null result stops and will return it's value.
433
+ */
434
+ hookFirstSync<H extends PluginLifecycleHooks>({
435
+ hookName,
436
+ parameters,
437
+ skipped,
438
+ message
439
+ }: {
440
+ hookName: H;
441
+ parameters: PluginParameter<H>;
442
+ skipped?: ReadonlySet<Plugin> | null;
443
+ message: string;
444
+ }): SafeParseResult<H>;
445
+ /**
446
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
447
+ */
448
+ hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
449
+ hookName,
450
+ parameters,
451
+ message
452
+ }: {
453
+ hookName: H;
454
+ parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
455
+ message: string;
456
+ }): Promise<Awaited<TOuput>[]>;
457
+ /**
458
+ * Chains plugins
459
+ */
460
+ hookSeq<H extends PluginLifecycleHooks>({
461
+ hookName,
462
+ parameters,
463
+ message
464
+ }: {
465
+ hookName: H;
466
+ parameters?: PluginParameter<H>;
467
+ message: string;
468
+ }): Promise<void>;
469
+ getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
470
+ getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
471
+ }
472
+ //#endregion
37
473
  //#region src/utils.d.ts
38
474
  declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1$1.Document;
39
475
  declare function isParameterObject(obj: ParameterObject | SchemaObject$1): obj is ParameterObject;
@@ -84,6 +520,7 @@ declare function merge(pathOrApi: Array<string | OASDocument>, {
84
520
  }?: {
85
521
  oasClass?: typeof Oas;
86
522
  }): Promise<Oas>;
523
+ declare function parseFromConfig(config: Config, oasClass?: typeof Oas): Promise<Oas>;
87
524
  //#endregion
88
- export { HttpMethod, HttpMethods, type Infer, type Model, Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Operation, type RequestParams, type Response, SchemaObject, contentType, findSchemaDefinition, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, matchesMimeType, merge, parse };
525
+ export { HttpMethod, HttpMethods, type Infer, type Model, Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Operation, type RequestParams, type Response, SchemaObject, contentType, findSchemaDefinition, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, matchesMimeType, merge, parse, parseFromConfig };
89
526
  //# sourceMappingURL=index.d.cts.map