import {z} from 'zod' export type GetApiApiV1TaskTasksProjectProjectIdActiveTasksArgs = {project_id: string, jq_filters?: {[key: string]: string} | undefined}; export type GetApiApiV1TaskTasksProjectProjectIdActiveTasksOptions = {baseUrl: string, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const projectActiveTasksTasks = z.object({id: z.string().max(255).optional(), name: z.string().max(100).nullable().optional(), verbose_name: z.string(), user__name: z.string().optional(), worker: z.string().max(1024).nullable().optional(), status: z.enum(["FAILURE", "PENDING", "RECEIVED", "RETRY", "REVOKED", "STARTED", "SUCCESS"]).nullable().optional(), progress: z.number().int().gte(0).lte(2147483647).nullable().optional(), description: z.string().optional(), date_start: z.string(), date_work_start: z.string(), date_done: z.string(), total_time: z.string(), work_time: z.string()}); export const projectActiveTasks = z.object({tasks: projectActiveTasksTasks, document_transformer_change_in_progress: z.boolean(), text_unit_transformer_change_in_progress: z.boolean(), locate_terms_in_progress: z.boolean(), locate_companies_in_progress: z.boolean()}); export const getApiApiV1TaskTasksProjectProjectIdActiveTasksResponse = z.array(projectActiveTasks); 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 /api/v1/task/tasks/project/{project_id}/active-tasks/ */ export const getApiApiV1TaskTasksProjectProjectIdActiveTasks = async (args: GetApiApiV1TaskTasksProjectProjectIdActiveTasksArgs, options: GetApiApiV1TaskTasksProjectProjectIdActiveTasksOptions) => { const {baseUrl, fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.jq_filters != null) query.append("jq_filters", JSON.stringify(args.jq_filters)) if (AuthToken !== undefined) headers.set("Authorization", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/task/tasks/project/${encodeURIComponent(String(args.project_id))}/active-tasks/${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(getApiApiV1TaskTasksProjectProjectIdActiveTasksResponse, await res.json()) };