diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 680a7671d5..769a1dbe5e 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -17,6 +17,7 @@ import { GetRowResponse, PatchRowRequest, PatchRowResponse, + RequiredKeys, Row, RowAttachment, RowSearchParams, @@ -211,15 +212,17 @@ export async function search(ctx: Ctx) { await context.ensureSnippetContext(true) + const searchRequest = ctx.request.body + const enrichedQuery = await utils.enrichSearchContext( - { ...ctx.request.body.query }, + { ...searchRequest.query }, { user: sdk.users.getUserContextBindings(ctx.user), } ) - const searchParams: RowSearchParams = { - ...ctx.request.body, + const searchParams: RequiredKeys = { + ...searchRequest, query: enrichedQuery, tableId, viewId, diff --git a/packages/types/src/api/web/app/rows.ts b/packages/types/src/api/web/app/rows.ts index ce6f6f672d..166c6965c4 100644 --- a/packages/types/src/api/web/app/rows.ts +++ b/packages/types/src/api/web/app/rows.ts @@ -1,7 +1,8 @@ import { SearchFilters, RowSearchParams } from "../../../sdk" import { Row } from "../../../documents" -import { PaginationResponse, SortOrder } from "../../../api" +import { PaginationResponse, SortOrder, SortType } from "../../../api" import { ReadStream } from "fs" +import { z } from "zod" export interface SaveRowRequest extends Row {} @@ -13,7 +14,29 @@ export interface PatchRowRequest extends Row { export interface PatchRowResponse extends Row {} -export interface SearchRowRequest extends Omit {} +const searchRowRequest = z.object({ + table: z.string(), + query: z.object({ + allOr: z.boolean().optional(), + }), + paginate: z.boolean().optional(), + bookmark: z.union([z.string(), z.number()]).optional(), + limit: z.number().optional(), + sort: z.string().optional(), + sortOrder: z.nativeEnum(SortOrder).optional(), + sortType: z.nativeEnum(SortType).optional(), + version: z.string().optional(), + disableEscaping: z.boolean().optional(), + countRows: z.boolean().optional(), + + // viewId?: string + // query?: SearchFilters + + // fields?: string[] + // indexer?: () => Promise + // rows?: Row[] +}) +export type SearchRowRequest = z.infer export interface SearchViewRowRequest extends Pick<