import { z } from 'zod'; import { get } from '../../../operators/get.js'; import { getById } from '../../../operators/getById.js'; import { Pagination } from '../../../shared.js'; import type { ThreekitAuthProps } from '../../../ThreekitAuthProps.js'; import { Route } from '../../Route.js'; import { JobRun } from '../runs/JobRuns.js'; export const JobTask = z.object({ id: z.string().uuid(), orgId: z.string().uuid(), jobId: z.string().uuid(), branch: z.string(), createdBy: z.string().uuid(), createdAt: z.string().optional(), // when getting this from AssetJob sync export, this is not defined. updatedAt: z.string().optional(), // when getting this from AssetJob sync export, this is not defined. type: z.string(), image: z.string().optional(), // docker image cmd: z.string().optional(), parameters: z.string(), version: z.string().optional(), title: z.string(), runs: z.array(JobRun).optional(), vrayVersion: z.string().optional(), envFromSecret: z.string().optional(), status: z.string().optional(), // when getting this from AssetJob sync export, this is not defined. duration: z.object({}).optional(), // TODO should be { [key: string]: any }. when getting this from AssetJob sync export, this is not defined. runStatus: z.string().optional(), // when getting this from AssetJob sync export, this is not defined. runResult: z.string().optional(), // when getting this from AssetJob sync export, this is not defined. reportProgress: z.boolean().optional() // when getting this from AssetJob sync export, this is not defined. }); export type JobTask = z.infer; export const JobTaskListing = Pagination.merge( z.object({ tasks: z.array(JobTask) }) ); export type JobTaskListing = z.infer; export const QueryJobTaskProps = z.object({ jobId: z.string().uuid().optional(), runStatus: z.string().optional() }); export type QueryJobTaskProps = z.infer; const API_ROUTE = '/api/jobs/tasks'; export class JobTasks extends Route { constructor(auth: ThreekitAuthProps) { super(auth, API_ROUTE); } get(queryProps?: QueryJobTaskProps, pagination: Pagination = {}) { return get(this.context, { ...queryProps, ...pagination }); } getById(id: string) { const assetId = z.string().uuid().parse(id); return getById(this.context, assetId); } }