From 94f475c0607a001f131da6146b3b6fe55af63a2d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 20 Nov 2024 16:09:03 +0100 Subject: [PATCH] Exclude InternalSearchFilterOperator.COMPLEX_ID_OPERATOR --- packages/types/src/api/web/app/rows.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/types/src/api/web/app/rows.ts b/packages/types/src/api/web/app/rows.ts index 34ef1ee4c1..520983d353 100644 --- a/packages/types/src/api/web/app/rows.ts +++ b/packages/types/src/api/web/app/rows.ts @@ -2,6 +2,7 @@ import { ArrayOperator, BasicOperator, EmptyFilterOption, + InternalSearchFilterOperator, LogicalOperator, RangeOperator, SearchFilterKey, @@ -26,10 +27,15 @@ export interface PatchRowRequest extends Row { export interface PatchRowResponse extends Row {} -// TODO: exclude InternalSearchFilterOperator.COMPLEX_ID_OPERATOR -const stringBasicFilter = z.record(z.string(), z.string()) -const basicFilter = z.record(z.string(), z.any()) -const arrayFilter = z.record(z.string(), z.union([z.any().array(), z.string()])) +const fieldKey = z + .string() + .refine(s => s !== InternalSearchFilterOperator.COMPLEX_ID_OPERATOR, { + message: `Key '${InternalSearchFilterOperator.COMPLEX_ID_OPERATOR}' is not allowed`, + }) + +const stringBasicFilter = z.record(fieldKey, z.string()) +const basicFilter = z.record(fieldKey, z.any()) +const arrayFilter = z.record(fieldKey, z.union([z.any().array(), z.string()])) const logicFilter = z.lazy(() => z.object({ conditions: z.array(z.object(queryFilterValidation)), @@ -43,7 +49,7 @@ const queryFilterValidation: Record = { [BasicOperator.FUZZY]: stringBasicFilter.optional(), [RangeOperator.RANGE]: z .record( - z.string(), + fieldKey, z.union([ z.object({ high: stringOrNumber, low: stringOrNumber }), z.object({ high: stringOrNumber }),