@kubb/plugin-faker 4.10.0 → 4.11.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,304 +0,0 @@
1
- import transformers from "@kubb/core/transformers";
2
- import { SchemaGenerator, isKeyword, schemaKeywords } from "@kubb/plugin-oas";
3
- import { File, Function, FunctionParams } from "@kubb/react-fabric";
4
- import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
5
-
6
- //#region src/parser.ts
7
- const fakerKeywordMapper = {
8
- any: () => "undefined",
9
- unknown: () => "undefined",
10
- void: () => "undefined",
11
- number: (min, max) => {
12
- if (max !== void 0 && min !== void 0) return `faker.number.float({ min: ${min}, max: ${max} })`;
13
- if (max !== void 0) return `faker.number.float({ max: ${max} })`;
14
- if (min !== void 0) return `faker.number.float({ min: ${min} })`;
15
- return "faker.number.float()";
16
- },
17
- integer: (min, max) => {
18
- if (max !== void 0 && min !== void 0) return `faker.number.int({ min: ${min}, max: ${max} })`;
19
- if (max !== void 0) return `faker.number.int({ max: ${max} })`;
20
- if (min !== void 0) return `faker.number.int({ min: ${min} })`;
21
- return "faker.number.int()";
22
- },
23
- string: (min, max) => {
24
- if (max !== void 0 && min !== void 0) return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
25
- if (max !== void 0) return `faker.string.alpha({ length: ${max} })`;
26
- if (min !== void 0) return `faker.string.alpha({ length: ${min} })`;
27
- return "faker.string.alpha()";
28
- },
29
- boolean: () => "faker.datatype.boolean()",
30
- undefined: () => "undefined",
31
- null: () => "null",
32
- array: (items = [], min, max) => {
33
- if (items.length > 1) return `faker.helpers.arrayElements([${items.join(", ")}])`;
34
- const item = items.at(0);
35
- if (min !== void 0 && max !== void 0) return `faker.helpers.multiple(() => (${item}), { count: { min: ${min}, max: ${max} }})`;
36
- if (min !== void 0) return `faker.helpers.multiple(() => (${item}), { count: ${min} })`;
37
- if (max !== void 0) return `faker.helpers.multiple(() => (${item}), { count: { min: 0, max: ${max} }})`;
38
- return `faker.helpers.multiple(() => (${item}))`;
39
- },
40
- tuple: (items = []) => `[${items.join(", ")}]`,
41
- enum: (items = [], type = "any") => `faker.helpers.arrayElement<${type}>([${items.join(", ")}])`,
42
- union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
43
- datetime: () => "faker.date.anytime().toISOString()",
44
- date: (type = "string", parser = "faker") => {
45
- if (type === "string") {
46
- if (parser !== "faker") return `${parser}(faker.date.anytime()).format("YYYY-MM-DD")`;
47
- return "faker.date.anytime().toISOString().substring(0, 10)";
48
- }
49
- if (parser !== "faker") throw new Error(`type '${type}' and parser '${parser}' can not work together`);
50
- return "faker.date.anytime()";
51
- },
52
- time: (type = "string", parser = "faker") => {
53
- if (type === "string") {
54
- if (parser !== "faker") return `${parser}(faker.date.anytime()).format("HH:mm:ss")`;
55
- return "faker.date.anytime().toISOString().substring(11, 19)";
56
- }
57
- if (parser !== "faker") throw new Error(`type '${type}' and parser '${parser}' can not work together`);
58
- return "faker.date.anytime()";
59
- },
60
- uuid: () => "faker.string.uuid()",
61
- url: () => "faker.internet.url()",
62
- and: (items = []) => `Object.assign({}, ${items.join(", ")})`,
63
- object: () => "object",
64
- ref: () => "ref",
65
- matches: (value = "", regexGenerator = "faker") => {
66
- if (regexGenerator === "randexp") return `${transformers.toRegExpString(value, "RandExp")}.gen()`;
67
- return `faker.helpers.fromRegExp("${value}")`;
68
- },
69
- email: () => "faker.internet.email()",
70
- firstName: () => "faker.person.firstName()",
71
- lastName: () => "faker.person.lastName()",
72
- password: () => "faker.internet.password()",
73
- phone: () => "faker.phone.number()",
74
- blob: () => "faker.image.url() as unknown as Blob",
75
- default: void 0,
76
- describe: void 0,
77
- const: (value) => value ?? "",
78
- max: void 0,
79
- min: void 0,
80
- nullable: void 0,
81
- nullish: void 0,
82
- optional: void 0,
83
- readOnly: void 0,
84
- writeOnly: void 0,
85
- deprecated: void 0,
86
- example: void 0,
87
- schema: void 0,
88
- catchall: void 0,
89
- name: void 0,
90
- interface: void 0,
91
- exclusiveMaximum: void 0,
92
- exclusiveMinimum: void 0
93
- };
94
- /**
95
- * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
96
- */
97
- function schemaKeywordSorter(_a, b) {
98
- if (b.keyword === "null") return -1;
99
- return 0;
100
- }
101
- function joinItems(items) {
102
- switch (items.length) {
103
- case 0: return "undefined";
104
- case 1: return items[0];
105
- default: return fakerKeywordMapper.union(items);
106
- }
107
- }
108
- function parse({ schema, current, parent, name, siblings }, options) {
109
- const value = fakerKeywordMapper[current.keyword];
110
- if (!value) return;
111
- if (isKeyword(current, schemaKeywords.union)) {
112
- if (Array.isArray(current.args) && !current.args.length) return "";
113
- return fakerKeywordMapper.union(current.args.map((it) => parse({
114
- schema,
115
- parent: current,
116
- name,
117
- current: it,
118
- siblings
119
- }, {
120
- ...options,
121
- canOverride: false
122
- })).filter(Boolean));
123
- }
124
- if (isKeyword(current, schemaKeywords.and)) return fakerKeywordMapper.and(current.args.map((it) => parse({
125
- schema,
126
- parent: current,
127
- current: it,
128
- siblings
129
- }, {
130
- ...options,
131
- canOverride: false
132
- })).filter(Boolean));
133
- if (isKeyword(current, schemaKeywords.array)) return fakerKeywordMapper.array(current.args.items.map((it) => parse({
134
- schema,
135
- parent: current,
136
- current: it,
137
- siblings
138
- }, {
139
- ...options,
140
- typeName: `NonNullable<${options.typeName}>[number]`,
141
- canOverride: false
142
- })).filter(Boolean), current.args.min, current.args.max);
143
- if (isKeyword(current, schemaKeywords.enum)) {
144
- if (parent ? isKeyword(parent, schemaKeywords.tuple) : false) return fakerKeywordMapper.enum(current.args.items.map((schema$1) => {
145
- if (schema$1.format === "number") return schema$1.value;
146
- if (schema$1.format === "boolean") return schema$1.value;
147
- return transformers.stringify(schema$1.value);
148
- }));
149
- return fakerKeywordMapper.enum(current.args.items.map((schema$1) => {
150
- if (schema$1.format === "number") return schema$1.value;
151
- if (schema$1.format === "boolean") return schema$1.value;
152
- return transformers.stringify(schema$1.value);
153
- }), name ? options.typeName : void 0);
154
- }
155
- if (isKeyword(current, schemaKeywords.ref)) {
156
- if (!current.args?.name) throw new Error(`Name not defined for keyword ${current.keyword}`);
157
- if (options.canOverride) return `${current.args.name}(data)`;
158
- return `${current.args.name}()`;
159
- }
160
- if (isKeyword(current, schemaKeywords.object)) return `{${Object.entries(current.args?.properties || {}).filter((item) => {
161
- const schema$1 = item[1];
162
- return schema$1 && typeof schema$1.map === "function";
163
- }).map(([name$1, schemas]) => {
164
- const mappedName = schemas.find((schema$1) => schema$1.keyword === schemaKeywords.name)?.args || name$1;
165
- if (options.mapper?.[mappedName]) return `"${name$1}": ${options.mapper?.[mappedName]}`;
166
- return `"${name$1}": ${joinItems(schemas.sort(schemaKeywordSorter).map((it) => parse({
167
- schema,
168
- name: name$1,
169
- parent: current,
170
- current: it,
171
- siblings: schemas
172
- }, {
173
- ...options,
174
- typeName: `NonNullable<${options.typeName}>[${JSON.stringify(name$1)}]`,
175
- canOverride: false
176
- })).filter(Boolean))}`;
177
- }).join(",")}}`;
178
- if (isKeyword(current, schemaKeywords.tuple)) {
179
- if (Array.isArray(current.args.items)) return fakerKeywordMapper.tuple(current.args.items.map((it) => parse({
180
- schema,
181
- parent: current,
182
- current: it,
183
- siblings
184
- }, {
185
- ...options,
186
- canOverride: false
187
- })).filter(Boolean));
188
- return parse({
189
- schema,
190
- parent: current,
191
- current: current.args.items,
192
- siblings
193
- }, {
194
- ...options,
195
- canOverride: false
196
- });
197
- }
198
- if (isKeyword(current, schemaKeywords.const)) {
199
- if (current.args.format === "number" && current.args.name !== void 0) return fakerKeywordMapper.const(current.args.name?.toString());
200
- return fakerKeywordMapper.const(transformers.stringify(current.args.value));
201
- }
202
- if (isKeyword(current, schemaKeywords.matches) && current.args) return fakerKeywordMapper.matches(current.args, options.regexGenerator);
203
- if (isKeyword(current, schemaKeywords.null) || isKeyword(current, schemaKeywords.undefined) || isKeyword(current, schemaKeywords.any)) return value() || "";
204
- if (isKeyword(current, schemaKeywords.string)) {
205
- if (siblings) {
206
- const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min);
207
- const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max);
208
- return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
209
- }
210
- return fakerKeywordMapper.string();
211
- }
212
- if (isKeyword(current, schemaKeywords.number)) {
213
- if (siblings) {
214
- const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min);
215
- const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max);
216
- return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
217
- }
218
- return fakerKeywordMapper.number();
219
- }
220
- if (isKeyword(current, schemaKeywords.integer)) {
221
- if (siblings) {
222
- const minSchema = SchemaGenerator.find(siblings, schemaKeywords.min);
223
- const maxSchema = SchemaGenerator.find(siblings, schemaKeywords.max);
224
- return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
225
- }
226
- return fakerKeywordMapper.integer();
227
- }
228
- if (isKeyword(current, schemaKeywords.datetime)) return fakerKeywordMapper.datetime();
229
- if (isKeyword(current, schemaKeywords.date)) return fakerKeywordMapper.date(current.args.type, options.dateParser);
230
- if (isKeyword(current, schemaKeywords.time)) return fakerKeywordMapper.time(current.args.type, options.dateParser);
231
- if (current.keyword in fakerKeywordMapper && "args" in current) {
232
- const value$1 = fakerKeywordMapper[current.keyword];
233
- return value$1(JSON.stringify(current.args));
234
- }
235
- if (current.keyword in fakerKeywordMapper) return value();
236
- }
237
-
238
- //#endregion
239
- //#region src/components/Faker.tsx
240
- function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }) {
241
- const fakerText = joinItems(tree.map((schema, _index, siblings) => parse({
242
- name,
243
- schema,
244
- parent: void 0,
245
- current: schema,
246
- siblings
247
- }, {
248
- typeName,
249
- regexGenerator,
250
- mapper,
251
- canOverride,
252
- dateParser
253
- })).filter(Boolean));
254
- const isArray = fakerText.startsWith("faker.helpers.arrayElements") || fakerText.startsWith("faker.helpers.multiple");
255
- const isObject = fakerText.startsWith("{");
256
- const isTuple = fakerText.startsWith("faker.helpers.arrayElement");
257
- const isSimpleString = name === "string";
258
- const isSimpleInt = name === "integer";
259
- const isSimpleFloat = name === "float";
260
- let fakerTextWithOverride = fakerText;
261
- if (canOverride && isObject) fakerTextWithOverride = `{
262
- ...${fakerText},
263
- ...data || {}
264
- }`;
265
- if (canOverride && isTuple) fakerTextWithOverride = `data || ${fakerText}`;
266
- if (canOverride && isArray) fakerTextWithOverride = `[
267
- ...${fakerText},
268
- ...data || []
269
- ]`;
270
- if (canOverride && isSimpleString) fakerTextWithOverride = "data ?? faker.string.alpha()";
271
- if (canOverride && isSimpleInt) fakerTextWithOverride = "data ?? faker.number.int()";
272
- if (canOverride && isSimpleFloat) fakerTextWithOverride = "data ?? faker.number.float()";
273
- let type = `Partial<${typeName}>`;
274
- if (isArray) type = typeName;
275
- else if (isSimpleString) type = name;
276
- else if (isSimpleInt || isSimpleFloat) type = "number";
277
- const params = FunctionParams.factory({ data: {
278
- type,
279
- optional: true
280
- } });
281
- let returnType = canOverride ? typeName : void 0;
282
- if (isSimpleString || isSimpleInt || isSimpleFloat) returnType = type;
283
- return /* @__PURE__ */ jsx(File.Source, {
284
- name,
285
- isExportable: true,
286
- isIndexable: true,
287
- children: /* @__PURE__ */ jsxs(Function, {
288
- export: true,
289
- name,
290
- JSDoc: { comments: [description ? `@description ${transformers.jsStringEscape(description)}` : void 0].filter(Boolean) },
291
- params: canOverride ? params.toConstructor() : void 0,
292
- returnType,
293
- children: [
294
- seed ? `faker.seed(${JSON.stringify(seed)})` : void 0,
295
- /* @__PURE__ */ jsx("br", {}),
296
- `return ${fakerTextWithOverride}`
297
- ]
298
- })
299
- });
300
- }
301
-
302
- //#endregion
303
- export { Faker as t };
304
- //# sourceMappingURL=components-DUQvu8JV.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-DUQvu8JV.js","names":["schema","name","value","parserFaker.joinItems","parserFaker.parse"],"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 exclusiveMaximum: undefined,\n exclusiveMinimum: 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 typeName?: string\n regexGenerator?: 'faker' | 'randexp'\n canOverride?: boolean\n dateParser?: Options['dateParser']\n mapper?: Record<string, string>\n}\n\nexport function parse({ schema, 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((it) => parse({ schema, parent: current, name, current: it, siblings }, { ...options, canOverride: false })).filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n return fakerKeywordMapper.and(\n current.args.map((it) => parse({ schema, parent: current, current: it, 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((it) =>\n parse(\n { schema, parent: current, current: it, 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((it) =>\n parse(\n { schema, name, parent: current, current: it, 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((it) => parse({ schema, parent: current, current: it, siblings }, { ...options, canOverride: false })).filter(Boolean),\n )\n }\n\n return parse({ schema, 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 transformers from '@kubb/core/transformers'\nimport type { Schema } from '@kubb/plugin-oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\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): KubbNode {\n const fakerText = parserFaker.joinItems(\n tree\n .map((schema, _index, siblings) =>\n parserFaker.parse(\n { name, schema, parent: undefined, current: schema, siblings },\n {\n typeName,\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,QAAQ,OACV,QAAO,2BAA2B,IAAI;AAGxC,MAAI,QAAQ,OACV,QAAO,2BAA2B,IAAI;AAGxC,SAAO;;CAET,SAAS,KAAc,QAAiB;AACtC,MAAI,QAAQ,UAAa,QAAQ,OAC/B,QAAO,uCAAuC,IAAI,SAAS,IAAI;AAGjE,MAAI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