Skip to content

Commit

Permalink
Improved in check
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwillcode committed Jul 11, 2024
1 parent c8ec0db commit 91d936b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/prisma/extensions/undefined-guard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Prisma } from "@prisma/client";

const checkUndefined = (where: any) => {
const checkUndefinedInValue = (where: any) => {
if (where) {
for (const key in where) {
// INFO: Since this is for $allModels, we don't have a way to get the correct
// where type
// @ts-expect-error Element implicitly has any type
const whereInput = where[key as any] as any;
if (whereInput?.in === undefined || (whereInput?.in !== undefined && !Array.isArray(whereInput.in))) {
if (
whereInput.hasOwnProperty("in") &&
(whereInput?.in === undefined || (whereInput?.in !== undefined && !Array.isArray(whereInput.in)))
) {
throw new Error(`The "in" value for the field "${key}" is undefined.`);
}
}
Expand All @@ -19,11 +22,11 @@ export function undefinedGuardExtension() {
query: {
$allModels: {
async deleteMany({ model, operation, args, query }) {
checkUndefined(args.where);
checkUndefinedInValue(args.where);
return query(args);
},
async updateMany({ model, operation, args, query }) {
checkUndefined(args.where);
checkUndefinedInValue(args.where);
return query(args);
},
},
Expand Down

0 comments on commit 91d936b

Please sign in to comment.