@flowlab/all
Version:
A cool library focusing on handling various flows
66 lines (60 loc) • 2.05 kB
text/typescript
// src/types/runtime.ts
export enum NodeStatus {
PENDING = 'PENDING', // 待执行
RUNNING = 'RUNNING', // 执行中
COMPLETED = 'COMPLETED', // 完成
FAILED = 'FAILED', // 失败
TIMEOUT = 'TIMEOUT', // 超时
SKIPPED = 'SKIPPED', // 跳过
CANCELLED = 'CANCELLED', // 取消
COMPENSATING = 'COMPENSATING', // 补偿中
COMPENSATED = 'COMPENSATED', // 补偿完成
}
export interface IWorkflowContext {
readonly workflowId: string; // 实例 ID
readonly definitionId: string; // 定义 ID
readonly definitionName?: string;
readonly input: Readonly<Record<string, any>>;
status: NodeStatus;
variables: Record<string, any>; // 可变状态
output?: Record<string, any>;
startTime: Date;
endTime?: Date;
history: ReadonlyArray<IExecutionRecord>;
logs: string[];
// Optional context from Root/Combined
tenantId?: string;
userId?: string;
userRole?: string;
traceId?: string;
// Allows extension
[key: string]: any;
}
export interface INodeContext {
readonly workflowContext: IWorkflowContext;
readonly stepId: string; // 步骤 ID
readonly nodeId: string; // 节点 ID
readonly input: Readonly<Record<string, any>>; // 节点输入
status: NodeStatus; // 节点状态
output?: Record<string, any>; // 节点输出
startTime: Date; // 开始时间
endTime?: Date; // 结束时间
retries: number; // 当前重试次数
error?: Error; // 错误
logs: { timestamp: Date; message: string }[]; // 更多结构化的日志
// Helper methods potentially
getVariable<T = any>(name: string): T | undefined;
setVariable(name:string, value: any): void;
log(message: string): void;
}
export interface IExecutionRecord {
stepId: string; // 步骤 ID
nodeId?: string; // 节点 ID
status: NodeStatus; // 节点状态
startTime: Date; // 开始时间
endTime?: Date; // 结束时间
input?: Record<string, any>; // 可选: 记录输入
output?: Record<string, any>; // 可选: 记录输出
error?: string; // 存储错误消息
retries?: number; // 重试次数
}