arvo-core 1.0.11 → 1.0.13
Sign up to get free protection for your applications and to get access to all the features.
@@ -47,7 +47,7 @@ export default class ArvoContract<TUri extends string = string, TType extends st
|
|
47
47
|
* @returns The validation result.
|
48
48
|
* @throws If the accept type is not found in the contract.
|
49
49
|
*/
|
50
|
-
validateInput<U>(type: TType, input: U): z.SafeParseReturnType<
|
50
|
+
validateInput<U>(type: TType, input: U): z.SafeParseReturnType<any, any>;
|
51
51
|
/**
|
52
52
|
* Validates the contract bound handler's output against the
|
53
53
|
* contract's emit schema.
|
@@ -57,9 +57,7 @@ export default class ArvoContract<TUri extends string = string, TType extends st
|
|
57
57
|
* @returns The validation result.
|
58
58
|
* @throws If the emit type is not found in the contract.
|
59
59
|
*/
|
60
|
-
validateOutput<U extends keyof TEmits>(type: U, output: unknown): z.SafeParseReturnType<
|
61
|
-
type: U;
|
62
|
-
}>['schema']>>;
|
60
|
+
validateOutput<U extends keyof TEmits>(type: U, output: unknown): z.SafeParseReturnType<any, any>;
|
63
61
|
/**
|
64
62
|
* Validates the accepts record.
|
65
63
|
* @param accepts - The accepts record to validate.
|
@@ -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
|
/**
|