Exclude InternalSearchFilterOperator.COMPLEX_ID_OPERATOR

This commit is contained in:
Adria Navarro 2024-11-20 16:09:03 +01:00
parent 414d79d73c
commit 94f475c060
1 changed files with 11 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import {
ArrayOperator, ArrayOperator,
BasicOperator, BasicOperator,
EmptyFilterOption, EmptyFilterOption,
InternalSearchFilterOperator,
LogicalOperator, LogicalOperator,
RangeOperator, RangeOperator,
SearchFilterKey, SearchFilterKey,
@ -26,10 +27,15 @@ export interface PatchRowRequest extends Row {
export interface PatchRowResponse extends Row {} export interface PatchRowResponse extends Row {}
// TODO: exclude InternalSearchFilterOperator.COMPLEX_ID_OPERATOR const fieldKey = z
const stringBasicFilter = z.record(z.string(), z.string()) .string()
const basicFilter = z.record(z.string(), z.any()) .refine(s => s !== InternalSearchFilterOperator.COMPLEX_ID_OPERATOR, {
const arrayFilter = z.record(z.string(), z.union([z.any().array(), z.string()])) 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(() => const logicFilter = z.lazy(() =>
z.object({ z.object({
conditions: z.array(z.object(queryFilterValidation)), conditions: z.array(z.object(queryFilterValidation)),
@ -43,7 +49,7 @@ const queryFilterValidation: Record<SearchFilterKey, z.ZodTypeAny> = {
[BasicOperator.FUZZY]: stringBasicFilter.optional(), [BasicOperator.FUZZY]: stringBasicFilter.optional(),
[RangeOperator.RANGE]: z [RangeOperator.RANGE]: z
.record( .record(
z.string(), fieldKey,
z.union([ z.union([
z.object({ high: stringOrNumber, low: stringOrNumber }), z.object({ high: stringOrNumber, low: stringOrNumber }),
z.object({ high: stringOrNumber }), z.object({ high: stringOrNumber }),