import { SagaTreeNode } from './TreeNode'; import { AbortError } from './AbortError'; import { throwIfCancelled } from './effects/throwIfCancelled'; import { cancel, cancelled } from './effects/canceling'; import { observable } from './effects/observable'; import { cancellable } from './effects/cancellable'; import { all, call, callFn, callPromise, delay, fork, race, spawn } from './effects/lower'; export type Optional = { [P in keyof T]?: T[P]; }; export type PromiseMapResult = { [P in keyof T]: Awaited; }; export type AnyRecord = Record; export type FnActionInput = (...args: P) => T; export type FnAction = { (...args: P): T; type: symbol; }; export type FnActionResult = { type: symbol; result: T; args: P; }; export type SagaCancelApi = { cancel: (err?: AbortError) => void; cancelled: () => boolean; }; export type SagaIterator = Promise & SagaCancelApi; export type SagaIteratorLike = Promise & Partial; export type SagaInput = (this: SagaScope & S, ...args: P) => Promise; export type Saga = (this: SagaNodeScope & ET | void, ...args: P) => SagaIterator; export type SagaFn = (this: SagaNodeScope & ET | void, ...args: P) => T; export type SagaOrFn = (this: SagaNodeScope & ET | void, ...args: P) => T | SagaIterator; export interface SagaError extends Error { node: SagaTreeNode; } export type SagaThrowCancelledEffects = { throwIfCancelled: typeof throwIfCancelled; }; export type SagaCancelingEffects = { cancel: typeof cancel; cancelled: typeof cancelled; }; export type SagaCancellableEffects = { cancellable: typeof cancellable; }; export type SagaObservableEffects = { observable: typeof observable; }; export type SagaLowerEffects = { delay: typeof delay; call: typeof call; callFn: typeof callFn; callPromise: typeof callPromise; fork: typeof fork; spawn: typeof spawn; all: typeof all; race: typeof race; }; export type SagaNodeScope = { node: SagaTreeNode; abortController: AbortController; }; export type SagaLowerEffectsScope = SagaNodeScope & SagaThrowCancelledEffects & SagaObservableEffects & SagaCancellableEffects; export type SagaHigherEffectsScope = SagaLowerEffects & SagaLowerEffectsScope; export type SagaScope = SagaHigherEffectsScope & SagaCancelingEffects; export type CancellableFinallyHandler = () => void; export type CancellableConfig = { node?: SagaTreeNode; abortController?: AbortController; onFinally?: CancellableFinallyHandler; onError?: (err: unknown) => void; }; export type CancellableOrConfig = CancellableFinallyHandler | CancellableConfig; export type SagaConfig = { plugin?: SagaPlugin; tree?: SagaTreeNode; onError?: (err: unknown, node: SagaTreeNode) => void; this?: ET; }; export type SagaPlugin = { main?: S1; lower?: S2; higher?: S3; };