arvo-event-handler 3.0.11 → 3.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,9 +25,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.setupArvoMachine = setupArvoMachine;
27
27
  var arvo_core_1 = require("arvo-core");
28
- var uuid_1 = require("uuid");
29
28
  var xstate_1 = require("xstate");
30
29
  var _1 = __importDefault(require("."));
30
+ var servicesValidation_1 = require("../ArvoOrchestrationUtils/servicesValidation");
31
31
  var object_1 = require("../utils/object");
32
32
  var utils_1 = require("./utils");
33
33
  /**
@@ -194,8 +194,7 @@ var utils_1 = require("./utils");
194
194
  * 4. Using XState features like `emit` bound with Arvo contracts for event emitting and event handling via transitions
195
195
  */
196
196
  function setupArvoMachine(param) {
197
- var _a;
198
- var _b, _c;
197
+ var _a, _b;
199
198
  var createConfigErrorMessage = function (type) {
200
199
  return (0, arvo_core_1.cleanString)("\n Configuration Error: '".concat(type, "' not supported in Arvo machines\n \n Arvo machines do not support XState ").concat(type === 'actor' ? 'actors' : 'delay transitions', " as they introduce asynchronous behavior.\n \n To fix:\n 1. Remove the '").concat(type, "' configuration\n 2. Use Arvo's event-driven patterns instead for asynchronous operations\n "));
201
200
  };
@@ -205,18 +204,11 @@ function setupArvoMachine(param) {
205
204
  if (param.delays) {
206
205
  throw new Error(createConfigErrorMessage('delays'));
207
206
  }
208
- if ((_b = param.actions) === null || _b === void 0 ? void 0 : _b.enqueueArvoEvent) {
207
+ if ((_a = param.actions) === null || _a === void 0 ? void 0 : _a.enqueueArvoEvent) {
209
208
  throw new Error((0, arvo_core_1.cleanString)("\n Configuration Error: Reserved action name 'enqueueArvoEvent'\n \n 'enqueueArvoEvent' is an internal Arvo system action and cannot be overridden.\n \n To fix: Use a different name for your action, such as:\n - 'queueCustomEvent'\n - 'scheduleEvent'\n - 'dispatchEvent'\n "));
210
209
  }
211
- var __areServiceContractsUnique = (0, utils_1.areServiceContractsUnique)(param.contracts.services);
212
- if (!__areServiceContractsUnique.result) {
213
- throw new Error("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, "'"));
214
- }
215
- var __checkIfSelfIsAService = (0, utils_1.areServiceContractsUnique)(__assign(__assign({}, param.contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = param.contracts.self, _a)));
216
- if (!__checkIfSelfIsAService.result) {
217
- throw new Error("Circular dependency detected: Machine with URI '".concat(param.contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
218
- }
219
- var combinedActions = __assign(__assign({}, ((_c = param.actions) !== null && _c !== void 0 ? _c : {})), { enqueueArvoEvent: (0, xstate_1.assign)(function (_a, param) {
210
+ (0, servicesValidation_1.servicesValidation)(param.contracts, 'machine');
211
+ var combinedActions = __assign(__assign({}, ((_b = param.actions) !== null && _b !== void 0 ? _b : {})), { enqueueArvoEvent: (0, xstate_1.assign)(function (_a, param) {
220
212
  var _b, _c, _d, _e, _f;
221
213
  var context = _a.context;
222
214
  return (__assign(__assign({}, (context !== null && context !== void 0 ? context : {})), { arvo$$: __assign(__assign({}, ((_b = context === null || context === void 0 ? void 0 : context.arvo$$) !== null && _b !== void 0 ? _b : {})), { volatile$$: __assign(__assign({}, ((_d = (_c = context === null || context === void 0 ? void 0 : context.arvo$$) === null || _c === void 0 ? void 0 : _c.volatile$$) !== null && _d !== void 0 ? _d : {})), { eventQueue$$: __spreadArray(__spreadArray([], (((_f = (_e = context === null || context === void 0 ? void 0 : context.arvo$$) === null || _e === void 0 ? void 0 : _e.volatile$$) === null || _f === void 0 ? void 0 : _f.eventQueue$$) || []), true), [param], false) }) }) }));
@@ -1,4 +1,3 @@
1
- import type { ArvoContract, VersionedArvoContract } from 'arvo-core';
2
1
  import type { MachineConfig } from 'xstate';
3
2
  /**
4
3
  * Detects if an XState machine configuration contains any parallel states.
@@ -22,19 +21,3 @@ import type { MachineConfig } from 'xstate';
22
21
  * const hasParallel = detectParallelStates(machine) // Returns true
23
22
  */
24
23
  export declare const detectParallelStates: (config?: MachineConfig<any, any, any, any, any, any, any, any, any, any, any>) => boolean;
25
- /**
26
- * Validates that all service contracts in a collection have unique URIs.
27
- *
28
- * Iterates through the provided contracts and checks if any URI appears more than once.
29
- * Multiple versions of the same contract (with the same URI) are not allowed.
30
- *
31
- * @param contracts - A record mapping contract keys to their respective ArvoContract objects
32
- * @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
33
- */
34
- export declare const areServiceContractsUnique: (contracts: Record<string, ArvoContract | VersionedArvoContract<any, any>>) => {
35
- result: false;
36
- keys: [string, string];
37
- contractUri: string;
38
- } | {
39
- result: true;
40
- };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.areServiceContractsUnique = exports.detectParallelStates = void 0;
3
+ exports.detectParallelStates = void 0;
4
4
  /**
5
5
  * Detects if an XState machine configuration contains any parallel states.
6
6
  * Uses a stack-based approach for efficient traversal of the state hierarchy.
@@ -41,30 +41,3 @@ var detectParallelStates = function (config) {
41
41
  return false;
42
42
  };
43
43
  exports.detectParallelStates = detectParallelStates;
44
- /**
45
- * Validates that all service contracts in a collection have unique URIs.
46
- *
47
- * Iterates through the provided contracts and checks if any URI appears more than once.
48
- * Multiple versions of the same contract (with the same URI) are not allowed.
49
- *
50
- * @param contracts - A record mapping contract keys to their respective ArvoContract objects
51
- * @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
52
- */
53
- var areServiceContractsUnique = function (contracts) {
54
- var uriToKeyMap = {};
55
- for (var _i = 0, _a = Object.entries(contracts); _i < _a.length; _i++) {
56
- var _b = _a[_i], key = _b[0], contract = _b[1];
57
- if (uriToKeyMap[contract.uri]) {
58
- return {
59
- result: false,
60
- keys: [key, uriToKeyMap[contract.uri]],
61
- contractUri: contract.uri,
62
- };
63
- }
64
- uriToKeyMap[contract.uri] = key;
65
- }
66
- return {
67
- result: true,
68
- };
69
- };
70
- exports.areServiceContractsUnique = areServiceContractsUnique;
@@ -1,5 +1,5 @@
1
1
  import { type Span } from '@opentelemetry/api';
2
- import { type ArvoEvent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract, type ViolationError } from 'arvo-core';
2
+ import { type ArvoContract, type ArvoEvent, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract, type ViolationError } from 'arvo-core';
3
3
  import type { SyncEventResource } from '../SyncEventResource';
4
4
  import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
5
5
  import { type ArvoOrchestrationHandlerType } from './types';
@@ -12,7 +12,7 @@ export type CreateSystemErrorEventsParams = {
12
12
  otelHeaders: OpenTelemetryHeaders;
13
13
  orchestrationParentSubject: string | null;
14
14
  initEventId: string | null;
15
- selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
15
+ selfContract: VersionedArvoContract<ArvoContract, ArvoSemanticVersion>;
16
16
  systemErrorDomain?: (string | null)[];
17
17
  executionunits: number;
18
18
  source: string;
@@ -105,7 +105,7 @@ var ArvoResumable = /** @class */ (function () {
105
105
  this.contracts = param.contracts;
106
106
  this.handler = param.handler;
107
107
  this.systemErrorDomain = param.systemErrorDomain;
108
- this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_d = (_c = param.spanOptions) === null || _c === void 0 ? void 0 : _c.attributes) !== null && _d !== void 0 ? _d : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
108
+ this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.RESUMABLE, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_d = (_c = param.spanOptions) === null || _c === void 0 ? void 0 : _c.attributes) !== null && _d !== void 0 ? _d : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
109
109
  }
110
110
  Object.defineProperty(ArvoResumable.prototype, "requiresResourceLocking", {
111
111
  get: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-event-handler",
3
- "version": "3.0.11",
3
+ "version": "3.0.14",
4
4
  "description": "Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@opentelemetry/api": "^1.9.0",
48
48
  "@opentelemetry/core": "^1.30.1",
49
- "arvo-core": "^3.0.11",
49
+ "arvo-core": "^3.0.14",
50
50
  "uuid": "^11.1.0",
51
51
  "xstate": "^5.23.0",
52
52
  "zod": "^3.25.74",