@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
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2026 Kubb Labs
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
— see licenses/LICENSE-AGPL-3.0 for the full license text:
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
<img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
|
|
5
5
|
</a>
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
[![npm version][npm-version-src]][npm-version-href]
|
|
9
8
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
10
9
|
[![Coverage][coverage-src]][coverage-href]
|
|
11
10
|
[![License][license-src]][license-href]
|
|
12
11
|
[![Sponsors][sponsors-src]][sponsors-href]
|
|
12
|
+
|
|
13
13
|
<h4>
|
|
14
14
|
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
15
15
|
<span> · </span>
|
|
@@ -21,10 +21,8 @@
|
|
|
21
21
|
</h4>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
Swagger integration to create mock data based on Faker.js
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
## Supporting Kubb
|
|
29
27
|
|
|
30
28
|
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
@@ -37,7 +35,6 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
|
|
|
37
35
|
</a>
|
|
38
36
|
</p>
|
|
39
37
|
|
|
40
|
-
|
|
41
38
|
<!-- Badges -->
|
|
42
39
|
|
|
43
40
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-faker?flat&colorA=18181B&colorB=f58517
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let node_path = require("node:path");
|
|
28
|
+
let _kubb_core = require("@kubb/core");
|
|
29
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
30
|
+
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
31
|
+
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
32
|
+
//#region ../../internals/utils/src/string.ts
|
|
33
|
+
/**
|
|
34
|
+
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
35
|
+
* Returns the string unchanged when no balanced quote pair is found.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* trimQuotes('"hello"') // 'hello'
|
|
39
|
+
* trimQuotes('hello') // 'hello'
|
|
40
|
+
*/
|
|
41
|
+
function trimQuotes(text) {
|
|
42
|
+
if (text.length >= 2) {
|
|
43
|
+
const first = text[0];
|
|
44
|
+
const last = text[text.length - 1];
|
|
45
|
+
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
46
|
+
}
|
|
47
|
+
return text;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Escapes characters that are not allowed inside JS string literals.
|
|
51
|
+
* Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).
|
|
52
|
+
*
|
|
53
|
+
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function jsStringEscape(input) {
|
|
61
|
+
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
62
|
+
switch (character) {
|
|
63
|
+
case "\"":
|
|
64
|
+
case "'":
|
|
65
|
+
case "\\": return `\\${character}`;
|
|
66
|
+
case "\n": return "\\n";
|
|
67
|
+
case "\r": return "\\r";
|
|
68
|
+
case "\u2028": return "\\u2028";
|
|
69
|
+
case "\u2029": return "\\u2029";
|
|
70
|
+
default: return "";
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/utils.ts
|
|
76
|
+
/**
|
|
77
|
+
* Returns the `@faker-js/faker` named export for a locale code.
|
|
78
|
+
*
|
|
79
|
+
* Without a locale, returns `'faker'` for the default English instance.
|
|
80
|
+
* With a locale, the language code is converted to upper case and joined with any region suffix.
|
|
81
|
+
*
|
|
82
|
+
* @example Default
|
|
83
|
+
* `localeToFakerImport() // 'faker'`
|
|
84
|
+
*
|
|
85
|
+
* @example Simple locale
|
|
86
|
+
* `localeToFakerImport('de') // 'fakerDE'`
|
|
87
|
+
*
|
|
88
|
+
* @example Compound locale
|
|
89
|
+
* `localeToFakerImport('de_AT') // 'fakerDE_AT'`
|
|
90
|
+
*/
|
|
91
|
+
function localeToFakerImport(locale) {
|
|
92
|
+
if (!locale) return "faker";
|
|
93
|
+
const parts = locale.split("_");
|
|
94
|
+
parts[0] = parts[0].toUpperCase();
|
|
95
|
+
return `faker${parts.join("_")}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Determines if a schema node can be overridden during faker generation.
|
|
99
|
+
*/
|
|
100
|
+
function canOverrideSchema(node) {
|
|
101
|
+
return new Set([
|
|
102
|
+
"array",
|
|
103
|
+
"tuple",
|
|
104
|
+
"object",
|
|
105
|
+
"intersection",
|
|
106
|
+
"union",
|
|
107
|
+
"enum",
|
|
108
|
+
"ref",
|
|
109
|
+
"string",
|
|
110
|
+
"email",
|
|
111
|
+
"url",
|
|
112
|
+
"uuid",
|
|
113
|
+
"number",
|
|
114
|
+
"integer",
|
|
115
|
+
"bigint",
|
|
116
|
+
"boolean",
|
|
117
|
+
"date",
|
|
118
|
+
"time",
|
|
119
|
+
"datetime",
|
|
120
|
+
"blob"
|
|
121
|
+
]).has(node.type);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolves a schema reference by looking up the referenced schema in the provided array.
|
|
125
|
+
* Returns the original node if it's not a reference.
|
|
126
|
+
*/
|
|
127
|
+
function resolveSchemaRef(node, schemas) {
|
|
128
|
+
if (node.type !== "ref") return node;
|
|
129
|
+
return schemas.find((schema) => schema.name === node.name && schema.type !== "ref") ?? node;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolves a parameter name based on its location (path, query, header, etc.) using the provided resolver.
|
|
133
|
+
*/
|
|
134
|
+
function resolveParamNameByLocation(resolver, node, param) {
|
|
135
|
+
switch (param.in) {
|
|
136
|
+
case "path": return resolver.resolvePathParamsName(node, param);
|
|
137
|
+
case "query": return resolver.resolveQueryParamsName(node, param);
|
|
138
|
+
case "header": return resolver.resolveHeaderParamsName(node, param);
|
|
139
|
+
default: return resolver.resolveParamName(node, param);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function shouldInlineSingleResponseSchema(schema) {
|
|
143
|
+
return new Set([
|
|
144
|
+
"any",
|
|
145
|
+
"unknown",
|
|
146
|
+
"void",
|
|
147
|
+
"null",
|
|
148
|
+
"array",
|
|
149
|
+
"tuple",
|
|
150
|
+
"string",
|
|
151
|
+
"email",
|
|
152
|
+
"url",
|
|
153
|
+
"uuid",
|
|
154
|
+
"number",
|
|
155
|
+
"integer",
|
|
156
|
+
"bigint",
|
|
157
|
+
"boolean",
|
|
158
|
+
"date",
|
|
159
|
+
"time",
|
|
160
|
+
"datetime",
|
|
161
|
+
"blob",
|
|
162
|
+
"enum",
|
|
163
|
+
"union"
|
|
164
|
+
]).has(schema.type);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Builds a response schema as a union of all response statuses.
|
|
168
|
+
* Returns null if no responses are provided, or embeds single simple responses inline.
|
|
169
|
+
*/
|
|
170
|
+
function buildResponseUnionSchema(node, resolver) {
|
|
171
|
+
const responses = node.responses.filter((response) => response.schema);
|
|
172
|
+
if (!responses.length) return null;
|
|
173
|
+
if (responses.length === 1) {
|
|
174
|
+
if (shouldInlineSingleResponseSchema(responses[0].schema)) return responses[0].schema;
|
|
175
|
+
return _kubb_core.ast.createSchema({
|
|
176
|
+
type: "ref",
|
|
177
|
+
name: resolver.resolveResponseStatusName(node, responses[0].statusCode)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return _kubb_core.ast.createSchema({
|
|
181
|
+
type: "union",
|
|
182
|
+
members: responses.map((response) => _kubb_core.ast.createSchema({
|
|
183
|
+
type: "ref",
|
|
184
|
+
name: resolver.resolveResponseStatusName(node, response.statusCode)
|
|
185
|
+
}))
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const SCALAR_TYPES$1 = new Set([
|
|
189
|
+
"string",
|
|
190
|
+
"email",
|
|
191
|
+
"url",
|
|
192
|
+
"uuid",
|
|
193
|
+
"number",
|
|
194
|
+
"integer",
|
|
195
|
+
"bigint",
|
|
196
|
+
"boolean",
|
|
197
|
+
"date",
|
|
198
|
+
"time",
|
|
199
|
+
"datetime",
|
|
200
|
+
"blob",
|
|
201
|
+
"enum"
|
|
202
|
+
]);
|
|
203
|
+
const ARRAY_TYPES$1 = new Set(["array"]);
|
|
204
|
+
function toRelativeImportPath(from, to) {
|
|
205
|
+
const relativePath = node_path.posix.relative(node_path.posix.dirname(from), to);
|
|
206
|
+
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
207
|
+
}
|
|
208
|
+
function escapeRegExp(value) {
|
|
209
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Filters imports to only those that are actually used in the generated code.
|
|
213
|
+
* Checks for function calls matching the imported names.
|
|
214
|
+
*/
|
|
215
|
+
function filterUsedImports(imports, text, skipImportNames = []) {
|
|
216
|
+
return imports.filter((entry) => {
|
|
217
|
+
return (Array.isArray(entry.name) ? entry.name : [entry.name]).map((name) => {
|
|
218
|
+
if (typeof name === "string") return name;
|
|
219
|
+
return name?.name ?? name?.propertyName;
|
|
220
|
+
}).filter((name) => Boolean(name)).some((name) => {
|
|
221
|
+
if (skipImportNames.includes(name)) return false;
|
|
222
|
+
return new RegExp(`\\b${escapeRegExp(name)}\\b(?=\\s*\\()`).test(text);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Detects and resolves import name conflicts by adding aliases to conflicting names.
|
|
228
|
+
* Returns updated imports with a mapping of original names to their aliases.
|
|
229
|
+
*/
|
|
230
|
+
function aliasConflictingImports(imports, reservedNames) {
|
|
231
|
+
const reservedNameSet = new Set(reservedNames);
|
|
232
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
233
|
+
return {
|
|
234
|
+
imports: imports.map((entry) => {
|
|
235
|
+
const aliasedNames = (Array.isArray(entry.name) ? entry.name : [entry.name]).map((item) => {
|
|
236
|
+
if (typeof item !== "string" || !reservedNameSet.has(item)) return item;
|
|
237
|
+
const alias = `${item}Schema`;
|
|
238
|
+
aliases.set(item, alias);
|
|
239
|
+
return {
|
|
240
|
+
propertyName: item,
|
|
241
|
+
name: alias
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
return aliasedNames.some((item) => typeof item === "object" && item.name) ? {
|
|
245
|
+
...entry,
|
|
246
|
+
name: aliasedNames
|
|
247
|
+
} : entry;
|
|
248
|
+
}),
|
|
249
|
+
aliases
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Replaces all occurrences of original names with their aliased versions in the given text.
|
|
254
|
+
*/
|
|
255
|
+
function rewriteAliasedImports(text, aliases) {
|
|
256
|
+
return Array.from(aliases).reduce((acc, [name, alias]) => acc.replace(new RegExp(`\\b${escapeRegExp(name)}\\b`, "g"), alias), text);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Resolves a type reference, determining if it needs an import statement or inline type reference.
|
|
260
|
+
* Takes into account whether the type can be overridden and the file paths.
|
|
261
|
+
*/
|
|
262
|
+
function resolveTypeReference({ node, canOverride, name, typeName, filePath, typeFilePath }) {
|
|
263
|
+
const { usesTypeName } = resolveFakerTypeUsage(node, typeName, canOverride);
|
|
264
|
+
if (!usesTypeName) return { typeName };
|
|
265
|
+
if (name === typeName) return { typeName: `import('${toRelativeImportPath(filePath, typeFilePath)}').${typeName}` };
|
|
266
|
+
return {
|
|
267
|
+
importPath: typeFilePath,
|
|
268
|
+
typeName
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Maps a schema node type to its corresponding scalar type representation.
|
|
273
|
+
* Returns the type name for enums or the base type (string, number, etc.) for primitives.
|
|
274
|
+
*/
|
|
275
|
+
function getScalarType(node, typeName) {
|
|
276
|
+
switch (node.type) {
|
|
277
|
+
case "string":
|
|
278
|
+
case "email":
|
|
279
|
+
case "url":
|
|
280
|
+
case "uuid": return "string";
|
|
281
|
+
case "number":
|
|
282
|
+
case "integer": return "number";
|
|
283
|
+
case "bigint": return "bigint";
|
|
284
|
+
case "boolean": return "boolean";
|
|
285
|
+
case "date":
|
|
286
|
+
case "time": return node.representation === "date" ? "Date" : "string";
|
|
287
|
+
case "datetime": return "string";
|
|
288
|
+
case "blob": return "Blob";
|
|
289
|
+
case "enum": return typeName;
|
|
290
|
+
default: return typeName;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Resolves faker type usage information for a schema.
|
|
295
|
+
* Determines the data type, return type, and whether it uses the type name.
|
|
296
|
+
*/
|
|
297
|
+
function resolveFakerTypeUsage(node, typeName, canOverride) {
|
|
298
|
+
const isArray = ARRAY_TYPES$1.has(node.type);
|
|
299
|
+
const isTuple = node.type === "tuple";
|
|
300
|
+
const isScalar = SCALAR_TYPES$1.has(node.type);
|
|
301
|
+
let dataType = `Partial<${typeName}>`;
|
|
302
|
+
if (isArray || isTuple || node.type === "union" || node.type === "enum") dataType = typeName;
|
|
303
|
+
if (isScalar) dataType = getScalarType(node, typeName);
|
|
304
|
+
let returnType = canOverride ? typeName : void 0;
|
|
305
|
+
if (isScalar) returnType = getScalarType(node, typeName);
|
|
306
|
+
return {
|
|
307
|
+
dataType,
|
|
308
|
+
returnType,
|
|
309
|
+
usesTypeName: dataType.includes(typeName) || Boolean(returnType?.includes(typeName))
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/components/Faker.tsx
|
|
314
|
+
const OBJECT_TYPES = new Set(["object", "intersection"]);
|
|
315
|
+
const ARRAY_TYPES = new Set(["array"]);
|
|
316
|
+
const SCALAR_TYPES = new Set([
|
|
317
|
+
"string",
|
|
318
|
+
"email",
|
|
319
|
+
"url",
|
|
320
|
+
"uuid",
|
|
321
|
+
"number",
|
|
322
|
+
"integer",
|
|
323
|
+
"bigint",
|
|
324
|
+
"boolean",
|
|
325
|
+
"date",
|
|
326
|
+
"time",
|
|
327
|
+
"datetime",
|
|
328
|
+
"blob",
|
|
329
|
+
"enum"
|
|
330
|
+
]);
|
|
331
|
+
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
332
|
+
function Faker({ node, description, name, typeName, printer, seed, canOverride }) {
|
|
333
|
+
const fakerText = printer.print(node) ?? "undefined";
|
|
334
|
+
const isArray = ARRAY_TYPES.has(node.type);
|
|
335
|
+
const isObject = OBJECT_TYPES.has(node.type);
|
|
336
|
+
const isTuple = node.type === "tuple";
|
|
337
|
+
const isScalar = SCALAR_TYPES.has(node.type);
|
|
338
|
+
let fakerTextWithOverride = fakerText;
|
|
339
|
+
let useGenericOverride = false;
|
|
340
|
+
if (canOverride && isObject) useGenericOverride = true;
|
|
341
|
+
if (canOverride && isTuple) fakerTextWithOverride = `data || ${fakerText}`;
|
|
342
|
+
if (canOverride && isArray) fakerTextWithOverride = `[
|
|
343
|
+
...${fakerText},
|
|
344
|
+
...(data || [])
|
|
345
|
+
]`;
|
|
346
|
+
if (canOverride && isScalar) fakerTextWithOverride = `data ?? ${fakerText}`;
|
|
347
|
+
const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);
|
|
348
|
+
let functionSignature = "";
|
|
349
|
+
let functionBody = "";
|
|
350
|
+
if (useGenericOverride) {
|
|
351
|
+
functionSignature = `${description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : ""}export function ${name}(data?: Partial<${typeName}>): Required<${typeName}>`;
|
|
352
|
+
const seedCode = seed ? `faker.seed(${JSON.stringify(seed)})\n ` : "";
|
|
353
|
+
const { cyclicSchemas, schemaName } = printer.options;
|
|
354
|
+
if (node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => _kubb_core.ast.containsCircularRef(p.schema, {
|
|
355
|
+
circularSchemas: cyclicSchemas,
|
|
356
|
+
excludeName: schemaName
|
|
357
|
+
}))) functionBody = `{
|
|
358
|
+
${seedCode}const defaultFakeData = ${fakerText}
|
|
359
|
+
if (data) {
|
|
360
|
+
for (const [key, value] of Object.entries(data)) {
|
|
361
|
+
Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return defaultFakeData as Required<${typeName}>
|
|
365
|
+
}`;
|
|
366
|
+
else functionBody = `{
|
|
367
|
+
${seedCode}const defaultFakeData = ${fakerText}
|
|
368
|
+
return {
|
|
369
|
+
...defaultFakeData,
|
|
370
|
+
...(data || {}),
|
|
371
|
+
} as Required<${typeName}>
|
|
372
|
+
}`;
|
|
373
|
+
} else {
|
|
374
|
+
const dataParamName = /\bdata\b/.test(fakerTextWithOverride) ? "data" : "_data";
|
|
375
|
+
const params = _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
376
|
+
name: dataParamName,
|
|
377
|
+
type: _kubb_core.ast.createParamsType({
|
|
378
|
+
variant: "reference",
|
|
379
|
+
name: dataType
|
|
380
|
+
}),
|
|
381
|
+
optional: true
|
|
382
|
+
})] });
|
|
383
|
+
const paramsSignature = declarationPrinter.print(params) ?? "";
|
|
384
|
+
const returnType = resolvedReturnType;
|
|
385
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
386
|
+
name,
|
|
387
|
+
isExportable: true,
|
|
388
|
+
isIndexable: true,
|
|
389
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.Function, {
|
|
390
|
+
export: true,
|
|
391
|
+
name,
|
|
392
|
+
JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
|
|
393
|
+
params: canOverride ? paramsSignature : void 0,
|
|
394
|
+
returnType,
|
|
395
|
+
children: [seed ? /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [`faker.seed(${JSON.stringify(seed)})`, /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {})] }) : void 0, `return ${fakerTextWithOverride}`]
|
|
396
|
+
})
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File.Source, {
|
|
400
|
+
name,
|
|
401
|
+
isExportable: true,
|
|
402
|
+
isIndexable: true,
|
|
403
|
+
children: [functionSignature, functionBody]
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
Object.defineProperty(exports, "Faker", {
|
|
408
|
+
enumerable: true,
|
|
409
|
+
get: function() {
|
|
410
|
+
return Faker;
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
Object.defineProperty(exports, "__name", {
|
|
414
|
+
enumerable: true,
|
|
415
|
+
get: function() {
|
|
416
|
+
return __name;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
Object.defineProperty(exports, "__toESM", {
|
|
420
|
+
enumerable: true,
|
|
421
|
+
get: function() {
|
|
422
|
+
return __toESM;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
Object.defineProperty(exports, "aliasConflictingImports", {
|
|
426
|
+
enumerable: true,
|
|
427
|
+
get: function() {
|
|
428
|
+
return aliasConflictingImports;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
Object.defineProperty(exports, "buildResponseUnionSchema", {
|
|
432
|
+
enumerable: true,
|
|
433
|
+
get: function() {
|
|
434
|
+
return buildResponseUnionSchema;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
Object.defineProperty(exports, "canOverrideSchema", {
|
|
438
|
+
enumerable: true,
|
|
439
|
+
get: function() {
|
|
440
|
+
return canOverrideSchema;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
Object.defineProperty(exports, "filterUsedImports", {
|
|
444
|
+
enumerable: true,
|
|
445
|
+
get: function() {
|
|
446
|
+
return filterUsedImports;
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
Object.defineProperty(exports, "localeToFakerImport", {
|
|
450
|
+
enumerable: true,
|
|
451
|
+
get: function() {
|
|
452
|
+
return localeToFakerImport;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
Object.defineProperty(exports, "resolveParamNameByLocation", {
|
|
456
|
+
enumerable: true,
|
|
457
|
+
get: function() {
|
|
458
|
+
return resolveParamNameByLocation;
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
Object.defineProperty(exports, "resolveSchemaRef", {
|
|
462
|
+
enumerable: true,
|
|
463
|
+
get: function() {
|
|
464
|
+
return resolveSchemaRef;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
Object.defineProperty(exports, "resolveTypeReference", {
|
|
468
|
+
enumerable: true,
|
|
469
|
+
get: function() {
|
|
470
|
+
return resolveTypeReference;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(exports, "rewriteAliasedImports", {
|
|
474
|
+
enumerable: true,
|
|
475
|
+
get: function() {
|
|
476
|
+
return rewriteAliasedImports;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
Object.defineProperty(exports, "trimQuotes", {
|
|
480
|
+
enumerable: true,
|
|
481
|
+
get: function() {
|
|
482
|
+
return trimQuotes;
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
//# sourceMappingURL=Faker-BgleOzVN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Faker-BgleOzVN.cjs","names":["ast","SCALAR_TYPES","ARRAY_TYPES","posix","ast","File","Function"],"sources":["../../../internals/utils/src/string.ts","../src/utils.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 *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\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 * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","import { posix } from 'node:path'\nimport { ast } from '@kubb/core'\nimport type { ResolverFaker } from './types.ts'\n\n/**\n * Returns the `@faker-js/faker` named export for a locale code.\n *\n * Without a locale, returns `'faker'` for the default English instance.\n * With a locale, the language code is converted to upper case and joined with any region suffix.\n *\n * @example Default\n * `localeToFakerImport() // 'faker'`\n *\n * @example Simple locale\n * `localeToFakerImport('de') // 'fakerDE'`\n *\n * @example Compound locale\n * `localeToFakerImport('de_AT') // 'fakerDE_AT'`\n */\nexport function localeToFakerImport(locale?: string): string {\n if (!locale) {\n return 'faker'\n }\n\n const parts = locale.split('_')\n parts[0] = parts[0]!.toUpperCase()\n return `faker${parts.join('_')}`\n}\n\n/**\n * Determines if a schema node can be overridden during faker generation.\n */\nexport function canOverrideSchema(node: ast.SchemaNode): boolean {\n return new Set<ast.SchemaNode['type']>([\n 'array',\n 'tuple',\n 'object',\n 'intersection',\n 'union',\n 'enum',\n 'ref',\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n ]).has(node.type)\n}\n\n/**\n * Resolves a schema reference by looking up the referenced schema in the provided array.\n * Returns the original node if it's not a reference.\n */\nexport function resolveSchemaRef(node: ast.SchemaNode, schemas: Array<ast.SchemaNode>): ast.SchemaNode {\n if (node.type !== 'ref') {\n return node\n }\n\n return schemas.find((schema) => schema.name === node.name && schema.type !== 'ref') ?? node\n}\n\n/**\n * Resolves a parameter name based on its location (path, query, header, etc.) using the provided resolver.\n */\nexport function resolveParamNameByLocation(\n resolver: Pick<ResolverFaker, 'resolvePathParamsName' | 'resolveQueryParamsName' | 'resolveHeaderParamsName' | 'resolveParamName'>,\n node: ast.OperationNode,\n param: ast.ParameterNode,\n): string {\n switch (param.in) {\n case 'path':\n return resolver.resolvePathParamsName(node, param)\n case 'query':\n return resolver.resolveQueryParamsName(node, param)\n case 'header':\n return resolver.resolveHeaderParamsName(node, param)\n default:\n return resolver.resolveParamName(node, param)\n }\n}\n\nfunction shouldInlineSingleResponseSchema(schema: ast.SchemaNode): boolean {\n return new Set<ast.SchemaNode['type']>([\n 'any',\n 'unknown',\n 'void',\n 'null',\n 'array',\n 'tuple',\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n 'union',\n ]).has(schema.type)\n}\n\n/**\n * Builds a response schema as a union of all response statuses.\n * Returns null if no responses are provided, or embeds single simple responses inline.\n */\nexport function buildResponseUnionSchema(node: ast.OperationNode, resolver: ResolverFaker): ast.SchemaNode | null {\n const responses = node.responses.filter((response) => response.schema)\n\n if (!responses.length) {\n return null\n }\n\n if (responses.length === 1) {\n if (shouldInlineSingleResponseSchema(responses[0]!.schema)) {\n return responses[0]!.schema\n }\n\n return ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, responses[0]!.statusCode) })\n }\n\n return ast.createSchema({\n type: 'union',\n members: responses.map((response) => ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, response.statusCode) })),\n })\n}\n\n/**\n * Import name that can be a string or a renamed import object.\n */\nexport type ImportName = string | { propertyName: string; name?: string }\n\n/**\n * Import entry containing module path and imported names.\n */\nexport type ImportEntry = {\n name: string | Array<ImportName>\n path: string\n}\n\nconst SCALAR_TYPES = new Set<ast.SchemaNode['type']>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst ARRAY_TYPES = new Set<ast.SchemaNode['type']>(['array'])\n\nfunction toRelativeImportPath(from: string, to: string): string {\n const relativePath = posix.relative(posix.dirname(from), to)\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Filters imports to only those that are actually used in the generated code.\n * Checks for function calls matching the imported names.\n */\nexport function filterUsedImports(imports: Array<ImportEntry>, text: string, skipImportNames: Array<string> = []): Array<ImportEntry> {\n return imports.filter((entry) => {\n const names = (Array.isArray(entry.name) ? entry.name : [entry.name])\n .map((name) => {\n if (typeof name === 'string') {\n return name\n }\n\n return name?.name ?? name?.propertyName\n })\n .filter((name): name is string => Boolean(name))\n\n return names.some((name) => {\n if (skipImportNames.includes(name)) {\n return false\n }\n\n return new RegExp(`\\\\b${escapeRegExp(name)}\\\\b(?=\\\\s*\\\\()`).test(text)\n })\n })\n}\n\n/**\n * Detects and resolves import name conflicts by adding aliases to conflicting names.\n * Returns updated imports with a mapping of original names to their aliases.\n */\nexport function aliasConflictingImports(\n imports: Array<ImportEntry>,\n reservedNames: Iterable<string>,\n): { imports: Array<ImportEntry>; aliases: Map<string, string> } {\n const reservedNameSet = new Set(reservedNames)\n const aliases = new Map<string, string>()\n\n const aliasedImports = imports.map((entry) => {\n const names = Array.isArray(entry.name) ? entry.name : [entry.name]\n const aliasedNames = names.map((item): ImportName => {\n if (typeof item !== 'string' || !reservedNameSet.has(item)) {\n return item\n }\n\n const alias = `${item}Schema`\n aliases.set(item, alias)\n\n return { propertyName: item, name: alias }\n })\n\n return aliasedNames.some((item) => typeof item === 'object' && item.name)\n ? {\n ...entry,\n name: aliasedNames,\n }\n : entry\n })\n\n return {\n imports: aliasedImports,\n aliases,\n }\n}\n\n/**\n * Replaces all occurrences of original names with their aliased versions in the given text.\n */\nexport function rewriteAliasedImports(text: string, aliases: ReadonlyMap<string, string>): string {\n return Array.from(aliases).reduce((acc, [name, alias]) => acc.replace(new RegExp(`\\\\b${escapeRegExp(name)}\\\\b`, 'g'), alias), text)\n}\n\n/**\n * Resolves a type reference, determining if it needs an import statement or inline type reference.\n * Takes into account whether the type can be overridden and the file paths.\n */\nexport function resolveTypeReference({\n node,\n canOverride,\n name,\n typeName,\n filePath,\n typeFilePath,\n}: {\n node: ast.SchemaNode\n canOverride: boolean\n name: string\n typeName: string\n filePath: string\n typeFilePath: string\n}): { importPath?: string; typeName: string } {\n const { usesTypeName } = resolveFakerTypeUsage(node, typeName, canOverride)\n\n if (!usesTypeName) {\n return { typeName }\n }\n\n if (name === typeName) {\n return {\n typeName: `import('${toRelativeImportPath(filePath, typeFilePath)}').${typeName}`,\n }\n }\n\n return {\n importPath: typeFilePath,\n typeName,\n }\n}\n\n/**\n * Maps a schema node type to its corresponding scalar type representation.\n * Returns the type name for enums or the base type (string, number, etc.) for primitives.\n */\nexport function getScalarType(node: ast.SchemaNode, typeName: string): string {\n switch (node.type) {\n case 'string':\n case 'email':\n case 'url':\n case 'uuid':\n return 'string'\n case 'number':\n case 'integer':\n return 'number'\n case 'bigint':\n return 'bigint'\n case 'boolean':\n return 'boolean'\n case 'date':\n case 'time':\n return node.representation === 'date' ? 'Date' : 'string'\n case 'datetime':\n return 'string'\n case 'blob':\n return 'Blob'\n case 'enum':\n return typeName\n default:\n return typeName\n }\n}\n\n/**\n * Resolves faker type usage information for a schema.\n * Determines the data type, return type, and whether it uses the type name.\n */\nexport function resolveFakerTypeUsage(\n node: ast.SchemaNode,\n typeName: string,\n canOverride: boolean,\n): {\n dataType: string\n returnType: string | undefined\n usesTypeName: boolean\n} {\n const isArray = ARRAY_TYPES.has(node.type)\n const isTuple = node.type === 'tuple'\n const isScalar = SCALAR_TYPES.has(node.type)\n\n let dataType = `Partial<${typeName}>`\n\n if (isArray || isTuple || node.type === 'union' || node.type === 'enum') {\n dataType = typeName\n }\n\n if (isScalar) {\n dataType = getScalarType(node, typeName)\n }\n\n let returnType = canOverride ? typeName : undefined\n\n if (isScalar) {\n returnType = getScalarType(node, typeName)\n }\n\n return {\n dataType,\n returnType,\n usesTypeName: dataType.includes(typeName) || Boolean(returnType?.includes(typeName)),\n }\n}\n","import { jsStringEscape } from '@internals/utils'\nimport { ast } from '@kubb/core'\nimport { functionPrinter } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx/types'\nimport type { PrinterFakerFactory } from '../printers/printerFaker.ts'\nimport type { PluginFaker } from '../types.ts'\nimport { resolveFakerTypeUsage } from '../utils.ts'\n\ntype Props = {\n name: string\n typeName: string\n node: ast.SchemaNode\n printer: ast.Printer<PrinterFakerFactory>\n seed?: PluginFaker['options']['seed']\n description?: string\n canOverride: boolean\n}\n\nconst OBJECT_TYPES = new Set<ast.SchemaNode['type']>(['object', 'intersection'])\nconst ARRAY_TYPES = new Set<ast.SchemaNode['type']>(['array'])\nconst SCALAR_TYPES = new Set<ast.SchemaNode['type']>([\n 'string',\n 'email',\n 'url',\n 'uuid',\n 'number',\n 'integer',\n 'bigint',\n 'boolean',\n 'date',\n 'time',\n 'datetime',\n 'blob',\n 'enum',\n])\nconst declarationPrinter = functionPrinter({ mode: 'declaration' })\n\nexport function Faker({ node, description, name, typeName, printer, seed, canOverride }: Props): KubbReactNode {\n const fakerText = printer.print(node) ?? 'undefined'\n\n const isArray = ARRAY_TYPES.has(node.type)\n const isObject = OBJECT_TYPES.has(node.type)\n const isTuple = node.type === 'tuple'\n const isScalar = SCALAR_TYPES.has(node.type)\n\n let fakerTextWithOverride = fakerText\n let useGenericOverride = false\n\n if (canOverride && isObject) {\n useGenericOverride = true\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 && isScalar) {\n fakerTextWithOverride = `data ?? ${fakerText}`\n }\n\n const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride)\n\n let functionSignature = ''\n let functionBody = ''\n\n if (useGenericOverride) {\n // Generate function with defaultFakeData structure\n const jsdoc = description ? `/**\\n * @description ${jsStringEscape(description)}\\n */\\n ` : ''\n functionSignature = `${jsdoc}export function ${name}(data?: Partial<${typeName}>): Required<${typeName}>`\n\n const seedCode = seed ? `faker.seed(${JSON.stringify(seed)})\\n ` : ''\n\n // When the object node has properties that transitively reference a cyclic schema,\n // the printer emits memoizing getters for those properties. Spreading the object\n // literal would immediately invoke those getters, triggering recursive faker calls\n // and causing a stack overflow. Detect this upfront via ast helpers so we can\n // use Object.defineProperty-based merging instead of spread.\n const { cyclicSchemas, schemaName } = printer.options\n const hasGetters =\n node.type === 'object' &&\n !!cyclicSchemas &&\n (node.properties ?? []).some((p) => ast.containsCircularRef(p.schema, { circularSchemas: cyclicSchemas, excludeName: schemaName }))\n\n if (hasGetters) {\n functionBody = `{\n ${seedCode}const defaultFakeData = ${fakerText}\n if (data) {\n for (const [key, value] of Object.entries(data)) {\n Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })\n }\n }\n return defaultFakeData as Required<${typeName}>\n}`\n } else {\n functionBody = `{\n ${seedCode}const defaultFakeData = ${fakerText}\n return {\n ...defaultFakeData,\n ...(data || {}),\n } as Required<${typeName}>\n}`\n }\n } else {\n const usesData = /\\bdata\\b/.test(fakerTextWithOverride)\n const dataParamName = usesData ? 'data' : '_data'\n const params = ast.createFunctionParameters({\n params: [\n ast.createFunctionParameter({\n name: dataParamName,\n type: ast.createParamsType({ variant: 'reference', name: dataType }),\n optional: true,\n }),\n ],\n })\n const paramsSignature = declarationPrinter.print(params) ?? ''\n const returnType = resolvedReturnType\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n export\n name={name}\n JSDoc={{ comments: description ? [`@description ${jsStringEscape(description)}`] : [] }}\n params={canOverride ? paramsSignature : undefined}\n returnType={returnType}\n >\n {seed ? (\n <>\n {`faker.seed(${JSON.stringify(seed)})`}\n <br />\n </>\n ) : undefined}\n {`return ${fakerTextWithOverride}`}\n </Function>\n </File.Source>\n )\n }\n\n return (\n <File.Source name={name} isExportable isIndexable>\n {functionSignature}\n {functionBody}\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;;;;;;;;;;;;;AAcT,SAAgB,eAAe,OAAwB;AACrD,QAAO,GAAG,QAAQ,QAAQ,4BAA4B,c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A;GAAa,aAAA;aACpC,iBAAA,GAAA,+BAAA,MAACC,mBAAAA,UAAD;IACE,QAAA;IACM;IACN,OAAO,EAAE,UAAU,cAAc,CAAC,gBAAgB,eAAe,YAAY,GAAG,GAAG,EAAE,EAAE;IACvF,QAAQ,cAAc,kBAAkB,KAAA;IAC5B;cALd,CAOG,OACC,iBAAA,GAAA,+BAAA,MAAA,+BAAA,UAAA,EAAA,UAAA,CACG,cAAc,KAAK,UAAU,KAAK,CAAC,IACpC,iBAAA,GAAA,+BAAA,KAAC,MAAD,EAAM,CAAA,CACL,EAAA,CAAA,GACD,KAAA,GACH,UAAU,wBACF;;GACC,CAAA;;AAIlB,QACE,iBAAA,GAAA,+BAAA,MAACD,mBAAAA,KAAK,QAAN;EAAmB;EAAM,cAAA;EAAa,aAAA;YAAtC,CACG,mBACA,aACW"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { o as PluginFaker, t as PrinterFakerFactory } from "./printerFaker-CJiwzoto.js";
|
|
3
|
+
import { ast } from "@kubb/core";
|
|
4
|
+
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
5
|
+
|
|
6
|
+
//#region src/components/Faker.d.ts
|
|
7
|
+
type Props = {
|
|
8
|
+
name: string;
|
|
9
|
+
typeName: string;
|
|
10
|
+
node: ast.SchemaNode;
|
|
11
|
+
printer: ast.Printer<PrinterFakerFactory>;
|
|
12
|
+
seed?: PluginFaker['options']['seed'];
|
|
13
|
+
description?: string;
|
|
14
|
+
canOverride: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare function Faker({
|
|
17
|
+
node,
|
|
18
|
+
description,
|
|
19
|
+
name,
|
|
20
|
+
typeName,
|
|
21
|
+
printer,
|
|
22
|
+
seed,
|
|
23
|
+
canOverride
|
|
24
|
+
}: Props): KubbReactNode;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Faker as t };
|
|
27
|
+
//# sourceMappingURL=Faker-CdyPfOPg.d.ts.map
|