prisma-guard 1.32.0 → 1.32.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.cjs +45 -19
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +45 -19
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.cjs
CHANGED
|
@@ -1517,12 +1517,15 @@ function applyForcedCountWhere(container, forcedCountWhere) {
|
|
|
1517
1517
|
}
|
|
1518
1518
|
function resolvedWhereCoversConstraint(where, constraint) {
|
|
1519
1519
|
if (constraint.fields.length === 1) {
|
|
1520
|
-
|
|
1520
|
+
const value2 = where[constraint.fields[0]];
|
|
1521
|
+
return value2 !== null && value2 !== void 0;
|
|
1521
1522
|
}
|
|
1522
1523
|
const value = where[constraint.selector];
|
|
1523
1524
|
if (!isPlainObject(value))
|
|
1524
1525
|
return false;
|
|
1525
|
-
return constraint.fields.every(
|
|
1526
|
+
return constraint.fields.every(
|
|
1527
|
+
(field) => value[field] !== null && value[field] !== void 0
|
|
1528
|
+
);
|
|
1526
1529
|
}
|
|
1527
1530
|
function validateResolvedUniqueWhere(model, where, method, uniqueMap) {
|
|
1528
1531
|
const constraints = uniqueMap[model];
|
|
@@ -1549,17 +1552,16 @@ function assertDirectUniqueShapeValue(model, field, value, typeMap) {
|
|
|
1549
1552
|
);
|
|
1550
1553
|
}
|
|
1551
1554
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
const keys = Object.keys(value);
|
|
1555
|
+
const actual = isForcedValue(value) ? value.value : value;
|
|
1556
|
+
if (isPlainObject(actual)) {
|
|
1557
|
+
const keys = Object.keys(actual);
|
|
1556
1558
|
throw new ShapeError(
|
|
1557
1559
|
`Invalid unique where shape for "${model ?? "unknown"}.${field}". Prisma WhereUniqueInput does not accept filter operator objects${keys.length ? `: ${keys.join(", ")}` : ""}. Use { ${field}: true } in guard shape and { ${field}: value } in request args.`
|
|
1558
1560
|
);
|
|
1559
1561
|
}
|
|
1560
|
-
if (
|
|
1562
|
+
if (actual === null || actual === void 0) {
|
|
1561
1563
|
throw new ShapeError(
|
|
1562
|
-
`Invalid unique where shape for "${model ?? "unknown"}.${field}". Unique fields must use true or a forced value.`
|
|
1564
|
+
`Invalid unique where shape for "${model ?? "unknown"}.${field}". Unique fields must use true or a forced non-null value.`
|
|
1563
1565
|
);
|
|
1564
1566
|
}
|
|
1565
1567
|
}
|
|
@@ -1573,9 +1575,8 @@ function shapeCoversConstraint(where, constraint, model, typeMap) {
|
|
|
1573
1575
|
}
|
|
1574
1576
|
if (!(constraint.selector in where))
|
|
1575
1577
|
return false;
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
return true;
|
|
1578
|
+
const rawSelectorValue = where[constraint.selector];
|
|
1579
|
+
const selectorValue = isForcedValue(rawSelectorValue) ? rawSelectorValue.value : rawSelectorValue;
|
|
1579
1580
|
if (!isPlainObject(selectorValue)) {
|
|
1580
1581
|
throw new ShapeError(
|
|
1581
1582
|
`Compound unique selector "${model}.${constraint.selector}" must be an object with fields: ${constraint.fields.join(", ")}`
|
|
@@ -2078,8 +2079,18 @@ function createWhereBuilder(typeMap, enumMap, scalarBase, uniqueMap = {}) {
|
|
|
2078
2079
|
(constraint) => constraint.selector === selector
|
|
2079
2080
|
) ?? null;
|
|
2080
2081
|
}
|
|
2081
|
-
function
|
|
2082
|
+
function buildUniqueWhereFieldSchema(fieldMeta, allowNullableFilter) {
|
|
2082
2083
|
const schema = buildDirectScalarSchema(fieldMeta, enumMap, scalarBase);
|
|
2084
|
+
if (allowNullableFilter && !fieldMeta.isRequired) {
|
|
2085
|
+
return schema.nullable();
|
|
2086
|
+
}
|
|
2087
|
+
return schema;
|
|
2088
|
+
}
|
|
2089
|
+
function parseForcedUniqueValue(model, fieldName, fieldMeta, value, allowNullableFilter) {
|
|
2090
|
+
const schema = buildUniqueWhereFieldSchema(
|
|
2091
|
+
fieldMeta,
|
|
2092
|
+
allowNullableFilter
|
|
2093
|
+
);
|
|
2083
2094
|
const actual = isForcedValue(value) ? value.value : value;
|
|
2084
2095
|
try {
|
|
2085
2096
|
return schema.parse(actual);
|
|
@@ -2157,10 +2168,9 @@ function createWhereBuilder(typeMap, enumMap, scalarBase, uniqueMap = {}) {
|
|
|
2157
2168
|
`Invalid compound unique where shape for "${model}.${key}.${fieldName}". Prisma compound unique selectors do not accept filter operator objects${operators.length ? `: ${operators.join(", ")}` : ""}. Use direct values only.`
|
|
2158
2169
|
);
|
|
2159
2170
|
}
|
|
2160
|
-
const directSchema2 =
|
|
2171
|
+
const directSchema2 = buildUniqueWhereFieldSchema(
|
|
2161
2172
|
fieldMeta2,
|
|
2162
|
-
|
|
2163
|
-
scalarBase
|
|
2173
|
+
false
|
|
2164
2174
|
);
|
|
2165
2175
|
if (fieldValue === true) {
|
|
2166
2176
|
nestedSchemas[fieldName] = directSchema2;
|
|
@@ -2169,7 +2179,8 @@ function createWhereBuilder(typeMap, enumMap, scalarBase, uniqueMap = {}) {
|
|
|
2169
2179
|
model,
|
|
2170
2180
|
fieldName,
|
|
2171
2181
|
fieldMeta2,
|
|
2172
|
-
fieldValue
|
|
2182
|
+
fieldValue,
|
|
2183
|
+
false
|
|
2173
2184
|
);
|
|
2174
2185
|
}
|
|
2175
2186
|
}
|
|
@@ -2208,7 +2219,7 @@ function createWhereBuilder(typeMap, enumMap, scalarBase, uniqueMap = {}) {
|
|
|
2208
2219
|
`Invalid unique where shape for "${model}.${key}". Prisma WhereUniqueInput does not accept operators: ${keys.join(", ")}. Use a direct unique value shape, for example { ${key}: true }.`
|
|
2209
2220
|
);
|
|
2210
2221
|
}
|
|
2211
|
-
const directSchema =
|
|
2222
|
+
const directSchema = buildUniqueWhereFieldSchema(fieldMeta, true);
|
|
2212
2223
|
if (value === true) {
|
|
2213
2224
|
fieldSchemas[key] = directSchema;
|
|
2214
2225
|
continue;
|
|
@@ -2217,7 +2228,8 @@ function createWhereBuilder(typeMap, enumMap, scalarBase, uniqueMap = {}) {
|
|
|
2217
2228
|
model,
|
|
2218
2229
|
key,
|
|
2219
2230
|
fieldMeta,
|
|
2220
|
-
value
|
|
2231
|
+
value,
|
|
2232
|
+
true
|
|
2221
2233
|
);
|
|
2222
2234
|
forcedOnlyKeys.add(key);
|
|
2223
2235
|
}
|
|
@@ -3570,7 +3582,21 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
|
|
|
3570
3582
|
built = builtCache.get(resolution.key);
|
|
3571
3583
|
}
|
|
3572
3584
|
}
|
|
3573
|
-
|
|
3585
|
+
const result = applyBuiltShape(
|
|
3586
|
+
built,
|
|
3587
|
+
normalizedBody,
|
|
3588
|
+
isUnique,
|
|
3589
|
+
model
|
|
3590
|
+
);
|
|
3591
|
+
if (isUnique && result.where) {
|
|
3592
|
+
validateResolvedUniqueWhere(
|
|
3593
|
+
model,
|
|
3594
|
+
result.where,
|
|
3595
|
+
method,
|
|
3596
|
+
uniqueMap
|
|
3597
|
+
);
|
|
3598
|
+
}
|
|
3599
|
+
return result;
|
|
3574
3600
|
}
|
|
3575
3601
|
};
|
|
3576
3602
|
}
|