arvo-core 1.1.13 → 1.1.15

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -24,6 +24,16 @@ Key features of Arvo include:
24
24
 
25
25
  Whether you're building a small microservice or a large-scale distributed system, my hope with Arvo is to offers you some of the tools and patterns to help you succeed in the world of event-driven architecture.
26
26
 
27
+ ## Arvo suite
28
+
29
+ Arvo is a collection of libraries which allows you to build the event driven system in the Arvo pattern. However, if you feel you don't have to use them or you can use them as you see fit.
30
+
31
+ | Scope | NPM | Github | Documentation |
32
+ | ------------ | ------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- |
33
+ | Orchestration | https://www.npmjs.com/package/arvo-xstate?activeTab=readme | https://github.com/SaadAhmad123/arvo-xstate | https://saadahmad123.github.io/arvo-xstate/index.html |
34
+ | Core | https://www.npmjs.com/package/arvo-core?activeTab=readme | https://github.com/SaadAhmad123/arvo-core | https://saadahmad123.github.io/arvo-core/index.html |
35
+ | Event Handling | https://www.npmjs.com/package/arvo-event-handler?activeTab=readme | https://github.com/SaadAhmad123/arvo-event-handler | https://saadahmad123.github.io/arvo-event-handler/index.html |
36
+
27
37
  # Arvo - Core
28
38
 
29
39
  This core package defines primitive types and utility functions to help you quickly start building interesting and robust event-driven applications.
@@ -48,8 +48,9 @@ var uuid_1 = require("uuid");
48
48
  var createArvoEvent = function (event, extensions) {
49
49
  var span = OpenTelemetry_1.ArvoCoreTracer.startSpan("createArvoEvent<".concat(event.type, ">"), {});
50
50
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
51
- var _a, _b, _c, _d, _e, _f, _g, _h;
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
52
52
  span.setStatus({ code: api_1.SpanStatusCode.OK });
53
+ var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
53
54
  try {
54
55
  if (event.datacontenttype &&
55
56
  event.datacontenttype !== schema_1.ArvoDataContentType) {
@@ -64,11 +65,11 @@ var createArvoEvent = function (event, extensions) {
64
65
  type: event.type,
65
66
  accesscontrol: (_b = event.accesscontrol) !== null && _b !== void 0 ? _b : null,
66
67
  executionunits: (_c = event.executionunits) !== null && _c !== void 0 ? _c : null,
67
- traceparent: (_d = event.traceparent) !== null && _d !== void 0 ? _d : null,
68
- tracestate: (_e = event.tracestate) !== null && _e !== void 0 ? _e : null,
69
- datacontenttype: (_f = event.datacontenttype) !== null && _f !== void 0 ? _f : schema_1.ArvoDataContentType,
70
- specversion: (_g = event.specversion) !== null && _g !== void 0 ? _g : '1.0',
71
- time: (_h = event.time) !== null && _h !== void 0 ? _h : (0, utils_1.createTimestamp)(),
68
+ traceparent: (_e = (_d = event.traceparent) !== null && _d !== void 0 ? _d : otelHeaders.traceparent) !== null && _e !== void 0 ? _e : null,
69
+ tracestate: (_g = (_f = event.tracestate) !== null && _f !== void 0 ? _f : otelHeaders.tracestate) !== null && _g !== void 0 ? _g : null,
70
+ datacontenttype: (_h = event.datacontenttype) !== null && _h !== void 0 ? _h : schema_1.ArvoDataContentType,
71
+ specversion: (_j = event.specversion) !== null && _j !== void 0 ? _j : '1.0',
72
+ time: (_k = event.time) !== null && _k !== void 0 ? _k : (0, utils_1.createTimestamp)(),
72
73
  source: encodeURI(event.source),
73
74
  subject: encodeURI(event.subject),
74
75
  to: event.to ? encodeURI(event.to) : encodeURI(event.type),
@@ -26,7 +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' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
29
+ accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TAcceptSchema>, TType>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
30
30
  /**
31
31
  * Creates an ArvoEvent as per one of the emits record in the contract.
32
32
  *
@@ -37,7 +37,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
37
37
  * @returns The created ArvoEvent as per one of the emits records of the contract.
38
38
  * @throws If the event data fails validation against the contract.
39
39
  */
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>;
40
+ emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TEmits[U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
41
41
  /**
42
42
  * Creates a system error ArvoEvent.
43
43
  *
@@ -56,13 +56,15 @@ var ArvoEventFactory = /** @class */ (function () {
56
56
  var _this = this;
57
57
  var span = OpenTelemetry_1.ArvoCoreTracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.accepts<").concat(this.contract.accepts.type, ">.create"));
58
58
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
59
+ var _a, _b, _c, _d;
59
60
  span.setStatus({ code: api_1.SpanStatusCode.OK });
61
+ var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
60
62
  try {
61
63
  var validationResult = _this.contract.validateAccepts(_this.contract.accepts.type, event.data);
62
64
  if (!validationResult.success) {
63
65
  throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
64
66
  }
65
- 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);
67
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
66
68
  }
67
69
  catch (error) {
68
70
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -91,13 +93,15 @@ var ArvoEventFactory = /** @class */ (function () {
91
93
  var _this = this;
92
94
  var span = OpenTelemetry_1.ArvoCoreTracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.emits<").concat(event.type, ">.create"));
93
95
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
96
+ var _a, _b, _c, _d;
94
97
  span.setStatus({ code: api_1.SpanStatusCode.OK });
98
+ var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
95
99
  try {
96
100
  var validationResult = _this.contract.validateEmits(event.type, event.data);
97
101
  if (!validationResult.success) {
98
102
  throw new Error("Emit Event data validation failed: ".concat(validationResult.error.message));
99
103
  }
100
- return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
104
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
101
105
  }
102
106
  catch (error) {
103
107
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -124,14 +128,15 @@ var ArvoEventFactory = /** @class */ (function () {
124
128
  var _this = this;
125
129
  var span = OpenTelemetry_1.ArvoCoreTracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, ">.systemError<sys.").concat(this.contract.accepts.type, ".error>.create"));
126
130
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
127
- var _a;
131
+ var _a, _b, _c, _d, _e;
128
132
  span.setStatus({ code: api_1.SpanStatusCode.OK });
133
+ var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
129
134
  try {
130
135
  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: {
136
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { traceparent: (_b = (_a = event.traceparent) !== null && _a !== void 0 ? _a : otelHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined, tracestate: (_d = (_c = event.tracestate) !== null && _c !== void 0 ? _c : otelHeaders.tracestate) !== null && _d !== void 0 ? _d : undefined, type: "sys.".concat(_this.contract.accepts.type, ".error"), data: {
132
137
  errorName: error.name,
133
138
  errorMessage: error.message,
134
- errorStack: (_a = error.stack) !== null && _a !== void 0 ? _a : null,
139
+ errorStack: (_e = error.stack) !== null && _e !== void 0 ? _e : null,
135
140
  }, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri }), extensions);
136
141
  }
137
142
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
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": {