import { Logger, PdfEngine, PdfEngineMethodArgs, PdfEngineMethodName, PdfEngineMethodReturnType, TaskReturn } from '@elhalawany/models';
/**
* Request body that represent method calls of PdfEngine, it contains the
* method name and arguments
*/
export type PdfEngineMethodRequestBody = {
[P in PdfEngineMethodName]: {
name: P;
args: PdfEngineMethodArgs
;
};
}[PdfEngineMethodName];
/**
* Request body that represent method calls of PdfEngine, it contains the
* method name and arguments
*/
export type SpecificExecuteRequest = {
id: string;
type: 'ExecuteRequest';
data: {
name: M;
args: PdfEngineMethodArgs;
};
};
/**
* Response body that represent return value of PdfEngine
*/
export type PdfEngineMethodResponseBody = {
[P in PdfEngineMethodName]: TaskReturn>;
}[PdfEngineMethodName];
/**
* Request that abort the specified task
*/
export interface AbortRequest {
/**
* message id
*/
id: string;
/**
* request type
*/
type: 'AbortRequest';
}
/**
* Request that execute pdf engine method
*/
export interface ExecuteRequest {
/**
* message id
*/
id: string;
/**
* request type
*/
type: 'ExecuteRequest';
/**
* request body
*/
data: PdfEngineMethodRequestBody;
}
/**
* Response that execute pdf engine method
*/
export interface ExecuteResponse {
/**
* message id
*/
id: string;
/**
* response type
*/
type: 'ExecuteResponse';
/**
* response body
*/
data: PdfEngineMethodResponseBody;
}
/**
* Response that indicate progress of the task
*/
export interface ExecuteProgress {
/**
* message id
*/
id: string;
/**
* response type
*/
type: 'ExecuteProgress';
/**
* response body
*/
data: T;
}
/**
* Response that indicate engine is ready
*/
export interface ReadyResponse {
/**
* message id
*/
id: string;
/**
* response type
*/
type: 'ReadyResponse';
}
/**
* Request type
*/
export type Request = ExecuteRequest | AbortRequest;
/**
* Response type
*/
export type Response = ExecuteResponse | ReadyResponse | ExecuteProgress;
/**
* Pdf engine runner, it will execute pdf engine based on the request it received and
* send back the response with post message
*/
export declare class EngineRunner {
logger: Logger;
engine: PdfEngine | undefined;
/** All running tasks, keyed by the message-id coming from the UI */
private tasks;
/**
* Last time we yielded to the event loop
*/
private lastYield;
/**
* Ids of tasks that have been cancelled
*/
private cancelledIds;
/**
* Create instance of EngineRunnder
* @param logger - logger instance
*/
constructor(logger?: Logger);
/**
* Listening on post message
*/
listen(): void;
/**
* Handle post message
*/
handle(evt: MessageEvent): void;
/**
* Send the ready response when pdf engine is ready
* @returns
*
* @protected
*/
ready(): void;
private abort;
private maybeYield;
/**
* Execute the request
* @param request - request that represent the pdf engine call
* @returns
*
* @protected
*/
execute: (request: ExecuteRequest) => Promise;
/**
* Send back the response
* @param response - response that needs sent back
*
* @protected
*/
respond(response: Response): void;
}