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.
- package/dist/ArvoEventHandler/index.d.ts +3 -4
- package/dist/ArvoEventHandler/index.js +53 -71
- package/dist/ArvoEventHandler/types.d.ts +3 -2
- package/dist/ArvoMachine/createMachine.d.ts +1 -1
- package/dist/ArvoMachine/createMachine.js +1 -1
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.d.ts +30 -0
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +160 -0
- package/dist/ArvoOrchestrationUtils/error.d.ts +18 -0
- package/dist/{ArvoOrchestrator → ArvoOrchestrationUtils}/error.js +14 -9
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +36 -0
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +183 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.d.ts +11 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.js +7 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts +8 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js +69 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +42 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +221 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts +7 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js +25 -0
- package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +22 -0
- package/dist/ArvoOrchestrationUtils/servicesValidation.js +56 -0
- package/dist/ArvoOrchestrationUtils/types.d.ts +7 -0
- package/dist/ArvoOrchestrationUtils/types.js +9 -0
- package/dist/ArvoOrchestrator/factory.d.ts +2 -2
- package/dist/ArvoOrchestrator/factory.js +15 -1
- package/dist/ArvoOrchestrator/index.d.ts +5 -20
- package/dist/ArvoOrchestrator/index.js +94 -471
- package/dist/ArvoOrchestrator/types.d.ts +19 -21
- package/dist/ArvoResumable/factory.d.ts +4 -2
- package/dist/ArvoResumable/factory.js +6 -25
- package/dist/ArvoResumable/index.d.ts +9 -21
- package/dist/ArvoResumable/index.js +82 -422
- package/dist/ArvoResumable/types.d.ts +5 -4
- package/dist/IArvoEventHandler/index.d.ts +1 -2
- package/dist/MachineExecutionEngine/index.d.ts +1 -1
- package/dist/MachineRegistry/index.d.ts +1 -1
- package/dist/SyncEventResource/index.d.ts +1 -1
- package/dist/SyncEventResource/index.js +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.js +24 -21
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
- package/dist/ArvoOrchestrator/error.d.ts +0 -16
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ArvoEvent, InferArvoEvent } from 'arvo-core';
|
|
2
2
|
import type { Snapshot } from 'xstate';
|
|
3
3
|
import type ArvoMachine from '../ArvoMachine';
|
|
4
|
+
import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
4
5
|
import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
|
|
5
6
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
6
7
|
import type { IMachineRegistry } from '../MachineRegistry/interface';
|
|
8
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
7
9
|
export type TryFunctionOutput<TData, TError extends Error> = {
|
|
8
10
|
type: 'success';
|
|
9
11
|
data: TData;
|
|
@@ -14,7 +16,7 @@ export type TryFunctionOutput<TData, TError extends Error> = {
|
|
|
14
16
|
/**
|
|
15
17
|
* Represents the state record stored in machine memory.
|
|
16
18
|
*/
|
|
17
|
-
export type MachineMemoryRecord = {
|
|
19
|
+
export type MachineMemoryRecord = OrchestrationExecutionMemoryRecord<{
|
|
18
20
|
/** Unique identifier for the machine instance */
|
|
19
21
|
subject: string;
|
|
20
22
|
/**
|
|
@@ -67,7 +69,7 @@ export type MachineMemoryRecord = {
|
|
|
67
69
|
};
|
|
68
70
|
/** Machine definition string */
|
|
69
71
|
machineDefinition: string | null;
|
|
70
|
-
}
|
|
72
|
+
}>;
|
|
71
73
|
/**
|
|
72
74
|
* Interface defining the core components of an Arvo orchestrator.
|
|
73
75
|
*/
|
|
@@ -81,24 +83,6 @@ export type ArvoOrchestratorParam = {
|
|
|
81
83
|
/** Engine responsible for machine execution */
|
|
82
84
|
executionEngine: IMachineExectionEngine;
|
|
83
85
|
requiresResourceLocking: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Optional configuration to customize where system error events are emitted.
|
|
86
|
-
*/
|
|
87
|
-
systemErrorDomain?: (string | null)[];
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Configuration interface for creating an Arvo orchestrator instance.
|
|
91
|
-
*/
|
|
92
|
-
export interface ICreateArvoOrchestrator {
|
|
93
|
-
/** Memory interface for storing and retrieving machine state */
|
|
94
|
-
memory: IMachineMemory<MachineMemoryRecord>;
|
|
95
|
-
/** The cost of the execution of the orchestrator */
|
|
96
|
-
executionunits: number;
|
|
97
|
-
/**
|
|
98
|
-
* Collection of state machines to be managed by the orchestrator.
|
|
99
|
-
* All machines must have the same source identifier.
|
|
100
|
-
*/
|
|
101
|
-
machines: ArvoMachine<any, any, any, any, any>[];
|
|
102
86
|
/**
|
|
103
87
|
* Optional configuration to customize where system error events are emitted.
|
|
104
88
|
*
|
|
@@ -113,4 +97,18 @@ export interface ICreateArvoOrchestrator {
|
|
|
113
97
|
* @default undefined — uses standard fallback broadcast domains
|
|
114
98
|
*/
|
|
115
99
|
systemErrorDomain?: (string | null)[];
|
|
116
|
-
|
|
100
|
+
/**
|
|
101
|
+
* The OpenTelemetry span options
|
|
102
|
+
*/
|
|
103
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Configuration interface for creating an Arvo orchestrator instance.
|
|
107
|
+
*/
|
|
108
|
+
export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'systemErrorDomain'> & {
|
|
109
|
+
/**
|
|
110
|
+
* Collection of state machines to be managed by the orchestrator.
|
|
111
|
+
* All machines must have the same source identifier.
|
|
112
|
+
*/
|
|
113
|
+
machines: ArvoMachine<any, any, any, any, any>[];
|
|
114
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ArvoOrchestratorContract, VersionedArvoContract } from 'arvo-core';
|
|
2
|
-
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
3
|
-
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
4
2
|
import { ArvoResumable } from '.';
|
|
3
|
+
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
4
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
5
|
+
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* Factory function for creating ArvoResumable orchestrator instances
|
|
7
8
|
*
|
|
@@ -39,4 +40,5 @@ export declare const createArvoResumable: <TMemory extends Record<string, any>,
|
|
|
39
40
|
executionunits?: number;
|
|
40
41
|
requiresResourceLocking?: boolean;
|
|
41
42
|
systemErrorDomain?: (string | null)[];
|
|
43
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
42
44
|
}) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;
|
|
@@ -1,20 +1,8 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.createArvoResumable = void 0;
|
|
15
4
|
var _1 = require(".");
|
|
16
|
-
var
|
|
17
|
-
var uuid_1 = require("uuid");
|
|
5
|
+
var servicesValidation_1 = require("../ArvoOrchestrationUtils/servicesValidation");
|
|
18
6
|
/**
|
|
19
7
|
* Factory function for creating ArvoResumable orchestrator instances
|
|
20
8
|
*
|
|
@@ -40,23 +28,16 @@ var uuid_1 = require("uuid");
|
|
|
40
28
|
* @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
|
|
41
29
|
*/
|
|
42
30
|
var createArvoResumable = function (param) {
|
|
43
|
-
var _a;
|
|
44
|
-
|
|
45
|
-
var __areServiceContractsUnique = (0, utils_1.areServiceContractsUnique)(param.contracts.services);
|
|
46
|
-
if (!__areServiceContractsUnique.result) {
|
|
47
|
-
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, "'"));
|
|
48
|
-
}
|
|
49
|
-
var __checkIfSelfIsAService = (0, utils_1.areServiceContractsUnique)(__assign(__assign({}, param.contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = param.contracts.self, _a)));
|
|
50
|
-
if (!__checkIfSelfIsAService.result) {
|
|
51
|
-
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."));
|
|
52
|
-
}
|
|
31
|
+
var _a, _b;
|
|
32
|
+
(0, servicesValidation_1.servicesValidation)(param.contracts, 'resumable');
|
|
53
33
|
return new _1.ArvoResumable({
|
|
54
34
|
contracts: param.contracts,
|
|
55
35
|
memory: param.memory,
|
|
56
36
|
handler: param.handler,
|
|
57
|
-
executionunits: (
|
|
58
|
-
requiresResourceLocking: (
|
|
37
|
+
executionunits: (_a = param.executionunits) !== null && _a !== void 0 ? _a : 0,
|
|
38
|
+
requiresResourceLocking: (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : Object.keys(param.contracts.services).length > 1,
|
|
59
39
|
systemErrorDomain: param.systemErrorDomain,
|
|
40
|
+
spanOptions: param.spanOptions,
|
|
60
41
|
});
|
|
61
42
|
};
|
|
62
43
|
exports.createArvoResumable = createArvoResumable;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Span } from '@opentelemetry/api';
|
|
2
|
+
import { type ArvoEvent, type ArvoOrchestratorContract, type VersionedArvoContract } from 'arvo-core';
|
|
2
3
|
import type { z } from 'zod';
|
|
3
|
-
import type
|
|
4
|
+
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
4
5
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
5
6
|
import { SyncEventResource } from '../SyncEventResource/index';
|
|
6
|
-
import type {
|
|
7
|
-
import
|
|
8
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
7
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
|
+
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* ArvoResumable - A stateful orchestration handler for managing distributed workflows
|
|
11
11
|
*
|
|
@@ -43,6 +43,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
43
43
|
readonly source: string;
|
|
44
44
|
readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
45
45
|
readonly systemErrorDomain?: (string | null)[];
|
|
46
|
+
private readonly spanOptions;
|
|
46
47
|
readonly contracts: {
|
|
47
48
|
self: TSelfContract;
|
|
48
49
|
services: TServiceContract;
|
|
@@ -60,24 +61,11 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
60
61
|
requiresResourceLocking?: boolean;
|
|
61
62
|
handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
62
63
|
systemErrorDomain?: (string | null)[];
|
|
64
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
63
65
|
});
|
|
64
|
-
protected validateInput(event: ArvoEvent): {
|
|
66
|
+
protected validateInput(event: ArvoEvent, span: Span): {
|
|
65
67
|
contractType: 'self' | 'service';
|
|
66
68
|
};
|
|
67
|
-
/**
|
|
68
|
-
* Creates emittable event from execution result
|
|
69
|
-
* @param event - Source event to emit
|
|
70
|
-
* @param otelHeaders - OpenTelemetry headers
|
|
71
|
-
* @param orchestrationParentSubject - Parent orchestration subject
|
|
72
|
-
* @param sourceEvent - Original triggering event
|
|
73
|
-
* @param selfVersionedContract - The self versioned contract
|
|
74
|
-
* @param initEventId - The id of the event which initiated the orchestration in the first place
|
|
75
|
-
* @param _domain - The domain of the event.
|
|
76
|
-
*
|
|
77
|
-
* @throws {ContractViolation} On schema/contract mismatch
|
|
78
|
-
* @throws {ExecutionViolation} On invalid parentSubject$$ format
|
|
79
|
-
*/
|
|
80
|
-
protected createEmittableEvent(event: EnqueueArvoEventActionParam, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, selfVersionedContract: VersionedArvoContract<TSelfContract, ArvoSemanticVersion>, initEventId: string, _domain: string | null): ArvoEvent;
|
|
81
69
|
/**
|
|
82
70
|
* Executes the orchestration workflow for an incoming event
|
|
83
71
|
*
|
|
@@ -91,7 +79,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
91
79
|
* @throws {ContractViolation} When event schema validation fails
|
|
92
80
|
* @throws {ExecutionViolation} When workflow execution encounters critical errors
|
|
93
81
|
*/
|
|
94
|
-
execute(event: ArvoEvent, opentelemetry
|
|
82
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
95
83
|
events: ArvoEvent[];
|
|
96
84
|
}>;
|
|
97
85
|
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, z.ZodObject<{
|