arvo-event-handler 3.0.6 → 3.0.8

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 (46) hide show
  1. package/dist/ArvoEventHandler/helpers.d.ts +2 -2
  2. package/dist/ArvoEventHandler/index.d.ts +4 -4
  3. package/dist/ArvoEventHandler/index.js +13 -34
  4. package/dist/ArvoEventHandler/types.d.ts +5 -3
  5. package/dist/ArvoMachine/createMachine.d.ts +4 -2
  6. package/dist/ArvoMachine/createMachine.js +1 -1
  7. package/dist/ArvoMachine/types.d.ts +5 -1
  8. package/dist/ArvoOrchestrationUtils/createEmitableEvent.d.ts +30 -0
  9. package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +160 -0
  10. package/dist/ArvoOrchestrationUtils/error.d.ts +18 -0
  11. package/dist/{ArvoOrchestrator → ArvoOrchestrationUtils}/error.js +14 -9
  12. package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +35 -0
  13. package/dist/ArvoOrchestrationUtils/handlerErrors.js +184 -0
  14. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.d.ts +11 -0
  15. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.js +7 -0
  16. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts +8 -0
  17. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js +69 -0
  18. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +40 -0
  19. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +228 -0
  20. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts +7 -0
  21. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js +25 -0
  22. package/dist/ArvoOrchestrationUtils/types.d.ts +1 -0
  23. package/dist/ArvoOrchestrationUtils/types.js +2 -0
  24. package/dist/ArvoOrchestrator/factory.js +13 -0
  25. package/dist/ArvoOrchestrator/index.d.ts +5 -21
  26. package/dist/ArvoOrchestrator/index.js +93 -505
  27. package/dist/ArvoOrchestrator/types.d.ts +5 -4
  28. package/dist/ArvoResumable/factory.d.ts +2 -2
  29. package/dist/ArvoResumable/factory.js +1 -1
  30. package/dist/ArvoResumable/index.d.ts +6 -20
  31. package/dist/ArvoResumable/index.js +85 -462
  32. package/dist/ArvoResumable/types.d.ts +8 -5
  33. package/dist/IArvoEventHandler/index.d.ts +36 -0
  34. package/dist/IArvoEventHandler/index.js +2 -0
  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 +14 -13
  40. package/dist/index.js +24 -23
  41. package/dist/types.d.ts +2 -2
  42. package/dist/utils/SimpleEventBroker/helper.d.ts +2 -2
  43. package/package.json +5 -4
  44. package/dist/AbstractArvoEventHandler/index.d.ts +0 -91
  45. package/dist/AbstractArvoEventHandler/index.js +0 -18
  46. package/dist/ArvoOrchestrator/error.d.ts +0 -16
@@ -1,6 +1,6 @@
1
1
  import type { ArvoContract } from 'arvo-core';
2
2
  import ArvoEventHandler from '.';
3
- import type { IArvoEventHandler } from './types';
3
+ import type { ArvoEventHandlerParam } from './types';
4
4
  /**
5
5
  * Creates an instance of `ArvoEventHandler` for the specified versioned contract and handlers.
6
6
  *
@@ -42,4 +42,4 @@ import type { IArvoEventHandler } from './types';
42
42
  * @param param - Configuration object containing contract, versioned handlers, execution units, and span settings
43
43
  * @returns A fully configured `ArvoEventHandler` instance for the given contract
44
44
  */
45
- export declare const createArvoEventHandler: <TContract extends ArvoContract>(param: IArvoEventHandler<TContract>) => ArvoEventHandler<TContract>;
45
+ export declare const createArvoEventHandler: <TContract extends ArvoContract>(param: ArvoEventHandlerParam<TContract>) => ArvoEventHandler<TContract>;
@@ -1,8 +1,8 @@
1
1
  import { type SpanOptions } from '@opentelemetry/api';
2
2
  import { type ArvoContract, type ArvoEvent } from 'arvo-core';
3
- import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
3
+ import type IArvoEventHandler from '../IArvoEventHandler';
4
4
  import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
5
- import type { ArvoEventHandlerFunction, IArvoEventHandler } from './types';
5
+ import type { ArvoEventHandlerFunction, ArvoEventHandlerParam } from './types';
6
6
  /**
7
7
  * `ArvoEventHandler` is the foundational component for building stateless,
8
8
  * contract-bound services in the Arvo system.
@@ -83,7 +83,7 @@ import type { ArvoEventHandlerFunction, IArvoEventHandler } from './types';
83
83
  * - `'analytics.workflow'` → to pipe events into observability systems
84
84
  * - `'external.partner.sync'` → to route to external services
85
85
  */
