arvo-core 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,9 +26,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
26
26
  * @returns The created ArvoEvent as per the accept record of the contract.
27
27
  * @throws If the event data fails validation against the contract.
28
28
  */
29
- accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TAcceptSchema>, TType>, 'type'> & {
30
- to: string;
31
- }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
29
+ accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TAcceptSchema>, TType>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
32
30
  /**
33
31
  * Creates an ArvoEvent as per one of the emits record in the contract.
34
32
  *
@@ -39,9 +37,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
39
37
  * @returns The created ArvoEvent as per one of the emits records of the contract.
40
38
  * @throws If the event data fails validation against the contract.
41
39
  */
42
- emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TEmits[U]>, U> & {
43
- to: string;
44
- }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
40
+ emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TEmits[U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
45
41
  /**
46
42
  * Creates a system error ArvoEvent.
47
43
  *
@@ -50,9 +46,8 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
50
46
  * @param [extensions] - Optional extensions to add to the event.
51
47
  * @returns The created system error ArvoEvent.
52
48
  */
53
- systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type'> & {
49
+ systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
54
50
  error: Error;
55
- to: string;
56
51
  }, extensions?: TExtension): import("..").ArvoEvent<{
57
52
  errorMessage: string;
58
53
  errorName: string;
@@ -127,8 +127,8 @@ var ArvoEventFactory = /** @class */ (function () {
127
127
  var _a;
128
128
  span.setStatus({ code: api_1.SpanStatusCode.OK });
129
129
  try {
130
- var error = event.error, _events = __rest(event, ["error"]);
131
- return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { type: "sys.".concat(_this.contract.accepts.type, ".error"), data: {
130
+ var error = event.error, _event = __rest(event, ["error"]);
131
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { type: "sys.".concat(_this.contract.accepts.type, ".error"), data: {
132
132
  errorName: error.name,
133
133
  errorMessage: error.message,
134
134
  errorStack: (_a = error.stack) !== null && _a !== void 0 ? _a : null,
@@ -88,7 +88,7 @@ var ArvoEventHttp = /** @class */ (function () {
88
88
  */
89
89
  ArvoEventHttp.importFromBinary = function (config) {
90
90
  var _a, _b;
91
- this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "", 'application/json');
91
+ this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '', 'application/json');
92
92
  var event = this.extractEventFieldsFromHeaders(config.headers);
93
93
  this.validateRequiredFields(event, true);
94
94
  var extensions = this.extractExtensions(config.headers);
@@ -102,7 +102,7 @@ var ArvoEventHttp = /** @class */ (function () {
102
102
  */
103
103
  ArvoEventHttp.importFromStructured = function (config) {
104
104
  var _a, _b;
105
- this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "", schema_1.ArvoDataContentType);
105
+ this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '', schema_1.ArvoDataContentType);
106
106
  var eventData = config.data;
107
107
  this.validateRequiredFields(eventData, false);
108
108
  return this.createArvoEventFromStructured(eventData);
@@ -124,7 +124,22 @@ var ArvoEventHttp = /** @class */ (function () {
124
124
  * @returns An object with extracted event fields.
125
125
  */
126
126
  ArvoEventHttp.extractEventFieldsFromHeaders = function (headers) {
127
- var eventFields = ['id', 'type', 'accesscontrol', 'executionunits', 'traceparent', 'tracestate', 'datacontenttype', 'specversion', 'time', 'source', 'subject', 'to', 'redirectto', 'dataschema'];
127
+ var eventFields = [
128
+ 'id',
129
+ 'type',
130
+ 'accesscontrol',
131
+ 'executionunits',
132
+ 'traceparent',
133
+ 'tracestate',
134
+ 'datacontenttype',
135
+ 'specversion',
136
+ 'time',
137
+ 'source',
138
+ 'subject',
139
+ 'to',
140
+ 'redirectto',
141
+ 'dataschema',
142
+ ];
128
143
  return Object.fromEntries(eventFields
129
144
  .map(function (field) { return ["ce-".concat(field), headers["ce-".concat(field)]]; })
130
145
  .filter(function (_a) {
@@ -167,7 +182,22 @@ var ArvoEventHttp = /** @class */ (function () {
167
182
  * @returns An object with extracted extension fields.
168
183
  */
169
184
  ArvoEventHttp.extractExtensions = function (headers) {
170
- var eventFields = ['id', 'type', 'accesscontrol', 'executionunits', 'traceparent', 'tracestate', 'datacontenttype', 'specversion', 'time', 'source', 'subject', 'to', 'redirectto', 'dataschema'];
185
+ var eventFields = [
186
+ 'id',
187
+ 'type',
188
+ 'accesscontrol',
189
+ 'executionunits',
190
+ 'traceparent',
191
+ 'tracestate',
192
+ 'datacontenttype',
193
+ 'specversion',
194
+ 'time',
195
+ 'source',
196
+ 'subject',
197
+ 'to',
198
+ 'redirectto',
199
+ 'dataschema',
200
+ ];
171
201
  return Object.fromEntries(Object.entries(headers)
172
202
  .filter(function (_a) {
173
203
  var key = _a[0];
@@ -191,7 +221,9 @@ var ArvoEventHttp = /** @class */ (function () {
191
221
  id: (_a = event.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
192
222
  type: event.type,
193
223
  accesscontrol: (_b = event.accesscontrol) !== null && _b !== void 0 ? _b : null,
194
- executionunits: event.executionunits ? Number(event.executionunits) : null,
224
+ executionunits: event.executionunits
225
+ ? Number(event.executionunits)
226
+ : null,
195
227
  traceparent: (_c = event.traceparent) !== null && _c !== void 0 ? _c : null,
196
228
  tracestate: (_d = event.tracestate) !== null && _d !== void 0 ? _d : null,
197
229
  datacontenttype: (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : schema_1.ArvoDataContentType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {