arvo-event-handler 3.0.8 → 3.0.11
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 +2 -3
- package/dist/ArvoEventHandler/index.js +52 -70
- package/dist/ArvoEventHandler/types.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +1 -1
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +25 -22
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +5 -3
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +135 -142
- package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +22 -0
- package/dist/ArvoOrchestrationUtils/servicesValidation.js +56 -0
- package/dist/ArvoOrchestrationUtils/types.d.ts +7 -1
- package/dist/ArvoOrchestrationUtils/types.js +7 -0
- package/dist/ArvoOrchestrator/factory.d.ts +2 -2
- package/dist/ArvoOrchestrator/factory.js +2 -1
- package/dist/ArvoOrchestrator/index.d.ts +2 -1
- package/dist/ArvoOrchestrator/index.js +23 -8
- package/dist/ArvoOrchestrator/types.d.ts +16 -19
- package/dist/ArvoResumable/factory.d.ts +2 -0
- package/dist/ArvoResumable/factory.js +6 -25
- package/dist/ArvoResumable/index.d.ts +5 -3
- package/dist/ArvoResumable/index.js +20 -3
- package/dist/IArvoEventHandler/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
|
@@ -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
|
-
var uuid_1 = require("uuid");
|
|
16
4
|
var _1 = require(".");
|
|
17
|
-
var
|
|
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 utils_1 = require("../ArvoMachine/utils");
|
|
|
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,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Span } from '@opentelemetry/api';
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestratorContract, type VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type { z } from 'zod';
|
|
4
4
|
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
5
5
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
6
6
|
import { SyncEventResource } from '../SyncEventResource/index';
|
|
7
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
7
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
8
|
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* ArvoResumable - A stateful orchestration handler for managing distributed workflows
|
|
@@ -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,6 +61,7 @@ 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
66
|
protected validateInput(event: ArvoEvent, span: Span): {
|
|
65
67
|
contractType: 'self' | 'service';
|
|
@@ -77,7 +79,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
77
79
|
* @throws {ContractViolation} When event schema validation fails
|
|
78
80
|
* @throws {ExecutionViolation} When workflow execution encounters critical errors
|
|
79
81
|
*/
|
|
80
|
-
execute(event: ArvoEvent, opentelemetry
|
|
82
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
81
83
|
events: ArvoEvent[];
|
|
82
84
|
}>;
|
|
83
85
|
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, z.ZodObject<{
|
|
@@ -1,4 +1,15 @@
|
|
|
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,6 +57,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
46
57
|
};
|
|
47
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
59
|
exports.ArvoResumable = void 0;
|
|
60
|
+
var api_1 = require("@opentelemetry/api");
|
|
49
61
|
var arvo_core_1 = require("arvo-core");
|
|
50
62
|
var createEmitableEvent_1 = require("../ArvoOrchestrationUtils/createEmitableEvent");
|
|
51
63
|
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
@@ -85,13 +97,15 @@ var errors_1 = require("../errors");
|
|
|
85
97
|
var ArvoResumable = /** @class */ (function () {
|
|
86
98
|
function ArvoResumable(param) {
|
|
87
99
|
var _a;
|
|
100
|
+
var _b, _c, _d;
|
|
88
101
|
this.systemErrorDomain = [];
|
|
89
102
|
this.executionunits = param.executionunits;
|
|
90
103
|
this.source = param.contracts.self.type;
|
|
91
|
-
this.syncEventResource = new index_1.SyncEventResource(param.memory, (
|
|
104
|
+
this.syncEventResource = new index_1.SyncEventResource(param.memory, (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : true);
|
|
92
105
|
this.contracts = param.contracts;
|
|
93
106
|
this.handler = param.handler;
|
|
94
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 }) });
|
|
95
109
|
}
|
|
96
110
|
Object.defineProperty(ArvoResumable.prototype, "requiresResourceLocking", {
|
|
97
111
|
get: function () {
|
|
@@ -183,8 +197,11 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
183
197
|
case 0: return [4 /*yield*/, (0, orchestrationExecutionWrapper_1.executeWithOrchestrationWrapper)({
|
|
184
198
|
_handlerType: 'resumable',
|
|
185
199
|
event: event,
|
|
186
|
-
opentelemetry: opentelemetry,
|
|
187
|
-
spanName:
|
|
200
|
+
opentelemetry: opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' },
|
|
201
|
+
spanOptions: __assign({ spanName: function (_a) {
|
|
202
|
+
var selfContractUri = _a.selfContractUri, consumedEvent = _a.consumedEvent;
|
|
203
|
+
return "Resumable<".concat(selfContractUri, ">@<").concat(consumedEvent.type, ">");
|
|
204
|
+
} }, this.spanOptions),
|
|
188
205
|
source: this.source,
|
|
189
206
|
syncEventResource: this.syncEventResource,
|
|
190
207
|
executionunits: this.executionunits,
|
|
@@ -21,7 +21,7 @@ export default interface IArvoEventHandler {
|
|
|
21
21
|
* @returns A promise that resolves to an array of resulting Arvo events.
|
|
22
22
|
* These events represent the outcome of processing the input event.
|
|
23
23
|
*/
|
|
24
|
-
execute(event: ArvoEvent, opentelemetry
|
|
24
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
25
25
|
events: ArvoEvent[];
|
|
26
26
|
}>;
|
|
27
27
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { ArvoEventHandlerFunction, ArvoEventHandlerFunctionInput, ArvoEventHandl
|
|
|
6
6
|
import ArvoMachine from './ArvoMachine';
|
|
7
7
|
import { setupArvoMachine } from './ArvoMachine/createMachine';
|
|
8
8
|
import { ArvoMachineContext, EnqueueArvoEventActionParam } from './ArvoMachine/types';
|
|
9
|
-
import {
|
|
9
|
+
import { TransactionViolation, TransactionViolationCause, isTransactionViolationError } from './ArvoOrchestrationUtils/error';
|
|
10
|
+
import { OrchestrationExecutionStatus } from './ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
10
11
|
import { ArvoOrchestrator } from './ArvoOrchestrator';
|
|
11
12
|
import { createArvoOrchestrator } from './ArvoOrchestrator/factory';
|
|
12
13
|
import { ArvoOrchestratorParam, MachineMemoryRecord } from './ArvoOrchestrator/types';
|
|
@@ -23,13 +24,12 @@ import { IMachineMemory } from './MachineMemory/interface';
|
|
|
23
24
|
import { MachineRegistry } from './MachineRegistry';
|
|
24
25
|
import { IMachineRegistry } from './MachineRegistry/interface';
|
|
25
26
|
import { ConfigViolation, ContractViolation, ExecutionViolation } from './errors';
|
|
26
|
-
import { ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, PartialExcept } from './types';
|
|
27
|
+
import { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions, EventHandlerFactory, PartialExcept } from './types';
|
|
27
28
|
import { coalesce, coalesceOrDefault, getValueOrDefault, isNullOrUndefined } from './utils';
|
|
28
29
|
import { SimpleEventBroker } from './utils/SimpleEventBroker';
|
|
29
30
|
import { createSimpleEventBroker } from './utils/SimpleEventBroker/helper';
|
|
30
|
-
import { OrchestrationExecutionStatus } from './ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
31
31
|
declare const xstate: {
|
|
32
32
|
emit: typeof emit;
|
|
33
33
|
assign: typeof assign;
|
|
34
34
|
};
|
|
35
|
-
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, ContractViolation, ConfigViolation, ExecutionViolation, ArvoMachine, setupArvoMachine, ArvoMachineContext, EnqueueArvoEventActionParam, IMachineRegistry, MachineRegistry, MachineExecutionEngine, IMachineExectionEngine, ExecuteMachineInput, ExecuteMachineOutput, IMachineMemory, SimpleMachineMemory, MachineMemoryRecord, ArvoOrchestratorParam, TransactionViolation, TransactionViolationCause, ArvoOrchestrator, createArvoOrchestrator, SimpleEventBroker, createSimpleEventBroker, TelemetredSimpleMachineMemory, xstate, ArvoResumable, createArvoResumable, ArvoResumableHandler, ArvoResumableState, ArvoDomain, resolveEventDomain, isTransactionViolationError, OrchestrationExecutionStatus };
|
|
35
|
+
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, ContractViolation, ConfigViolation, ExecutionViolation, ArvoMachine, setupArvoMachine, ArvoMachineContext, EnqueueArvoEventActionParam, IMachineRegistry, MachineRegistry, MachineExecutionEngine, IMachineExectionEngine, ExecuteMachineInput, ExecuteMachineOutput, IMachineMemory, SimpleMachineMemory, MachineMemoryRecord, ArvoOrchestratorParam, TransactionViolation, TransactionViolationCause, ArvoOrchestrator, createArvoOrchestrator, SimpleEventBroker, createSimpleEventBroker, TelemetredSimpleMachineMemory, xstate, ArvoResumable, createArvoResumable, ArvoResumableHandler, ArvoResumableState, ArvoDomain, resolveEventDomain, isTransactionViolationError, OrchestrationExecutionStatus, ArvoEventHandlerOtelSpanOptions, };
|
package/dist/index.js
CHANGED
|
@@ -17,9 +17,11 @@ exports.ArvoMachine = ArvoMachine_1.default;
|
|
|
17
17
|
var createMachine_1 = require("./ArvoMachine/createMachine");
|
|
18
18
|
Object.defineProperty(exports, "setupArvoMachine", { enumerable: true, get: function () { return createMachine_1.setupArvoMachine; } });
|
|
19
19
|
var error_1 = require("./ArvoOrchestrationUtils/error");
|
|
20
|
-
Object.defineProperty(exports, "isTransactionViolationError", { enumerable: true, get: function () { return error_1.isTransactionViolationError; } });
|
|
21
20
|
Object.defineProperty(exports, "TransactionViolation", { enumerable: true, get: function () { return error_1.TransactionViolation; } });
|
|
22
21
|
Object.defineProperty(exports, "TransactionViolationCause", { enumerable: true, get: function () { return error_1.TransactionViolationCause; } });
|
|
22
|
+
Object.defineProperty(exports, "isTransactionViolationError", { enumerable: true, get: function () { return error_1.isTransactionViolationError; } });
|
|
23
|
+
var orchestrationExecutionState_1 = require("./ArvoOrchestrationUtils/orchestrationExecutionState");
|
|
24
|
+
Object.defineProperty(exports, "OrchestrationExecutionStatus", { enumerable: true, get: function () { return orchestrationExecutionState_1.OrchestrationExecutionStatus; } });
|
|
23
25
|
var ArvoOrchestrator_1 = require("./ArvoOrchestrator");
|
|
24
26
|
Object.defineProperty(exports, "ArvoOrchestrator", { enumerable: true, get: function () { return ArvoOrchestrator_1.ArvoOrchestrator; } });
|
|
25
27
|
var factory_1 = require("./ArvoOrchestrator/factory");
|
|
@@ -49,8 +51,6 @@ var SimpleEventBroker_1 = require("./utils/SimpleEventBroker");
|
|
|
49
51
|
Object.defineProperty(exports, "SimpleEventBroker", { enumerable: true, get: function () { return SimpleEventBroker_1.SimpleEventBroker; } });
|
|
50
52
|
var helper_1 = require("./utils/SimpleEventBroker/helper");
|
|
51
53
|
Object.defineProperty(exports, "createSimpleEventBroker", { enumerable: true, get: function () { return helper_1.createSimpleEventBroker; } });
|
|
52
|
-
var orchestrationExecutionState_1 = require("./ArvoOrchestrationUtils/orchestrationExecutionState");
|
|
53
|
-
Object.defineProperty(exports, "OrchestrationExecutionStatus", { enumerable: true, get: function () { return orchestrationExecutionState_1.OrchestrationExecutionStatus; } });
|
|
54
54
|
var xstate = {
|
|
55
55
|
emit: xstate_1.emit,
|
|
56
56
|
assign: xstate_1.assign,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { ArvoEvent } from 'arvo-core';
|
|
1
3
|
import type IArvoEventHandler from './IArvoEventHandler';
|
|
2
4
|
/**
|
|
3
5
|
* Makes properties optional except specified keys
|
|
@@ -30,3 +32,9 @@ export type ArvoEventHandlerOpenTelemetryOptions = {
|
|
|
30
32
|
* @template T - Configuration object type
|
|
31
33
|
*/
|
|
32
34
|
export type EventHandlerFactory<T = void> = T extends void ? () => IArvoEventHandler : (config: T) => IArvoEventHandler;
|
|
35
|
+
export type ArvoEventHandlerOtelSpanOptions = SpanOptions & {
|
|
36
|
+
spanName?: (param: {
|
|
37
|
+
selfContractUri: string;
|
|
38
|
+
consumedEvent: ArvoEvent;
|
|
39
|
+
}) => string;
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
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.
|
|
49
|
+
"arvo-core": "^3.0.11",
|
|
50
50
|
"uuid": "^11.1.0",
|
|
51
51
|
"xstate": "^5.23.0",
|
|
52
52
|
"zod": "^3.25.74",
|