UNPKG

@gsb-core/core

Version:

GSB core services and classes for platform-independent web applications

52 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GsbWorkflowService = void 0; const gsb_workflow_model_1 = require("../../models/gsb-workflow.model"); class GsbWorkflowService { constructor() { this.workflows = new Map(); } async getWorkflowById(id) { // For demo purposes, return from memory or create a new one if (this.workflows.has(id)) { return this.workflows.get(id); } return null; } async saveWorkflow(workflow) { var _a; // For demo purposes, save to memory this.workflows.set((_a = workflow.id) !== null && _a !== void 0 ? _a : '', workflow); return workflow; } async testWorkflow(workflow, context) { var _a, _b, _c, _d, _e; // Mock implementation for testing // In a real implementation, this would call the backend API await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate API call // For demo purposes, we'll simulate a path through the workflow const visitedNodes = []; const visitedEdges = []; let currentNode = (_a = workflow.activities) === null || _a === void 0 ? void 0 : _a.find(a => a.activityType === gsb_workflow_model_1.ActivityType.Start); if (!currentNode) { return { visitedNodes, visitedEdges }; } while (currentNode) { visitedNodes.push((_b = currentNode.id) !== null && _b !== void 0 ? _b : ''); // Find outgoing transitions const outgoingEdges = (_c = workflow.transitions) === null || _c === void 0 ? void 0 : _c.filter(t => t.from_id === currentNode.id); if ((outgoingEdges === null || outgoingEdges === void 0 ? void 0 : outgoingEdges.length) === 0) { // No more transitions, end the path break; } // For demo, just take the first transition const nextEdge = outgoingEdges === null || outgoingEdges === void 0 ? void 0 : outgoingEdges[0]; visitedEdges.push((_d = nextEdge === null || nextEdge === void 0 ? void 0 : nextEdge.id) !== null && _d !== void 0 ? _d : ''); // Move to the next node currentNode = (_e = workflow.activities) === null || _e === void 0 ? void 0 : _e.find(a => a.id === (nextEdge === null || nextEdge === void 0 ? void 0 : nextEdge.to_id)); } return { visitedNodes, visitedEdges }; } } exports.GsbWorkflowService = GsbWorkflowService; //# sourceMappingURL=workflow.service.js.map