UNPKG

@bernierllc/temporal-workflow-ui

Version:

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

125 lines (123 loc) 3.9 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.validateTemporalWorkflow = validateTemporalWorkflow; exports.validateTaskQueue = validateTaskQueue; exports.validateRetryPolicy = validateRetryPolicy; const stage_validator_1 = require("./stage-validator"); const transition_validator_1 = require("./transition-validator"); const validation_rules_1 = require("./validation-rules"); /** * Validate a Temporal workflow * * @param workflow - Temporal workflow to validate * @returns Validation result */ function validateTemporalWorkflow(workflow) { const errors = []; // Run all validation rules for (const rule of validation_rules_1.ALL_VALIDATION_RULES) { errors.push(...rule(workflow)); } // Validate each stage for (const stage of workflow.stages) { errors.push(...(0, stage_validator_1.validateStage)(stage)); } // Validate each transition for (const transition of workflow.transitions) { errors.push(...(0, transition_validator_1.validateTransition)(transition)); } return { valid: errors.length === 0, errors, }; } /** * Validate a task queue configuration * * @param taskQueue - Task queue to validate * @returns Validation result */ function validateTaskQueue(taskQueue) { const errors = []; if (!taskQueue.id || taskQueue.id.trim() === '') { errors.push({ field: 'id', message: 'Task queue must have an ID', severity: 'error', }); } if (!taskQueue.name || taskQueue.name.trim() === '') { errors.push({ field: 'name', message: 'Task queue must have a name', severity: 'error', }); } if (taskQueue.workerCount !== undefined && taskQueue.workerCount < 0) { errors.push({ field: 'workerCount', message: 'Worker count must be >= 0', severity: 'error', }); } return { valid: errors.length === 0, errors, }; } /** * Validate a retry policy configuration * * @param policy - Retry policy to validate * @returns Validation result */ function validateRetryPolicy(policy) { const errors = []; if (policy.maximumAttempts < 0) { errors.push({ field: 'maximumAttempts', message: 'maximumAttempts must be >= 0', severity: 'error', }); } if (policy.backoffCoefficient !== undefined && policy.backoffCoefficient < 1) { errors.push({ field: 'backoffCoefficient', message: 'backoffCoefficient must be >= 1', severity: 'error', }); } if (policy.initialInterval !== undefined && policy.initialInterval < 0) { errors.push({ field: 'initialInterval', message: 'initialInterval must be >= 0', severity: 'error', }); } if (policy.maximumInterval !== undefined && policy.maximumInterval < 0) { errors.push({ field: 'maximumInterval', message: 'maximumInterval must be >= 0', severity: 'error', }); } if (policy.initialInterval !== undefined && policy.maximumInterval !== undefined && policy.maximumInterval < policy.initialInterval) { errors.push({ field: 'maximumInterval', message: 'maximumInterval must be >= initialInterval', severity: 'error', }); } return { valid: errors.length === 0, errors, }; }