prisma-guard 1.17.0 → 1.18.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/runtime/index.js
CHANGED
|
@@ -1087,6 +1087,10 @@ function collectEqualityFields(where, model, typeMap) {
|
|
|
1087
1087
|
continue;
|
|
1088
1088
|
if (typeMap && model && typeMap[model]?.[key]?.isRelation)
|
|
1089
1089
|
continue;
|
|
1090
|
+
if (value !== null && value !== void 0 && !isPlainObject(value) && !Array.isArray(value)) {
|
|
1091
|
+
fields.add(key);
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1090
1094
|
if (!value || !isPlainObject(value))
|
|
1091
1095
|
continue;
|
|
1092
1096
|
if (Object.keys(value).every((op) => op === "equals")) {
|
|
@@ -3763,6 +3767,17 @@ var PROJECTION_MUTATION_METHODS = /* @__PURE__ */ new Set([
|
|
|
3763
3767
|
"updateManyAndReturn"
|
|
3764
3768
|
]);
|
|
3765
3769
|
var BATCH_CREATE_METHODS = /* @__PURE__ */ new Set(["createMany", "createManyAndReturn"]);
|
|
3770
|
+
function normalizeUniqueWhere(where) {
|
|
3771
|
+
const result = {};
|
|
3772
|
+
for (const [key, value] of Object.entries(where)) {
|
|
3773
|
+
if (key !== "AND" && key !== "OR" && key !== "NOT" && isPlainObject(value) && "equals" in value && Object.keys(value).length === 1) {
|
|
3774
|
+
result[key] = value.equals;
|
|
3775
|
+
} else {
|
|
3776
|
+
result[key] = value;
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
return result;
|
|
3780
|
+
}
|
|
3766
3781
|
function buildDefaultSelectInput(config) {
|
|
3767
3782
|
const result = {};
|
|
3768
3783
|
for (const [key, value] of Object.entries(config)) {
|
|
@@ -4372,7 +4387,7 @@ function createModelGuardExtension(config) {
|
|
|
4372
4387
|
dataSchema,
|
|
4373
4388
|
method
|
|
4374
4389
|
);
|
|
4375
|
-
|
|
4390
|
+
let where = isUniqueWhere ? requireWhere(
|
|
4376
4391
|
resolved.shape,
|
|
4377
4392
|
resolved.body.where,
|
|
4378
4393
|
method,
|
|
@@ -4393,6 +4408,7 @@ function createModelGuardExtension(config) {
|
|
|
4393
4408
|
}
|
|
4394
4409
|
if (isUniqueWhere) {
|
|
4395
4410
|
validateResolvedUniqueWhere(modelName, where, method, uniqueMap);
|
|
4411
|
+
where = normalizeUniqueWhere(where);
|
|
4396
4412
|
}
|
|
4397
4413
|
const args = { data, where };
|
|
4398
4414
|
if (supportsProjection) {
|
|
@@ -4431,7 +4447,7 @@ function createModelGuardExtension(config) {
|
|
|
4431
4447
|
);
|
|
4432
4448
|
}
|
|
4433
4449
|
maybeValidateUniqueWhere(modelName, resolved.shape, method);
|
|
4434
|
-
|
|
4450
|
+
let where = isUniqueWhere ? requireWhere(
|
|
4435
4451
|
resolved.shape,
|
|
4436
4452
|
resolved.body.where,
|
|
4437
4453
|
method,
|
|
@@ -4452,6 +4468,7 @@ function createModelGuardExtension(config) {
|
|
|
4452
4468
|
}
|
|
4453
4469
|
if (isUniqueWhere) {
|
|
4454
4470
|
validateResolvedUniqueWhere(modelName, where, method, uniqueMap);
|
|
4471
|
+
where = normalizeUniqueWhere(where);
|
|
4455
4472
|
}
|
|
4456
4473
|
const args = { where };
|
|
4457
4474
|
if (supportsProjection) {
|
|
@@ -4536,7 +4553,7 @@ function createModelGuardExtension(config) {
|
|
|
4536
4553
|
);
|
|
4537
4554
|
validateResolvedUniqueWhere(modelName, where, "upsert", uniqueMap);
|
|
4538
4555
|
const args = {
|
|
4539
|
-
where,
|
|
4556
|
+
where: normalizeUniqueWhere(where),
|
|
4540
4557
|
create: createData,
|
|
4541
4558
|
update: updateData
|
|
4542
4559
|
};
|