@kubb/plugin-ts 4.21.2 → 4.22.0

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.
@@ -1,4 +1,6 @@
1
- import { a as SchemaObject, i as Schema, n as PluginTs, o as __name } from "./types-Ct6STUWn.cjs";
1
+ import { n as PluginTs, r as __name } from "./types-DPguQrp_.cjs";
2
+ import { SchemaObject } from "@kubb/oas";
3
+ import { Schema } from "@kubb/plugin-oas";
2
4
  import { FabricReactNode } from "@kubb/react-fabric/types";
3
5
 
4
6
  //#region src/components/Type.d.ts
@@ -1,5 +1,7 @@
1
1
  import { t as __name } from "./chunk-eQyhnF5A.js";
2
- import { a as SchemaObject, i as Schema, n as PluginTs } from "./types-lrxr2PzI.js";
2
+ import { n as PluginTs } from "./types-C2WYWYjC.js";
3
+ import { Schema } from "@kubb/plugin-oas";
4
+ import { SchemaObject } from "@kubb/oas";
3
5
  import { FabricReactNode } from "@kubb/react-fabric/types";
4
6
 
5
7
  //#region src/components/Type.d.ts
@@ -1,5 +1,461 @@
1
- import { n as PluginTs, o as __name, r as ReactGenerator } from "./types-Ct6STUWn.cjs";
1
+ import { n as PluginTs, r as __name } from "./types-DPguQrp_.cjs";
2
+ import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
3
+ import { FabricReactNode } from "@kubb/react-fabric/types";
4
+ import { BaseGenerator, Config, FileMetaBase, Group, KubbEvents, Output, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from "@kubb/core";
5
+ import { AsyncEventEmitter } from "@kubb/core/utils";
6
+ import { KubbFile } from "@kubb/fabric-core/types";
7
+ import { Fabric } from "@kubb/react-fabric";
2
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
+ * `pluginKey` 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
+ pluginKey?: Plugin['key'];
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;
96
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
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
+ pluginManager: PluginManager;
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> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
119
+ #private;
120
+ getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
121
+ getSchemas(operation: Operation, {
122
+ resolveName
123
+ }?: {
124
+ resolveName?: (name: string) => string;
125
+ }): OperationSchemas;
126
+ getOperations(): Promise<Array<{
127
+ path: string;
128
+ method: HttpMethod;
129
+ operation: Operation;
130
+ }>>;
131
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
132
+ }
133
+ //#endregion
134
+ //#region ../plugin-oas/src/SchemaMapper.d.ts
135
+ type SchemaKeywordMapper = {
136
+ object: {
137
+ keyword: 'object';
138
+ args: {
139
+ properties: {
140
+ [x: string]: Schema[];
141
+ };
142
+ additionalProperties: Schema[];
143
+ patternProperties?: Record<string, Schema[]>;
144
+ strict?: boolean;
145
+ };
146
+ };
147
+ url: {
148
+ keyword: 'url';
149
+ };
150
+ readOnly: {
151
+ keyword: 'readOnly';
152
+ };
153
+ writeOnly: {
154
+ keyword: 'writeOnly';
155
+ };
156
+ uuid: {
157
+ keyword: 'uuid';
158
+ };
159
+ email: {
160
+ keyword: 'email';
161
+ };
162
+ firstName: {
163
+ keyword: 'firstName';
164
+ };
165
+ lastName: {
166
+ keyword: 'lastName';
167
+ };
168
+ phone: {
169
+ keyword: 'phone';
170
+ };
171
+ password: {
172
+ keyword: 'password';
173
+ };
174
+ date: {
175
+ keyword: 'date';
176
+ args: {
177
+ type?: 'date' | 'string';
178
+ };
179
+ };
180
+ time: {
181
+ keyword: 'time';
182
+ args: {
183
+ type?: 'date' | 'string';
184
+ };
185
+ };
186
+ datetime: {
187
+ keyword: 'datetime';
188
+ args: {
189
+ offset?: boolean;
190
+ local?: boolean;
191
+ };
192
+ };
193
+ tuple: {
194
+ keyword: 'tuple';
195
+ args: {
196
+ items: Schema[];
197
+ min?: number;
198
+ max?: number;
199
+ rest?: Schema;
200
+ };
201
+ };
202
+ array: {
203
+ keyword: 'array';
204
+ args: {
205
+ items: Schema[];
206
+ min?: number;
207
+ max?: number;
208
+ unique?: boolean;
209
+ };
210
+ };
211
+ enum: {
212
+ keyword: 'enum';
213
+ args: {
214
+ name: string;
215
+ typeName: string;
216
+ asConst: boolean;
217
+ items: Array<{
218
+ name: string | number;
219
+ format: 'string' | 'number' | 'boolean';
220
+ value?: string | number | boolean;
221
+ }>;
222
+ };
223
+ };
224
+ and: {
225
+ keyword: 'and';
226
+ args: Schema[];
227
+ };
228
+ const: {
229
+ keyword: 'const';
230
+ args: {
231
+ name: string | number;
232
+ format: 'string' | 'number' | 'boolean';
233
+ value?: string | number | boolean;
234
+ };
235
+ };
236
+ union: {
237
+ keyword: 'union';
238
+ args: Schema[];
239
+ };
240
+ ref: {
241
+ keyword: 'ref';
242
+ args: {
243
+ name: string;
244
+ $ref: string;
245
+ /**
246
+ * Full qualified path.
247
+ */
248
+ path: KubbFile.Path;
249
+ /**
250
+ * When true `File.Import` is used.
251
+ * When false a reference is used inside the current file.
252
+ */
253
+ isImportable: boolean;
254
+ };
255
+ };
256
+ matches: {
257
+ keyword: 'matches';
258
+ args?: string;
259
+ };
260
+ boolean: {
261
+ keyword: 'boolean';
262
+ };
263
+ default: {
264
+ keyword: 'default';
265
+ args: string | number | boolean;
266
+ };
267
+ string: {
268
+ keyword: 'string';
269
+ };
270
+ integer: {
271
+ keyword: 'integer';
272
+ };
273
+ number: {
274
+ keyword: 'number';
275
+ };
276
+ max: {
277
+ keyword: 'max';
278
+ args: number;
279
+ };
280
+ min: {
281
+ keyword: 'min';
282
+ args: number;
283
+ };
284
+ exclusiveMaximum: {
285
+ keyword: 'exclusiveMaximum';
286
+ args: number;
287
+ };
288
+ exclusiveMinimum: {
289
+ keyword: 'exclusiveMinimum';
290
+ args: number;
291
+ };
292
+ describe: {
293
+ keyword: 'describe';
294
+ args: string;
295
+ };
296
+ example: {
297
+ keyword: 'example';
298
+ args: string;
299
+ };
300
+ deprecated: {
301
+ keyword: 'deprecated';
302
+ };
303
+ optional: {
304
+ keyword: 'optional';
305
+ };
306
+ undefined: {
307
+ keyword: 'undefined';
308
+ };
309
+ nullish: {
310
+ keyword: 'nullish';
311
+ };
312
+ nullable: {
313
+ keyword: 'nullable';
314
+ };
315
+ null: {
316
+ keyword: 'null';
317
+ };
318
+ any: {
319
+ keyword: 'any';
320
+ };
321
+ unknown: {
322
+ keyword: 'unknown';
323
+ };
324
+ void: {
325
+ keyword: 'void';
326
+ };
327
+ blob: {
328
+ keyword: 'blob';
329
+ };
330
+ schema: {
331
+ keyword: 'schema';
332
+ args: {
333
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
334
+ format?: string;
335
+ };
336
+ };
337
+ name: {
338
+ keyword: 'name';
339
+ args: string;
340
+ };
341
+ catchall: {
342
+ keyword: 'catchall';
343
+ };
344
+ interface: {
345
+ keyword: 'interface';
346
+ };
347
+ };
348
+ type Schema = {
349
+ keyword: string;
350
+ } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
351
+ //#endregion
352
+ //#region ../plugin-oas/src/SchemaGenerator.d.ts
353
+ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
354
+ fabric: Fabric;
355
+ oas: Oas;
356
+ pluginManager: PluginManager;
357
+ events?: AsyncEventEmitter<KubbEvents>;
358
+ /**
359
+ * Current plugin
360
+ */
361
+ plugin: Plugin<TPluginOptions>;
362
+ mode: KubbFile.Mode;
363
+ include?: Array<'schemas' | 'responses' | 'requestBodies'>;
364
+ override: Array<Override<TOptions>> | undefined;
365
+ contentType?: contentType;
366
+ output?: string;
367
+ };
368
+ type SchemaGeneratorOptions = {
369
+ dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
370
+ unknownType: 'any' | 'unknown' | 'void';
371
+ emptySchemaType: 'any' | 'unknown' | 'void';
372
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
373
+ enumSuffix?: string;
374
+ /**
375
+ * @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
376
+ * When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
377
+ * @internal
378
+ */
379
+ usedEnumNames?: Record<string, number>;
380
+ mapper?: Record<string, string>;
381
+ typed?: boolean;
382
+ transformers: {
383
+ /**
384
+ * Customize the names based on the type that is provided by the plugin.
385
+ */
386
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
387
+ /**
388
+ * Receive schema and name(propertyName) and return FakerMeta array
389
+ * TODO TODO add docs
390
+ * @beta
391
+ */
392
+ schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
393
+ };
394
+ };
395
+ type SchemaProps$1 = {
396
+ schema: SchemaObject | null;
397
+ name: string | null;
398
+ parentName: string | null;
399
+ rootName?: string | null;
400
+ };
401
+ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
402
+ #private;
403
+ refs: Refs;
404
+ /**
405
+ * Creates a type node from a given schema.
406
+ * Delegates to getBaseTypeFromSchema internally and
407
+ * optionally adds a union with null.
408
+ */
409
+ parse(props: SchemaProps$1): Schema[];
410
+ static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
411
+ static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
412
+ static combineObjects(tree: Schema[] | undefined): Schema[];
413
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
414
+ }
415
+ //#endregion
416
+ //#region ../plugin-oas/src/generators/createGenerator.d.ts
417
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
418
+ name: string;
419
+ type: 'core';
420
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
421
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
422
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
423
+ };
424
+ //#endregion
425
+ //#region ../plugin-oas/src/generators/types.d.ts
426
+ type OperationsProps<TOptions extends PluginFactoryOptions> = {
427
+ config: Config;
428
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
429
+ plugin: Plugin<TOptions>;
430
+ operations: Array<Operation>;
431
+ };
432
+ type OperationProps<TOptions extends PluginFactoryOptions> = {
433
+ config: Config;
434
+ generator: Omit<OperationGenerator<TOptions>, 'build'>;
435
+ plugin: Plugin<TOptions>;
436
+ operation: Operation;
437
+ };
438
+ type SchemaProps<TOptions extends PluginFactoryOptions> = {
439
+ config: Config;
440
+ generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
441
+ plugin: Plugin<TOptions>;
442
+ schema: {
443
+ name: string;
444
+ tree: Array<Schema>;
445
+ value: SchemaObject;
446
+ };
447
+ };
448
+ type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
449
+ //#endregion
450
+ //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
451
+ type ReactGenerator<TOptions extends PluginFactoryOptions> = {
452
+ name: string;
453
+ type: 'react';
454
+ Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
455
+ Operation: (props: OperationProps<TOptions>) => FabricReactNode;
456
+ Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
457
+ };
458
+ //#endregion
3
459
  //#region src/generators/typeGenerator.d.ts
4
460
  declare const typeGenerator: ReactGenerator<PluginTs>;
5
461
  //#endregion