API reference
import type { Either, EitherAsync } from "@ngwes/mini-fp";
/** What a step or a hook may return: an Either, or anything that resolves to one. */type StepResult<E, Ctx> = Either<E, Ctx> | PromiseLike<Either<E, Ctx>>;
type Step<E, Ctx> = (ctx: Readonly<Ctx>) => StepResult<E, Ctx>;
interface PipelineOptions<E, Ctx extends object> { /** A step returned left(error). Optional: by default the error stops the pipeline. */ onLeft?: (error: E, ctx: Readonly<Ctx>) => StepResult<E, Ctx>; /** A step threw or its promise rejected. */ onException: (exception: unknown, ctx: Readonly<Ctx>) => StepResult<E, Ctx>; /** A step changed or removed a value an earlier step had written. */ onConflictingKeys: ( keys: ReadonlyArray<keyof Ctx & string>, ctx: Readonly<Ctx>, // the context the step received next: Readonly<Ctx>, // the context the step returned ) => StepResult<E, Ctx>;}
type DynamicStepModule<E, Ctx> = | { default: Step<E, Ctx> } | { default: ReadonlyArray<Step<E, Ctx>> } | { steps: ReadonlyArray<Step<E, Ctx>> };
type LoadError = | { tag: "not-found"; path: string; cause: unknown } | { tag: "import-failed"; path: string; cause: unknown } | { tag: "invalid-export"; path: string; detail: string };Functions
Section titled “Functions”| Function | Returns |
|---|---|
Pipeline(ctx, steps, options) |
EitherAsync<E, Readonly<Ctx>> |
loadSteps<E, Ctx>(paths) |
EitherAsync<ReadonlyArray<LoadError>, ReadonlyArray<Step<E, Ctx>>> |
loadStepsFromDir<E, Ctx>(dir, options?) |
EitherAsync<ReadonlyArray<LoadError>, ReadonlyArray<Step<E, Ctx>>> |
The package exports Pipeline, loadSteps and loadStepsFromDir, and the types Step, StepResult, PipelineOptions, DynamicStepModule and LoadError.