@kubb/plugin-ts 5.0.0-alpha.11 → 5.0.0-alpha.12

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 (43) hide show
  1. package/dist/{components-CRu8IKY3.js → Type-CX1HRooG.js} +377 -365
  2. package/dist/Type-CX1HRooG.js.map +1 -0
  3. package/dist/Type-Cat0_htq.cjs +808 -0
  4. package/dist/Type-Cat0_htq.cjs.map +1 -0
  5. package/dist/components.cjs +3 -2
  6. package/dist/components.d.ts +40 -9
  7. package/dist/components.js +2 -2
  8. package/dist/generators-CLuCmfUz.js +532 -0
  9. package/dist/generators-CLuCmfUz.js.map +1 -0
  10. package/dist/generators-DWBU-MuW.cjs +536 -0
  11. package/dist/generators-DWBU-MuW.cjs.map +1 -0
  12. package/dist/generators.cjs +2 -3
  13. package/dist/generators.d.ts +3 -503
  14. package/dist/generators.js +2 -2
  15. package/dist/index.cjs +308 -4
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +26 -21
  18. package/dist/index.js +305 -2
  19. package/dist/index.js.map +1 -0
  20. package/dist/{types-mSXmB8WU.d.ts → types-BA1ZCQ5p.d.ts} +73 -57
  21. package/package.json +5 -5
  22. package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
  23. package/src/components/Type.tsx +23 -141
  24. package/src/components/index.ts +1 -0
  25. package/src/generators/index.ts +0 -1
  26. package/src/generators/typeGenerator.tsx +189 -413
  27. package/src/generators/utils.ts +298 -0
  28. package/src/index.ts +1 -1
  29. package/src/plugin.ts +80 -126
  30. package/src/printer.ts +15 -4
  31. package/src/resolverTs.ts +109 -1
  32. package/src/types.ts +68 -52
  33. package/dist/components-CRu8IKY3.js.map +0 -1
  34. package/dist/components-DeNDKlzf.cjs +0 -982
  35. package/dist/components-DeNDKlzf.cjs.map +0 -1
  36. package/dist/plugin-CJ29AwE2.cjs +0 -1320
  37. package/dist/plugin-CJ29AwE2.cjs.map +0 -1
  38. package/dist/plugin-D60XNJSD.js +0 -1267
  39. package/dist/plugin-D60XNJSD.js.map +0 -1
  40. package/src/components/v2/Type.tsx +0 -59
  41. package/src/generators/v2/typeGenerator.tsx +0 -167
  42. package/src/generators/v2/utils.ts +0 -140
  43. package/src/parser.ts +0 -389
@@ -1,509 +1,9 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginTs } from "./types-mSXmB8WU.js";
2
+ import { n as PluginTs } from "./types-BA1ZCQ5p.js";
3
3
  import * as _kubb_core0 from "@kubb/core";
4
- import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
5
- import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
6
- import { FabricReactNode } from "@kubb/react-fabric/types";
7
- import { Fabric, KubbFile } from "@kubb/fabric-core/types";
8
4
 
