UNPKG

arvo-event-handler

Version:

Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.

59 lines (58 loc) 2.86 kB
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createArvoOrchestrator = void 0; var _1 = require("."); var MachineExecutionEngine_1 = require("../MachineExecutionEngine"); var MachineRegistry_1 = require("../MachineRegistry"); /** * Creates a new Arvo orchestrator instance with default components. * For custom components, use ArvoOrchestrator constructor directly. * * @param config - Orchestrator configuration * @param config.memory - State persistence interface for storing machine states * @param config.executionunits - Cost units for execution tracking * @param config.machines - Array of state machines to manage. Their resource locking flags determine orchestrator's locking behavior * @param config.systemErrorDomain - An optional array of system error domain overrides * @returns Configured ArvoOrchestrator instance with default registry and execution engine * * @remarks * The orchestrator's resource locking is enabled if any machine requires it. Locking is needed when: * - Machine contains parallel states where multiple states can be active simultaneously * - Race conditions need to be prevented in concurrent processing * - State consistency must be maintained across distributed executions * * @example * ```typescript * const orchestrator = createArvoOrchestrator({ * memory: new SimpleMachineMemory() // or, any other IMachineMemory implementation, * executionunits: 1, * machines: [machineA, machineB] * }); * ``` */ var createArvoOrchestrator = function (_a) { var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain; if (!(machines === null || machines === void 0 ? void 0 : machines.length)) { throw new Error('At least one machine must be provided'); } var registry = new (MachineRegistry_1.MachineRegistry.bind.apply(MachineRegistry_1.MachineRegistry, __spreadArray([void 0], machines, false)))(); var requiresResourceLocking = machines.some(function (machine) { return machine.requiresResourceLocking; }); return new _1.ArvoOrchestrator({ executionunits: executionunits, memory: memory, registry: registry, executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(), requiresResourceLocking: requiresResourceLocking, systemErrorDomain: systemErrorDomain, }); }; exports.createArvoOrchestrator = createArvoOrchestrator;