import Job, { JobData } from './Job'; import DataEntity, { EntityEvents } from '../lib/DataEntity'; import { ProjectParams } from './types'; import ErrorData from '../types/ErrorData'; import ProjectsApi from './index'; import { Logger } from '../lib/DefaultLogger'; export type ProjectStatus = 'pending' | 'queued' | 'processing' | 'completed' | 'failed' | 'canceled'; /** * @inline */ export interface ProjectData { id: string; startedAt: Date; params: ProjectParams; queuePosition: number; status: ProjectStatus; error?: ErrorData; } /** @inline */ export interface SerializedProject extends ProjectData { jobs: JobData[]; } export interface ProjectEventMap extends EntityEvents { progress: number; completed: string[]; failed: ErrorData; jobCompleted: Job; jobFailed: Job; } export interface ProjectOptions { api: ProjectsApi; logger: Logger; } declare class Project extends DataEntity { private _jobs; private _lastEmitedProgress; private readonly _api; private readonly _logger; private _timeout; private _failedSyncAttempts; constructor(data: ProjectParams, options: ProjectOptions); get id(): string; get params(): ProjectParams; get status(): ProjectStatus; get finished(): boolean; get error(): ErrorData | undefined; /** * Progress of the project in percentage (0-100). */ get progress(): number; get queuePosition(): number; /** * List of jobs in the project. Note that jobs will be added to this list as * workers start processing them. So initially this list will be empty. * Subscribe to project `updated` event to get notified about any update, including new jobs. * @example * project.on('updated', (keys) => { * if (keys.includes('jobs')) { * // Project jobs have been updated * } * }); */ get jobs(): Job[]; /** * List of result URLs for all completed jobs in the project. */ get resultUrls(): string[]; /** * Wait for the project to complete, then return the result URLs, or throw an error if the project fails. * @returns Promise - Promise that resolves to the list of result URLs * @throws ErrorData */ waitForCompletion(): Promise; /** * Cancel the project. This will cancel all jobs in the project. */ cancel(): Promise; /** * Find a job by id * @param id */ job(id: string): Job | undefined; private handleUpdated; /** * This is internal method to add a job to the project. Do not call this directly. * @internal * @param data */ _addJob(data: JobData | Job): Job; private _handleJobFinished; private _checkForTimeout; /** * Sync project data with the data received from the REST API. * @internal */ _syncToServer(): Promise; /** * Get full project data snapshot. Can be used to serialize the project and store it in a database. */ toJSON(): SerializedProject; } export default Project;