import {z} from 'zod' export type GetApiFolderSlugContentsArgs = {slug: string, name_contains?: (string | null) | undefined, public?: (boolean | null) | undefined, shared_with_rowan?: (boolean | null) | undefined, starred?: (boolean | null) | undefined, page?: number | undefined, size?: number | undefined, sort?: string | undefined, asc?: boolean | undefined, return_object_data?: boolean | undefined, updated_after?: (string | null) | undefined, updated_before?: (string | null) | undefined, created_after?: (string | null) | undefined, created_before?: (string | null) | undefined, access_token?: (string | null) | undefined}; export type GetApiFolderSlugContentsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const folder = z.object({name: z.string().nullable().optional(), parent_uuid: z.string().nullable().optional(), notes: z.string().optional(), starred: z.boolean().optional(), public: z.boolean().optional(), shared_with_rowan: z.boolean().optional(), created_at: z.string(), updated_at: z.string().nullable().optional(), public_until: z.string().nullable().optional(), is_root: z.boolean(), uuid: z.string(), ancestor_is_public: z.boolean().optional(), project_uuid: z.string().nullable().optional(), is_temporarily_public: z.boolean()}); export const workflowContentItem = z.object({name: z.string().nullable().optional(), starred: z.boolean().optional(), email_when_complete: z.boolean().optional(), public: z.boolean().optional(), public_until: z.string().nullable().optional(), created_at: z.string(), object_type: z.string(), object_status: z.number().int(), object_data: z.object({}).nullable().optional(), smiles: z.string().nullable().optional(), uuid: z.string(), compute_hardware: z.string().nullable().optional(), retry_count: z.number().int().optional(), is_temporarily_public: z.boolean()}); export const folderItem = z.object({type: z.string(), data: z.union([folder, workflowContentItem])}); export const folderContents = z.object({num_pages: z.number().int(), items: z.array(folderItem)}); 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 Contents * * GET /folder/{slug}/contents */ export const getApiFolderSlugContents = async (args: GetApiFolderSlugContentsArgs, options: GetApiFolderSlugContentsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const cookies: string[] = [] headers.set('accept', "application/json") if (args.name_contains != null) query.append("name_contains", String(args.name_contains)) if (args.public != null) query.append("public", String(args.public)) if (args.shared_with_rowan != null) query.append("shared_with_rowan", String(args.shared_with_rowan)) if (args.starred != null) query.append("starred", String(args.starred)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.asc != null) query.append("asc", String(args.asc)) if (args.return_object_data != null) query.append("return_object_data", String(args.return_object_data)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.access_token != null) cookies.push("access_token=" + encodeURIComponent(String(args.access_token))) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) if (cookies.length > 0) headers.set('cookie', cookies.join('; ')) const url = `${baseUrl.replace(/\/+$/, '')}/folder/${encodeURIComponent(String(args.slug))}/contents${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(folderContents, await res.json()) };