prisma-guard 1.29.0 → 1.30.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/dist/runtime/index.cjs +36 -23
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +36 -23
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.cjs
CHANGED
|
@@ -307,6 +307,9 @@ function isPlainObject(v) {
|
|
|
307
307
|
const proto = Object.getPrototypeOf(v);
|
|
308
308
|
return proto === Object.prototype || proto === null;
|
|
309
309
|
}
|
|
310
|
+
function isObjectLike(v) {
|
|
311
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
312
|
+
}
|
|
310
313
|
function schemaProducesValueForUndefined(schema) {
|
|
311
314
|
const result = schema.safeParse(void 0);
|
|
312
315
|
return result.success && result.data !== void 0;
|
|
@@ -4880,12 +4883,23 @@ function walkForClientContent(obj, predicate, depth) {
|
|
|
4880
4883
|
const nested = value;
|
|
4881
4884
|
if (nested.orderBy || nested.cursor || nested.take || nested.skip)
|
|
4882
4885
|
return true;
|
|
4883
|
-
if (nested.where && isPlainObject(nested.where) && hasClientControlledValues(
|
|
4886
|
+
if (nested.where && isPlainObject(nested.where) && hasClientControlledValues(
|
|
4887
|
+
nested.where,
|
|
4888
|
+
depth + 1
|
|
4889
|
+
)) {
|
|
4884
4890
|
return true;
|
|
4885
4891
|
}
|
|
4886
|
-
if (nested.include && walkForClientContent(
|
|
4892
|
+
if (nested.include && walkForClientContent(
|
|
4893
|
+
nested.include,
|
|
4894
|
+
predicate,
|
|
4895
|
+
depth + 1
|
|
4896
|
+
))
|
|
4887
4897
|
return true;
|
|
4888
|
-
if (nested.select && walkForClientContent(
|
|
4898
|
+
if (nested.select && walkForClientContent(
|
|
4899
|
+
nested.select,
|
|
4900
|
+
predicate,
|
|
4901
|
+
depth + 1
|
|
4902
|
+
))
|
|
4889
4903
|
return true;
|
|
4890
4904
|
}
|
|
4891
4905
|
return false;
|
|
@@ -4907,11 +4921,19 @@ function hasClientControlledValues(obj, depth = 0) {
|
|
|
4907
4921
|
function hasNestedClientControlledArgs(shape) {
|
|
4908
4922
|
const predicate = () => false;
|
|
4909
4923
|
if (shape.include) {
|
|
4910
|
-
if (walkForClientContent(
|
|
4924
|
+
if (walkForClientContent(
|
|
4925
|
+
shape.include,
|
|
4926
|
+
predicate,
|
|
4927
|
+
0
|
|
4928
|
+
))
|
|
4911
4929
|
return true;
|
|
4912
4930
|
}
|
|
4913
4931
|
if (shape.select) {
|
|
4914
|
-
if (walkForClientContent(
|
|
4932
|
+
if (walkForClientContent(
|
|
4933
|
+
shape.select,
|
|
4934
|
+
predicate,
|
|
4935
|
+
0
|
|
4936
|
+
))
|
|
4915
4937
|
return true;
|
|
4916
4938
|
}
|
|
4917
4939
|
return false;
|
|
@@ -5209,15 +5231,13 @@ function createModelGuardExtension(config) {
|
|
|
5209
5231
|
let result = {};
|
|
5210
5232
|
if (built.schema) {
|
|
5211
5233
|
if (bodyWhere !== void 0 && bodyWhere !== null) {
|
|
5212
|
-
if (!
|
|
5234
|
+
if (!isObjectLike(bodyWhere)) {
|
|
5213
5235
|
throw new ShapeError(
|
|
5214
|
-
`Invalid "where" on model "${modelName}": unique where must be
|
|
5236
|
+
`Invalid "where" on model "${modelName}": unique where must be an object`
|
|
5215
5237
|
);
|
|
5216
5238
|
}
|
|
5217
|
-
const
|
|
5218
|
-
|
|
5219
|
-
built.forced
|
|
5220
|
-
) : { ...bodyWhere };
|
|
5239
|
+
const bodyWhereObj = { ...bodyWhere };
|
|
5240
|
+
const sanitized = hasWhereForced(built.forced) ? stripUniqueWhereForcedInput(bodyWhereObj, built.forced) : bodyWhereObj;
|
|
5221
5241
|
try {
|
|
5222
5242
|
result = built.schema.parse(sanitized);
|
|
5223
5243
|
} catch (err) {
|
|
@@ -5229,11 +5249,9 @@ function createModelGuardExtension(config) {
|
|
|
5229
5249
|
}
|
|
5230
5250
|
}
|
|
5231
5251
|
} else if (bodyWhere !== void 0 && bodyWhere !== null) {
|
|
5232
|
-
if (
|
|
5233
|
-
const
|
|
5234
|
-
|
|
5235
|
-
built.forced
|
|
5236
|
-
) : { ...bodyWhere };
|
|
5252
|
+
if (isObjectLike(bodyWhere)) {
|
|
5253
|
+
const bodyWhereObj = { ...bodyWhere };
|
|
5254
|
+
const sanitized = hasWhereForced(built.forced) ? stripUniqueWhereForcedInput(bodyWhereObj, built.forced) : bodyWhereObj;
|
|
5237
5255
|
if (Object.keys(sanitized).length > 0) {
|
|
5238
5256
|
throw new ShapeError(
|
|
5239
5257
|
`Unique where on model "${modelName}" contains only forced values. Client where input is not accepted.`
|
|
@@ -5241,7 +5259,7 @@ function createModelGuardExtension(config) {
|
|
|
5241
5259
|
}
|
|
5242
5260
|
} else {
|
|
5243
5261
|
throw new ShapeError(
|
|
5244
|
-
`Invalid "where" on model "${modelName}": unique where must be
|
|
5262
|
+
`Invalid "where" on model "${modelName}": unique where must be an object`
|
|
5245
5263
|
);
|
|
5246
5264
|
}
|
|
5247
5265
|
}
|
|
@@ -5594,12 +5612,7 @@ function createModelGuardExtension(config) {
|
|
|
5594
5612
|
"upsert",
|
|
5595
5613
|
"shape"
|
|
5596
5614
|
);
|
|
5597
|
-
validateAllowedKeys(
|
|
5598
|
-
resolved.body,
|
|
5599
|
-
allowedBodyKeys,
|
|
5600
|
-
"upsert",
|
|
5601
|
-
"body"
|
|
5602
|
-
);
|
|
5615
|
+
validateAllowedKeys(resolved.body, allowedBodyKeys, "upsert", "body");
|
|
5603
5616
|
validateUniqueWhereShapeConfig(
|
|
5604
5617
|
modelName,
|
|
5605
5618
|
resolved.shape.where,
|