import { Logger } from "./logger"; import { JsonObj } from "./types"; /** * A Task encapsulates a unit of work * * args constructor parameter is mandatory if Args type given * args constructor parameter is optional if no Args type given */ export declare abstract class Task { protected readonly args: Args; /** * * @param {Args} args */ constructor(...args: (unknown extends Args ? [] : [Args])); abstract run(ctx: Task.Context): Promise; log(): unknown; } export declare namespace Task { /** * Context using proxy so we can extend arbitrarily */ class ContextProxy { private readonly opts; readonly logger: Logger; private readonly modules; private readonly _proxy; constructor(opts: JsonObj); run(task: Task): Promise; extend(deps: JsonObj): this; } /** * used to mask the Proxy behaviour * and enable Typescript to know what Modules should be accessible */ interface ContextCtor { new (modules: T): Context; } /** * Context is provided to running tasks * it optimistically provides access to Modules */ export type Context = T & ContextProxy; export const Context: ContextCtor; /** * used to enable Modules to propagate the Context * and have access to runTask */ export abstract class Runner { private context?; abstract clone(): Runner; withContext(ctx: Context): Runner; protected runTask(task: Task): Promise; } export {}; }