86
- export default class ArvoEventHandler<TContract extends ArvoContract> extends AbstractArvoEventHandler {
86
+ export default class ArvoEventHandler<TContract extends ArvoContract> implements IArvoEventHandler {
87
87
  /** Contract instance that defines the event schema and validation rules */
88
88
  readonly contract: TContract;
89
89
  /** Computational cost metric associated with event handling operations */
@@ -111,7 +111,7 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
111
111
  * @param param - Handler configuration including contract, execution units, and handler implementations
112
112
  * @throws When handler implementations are missing for any contract version
113
113
  */
114
- constructor(param: IArvoEventHandler<TContract>);
114
+ constructor(param: ArvoEventHandlerParam<TContract>);
115
115
  /**
116
116
  * Processes an incoming event according to the handler's contract specifications. This method
117
117
  * handles the complete lifecycle of event processing including validation, execution, error
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __assign = (this && this.__assign) || function () {
18
3
  __assign = Object.assign || function(t) {
19
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -72,16 +57,12 @@ var __rest = (this && this.__rest) || function (s, e) {
72
57
  }
73
58
  return t;
74
59
  };
75
- var __importDefault = (this && this.__importDefault) || function (mod) {
76
- return (mod && mod.__esModule) ? mod : { "default": mod };
77
- };
78
60
  Object.defineProperty(exports, "__esModule", { value: true });
79
61
  var api_1 = require("@opentelemetry/api");
80
62
  var arvo_core_1 = require("arvo-core");
81
- var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
63
+ var ArvoDomain_1 = require("../ArvoDomain");
82
64
  var errors_1 = require("../errors");
83
65
  var utils_1 = require("../utils");
84
- var ArvoDomain_1 = require("../ArvoDomain");
85
66
  /**
86
67
  * `ArvoEventHandler` is the foundational component for building stateless,
87
68
  * contract-bound services in the Arvo system.
@@ -162,8 +143,7 @@ var ArvoDomain_1 = require("../ArvoDomain");
162
143
  * - `'analytics.workflow'` → to pipe events into observability systems
163
144
  * - `'external.partner.sync'` → to route to external services
164
145
  */
165
- var ArvoEventHandler = /** @class */ (function (_super) {
166
- __extends(ArvoEventHandler, _super);
146
+ var ArvoEventHandler = /** @class */ (function () {
167
147
  /**
168
148
  * Initializes a new ArvoEventHandler instance with the specified contract and configuration.
169
149
  * Validates handler implementations against contract versions during initialization.
@@ -177,20 +157,18 @@ var ArvoEventHandler = /** @class */ (function (_super) {
177
157
  function ArvoEventHandler(param) {
178
158
  var _a;
179
159
  var _b, _c;
180
- var _this = _super.call(this) || this;
181
- _this.systemErrorDomain = undefined;
182
- _this.contract = param.contract;
183
- _this.executionunits = param.executionunits;
184
- _this.handler = param.handler;
185
- _this.systemErrorDomain = param.systemErrorDomain;
186
- for (var _i = 0, _d = Object.keys(_this.contract.versions); _i < _d.length; _i++) {
160
+ this.systemErrorDomain = undefined;
161
+ this.contract = param.contract;
162
+ this.executionunits = param.executionunits;
163
+ this.handler = param.handler;
164
+ this.systemErrorDomain = param.systemErrorDomain;
165
+ for (var _i = 0, _d = Object.keys(this.contract.versions); _i < _d.length; _i++) {
187
166
  var contractVersions = _d[_i];
188
- if (!_this.handler[contractVersions]) {
189
- throw new Error("Contract ".concat(_this.contract.uri, " requires handler implementation for version ").concat(contractVersions));
167
+ if (!this.handler[contractVersions]) {
168
+ throw new Error("Contract ".concat(this.contract.uri, " requires handler implementation for version ").concat(contractVersions));
190
169
  }
191
170
  }
192
- _this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.CONSUMER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_c = (_b = param.spanOptions) === null || _b === void 0 ? void 0 : _b.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': _this.source, 'arvo.contract.uri': _this.contract.uri }) });
193
- return _this;
171
+ this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.CONSUMER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_c = (_b = param.spanOptions) === null || _b === void 0 ? void 0 : _b.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contract.uri }) });
194
172
  }
195
173
  Object.defineProperty(ArvoEventHandler.prototype, "source", {
196
174
  /** The source identifier for events produced by this handler */
@@ -308,6 +286,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
308
286
  event: event.domain,
309
287
  },
310
288
  span: span,
289
+ spanHeaders: otelSpanHeaders,
311
290
  })];
312
291
  case 2:
313
292
  _handleOutput = _z.sent();
@@ -441,5 +420,5 @@ var ArvoEventHandler = /** @class */ (function (_super) {
441
420
  configurable: true
442
421
  });
443
422
  return ArvoEventHandler;
444
- }(AbstractArvoEventHandler_1.default));
423
+ }());
445
424
  exports.default = ArvoEventHandler;
