Skip to main content

@getriebe/workflow

Execute workflow definitions and snapshot running instances.

Source revision 49560371f6cd34d30383df5619df46969c594ae4.

Additional import paths:

  • @getriebe/workflow/node
export interface ActivityLoop {
readonly condition: WorkflowExpression;
readonly testBefore: boolean;
readonly maximum?: number;
}
export declare const EXPRESSION_SCRIPT_FORMAT = "application/vnd.getriebe.expression-v1";
export declare const JAVASCRIPT_SCRIPT_FORMAT = "text/javascript";
export type MultiInstance = {
readonly inputField: string;
readonly outputField: string;
readonly completionCondition?: MultiInstanceCompletionCondition;
readonly sequential?: boolean;
} & ({
readonly resourceId: string;
readonly roleByItem?: never;
} | {
readonly resourceId?: never;
readonly roleByItem: Readonly<Record<string, string>>;
});
export interface MultiInstanceCompletionCondition extends WorkflowExpression {
readonly outputItem: string;
}
export interface ParallelMultiInstance {
readonly inputField: string;
readonly outputField: string;
readonly completionCondition?: MultiInstanceCompletionCondition;
readonly sequential?: false;
readonly resourceId?: never;
readonly roleByItem: Readonly<Record<string, string>>;
}
export interface ScriptEvaluator {
readonly format: string;
compile(source: string, inputs: Readonly<Record<string, ValueKind>>, output: ValueKind): (inputs: Readonly<Record<string, EncodedProcessValue>>) => unknown;
}
export interface SequenceFlow {
readonly id: string;
readonly source: string;
readonly target: string;
readonly condition?: WorkflowExpression;
}
export declare function splitCalledElementId(id: string): {
readonly callId: string;
readonly elementId: string;
} | undefined;
export interface WaitingParallelJoin {
readonly nodeId: string;
readonly arrived: readonly string[];
readonly waitingFor: readonly string[];
readonly scopeExecutionId?: string;
}
export declare class Workflow {
constructor(definition: WorkflowDefinition, options?: WorkflowOptions);
start(): WorkflowInstance;
startMessage(type: MessageType, payload: unknown): {
readonly instance: WorkflowInstance;
readonly data: ProcessData;
};
waitingParallelJoins(instance: WorkflowInstance): readonly WaitingParallelJoin[];
advance(instance: WorkflowInstance, rootData?: ProcessData, options?: {
readonly now?: number;
}): WorkflowAdvance;
writeScopeData(instance: WorkflowInstance, executionId: string, updates: ProcessData): WorkflowInstance;
faultServiceActivity(instance: WorkflowInstance, id: string, errorCode: string): WorkflowAdvance;
completeActivity(instance: WorkflowInstance, id: string, result?: boolean): WorkflowAdvance;
fireDueTimer(instance: WorkflowInstance, now: number, id?: string | undefined): WorkflowTimerResult;
restore(snapshot: string): WorkflowInstance;
}
export interface WorkflowActivity {
readonly id: string;
readonly nodeId: string;
readonly kind: WorkflowActivityKind;
readonly iteration: number;
readonly dueAt?: number;
readonly reminderAt?: number;
readonly scopeExecutionId?: string;
readonly roundInputs?: Readonly<Record<string, EncodedProcessValue>>;
readonly multiInstance?: {
readonly roundId: string;
readonly index: number;
readonly item: string;
readonly resourceId: string;
};
}
export declare class WorkflowActivityError extends Error {
readonly code = "not-active";
constructor(id: string);
}
export type WorkflowActivityKind = "userTask" | "serviceTask" | "sendTask" | "messageCatch";
export declare class WorkflowActivityResultError extends TypeError {
constructor(message: string);
}
export interface WorkflowAdvance {
readonly instance: WorkflowInstance;
readonly executedNodeId?: string;
readonly activatedActivity?: WorkflowActivity;
readonly activatedActivities?: readonly WorkflowActivity[];
readonly completedActivity?: WorkflowActivity;
readonly multiInstanceCompletion?: {
readonly vote: boolean;
readonly withdrawnActivities: readonly WorkflowActivity[];
};
readonly completionConditionError?: {
readonly nodeId: string;
readonly message: string;
};
readonly dataUpdates?: ProcessData;
readonly decision?: WorkflowDecision;
readonly script?: WorkflowScriptCompletion;
readonly callStarted?: WorkflowCallExecution;
readonly callReturn?: WorkflowCallExecution;
readonly modeledError?: WorkflowModeledError;
readonly termination?: ScopeWithdrawal;
}
export interface WorkflowCallActivity {
readonly id: string;
readonly kind: "callActivity";
readonly target: WorkflowDefinition;
readonly inputs: readonly WorkflowCallBinding[];
readonly outputs: readonly WorkflowCallBinding[];
}
export interface WorkflowCallBinding {
readonly source: string;
readonly target: string;
readonly kind: ValueKind;
}
export interface WorkflowCallExecution {
readonly nodeId: string;
readonly executionId: string;
readonly targetVersionId: string;
readonly scopeExecutionId?: string;
}
export interface WorkflowDecision {
readonly executionId: string;
readonly nodeId: string;
readonly tableId: string;
readonly ruleId: string;
readonly scopeExecutionId?: string;
}
export interface WorkflowDecisionTable {
readonly tableId: string;
readonly inputField: string;
readonly outputField: string;
readonly rules: readonly DecisionRule[];
}
export interface WorkflowDefinition extends WorkflowScope {
readonly id: string;
}
export declare class WorkflowDefinitionError extends Error {
readonly code: WorkflowDefinitionErrorCode;
readonly elementId: string | undefined;
constructor(code: WorkflowDefinitionErrorCode, message: string, elementId?: string, options?: ErrorOptions);
}
export type WorkflowDefinitionErrorCode = "invalid-id" | "duplicate-id" | "unknown-node" | "unsupported-node" | "invalid-start" | "invalid-connections" | "invalid-condition" | "invalid-loop" | "invalid-activity" | "invalid-timer" | "invalid-call-binding" | "invalid-bpmn-error" | "invalid-multi-instance" | "disconnected";
export interface WorkflowExpression {
readonly source: string;
readonly language: string;
}
export type WorkflowFailure = {
readonly code: "deadlock";
} | {
readonly code: "unhandled-bpmn-error";
readonly nodeId: string;
readonly errorCode: string;
} | {
readonly code: "firing-rejected" | "no-matching-route";
readonly nodeId: string;
} | {
readonly code: "condition-error" | "invalid-multi-instance-input" | "invalid-decision-input" | "script-task-error" | "invalid-call-input" | "invalid-call-output";
readonly nodeId: string;
readonly message: string;
};
declare class WorkflowInstance {
readonly activities: readonly WorkflowActivity[];
readonly scopeExecutions: readonly WorkflowScopeExecution[];
readonly intermediateTimers: readonly WorkflowIntermediateTimer[];
readonly scopeTimers: readonly WorkflowScopeTimer[];
constructor(state: State, definitionKey: string, activities: readonly WorkflowActivity[], scopeExecutions: readonly WorkflowScopeExecution[], intermediateTimers: readonly WorkflowIntermediateTimer[], scopeTimers: readonly WorkflowScopeTimer[]);
get status(): WorkflowStatus;
get reachedEnds(): readonly string[];
get nextTimer(): WorkflowTimer | undefined;
scopeDeadlines(scopeExecutionId: string | undefined): readonly WorkflowScopeTimer[];
effectiveDueAt(activity: WorkflowActivity): number | undefined;
get failure(): WorkflowFailure | undefined;
snapshot(): string;
}
export interface WorkflowIntermediateTimer extends WorkflowTimer {
readonly nodeId: string;
readonly scopeExecutionId?: string;
}
export interface WorkflowModeledError {
readonly errorCode: string;
readonly throwNodeId: string;
readonly scopeExecutionId?: string;
readonly handlerNodeId?: string;
readonly handlerExecutionId?: string;
readonly handlerActivityId?: string;
}
export type WorkflowNode = FlowNode & ({
readonly kind: "start" | "step" | "end" | "xor" | "and" | Exclude<WorkflowActivityKind, "serviceTask">;
} | {
readonly kind: "serviceTask";
readonly errorCodes?: readonly string[];
} | {
readonly kind: "businessRuleTask";
readonly decision: WorkflowDecisionTable;
} | WorkflowMessageStart | WorkflowScriptTask | WorkflowCallActivity | {
readonly kind: "subProcess";
readonly scope: WorkflowScope;
} | {
readonly kind: "intermediateTimer";
readonly durationMs: number;
} | {
readonly kind: "terminateEnd";
} | {
readonly kind: "errorEnd";
readonly errorCode: string;
} | {
readonly kind: "boundaryError";
readonly attachedTo: string;
readonly errorCode: string;
} | {
readonly kind: "boundaryTimer";
readonly attachedTo: string;
readonly interrupting?: boolean;
readonly durationMs: number;
});
export interface WorkflowOptions {
readonly scriptEvaluators?: readonly ScriptEvaluator[];
}
export interface WorkflowScope {
readonly nodes: readonly WorkflowNode[];
readonly flows: readonly SequenceFlow[];
readonly fields?: Readonly<Record<string, ValueKind>>;
}
export interface WorkflowScopeExecution {
readonly id: string;
readonly nodeId: string;
readonly parentId?: string;
readonly targetVersionId?: string;
readonly fields: Readonly<Record<string, ValueKind>>;
readonly data: ProcessData;
}
export interface WorkflowScopeTimer extends WorkflowIntermediateTimer {
readonly scopeExecutionId: string;
}
export interface WorkflowScriptCompletion {
readonly executionId: string;
readonly nodeId: string;
readonly scopeExecutionId?: string;
}
export interface WorkflowScriptTask {
readonly id: string;
readonly kind: "scriptTask";
readonly scriptFormat: string;
readonly script: string;
readonly inputs: readonly {
readonly name: string;
readonly kind: ValueKind;
readonly source: string;
}[];
readonly outputs: readonly [
{
readonly name: string;
readonly kind: ValueKind;
readonly target: string;
}
];
}
export type WorkflowStatus = "running" | "completed" | "failed";
export declare class WorkflowTimeError extends RangeError {
constructor(message: string);
}
export interface WorkflowTimer {
readonly activityId: string;
readonly dueAt: number;
}
export type WorkflowTimerResult = {
readonly status: "ignored" | "failed";
readonly instance: WorkflowInstance;
} | {
readonly status: "fired";
readonly instance: WorkflowInstance;
readonly timer: WorkflowTimer;
readonly executedNodeId: string;
readonly termination?: ScopeWithdrawal;
};