import type { IssuePhase, JobStatus } from '../services/job/types.js'; import type { ImportEntity } from '../services/types.js'; import type { JobView } from '../web/jobView.js'; /** * What the page of one job shows (§ 8.2), decided from the job alone. The page * writes the words (`_()`); this module says WHICH screen, WHICH buttons and * WHAT numbers, so the table of states is tested without a browser. */ export type ScreenState = 'uploading' | 'uploaded' | 'validating' /** Checked, with errors. */ | 'invalid' /** Checked, no errors: it can start. */ | 'valid' /** Accepted, waiting for a worker. */ | 'queued' /** A resumed job, waiting for a worker. */ | 'resuming' /** The check at the start of the import (D-33). */ | 'rechecking' | 'running' | 'completed' | 'stopped' | 'interrupted' | 'failed' | 'canceled'; export type ScreenAction = 'start' | 'cancel' | 'resume' | 'recheck' | 'uploadNew' | 'downloadErrors' | 'delete'; /** Why Start or Resume cannot be pressed now (§ 8.2, § 8.3). */ export type Blocker = { kind: 'importRunning'; entity: ImportEntity; } | { kind: 'openJob'; entity: ImportEntity; }; export type ScreenNote = { kind: 'cancelRequested'; } /** Waiting for a worker for too long (J4). */ | { kind: 'notStarted'; } /** The worker is waiting for the event queue (§ 8.5). */ | { kind: 'waiting'; } /** The check ran while another import was queued or running (§ 8.4). */ | { kind: 'overlapped'; entity: ImportEntity; } | { kind: 'recheckFoundErrors'; } | { kind: 'pageAddresses'; rebuilt: number; } /** The reason the server gives for a job that stopped, failed or was interrupted. */ | { kind: 'reason'; text: string; }; export type Progress = /** The share of the file read. Two passes: the rows, then the store. */ { kind: 'file'; pass: 1 | 2; percent: number; } | { kind: 'rows'; done: number; total: number; percent: number; }; export interface Screen { state: ScreenState; /** The page asks again every few seconds while this is true. */ live: boolean; progress: Progress | null; actions: ScreenAction[]; blockedBy: Blocker | null; notes: ScreenNote[]; /** The table of problems to show, and which phase it is from. */ problems: { phase: IssuePhase; } | null; } export interface ScreenContext { /** The jobs of `GET /import-open-jobs` (this one may be among them). */ others: readonly JobView[]; nowMs: number; } /** After this long in `uploaded` or `queued` the page suspects that no worker runs (J4). */ export declare const NOT_STARTED_AFTER_MS: number; /** Whether the page keeps asking about a job in this status. */ export declare const isLive: (status: JobStatus) => boolean; /** * The file is read twice: first for what the rows say, then against the store. * The percentage covers both, so the bar does not fall back to zero in the middle. */ export declare function fileProgress(job: JobView): Progress; export declare function rowProgress(job: JobView): Progress; export declare function describeJob(job: JobView, context: ScreenContext): Screen;