@@ -1,5 +1,5 @@
1
1
  import type { Span, SpanOptions } from '@opentelemetry/api';
2
- import type { ArvoContract, ArvoEvent, ArvoSemanticVersion, CreateArvoEvent, InferArvoEvent, VersionedArvoContract } from 'arvo-core';
2
+ import type { ArvoContract, ArvoEvent, ArvoSemanticVersion, CreateArvoEvent, InferArvoEvent, OpenTelemetryHeaders, VersionedArvoContract } from 'arvo-core';
3
3
  import type { z } from 'zod';
4
4
  /**
5
5
  * Represents the input for an ArvoEvent handler function.
@@ -18,6 +18,8 @@ export type ArvoEventHandlerFunctionInput<TContract extends VersionedArvoContrac
18
18
  contract: TContract;
19
19
  /** The OpenTelemetry span */
20
20
  span: Span;
21
+ /** The span headers */
22
+ spanHeaders: OpenTelemetryHeaders;
21
23
  };
22
24
  /**
23
25
  * Represents the output of an ArvoEvent handler function.
@@ -69,7 +71,7 @@ export type ArvoEventHandlerFunction<TContract extends ArvoContract> = {
69
71
  /**
70
72
  * Interface for an ArvoEvent handler.
71
73
  */
72
- export interface IArvoEventHandler<TContract extends ArvoContract> {
74
+ export type ArvoEventHandlerParam<TContract extends ArvoContract> = {
73
75
  /**
74
76
  * The contract for the handler defining its input and outputs as well as the description.
75
77
  */
@@ -103,4 +105,4 @@ export interface IArvoEventHandler<TContract extends ArvoContract> {
103
105
  * @default undefined — uses standard fallback broadcast domains
104
106
  */
105
107
  systemErrorDomain?: (string | null)[];
106
- }
108
+ };
@@ -1,4 +1,4 @@
1
- import { type ArvoOrchestratorEventTypeGen, type InferVersionedArvoContract, type VersionedArvoContract } from 'arvo-core';
1
+ import { type ArvoOrchestratorEventTypeGen, type CreateArvoEvent, type InferVersionedArvoContract, type VersionedArvoContract } from 'arvo-core';
2
2
  import { type ActionFunction, type MachineConfig, type MachineContext, type MetaObject, type ParameterizedObject, type SetupTypes } from 'xstate';
3
3
  import type { z } from 'zod';
4
4
  import ArvoMachine from '.';
@@ -185,7 +185,9 @@ export declare function setupArvoMachine<TContext extends MachineContext, TSelfC
185
185
  }): {
186
186
  createMachine: <const TConfig extends MachineConfig<TContext, InferServiceContract<TServiceContracts>["events"], ToProvidedActor<{}, {}>, ToParameterizedObject<TActions & {
187
187
  enqueueArvoEvent: EnqueueArvoEventActionParam;
188
- }>, ToParameterizedObject<TGuards>, never, TTag, InferVersionedArvoContract<TSelfContract>["accepts"], z.input<TSelfContract["emits"][ReturnType<typeof ArvoOrchestratorEventTypeGen.complete<ExtractOrchestratorType<TSelfContract["accepts"]["type"]>>>]>, InferServiceContract<TServiceContracts>["emitted"], TMeta>>(config: TConfig & {
188
+ }>, ToParameterizedObject<TGuards>, never, TTag, InferVersionedArvoContract<TSelfContract>["accepts"], z.input<TSelfContract["emits"][ReturnType<typeof ArvoOrchestratorEventTypeGen.complete<ExtractOrchestratorType<TSelfContract["accepts"]["type"]>>>]> & {
189
+ __id?: CreateArvoEvent<Record<string, unknown>, string>["id"];
190
+ }, InferServiceContract<TServiceContracts>["emitted"], TMeta>>(config: TConfig & {
189
191
  id: string;
190
192
  version?: TSelfContract["version"];
191
193
  }) => ArvoMachine<string, TSelfContract["version"], TSelfContract, TServiceContracts, import("xstate").StateMachine<TContext, { [K in keyof TServiceContracts]: import("./types").InferEmittableEventsFromVersionedArvoContract<TServiceContracts[K]>; }[keyof TServiceContracts], {}, never, import("xstate").IsNever<TActions & {
@@ -25,11 +25,11 @@ 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");
28
29
  var xstate_1 = require("xstate");
29
30
  var _1 = __importDefault(require("."));
30
31
  var object_1 = require("../utils/object");
31
32
  var utils_1 = require("./utils");
32
- var uuid_1 = require("uuid");
33
33
  /**
34
34
  * Establishes the foundation for creating Arvo-compatible state machines.
35
35
  *
@@ -1,4 +1,4 @@
1
- import type { ArvoContract, ArvoEventData, ArvoOrchestratorEventTypeGen, ArvoSemanticVersion, CloudEventExtension, InferVersionedArvoContract, VersionedArvoContract } from 'arvo-core';
1
+ import type { ArvoContract, ArvoEventData, ArvoOrchestratorEventTypeGen, ArvoSemanticVersion, CloudEventExtension, CreateArvoEvent, InferVersionedArvoContract, VersionedArvoContract } from 'arvo-core';
2
2
  import type { Invert, IsNever, ParameterizedObject, UnknownActorLogic, Values } from 'xstate';
3
3
  import type { z } from 'zod';
4
4
  /**
@@ -35,6 +35,10 @@ export type ArvoMachineContext = {
35
35
  * ```
36
36
  */
37
37
  export type EnqueueArvoEventActionParam<TData extends ArvoEventData = ArvoEventData, TType extends string = string, TExtension extends CloudEventExtension = CloudEventExtension> = {
38
+ /**
39
+ * The event id
40
+ */
41
+ id?: CreateArvoEvent<TData, TType>['id'];
38
42
  /**
39
43
  * The domain configuration for multi-domain event broadcasting.
40
44
  *
@@ -0,0 +1,30 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import { type ArvoEvent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract } from 'arvo-core';
3
+ import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types';
4
+ export type CreateEmittableEventParams = {
5
+ event: EnqueueArvoEventActionParam;
6
+ otelHeaders: OpenTelemetryHeaders;
7
+ orchestrationParentSubject: string | null;
8
+ sourceEvent: ArvoEvent;
9
+ selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
10
+ serviceContracts: Record<string, VersionedArvoContract<any, any>>;
11
+ initEventId: string;
12
+ domain: string | null;
13
+ executionunits: number;
14
+ source: string;
15
+ };
16
+ export declare const createEmittableEvent: ({ event, otelHeaders, orchestrationParentSubject, sourceEvent, selfContract, serviceContracts, initEventId, domain: _domain, executionunits, source, }: CreateEmittableEventParams, span: Span) => ArvoEvent;
17
+ /**
18
+ * Processes raw events into emittable events with domain resolution
19
+ */
20
+ export declare const processRawEventsIntoEmittables: (params: {
21
+ rawEvents: EnqueueArvoEventActionParam[];
22
+ otelHeaders: OpenTelemetryHeaders;
23
+ orchestrationParentSubject: string | null;
24
+ sourceEvent: ArvoEvent;
25
+ selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
26
+ serviceContracts: Record<string, VersionedArvoContract<any, any>>;
27
+ initEventId: string;
28
+ executionunits: number;
29
+ source: string;
30
+ }, span: Span) => ArvoEvent[];
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processRawEventsIntoEmittables = exports.createEmittableEvent = void 0;
4
+ var arvo_core_1 = require("arvo-core");
5
+ var ArvoDomain_1 = require("../ArvoDomain");
6
+ var errors_1 = require("../errors");
7
+ var createEmittableEvent = function (_a, span) {
8
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
9
+ var event = _a.event, otelHeaders = _a.otelHeaders, orchestrationParentSubject = _a.orchestrationParentSubject, sourceEvent = _a.sourceEvent, selfContract = _a.selfContract, serviceContracts = _a.serviceContracts, initEventId = _a.initEventId, _domain = _a.domain, executionunits = _a.executionunits, source = _a.source;
10
+ (0, arvo_core_1.logToSpan)({
11
+ level: 'INFO',
12
+ message: "Creating emittable event: ".concat(event.type),
13
+ }, span);
14
+ var serviceContractMap = Object.fromEntries(Object.values(serviceContracts).map(function (item) { return [
15
+ item.accepts.type,
16
+ item,
17
+ ]; }));
18
+ var schema = null;
19
+ var contract = null;
20
+ var subject = sourceEvent.subject;
21
+ var parentId = sourceEvent.id;
22
+ var domain = (0, ArvoDomain_1.resolveEventDomain)({
23
+ domainToResolve: _domain,
24
+ handlerSelfContract: selfContract,
25
+ eventContract: null,
26
+ triggeringEvent: sourceEvent,
27
+ });
28
+ if (event.type === selfContract.metadata.completeEventType) {
29
+ (0, arvo_core_1.logToSpan)({
30
+ level: 'INFO',
31
+ message: "Creating event for workflow completion: ".concat(event.type),
32
+ }, span);
33
+ contract = selfContract;
34
+ schema = selfContract.emits[selfContract.metadata.completeEventType];
35
+ subject = orchestrationParentSubject !== null && orchestrationParentSubject !== void 0 ? orchestrationParentSubject : sourceEvent.subject;
36
+ parentId = initEventId;
37
+ domain = (0, ArvoDomain_1.resolveEventDomain)({
38
+ domainToResolve: _domain,
39
+ handlerSelfContract: selfContract,
40
+ eventContract: selfContract,
41
+ triggeringEvent: sourceEvent,
42
+ });
43
+ }
44
+ else if (serviceContractMap[event.type]) {
45
+ (0, arvo_core_1.logToSpan)({
46
+ level: 'INFO',
47
+ message: "Creating service event for external system: ".concat(event.type),
48
+ }, span);
49
+ contract = serviceContractMap[event.type];
50
+ schema = serviceContractMap[event.type].accepts.schema;
51
+ domain = (0, ArvoDomain_1.resolveEventDomain)({
52
+ domainToResolve: _domain,
53
+ handlerSelfContract: selfContract,
54
+ eventContract: contract,
55
+ triggeringEvent: sourceEvent,
56
+ });
57
+ if (contract.metadata.contractType === 'ArvoOrchestratorContract') {
58
+ if (event.data.parentSubject$$) {
59
+ try {
60
+ arvo_core_1.ArvoOrchestrationSubject.parse(event.data.parentSubject$$);
61
+ }
62
+ catch (_o) {
63
+ throw new errors_1.ExecutionViolation("Invalid parentSubject$$ for the event(type='".concat(event.type, "', uri='").concat((_b = event.dataschema) !== null && _b !== void 0 ? _b : arvo_core_1.EventDataschemaUtil.create(contract), "'). It must be follow the ArvoOrchestrationSubject schema. The easiest way is to use the current orchestration subject by storing the subject via the context block in the machine definition."));
64
+ }
65
+ }
66
+ try {
67
+ if (event.data.parentSubject$$) {
68
+ subject = arvo_core_1.ArvoOrchestrationSubject.from({
69
+ orchestator: contract.accepts.type,
70
+ version: contract.version,
71
+ subject: event.data.parentSubject$$,
72
+ domain: domain !== null && domain !== void 0 ? domain : null,
73
+ meta: {
74
+ redirectto: (_c = event.redirectto) !== null && _c !== void 0 ? _c : source,
75
+ },
76
+ });
77
+ }
78
+ else {
79
+ subject = arvo_core_1.ArvoOrchestrationSubject.new({
80
+ version: contract.version,
81
+ orchestator: contract.accepts.type,
82
+ initiator: source,
83
+ domain: domain !== null && domain !== void 0 ? domain : undefined,
84
+ meta: {
85
+ redirectto: (_d = event.redirectto) !== null && _d !== void 0 ? _d : source,
86
+ },
87
+ });
88
+ }
89
+ }
90
+ catch (error) {
91
+ throw new errors_1.ExecutionViolation("Orchestration subject creation failed due to invalid parameters - Event: ".concat(event.type, " - ").concat(error === null || error === void 0 ? void 0 : error.message));
92
+ }
93
+ }
94
+ }
95
+ var finalDataschema = event.dataschema;
96
+ var finalData = event.data;
97
+ if (contract && schema) {
98
+ try {
99
+ finalData = schema.parse(event.data);
100
+ finalDataschema = arvo_core_1.EventDataschemaUtil.create(contract);
101
+ }
102
+ catch (error) {
103
+ throw new errors_1.ContractViolation("Invalid event data: Schema validation failed.\nEvent type: ".concat(event.type, "\nDetails: ").concat(error.message));
104
+ }
105
+ }
106
+ var emittableEvent = (0, arvo_core_1.createArvoEvent)({
107
+ id: event.id,
108
+ source: source,
109
+ type: event.type,
110
+ subject: subject,
111
+ dataschema: finalDataschema !== null && finalDataschema !== void 0 ? finalDataschema : undefined,
112
+ data: finalData,
113
+ to: (_e = event.to) !== null && _e !== void 0 ? _e : event.type,
114
+ accesscontrol: (_g = (_f = event.accesscontrol) !== null && _f !== void 0 ? _f : sourceEvent.accesscontrol) !== null && _g !== void 0 ? _g : undefined,
115
+ redirectto: (_h = event.redirectto) !== null && _h !== void 0 ? _h : source,
116
+ executionunits: (_j = event.executionunits) !== null && _j !== void 0 ? _j : executionunits,
117
+ traceparent: (_k = otelHeaders.traceparent) !== null && _k !== void 0 ? _k : undefined,
118
+ tracestate: (_l = otelHeaders.tracestate) !== null && _l !== void 0 ? _l : undefined,
119
+ parentid: parentId,
120
+ domain: domain !== null && domain !== void 0 ? domain : undefined,
121
+ }, (_m = event.__extensions) !== null && _m !== void 0 ? _m : {});
122
+ (0, arvo_core_1.logToSpan)({
123
+ level: 'INFO',
124
+ message: "Event created successfully: ".concat(emittableEvent.type),
125
+ }, span);
126
+ return emittableEvent;
127
+ };
128
+ exports.createEmittableEvent = createEmittableEvent;
129
+ /**
130
+ * Processes raw events into emittable events with domain resolution
131
+ */
132
+ var processRawEventsIntoEmittables = function (params, span) {
133
+ var _a;
134
+ var emittables = [];
135
+ for (var _i = 0, _b = params.rawEvents; _i < _b.length; _i++) {
136
+ var item = _b[_i];
137
+ for (var _c = 0, _d = Array.from(new Set((_a = item.domain) !== null && _a !== void 0 ? _a : [null])); _c < _d.length; _c++) {
138
+ var _dom = _d[_c];
139
+ var evt = (0, exports.createEmittableEvent)({
140
+ event: item,
141
+ otelHeaders: params.otelHeaders,
142
+ orchestrationParentSubject: params.orchestrationParentSubject,
143
+ sourceEvent: params.sourceEvent,
144
+ selfContract: params.selfContract,
145
+ serviceContracts: params.serviceContracts,
146
+ initEventId: params.initEventId,
147
+ domain: _dom,
148
+ executionunits: params.executionunits,
149
+ source: params.source,
150
+ }, span);
151
+ emittables.push(evt);
152
+ for (var _e = 0, _f = Object.entries(emittables[emittables.length - 1].otelAttributes); _e < _f.length; _e++) {
153
+ var _g = _f[_e], key = _g[0], value = _g[1];
154
+ span.setAttribute("to_emit.".concat(emittables.length - 1, ".").concat(key), value);
155
+ }
156
+ }
157
+ }
158
+ return emittables;
159
+ };
160
+ exports.processRawEventsIntoEmittables = processRawEventsIntoEmittables;
@@ -0,0 +1,18 @@
1
+ import { type ArvoEvent, ViolationError } from 'arvo-core';
2
+ export declare const TransactionViolationCause: {
3
+ readonly READ_FAILURE: "READ_MACHINE_MEMORY_FAILURE";
4
+ readonly LOCK_FAILURE: "LOCK_MACHINE_MEMORY_FAILURE";
5
+ readonly WRITE_FAILURE: "WRITE_MACHINE_MEMORY_FAILURE";
6
+ readonly LOCK_UNACQUIRED: "LOCK_UNACQUIRED";
7
+ readonly INVALID_SUBJECT: "INVALID_SUBJECT";
8
+ };
9
+ export type TransactionViolationCauseType = (typeof TransactionViolationCause)[keyof typeof TransactionViolationCause];
10
+ export declare class TransactionViolation extends ViolationError<'OrchestratorTransaction'> {
11
+ readonly cause: TransactionViolationCauseType;
12
+ constructor(param: {
13
+ cause: TransactionViolationCauseType;
14
+ message: string;
15
+ initiatingEvent: ArvoEvent;
16
+ });
17
+ }
18
+ export declare const isTransactionViolationError: (error: unknown, cause?: TransactionViolationCauseType) => boolean;
@@ -15,16 +15,15 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TransactionViolation = exports.TransactionViolationCause = void 0;
18
+ exports.isTransactionViolationError = exports.TransactionViolation = exports.TransactionViolationCause = void 0;
19
19
  var arvo_core_1 = require("arvo-core");
20
- var TransactionViolationCause;
21
- (function (TransactionViolationCause) {
22
- TransactionViolationCause["READ_FAILURE"] = "READ_MACHINE_MEMORY_FAILURE";
23
- TransactionViolationCause["LOCK_FAILURE"] = "LOCK_MACHINE_MEMORY_FAILURE";
24
- TransactionViolationCause["WRITE_FAILURE"] = "WRITE_MACHINE_MEMORY_FAILURE";
25
- TransactionViolationCause["LOCK_UNACQUIRED"] = "LOCK_UNACQUIRED";
26
- TransactionViolationCause["INVALID_SUBJECT"] = "INVALID_SUBJECT";
27
- })(TransactionViolationCause || (exports.TransactionViolationCause = TransactionViolationCause = {}));
20
+ exports.TransactionViolationCause = {
21
+ READ_FAILURE: 'READ_MACHINE_MEMORY_FAILURE',
22
+ LOCK_FAILURE: 'LOCK_MACHINE_MEMORY_FAILURE',
23
+ WRITE_FAILURE: 'WRITE_MACHINE_MEMORY_FAILURE',
24
+ LOCK_UNACQUIRED: 'LOCK_UNACQUIRED',
25
+ INVALID_SUBJECT: 'INVALID_SUBJECT',
26
+ };
28
27
  var TransactionViolation = /** @class */ (function (_super) {
29
28
  __extends(TransactionViolation, _super);
30
29
  function TransactionViolation(param) {
@@ -41,3 +40,9 @@ var TransactionViolation = /** @class */ (function (_super) {
41
40
  return TransactionViolation;
42
41
  }(arvo_core_1.ViolationError));
43
42
  exports.TransactionViolation = TransactionViolation;
43
+ var isTransactionViolationError = function (error, cause) {
44
+ return ((0, arvo_core_1.isViolationError)(error) &&
45
+ error.type === 'OrchestratorTransaction' &&
46
+ (cause ? error.cause === cause : true));
47
+ };
48
+ exports.isTransactionViolationError = isTransactionViolationError;
@@ -0,0 +1,35 @@
1
+ import { type Span } from '@opentelemetry/api';
2
+ import { type ArvoEvent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract, type ViolationError } from 'arvo-core';
3
+ import type { SyncEventResource } from '../SyncEventResource';
4
+ import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
5
+ import type { ArvoOrchestrationHandlerType } from './types';
6
+ /**
7
+ * Parameters for system error event creation
8
+ */
9
+ export type CreateSystemErrorEventsParams = {
10
+ error: unknown;
11
+ event: ArvoEvent;
12
+ otelHeaders: OpenTelemetryHeaders;
13
+ orchestrationParentSubject: string | null;
14
+ initEventId: string | null;
15
+ selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
16
+ systemErrorDomain?: (string | null)[];
17
+ executionunits: number;
18
+ source: string;
19
+ domain: string | null;
20
+ };
21
+ /**
22
+ * Creates system error events
23
+ */
24
+ export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, }: CreateSystemErrorEventsParams & {
25
+ error: Error;
26
+ }) => ArvoEvent[];
27
+ export declare const handleOrchestrationErrors: (_handlerType: ArvoOrchestrationHandlerType, param: CreateSystemErrorEventsParams & {
28
+ syncEventResource: SyncEventResource<OrchestrationExecutionMemoryRecord<Record<string, any>>>;
29
+ }, span: Span) => Promise<{
30
+ errorToThrow: ViolationError;
31
+ events: null;
32
+ } | {
33
+ errorToThrow: null;
34
+ events: ArvoEvent[];
35
+ }>;