@kubb/plugin-faker 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +13 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/package.json +16 -5
package/dist/index.d.ts
CHANGED
|
@@ -229,11 +229,10 @@ type Props = {
|
|
|
229
229
|
typeName: string;
|
|
230
230
|
node: ast.SchemaNode;
|
|
231
231
|
printer: ast.Printer<PrinterFakerFactory>;
|
|
232
|
-
seed?: PluginFaker['options']['seed'];
|
|
233
232
|
description?: string;
|
|
234
233
|
canOverride: boolean;
|
|
235
234
|
};
|
|
236
|
-
declare function Faker({ node, description, name, typeName, printer,
|
|
235
|
+
declare function Faker({ node, description, name, typeName, printer, canOverride }: Props): KubbReactNode;
|
|
237
236
|
//#endregion
|
|
238
237
|
//#region src/generators/fakerGenerator.d.ts
|
|
239
238
|
/**
|
package/dist/index.js
CHANGED
|
@@ -561,7 +561,7 @@ const SCALAR_TYPES = /* @__PURE__ */ new Set([
|
|
|
561
561
|
"enum"
|
|
562
562
|
]);
|
|
563
563
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
564
|
-
function Faker({ node, description, name, typeName, printer,
|
|
564
|
+
function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
565
565
|
const fakerText = printer.print(node) ?? "undefined";
|
|
566
566
|
const isArray = node.type === "array";
|
|
567
567
|
const isObject = OBJECT_TYPES.has(node.type);
|
|
@@ -589,24 +589,23 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
589
589
|
name,
|
|
590
590
|
isExportable: true,
|
|
591
591
|
isIndexable: true,
|
|
592
|
-
children: /* @__PURE__ */
|
|
592
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
593
593
|
export: true,
|
|
594
594
|
name,
|
|
595
595
|
JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
|
|
596
596
|
params: canOverride ? paramsSignature : void 0,
|
|
597
597
|
returnType: returnType ?? void 0,
|
|
598
|
-
children:
|
|
598
|
+
children: `return ${returnExpression}`
|
|
599
599
|
})
|
|
600
600
|
});
|
|
601
601
|
}
|
|
602
602
|
const functionSignature = `${description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : ""}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
|
|
603
|
-
const seedCode = seed ? `faker.seed(${JSON.stringify(seed)})\n ` : "";
|
|
604
603
|
const { cyclicSchemas, schemaName } = printer.options;
|
|
605
604
|
const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => containsCircularRef(p.schema, {
|
|
606
605
|
circularSchemas: cyclicSchemas,
|
|
607
606
|
excludeName: schemaName
|
|
608
607
|
})) ? `{
|
|
609
|
-
|
|
608
|
+
const defaultFakeData = ${fakerText}
|
|
610
609
|
if (data) {
|
|
611
610
|
for (const [key, value] of Object.entries(data)) {
|
|
612
611
|
Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
|
|
@@ -614,7 +613,7 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
614
613
|
}
|
|
615
614
|
return defaultFakeData as Omit<typeof defaultFakeData, keyof TData> & TData
|
|
616
615
|
}` : `{
|
|
617
|
-
|
|
616
|
+
const defaultFakeData = ${fakerText}
|
|
618
617
|
return {
|
|
619
618
|
...defaultFakeData,
|
|
620
619
|
...(data || {}),
|
|
@@ -1223,13 +1222,16 @@ const fakerGenerator = defineGenerator({
|
|
|
1223
1222
|
imp.path,
|
|
1224
1223
|
imp.name
|
|
1225
1224
|
].join("-"))),
|
|
1225
|
+
seed ? /* @__PURE__ */ jsx(File.Source, {
|
|
1226
|
+
name: "faker-seed",
|
|
1227
|
+
children: `faker.seed(${JSON.stringify(seed)})`
|
|
1228
|
+
}) : void 0,
|
|
1226
1229
|
/* @__PURE__ */ jsx(Faker, {
|
|
1227
1230
|
name: meta.name,
|
|
1228
1231
|
typeName: typeReference.typeName,
|
|
1229
1232
|
description: node.description,
|
|
1230
1233
|
node,
|
|
1231
1234
|
printer: printerInstance,
|
|
1232
|
-
seed,
|
|
1233
1235
|
canOverride
|
|
1234
1236
|
})
|
|
1235
1237
|
]
|
|
@@ -1386,7 +1388,6 @@ const fakerGenerator = defineGenerator({
|
|
|
1386
1388
|
...printerInstance,
|
|
1387
1389
|
print: () => rewrittenFakerText
|
|
1388
1390
|
},
|
|
1389
|
-
seed,
|
|
1390
1391
|
canOverride
|
|
1391
1392
|
})
|
|
1392
1393
|
] });
|
|
@@ -1427,6 +1428,10 @@ const fakerGenerator = defineGenerator({
|
|
|
1427
1428
|
path: dateParser,
|
|
1428
1429
|
name: dateParser
|
|
1429
1430
|
}),
|
|
1431
|
+
seed ? /* @__PURE__ */ jsx(File.Source, {
|
|
1432
|
+
name: "faker-seed",
|
|
1433
|
+
children: `faker.seed(${JSON.stringify(seed)})`
|
|
1434
|
+
}) : void 0,
|
|
1430
1435
|
paramGroups.map((group) => renderEntry(group)),
|
|
1431
1436
|
responseUnits.map((unit) => renderEntry({
|
|
1432
1437
|
schema: unit.schema,
|