arvo-core 1.0.12 → 1.0.13

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.
@@ -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>, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, string>;
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>, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<z.TypeOf<TEmits[U]>>, TExtension, string>;
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(event.type, event.data);
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
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": {