@kubb/plugin-faker 5.0.6 → 5.0.7
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 +5 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -532,11 +532,8 @@ function getScalarType(node, typeName) {
|
|
|
532
532
|
* Determines the data type, return type, and whether it uses the type name.
|
|
533
533
|
*/
|
|
534
534
|
function resolveFakerTypeUsage(node, typeName, canOverride) {
|
|
535
|
-
const isArray = node.type === "array";
|
|
536
|
-
const isTuple = node.type === "tuple";
|
|
537
535
|
const isScalar = SCALAR_TYPES$1.has(node.type);
|
|
538
536
|
let dataType = `Partial<${typeName}>`;
|
|
539
|
-
if (isArray || isTuple || node.type === "union" || node.type === "enum") dataType = typeName;
|
|
540
537
|
if (isScalar) dataType = getScalarType(node, typeName);
|
|
541
538
|
let returnType = canOverride ? typeName : null;
|
|
542
539
|
if (isScalar) returnType = getScalarType(node, typeName);
|
|
@@ -571,11 +568,12 @@ function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
|
571
568
|
const isObject = OBJECT_TYPES.has(node.type);
|
|
572
569
|
const isTuple = node.type === "tuple";
|
|
573
570
|
const isScalar = SCALAR_TYPES.has(node.type);
|
|
571
|
+
const isUnion = node.type === "union";
|
|
574
572
|
const useGenericOverride = canOverride && isObject;
|
|
575
573
|
const fakerTextWithOverride = (() => {
|
|
576
|
-
if (canOverride &&
|
|
577
|
-
if (canOverride && isArray) return `[\n ...${fakerText},\n ...(data || [])
|
|
578
|
-
if (canOverride && isScalar) return `data ?? ${fakerText}`;
|
|
574
|
+
if (canOverride && node.type === "tuple") return `data && data.length === ${node.items?.length ?? 0} && !data.includes(undefined) ? data : ${fakerText}`;
|
|
575
|
+
if (canOverride && isArray) return `[\n ...${fakerText},\n ...(data || []).filter((item) => item !== undefined),\n]`;
|
|
576
|
+
if (canOverride && (isScalar || isUnion)) return `data ?? ${fakerText}`;
|
|
579
577
|
return fakerText;
|
|
580
578
|
})();
|
|
581
579
|
const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);
|
|
@@ -588,7 +586,7 @@ function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
|
588
586
|
})] });
|
|
589
587
|
const paramsSignature = declarationPrinter.print(params) ?? "";
|
|
590
588
|
const returnType = resolvedReturnType;
|
|
591
|
-
const returnExpression = node.type === "ref"
|
|
589
|
+
const returnExpression = canOverride && !!returnType && (node.type === "ref" || isArray || isTuple || isUnion) ? `${isTuple || isUnion ? `(${fakerTextWithOverride})` : fakerTextWithOverride} as ${returnType}` : fakerTextWithOverride;
|
|
592
590
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
593
591
|
name,
|
|
594
592
|
isExportable: true,
|