@flowlab/all
Version:
A cool library focusing on handling various flows
52 lines (51 loc) • 2.31 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWorkflowContext = createWorkflowContext;
exports.createNodeContext = createNodeContext;
// Implementation for createWorkflowContext, createNodeContext
var uuid_1 = require("uuid");
var runtime_1 = require("../types/runtime");
function createWorkflowContext(definitionId, definitionName, input, extras) {
if (extras === void 0) { extras = {}; }
return __assign({ workflowId: (0, uuid_1.v4)(), // Generate unique instance ID
definitionId: definitionId, definitionName: definitionName, input: Object.freeze(__assign({}, input)), status: runtime_1.NodeStatus.PENDING, variables: {}, startTime: new Date(), history: [], logs: [] }, extras);
}
function createNodeContext(workflowContext, stepId, nodeId, retryAttempt // Pass retry attempt
) {
// Provide helper functions bound to the workflow context
var getVariable = function (name) { return workflowContext.variables[name]; };
var setVariable = function (name, value) { workflowContext.variables[name] = value; };
var log = function (message) {
var logEntry = { timestamp: new Date(), message: message };
// Add to both node-specific and workflow logs?
nodeContext.logs.push(logEntry); // Need temp 'any' due to initialization order
workflowContext.logs.push("[".concat(stepId, "|").concat(nodeId, "] ").concat(message));
};
var nodeContext = {
workflowContext: workflowContext,
stepId: stepId,
nodeId: nodeId,
input: {}, // This will be populated by executor using inputMapping
status: runtime_1.NodeStatus.PENDING,
output: undefined,
startTime: new Date(),
retries: retryAttempt,
logs: [],
// Add helper methods
getVariable: getVariable,
setVariable: setVariable,
log: log,
};
return nodeContext;
}