@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.cjs
CHANGED
|
@@ -536,11 +536,8 @@ function getScalarType(node, typeName) {
|
|
|
536
536
|
* Determines the data type, return type, and whether it uses the type name.
|
|
537
537
|
*/
|
|
538
538
|
function resolveFakerTypeUsage(node, typeName, canOverride) {
|
|
539
|
-
const isArray = node.type === "array";
|
|
540
|
-
const isTuple = node.type === "tuple";
|
|
541
539
|
const isScalar = SCALAR_TYPES$1.has(node.type);
|
|
542
540
|
let dataType = `Partial<${typeName}>`;
|
|
543
|
-
if (isArray || isTuple || node.type === "union" || node.type === "enum") dataType = typeName;
|
|
544
541
|
if (isScalar) dataType = getScalarType(node, typeName);
|
|
545
542
|
let returnType = canOverride ? typeName : null;
|
|
546
543
|
if (isScalar) returnType = getScalarType(node, typeName);
|
|
@@ -575,11 +572,12 @@ function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
|
575
572
|
const isObject = OBJECT_TYPES.has(node.type);
|
|
576
573
|
const isTuple = node.type === "tuple";
|
|
577
574
|
const isScalar = SCALAR_TYPES.has(node.type);
|
|
575
|
+
const isUnion = node.type === "union";
|
|
578
576
|
const useGenericOverride = canOverride && isObject;
|
|
579
577
|
const fakerTextWithOverride = (() => {
|
|
580
|
-
if (canOverride &&
|
|
581
|
-
if (canOverride && isArray) return `[\n ...${fakerText},\n ...(data || [])
|
|
582
|
-
if (canOverride && isScalar) return `data ?? ${fakerText}`;
|
|
578
|
+
if (canOverride && node.type === "tuple") return `data && data.length === ${node.items?.length ?? 0} && !data.includes(undefined) ? data : ${fakerText}`;
|
|
579
|
+
if (canOverride && isArray) return `[\n ...${fakerText},\n ...(data || []).filter((item) => item !== undefined),\n]`;
|
|
580
|
+
if (canOverride && (isScalar || isUnion)) return `data ?? ${fakerText}`;
|
|
583
581
|
return fakerText;
|
|
584
582
|
})();
|
|
585
583
|
const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);
|
|
@@ -592,7 +590,7 @@ function Faker({ node, description, name, typeName, printer, canOverride }) {
|
|
|
592
590
|
})] });
|
|
593
591
|
const paramsSignature = declarationPrinter.print(params) ?? "";
|
|
594
592
|
const returnType = resolvedReturnType;
|
|
595
|
-
const returnExpression = node.type === "ref"
|
|
593
|
+
const returnExpression = canOverride && !!returnType && (node.type === "ref" || isArray || isTuple || isUnion) ? `${isTuple || isUnion ? `(${fakerTextWithOverride})` : fakerTextWithOverride} as ${returnType}` : fakerTextWithOverride;
|
|
596
594
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
597
595
|
name,
|
|
598
596
|
isExportable: true,
|