prisma-guard 1.5.0 → 1.6.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 +41 -13
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +41 -13
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime/index.cjs
CHANGED
|
@@ -735,20 +735,28 @@ function mergeUniqueWhereForced(where, forced) {
|
|
|
735
735
|
}
|
|
736
736
|
function applyBuiltShape(built, body, isUniqueMethod) {
|
|
737
737
|
let parseable = body;
|
|
738
|
-
if (
|
|
738
|
+
if (isPlainObject(body)) {
|
|
739
739
|
const bodyObj = body;
|
|
740
740
|
if (isPlainObject(bodyObj.where)) {
|
|
741
741
|
const where = { ...bodyObj.where };
|
|
742
|
-
let
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
742
|
+
let modified = false;
|
|
743
|
+
if (built.forcedOnlyWhereKeys.size > 0) {
|
|
744
|
+
for (const key of built.forcedOnlyWhereKeys) {
|
|
745
|
+
if (key in where) {
|
|
746
|
+
delete where[key];
|
|
747
|
+
modified = true;
|
|
748
|
+
}
|
|
747
749
|
}
|
|
748
750
|
}
|
|
749
|
-
if (
|
|
751
|
+
if (Object.keys(where).length === 0 && hasWhereForced(built.forcedWhere)) {
|
|
752
|
+
const { where: _, ...rest } = bodyObj;
|
|
753
|
+
parseable = rest;
|
|
754
|
+
} else if (modified) {
|
|
750
755
|
parseable = { ...bodyObj, where };
|
|
751
756
|
}
|
|
757
|
+
} else if ("where" in bodyObj && hasWhereForced(built.forcedWhere) && !built.zodSchema.shape.where) {
|
|
758
|
+
const { where: _, ...rest } = bodyObj;
|
|
759
|
+
parseable = rest;
|
|
752
760
|
}
|
|
753
761
|
}
|
|
754
762
|
const validated = built.zodSchema.parse(parseable);
|
|
@@ -2136,9 +2144,11 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
|
|
|
2136
2144
|
}
|
|
2137
2145
|
if (method === "count" && shape.include)
|
|
2138
2146
|
throw new ShapeError('count does not support "include"');
|
|
2139
|
-
if (method === "groupBy" && shape.orderBy) {
|
|
2147
|
+
if (method === "groupBy" && shape.orderBy && shape.orderBy !== true) {
|
|
2140
2148
|
const bySet = new Set(shape.by);
|
|
2141
2149
|
for (const fieldName of Object.keys(shape.orderBy)) {
|
|
2150
|
+
if (fieldName === "_count")
|
|
2151
|
+
continue;
|
|
2142
2152
|
if (!bySet.has(fieldName)) {
|
|
2143
2153
|
throw new ShapeError(
|
|
2144
2154
|
`orderBy field "${fieldName}" must be included in "by" for groupBy`
|
|
@@ -2216,11 +2226,29 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
|
|
|
2216
2226
|
forcedSelectCountWhere = result.forcedCountWhere;
|
|
2217
2227
|
}
|
|
2218
2228
|
}
|
|
2219
|
-
if (shape.orderBy)
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2229
|
+
if (shape.orderBy) {
|
|
2230
|
+
if (method === "groupBy" && shape.orderBy === true && shape.by) {
|
|
2231
|
+
const sortEnum = import_zod7.z.enum(["asc", "desc"]);
|
|
2232
|
+
const groupByOrderFields = {};
|
|
2233
|
+
for (const field of shape.by) {
|
|
2234
|
+
groupByOrderFields[field] = sortEnum.optional();
|
|
2235
|
+
}
|
|
2236
|
+
groupByOrderFields["_count"] = sortEnum.optional();
|
|
2237
|
+
const fieldKeys = Object.keys(groupByOrderFields);
|
|
2238
|
+
const singleSchema = import_zod7.z.object(groupByOrderFields).strict().refine(
|
|
2239
|
+
(v) => fieldKeys.some(
|
|
2240
|
+
(k) => v[k] !== void 0
|
|
2241
|
+
),
|
|
2242
|
+
{ message: "orderBy must specify at least one field" }
|
|
2243
|
+
);
|
|
2244
|
+
schemaFields["orderBy"] = import_zod7.z.union([singleSchema, import_zod7.z.array(singleSchema).min(1)]).optional();
|
|
2245
|
+
} else {
|
|
2246
|
+
schemaFields["orderBy"] = argsBuilder.buildOrderBySchema(
|
|
2247
|
+
model,
|
|
2248
|
+
shape.orderBy
|
|
2249
|
+
);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2224
2252
|
if (shape.cursor)
|
|
2225
2253
|
schemaFields["cursor"] = argsBuilder.buildCursorSchema(
|
|
2226
2254
|
model,
|