arvo-core 1.0.12 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
@@ -15,7 +15,7 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
|
|
15
15
|
readonly dataschema: string | null;
|
16
16
|
readonly data: TData;
|
17
17
|
readonly time: string;
|
18
|
-
extensions: TExtension & ArvoExtension & OpenTelemetryExtension;
|
18
|
+
readonly extensions: TExtension & ArvoExtension & OpenTelemetryExtension;
|
19
19
|
/**
|
20
20
|
* Creates an instance of ArvoEvent.
|
21
21
|
* @param context - The CloudEvent context along with Arvo and OpenTelemetry extensions.
|
@@ -86,4 +86,70 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
|
|
86
86
|
'cloudevents.arvo.event_to': string;
|
87
87
|
'cloudevents.arvo.event_executionunits': string | number;
|
88
88
|
};
|
89
|
+
/**
|
90
|
+
* Gets the 'to' field from the ArvoExtension.
|
91
|
+
* This field represents the intended recipient or destination of the event.
|
92
|
+
* @returns The value of the 'to' field.
|
93
|
+
*
|
94
|
+
* @remark
|
95
|
+
* This is a convenience getter for the data in `this.extensions.to` as this
|
96
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
97
|
+
* spec.
|
98
|
+
*/
|
99
|
+
get to(): string | null;
|
100
|
+
/**
|
101
|
+
* Gets the 'accesscontrol' field from the ArvoExtension.
|
102
|
+
* This field contains access control information for the event.
|
103
|
+
* @returns The value of the 'accesscontrol' field.
|
104
|
+
*
|
105
|
+
* @remark
|
106
|
+
* This is a convenience getter for the data in `this.extensions.accesscontrol` as this
|
107
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
108
|
+
* spec.
|
109
|
+
*/
|
110
|
+
get accesscontrol(): string | null;
|
111
|
+
/**
|
112
|
+
* Gets the 'redirectto' field from the ArvoExtension.
|
113
|
+
* This field indicate an alternative destination for the event.
|
114
|
+
* @returns The value of the 'redirectto' field.
|
115
|
+
*
|
116
|
+
* @remark
|
117
|
+
* This is a convenience getter for the data in `this.extensions.redirectto` as this
|
118
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
119
|
+
* spec.
|
120
|
+
*/
|
121
|
+
get redirectto(): string | null;
|
122
|
+
/**
|
123
|
+
* Gets the 'executionunits' field from the ArvoExtension.
|
124
|
+
* This field contains information about the execution units associated with the event.
|
125
|
+
* @returns The value of the 'executionunits' field.
|
126
|
+
*
|
127
|
+
* @remark
|
128
|
+
* This is a convenience getter for the data in `this.extensions.executionunits` as this
|
129
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
130
|
+
* spec.
|
131
|
+
*/
|
132
|
+
get executionunits(): number | null;
|
133
|
+
/**
|
134
|
+
* Gets the 'traceparent' field from the OpenTelemetryExtension.
|
135
|
+
* This field contains the W3C Trace Context traceparent header.
|
136
|
+
* @returns The value of the 'traceparent' field.
|
137
|
+
*
|
138
|
+
* @remark
|
139
|
+
* This is a convenience getter for the data in `this.extensions.traceparent` as this
|
140
|
+
* is an ArvoEvent object which natively defined this extension on the CloudEvent
|
141
|
+
* spec.
|
142
|
+
*/
|
143
|
+
get traceparent(): string | null;
|
144
|
+
/**
|
145
|
+
* Gets the 'tracestate' field from the OpenTelemetryExtension.
|
146
|
+
* This field contains the W3C Trace Context tracestate header.
|
147
|
+
* @returns The value of the 'tracestate' field, or undefined if not set.
|
148
|
+
*
|
149
|
+
* @remark
|
150
|
+
* This is a convenience getter for the data in `this.extensions.tracestate` as this
|
151
|
+
* is an ArvoEvent object which natively defined this extension on the CloudEvent
|
152
|
+
* spec.
|
153
|
+
*/
|
154
|
+
get tracestate(): string | null;
|
89
155
|
}
|
package/dist/ArvoEvent/index.js
CHANGED
@@ -122,6 +122,108 @@ var ArvoEvent = /** @class */ (function () {
|
|
122
122
|
enumerable: false,
|
123
123
|
configurable: true
|
124
124
|
});
|
125
|
+
Object.defineProperty(ArvoEvent.prototype, "to", {
|
126
|
+
/**
|
127
|
+
* Gets the 'to' field from the ArvoExtension.
|
128
|
+
* This field represents the intended recipient or destination of the event.
|
129
|
+
* @returns The value of the 'to' field.
|
130
|
+
*
|
131
|
+
* @remark
|
132
|
+
* This is a convenience getter for the data in `this.extensions.to` as this
|
133
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
134
|
+
* spec.
|
135
|
+
*/
|
136
|
+
get: function () {
|
137
|
+
return this.extensions.to;
|
138
|
+
},
|
139
|
+
enumerable: false,
|
140
|
+
configurable: true
|
141
|
+
});
|
142
|
+
Object.defineProperty(ArvoEvent.prototype, "accesscontrol", {
|
143
|
+
/**
|
144
|
+
* Gets the 'accesscontrol' field from the ArvoExtension.
|
145
|
+
* This field contains access control information for the event.
|
146
|
+
* @returns The value of the 'accesscontrol' field.
|
147
|
+
*
|
148
|
+
* @remark
|
149
|
+
* This is a convenience getter for the data in `this.extensions.accesscontrol` as this
|
150
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
151
|
+
* spec.
|
152
|
+
*/
|
153
|
+
get: function () {
|
154
|
+
return this.extensions.accesscontrol;
|
155
|
+
},
|
156
|
+
enumerable: false,
|
157
|
+
configurable: true
|
158
|
+
});
|
159
|
+
Object.defineProperty(ArvoEvent.prototype, "redirectto", {
|
160
|
+
/**
|
161
|
+
* Gets the 'redirectto' field from the ArvoExtension.
|
162
|
+
* This field indicate an alternative destination for the event.
|
163
|
+
* @returns The value of the 'redirectto' field.
|
164
|
+
*
|
165
|
+
* @remark
|
166
|
+
* This is a convenience getter for the data in `this.extensions.redirectto` as this
|
167
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
168
|
+
* spec.
|
169
|
+
*/
|
170
|
+
get: function () {
|
171
|
+
return this.extensions.redirectto;
|
172
|
+
},
|
173
|
+
enumerable: false,
|
174
|
+
configurable: true
|
175
|
+
});
|
176
|
+
Object.defineProperty(ArvoEvent.prototype, "executionunits", {
|
177
|
+
/**
|
178
|
+
* Gets the 'executionunits' field from the ArvoExtension.
|
179
|
+
* This field contains information about the execution units associated with the event.
|
180
|
+
* @returns The value of the 'executionunits' field.
|
181
|
+
*
|
182
|
+
* @remark
|
183
|
+
* This is a convenience getter for the data in `this.extensions.executionunits` as this
|
184
|
+
* is an ArvoEvent object which natively defines this extension on the CloudEvent
|
185
|
+
* spec.
|
186
|
+
*/
|
187
|
+
get: function () {
|
188
|
+
return this.extensions.executionunits;
|
189
|
+
},
|
190
|
+
enumerable: false,
|
191
|
+
configurable: true
|
192
|
+
});
|
193
|
+
Object.defineProperty(ArvoEvent.prototype, "traceparent", {
|
194
|
+
/**
|
195
|
+
* Gets the 'traceparent' field from the OpenTelemetryExtension.
|
196
|
+
* This field contains the W3C Trace Context traceparent header.
|
197
|
+
* @returns The value of the 'traceparent' field.
|
198
|
+
*
|
199
|
+
* @remark
|
200
|
+
* This is a convenience getter for the data in `this.extensions.traceparent` as this
|
201
|
+
* is an ArvoEvent object which natively defined this extension on the CloudEvent
|
202
|
+
* spec.
|
203
|
+
*/
|
204
|
+
get: function () {
|
205
|
+
return this.extensions.traceparent;
|
206
|
+
},
|
207
|
+
enumerable: false,
|
208
|
+
configurable: true
|
209
|
+
});
|
210
|
+
Object.defineProperty(ArvoEvent.prototype, "tracestate", {
|
211
|
+
/**
|
212
|
+
* Gets the 'tracestate' field from the OpenTelemetryExtension.
|
213
|
+
* This field contains the W3C Trace Context tracestate header.
|
214
|
+
* @returns The value of the 'tracestate' field, or undefined if not set.
|
215
|
+
*
|
216
|
+
* @remark
|
217
|
+
* This is a convenience getter for the data in `this.extensions.tracestate` as this
|
218
|
+
* is an ArvoEvent object which natively defined this extension on the CloudEvent
|
219
|
+
* spec.
|
220
|
+
*/
|
221
|
+
get: function () {
|
222
|
+
return this.extensions.tracestate;
|
223
|
+
},
|
224
|
+
enumerable: false,
|
225
|
+
configurable: true
|
226
|
+
});
|
125
227
|
return ArvoEvent;
|
126
228
|
}());
|
127
229
|
exports.default = ArvoEvent;
|
@@ -22,13 +22,15 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
22
22
|
* Creates an ArvoEvent as per the accept record of the contract.
|
23
23
|
*
|
24
24
|
* @template TExtension - The type of extensions to add to the event.
|
25
|
-
* @param event - The event to create.
|
25
|
+
* @param event - The event to create. The field 'type' is automatically infered
|
26
26
|
* @param [extensions] - Optional extensions to add to the event.
|
27
27
|
* @param [telemetry] - Optional telemetry context for tracing.
|
28
28
|
* @returns The created ArvoEvent as per the accept record of the contract.
|
29
29
|
* @throws If the event data fails validation against the contract.
|
30
30
|
*/
|
31
|
-
accepts<TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TAcceptSchema>, TType>,
|
31
|
+
accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TAcceptSchema>, TType>, 'type'> & {
|
32
|
+
to: string;
|
33
|
+
}, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, string>;
|
32
34
|
/**
|
33
35
|
* Creates an ArvoEvent as per one of the emits record in the contract.
|
34
36
|
*
|
@@ -40,7 +42,9 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
40
42
|
* @returns The created ArvoEvent as per one of the emits records of the contract.
|
41
43
|
* @throws If the event data fails validation against the contract.
|
42
44
|
*/
|
43
|
-
emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TEmits[U]>, U
|
45
|
+
emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TEmits[U]>, U> & {
|
46
|
+
to: string;
|
47
|
+
}, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<z.TypeOf<TEmits[U]>>, TExtension, string>;
|
44
48
|
/**
|
45
49
|
* Creates a system error ArvoEvent.
|
46
50
|
*
|
@@ -52,6 +56,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
|
|
52
56
|
*/
|
53
57
|
systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type'> & {
|
54
58
|
error: Error;
|
59
|
+
to: string;
|
55
60
|
}, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<{
|
56
61
|
errorName: string;
|
57
62
|
errorMessage: string;
|
@@ -46,7 +46,7 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
46
46
|
* Creates an ArvoEvent as per the accept record of the contract.
|
47
47
|
*
|
48
48
|
* @template TExtension - The type of extensions to add to the event.
|
49
|
-
* @param event - The event to create.
|
49
|
+
* @param event - The event to create. The field 'type' is automatically infered
|
50
50
|
* @param [extensions] - Optional extensions to add to the event.
|
51
51
|
* @param [telemetry] - Optional telemetry context for tracing.
|
52
52
|
* @returns The created ArvoEvent as per the accept record of the contract.
|
@@ -55,11 +55,11 @@ var ArvoEventFactory = /** @class */ (function () {
|
|
55
55
|
ArvoEventFactory.prototype.accepts = function (event, extensions, telemetry) {
|
56
56
|
var _this = this;
|
57
57
|
return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'ContractualArvoEventFactory.accepts', {}, function () {
|
58
|
-
var validationResult = _this.contract.validateInput(
|
58
|
+
var validationResult = _this.contract.validateInput(_this.contract.accepts.type, event.data);
|
59
59
|
if (!validationResult.success) {
|
60
60
|
throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
|
61
61
|
}
|
62
|
-
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions, telemetry);
|
62
|
+
return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions, telemetry);
|
63
63
|
});
|
64
64
|
};
|
65
65
|
/**
|
@@ -152,6 +152,9 @@ var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedF
|
|
152
152
|
activeTracer = telemetryContext.tracer;
|
153
153
|
}
|
154
154
|
var newSpan = activeTracer.startSpan(spanName, spanOptions, activeContext);
|
155
|
+
newSpan.setStatus({
|
156
|
+
code: api_1.SpanStatusCode.OK,
|
157
|
+
});
|
155
158
|
try {
|
156
159
|
var result = api_1.context.with(api_1.trace.setSpan(activeContext, newSpan), function () {
|
157
160
|
return wrappedFunction.call.apply(wrappedFunction, __spreadArray([thisArg,
|
@@ -161,9 +164,6 @@ var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedF
|
|
161
164
|
carrier: (0, exports.getTelemetryCarrier)(newSpan, activeContext),
|
162
165
|
}], args, false));
|
163
166
|
});
|
164
|
-
newSpan.setStatus({
|
165
|
-
code: api_1.SpanStatusCode.OK,
|
166
|
-
});
|
167
167
|
newSpan.end();
|
168
168
|
return result;
|
169
169
|
}
|