@kubb/plugin-faker 4.1.4 → 4.2.1
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/{components-CD3T0xBr.cjs → components-D2QMTfoh.cjs} +2 -3
- package/dist/components-D2QMTfoh.cjs.map +1 -0
- package/dist/{components-CcZ6wgHo.js → components-DifNFxNO.js} +3 -4
- package/dist/components-DifNFxNO.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{fakerGenerator-CUjWtMAx.js → fakerGenerator-B99X1p4-.js} +10 -6
- package/dist/fakerGenerator-B99X1p4-.js.map +1 -0
- package/dist/{fakerGenerator-CgqkxhR7.cjs → fakerGenerator-CkkZzBD8.cjs} +9 -4
- package/dist/fakerGenerator-CkkZzBD8.cjs.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/{types-DsDfBfOk.d.ts → types-CE8sVPcD.d.ts} +78 -122
- package/dist/{types-B1Xb1ZXg.d.cts → types-DNb0qEes.d.cts} +78 -122
- package/package.json +8 -8
- package/src/generators/fakerGenerator.tsx +9 -7
- package/src/plugin.ts +6 -10
- package/dist/components-CD3T0xBr.cjs.map +0 -1
- package/dist/components-CcZ6wgHo.js.map +0 -1
- package/dist/fakerGenerator-CUjWtMAx.js.map +0 -1
- package/dist/fakerGenerator-CgqkxhR7.cjs.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
2
|
+
import { FileManager } from "@kubb/fabric-core";
|
|
2
3
|
import * as OasTypes from "oas/types";
|
|
3
4
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
4
5
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -11,17 +12,17 @@ import BaseOas from "oas";
|
|
|
11
12
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
12
13
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
13
14
|
*/
|
|
14
|
-
declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
15
|
+
declare abstract class BaseGenerator<TOptions$1 = unknown, TContext = unknown> {
|
|
15
16
|
#private;
|
|
16
|
-
constructor(options?: TOptions, context?: TContext);
|
|
17
|
-
get options(): TOptions;
|
|
17
|
+
constructor(options?: TOptions$1, context?: TContext);
|
|
18
|
+
get options(): TOptions$1;
|
|
18
19
|
get context(): TContext;
|
|
19
|
-
set options(options: TOptions);
|
|
20
|
+
set options(options: TOptions$1);
|
|
20
21
|
abstract build(...params: unknown[]): unknown;
|
|
21
22
|
}
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region ../core/src/fs/types.d.ts
|
|
24
|
-
type BasePath<T extends string = string> = `${T}/`;
|
|
25
|
+
type BasePath<T$1 extends string = string> = `${T$1}/`;
|
|
25
26
|
type Import = {
|
|
26
27
|
/**
|
|
27
28
|
* Import name to be used
|
|
@@ -95,7 +96,7 @@ type BaseName = `${string}.${string}`;
|
|
|
95
96
|
* Path will be full qualified path to a specified file
|
|
96
97
|
*/
|
|
97
98
|
type Path = string;
|
|
98
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
99
|
+
type AdvancedPath<T$1 extends BaseName = BaseName> = `${BasePath}${T$1}`;
|
|
99
100
|
type OptionalPath = Path | undefined | null;
|
|
100
101
|
type File<TMeta extends object = object> = {
|
|
101
102
|
/**
|
|
@@ -184,9 +185,7 @@ type Logger = {
|
|
|
184
185
|
};
|
|
185
186
|
//#endregion
|
|
186
187
|
//#region ../core/src/utils/types.d.ts
|
|
187
|
-
type PossiblePromise<T> = Promise<T> | T;
|
|
188
|
-
type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
|
|
189
|
-
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
|
|
188
|
+
type PossiblePromise<T$1> = Promise<T$1> | T$1;
|
|
190
189
|
//#endregion
|
|
191
190
|
//#region ../core/src/types.d.ts
|
|
192
191
|
type InputPath = {
|
|
@@ -299,11 +298,11 @@ TName extends string = string,
|
|
|
299
298
|
/**
|
|
300
299
|
* Options of the plugin.
|
|
301
300
|
*/
|
|
302
|
-
TOptions extends object = object,
|
|
301
|
+
TOptions$1 extends object = object,
|
|
303
302
|
/**
|
|
304
303
|
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
305
304
|
*/
|
|
306
|
-
TResolvedOptions extends object = TOptions,
|
|
305
|
+
TResolvedOptions extends object = TOptions$1,
|
|
307
306
|
/**
|
|
308
307
|
* Context that you want to expose to other plugins.
|
|
309
308
|
*/
|
|
@@ -317,23 +316,23 @@ TResolvePathOptions extends object = object> = {
|
|
|
317
316
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
318
317
|
*/
|
|
319
318
|
key: PluginKey<TName | string>;
|
|
320
|
-
options: TOptions;
|
|
319
|
+
options: TOptions$1;
|
|
321
320
|
resolvedOptions: TResolvedOptions;
|
|
322
321
|
context: TContext;
|
|
323
322
|
resolvePathOptions: TResolvePathOptions;
|
|
324
323
|
};
|
|
325
324
|
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
326
|
-
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
325
|
+
type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
327
326
|
/**
|
|
328
327
|
* Unique name used for the plugin
|
|
329
328
|
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
330
329
|
* @example @kubb/typescript
|
|
331
330
|
*/
|
|
332
|
-
name: TOptions['name'];
|
|
331
|
+
name: TOptions$1['name'];
|
|
333
332
|
/**
|
|
334
333
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
335
334
|
*/
|
|
336
|
-
options: TOptions['resolvedOptions'];
|
|
335
|
+
options: TOptions$1['resolvedOptions'];
|
|
337
336
|
/**
|
|
338
337
|
* 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.
|
|
339
338
|
* Can be used to validate dependent plugins.
|
|
@@ -343,23 +342,23 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
343
342
|
* 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.
|
|
344
343
|
*/
|
|
345
344
|
post?: Array<string>;
|
|
346
|
-
} & (TOptions['context'] extends never ? {
|
|
345
|
+
} & (TOptions$1['context'] extends never ? {
|
|
347
346
|
context?: never;
|
|
348
347
|
} : {
|
|
349
|
-
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
348
|
+
context: (this: TOptions$1['name'] extends 'core' ? null : Omit<PluginContext<TOptions$1>, 'addFile'>) => TOptions$1['context'];
|
|
350
349
|
});
|
|
351
|
-
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
352
|
-
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
350
|
+
type UserPluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions$1> & PluginLifecycle<TOptions$1>;
|
|
351
|
+
type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
353
352
|
/**
|
|
354
353
|
* Unique name used for the plugin
|
|
355
354
|
* @example @kubb/typescript
|
|
356
355
|
*/
|
|
357
|
-
name: TOptions['name'];
|
|
356
|
+
name: TOptions$1['name'];
|
|
358
357
|
/**
|
|
359
358
|
* Internal key used when a developer uses more than one of the same plugin
|
|
360
359
|
* @private
|
|
361
360
|
*/
|
|
362
|
-
key: TOptions['key'];
|
|
361
|
+
key: TOptions$1['key'];
|
|
363
362
|
/**
|
|
364
363
|
* 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.
|
|
365
364
|
* Can be used to validate dependent plugins.
|
|
@@ -372,49 +371,49 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
372
371
|
/**
|
|
373
372
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
374
373
|
*/
|
|
375
|
-
options: TOptions['resolvedOptions'];
|
|
376
|
-
} & (TOptions['context'] extends never ? {
|
|
374
|
+
options: TOptions$1['resolvedOptions'];
|
|
375
|
+
} & (TOptions$1['context'] extends never ? {
|
|
377
376
|
context?: never;
|
|
378
377
|
} : {
|
|
379
|
-
context: TOptions['context'];
|
|
378
|
+
context: TOptions$1['context'];
|
|
380
379
|
});
|
|
381
|
-
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
382
|
-
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
380
|
+
type PluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions$1> & PluginLifecycle<TOptions$1>;
|
|
381
|
+
type PluginLifecycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
383
382
|
/**
|
|
384
383
|
* Start of the lifecycle of a plugin.
|
|
385
384
|
* @type hookParallel
|
|
386
385
|
*/
|
|
387
|
-
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
386
|
+
buildStart?: (this: PluginContext<TOptions$1>, Config: Config) => PossiblePromise<void>;
|
|
388
387
|
/**
|
|
389
388
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
390
389
|
* Options can als be included.
|
|
391
390
|
* @type hookFirst
|
|
392
391
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
393
392
|
*/
|
|
394
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
|
|
393
|
+
resolvePath?: (this: PluginContext<TOptions$1>, baseName: BaseName, mode?: Mode, options?: TOptions$1['resolvePathOptions']) => OptionalPath;
|
|
395
394
|
/**
|
|
396
395
|
* Resolve to a name based on a string.
|
|
397
396
|
* Useful when converting to PascalCase or camelCase.
|
|
398
397
|
* @type hookFirst
|
|
399
398
|
* @example ('pet') => 'Pet'
|
|
400
399
|
*/
|
|
401
|
-
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
400
|
+
resolveName?: (this: PluginContext<TOptions$1>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
402
401
|
/**
|
|
403
402
|
* End of the plugin lifecycle.
|
|
404
403
|
* @type hookParallel
|
|
405
404
|
*/
|
|
406
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
405
|
+
buildEnd?: (this: PluginContext<TOptions$1>) => PossiblePromise<void>;
|
|
407
406
|
};
|
|
408
407
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
409
|
-
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
410
|
-
type ResolvePathParams<TOptions = object> = {
|
|
408
|
+
type PluginParameter<H$1 extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H$1]>;
|
|
409
|
+
type ResolvePathParams<TOptions$1 = object> = {
|
|
411
410
|
pluginKey?: Plugin['key'];
|
|
412
411
|
baseName: BaseName;
|
|
413
412
|
mode?: Mode;
|
|
414
413
|
/**
|
|
415
414
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
416
415
|
*/
|
|
417
|
-
options?: TOptions;
|
|
416
|
+
options?: TOptions$1;
|
|
418
417
|
};
|
|
419
418
|
type ResolveNameParams = {
|
|
420
419
|
name: string;
|
|
@@ -427,12 +426,15 @@ type ResolveNameParams = {
|
|
|
427
426
|
*/
|
|
428
427
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
429
428
|
};
|
|
430
|
-
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
429
|
+
type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
431
430
|
config: Config;
|
|
431
|
+
/**
|
|
432
|
+
* @deprecated
|
|
433
|
+
*/
|
|
432
434
|
fileManager: FileManager;
|
|
433
435
|
pluginManager: PluginManager;
|
|
434
436
|
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
435
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
|
|
437
|
+
resolvePath: (params: ResolvePathParams<TOptions$1['resolvePathOptions']>) => OptionalPath;
|
|
436
438
|
resolveName: (params: ResolveNameParams) => string;
|
|
437
439
|
logger: Logger;
|
|
438
440
|
/**
|
|
@@ -442,12 +444,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
442
444
|
/**
|
|
443
445
|
* Current plugin
|
|
444
446
|
*/
|
|
445
|
-
plugin: Plugin<TOptions>;
|
|
447
|
+
plugin: Plugin<TOptions$1>;
|
|
446
448
|
};
|
|
447
449
|
/**
|
|
448
450
|
* Specify the export location for the files and define the behavior of the output
|
|
449
451
|
*/
|
|
450
|
-
type Output<TOptions> = {
|
|
452
|
+
type Output<TOptions$1> = {
|
|
451
453
|
/**
|
|
452
454
|
* Path to the output folder or file that will contain the generated code
|
|
453
455
|
*/
|
|
@@ -460,11 +462,11 @@ type Output<TOptions> = {
|
|
|
460
462
|
/**
|
|
461
463
|
* Add a banner text in the beginning of every file
|
|
462
464
|
*/
|
|
463
|
-
banner?: string | ((options: TOptions) => string);
|
|
465
|
+
banner?: string | ((options: TOptions$1) => string);
|
|
464
466
|
/**
|
|
465
467
|
* Add a footer text in the beginning of every file
|
|
466
468
|
*/
|
|
467
|
-
footer?: string | ((options: TOptions) => string);
|
|
469
|
+
footer?: string | ((options: TOptions$1) => string);
|
|
468
470
|
};
|
|
469
471
|
type GroupContext = {
|
|
470
472
|
group: string;
|
|
@@ -480,73 +482,19 @@ type Group = {
|
|
|
480
482
|
name?: (context: GroupContext) => string;
|
|
481
483
|
};
|
|
482
484
|
//#endregion
|
|
483
|
-
//#region ../core/src/FileManager.d.ts
|
|
484
|
-
type FileMetaBase = {
|
|
485
|
-
pluginKey?: Plugin['key'];
|
|
486
|
-
};
|
|
487
|
-
type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
488
|
-
type AddIndexesProps = {
|
|
489
|
-
type: BarrelType | false | undefined;
|
|
490
|
-
/**
|
|
491
|
-
* Root based on root and output.path specified in the config
|
|
492
|
-
*/
|
|
493
|
-
root: string;
|
|
494
|
-
/**
|
|
495
|
-
* Output for plugin
|
|
496
|
-
*/
|
|
497
|
-
output: {
|
|
498
|
-
path: string;
|
|
499
|
-
};
|
|
500
|
-
group?: {
|
|
501
|
-
output: string;
|
|
502
|
-
exportAs: string;
|
|
503
|
-
};
|
|
504
|
-
logger?: Logger;
|
|
505
|
-
meta?: FileMetaBase;
|
|
506
|
-
};
|
|
507
|
-
type WriteFilesProps = {
|
|
508
|
-
root: Config['root'];
|
|
509
|
-
extension?: Record<Extname, Extname | ''>;
|
|
510
|
-
logger?: Logger;
|
|
511
|
-
dryRun?: boolean;
|
|
512
|
-
};
|
|
513
|
-
declare class FileManager {
|
|
514
|
-
#private;
|
|
515
|
-
constructor();
|
|
516
|
-
add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
|
|
517
|
-
getByPath(path: Path): Promise<ResolvedFile | null>;
|
|
518
|
-
deleteByPath(path: Path): Promise<void>;
|
|
519
|
-
clear(): Promise<void>;
|
|
520
|
-
getFiles(): Promise<Array<ResolvedFile>>;
|
|
521
|
-
processFiles({
|
|
522
|
-
dryRun,
|
|
523
|
-
root,
|
|
524
|
-
extension,
|
|
525
|
-
logger
|
|
526
|
-
}: WriteFilesProps): Promise<Array<ResolvedFile>>;
|
|
527
|
-
getBarrelFiles({
|
|
528
|
-
type,
|
|
529
|
-
meta,
|
|
530
|
-
root,
|
|
531
|
-
output,
|
|
532
|
-
logger
|
|
533
|
-
}: AddIndexesProps): Promise<File[]>;
|
|
534
|
-
static getMode(path: string | undefined | null): Mode;
|
|
535
|
-
}
|
|
536
|
-
//#endregion
|
|
537
485
|
//#region ../core/src/PluginManager.d.ts
|
|
538
486
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
539
487
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
540
|
-
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
488
|
+
type Executer<H$1 extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
541
489
|
message: string;
|
|
542
490
|
strategy: Strategy;
|
|
543
|
-
hookName: H;
|
|
491
|
+
hookName: H$1;
|
|
544
492
|
plugin: Plugin;
|
|
545
493
|
parameters?: unknown[] | undefined;
|
|
546
494
|
output?: unknown;
|
|
547
495
|
};
|
|
548
|
-
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
549
|
-
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
496
|
+
type ParseResult<H$1 extends PluginLifecycleHooks> = RequiredPluginLifecycle[H$1];
|
|
497
|
+
type SafeParseResult<H$1 extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H$1>>> = {
|
|
550
498
|
result: Result;
|
|
551
499
|
plugin: Plugin;
|
|
552
500
|
};
|
|
@@ -562,16 +510,19 @@ type Events = {
|
|
|
562
510
|
executed: [executer: Executer];
|
|
563
511
|
error: [error: Error];
|
|
564
512
|
};
|
|
565
|
-
type GetFileProps<TOptions = object> = {
|
|
513
|
+
type GetFileProps<TOptions$1 = object> = {
|
|
566
514
|
name: string;
|
|
567
515
|
mode?: Mode;
|
|
568
516
|
extname: Extname;
|
|
569
517
|
pluginKey: Plugin['key'];
|
|
570
|
-
options?: TOptions;
|
|
518
|
+
options?: TOptions$1;
|
|
571
519
|
};
|
|
572
520
|
declare class PluginManager {
|
|
573
521
|
#private;
|
|
574
522
|
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
523
|
+
/**
|
|
524
|
+
* @deprecated do not use from pluginManager
|
|
525
|
+
*/
|
|
575
526
|
readonly fileManager: FileManager;
|
|
576
527
|
readonly events: EventEmitter<Events>;
|
|
577
528
|
readonly config: Config;
|
|
@@ -680,6 +631,11 @@ declare class PluginManager {
|
|
|
680
631
|
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
681
632
|
}
|
|
682
633
|
//#endregion
|
|
634
|
+
//#region ../core/src/FileManager.d.ts
|
|
635
|
+
type FileMetaBase = {
|
|
636
|
+
pluginKey?: Plugin['key'];
|
|
637
|
+
};
|
|
638
|
+
//#endregion
|
|
683
639
|
//#region ../oas/src/types.d.ts
|
|
684
640
|
type contentType = 'application/json' | (string & {});
|
|
685
641
|
type SchemaObject$1 = OasTypes.SchemaObject & {
|
|
@@ -1008,12 +964,12 @@ type ByContentType = {
|
|
|
1008
964
|
};
|
|
1009
965
|
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
1010
966
|
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
1011
|
-
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
1012
|
-
options: Partial<TOptions>;
|
|
967
|
+
type Override<TOptions$1> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
968
|
+
options: Partial<TOptions$1>;
|
|
1013
969
|
};
|
|
1014
970
|
//#endregion
|
|
1015
971
|
//#region ../plugin-oas/src/SchemaGenerator.d.ts
|
|
1016
|
-
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
972
|
+
type Context$1<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
|
|
1017
973
|
oas: Oas;
|
|
1018
974
|
pluginManager: PluginManager;
|
|
1019
975
|
/**
|
|
@@ -1022,7 +978,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
1022
978
|
plugin: Plugin<TPluginOptions>;
|
|
1023
979
|
mode: Mode;
|
|
1024
980
|
include?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
1025
|
-
override: Array<Override<TOptions>> | undefined;
|
|
981
|
+
override: Array<Override<TOptions$1>> | undefined;
|
|
1026
982
|
contentType?: contentType;
|
|
1027
983
|
output?: string;
|
|
1028
984
|
};
|
|
@@ -1053,7 +1009,7 @@ type SchemaProps$1 = {
|
|
|
1053
1009
|
name?: string;
|
|
1054
1010
|
parentName?: string;
|
|
1055
1011
|
};
|
|
1056
|
-
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
|
|
1012
|
+
declare class SchemaGenerator<TOptions$1 extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions$1, Context$1<TOptions$1, TPluginOptions>> {
|
|
1057
1013
|
#private;
|
|
1058
1014
|
refs: Refs;
|
|
1059
1015
|
/**
|
|
@@ -1072,39 +1028,39 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
|
|
|
1072
1028
|
}
|
|
1073
1029
|
//#endregion
|
|
1074
1030
|
//#region ../plugin-oas/src/generator.d.ts
|
|
1075
|
-
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
1076
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
1077
|
-
options: TOptions['resolvedOptions'];
|
|
1031
|
+
type OperationsProps<TOptions$1 extends PluginFactoryOptions> = {
|
|
1032
|
+
instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
|
|
1033
|
+
options: TOptions$1['resolvedOptions'];
|
|
1078
1034
|
operations: Array<Operation$1>;
|
|
1079
1035
|
};
|
|
1080
|
-
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
1081
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
1082
|
-
options: TOptions['resolvedOptions'];
|
|
1036
|
+
type OperationProps<TOptions$1 extends PluginFactoryOptions> = {
|
|
1037
|
+
instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
|
|
1038
|
+
options: TOptions$1['resolvedOptions'];
|
|
1083
1039
|
operation: Operation$1;
|
|
1084
1040
|
};
|
|
1085
|
-
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
1086
|
-
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
1087
|
-
options: TOptions['resolvedOptions'];
|
|
1041
|
+
type SchemaProps<TOptions$1 extends PluginFactoryOptions> = {
|
|
1042
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions$1>, 'build'>;
|
|
1043
|
+
options: TOptions$1['resolvedOptions'];
|
|
1088
1044
|
schema: {
|
|
1089
1045
|
name: string;
|
|
1090
1046
|
tree: Array<Schema>;
|
|
1091
1047
|
value: SchemaObject$1;
|
|
1092
1048
|
};
|
|
1093
1049
|
};
|
|
1094
|
-
type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
1050
|
+
type GeneratorOptions<TOptions$1 extends PluginFactoryOptions> = {
|
|
1095
1051
|
name: string;
|
|
1096
|
-
operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<File[]>;
|
|
1097
|
-
operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<File[]>;
|
|
1098
|
-
schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<File[]>;
|
|
1052
|
+
operations?: (this: GeneratorOptions<TOptions$1>, props: OperationsProps<TOptions$1>) => Promise<File[]>;
|
|
1053
|
+
operation?: (this: GeneratorOptions<TOptions$1>, props: OperationProps<TOptions$1>) => Promise<File[]>;
|
|
1054
|
+
schema?: (this: GeneratorOptions<TOptions$1>, props: SchemaProps<TOptions$1>) => Promise<File[]>;
|
|
1099
1055
|
};
|
|
1100
|
-
type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
|
|
1056
|
+
type Generator<TOptions$1 extends PluginFactoryOptions> = GeneratorOptions<TOptions$1>;
|
|
1101
1057
|
//#endregion
|
|
1102
1058
|
//#region ../plugin-oas/src/OperationGenerator.d.ts
|
|
1103
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
1059
|
+
type Context<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
|
|
1104
1060
|
oas: Oas;
|
|
1105
1061
|
exclude: Array<Exclude$1> | undefined;
|
|
1106
1062
|
include: Array<Include> | undefined;
|
|
1107
|
-
override: Array<Override<TOptions>> | undefined;
|
|
1063
|
+
override: Array<Override<TOptions$1>> | undefined;
|
|
1108
1064
|
contentType: contentType | undefined;
|
|
1109
1065
|
pluginManager: PluginManager;
|
|
1110
1066
|
/**
|
|
@@ -1231,5 +1187,5 @@ type ResolvedOptions = {
|
|
|
1231
1187
|
};
|
|
1232
1188
|
type PluginFaker = PluginFactoryOptions<'plugin-faker', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1233
1189
|
//#endregion
|
|
1234
|
-
export {
|
|
1235
|
-
//# sourceMappingURL=types-
|
|
1190
|
+
export { UserPluginWithLifeCycle as a, Schema as i, PluginFaker as n, Generator as r, Options$1 as t };
|
|
1191
|
+
//# sourceMappingURL=types-DNb0qEes.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-faker",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Faker.js data generator plugin for Kubb, creating realistic mock data from OpenAPI specifications for development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
"!/**/__tests__/**"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@kubb/core": "4.1
|
|
65
|
-
"@kubb/oas": "4.1
|
|
66
|
-
"@kubb/plugin-oas": "4.1
|
|
67
|
-
"@kubb/plugin-ts": "4.1
|
|
68
|
-
"@kubb/react": "4.1
|
|
64
|
+
"@kubb/core": "4.2.1",
|
|
65
|
+
"@kubb/oas": "4.2.1",
|
|
66
|
+
"@kubb/plugin-oas": "4.2.1",
|
|
67
|
+
"@kubb/plugin-ts": "4.2.1",
|
|
68
|
+
"@kubb/react": "4.2.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"tsdown": "^0.
|
|
71
|
+
"tsdown": "^0.15.9",
|
|
72
72
|
"typescript": "^5.9.3",
|
|
73
|
-
"@kubb/plugin-oas": "4.1
|
|
73
|
+
"@kubb/plugin-oas": "4.2.1"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@kubb/react": "^4.0.0"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { useMode, usePlugin, usePluginManager } from '@kubb/core/hooks'
|
|
1
2
|
import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
2
3
|
import { Oas } from '@kubb/plugin-oas/components'
|
|
3
4
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
4
5
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
|
-
import { File
|
|
7
|
+
import { File } from '@kubb/react'
|
|
7
8
|
import { Faker } from '../components'
|
|
8
9
|
import type { PluginFaker } from '../types'
|
|
9
10
|
|
|
@@ -12,7 +13,10 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
12
13
|
Operation({ operation, options }) {
|
|
13
14
|
const { dateParser, regexGenerator, seed, mapper } = options
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const plugin = usePlugin<PluginFaker>()
|
|
17
|
+
const mode = useMode()
|
|
18
|
+
const pluginManager = usePluginManager()
|
|
19
|
+
|
|
16
20
|
const oas = useOas()
|
|
17
21
|
const { getSchemas, getFile, getGroup } = useOperationManager()
|
|
18
22
|
const schemaManager = useSchemaManager()
|
|
@@ -96,11 +100,9 @@ export const fakerGenerator = createReactGenerator<PluginFaker>({
|
|
|
96
100
|
|
|
97
101
|
const { getName, getFile, getImports } = useSchemaManager()
|
|
98
102
|
const {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
} = useApp<PluginFaker>()
|
|
103
|
+
options: { output },
|
|
104
|
+
} = usePlugin<PluginFaker>()
|
|
105
|
+
const pluginManager = usePluginManager()
|
|
104
106
|
const oas = useOas()
|
|
105
107
|
const imports = getImports(schema.tree)
|
|
106
108
|
|
package/src/plugin.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
2
|
+
import { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'
|
|
4
3
|
import { camelCase } from '@kubb/core/transformers'
|
|
5
|
-
import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
6
|
-
|
|
7
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
|
-
|
|
9
|
-
import type { Plugin } from '@kubb/core'
|
|
10
4
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
5
|
+
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
11
7
|
import { fakerGenerator } from './generators/fakerGenerator.tsx'
|
|
12
8
|
import type { PluginFaker } from './types.ts'
|
|
13
9
|
|
|
@@ -50,7 +46,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
|
|
|
50
46
|
pre: [pluginOasName, pluginTsName],
|
|
51
47
|
resolvePath(baseName, pathMode, options) {
|
|
52
48
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
53
|
-
const mode = pathMode ??
|
|
49
|
+
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
54
50
|
|
|
55
51
|
if (mode === 'single') {
|
|
56
52
|
/**
|
|
@@ -99,7 +95,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
|
|
|
99
95
|
|
|
100
96
|
const oas = await swaggerPlugin.context.getOas()
|
|
101
97
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
102
|
-
const mode =
|
|
98
|
+
const mode = getMode(path.resolve(root, output.path))
|
|
103
99
|
|
|
104
100
|
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
105
101
|
oas,
|
|
@@ -129,7 +125,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
|
|
|
129
125
|
const operationFiles = await operationGenerator.build(...generators)
|
|
130
126
|
await this.addFile(...operationFiles)
|
|
131
127
|
|
|
132
|
-
const barrelFiles = await this.fileManager.
|
|
128
|
+
const barrelFiles = await getBarrelFiles(this.fileManager.files, {
|
|
133
129
|
type: output.barrelType ?? 'named',
|
|
134
130
|
root,
|
|
135
131
|
output,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-CD3T0xBr.cjs","names":["transformers","schemaKeywords","name","SchemaGenerator","value","options","parserFaker.joinItems","parserFaker.parse","FunctionParams","File","Function","transformers"],"sources":["../src/parser.ts","../src/components/Faker.tsx"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport type { Schema, SchemaKeywordBase, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'\nimport { isKeyword, SchemaGenerator, type SchemaTree, schemaKeywords } from '@kubb/plugin-oas'\nimport type { Options } from './types.ts'\n\nconst fakerKeywordMapper = {\n any: () => 'undefined',\n unknown: () => 'undefined',\n void: () => 'undefined',\n number: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.float({ min: ${min}, max: ${max} })`\n }\n\n if (max !== undefined) {\n return `faker.number.float({ max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.float({ min: ${min} })`\n }\n\n return 'faker.number.float()'\n },\n integer: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.number.int({ min: ${min}, max: ${max} })`\n }\n\n if (max !== undefined) {\n return `faker.number.int({ max: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.number.int({ min: ${min} })`\n }\n\n return 'faker.number.int()'\n },\n string: (min?: number, max?: number) => {\n if (max !== undefined && min !== undefined) {\n return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`\n }\n\n if (max !== undefined) {\n return `faker.string.alpha({ length: ${max} })`\n }\n\n if (min !== undefined) {\n return `faker.string.alpha({ length: ${min} })`\n }\n\n return 'faker.string.alpha()'\n },\n boolean: () => 'faker.datatype.boolean()',\n undefined: () => 'undefined',\n null: () => 'null',\n array: (items: string[] = [], min?: number, max?: number) => {\n if (items.length > 1) {\n return `faker.helpers.arrayElements([${items.join(', ')}])`\n }\n const item = items.at(0)\n\n if (min !== undefined && max !== undefined) {\n return `faker.helpers.multiple(() => (${item}), { count: { min: ${min}, max: ${max} }})`\n }\n if (min !== undefined) {\n return `faker.helpers.multiple(() => (${item}), { count: ${min} })`\n }\n if (max !== undefined) {\n return `faker.helpers.multiple(() => (${item}), { count: { min: 0, max: ${max} }})`\n }\n\n return `faker.helpers.multiple(() => (${item}))`\n },\n tuple: (items: string[] = []) => `[${items.join(', ')}]`,\n enum: (items: Array<string | number | boolean | undefined> = [], type = 'any') => `faker.helpers.arrayElement<${type}>([${items.join(', ')}])`,\n union: (items: string[] = []) => `faker.helpers.arrayElement<any>([${items.join(', ')}])`,\n /**\n * ISO 8601\n */\n datetime: () => 'faker.date.anytime().toISOString()',\n /**\n * Type `'date'` Date\n * Type `'string'` ISO date format (YYYY-MM-DD)\n * @default ISO date format (YYYY-MM-DD)\n */\n date: (type: 'date' | 'string' = 'string', parser: Options['dateParser'] = 'faker') => {\n if (type === 'string') {\n if (parser !== 'faker') {\n return `${parser}(faker.date.anytime()).format(\"YYYY-MM-DD\")`\n }\n return 'faker.date.anytime().toISOString().substring(0, 10)'\n }\n\n if (parser !== 'faker') {\n throw new Error(`type '${type}' and parser '${parser}' can not work together`)\n }\n\n return 'faker.date.anytime()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])\n * @default ISO time format (HH:mm:ss[.SSSSSS])\n */\n time: (type: 'date' | 'string' = 'string', parser: Options['dateParser'] = 'faker') => {\n if (type === 'string') {\n if (parser !== 'faker') {\n return `${parser}(faker.date.anytime()).format(\"HH:mm:ss\")`\n }\n return 'faker.date.anytime().toISOString().substring(11, 19)'\n }\n\n if (parser !== 'faker') {\n throw new Error(`type '${type}' and parser '${parser}' can not work together`)\n }\n\n return 'faker.date.anytime()'\n },\n uuid: () => 'faker.string.uuid()',\n url: () => 'faker.internet.url()',\n and: (items: string[] = []) => `Object.assign({}, ${items.join(', ')})`,\n object: () => 'object',\n ref: () => 'ref',\n matches: (value = '', regexGenerator: 'faker' | 'randexp' = 'faker') => {\n if (regexGenerator === 'randexp') {\n return `${transformers.toRegExpString(value, 'RandExp')}.gen()`\n }\n return `faker.helpers.fromRegExp(\"${value}\")`\n },\n email: () => 'faker.internet.email()',\n firstName: () => 'faker.person.firstName()',\n lastName: () => 'faker.person.lastName()',\n password: () => 'faker.internet.password()',\n phone: () => 'faker.phone.number()',\n blob: () => 'faker.image.url() as unknown as Blob',\n default: undefined,\n describe: undefined,\n const: (value?: string | number) => (value as string) ?? '',\n max: undefined,\n min: undefined,\n nullable: undefined,\n nullish: undefined,\n optional: undefined,\n readOnly: undefined,\n writeOnly: undefined,\n deprecated: undefined,\n example: undefined,\n schema: undefined,\n catchall: undefined,\n name: undefined,\n interface: undefined,\n} satisfies SchemaMapper<string | null | undefined>\n\n/**\n * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n */\n\nfunction schemaKeywordSorter(_a: Schema, b: Schema) {\n if (b.keyword === 'null') {\n return -1\n }\n\n return 0\n}\n\nexport function joinItems(items: string[]): string {\n switch (items.length) {\n case 0:\n return 'undefined'\n case 1:\n return items[0]!\n default:\n return fakerKeywordMapper.union(items)\n }\n}\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n\n seed?: number | number[]\n regexGenerator?: 'faker' | 'randexp'\n canOverride?: boolean\n dateParser?: Options['dateParser']\n mapper?: Record<string, string>\n}\n\nexport function parse({ current, parent, name, siblings }: SchemaTree, options: ParserOptions): string | null | undefined {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n if (Array.isArray(current.args) && !current.args.length) {\n return ''\n }\n\n return fakerKeywordMapper.union(\n current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n return fakerKeywordMapper.and(\n current.args.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return fakerKeywordMapper.array(\n current.args.items\n .map((schema) =>\n parse(\n { parent: current, current: schema, siblings },\n {\n ...options,\n typeName: `NonNullable<${options.typeName}>[number]`,\n canOverride: false,\n },\n ),\n )\n .filter(Boolean),\n current.args.min,\n current.args.max,\n )\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n const isParentTuple = parent ? isKeyword(parent, schemaKeywords.tuple) : false\n\n if (isParentTuple) {\n return fakerKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'number') {\n return schema.value\n }\n\n if (schema.format === 'boolean') {\n return schema.value\n }\n return transformers.stringify(schema.value)\n }),\n )\n }\n\n return fakerKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'number') {\n return schema.value\n }\n if (schema.format === 'boolean') {\n return schema.value\n }\n return transformers.stringify(schema.value)\n }),\n // TODO replace this with getEnumNameFromSchema\n name ? options.typeName : undefined,\n )\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n if (!current.args?.name) {\n throw new Error(`Name not defined for keyword ${current.keyword}`)\n }\n\n if (options.canOverride) {\n return `${current.args.name}(data)`\n }\n\n return `${current.args.name}()`\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const argsObject = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n .map(([name, schemas]) => {\n const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']\n const mappedName = nameSchema?.args || name\n\n // custom mapper(pluginOptions)\n if (options.mapper?.[mappedName]) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${joinItems(\n schemas\n .sort(schemaKeywordSorter)\n .map((schema) =>\n parse(\n { name, parent: current, current: schema, siblings: schemas },\n {\n ...options,\n typeName: `NonNullable<${options.typeName}>[${JSON.stringify(name)}]`,\n canOverride: false,\n },\n ),\n )\n .filter(Boolean),\n )}`\n })\n .join(',')\n\n return `{${argsObject}}`\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n if (Array.isArray(current.args.items)) {\n return fakerKeywordMapper.tuple(\n current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, { ...options, canOverride: false })).filter(Boolean),\n )\n }\n\n return parse({ parent: current, current: current.args.items, siblings }, { ...options, canOverride: false })\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n if (current.args.format === 'number' && current.args.name !== undefined) {\n return fakerKeywordMapper.const(current.args.name?.toString())\n }\n return fakerKeywordMapper.const(transformers.stringify(current.args.value))\n }\n\n if (isKeyword(current, schemaKeywords.matches) && current.args) {\n return fakerKeywordMapper.matches(current.args, options.regexGenerator)\n }\n\n if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) {\n return value() || ''\n }\n\n if (isKeyword(current, schemaKeywords.string)) {\n if (siblings) {\n const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min)\n const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max)\n\n return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.string()\n }\n\n if (isKeyword(current, schemaKeywords.number)) {\n if (siblings) {\n const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min)\n const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max)\n\n return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.number()\n }\n\n if (isKeyword(current, schemaKeywords.integer)) {\n if (siblings) {\n const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min)\n const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max)\n\n return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.integer()\n }\n\n if (isKeyword(current, schemaKeywords.datetime)) {\n return fakerKeywordMapper.datetime()\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return fakerKeywordMapper.date(current.args.type, options.dateParser)\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return fakerKeywordMapper.time(current.args.type, options.dateParser)\n }\n\n if (current.keyword in fakerKeywordMapper && 'args' in current) {\n const value = fakerKeywordMapper[current.keyword as keyof typeof fakerKeywordMapper] as (typeof fakerKeywordMapper)['const']\n\n const options = JSON.stringify((current as SchemaKeywordBase<unknown>).args)\n\n return value(options)\n }\n\n if (current.keyword in fakerKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport transformers from '@kubb/core/transformers'\nimport type { Schema } from '@kubb/plugin-oas'\nimport * as parserFaker from '../parser.ts'\nimport type { PluginFaker } from '../types.ts'\n\ntype Props = {\n name: string\n typeName: string\n tree: Array<Schema>\n seed?: PluginFaker['options']['seed']\n description?: string\n regexGenerator?: PluginFaker['options']['regexGenerator']\n mapper?: PluginFaker['options']['mapper']\n dateParser?: PluginFaker['options']['dateParser']\n canOverride: boolean\n}\n\nexport function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props) {\n const fakerText = parserFaker.joinItems(\n tree\n .map((schema, _index, siblings) =>\n parserFaker.parse(\n { parent: undefined, current: schema, siblings },\n {\n name,\n typeName,\n seed,\n regexGenerator,\n mapper,\n canOverride,\n dateParser,\n },\n ),\n )\n .filter(Boolean),\n )\n\n const isArray = fakerText.startsWith('faker.helpers.arrayElements') || fakerText.startsWith('faker.helpers.multiple')\n const isObject = fakerText.startsWith('{')\n const isTuple = fakerText.startsWith('faker.helpers.arrayElement')\n\n const isSimpleString = name === 'string'\n const isSimpleInt = name === 'integer'\n const isSimpleFloat = name === 'float'\n\n let fakerTextWithOverride = fakerText\n\n if (canOverride && isObject) {\n fakerTextWithOverride = `{\n ...${fakerText},\n ...data || {}\n}`\n }\n\n if (canOverride && isTuple) {\n fakerTextWithOverride = `data || ${fakerText}`\n }\n\n if (canOverride && isArray) {\n fakerTextWithOverride = `[\n ...${fakerText},\n ...data || []\n ]`\n }\n\n if (canOverride && isSimpleString) {\n fakerTextWithOverride = 'data ?? faker.string.alpha()'\n }\n\n if (canOverride && isSimpleInt) {\n fakerTextWithOverride = 'data ?? faker.number.int()'\n }\n\n if (canOverride && isSimpleFloat) {\n fakerTextWithOverride = 'data ?? faker.number.float()'\n }\n\n let type = `Partial<${typeName}>`\n\n if (isArray) type = typeName\n else if (isSimpleString) type = name\n else if (isSimpleInt || isSimpleFloat) type = 'number'\n\n const params = FunctionParams.factory({\n data: {\n // making a partial out of an array does not make sense\n type,\n optional: true,\n },\n })\n\n let returnType = canOverride ? typeName : undefined\n\n if (isSimpleString || isSimpleInt || isSimpleFloat) returnType = type\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n export\n name={name}\n JSDoc={{ comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean) }}\n params={canOverride ? params.toConstructor() : undefined}\n returnType={returnType}\n >\n {seed ? `faker.seed(${JSON.stringify(seed)})` : undefined}\n <br />\n {`return ${fakerTextWithOverride}`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,qBAAqB;CACzB,WAAW;CACX,eAAe;CACf,YAAY;CACZ,SAAS,KAAc,QAAiB;AACtC,MAAI,QAAQ,UAAa,QAAQ,OAC/B,QAAO,6BAA6B,IAAI,SAAS,IAAI;AAGvD,MAAI,QAAQ,OACV,QAAO,6BAA6B,IAAI;AAG1C,MAAI,QAAQ,OACV,QAAO,6BAA6B,IAAI;AAG1C,SAAO;;CAET,UAAU,KAAc,QAAiB;AACvC,MAAI,QAAQ,UAAa,QAAQ,OAC/B,QAAO,2BAA2B,IAAI,SAAS,IAAI;AAGrD,MAAI,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