import { FutureInstance } from 'fluture'; import { Environment } from './connector'; import { Values } from './context'; import { Validator, TypeOf } from './validator'; /** * A Spec object describes the unique name of a Task, as well as validation functions to be used for run-time checking * of Input, Output, and optionally, Context values. */ export declare type Spec = { name: string; input: Validator; output: Validator; context?: { [key: string]: Validator; }; }; /** * A Conditional type that allows us to extract the design-time type information of a Spec object's `input` type, based * on it's validator function. */ export declare type InputOf = S extends Spec ? TypeOf : never; /** * A Conditional type that allows us to extract the design-time type information of a Spec object's `output` type, * based on it's validator function. */ export declare type OutputOf = S extends Spec ? TypeOf : never; /** * A Conditional type that allows the keys defined in a Task spec's `context` object to be extracted. */ export declare type ContextKeysOf = S extends Spec ? keyof S['context'] : never; /** * A Conditional type that allows the design-time type information of values in a Spec's `context` object to be * extracted. */ export declare type ContextOf = S extends Spec ? { [K in ContextKeysOf]: TypeOf; } : never; /** * A Definition allows a Task to be invoked by end-users through a simple function-call. The function expects a single * parameter, whose design-time type will be determined by the Validator function supplied for `spec.input`. * * When called, the Definition function will return a Future that resolves to a Process object. * * It is important to note that a Definition does *not* encapsulate the information required to actually _perform_ a * Task's computation. This role is performed by an `Implementation` object. */ export declare type Definition = { spec: S; (input: InputOf): FutureInstance>; }; /** * An Implementation object extends a Definition object, and includes a Function that is responsible for performing * some Tasks's computation proper. */ export declare type Implementation = Definition & { implementation: ImplementationFunction; }; /** * The signature of a Task's implementation. It accepts two arguments: * * - `input` is the input that was passed in when calling the Task * - `environment` contains functions and values that may be of use during the Task's execution, such as accessing * Context or running additional Tasks as children. */ export declare type ImplementationFunction = (input: InputOf, environment: Environment) => OutputOf | FutureInstance>; /** * A Process object encapsulates the information necessary to run a Task. A Process object is obtained by invoking a * Definition function, and is typically passed to a `run` function (such as that exposed on a Connector, Context or * Environment.) */ export declare type Process = { spec: S; id: string; parentId?: string; input: InputOf; context?: { id: string; parentId?: string; values: Values; }; }; export declare type DefineFn = (spec: S) => Definition; export declare type ImplementFn = (definition: Definition, implementation: ImplementationFunction) => Implementation; /** * Creates a Definition function from a Spec object. */ export declare const define: DefineFn; /** * Creates an Implementation object from a Definition object. * * **NOTE**: To prevent mutation of the passed in `definition` object, a new definition is created by calling `define` * internally. */ export declare const implement: ImplementFn; //# sourceMappingURL=task.d.ts.map