import {z} from 'zod' export type GetApiFilesystemsFilesystemIdFilesArgs = {filesystem_id: string, directory?: string | undefined, recursive?: boolean | undefined, mime_type?: (string | null) | undefined, include_content?: boolean | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiFilesystemsFilesystemIdFilesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const filesystemFileResponse = z.object({checksum: z.string().nullable().optional(), content: z.string().nullable().optional(), content_truncated: z.boolean().optional(), is_binary: z.boolean().optional(), is_directory: z.boolean().optional(), mime_type: z.string().nullable().optional(), modified_at: z.string(), path: z.string(), size_bytes: z.number().int().nullable().optional(), synced_at: z.string()}); export const listFilesResponse = z.object({files: z.array(filesystemFileResponse), filesystem_id: z.string(), synced_at: z.string().nullable().optional(), total_count: z.number().int()}); 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 }; /** * List Files * * GET /filesystems/{filesystem_id}/files */ export const getApiFilesystemsFilesystemIdFiles = async (args: GetApiFilesystemsFilesystemIdFilesArgs, options: GetApiFilesystemsFilesystemIdFilesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.directory != null) query.append("directory", String(args.directory)) if (args.recursive != null) query.append("recursive", String(args.recursive)) if (args.mime_type != null) query.append("mime_type", String(args.mime_type)) if (args.include_content != null) query.append("include_content", String(args.include_content)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/filesystems/${encodeURIComponent(String(args.filesystem_id))}/files${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(listFilesResponse, await res.json()) };