@kubb/plugin-faker 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.
- package/LICENSE +17 -10
- package/README.md +1 -4
- package/dist/Faker-BgleOzVN.cjs +486 -0
- package/dist/Faker-BgleOzVN.cjs.map +1 -0
- package/dist/Faker-CdyPfOPg.d.ts +27 -0
- package/dist/Faker-fcQEB9i5.js +384 -0
- package/dist/Faker-fcQEB9i5.js.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.d.ts +2 -31
- package/dist/components.js +1 -1
- package/dist/fakerGenerator-C3Ho3BaI.d.ts +9 -0
- package/dist/fakerGenerator-D7daHCh6.js +516 -0
- package/dist/fakerGenerator-D7daHCh6.js.map +1 -0
- package/dist/fakerGenerator-VJEVzLjc.cjs +526 -0
- package/dist/fakerGenerator-VJEVzLjc.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +2 -476
- package/dist/generators.js +1 -1
- package/dist/index.cjs +136 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -4
- package/dist/index.js +128 -83
- package/dist/index.js.map +1 -1
- package/dist/printerFaker-CJiwzoto.d.ts +206 -0
- package/package.json +52 -50
- package/src/components/Faker.tsx +124 -78
- package/src/generators/fakerGenerator.tsx +235 -134
- package/src/index.ts +7 -2
- package/src/plugin.ts +60 -121
- package/src/printers/printerFaker.ts +341 -0
- package/src/resolvers/resolverFaker.ts +92 -0
- package/src/types.ts +127 -81
- package/src/utils.ts +356 -0
- package/dist/components-BkBIov4R.js +0 -419
- package/dist/components-BkBIov4R.js.map +0 -1
- package/dist/components-IdP8GXXX.cjs +0 -461
- package/dist/components-IdP8GXXX.cjs.map +0 -1
- package/dist/fakerGenerator-CYUCNH3Q.cjs +0 -204
- package/dist/fakerGenerator-CYUCNH3Q.cjs.map +0 -1
- package/dist/fakerGenerator-M5oCrPmy.js +0 -200
- package/dist/fakerGenerator-M5oCrPmy.js.map +0 -1
- package/dist/types-r7BubMLO.d.ts +0 -132
- package/src/parser.ts +0 -453
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { createParser, findSchemaKeyword, 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
|
-
//#region ../../internals/utils/src/string.ts
|
|
6
|
-
/**
|
|
7
|
-
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
8
|
-
* Returns the string unchanged when no balanced quote pair is found.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* trimQuotes('"hello"') // 'hello'
|
|
12
|
-
* trimQuotes('hello') // 'hello'
|
|
13
|
-
*/
|
|
14
|
-
function trimQuotes(text) {
|
|
15
|
-
if (text.length >= 2) {
|
|
16
|
-
const first = text[0];
|
|
17
|
-
const last = text[text.length - 1];
|
|
18
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
19
|
-
}
|
|
20
|
-
return text;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Escapes characters that are not allowed inside JS string literals.
|
|
24
|
-
* Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).
|
|
25
|
-
*
|
|
26
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
27
|
-
*/
|
|
28
|
-
function jsStringEscape(input) {
|
|
29
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
30
|
-
switch (character) {
|
|
31
|
-
case "\"":
|
|
32
|
-
case "'":
|
|
33
|
-
case "\\": return `\\${character}`;
|
|
34
|
-
case "\n": return "\\n";
|
|
35
|
-
case "\r": return "\\r";
|
|
36
|
-
case "\u2028": return "\\u2028";
|
|
37
|
-
case "\u2029": return "\\u2029";
|
|
38
|
-
default: return "";
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region ../../internals/utils/src/object.ts
|
|
44
|
-
/**
|
|
45
|
-
* Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* stringify('hello') // '"hello"'
|
|
49
|
-
* stringify('"hello"') // '"hello"'
|
|
50
|
-
*/
|
|
51
|
-
function stringify(value) {
|
|
52
|
-
if (value === void 0 || value === null) return "\"\"";
|
|
53
|
-
return JSON.stringify(trimQuotes(value.toString()));
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region ../../internals/utils/src/regexp.ts
|
|
57
|
-
/**
|
|
58
|
-
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
59
|
-
* Inline flags expressed as `^(?im)` prefixes are extracted and applied to the resulting expression.
|
|
60
|
-
* Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* toRegExpString('^(?im)foo') // → 'new RegExp("foo", "im")'
|
|
64
|
-
* toRegExpString('^(?im)foo', null) // → '/foo/im'
|
|
65
|
-
*/
|
|
66
|
-
function toRegExpString(text, func = "RegExp") {
|
|
67
|
-
const raw = trimQuotes(text);
|
|
68
|
-
const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
|
|
69
|
-
const replacementTarget = match?.[1] ?? "";
|
|
70
|
-
const matchedFlags = match?.[2];
|
|
71
|
-
const cleaned = raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, "");
|
|
72
|
-
const { source, flags } = new RegExp(cleaned, matchedFlags);
|
|
73
|
-
if (func === null) return `/${source}/${flags}`;
|
|
74
|
-
return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/parser.ts
|
|
78
|
-
const fakerKeywordMapper = {
|
|
79
|
-
any: () => "undefined",
|
|
80
|
-
unknown: () => "undefined",
|
|
81
|
-
void: () => "undefined",
|
|
82
|
-
number: (min, max) => {
|
|
83
|
-
if (max !== void 0 && min !== void 0) return `faker.number.float({ min: ${min}, max: ${max} })`;
|
|
84
|
-
if (max !== void 0) return `faker.number.float({ max: ${max} })`;
|
|
85
|
-
if (min !== void 0) return `faker.number.float({ min: ${min} })`;
|
|
86
|
-
return "faker.number.float()";
|
|
87
|
-
},
|
|
88
|
-
integer: (min, max) => {
|
|
89
|
-
if (max !== void 0 && min !== void 0) return `faker.number.int({ min: ${min}, max: ${max} })`;
|
|
90
|
-
if (max !== void 0) return `faker.number.int({ max: ${max} })`;
|
|
91
|
-
if (min !== void 0) return `faker.number.int({ min: ${min} })`;
|
|
92
|
-
return "faker.number.int()";
|
|
93
|
-
},
|
|
94
|
-
bigint: () => "faker.number.bigInt()",
|
|
95
|
-
string: (min, max) => {
|
|
96
|
-
if (max !== void 0 && min !== void 0) return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
|
|
97
|
-
if (max !== void 0) return `faker.string.alpha({ length: ${max} })`;
|
|
98
|
-
if (min !== void 0) return `faker.string.alpha({ length: ${min} })`;
|
|
99
|
-
return "faker.string.alpha()";
|
|
100
|
-
},
|
|
101
|
-
boolean: () => "faker.datatype.boolean()",
|
|
102
|
-
undefined: () => "undefined",
|
|
103
|
-
null: () => "null",
|
|
104
|
-
array: (items = [], min, max) => {
|
|
105
|
-
if (items.length > 1) return `faker.helpers.arrayElements([${items.join(", ")}])`;
|
|
106
|
-
const item = items.at(0);
|
|
107
|
-
if (min !== void 0 && max !== void 0) return `faker.helpers.multiple(() => (${item}), { count: { min: ${min}, max: ${max} }})`;
|
|
108
|
-
if (min !== void 0) return `faker.helpers.multiple(() => (${item}), { count: ${min} })`;
|
|
109
|
-
if (max !== void 0) return `faker.helpers.multiple(() => (${item}), { count: { min: 0, max: ${max} }})`;
|
|
110
|
-
return `faker.helpers.multiple(() => (${item}))`;
|
|
111
|
-
},
|
|
112
|
-
tuple: (items = []) => `[${items.join(", ")}]`,
|
|
113
|
-
enum: (items = [], type = "any") => `faker.helpers.arrayElement<${type}>([${items.join(", ")}])`,
|
|
114
|
-
union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
|
|
115
|
-
datetime: () => "faker.date.anytime().toISOString()",
|
|
116
|
-
date: (type = "string", parser = "faker") => {
|
|
117
|
-
if (type === "string") {
|
|
118
|
-
if (parser !== "faker") return `${parser}(faker.date.anytime()).format("YYYY-MM-DD")`;
|
|
119
|
-
return "faker.date.anytime().toISOString().substring(0, 10)";
|
|
120
|
-
}
|
|
121
|
-
if (parser !== "faker") throw new Error(`type '${type}' and parser '${parser}' can not work together`);
|
|
122
|
-
return "faker.date.anytime()";
|
|
123
|
-
},
|
|
124
|
-
time: (type = "string", parser = "faker") => {
|
|
125
|
-
if (type === "string") {
|
|
126
|
-
if (parser !== "faker") return `${parser}(faker.date.anytime()).format("HH:mm:ss")`;
|
|
127
|
-
return "faker.date.anytime().toISOString().substring(11, 19)";
|
|
128
|
-
}
|
|
129
|
-
if (parser !== "faker") throw new Error(`type '${type}' and parser '${parser}' can not work together`);
|
|
130
|
-
return "faker.date.anytime()";
|
|
131
|
-
},
|
|
132
|
-
uuid: () => "faker.string.uuid()",
|
|
133
|
-
url: () => "faker.internet.url()",
|
|
134
|
-
and: (items = []) => {
|
|
135
|
-
if (items.length === 0) return "{}";
|
|
136
|
-
if (items.length === 1) return items[0] ?? "{}";
|
|
137
|
-
return `{...${items.join(", ...")}}`;
|
|
138
|
-
},
|
|
139
|
-
object: () => "object",
|
|
140
|
-
ref: () => "ref",
|
|
141
|
-
matches: (value = "", regexGenerator = "faker") => {
|
|
142
|
-
if (regexGenerator === "randexp") return `${toRegExpString(value, "RandExp")}.gen()`;
|
|
143
|
-
return `faker.helpers.fromRegExp("${value}")`;
|
|
144
|
-
},
|
|
145
|
-
email: () => "faker.internet.email()",
|
|
146
|
-
firstName: () => "faker.person.firstName()",
|
|
147
|
-
lastName: () => "faker.person.lastName()",
|
|
148
|
-
password: () => "faker.internet.password()",
|
|
149
|
-
phone: () => "faker.phone.number()",
|
|
150
|
-
blob: () => "faker.image.url() as unknown as Blob",
|
|
151
|
-
default: void 0,
|
|
152
|
-
describe: void 0,
|
|
153
|
-
const: (value) => value ?? "",
|
|
154
|
-
max: void 0,
|
|
155
|
-
min: void 0,
|
|
156
|
-
nullable: void 0,
|
|
157
|
-
nullish: void 0,
|
|
158
|
-
optional: void 0,
|
|
159
|
-
readOnly: void 0,
|
|
160
|
-
writeOnly: void 0,
|
|
161
|
-
deprecated: void 0,
|
|
162
|
-
example: void 0,
|
|
163
|
-
schema: void 0,
|
|
164
|
-
catchall: void 0,
|
|
165
|
-
name: void 0,
|
|
166
|
-
interface: void 0,
|
|
167
|
-
exclusiveMaximum: void 0,
|
|
168
|
-
exclusiveMinimum: void 0
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
|
|
172
|
-
*/
|
|
173
|
-
function schemaKeywordSorter(_a, b) {
|
|
174
|
-
if (b.keyword === "null") return -1;
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
function joinItems(items) {
|
|
178
|
-
switch (items.length) {
|
|
179
|
-
case 0: return "undefined";
|
|
180
|
-
case 1: return items[0];
|
|
181
|
-
default: return fakerKeywordMapper.union(items);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
const parse = createParser({
|
|
185
|
-
mapper: fakerKeywordMapper,
|
|
186
|
-
handlers: {
|
|
187
|
-
union(tree, options) {
|
|
188
|
-
const { current, schema, name, siblings } = tree;
|
|
189
|
-
if (Array.isArray(current.args) && !current.args.length) return "";
|
|
190
|
-
return fakerKeywordMapper.union(current.args.map((it) => this.parse({
|
|
191
|
-
schema,
|
|
192
|
-
parent: current,
|
|
193
|
-
name,
|
|
194
|
-
current: it,
|
|
195
|
-
siblings
|
|
196
|
-
}, {
|
|
197
|
-
...options,
|
|
198
|
-
canOverride: false
|
|
199
|
-
})).filter((x) => Boolean(x)));
|
|
200
|
-
},
|
|
201
|
-
and(tree, options) {
|
|
202
|
-
const { current, schema, siblings } = tree;
|
|
203
|
-
return fakerKeywordMapper.and(current.args.map((it) => this.parse({
|
|
204
|
-
schema,
|
|
205
|
-
parent: current,
|
|
206
|
-
current: it,
|
|
207
|
-
siblings
|
|
208
|
-
}, {
|
|
209
|
-
...options,
|
|
210
|
-
canOverride: false
|
|
211
|
-
})).filter((x) => Boolean(x)));
|
|
212
|
-
},
|
|
213
|
-
array(tree, options) {
|
|
214
|
-
const { current, schema } = tree;
|
|
215
|
-
return fakerKeywordMapper.array(current.args.items.map((it) => this.parse({
|
|
216
|
-
schema,
|
|
217
|
-
parent: current,
|
|
218
|
-
current: it,
|
|
219
|
-
siblings: current.args.items
|
|
220
|
-
}, {
|
|
221
|
-
...options,
|
|
222
|
-
typeName: `NonNullable<${options.typeName}>[number]`,
|
|
223
|
-
canOverride: false
|
|
224
|
-
})).filter((x) => Boolean(x)), current.args.min, current.args.max);
|
|
225
|
-
},
|
|
226
|
-
enum(tree, options) {
|
|
227
|
-
const { current, parent, name } = tree;
|
|
228
|
-
if (parent ? isKeyword(parent, schemaKeywords.tuple) : false) return fakerKeywordMapper.enum(current.args.items.map((schema) => {
|
|
229
|
-
if (schema.format === "number") return schema.value;
|
|
230
|
-
if (schema.format === "boolean") return schema.value;
|
|
231
|
-
return stringify(schema.value);
|
|
232
|
-
}));
|
|
233
|
-
return fakerKeywordMapper.enum(current.args.items.map((schema) => {
|
|
234
|
-
if (schema.format === "number") return schema.value;
|
|
235
|
-
if (schema.format === "boolean") return schema.value;
|
|
236
|
-
return stringify(schema.value);
|
|
237
|
-
}), name ? options.typeName : void 0);
|
|
238
|
-
},
|
|
239
|
-
ref(tree, options) {
|
|
240
|
-
const { current, parent } = tree;
|
|
241
|
-
if (!current.args?.name) throw new Error(`Name not defined for keyword ${current.keyword}`);
|
|
242
|
-
if (options.rootTypeName && current.args.name === options.rootTypeName) return "undefined as any";
|
|
243
|
-
const isNestedInObjectOrAnd = parent && (isKeyword(parent, schemaKeywords.object) || isKeyword(parent, schemaKeywords.and));
|
|
244
|
-
if (options.canOverride && !isNestedInObjectOrAnd) return `${current.args.name}(data)`;
|
|
245
|
-
return `${current.args.name}()`;
|
|
246
|
-
},
|
|
247
|
-
object(tree, options) {
|
|
248
|
-
const { current, schema } = tree;
|
|
249
|
-
return `{${Object.entries(current.args?.properties || {}).filter((item) => {
|
|
250
|
-
const schema = item[1];
|
|
251
|
-
return schema && typeof schema.map === "function";
|
|
252
|
-
}).map(([name, schemas]) => {
|
|
253
|
-
const mappedName = schemas.find((schema) => schema.keyword === schemaKeywords.name)?.args || name;
|
|
254
|
-
if (options.mapper && Object.hasOwn(options.mapper, mappedName)) return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
255
|
-
return `"${name}": ${joinItems(schemas.sort(schemaKeywordSorter).map((it) => this.parse({
|
|
256
|
-
schema,
|
|
257
|
-
name,
|
|
258
|
-
parent: current,
|
|
259
|
-
current: it,
|
|
260
|
-
siblings: schemas
|
|
261
|
-
}, {
|
|
262
|
-
...options,
|
|
263
|
-
typeName: `NonNullable<${options.typeName}>[${JSON.stringify(name)}]`,
|
|
264
|
-
canOverride: false
|
|
265
|
-
})).filter((x) => Boolean(x)))}`;
|
|
266
|
-
}).join(",")}}`;
|
|
267
|
-
},
|
|
268
|
-
tuple(tree, options) {
|
|
269
|
-
const { current, schema, siblings } = tree;
|
|
270
|
-
if (Array.isArray(current.args.items)) return fakerKeywordMapper.tuple(current.args.items.map((it) => this.parse({
|
|
271
|
-
schema,
|
|
272
|
-
parent: current,
|
|
273
|
-
current: it,
|
|
274
|
-
siblings
|
|
275
|
-
}, {
|
|
276
|
-
...options,
|
|
277
|
-
canOverride: false
|
|
278
|
-
})).filter((x) => Boolean(x)));
|
|
279
|
-
return this.parse({
|
|
280
|
-
schema,
|
|
281
|
-
parent: current,
|
|
282
|
-
current: current.args.items,
|
|
283
|
-
siblings
|
|
284
|
-
}, {
|
|
285
|
-
...options,
|
|
286
|
-
canOverride: false
|
|
287
|
-
});
|
|
288
|
-
},
|
|
289
|
-
const(tree, _options) {
|
|
290
|
-
const { current } = tree;
|
|
291
|
-
if (current.args.format === "number" && current.args.name !== void 0) return fakerKeywordMapper.const(current.args.name?.toString());
|
|
292
|
-
return fakerKeywordMapper.const(stringify(current.args.value));
|
|
293
|
-
},
|
|
294
|
-
matches(tree, options) {
|
|
295
|
-
const { current } = tree;
|
|
296
|
-
if (current.args) return fakerKeywordMapper.matches(current.args, options.regexGenerator);
|
|
297
|
-
},
|
|
298
|
-
null() {
|
|
299
|
-
return fakerKeywordMapper.null();
|
|
300
|
-
},
|
|
301
|
-
undefined() {
|
|
302
|
-
return fakerKeywordMapper.undefined();
|
|
303
|
-
},
|
|
304
|
-
any() {
|
|
305
|
-
return fakerKeywordMapper.any();
|
|
306
|
-
},
|
|
307
|
-
string(tree, _options) {
|
|
308
|
-
const { siblings } = tree;
|
|
309
|
-
if (siblings) {
|
|
310
|
-
const minSchema = findSchemaKeyword(siblings, "min");
|
|
311
|
-
const maxSchema = findSchemaKeyword(siblings, "max");
|
|
312
|
-
return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args);
|
|
313
|
-
}
|
|
314
|
-
return fakerKeywordMapper.string();
|
|
315
|
-
},
|
|
316
|
-
number(tree, _options) {
|
|
317
|
-
const { siblings } = tree;
|
|
318
|
-
if (siblings) {
|
|
319
|
-
const minSchema = findSchemaKeyword(siblings, "min");
|
|
320
|
-
const maxSchema = findSchemaKeyword(siblings, "max");
|
|
321
|
-
return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args);
|
|
322
|
-
}
|
|
323
|
-
return fakerKeywordMapper.number();
|
|
324
|
-
},
|
|
325
|
-
integer(tree, _options) {
|
|
326
|
-
const { siblings } = tree;
|
|
327
|
-
if (siblings) {
|
|
328
|
-
const minSchema = findSchemaKeyword(siblings, "min");
|
|
329
|
-
const maxSchema = findSchemaKeyword(siblings, "max");
|
|
330
|
-
return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args);
|
|
331
|
-
}
|
|
332
|
-
return fakerKeywordMapper.integer();
|
|
333
|
-
},
|
|
334
|
-
bigint(_tree, _options) {
|
|
335
|
-
return fakerKeywordMapper.bigint();
|
|
336
|
-
},
|
|
337
|
-
datetime() {
|
|
338
|
-
return fakerKeywordMapper.datetime();
|
|
339
|
-
},
|
|
340
|
-
date(tree, options) {
|
|
341
|
-
const { current } = tree;
|
|
342
|
-
return fakerKeywordMapper.date(current.args.type, options.dateParser);
|
|
343
|
-
},
|
|
344
|
-
time(tree, options) {
|
|
345
|
-
const { current } = tree;
|
|
346
|
-
return fakerKeywordMapper.time(current.args.type, options.dateParser);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region src/components/Faker.tsx
|
|
352
|
-
function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }) {
|
|
353
|
-
const fakerText = joinItems(tree.map((schema, _index, siblings) => parse({
|
|
354
|
-
name,
|
|
355
|
-
schema,
|
|
356
|
-
parent: void 0,
|
|
357
|
-
current: schema,
|
|
358
|
-
siblings
|
|
359
|
-
}, {
|
|
360
|
-
typeName,
|
|
361
|
-
rootTypeName: name,
|
|
362
|
-
regexGenerator,
|
|
363
|
-
mapper,
|
|
364
|
-
canOverride,
|
|
365
|
-
dateParser
|
|
366
|
-
})).filter((x) => Boolean(x)));
|
|
367
|
-
const isArray = fakerText.startsWith("faker.helpers.arrayElements") || fakerText.startsWith("faker.helpers.multiple");
|
|
368
|
-
const isRefToArray = tree.some((s) => isKeyword(s, schemaKeywords.schema) && s.args.type === "array");
|
|
369
|
-
const isObject = fakerText.startsWith("{");
|
|
370
|
-
const isTuple = fakerText.startsWith("faker.helpers.arrayElement");
|
|
371
|
-
const isSimpleString = name === "string";
|
|
372
|
-
const isSimpleInt = name === "integer";
|
|
373
|
-
const isSimpleFloat = name === "float";
|
|
374
|
-
let fakerTextWithOverride = fakerText;
|
|
375
|
-
if (canOverride && isObject) fakerTextWithOverride = `{
|
|
376
|
-
...${fakerText},
|
|
377
|
-
...data || {}
|
|
378
|
-
}`;
|
|
379
|
-
if (canOverride && isTuple) fakerTextWithOverride = `data || ${fakerText}`;
|
|
380
|
-
if (canOverride && isArray) fakerTextWithOverride = `[
|
|
381
|
-
...${fakerText},
|
|
382
|
-
...data || []
|
|
383
|
-
]`;
|
|
384
|
-
if (canOverride && isSimpleString) fakerTextWithOverride = "data ?? faker.string.alpha()";
|
|
385
|
-
if (canOverride && isSimpleInt) fakerTextWithOverride = "data ?? faker.number.int()";
|
|
386
|
-
if (canOverride && isSimpleFloat) fakerTextWithOverride = "data ?? faker.number.float()";
|
|
387
|
-
let type = `Partial<${typeName}>`;
|
|
388
|
-
if (isArray) type = typeName;
|
|
389
|
-
if (isRefToArray) type = typeName;
|
|
390
|
-
if (isSimpleString) type = name;
|
|
391
|
-
if (isSimpleInt || isSimpleFloat) type = "number";
|
|
392
|
-
const params = FunctionParams.factory({ data: {
|
|
393
|
-
type,
|
|
394
|
-
optional: true
|
|
395
|
-
} });
|
|
396
|
-
let returnType = canOverride ? typeName : void 0;
|
|
397
|
-
if (isSimpleString || isSimpleInt || isSimpleFloat) returnType = type;
|
|
398
|
-
return /* @__PURE__ */ jsx(File.Source, {
|
|
399
|
-
name,
|
|
400
|
-
isExportable: true,
|
|
401
|
-
isIndexable: true,
|
|
402
|
-
children: /* @__PURE__ */ jsxs(Function, {
|
|
403
|
-
export: true,
|
|
404
|
-
name,
|
|
405
|
-
JSDoc: { comments: [description ? `@description ${jsStringEscape(description)}` : void 0].filter(Boolean) },
|
|
406
|
-
params: canOverride ? params.toConstructor() : void 0,
|
|
407
|
-
returnType,
|
|
408
|
-
children: [
|
|
409
|
-
seed ? `faker.seed(${JSON.stringify(seed)})` : void 0,
|
|
410
|
-
/* @__PURE__ */ jsx("br", {}),
|
|
411
|
-
`return ${fakerTextWithOverride}`
|
|
412
|
-
]
|
|
413
|
-
})
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
//#endregion
|
|
417
|
-
export { Faker as t };
|
|
418
|
-
|
|
419
|
-
//# sourceMappingURL=components-BkBIov4R.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components-BkBIov4R.js","names":["parserFaker.joinItems","parserFaker.parse"],"sources":["../../../internals/utils/src/string.ts","../../../internals/utils/src/object.ts","../../../internals/utils/src/regexp.ts","../src/parser.ts","../src/components/Faker.tsx"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Returns a masked version of a string, showing only the first and last few characters.\n * Useful for logging sensitive values (tokens, keys) without exposing the full value.\n *\n * @example\n * maskString('KUBB_STUDIO-abc123-xyz789') // 'KUBB_STUDIO-…789'\n */\nexport function maskString(value: string, start = 8, end = 4): string {\n if (value.length <= start + end) return value\n return `${value.slice(0, start)}…${value.slice(-end)}`\n}\n","import { trimQuotes } from './string.ts'\n\n/**\n * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.\n *\n * @example\n * stringify('hello') // '\"hello\"'\n * stringify('\"hello\"') // '\"hello\"'\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return '\"\"'\n return JSON.stringify(trimQuotes(value.toString()))\n}\n\n/**\n * Converts a plain object into a multiline key-value string suitable for embedding in generated code.\n * Nested objects are recursively stringified with indentation.\n *\n * @example\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Serializes plugin options for safe JSON transport.\n * Strips functions, symbols, and `undefined` values recursively.\n */\nexport function serializePluginOptions<TOptions extends object>(options: TOptions): TOptions {\n if (options === null || options === undefined) return {} as TOptions\n if (typeof options !== 'object') return options\n if (Array.isArray(options)) return options.map(serializePluginOptions) as unknown as TOptions\n\n const serialized: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(options)) {\n if (typeof value === 'function' || typeof value === 'symbol' || value === undefined) continue\n serialized[key] = value !== null && typeof value === 'object' ? serializePluginOptions(value as object) : value\n }\n return serialized as TOptions\n}\n\n/**\n * Converts a dot-notation path or string array into an optional-chaining accessor expression.\n *\n * @example\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // → \"lastPage?.['pagination']?.['next']?.['id']\"\n */\nexport function getNestedAccessor(param: string | string[], accessor: string): string | undefined {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return undefined\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { trimQuotes } from './string.ts'\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as `^(?im)` prefixes are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * toRegExpString('^(?im)foo') // → 'new RegExp(\"foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // → '/foo/im'\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n","import { stringify, toRegExpString } from '@internals/utils'\nimport type { Schema, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'\nimport { createParser, findSchemaKeyword, isKeyword, 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 bigint: () => 'faker.number.bigInt()',\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[] = []) => {\n // Handle empty array case\n if (items.length === 0) {\n return '{}'\n }\n\n // If only one item, return it as-is (no need to spread)\n // This fixes the issue with single refs to primitives like enums\n if (items.length === 1) {\n return items[0] ?? '{}'\n }\n\n // If multiple items, spread them together\n // This handles both object literals and multiple refs to objects\n return `{...${items.join(', ...')}}`\n },\n object: () => 'object',\n ref: () => 'ref',\n matches: (value = '', regexGenerator: 'faker' | 'randexp' = 'faker') => {\n if (regexGenerator === 'randexp') {\n return `${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 rootTypeName?: string\n regexGenerator?: 'faker' | 'randexp'\n canOverride?: boolean\n dateParser?: Options['dateParser']\n mapper?: Record<string, string>\n}\n\nexport const parse = createParser<string, ParserOptions>({\n mapper: fakerKeywordMapper,\n handlers: {\n union(tree, options) {\n const { current, schema, name, siblings } = tree\n\n if (Array.isArray(current.args) && !current.args.length) {\n return ''\n }\n\n return fakerKeywordMapper.union(\n current.args\n .map((it) => this.parse({ schema, parent: current, name, current: it, siblings }, { ...options, canOverride: false }))\n .filter((x): x is string => Boolean(x)),\n )\n },\n and(tree, options) {\n const { current, schema, siblings } = tree\n\n return fakerKeywordMapper.and(\n current.args\n .map((it) => this.parse({ schema, parent: current, current: it, siblings }, { ...options, canOverride: false }))\n .filter((x): x is string => Boolean(x)),\n )\n },\n array(tree, options) {\n const { current, schema } = tree\n\n return fakerKeywordMapper.array(\n current.args.items\n .map((it) =>\n this.parse(\n {\n schema,\n parent: current,\n current: it,\n siblings: current.args.items,\n },\n {\n ...options,\n typeName: `NonNullable<${options.typeName}>[number]`,\n canOverride: false,\n },\n ),\n )\n .filter((x): x is string => Boolean(x)),\n current.args.min,\n current.args.max,\n )\n },\n enum(tree, options) {\n const { current, parent, name } = tree\n\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 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 stringify(schema.value)\n }),\n // TODO replace this with getEnumNameFromSchema\n name ? options.typeName : undefined,\n )\n },\n ref(tree, options) {\n const { current, parent } = tree\n\n if (!current.args?.name) {\n throw new Error(`Name not defined for keyword ${current.keyword}`)\n }\n\n // Check if this is a self-referencing type (prevents infinite recursion)\n // The rootTypeName is the function name being generated (e.g., \"createNode\")\n // The current.args.name is the ref function name (e.g., \"createNode\")\n const isSelfReferencing = options.rootTypeName && current.args.name === options.rootTypeName\n\n if (isSelfReferencing) {\n // For self-referencing types, return undefined to prevent infinite recursion\n // This will result in empty arrays/objects by default\n return 'undefined as any'\n }\n\n // Check if the parent is an object or and keyword - in these cases, we don't want to pass data\n // because it would incorrectly forward the parent's data to a nested ref\n const isNestedInObjectOrAnd = parent && (isKeyword(parent, schemaKeywords.object) || isKeyword(parent, schemaKeywords.and))\n\n if (options.canOverride && !isNestedInObjectOrAnd) {\n return `${current.args.name}(data)`\n }\n\n return `${current.args.name}()`\n },\n object(tree, options) {\n const { current, schema } = tree\n\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 // Use Object.hasOwn to avoid matching inherited properties like 'toString', 'valueOf', etc.\n if (options.mapper && Object.hasOwn(options.mapper, mappedName)) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${joinItems(\n schemas\n .sort(schemaKeywordSorter)\n .map((it) =>\n this.parse(\n {\n schema,\n name,\n parent: current,\n current: it,\n siblings: schemas,\n },\n {\n ...options,\n typeName: `NonNullable<${options.typeName}>[${JSON.stringify(name)}]`,\n canOverride: false,\n },\n ),\n )\n .filter((x): x is string => Boolean(x)),\n )}`\n })\n .join(',')\n\n return `{${argsObject}}`\n },\n tuple(tree, options) {\n const { current, schema, siblings } = tree\n\n if (Array.isArray(current.args.items)) {\n return fakerKeywordMapper.tuple(\n current.args.items\n .map((it) => this.parse({ schema, parent: current, current: it, siblings }, { ...options, canOverride: false }))\n .filter((x): x is string => Boolean(x)),\n )\n }\n\n return this.parse({ schema, parent: current, current: current.args.items, siblings }, { ...options, canOverride: false })\n },\n const(tree, _options) {\n const { current } = tree\n\n if (current.args.format === 'number' && current.args.name !== undefined) {\n return fakerKeywordMapper.const(current.args.name?.toString())\n }\n return fakerKeywordMapper.const(stringify(current.args.value))\n },\n matches(tree, options) {\n const { current } = tree\n\n if (current.args) {\n return fakerKeywordMapper.matches(current.args, options.regexGenerator)\n }\n return undefined\n },\n null() {\n return fakerKeywordMapper.null()\n },\n undefined() {\n return fakerKeywordMapper.undefined()\n },\n any() {\n return fakerKeywordMapper.any()\n },\n string(tree, _options) {\n const { siblings } = tree\n\n if (siblings) {\n const minSchema = findSchemaKeyword(siblings, 'min')\n const maxSchema = findSchemaKeyword(siblings, 'max')\n\n return fakerKeywordMapper.string(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.string()\n },\n number(tree, _options) {\n const { siblings } = tree\n\n if (siblings) {\n const minSchema = findSchemaKeyword(siblings, 'min')\n const maxSchema = findSchemaKeyword(siblings, 'max')\n\n return fakerKeywordMapper.number(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.number()\n },\n integer(tree, _options) {\n const { siblings } = tree\n\n if (siblings) {\n const minSchema = findSchemaKeyword(siblings, 'min')\n const maxSchema = findSchemaKeyword(siblings, 'max')\n\n return fakerKeywordMapper.integer(minSchema?.args, maxSchema?.args)\n }\n\n return fakerKeywordMapper.integer()\n },\n bigint(_tree, _options) {\n return fakerKeywordMapper.bigint()\n },\n datetime() {\n return fakerKeywordMapper.datetime()\n },\n date(tree, options) {\n const { current } = tree\n\n return fakerKeywordMapper.date(current.args.type, options.dateParser)\n },\n time(tree, options) {\n const { current } = tree\n\n return fakerKeywordMapper.time(current.args.type, options.dateParser)\n },\n },\n})\n","import { jsStringEscape } from '@internals/utils'\nimport type { Schema } from '@kubb/plugin-oas'\nimport { isKeyword, schemaKeywords } from '@kubb/plugin-oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } 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): FabricReactNode {\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 rootTypeName: name,\n regexGenerator,\n mapper,\n canOverride,\n dateParser,\n },\n ),\n )\n .filter((x): x is string => Boolean(x)),\n )\n\n const isArray = fakerText.startsWith('faker.helpers.arrayElements') || fakerText.startsWith('faker.helpers.multiple')\n const isRefToArray = tree.some((s) => isKeyword(s, schemaKeywords.schema) && s.args.type === 'array')\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) fakerTextWithOverride = `data || ${fakerText}`\n\n if (canOverride && isArray) {\n fakerTextWithOverride = `[\n ...${fakerText},\n ...data || []\n ]`\n }\n\n if (canOverride && isSimpleString) fakerTextWithOverride = 'data ?? faker.string.alpha()'\n\n if (canOverride && isSimpleInt) fakerTextWithOverride = 'data ?? faker.number.int()'\n\n if (canOverride && isSimpleFloat) fakerTextWithOverride = 'data ?? faker.number.float()'\n\n let type = `Partial<${typeName}>`\n\n if (isArray) type = typeName\n if (isRefToArray) type = typeName\n if (isSimpleString) type = name\n 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 ${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":";;;;;;;;;;;;;AAQA,SAAgB,WAAW,MAAsB;AAC/C,KAAI,KAAK,UAAU,GAAG;EACpB,MAAM,QAAQ,KAAK;EACnB,MAAM,OAAO,KAAK,KAAK,SAAS;AAChC,MAAK,UAAU,QAAO,SAAS,QAAS,UAAU,OAAO,SAAS,OAAS,UAAU,OAAO,SAAS,IACnG,QAAO,KAAK,MAAM,GAAG,GAAG;;AAG5B,QAAO;;;;;;;;AAST,SAAgB,eAAe,OAAwB;AACrD,QAAO,GAAG,QAAQ,QAAQ,4BAA4B,cAAc;AAClE,UAAQ,WAAR;GACE,KAAK;GACL,KAAK;GACL,KAAK,KACH,QAAO,KAAK;GACd,KAAK,KACH,QAAO;GACT,KAAK,KACH,QAAO;GACT,KAAK,SACH,QAAO;GACT,KAAK,SACH,QAAO;GACT,QACE,QAAO;;GAEX;;;;;;;;;;;ACl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