arvo-event-handler 3.0.7 → 3.0.10

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.
Files changed (43) hide show
  1. package/dist/ArvoEventHandler/index.d.ts +3 -4
  2. package/dist/ArvoEventHandler/index.js +53 -71
  3. package/dist/ArvoEventHandler/types.d.ts +3 -2
  4. package/dist/ArvoMachine/createMachine.d.ts +1 -1
  5. package/dist/ArvoMachine/createMachine.js +1 -1
  6. package/dist/ArvoOrchestrationUtils/createEmitableEvent.d.ts +30 -0
  7. package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +160 -0
  8. package/dist/ArvoOrchestrationUtils/error.d.ts +18 -0
  9. package/dist/{ArvoOrchestrator → ArvoOrchestrationUtils}/error.js +14 -9
  10. package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +36 -0
  11. package/dist/ArvoOrchestrationUtils/handlerErrors.js +183 -0
  12. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.d.ts +11 -0
  13. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.js +7 -0
  14. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts +8 -0
  15. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js +69 -0
  16. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +42 -0
  17. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +221 -0
  18. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts +7 -0
  19. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js +25 -0
  20. package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +22 -0
  21. package/dist/ArvoOrchestrationUtils/servicesValidation.js +56 -0
  22. package/dist/ArvoOrchestrationUtils/types.d.ts +7 -0
  23. package/dist/ArvoOrchestrationUtils/types.js +9 -0
  24. package/dist/ArvoOrchestrator/factory.d.ts +2 -2
  25. package/dist/ArvoOrchestrator/factory.js +15 -1
  26. package/dist/ArvoOrchestrator/index.d.ts +5 -20
  27. package/dist/ArvoOrchestrator/index.js +94 -471
  28. package/dist/ArvoOrchestrator/types.d.ts +19 -21
  29. package/dist/ArvoResumable/factory.d.ts +4 -2
  30. package/dist/ArvoResumable/factory.js +6 -25
  31. package/dist/ArvoResumable/index.d.ts +9 -21
  32. package/dist/ArvoResumable/index.js +82 -422
  33. package/dist/ArvoResumable/types.d.ts +5 -4
  34. package/dist/IArvoEventHandler/index.d.ts +1 -2
  35. package/dist/MachineExecutionEngine/index.d.ts +1 -1
  36. package/dist/MachineRegistry/index.d.ts +1 -1
  37. package/dist/SyncEventResource/index.d.ts +1 -1
  38. package/dist/SyncEventResource/index.js +1 -1
  39. package/dist/index.d.ts +12 -11
  40. package/dist/index.js +24 -21
  41. package/dist/types.d.ts +8 -0
  42. package/package.json +2 -2
  43. package/dist/ArvoOrchestrator/error.d.ts +0 -16
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.servicesValidation = exports.areServiceContractsUnique = void 0;
15
+ var uuid_1 = require("uuid");
16
+ var errors_1 = require("../errors");
17
+ var types_1 = require("./types");
18
+ /**
19
+ * Validates that all service contracts in a collection have unique URIs.
20
+ *
21
+ * Iterates through the provided contracts and checks if any URI appears more than once.
22
+ * Multiple versions of the same contract (with the same URI) are not allowed.
23
+ *
24
+ * @param contracts - A record mapping contract keys to their respective ArvoContract objects
25
+ * @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
26
+ */
27
+ var areServiceContractsUnique = function (contracts) {
28
+ var uriToKeyMap = {};
29
+ for (var _i = 0, _a = Object.entries(contracts); _i < _a.length; _i++) {
30
+ var _b = _a[_i], key = _b[0], contract = _b[1];
31
+ if (uriToKeyMap[contract.uri]) {
32
+ return {
33
+ result: false,
34
+ keys: [key, uriToKeyMap[contract.uri]],
35
+ contractUri: contract.uri,
36
+ };
37
+ }
38
+ uriToKeyMap[contract.uri] = key;
39
+ }
40
+ return {
41
+ result: true,
42
+ };
43
+ };
44
+ exports.areServiceContractsUnique = areServiceContractsUnique;
45
+ var servicesValidation = function (contracts, _handlerType) {
46
+ var _a;
47
+ var __areServiceContractsUnique = (0, exports.areServiceContractsUnique)(contracts.services);
48
+ if (!__areServiceContractsUnique.result) {
49
+ 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, "'"));
50
+ }
51
+ var __checkIfSelfIsAService = (0, exports.areServiceContractsUnique)(__assign(__assign({}, contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = contracts.self, _a)));
52
+ if (!__checkIfSelfIsAService.result) {
53
+ 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."));
54
+ }
55
+ };
56
+ exports.servicesValidation = servicesValidation;
@@ -0,0 +1,7 @@
1
+ export declare const ArvoOrchestrationHandlerMap: {
2
+ readonly orchestrator: "ArvoOrchestrator";
3
+ readonly resumable: "ArvoResumable";
4
+ readonly machine: "ArvoMachine";
5
+ readonly handler: "ArvoEventHandler";
6
+ };
7
+ export type ArvoOrchestrationHandlerType = keyof typeof ArvoOrchestrationHandlerMap;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArvoOrchestrationHandlerMap = void 0;
4
+ exports.ArvoOrchestrationHandlerMap = {
5
+ orchestrator: 'ArvoOrchestrator',
6
+ resumable: 'ArvoResumable',
7
+ machine: 'ArvoMachine',
8
+ handler: 'ArvoEventHandler',
9
+ };
@@ -1,5 +1,5 @@
1
1
  import { ArvoOrchestrator } from '.';
