UNPKG

@hotmeshio/hotmesh

Version:

Serverless Workflow

84 lines (83 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WorkflowService = void 0; const context_1 = require("./context"); const didRun_1 = require("./didRun"); const isSideEffectAllowed_1 = require("./isSideEffectAllowed"); const trace_1 = require("./trace"); const enrich_1 = require("./enrich"); const emit_1 = require("./emit"); const execChild_1 = require("./execChild"); const proxyActivities_1 = require("./proxyActivities"); const searchMethods_1 = require("./searchMethods"); const random_1 = require("./random"); const signal_1 = require("./signal"); const hook_1 = require("./hook"); const interrupt_1 = require("./interrupt"); const all_1 = require("./all"); const sleepFor_1 = require("./sleepFor"); const waitFor_1 = require("./waitFor"); const common_1 = require("./common"); /** * The WorkflowService class provides a set of static methods to be used within a workflow function. * These methods ensure deterministic replay, persistence of state, and error handling across * re-entrant workflow executions. * * By refactoring the original single-file implementation into submodules, * we maintain clear separation of concerns and improved maintainability, * while preserving type information and full functionality. * * @example * ```typescript * import { MeshFlow } from '@hotmeshio/hotmesh'; * * export async function waitForExample(): Promise<[boolean, number]> { * const [s1, s2] = await Promise.all([ * MeshFlow.workflow.waitFor<boolean>('my-sig-nal-1'), * MeshFlow.workflow.waitFor<number>('my-sig-nal-2') * ]); * return [s1, s2]; * } * ``` */ class WorkflowService { /** * @private * The constructor is private to prevent instantiation; * all methods are static. */ constructor() { } /** * Return a handle to the HotMesh client hosting the workflow execution. * @returns {Promise<HotMesh>} The HotMesh client instance. */ static async getHotMesh() { const store = common_1.asyncLocalStorage.getStore(); const workflowTopic = store.get('workflowTopic'); const connection = store.get('connection'); const namespace = store.get('namespace'); return await common_1.WorkerService.getHotMesh(workflowTopic, { connection, namespace, }); } } WorkflowService.getContext = context_1.getContext; WorkflowService.didRun = didRun_1.didRun; WorkflowService.isSideEffectAllowed = isSideEffectAllowed_1.isSideEffectAllowed; WorkflowService.trace = trace_1.trace; WorkflowService.enrich = enrich_1.enrich; WorkflowService.emit = emit_1.emit; WorkflowService.execChild = execChild_1.execChild; WorkflowService.executeChild = execChild_1.executeChild; WorkflowService.startChild = execChild_1.startChild; WorkflowService.proxyActivities = proxyActivities_1.proxyActivities; WorkflowService.search = searchMethods_1.search; WorkflowService.random = random_1.random; WorkflowService.signal = signal_1.signal; WorkflowService.hook = hook_1.hook; WorkflowService.interrupt = interrupt_1.interrupt; WorkflowService.all = all_1.all; WorkflowService.sleepFor = sleepFor_1.sleepFor; WorkflowService.waitFor = waitFor_1.waitFor; exports.WorkflowService = WorkflowService;