import {z} from 'zod' export type GetApiRowsArgs = {id?: string | undefined, created_at?: unknown | undefined, content?: unknown | undefined, column_id?: string | undefined, table_id?: string | undefined, order?: string | undefined, due_date?: unknown | undefined, priority?: unknown | undefined, exp_cost?: unknown | undefined, act_cost?: unknown | undefined, payment_status?: unknown | undefined, category?: unknown | undefined, assignee_id?: string | undefined, description?: unknown | undefined, budget_id?: string | undefined, assignees?: unknown | undefined, properties?: unknown | undefined, select?: string | undefined, Range?: string | undefined, 'Range-Unit'?: string | undefined, offset?: string | undefined, limit?: string | undefined, Prefer?: 'count=none' | undefined}; export type GetApiRowsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const rows = z.object({id: z.string(), created_at: z.string(), content: z.string().optional(), column_id: z.string().optional(), table_id: z.string().optional(), order: z.number().int().optional(), due_date: z.string().optional(), priority: z.string().optional(), exp_cost: z.number().int().optional(), act_cost: z.number().int().optional(), payment_status: z.string().optional(), category: z.string().optional(), assignee_id: z.string().optional(), description: z.string().optional(), budget_id: z.string().optional(), assignees: z.array(z.string()).optional(), properties: z.unknown()}); export const getApiRowsResponse = z.array(rows); 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 /rows */ export const getApiRows = async (args: GetApiRowsArgs, options?: GetApiRowsOptions) => { const {baseUrl = "https://vnaabuozknwgxuvnfwjo.supabase.co:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.content != null) query.append("content", String(args.content)) if (args.column_id != null) query.append("column_id", String(args.column_id)) if (args.table_id != null) query.append("table_id", String(args.table_id)) if (args.order != null) query.append("order", String(args.order)) if (args.due_date != null) query.append("due_date", String(args.due_date)) if (args.priority != null) query.append("priority", String(args.priority)) if (args.exp_cost != null) query.append("exp_cost", String(args.exp_cost)) if (args.act_cost != null) query.append("act_cost", String(args.act_cost)) if (args.payment_status != null) query.append("payment_status", String(args.payment_status)) if (args.category != null) query.append("category", String(args.category)) if (args.assignee_id != null) query.append("assignee_id", String(args.assignee_id)) if (args.description != null) query.append("description", String(args.description)) if (args.budget_id != null) query.append("budget_id", String(args.budget_id)) if (args.assignees != null) query.append("assignees", String(args.assignees)) if (args.properties != null) query.append("properties", String(args.properties)) if (args.select != null) query.append("select", String(args.select)) if (args.order != null) query.append("order", String(args.order)) if (args.Range != null) headers.set("Range", String(args.Range)) if (args['Range-Unit'] != null) headers.set("Range-Unit", String(args['Range-Unit'])) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.Prefer != null) headers.set("Prefer", String(args.Prefer)) const url = `${baseUrl.replace(/\/+$/, '')}/rows${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(getApiRowsResponse, await res.json()) };