import {z} from 'zod' export type GetApiV1WorkspacesWorkspaceIdArtifactsRowsArgs = {workspace_id: string, path: string, start_row?: number | undefined, limit?: number | undefined, ranges?: (string | null) | undefined}; export type GetApiV1WorkspacesWorkspaceIdArtifactsRowsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const queryTableColumn = z.object({name: z.string(), data_type: z.string()}); export const artifactRowsPage = z.object({path: z.string(), start_row: z.number().int(), limit: z.number().int(), total_rows: z.number().int(), columns: z.array(queryTableColumn), rows: z.array(z.record(z.string(), z.string()))}); 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_artifact_rows * * GET /v1/workspaces/{workspace_id}/artifacts/rows */ export const getApiV1WorkspacesWorkspaceIdArtifactsRows = async (args: GetApiV1WorkspacesWorkspaceIdArtifactsRowsArgs, options: GetApiV1WorkspacesWorkspaceIdArtifactsRowsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.path != null) query.append("path", String(args.path)) if (args.start_row != null) query.append("start_row", String(args.start_row)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.ranges != null) query.append("ranges", String(args.ranges)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace_id))}/artifacts/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(artifactRowsPage, await res.json()) };