arvo-event-handler
Version:
A complete set of orthogonal event handler and orchestration primitives for Arvo based applications, featuring declarative state machines (XState), imperative resumables for agentic workflows, contract-based routing, OpenTelemetry observability, and in-me
65 lines (64 loc) • 3.15 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.servicesValidation = exports.areServiceContractsUnique = void 0;
var uuid_1 = require("uuid");
var errors_1 = require("../errors");
var types_1 = require("./types");
/**
* Validates that all service contracts have unique URIs.
*
* Ensures no duplicate contract URIs exist in the service collection.
* Multiple versions of the same contract (same URI) are not permitted as
* they create ambiguity in event routing and contract resolution.
*/
var areServiceContractsUnique = function (contracts) {
var uriToKeyMap = {};
for (var _i = 0, _a = Object.entries(contracts); _i < _a.length; _i++) {
var _b = _a[_i], key = _b[0], contract = _b[1];
if (uriToKeyMap[contract.uri]) {
return {
result: false,
keys: [key, uriToKeyMap[contract.uri]],
contractUri: contract.uri,
};
}
uriToKeyMap[contract.uri] = key;
}
return {
result: true,
};
};
exports.areServiceContractsUnique = areServiceContractsUnique;
/**
* Validates service contracts for orchestration handlers.
*
* Performs two critical validations:
* 1. Ensures all service contracts have unique URIs (no duplicate contracts)
* 2. Prevents circular dependencies (self contract not registered as service)
*
* These validations prevent configuration errors that would cause runtime
* failures or infinite execution loops in orchestration workflows.
*/
var servicesValidation = function (contracts, _handlerType) {
var _a;
var __areServiceContractsUnique = (0, exports.areServiceContractsUnique)(contracts.services);
if (!__areServiceContractsUnique.result) {
throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", the service contracts must have unique URIs. Multiple versions of the same contract are not allow. The contracts '").concat(__areServiceContractsUnique.keys[0], "' and '").concat(__areServiceContractsUnique.keys[1], "' have the same URI '").concat(__areServiceContractsUnique.contractUri, "'"));
}
var __checkIfSelfIsAService = (0, exports.areServiceContractsUnique)(__assign(__assign({}, contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = contracts.self, _a)));
if (!__checkIfSelfIsAService.result) {
throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", Circular dependency detected: Machine with URI '").concat(contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
}
};
exports.servicesValidation = servicesValidation;