arvo-core 2.2.7 → 2.2.9
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/CHANGELOG.md +4 -0
- package/dist/ArvoEventFactory/Orchestrator.d.ts +6 -2
- package/dist/ArvoEventFactory/Orchestrator.js +18 -7
- package/dist/ArvoEventFactory/index.d.ts +8 -3
- package/dist/ArvoEventFactory/index.js +42 -6
- package/dist/ArvoOrchestrationSubject/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -27,7 +27,9 @@ export declare class ArvoOrchestratorEventFactory<TContract extends VersionedArv
|
|
27
27
|
*
|
28
28
|
* @throws Error if event validation fails
|
29
29
|
*/
|
30
|
-
init<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject'
|
30
|
+
init<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
|
31
|
+
subject?: string;
|
32
|
+
}, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["accepts"]["schema"]>, TExtension, TContract["accepts"]["type"]>;
|
31
33
|
/**
|
32
34
|
* Creates a completion event for the orchestration flow.
|
33
35
|
* Uses the contract's configured complete event type from metadata.
|
@@ -38,5 +40,7 @@ export declare class ArvoOrchestratorEventFactory<TContract extends VersionedArv
|
|
38
40
|
*
|
39
41
|
* @throws Error if event validation fails or complete event type not configured
|
40
42
|
*/
|
41
|
-
complete<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][TContract['metadata']['completeEventType']]>, TContract['metadata']['completeEventType']>, 'datacontenttype' | 'dataschema' | 'type'
|
43
|
+
complete<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][TContract['metadata']['completeEventType']]>, TContract['metadata']['completeEventType']>, 'datacontenttype' | 'dataschema' | 'type' | 'subject'> & {
|
44
|
+
subject?: string;
|
45
|
+
}, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["emits"][TContract["metadata"]["completeEventType"]]>, TExtension, TContract["metadata"]["completeEventType"]>;
|
42
46
|
}
|
@@ -77,20 +77,20 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
|
|
77
77
|
name: "".concat(this._name, ".init"),
|
78
78
|
spanOptions: (0, utils_2.createSpanOptions)(this.contract),
|
79
79
|
fn: function (span) {
|
80
|
-
var _a, _b, _c, _d, _e;
|
80
|
+
var _a, _b, _c, _d, _e, _f;
|
81
81
|
var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
|
82
82
|
var validationResult = _this.contract.accepts.schema.safeParse(event.data);
|
83
83
|
if (!validationResult.success) {
|
84
84
|
throw new Error("Init Event data validation failed: ".concat(validationResult.error.message));
|
85
85
|
}
|
86
86
|
var parentSubject = validationResult.data.parentSubject$$;
|
87
|
-
var
|
87
|
+
var eventSubject = (_a = event.subject) !== null && _a !== void 0 ? _a : (parentSubject
|
88
88
|
? ArvoOrchestrationSubject_1.default.from({
|
89
89
|
orchestator: _this.contract.accepts.type,
|
90
90
|
subject: parentSubject,
|
91
91
|
version: _this.contract.version,
|
92
92
|
meta: Object.fromEntries(Object.entries({
|
93
|
-
redirectto: (
|
93
|
+
redirectto: (_b = event.redirectto) !== null && _b !== void 0 ? _b : ArvoOrchestrationSubject_1.default.parse(parentSubject).execution.initiator,
|
94
94
|
}).filter(function (item) { return Boolean(item[1]); })),
|
95
95
|
})
|
96
96
|
: ArvoOrchestrationSubject_1.default.new({
|
@@ -102,8 +102,8 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
|
|
102
102
|
redirectto: event.redirectto,
|
103
103
|
}
|
104
104
|
: undefined,
|
105
|
-
});
|
106
|
-
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject:
|
105
|
+
}));
|
106
|
+
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_d = (_c = event.traceparent) !== null && _c !== void 0 ? _c : otelHeaders.traceparent) !== null && _d !== void 0 ? _d : undefined, tracestate: (_f = (_e = event.tracestate) !== null && _e !== void 0 ? _e : otelHeaders.tracestate) !== null && _f !== void 0 ? _f : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
|
107
107
|
span.setAttributes(generatedEvent.otelAttributes);
|
108
108
|
return generatedEvent;
|
109
109
|
},
|
@@ -125,14 +125,25 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
|
|
125
125
|
name: "".concat(this._name, ".complete"),
|
126
126
|
spanOptions: (0, utils_2.createSpanOptions)(this.contract),
|
127
127
|
fn: function (span) {
|
128
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
128
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
129
129
|
var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
|
130
130
|
var validationResult = (_b = (_a = _this.contract.emits) === null || _a === void 0 ? void 0 : _a[_this.contract.metadata.completeEventType]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
|
131
131
|
if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
|
132
132
|
var msg = (_d = (_c = validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : "No schema available for ".concat(_this.contract.metadata.completeEventType);
|
133
133
|
throw new Error("Emit Event data validation failed: ".concat(msg));
|
134
134
|
}
|
135
|
-
var
|
135
|
+
var eventType = _this.contract.metadata.completeEventType;
|
136
|
+
var eventSubject = (_e = event.subject) !== null && _e !== void 0 ? _e : ArvoOrchestrationSubject_1.default.new({
|
137
|
+
initiator: event.source,
|
138
|
+
version: _this.contract.version,
|
139
|
+
orchestator: eventType,
|
140
|
+
meta: event.redirectto
|
141
|
+
? {
|
142
|
+
redirectto: event.redirectto,
|
143
|
+
}
|
144
|
+
: undefined,
|
145
|
+
});
|
146
|
+
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, type: eventType, traceparent: (_g = (_f = event.traceparent) !== null && _f !== void 0 ? _f : otelHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined, tracestate: (_j = (_h = event.tracestate) !== null && _h !== void 0 ? _h : otelHeaders.tracestate) !== null && _j !== void 0 ? _j : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
|
136
147
|
span.setAttributes(generatedEvent.otelAttributes);
|
137
148
|
return generatedEvent;
|
138
149
|
},
|
@@ -44,7 +44,9 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
|
|
44
44
|
* });
|
45
45
|
* ```
|
46
46
|
*/
|
47
|
-
accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema'
|
47
|
+
accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
|
48
|
+
subject?: string;
|
49
|
+
}, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["accepts"]["schema"]>, TExtension, TContract["accepts"]["type"]>;
|
48
50
|
/**
|
49
51
|
* Creates and validates an event matching one of the contract's emit specifications.
|
50
52
|
*
|
@@ -64,7 +66,9 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
|
|
64
66
|
* });
|
65
67
|
* ```
|
66
68
|
*/
|
67
|
-
emits<U extends string & keyof TContract['emits'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][U]>, U>, 'datacontenttype' | 'dataschema'
|
69
|
+
emits<U extends string & keyof TContract['emits'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][U]>, U>, 'datacontenttype' | 'dataschema' | 'subject'> & {
|
70
|
+
subject?: string;
|
71
|
+
}, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["emits"][U]>, TExtension, U>;
|
68
72
|
/**
|
69
73
|
* Creates a system error event for error reporting and handling.
|
70
74
|
*
|
@@ -84,8 +88,9 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
|
|
84
88
|
* });
|
85
89
|
* ```
|
86
90
|
*/
|
87
|
-
systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
|
91
|
+
systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
|
88
92
|
error: Error;
|
93
|
+
subject?: string;
|
89
94
|
}, extensions?: TExtension): import("..").ArvoEvent<{
|
90
95
|
errorName: string;
|
91
96
|
errorMessage: string;
|
@@ -21,9 +21,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
21
21
|
}
|
22
22
|
return t;
|
23
23
|
};
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
26
|
+
};
|
24
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
25
28
|
var helpers_1 = require("../ArvoEvent/helpers");
|
26
29
|
var schema_1 = require("../ArvoEvent/schema");
|
30
|
+
var ArvoOrchestrationSubject_1 = __importDefault(require("../ArvoOrchestrationSubject"));
|
27
31
|
var OpenTelemetry_1 = require("../OpenTelemetry");
|
28
32
|
var utils_1 = require("../utils");
|
29
33
|
var utils_2 = require("./utils");
|
@@ -77,13 +81,24 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
77
81
|
name: "".concat(this._name, ".accepts"),
|
78
82
|
spanOptions: (0, utils_2.createSpanOptions)(this.contract),
|
79
83
|
fn: function (span) {
|
80
|
-
var _a, _b, _c, _d;
|
84
|
+
var _a, _b, _c, _d, _e;
|
81
85
|
var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
|
82
86
|
var validationResult = _this.contract.accepts.schema.safeParse(event.data);
|
83
87
|
if (!validationResult.success) {
|
84
88
|
throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
|
85
89
|
}
|
86
|
-
var
|
90
|
+
var eventType = _this.contract.accepts.type;
|
91
|
+
var eventSubject = (_a = event.subject) !== null && _a !== void 0 ? _a : ArvoOrchestrationSubject_1.default.new({
|
92
|
+
initiator: event.source,
|
93
|
+
version: _this.contract.version,
|
94
|
+
orchestator: _this.contract.accepts.type,
|
95
|
+
meta: event.redirectto
|
96
|
+
? {
|
97
|
+
redirectto: event.redirectto,
|
98
|
+
}
|
99
|
+
: undefined,
|
100
|
+
});
|
101
|
+
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
|
87
102
|
span.setAttributes(generatedEvent.otelAttributes);
|
88
103
|
return generatedEvent;
|
89
104
|
},
|
@@ -114,14 +129,24 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
114
129
|
name: "".concat(this._name, ".emits<").concat(event.type, ">"),
|
115
130
|
spanOptions: (0, utils_2.createSpanOptions)(this.contract),
|
116
131
|
fn: function (span) {
|
117
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
118
133
|
var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
|
119
134
|
var validationResult = (_b = (_a = _this.contract.emits) === null || _a === void 0 ? void 0 : _a[event.type]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
|
120
135
|
if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
|
121
136
|
var msg = (_d = (_c = validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : "No contract available for ".concat(event.type);
|
122
137
|
throw new Error("Emit Event data validation failed: ".concat(msg));
|
123
138
|
}
|
124
|
-
var
|
139
|
+
var eventSubject = (_e = event.subject) !== null && _e !== void 0 ? _e : ArvoOrchestrationSubject_1.default.new({
|
140
|
+
initiator: event.source,
|
141
|
+
version: _this.contract.version,
|
142
|
+
orchestator: event.type,
|
143
|
+
meta: event.redirectto
|
144
|
+
? {
|
145
|
+
redirectto: event.redirectto,
|
146
|
+
}
|
147
|
+
: undefined,
|
148
|
+
});
|
149
|
+
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_g = (_f = event.traceparent) !== null && _f !== void 0 ? _f : otelHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined, tracestate: (_j = (_h = event.tracestate) !== null && _h !== void 0 ? _h : otelHeaders.tracestate) !== null && _j !== void 0 ? _j : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
|
125
150
|
span.setAttributes(generatedEvent.otelAttributes);
|
126
151
|
return generatedEvent;
|
127
152
|
},
|
@@ -152,10 +177,21 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
152
177
|
name: "".concat(this._name, ".systemError"),
|
153
178
|
spanOptions: (0, utils_2.createSpanOptions)(this.contract),
|
154
179
|
fn: function (span) {
|
155
|
-
var _a, _b, _c, _d;
|
180
|
+
var _a, _b, _c, _d, _e;
|
156
181
|
var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
|
157
182
|
var error = event.error, _event = __rest(event, ["error"]);
|
158
|
-
var
|
183
|
+
var eventType = _this.contract.systemError.type;
|
184
|
+
var eventSubject = (_a = event.subject) !== null && _a !== void 0 ? _a : ArvoOrchestrationSubject_1.default.new({
|
185
|
+
initiator: event.source,
|
186
|
+
version: _this.contract.version,
|
187
|
+
orchestator: eventType,
|
188
|
+
meta: event.redirectto
|
189
|
+
? {
|
190
|
+
redirectto: event.redirectto,
|
191
|
+
}
|
192
|
+
: undefined,
|
193
|
+
});
|
194
|
+
var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, data: (0, utils_1.createArvoError)(error), datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.createWithWildCardVersion(_this.contract) }), extensions, { disable: true });
|
159
195
|
span.setAttributes(generatedEvent.otelAttributes);
|
160
196
|
return generatedEvent;
|
161
197
|
},
|