@kubb/plugin-faker 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/package.json +15 -4
package/dist/index.cjs
CHANGED
|
@@ -348,7 +348,7 @@ function filterUsedImports(imports, text, skipImportNames = []) {
|
|
|
348
348
|
return imports.filter((entry) => {
|
|
349
349
|
return getImportNames(entry).some((name) => {
|
|
350
350
|
if (skip.has(name)) return false;
|
|
351
|
-
return new RegExp(`\\b${escapeRegExp(name)}\\b(?=\\s
|
|
351
|
+
return new RegExp(`\\b${escapeRegExp(name)}\\b(?=\\s*[<(])`).test(text);
|
|
352
352
|
});
|
|
353
353
|
});
|
|
354
354
|
}
|
|
@@ -565,7 +565,7 @@ const SCALAR_TYPES = /* @__PURE__ */ new Set([
|
|
|
565
565
|
"enum"
|
|
566
566
|
]);
|
|
567
567
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
568
|
-
function Faker({ node, description, name, typeName, printer,
|
|
568
|
+
function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
569
569
|
const fakerText = printer.print(node) ?? "undefined";
|
|
570
570
|
const isArray = node.type === "array";
|
|
571
571
|
const isObject = OBJECT_TYPES.has(node.type);
|
|
@@ -593,24 +593,23 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
593
593
|
name,
|
|
594
594
|
isExportable: true,
|
|
595
595
|
isIndexable: true,
|
|
596
|
-
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.
|
|
596
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
597
597
|
export: true,
|
|
598
598
|
name,
|
|
599
599
|
JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
|
|
600
600
|
params: canOverride ? paramsSignature : void 0,
|
|
601
601
|
returnType: returnType ?? void 0,
|
|
602
|
-
children:
|
|
602
|
+
children: `return ${returnExpression}`
|
|
603
603
|
})
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
606
|
const functionSignature = `${description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : ""}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
|
|
607
|
-
const seedCode = seed ? `faker.seed(${JSON.stringify(seed)})\n ` : "";
|
|
608
607
|
const { cyclicSchemas, schemaName } = printer.options;
|
|
609
608
|
const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => (0, kubb_kit.containsCircularRef)(p.schema, {
|
|
610
609
|
circularSchemas: cyclicSchemas,
|
|
611
610
|
excludeName: schemaName
|
|
612
611
|
})) ? `{
|
|
613
|
-
|
|
612
|
+
const defaultFakeData = ${fakerText}
|
|
614
613
|
if (data) {
|
|
615
614
|
for (const [key, value] of Object.entries(data)) {
|
|
616
615
|
Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
|
|
@@ -618,7 +617,7 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
618
617
|
}
|
|
619
618
|
return defaultFakeData as Omit<typeof defaultFakeData, keyof TData> & TData
|
|
620
619
|
}` : `{
|
|
621
|
-
|
|
620
|
+
const defaultFakeData = ${fakerText}
|
|
622
621
|
return {
|
|
623
622
|
...defaultFakeData,
|
|
624
623
|
...(data || {}),
|
|
@@ -1046,7 +1045,7 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
|
|
|
1046
1045
|
if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
|
|
1047
1046
|
const resolvedName = node.ref ? this.options.resolver.name(refName) : refName;
|
|
1048
1047
|
if (!this.options.nestedInObject) return `${resolvedName}(data)`;
|
|
1049
|
-
return `${resolvedName}()`;
|
|
1048
|
+
return `${resolvedName}${this.options.nestedInUnion && (node.schema?.type === "object" || node.schema?.type === "intersection") ? "<object>" : ""}()`;
|
|
1050
1049
|
},
|
|
1051
1050
|
enum(node) {
|
|
1052
1051
|
return fakerKeywordMapper.enum(getEnumValues(node).map(parseEnumValue), this.options.typeName);
|
|
@@ -1227,13 +1226,16 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1227
1226
|
imp.path,
|
|
1228
1227
|
imp.name
|
|
1229
1228
|
].join("-"))),
|
|
1229
|
+
seed ? /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1230
|
+
name: "faker-seed",
|
|
1231
|
+
children: `faker.seed(${JSON.stringify(seed)})`
|
|
1232
|
+
}) : void 0,
|
|
1230
1233
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Faker, {
|
|
1231
1234
|
name: meta.name,
|
|
1232
1235
|
typeName: typeReference.typeName,
|
|
1233
1236
|
description: node.description,
|
|
1234
1237
|
node,
|
|
1235
1238
|
printer: printerInstance,
|
|
1236
|
-
seed,
|
|
1237
1239
|
canOverride
|
|
1238
1240
|
})
|
|
1239
1241
|
]
|
|
@@ -1390,7 +1392,6 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1390
1392
|
...printerInstance,
|
|
1391
1393
|
print: () => rewrittenFakerText
|
|
1392
1394
|
},
|
|
1393
|
-
seed,
|
|
1394
1395
|
canOverride
|
|
1395
1396
|
})
|
|
1396
1397
|
] });
|
|
@@ -1431,6 +1432,10 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1431
1432
|
path: dateParser,
|
|
1432
1433
|
name: dateParser
|
|
1433
1434
|
}),
|
|
1435
|
+
seed ? /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1436
|
+
name: "faker-seed",
|
|
1437
|
+
children: `faker.seed(${JSON.stringify(seed)})`
|
|
1438
|
+
}) : void 0,
|
|
1434
1439
|
paramGroups.map((group) => renderEntry(group)),
|
|
1435
1440
|
responseUnits.map((unit) => renderEntry({
|
|
1436
1441
|
schema: unit.schema,
|