@kubb/plugin-ts 5.0.0-alpha.8 → 5.0.0-beta.3

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