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.
@@ -735,18 +735,23 @@ function mergeUniqueWhereForced(where, forced) {
735
735
  }
736
736
  function applyBuiltShape(built, body, isUniqueMethod) {
737
737
  let parseable = body;
738
- if (built.forcedOnlyWhereKeys.size > 0 && isPlainObject(body)) {
738
+ if (isPlainObject(body)) {
739
739
  const bodyObj = body;
740
740
  if (isPlainObject(bodyObj.where)) {
741
741
  const where = { ...bodyObj.where };
742
- let stripped = false;
743
- for (const key of built.forcedOnlyWhereKeys) {
744
- if (key in where) {
745
- delete where[key];
746
- stripped = true;
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 (stripped) {
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
  }
752
757
  }
@@ -2136,9 +2141,11 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
2136
2141
  }
2137
2142
  if (method === "count" && shape.include)
2138
2143
  throw new ShapeError('count does not support "include"');
2139
- if (method === "groupBy" && shape.orderBy) {
2144
+ if (method === "groupBy" && shape.orderBy && shape.orderBy !== true) {
2140
2145
  const bySet = new Set(shape.by);
2141
2146
  for (const fieldName of Object.keys(shape.orderBy)) {
2147
+ if (fieldName === "_count")
2148
+ continue;
2142
2149
  if (!bySet.has(fieldName)) {
2143
2150
  throw new ShapeError(
2144
2151
  `orderBy field "${fieldName}" must be included in "by" for groupBy`
@@ -2216,11 +2223,29 @@ function createQueryBuilder(typeMap, enumMap, uniqueMap, scalarBase) {
2216
2223
  forcedSelectCountWhere = result.forcedCountWhere;
2217
2224
  }
2218
2225
  }
2219
- if (shape.orderBy)
2220
- schemaFields["orderBy"] = argsBuilder.buildOrderBySchema(
2221
- model,
2222
- shape.orderBy
2223
- );
2226
+ if (shape.orderBy) {
2227
+ if (method === "groupBy" && shape.orderBy === true && shape.by) {
2228
+ const sortEnum = import_zod7.z.enum(["asc", "desc"]);
2229
+ const groupByOrderFields = {};
2230
+ for (const field of shape.by) {
2231
+ groupByOrderFields[field] = sortEnum.optional();
2232
+ }
2233
+ groupByOrderFields["_count"] = sortEnum.optional();
2234
+ const fieldKeys = Object.keys(groupByOrderFields);
2235
+ const singleSchema = import_zod7.z.object(groupByOrderFields).strict().refine(
2236
+ (v) => fieldKeys.some(
2237
+ (k) => v[k] !== void 0
2238
+ ),
2239
+ { message: "orderBy must specify at least one field" }
2240
+ );
2241
+ schemaFields["orderBy"] = import_zod7.z.union([singleSchema, import_zod7.z.array(singleSchema).min(1)]).optional();
2242
+ } else {
2243
+ schemaFields["orderBy"] = argsBuilder.buildOrderBySchema(
2244
+ model,
2245
+ shape.orderBy
2246
+ );
2247
+ }
2248
+ }
2224
2249
  if (shape.cursor)
2225
2250
  schemaFields["cursor"] = argsBuilder.buildCursorSchema(
2226
2251
  model,