From ccc97ab759936226fb8340075959a7b229b16e4a Mon Sep 17 00:00:00 2001 From: Jonas Jesus Date: Tue, 6 Jan 2026 12:02:47 -0300 Subject: [PATCH] fix(registry): replace unknown with proper WhereExpression Zod schema - Add WhereExpression type with recursive structure - Create recursive Zod schema using z.lazy() for proper validation - Support all operators: eq, gt, gte, lt, lte, in, like, contains, and, or, not - Improve type safety for filter expressions --- registry/server/tools/registry-binding.ts | 41 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/registry/server/tools/registry-binding.ts b/registry/server/tools/registry-binding.ts index 97925cc3..7bf25f7d 100644 --- a/registry/server/tools/registry-binding.ts +++ b/registry/server/tools/registry-binding.ts @@ -44,9 +44,46 @@ const RegistryServerSchema = z.object({ }); /** - * WhereExpression schema - using z.unknown() to avoid deep type instantiation + * WhereExpression type - recursive type for filtering + * Supports simple conditions and logical operators (and, or, not) */ -const WhereExpressionSchema = z.unknown(); +type WhereExpression = { + field?: string[]; + operator?: string; + value?: unknown; + conditions?: WhereExpression[]; +}; + +/** + * WhereExpression schema - recursive Zod schema for filtering + * Supports: eq, gt, gte, lt, lte, in, like, contains, and, or, not + */ +const WhereExpressionSchema: z.ZodType = z.lazy(() => + z.object({ + field: z.array(z.string()).optional().describe("Field path to filter on"), + operator: z + .enum([ + "eq", + "gt", + "gte", + "lt", + "lte", + "in", + "like", + "contains", + "and", + "or", + "not", + ]) + .optional() + .describe("Comparison or logical operator"), + value: z.unknown().optional().describe("Value to compare against"), + conditions: z + .array(z.lazy(() => WhereExpressionSchema)) + .optional() + .describe("Nested conditions for logical operators"), + }), +); /** * Legacy simplified where schema for easier filtering