2
- import type { ICreateArvoOrchestrator } from './types';
2
+ import type { CreateArvoOrchestratorParam } from './types';
3
3
  /**
4
4
  * Creates a new Arvo orchestrator instance with default components.
5
5
  * For custom components, use ArvoOrchestrator constructor directly.
@@ -26,4 +26,4 @@ import type { ICreateArvoOrchestrator } from './types';
26
26
  * });
27
27
  * ```
28
28
  */
29
- export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, }: ICreateArvoOrchestrator) => ArvoOrchestrator;
29
+ export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
@@ -13,6 +13,7 @@ exports.createArvoOrchestrator = void 0;
13
13
  var _1 = require(".");
14
14
  var MachineExecutionEngine_1 = require("../MachineExecutionEngine");
15
15
  var MachineRegistry_1 = require("../MachineRegistry");
16
+ var errors_1 = require("../errors");
16
17
  /**
17
18
  * Creates a new Arvo orchestrator instance with default components.
18
19
  * For custom components, use ArvoOrchestrator constructor directly.
@@ -40,12 +41,24 @@ var MachineRegistry_1 = require("../MachineRegistry");
40
41
  * ```
41
42
  */
42
43
  var createArvoOrchestrator = function (_a) {
43
- var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain;
44
+ var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
44
45
  if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
45
46
  throw new Error('At least one machine must be provided');
46
47
  }
47
48
  var registry = new (MachineRegistry_1.MachineRegistry.bind.apply(MachineRegistry_1.MachineRegistry, __spreadArray([void 0], machines, false)))();
48
49
  var requiresResourceLocking = machines.some(function (machine) { return machine.requiresResourceLocking; });
50
+ var representativeMachine = registry.machines[0];
51
+ var lastSeenVersions = [];
52
+ for (var _i = 0, _b = registry.machines; _i < _b.length; _i++) {
53
+ var machine = _b[_i];
54
+ if (representativeMachine.source !== machine.source) {
55
+ throw new errors_1.ConfigViolation("All the machines in the orchestrator must have type '".concat(representativeMachine.source, "'"));
56
+ }
57
+ if (lastSeenVersions.includes(machine.version)) {
58
+ throw new errors_1.ConfigViolation("An orchestrator must have unique machine versions. Machine ID:".concat(machine.id, " has duplicate version ").concat(machine.version, "."));
59
+ }
60
+ lastSeenVersions.push(machine.version);
61
+ }
49
62
  return new _1.ArvoOrchestrator({
50
63
  executionunits: executionunits,
51
64
  memory: memory,
@@ -53,6 +66,7 @@ var createArvoOrchestrator = function (_a) {
53
66
  executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
54
67
  requiresResourceLocking: requiresResourceLocking,
55
68
  systemErrorDomain: systemErrorDomain,
69
+ spanOptions: spanOptions,
56
70
  });
57
71
  };
58
72
  exports.createArvoOrchestrator = createArvoOrchestrator;
@@ -1,13 +1,11 @@
1
- import { type ArvoContractRecord, type ArvoEvent, type OpenTelemetryHeaders } from 'arvo-core';
2
- import type ArvoMachine from '../ArvoMachine';
3
- import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types';
1
+ import { type ArvoContractRecord, type ArvoEvent } from 'arvo-core';
2
+ import type IArvoEventHandler from '../IArvoEventHandler';
4
3
  import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
5
4
  import type { IMachineMemory } from '../MachineMemory/interface';
6
5
  import type { IMachineRegistry } from '../MachineRegistry/interface';
7
- import type { ArvoOrchestratorParam, MachineMemoryRecord } from './types';
8
6
  import { SyncEventResource } from '../SyncEventResource';
9
- import IArvoEventHandler from '../IArvoEventHandler';
10
7
  import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
8
+ import type { ArvoOrchestratorParam, MachineMemoryRecord } from './types';
11
9
  /**
12
10
  * Orchestrates state machine execution and lifecycle management.
13
11
  * Handles machine resolution, state management, event processing and error handling.
@@ -18,6 +16,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
18
16
  readonly executionEngine: IMachineExectionEngine;
19
17
  readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
20
18
  readonly systemErrorDomain?: (string | null)[];
19
+ private readonly spanOptions;
21
20
  get source(): any;
22
21
  get requiresResourceLocking(): boolean;
23
22
  get memory(): IMachineMemory<MachineMemoryRecord>;
@@ -27,21 +26,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
27
26
  * @param params - Configuration parameters
28
27
  * @throws Error if machines in registry have different sources
29
28
  */
30
- constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, }: ArvoOrchestratorParam);
31
- /**
32
- * Creates emittable event from execution result
33
- * @param event - Source event to emit
34
- * @param machine - Machine that generated event
35
- * @param otelHeaders - OpenTelemetry headers
36
- * @param orchestrationParentSubject - Parent orchestration subject
37
- * @param sourceEvent - Original triggering event
38
- * @param initEventId - The id of the event which initiated the orchestration in the first place
39
- * @param _domain - The domain of the event.
40
- *
41
- * @throws {ContractViolation} On schema/contract mismatch
42
- * @throws {ExecutionViolation} On invalid parentSubject$$ format
43
- */
44
- protected createEmittableEvent(event: EnqueueArvoEventActionParam, machine: ArvoMachine<any, any, any, any, any>, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, initEventId: string, _domain: string | null): ArvoEvent;
29
+ constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, spanOptions, }: ArvoOrchestratorParam);
45
30
  /**
46
31
  * Core orchestration method that executes state machines in response to events.
47
32
  *