import {z} from 'zod' export type GetApiApiProjectsIdRevisionsArgs = {id: number, last_id?: number | undefined, name?: string | undefined, 'page[after]'?: string | undefined, 'page[size]'?: number | undefined}; export type GetApiApiProjectsIdRevisionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const restPagination = z.object({nextPage: z.string().optional()}); export const restRevision = z.object({archiveMd5: z.string().optional(), archiveType: z.string(), createdAt: z.string().optional(), revision: z.string(), userInfo: z.object({}).optional()}); export const restRevisionCollection = z.object({pagination: restPagination.optional(), revisions: z.array(restRevision).optional()}); 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 revisions of a project * * GET /api/projects/{id}/revisions */ export const getApiApiProjectsIdRevisions = async (args: GetApiApiProjectsIdRevisionsArgs, options?: GetApiApiProjectsIdRevisionsOptions) => { const {baseUrl = "https://api-workflow.treasuredata.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.last_id != null) query.append("last_id", String(args.last_id)) if (args.name != null) query.append("name", String(args.name)) if (args['page[after]'] != null) query.append("page[after]", String(args['page[after]'])) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (ApiKeyAuth !== undefined) headers.set('authorization', `TD1 ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.id))}/revisions${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(restRevisionCollection, await res.json()) };