prisma-mock 0.8.0 → 0.8.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/lib/index.js +37 -34
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -38,7 +38,7 @@ function IsFieldDefault(f) {
|
|
|
38
38
|
}
|
|
39
39
|
const throwKnownError = (message, cause) => {
|
|
40
40
|
const code = "P2025";
|
|
41
|
-
const clientVersion =
|
|
41
|
+
const clientVersion = client_1.Prisma.prismaVersion.client;
|
|
42
42
|
// PrismaClientKnownRequestError prototype changed in version 4.7.0
|
|
43
43
|
// from: constructor(message: string, code: string, clientVersion: string, meta?: any)
|
|
44
44
|
// to: constructor(message: string, { code, clientVersion, meta, batchRequestIdx }: KnownErrorParams)
|
|
@@ -234,6 +234,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
234
234
|
const c = d[field.name];
|
|
235
235
|
if (field.kind === "object") {
|
|
236
236
|
if (c.set) {
|
|
237
|
+
const { [field.name]: { set }, ...rest } = d;
|
|
237
238
|
const otherModel = datamodel.models.find((model) => {
|
|
238
239
|
return model.name === field.type;
|
|
239
240
|
});
|
|
@@ -255,6 +256,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
255
256
|
});
|
|
256
257
|
});
|
|
257
258
|
manyToManyData[field.relationName] = a;
|
|
259
|
+
d = rest;
|
|
258
260
|
}
|
|
259
261
|
if (c.connect) {
|
|
260
262
|
const { [field.name]: { connect }, ...rest } = d;
|
|
@@ -464,36 +466,38 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
464
466
|
const { [field.name]: _update, ...rest } = d;
|
|
465
467
|
d = rest;
|
|
466
468
|
}
|
|
467
|
-
if (
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
469
|
+
if (field.kind === "scalar") {
|
|
470
|
+
if (c.increment) {
|
|
471
|
+
d = {
|
|
472
|
+
...d,
|
|
473
|
+
[field.name]: item[field.name] + c.increment,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
if (c.decrement) {
|
|
477
|
+
d = {
|
|
478
|
+
...d,
|
|
479
|
+
[field.name]: item[field.name] - c.decrement,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
if (c.multiply) {
|
|
483
|
+
d = {
|
|
484
|
+
...d,
|
|
485
|
+
[field.name]: item[field.name] * c.multiply,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (c.divide) {
|
|
489
|
+
const newValue = item[field.name] / c.divide;
|
|
490
|
+
d = {
|
|
491
|
+
...d,
|
|
492
|
+
[field.name]: field.type === "Int" ? Math.floor(newValue) : newValue,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
if (c.set) {
|
|
496
|
+
d = {
|
|
497
|
+
...d,
|
|
498
|
+
[field.name]: c.set,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
503
|
if ((isCreating || d[field.name] === null) &&
|
|
@@ -780,9 +784,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
780
784
|
const findOrThrow = (args) => {
|
|
781
785
|
const found = findOne(args);
|
|
782
786
|
if (!found) {
|
|
783
|
-
|
|
784
|
-
// @ts-ignore
|
|
785
|
-
"1.2.3");
|
|
787
|
+
throwKnownError(`No ${prop.slice(0, 1).toUpperCase()}${prop.slice(1)} found`);
|
|
786
788
|
}
|
|
787
789
|
return found;
|
|
788
790
|
};
|
|
@@ -1000,6 +1002,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
1000
1002
|
const newItems = data[prop].map((e) => {
|
|
1001
1003
|
if (matchFnc(args.where)(e)) {
|
|
1002
1004
|
let data = nestedUpdate(args, false, e);
|
|
1005
|
+
data; //?
|
|
1003
1006
|
updatedItem = {
|
|
1004
1007
|
...e,
|
|
1005
1008
|
...data,
|