Skip to content

Commit ab5b15d

Browse files
committed
feat: simplify operator validation in createWhereBuilder by removing redundant checks
1 parent 83b1861 commit ab5b15d

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

src/runtime/query-builder-where.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,6 @@ export function createWhereBuilder(
399399
fieldSchemas: Record<string, z.ZodTypeAny>,
400400
scalarConditions: Record<string, unknown>,
401401
): void {
402-
if (operators === null || (typeof operators !== "object" && typeof operators !== "function")) {
403-
const equalsSchema = createOperatorSchema(fieldMeta, "equals", enumMap, scalarBase);
404-
const result = equalsSchema.safeParse(operators);
405-
if (result.success) {
406-
scalarConditions[fieldName] = { equals: result.data };
407-
return;
408-
}
409-
throw new ShapeError(
410-
`Where config for scalar field "${fieldName}" on model "${model}" must be an object of operators or a scalar shorthand value`,
411-
);
412-
}
413-
414402
if (!isPlainObject(operators)) {
415403
throw new ShapeError(
416404
`Where config for scalar field "${fieldName}" on model "${model}" must be an object of operators`,
@@ -515,19 +503,23 @@ export function createWhereBuilder(
515503

516504
if (hasClientOps) {
517505
const opObj = z.object(opSchemas).strict();
518-
const refined = opObj
519-
.refine(
520-
(v) =>
521-
clientOpKeys.some(
522-
(k) => (v as Record<string, unknown>)[k] !== undefined,
523-
),
524-
{
525-
message: `At least one operator required for where field "${fieldName}"`,
526-
},
527-
);
506+
const refined = opObj.refine(
507+
(v) =>
508+
clientOpKeys.some(
509+
(k) => (v as Record<string, unknown>)[k] !== undefined,
510+
),
511+
{
512+
message: `At least one operator required for where field "${fieldName}"`,
513+
},
514+
);
528515

529516
if ("equals" in opSchemas) {
530-
const equalsBase = createOperatorSchema(fieldMeta, "equals", enumMap, scalarBase);
517+
const equalsBase = createOperatorSchema(
518+
fieldMeta,
519+
"equals",
520+
enumMap,
521+
scalarBase,
522+
);
531523
const shorthand = equalsBase.transform((v: unknown) => ({ equals: v }));
532524
fieldSchemas[fieldName] = z.union([refined, shorthand]).optional();
533525
} else {
@@ -541,4 +533,4 @@ export function createWhereBuilder(
541533
}
542534

543535
return { buildWhereSchema };
544-
}
536+
}

0 commit comments

Comments
 (0)