UNPKG

@bernierllc/temporal-workflow-ui

Version:

Thin domain-specific wrapper around @bernierllc/generic-workflow-ui for Temporal workflows

99 lines (97 loc) 3.17 kB
"use strict"; /* Copyright (c) 2025 Bernier LLC This file is licensed to the client under a limited-use license. The client may use and modify this code *only within the scope of the project it was delivered for*. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.temporalWorkflowToJSON = temporalWorkflowToJSON; /** * Convert Temporal workflow to JSON definition (n8n-style) * * @param workflow - Temporal workflow * @returns JSON workflow definition */ function temporalWorkflowToJSON(workflow) { const nodes = workflow.stages.map((stage, index) => temporalStageToJSONNode(stage, index)); const connections = buildConnectionsFromTransitions(workflow.transitions); return { name: workflow.name, nodes, connections, settings: { timezone: 'UTC', tags: ['temporal'], }, meta: { instanceId: workflow.id, }, staticData: { defaultTaskQueue: workflow.defaultTaskQueue, workflowTimeout: workflow.workflowTimeout, searchAttributes: workflow.searchAttributes, }, }; } /** * Convert Temporal stage to JSON node * * @param stage - Temporal workflow stage * @param index - Node index for positioning * @returns JSON workflow node */ function temporalStageToJSONNode(stage, index) { // Calculate position in a grid layout const gridX = (index % 4) * 300; const gridY = Math.floor(index / 4) * 200; return { id: stage.id, name: stage.name, type: stage.type, position: [gridX, gridY], notes: stage.description, parameters: stage.metadata.parameters || {}, data: { temporal: stage.metadata, icon: stage.icon, color: stage.color, }, }; } /** * Build connections object from transitions * * @param transitions - Temporal workflow transitions * @returns Connections object */ function buildConnectionsFromTransitions(transitions) { const connections = {}; for (const transition of transitions) { const fromId = transition.from; // Initialize connections for this node if not exists if (!connections[fromId]) { connections[fromId] = {}; } // Determine output type based on condition const outputType = transition.condition ? 'conditional' : 'main'; // Initialize output type array if not exists if (!connections[fromId][outputType]) { connections[fromId][outputType] = [[]]; } // Add connection const connection = { node: transition.to, type: 'main', index: 0, data: { condition: transition.condition, metadata: transition.metadata, name: transition.name, description: transition.description, }, }; connections[fromId][outputType][0].push(connection); } return connections; }