import {z} from 'zod' export type GetApiTableTableIdAggregationSearchIndexArgs = {tableId: string, viewId?: string | undefined, ignoreViewQuery?: (string | boolean) | undefined, filterByTql?: string | undefined, filter?: string | undefined, search?: (Array | Array | Array) | undefined, filterLinkCellCandidate?: (Array | string) | undefined, filterLinkCellSelected?: (Array | string) | undefined, selectedRecordIds?: Array | undefined}; export type GetApiTableTableIdAggregationSearchIndexOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiTableTableIdAggregationSearchIndexResponse = z.array(z.object({index: z.number(), fieldId: z.string(), recordId: z.string()})).nullable(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get record indices for search * * GET /table/{tableId}/aggregation/search-index */ export const getApiTableTableIdAggregationSearchIndex = async (args: GetApiTableTableIdAggregationSearchIndexArgs, options?: GetApiTableTableIdAggregationSearchIndexOptions) => { const {baseUrl = "https://app.teable.ai/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.viewId != null) query.append("viewId", String(args.viewId)) if (args.ignoreViewQuery != null) query.append("ignoreViewQuery", String(args.ignoreViewQuery)) if (args.filterByTql != null) query.append("filterByTql", String(args.filterByTql)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.search != null) query.append("search", String(args.search)) if (args.filterLinkCellCandidate != null) query.append("filterLinkCellCandidate", String(args.filterLinkCellCandidate)) if (args.filterLinkCellSelected != null) query.append("filterLinkCellSelected", String(args.filterLinkCellSelected)) for (const item of args.selectedRecordIds ?? []) query.append("selectedRecordIds", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/table/${encodeURIComponent(String(args.tableId))}/aggregation/search-index${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiTableTableIdAggregationSearchIndexResponse, await res.json()) };