prisma-guard 1.5.0 → 1.5.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 +38 -13
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +38 -13
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.js
CHANGED
|
@@ -705,18 +705,23 @@ function mergeUniqueWhereForced(where, forced) {
|
|
|
705
705
|
}
|
|
706
706
|
function applyBuiltShape(built, body, isUniqueMethod) {
|
|
707
707
|
let parseable = body;
|
|
708
|
-
if (
|
|
708
|
+
if (isPlainObject(body)) {
|
|
709
709
|
const bodyObj = body;
|
|
710
710
|
if (isPlainObject(bodyObj.where)) {
|
|
711
711
|
const where = { ...bodyObj.where };
|
|
712
|
-
let
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
712
|
+
let modified = false;
|
|
713
|
+
if (built.forcedOnlyWhereKeys.size > 0) {
|
|
714
|
+
for (const key of built.forcedOnlyWhereKeys) {
|
|
715
|
+
if (key in where) {
|
|
716
|
+
delete where[key];
|
|
717
|
+
modified = true;
|
|
718
|
+
}
|
|
717
719
|
}
|
|
718
720
|
}
|
|
719
|
-
if (
|
|
721
|
+
if (Object.keys(where).length === 0 && hasWhereForced(built.forcedWhere)) {
|
|
722
|
+
const { where: _, ...rest } = bodyObj;
|
|
723
|
+
parseable = rest;
|
|
724
|
+
} else if (modified) {
|
|
720
725
|
parseable = { ...bodyObj, where };
|
|
721
726
|
}
|
|
722
727
|
}
|
|
@@ -2106,9 +2111,11 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
|
|
|
2106
2111
|
}
|
|
2107
2112
|
if (method === "count" && shape.include)
|
|
2108
2113
|
throw new ShapeError('count does not support "include"');
|
|
2109
|
-
if (method === "groupBy" && shape.orderBy) {
|
|
2114
|
+
if (method === "groupBy" && shape.orderBy && shape.orderBy !== true) {
|
|
2110
2115
|
const bySet = new Set(shape.by);
|
|
2111
2116
|
for (const fieldName of Object.keys(shape.orderBy)) {
|
|
2117
|
+
if (fieldName === "_count")
|
|
2118
|
+
continue;
|
|
2112
2119
|
if (!bySet.has(fieldName)) {
|
|
2113
2120
|
throw new ShapeError(
|
|
2114
2121
|
`orderBy field "${fieldName}" must be included in "by" for groupBy`
|
|
@@ -2186,11 +2193,29 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
|
|
|
2186
2193
|
forcedSelectCountWhere = result.forcedCountWhere;
|
|
2187
2194
|
}
|
|
2188
2195
|
}
|
|
2189
|
-
if (shape.orderBy)
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2196
|
+
if (shape.orderBy) {
|
|
2197
|
+
if (method === "groupBy" && shape.orderBy === true && shape.by) {
|
|
2198
|
+
const sortEnum = z7.enum(["asc", "desc"]);
|
|
2199
|
+
const groupByOrderFields = {};
|
|
2200
|
+
for (const field of shape.by) {
|
|
2201
|
+
groupByOrderFields[field] = sortEnum.optional();
|
|
2202
|
+
}
|
|
2203
|
+
groupByOrderFields["_count"] = sortEnum.optional();
|
|
2204
|
+
const fieldKeys = Object.keys(groupByOrderFields);
|
|
2205
|
+
const singleSchema = z7.object(groupByOrderFields).strict().refine(
|
|
2206
|
+
(v) => fieldKeys.some(
|
|
2207
|
+
(k) => v[k] !== void 0
|
|
2208
|
+
),
|
|
2209
|
+
{ message: "orderBy must specify at least one field" }
|
|
2210
|
+
);
|
|
2211
|
+
schemaFields["orderBy"] = z7.union([singleSchema, z7.array(singleSchema).min(1)]).optional();
|
|
2212
|
+
} else {
|
|
2213
|
+
schemaFields["orderBy"] = argsBuilder.buildOrderBySchema(
|
|
2214
|
+
model,
|
|
2215
|
+
shape.orderBy
|
|
2216
|
+
);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2194
2219
|
if (shape.cursor)
|
|
2195
2220
|
schemaFields["cursor"] = argsBuilder.buildCursorSchema(
|
|
2196
2221
|
model,
|