import {z} from 'zod' export type GetApiPropertiesArgs = {id?: string | undefined, created_at?: unknown | undefined, name?: unknown | undefined, type?: unknown | undefined, updated_at?: unknown | undefined, is_visible?: unknown | undefined, order?: string | undefined, budget_id?: string | undefined, columns?: unknown | undefined, is_immutable?: unknown | undefined, options?: unknown | undefined, table_id?: string | undefined, currency?: unknown | undefined, number_format?: unknown | undefined, select?: string | undefined, Range?: string | undefined, 'Range-Unit'?: string | undefined, offset?: string | undefined, limit?: string | undefined, Prefer?: 'count=none' | undefined}; export type GetApiPropertiesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const properties = z.object({id: z.string(), created_at: z.string(), name: z.string().optional(), type: z.enum(["text", "select", "number", "user", "link", "date", "checkbox", "column"]).optional(), updated_at: z.string().optional(), is_visible: z.boolean().optional(), order: z.number().int().optional(), budget_id: z.string().optional(), columns: z.unknown(), is_immutable: z.boolean().optional(), options: z.unknown(), table_id: z.string().optional(), currency: z.string().optional(), number_format: z.enum(["number", "currency"]).optional()}); export const getApiPropertiesResponse = z.array(properties); 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 /properties */ export const getApiProperties = async (args: GetApiPropertiesArgs, options?: GetApiPropertiesOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.type != null) query.append("type", String(args.type)) if (args.updated_at != null) query.append("updated_at", String(args.updated_at)) if (args.is_visible != null) query.append("is_visible", String(args.is_visible)) if (args.order != null) query.append("order", String(args.order)) if (args.budget_id != null) query.append("budget_id", String(args.budget_id)) if (args.columns != null) query.append("columns", String(args.columns)) if (args.is_immutable != null) query.append("is_immutable", String(args.is_immutable)) if (args.options != null) query.append("options", String(args.options)) if (args.table_id != null) query.append("table_id", String(args.table_id)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.number_format != null) query.append("number_format", String(args.number_format)) 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(/\/+$/, '')}/properties${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(getApiPropertiesResponse, await res.json()) };