prisma-mock 0.4.0 → 0.4.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/lib/index.js +14 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -96,9 +96,9 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
96
96
|
};
|
|
97
97
|
const getFieldRelationshipWhere = (item, field) => {
|
|
98
98
|
if (field.relationToFields.length === 0) {
|
|
99
|
-
|
|
99
|
+
const otherfield = getJoinField(field);
|
|
100
100
|
return {
|
|
101
|
-
[
|
|
101
|
+
[otherfield.relationFromFields[0]]: item[otherfield.relationToFields[0]],
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
return {
|
|
@@ -487,10 +487,12 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
487
487
|
return getCamelCase(model.name) === childName;
|
|
488
488
|
});
|
|
489
489
|
const delegate = Delegate(getCamelCase(childName), submodel);
|
|
490
|
-
const res = delegate.
|
|
490
|
+
const res = delegate._findMany({
|
|
491
491
|
where: {
|
|
492
|
-
|
|
493
|
-
|
|
492
|
+
AND: [
|
|
493
|
+
childWhere,
|
|
494
|
+
getFieldRelationshipWhere(item, info)
|
|
495
|
+
]
|
|
494
496
|
},
|
|
495
497
|
});
|
|
496
498
|
if (filter.every) {
|
|
@@ -596,7 +598,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
596
598
|
return true;
|
|
597
599
|
};
|
|
598
600
|
const matchAnd = (item, where) => {
|
|
599
|
-
return where.filter((child) => matchItems(item, child)).length
|
|
601
|
+
return where.filter((child) => matchItems(item, child)).length === where.length;
|
|
600
602
|
};
|
|
601
603
|
const matchOr = (item, where) => {
|
|
602
604
|
return where.some((child) => matchItems(item, child));
|
|
@@ -626,7 +628,9 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
626
628
|
return found;
|
|
627
629
|
};
|
|
628
630
|
const findMany = (args) => {
|
|
629
|
-
let res = data[prop]
|
|
631
|
+
let res = data[prop]
|
|
632
|
+
.filter(matchFnc(args?.where))
|
|
633
|
+
.map(includes(args));
|
|
630
634
|
if (args?.distinct) {
|
|
631
635
|
let values = {};
|
|
632
636
|
res = res.filter((item) => {
|
|
@@ -778,13 +782,13 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
778
782
|
// Add relation
|
|
779
783
|
newItem = {
|
|
780
784
|
...newItem,
|
|
781
|
-
[key]: delegate.
|
|
785
|
+
[key]: delegate._findMany(subArgs),
|
|
782
786
|
};
|
|
783
787
|
}
|
|
784
788
|
else {
|
|
785
789
|
newItem = {
|
|
786
790
|
...newItem,
|
|
787
|
-
[key]: delegate.
|
|
791
|
+
[key]: delegate._findMany(subArgs)?.[0] || null,
|
|
788
792
|
};
|
|
789
793
|
}
|
|
790
794
|
});
|
|
@@ -881,6 +885,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
881
885
|
return res.length;
|
|
882
886
|
},
|
|
883
887
|
_sortFunc: sortFunc,
|
|
888
|
+
_findMany: findMany
|
|
884
889
|
};
|
|
885
890
|
};
|
|
886
891
|
datamodel.models.forEach((model) => {
|