prisma-guard 1.26.2 → 1.27.0
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/README.md +44 -1
- package/dist/runtime/index.cjs +67 -5
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +67 -5
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.js
CHANGED
|
@@ -959,6 +959,60 @@ var EMPTY_WHERE_FORCED = {
|
|
|
959
959
|
function hasWhereForced(f) {
|
|
960
960
|
return Object.keys(f.conditions).length > 0 || Object.keys(f.relations).length > 0;
|
|
961
961
|
}
|
|
962
|
+
function forcedScalarsEqual(a, b) {
|
|
963
|
+
if (a === b)
|
|
964
|
+
return true;
|
|
965
|
+
if (a === null || b === null)
|
|
966
|
+
return false;
|
|
967
|
+
if (typeof a !== typeof b)
|
|
968
|
+
return false;
|
|
969
|
+
if (a instanceof Date && b instanceof Date) {
|
|
970
|
+
return a.getTime() === b.getTime();
|
|
971
|
+
}
|
|
972
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
973
|
+
return a.source === b.source && a.flags === b.flags;
|
|
974
|
+
}
|
|
975
|
+
if (Array.isArray(a)) {
|
|
976
|
+
if (!Array.isArray(b))
|
|
977
|
+
return false;
|
|
978
|
+
if (a.length !== b.length)
|
|
979
|
+
return false;
|
|
980
|
+
return a.every((v, i) => forcedScalarsEqual(v, b[i]));
|
|
981
|
+
}
|
|
982
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
983
|
+
const aKeys = Object.keys(a);
|
|
984
|
+
const bKeys = Object.keys(b);
|
|
985
|
+
if (aKeys.length !== bKeys.length)
|
|
986
|
+
return false;
|
|
987
|
+
return aKeys.every(
|
|
988
|
+
(k) => k in b && forcedScalarsEqual(a[k], b[k])
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
function tryInlineForcedField(result, field, forcedValue) {
|
|
994
|
+
if (!(field in result))
|
|
995
|
+
return false;
|
|
996
|
+
if (!isPlainObject(forcedValue))
|
|
997
|
+
return false;
|
|
998
|
+
const existing = result[field];
|
|
999
|
+
if (!isPlainObject(existing))
|
|
1000
|
+
return false;
|
|
1001
|
+
const merged = { ...existing };
|
|
1002
|
+
for (const [op, value] of Object.entries(forcedValue)) {
|
|
1003
|
+
if (op in merged) {
|
|
1004
|
+
if (!forcedScalarsEqual(merged[op], value)) {
|
|
1005
|
+
throw new ShapeError(
|
|
1006
|
+
`Conflicting where values for "${field}.${op}": client provided a different value than the forced shape`
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
merged[op] = deepClone(value);
|
|
1012
|
+
}
|
|
1013
|
+
result[field] = merged;
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
962
1016
|
function mergeWhereForced(where, forced) {
|
|
963
1017
|
if (!hasWhereForced(forced))
|
|
964
1018
|
return where ?? {};
|
|
@@ -976,11 +1030,19 @@ function mergeWhereForced(where, forced) {
|
|
|
976
1030
|
}
|
|
977
1031
|
}
|
|
978
1032
|
if (Object.keys(forced.conditions).length > 0) {
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1033
|
+
const remaining = {};
|
|
1034
|
+
for (const [field, forcedValue] of Object.entries(forced.conditions)) {
|
|
1035
|
+
const inlined = tryInlineForcedField(result, field, forcedValue);
|
|
1036
|
+
if (!inlined) {
|
|
1037
|
+
remaining[field] = deepClone(forcedValue);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (Object.keys(remaining).length > 0) {
|
|
1041
|
+
if (Object.keys(result).length === 0) {
|
|
1042
|
+
result = remaining;
|
|
1043
|
+
} else {
|
|
1044
|
+
result = { AND: [result, remaining] };
|
|
1045
|
+
}
|
|
984
1046
|
}
|
|
985
1047
|
}
|
|
986
1048
|
return result;
|