9
- //#region ../../internals/utils/src/asyncEventEmitter.d.ts
10
- /** A function that can be registered as an event listener, synchronous or async. */
11
- type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
12
- /**
13
- * A typed EventEmitter that awaits all async listeners before resolving.
14
- * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
15
- */
16
- declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
17
- #private;
18
- /**
19
- * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
20
- * @default 10
21
- */
22
- constructor(maxListener?: number);
23
- /**
24
- * Emits an event and awaits all registered listeners in parallel.
25
- * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
26
- */
27
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
28
- /** Registers a persistent listener for the given event. */
29
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
30
- /** Registers a one-shot listener that removes itself after the first invocation. */
31
- onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
32
- /** Removes a previously registered listener. */
33
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
34
- /** Removes all listeners from every event channel. */
35
- removeAll(): void;
36
- }
37
- //#endregion
38
- //#region ../plugin-oas/src/types.d.ts
39
- type GetOasOptions = {
40
- validate?: boolean;
41
- };
42
- type Context$2 = {
43
- getOas(options?: GetOasOptions): Promise<Oas>;
44
- getBaseURL(): Promise<string | undefined>;
45
- };
46
- declare global {
47
- namespace Kubb {
48
- interface PluginContext extends Context$2 {}
49
- }
50
- }
51
- /**
52
- * `propertyName` is the ref name + resolved with the nameResolver
53
- * @example import { Pet } from './Pet'
54
- *
55
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
56
- *
57
- * `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
58
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
59
- */
60
- type Ref = {
61
- propertyName: string;
62
- originalName: string;
63
- path: KubbFile.Path;
64
- pluginName?: string;
65
- };
66
- type Refs = Record<string, Ref>;
67
- type OperationSchema = {
68
- /**
69
- * Converted name, contains already `PathParams`, `QueryParams`, ...
70
- */
71
- name: string;
72
- schema: SchemaObject;
73
- operation?: Operation;
74
- /**
75
- * OperationName in PascalCase, only being used in OperationGenerator
76
- */
77
- operationName: string;
78
- description?: string;
79
- statusCode?: number;
80
- keys?: string[];
81
- keysToOmit?: string[];
82
- withData?: boolean;
83
- };
84
- type OperationSchemas = {
85
- pathParams?: OperationSchema & {
86
- keysToOmit?: never;
87
- };
88
- queryParams?: OperationSchema & {
89
- keysToOmit?: never;
90
- };
91
- headerParams?: OperationSchema & {
92
- keysToOmit?: never;
93
- };
94
- request?: OperationSchema;
95
- response: OperationSchema;
96
- responses: Array<OperationSchema>;
97
- statusCodes?: Array<OperationSchema>;
98
- errors?: Array<OperationSchema>;
99
- };
100
- type ByTag = {
101
- type: 'tag';
102
- pattern: string | RegExp;
103
- };
104
- type ByOperationId = {
105
- type: 'operationId';
106
- pattern: string | RegExp;
107
- };
108
- type ByPath = {
109
- type: 'path';
110
- pattern: string | RegExp;
111
- };
112
- type ByMethod = {
113
- type: 'method';
114
- pattern: HttpMethod | RegExp;
115
- };
116
- type BySchemaName = {
117
- type: 'schemaName';
118
- pattern: string | RegExp;
119
- };
120
- type ByContentType = {
121
- type: 'contentType';
122
- pattern: string | RegExp;
123
- };
124
- type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
125
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
126
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
127
- options: Partial<TOptions>;
128
- };
129
- //#endregion
130
- //#region ../plugin-oas/src/OperationGenerator.d.ts
131
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
132
- fabric: Fabric;
133
- oas: Oas;
134
- exclude: Array<Exclude> | undefined;
135
- include: Array<Include> | undefined;
136
- override: Array<Override<TOptions>> | undefined;
137
- contentType: contentType | undefined;
138
- driver: PluginDriver;
139
- events?: AsyncEventEmitter<KubbEvents>;
140
- /**
141
- * Current plugin
142
- */
143
- plugin: Plugin<TPluginOptions>;
144
- mode: KubbFile.Mode;
145
- UNSTABLE_NAMING?: true;
146
- };
147
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
148
- #private;
149
- constructor(options: TPluginOptions['resolvedOptions'], context: Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>);
150
- get options(): TPluginOptions['resolvedOptions'];
151
- set options(options: TPluginOptions['resolvedOptions']);
152
- get context(): Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>;
153
- getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
154
- getSchemas(operation: Operation, {
155
- resolveName
156
- }?: {
157
- resolveName?: (name: string) => string;
158
- }): OperationSchemas;
159
- getOperations(): Promise<Array<{
160
- path: string;
161
- method: HttpMethod;
162
- operation: Operation;
163
- }>>;
164
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
165
- }
166
- //#endregion
167
- //#region ../plugin-oas/src/SchemaMapper.d.ts
168
- type SchemaKeywordMapper = {
169
- object: {
170
- keyword: 'object';
171
- args: {
172
- properties: {
173
- [x: string]: Schema[];
174
- };
175
- additionalProperties: Schema[];
176
- patternProperties?: Record<string, Schema[]>;
177
- strict?: boolean;
178
- };
179
- };
180
- url: {
181
- keyword: 'url';
182
- };
183
- readOnly: {
184
- keyword: 'readOnly';
185
- };
186
- writeOnly: {
187
- keyword: 'writeOnly';
188
- };
189
- uuid: {
190
- keyword: 'uuid';
191
- };
192
- email: {
193
- keyword: 'email';
194
- };
195
- firstName: {
196
- keyword: 'firstName';
197
- };
198
- lastName: {
199
- keyword: 'lastName';
200
- };
201
- phone: {
202
- keyword: 'phone';
203
- };
204
- password: {
205
- keyword: 'password';
206
- };
207
- date: {
208
- keyword: 'date';
209
- args: {
210
- type?: 'date' | 'string';
211
- };
212
- };
213
- time: {
214
- keyword: 'time';
215
- args: {
216
- type?: 'date' | 'string';
217
- };
218
- };
219
- datetime: {
220
- keyword: 'datetime';
221
- args: {
222
- offset?: boolean;
223
- local?: boolean;
224
- };
225
- };
226
- tuple: {
227
- keyword: 'tuple';
228
- args: {
229
- items: Schema[];
230
- min?: number;
231
- max?: number;
232
- rest?: Schema;
233
- };
234
- };
235
- array: {
236
- keyword: 'array';
237
- args: {
238
- items: Schema[];
239
- min?: number;
240
- max?: number;
241
- unique?: boolean;
242
- };
243
- };
244
- enum: {
245
- keyword: 'enum';
246
- args: {
247
- name: string;
248
- typeName: string;
249
- asConst: boolean;
250
- items: Array<{
251
- name: string | number;
252
- format: 'string' | 'number' | 'boolean';
253
- value?: string | number | boolean;
254
- }>;
255
- };
256
- };
257
- and: {
258
- keyword: 'and';
259
- args: Schema[];
260
- };
261
- const: {
262
- keyword: 'const';
263
- args: {
264
- name: string | number;
265
- format: 'string' | 'number' | 'boolean';
266
- value?: string | number | boolean;
267
- };
268
- };
269
- union: {
270
- keyword: 'union';
271
- args: Schema[];
272
- };
273
- ref: {
274
- keyword: 'ref';
275
- args: {
276
- name: string;
277
- $ref: string;
278
- /**
279
- * Full qualified path.
280
- */
281
- path: KubbFile.Path;
282
- /**
283
- * When true `File.Import` is used.
284
- * When false a reference is used inside the current file.
285
- */
286
- isImportable: boolean;
287
- };
288
- };
289
- matches: {
290
- keyword: 'matches';
291
- args?: string;
292
- };
293
- boolean: {
294
- keyword: 'boolean';
295
- };
296
- default: {
297
- keyword: 'default';
298
- args: string | number | boolean;
299
- };
300
- string: {
301
- keyword: 'string';
302
- };
303
- integer: {
304
- keyword: 'integer';
305
- };
306
- bigint: {
307
- keyword: 'bigint';
308
- };
309
- number: {
310
- keyword: 'number';
311
- };
312
- max: {
313
- keyword: 'max';
314
- args: number;
315
- };
316
- min: {
317
- keyword: 'min';
318
- args: number;
319
- };
320
- exclusiveMaximum: {
321
- keyword: 'exclusiveMaximum';
322
- args: number;
323
- };
324
- exclusiveMinimum: {
325
- keyword: 'exclusiveMinimum';
326
- args: number;
327
- };
328
- describe: {
329
- keyword: 'describe';
330
- args: string;
331
- };
332
- example: {
333
- keyword: 'example';
334
- args: string;
335
- };
336
- deprecated: {
337
- keyword: 'deprecated';
338
- };
339
- optional: {
340
- keyword: 'optional';
341
- };
342
- undefined: {
343
- keyword: 'undefined';
344
- };
345
- nullish: {
346
- keyword: 'nullish';
347
- };
348
- nullable: {
349
- keyword: 'nullable';
350
- };
351
- null: {
352
- keyword: 'null';
353
- };
354
- any: {
355
- keyword: 'any';
356
- };
357
- unknown: {
358
- keyword: 'unknown';
359
- };
360
- void: {
361
- keyword: 'void';
362
- };
363
- blob: {
364
- keyword: 'blob';
365
- };
366
- schema: {
367
- keyword: 'schema';
368
- args: {
369
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
370
- format?: string;
371
- };
372
- };
373
- name: {
374
- keyword: 'name';
375
- args: string;
376
- };
377
- catchall: {
378
- keyword: 'catchall';
379
- };
380
- interface: {
381
- keyword: 'interface';
382
- };
383
- };
384
- type Schema = {
385
- keyword: string;
386
- } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
387
- //#endregion
388
- //#region ../plugin-oas/src/SchemaGenerator.d.ts
389
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
390
- fabric: Fabric;
391
- oas: Oas;
392
- driver: PluginDriver;
393
- events?: AsyncEventEmitter<KubbEvents>;
394
- /**
395
- * Current plugin
396
- */
397
- plugin: Plugin<TPluginOptions>;
398
- mode: KubbFile.Mode;
399
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
400
- override: Array<Override<TOptions>> | undefined;
401
- contentType?: contentType;
402
- output?: string;
403
- };
404
- type SchemaGeneratorOptions = {
405
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
406
- integerType?: 'number' | 'bigint';
407
- unknownType: 'any' | 'unknown' | 'void';
408
- emptySchemaType: 'any' | 'unknown' | 'void';
409
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
410
- enumSuffix?: string;
411
- /**
412
- * @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
413
- * When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
414
- * @internal
415
- */
416
- usedEnumNames?: Record<string, number>;
417
- mapper?: Record<string, string>;
418
- typed?: boolean;
419
- transformers: {
420
- /**
421
- * Customize the names based on the type that is provided by the plugin.
422
- */
423
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
424
- /**
425
- * Receive schema and name(propertyName) and return Schema array.
426
- * Return `undefined` to fall through to default schema generation.
427
- * @beta
428
- */
429
- schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
430
- };
431
- };
432
- type SchemaProps$1 = {
433
- schema: SchemaObject | null;
434
- name: string | null;
435
- parentName: string | null;
436
- rootName?: string | null;
437
- };
438
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
439
- #private;
440
- constructor(options: TOptions, context: Context<TOptions, TPluginOptions>);
441
- get options(): TOptions;
442
- set options(options: TOptions);
443
- get context(): Context<TOptions, TPluginOptions>;
444
- refs: Refs;
445
- /**
446
- * Creates a type node from a given schema.
447
- * Delegates to getBaseTypeFromSchema internally and
448
- * optionally adds a union with null.
449
- */
450
- parse(props: SchemaProps$1): Schema[];
451
- static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
452
- static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
453
- static combineObjects(tree: Schema[] | undefined): Schema[];
454
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
455
- }
456
- //#endregion
457
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
458
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
459
- name: string;
460
- type: 'core';
461
- version: '1';
462
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
463
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
464
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
465
- };
466
- //#endregion
467
- //#region ../plugin-oas/src/generators/types.d.ts
468
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
469
- config: Config;
470
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
471
- plugin: Plugin<TOptions>;
472
- operations: Array<Operation>;
473
- };
474
- type OperationProps<TOptions extends PluginFactoryOptions> = {
475
- config: Config;
476
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
477
- plugin: Plugin<TOptions>;
478
- operation: Operation;
479
- };
480
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
481
- config: Config;
482
- generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
483
- plugin: Plugin<TOptions>;
484
- schema: {
485
- name: string;
486
- tree: Array<Schema>;
487
- value: SchemaObject;
488
- };
489
- };
490
- type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
491
- //#endregion
492
- //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
493
- type ReactGenerator<TOptions extends PluginFactoryOptions> = {
494
- name: string;
495
- type: 'react';
496
- version: '1';
497
- Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
498
- Operation: (props: OperationProps<TOptions>) => FabricReactNode;
499
- Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
500
- };
501
- //#endregion
502
5
  //#region src/generators/typeGenerator.d.ts
503
- declare const typeGenerator: ReactGenerator<PluginTs>;
504
- //#endregion
505
- //#region src/generators/v2/typeGenerator.d.ts
506
- declare const typeGenerator$1: _kubb_core0.ReactGeneratorV2<PluginTs>;
6
+ declare const typeGenerator: _kubb_core0.ReactGeneratorV2<PluginTs>;
507
7
  //#endregion
508
- export { typeGenerator, typeGenerator$1 as typeGeneratorV2 };
8
+ export { typeGenerator };
509
9
  //# sourceMappingURL=generators.d.ts.map
@@ -1,2 +1,2 @@
1
- import { a as typeGenerator, r as typeGenerator$1 } from "./plugin-D60XNJSD.js";
2
- export { typeGenerator, typeGenerator$1 as typeGeneratorV2 };
1
+ import { t as typeGenerator } from "./generators-CLuCmfUz.js";
2
+ export { typeGenerator };