import {z} from 'zod' export type GetApiTableTableIdAggregationRecordIndexArgs = {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, orderBy?: string | undefined, groupBy?: string | undefined, collapsedGroupIds?: string | undefined, queryId?: string | undefined, recordId: string}; export type GetApiTableTableIdAggregationRecordIndexOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiTableTableIdAggregationRecordIndexResponse = z.object({index: z.number()}).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 index * * GET /table/{tableId}/aggregation/record-index */ export const getApiTableTableIdAggregationRecordIndex = async (args: GetApiTableTableIdAggregationRecordIndexArgs, options?: GetApiTableTableIdAggregationRecordIndexOptions) => { 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 (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.groupBy != null) query.append("groupBy", String(args.groupBy)) if (args.collapsedGroupIds != null) query.append("collapsedGroupIds", String(args.collapsedGroupIds)) if (args.queryId != null) query.append("queryId", String(args.queryId)) if (args.recordId != null) query.append("recordId", String(args.recordId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/table/${encodeURIComponent(String(args.tableId))}/aggregation/record-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(getApiTableTableIdAggregationRecordIndexResponse, await res.json()) };