import CloudConvert from './CloudConvert'; import { type FileResult, type Operation, type Task, type TaskEventData, type TaskStatus } from './TasksResource'; export type JobEvent = 'created' | 'updated' | 'finished' | 'failed'; export type JobStatus = 'processing' | 'finished' | 'error'; export type JobTaskStatus = Task['status'] | 'queued'; export interface JobEventData { job: Job; } export interface Job { id: string; tag: string | null; status: TaskStatus; created_at: string; started_at: string | null; ended_at: string | null; tasks: JobTask[]; } type NotPresentWhenInsideJob = 'job_id' | 'status'; export interface JobTask extends Omit { name: string; status: JobTaskStatus; } export default class JobsResource { private readonly cloudConvert; constructor(cloudConvert: CloudConvert); get(id: string, query?: object): Promise; wait(id: string): Promise; all(query?: { 'filter[status]'?: JobStatus; 'filter[tag]'?: string; include?: string; per_page?: number; page?: number; }): Promise; create(data?: JobTemplate): Promise; delete(id: string): Promise; subscribeEvent(id: string, event: string, callback: (event: JobEventData) => void): Promise; subscribeTaskEvent(id: string, event: string, callback: (event: TaskEventData) => void): void; getExportUrls(job: Job): FileResult[]; } type PossibleOperationStrings = Operation['operation']; interface NamedOperation { operation: O; } type OperationByName = Extract>; type OperationData = OperationByName['data']; interface TaskExtras extends NamedOperation { ignore_error?: boolean; } type TaskTemplate = TaskExtras & OperationData; type Distribute = U extends unknown ? TaskTemplate : never; type PossibleOperations = Distribute; interface TaskContainer { [name: string]: PossibleOperations; } export interface JobTemplate { tasks: TaskContainer; tag?: string; webhook_url?: string; } export {};