UNPKG

@just-in/core

Version:

A TypeScript-first framework for building adaptive digital health interventions.

26 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeStep = executeStep; const logger_manager_1 = require("../logger/logger-manager"); /** * Executes a single step function, logging errors and results. * * @param step - The current step being executed (e.g., SHOULD_DECIDE, DECIDE, DO_ACTION). * @param fn - The function to execute for the step. * @returns {Promise<ExecuteStepReturn>} The result of the step execution. */ async function executeStep(step, fn) { const timestamp = new Date(); try { const result = await fn(); if (!['success', 'stop', 'error'].includes(result.status)) { throw new Error(`Invalid status "${result.status}" in step "${step}".`); } return { step, result, timestamp }; } catch (error) { logger_manager_1.Log.error(`Error in step "${step}": ${error}, stack: ${error instanceof Error ? error.stack : 'No stack trace available'}`); return { step, result: { status: 'error', error }, timestamp }; } } //# sourceMappingURL=steps.helpers.js.map