arvo-core 2.0.4 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -222,7 +222,7 @@ var ArvoContract = /** @class */ (function () {
222
222
  },
223
223
  systemError: {
224
224
  type: _this.systemError.type,
225
- schema: (0, zod_to_json_schema_1.zodToJsonSchema)(_this.systemError.schema)
225
+ schema: (0, zod_to_json_schema_1.zodToJsonSchema)(_this.systemError.schema),
226
226
  },
227
227
  emits: Object.entries(contract.emits).map(function (_a) {
228
228
  var key = _a[0], value = _a[1];
@@ -2,22 +2,23 @@ import ArvoEventFactory from '.';
2
2
  import ArvoContract from '../ArvoContract';
3
3
  import { ArvoSemanticVersion } from '../types';
4
4
  import ArvoEvent from '../ArvoEvent';
5
+ import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
5
6
  /**
6
- * Creates an ArvoEventFactory instance for a given contract.
7
- * This is the recommended way to instantiate an ArvoEventFactory.
7
+ * Creates an ArvoEventFactory for a specific version of a contract.
8
8
  *
9
- * @template TContract - The type of ArvoContract to create a factory for
9
+ * @template TContract - The versioned contract type
10
10
  *
11
- * @param contract - The ArvoContract instance to base the factory on
12
- * @returns A new ArvoEventFactory instance bound to the provided contract
11
+ * @param contract - The versioned contract to create a factory for
12
+ * @returns An ArvoEventFactory instance for the specified contract version
13
13
  *
14
14
  * @example
15
15
  * ```typescript
16
16
  * const contract = createArvoContract({...});
17
- * const factory = createArvoEventFactory(contract);
17
+ * const v1Contract = contract.version('1.0.0');
18
+ * const factory = createArvoEventFactory(v1Contract);
18
19
  * ```
19
20
  */
20
- export declare const createArvoEventFactory: <TContract extends ArvoContract>(contract: TContract) => ArvoEventFactory<TContract>;
21
+ export declare const createArvoEventFactory: <TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>>(contract: TContract) => ArvoEventFactory<TContract>;
21
22
  /**
22
23
  * Parses an event data schema string or ArvoEvent object to extract the URI and version.
23
24
  * The schema is expected to be in the format "uri/version" where version follows semantic versioning.
@@ -8,18 +8,18 @@ var _1 = __importDefault(require("."));
8
8
  var OpenTelemetry_1 = require("../OpenTelemetry");
9
9
  var schema_1 = require("../schema");
10
10
  /**
11
- * Creates an ArvoEventFactory instance for a given contract.
12
- * This is the recommended way to instantiate an ArvoEventFactory.
11
+ * Creates an ArvoEventFactory for a specific version of a contract.
13
12
  *
14
- * @template TContract - The type of ArvoContract to create a factory for
13
+ * @template TContract - The versioned contract type
15
14
  *
16
- * @param contract - The ArvoContract instance to base the factory on
17
- * @returns A new ArvoEventFactory instance bound to the provided contract
15
+ * @param contract - The versioned contract to create a factory for
16
+ * @returns An ArvoEventFactory instance for the specified contract version
18
17
  *
19
18
  * @example
20
19
  * ```typescript
21
20
  * const contract = createArvoContract({...});
22
- * const factory = createArvoEventFactory(contract);
21
+ * const v1Contract = contract.version('1.0.0');
22
+ * const factory = createArvoEventFactory(v1Contract);
23
23
  * ```
24
24
  */
25
25
  var createArvoEventFactory = function (contract) { return new _1.default(contract); };
@@ -3,79 +3,100 @@ import { z } from 'zod';
3
3
  import { CreateArvoEvent } from '../ArvoEvent/types';
4
4
  import { ExecutionOpenTelemetryConfiguration } from '../OpenTelemetry/types';
5
5
  import { ArvoSemanticVersion } from '../types';
6
+ import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
6
7
  /**
7
- * Factory class for creating contractual ArvoEvents based on a given ArvoContract.
8
- * This class handles the creation and validation of events according to contract specifications.
8
+ * Factory class for creating and validating events based on a versioned Arvo contract.
9
+ * Handles event creation, validation, and OpenTelemetry integration for a specific
10
+ * contract version.
9
11
  *
10
- * @template TContract - The type of ArvoContract this factory is bound to
12
+ * @template TContract - The versioned contract type this factory is bound to
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const contract = createArvoContract({
17
+ * uri: 'example/api',
18
+ * type: 'user.create',
19
+ * versions: { '1.0.0': { ... } }
20
+ * });
21
+ *
22
+ * const factory = createArvoEventFactory(contract.version('1.0.0'));
23
+ * ```
11
24
  */
12
- export default class ArvoEventFactory<TContract extends ArvoContract> {
25
+ export default class ArvoEventFactory<TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> {
13
26
  private readonly contract;
14
27
  /**
15
- * Creates an instance of ArvoEventFactory.
28
+ * Creates an ArvoEventFactory instance for a specific version of a contract.
16
29
  *
17
- * @param contract - The ArvoContract to base the events on.
30
+ * @param contract - The versioned contract to use for event creation and validation
18
31
  */
19
32
  constructor(contract: TContract);
20
33
  /**
21
- * Creates a validated ArvoEvent that matches the contract's accept specifications.
22
- * This method ensures the created event conforms to the contract's input schema.
34
+ * Creates and validates an event matching the contract's accept specification.
23
35
  *
24
- * @template V - The semantic version of the contract to use
25
- * @template TExtension - Additional custom properties to include in the event
36
+ * @template TExtension - Additional properties to include in the event
26
37
  *
27
38
  * @param event - The event configuration object
28
- * @param event.version - The semantic version of the contract to use
29
- * @param event.data - The event payload that must conform to the contract's accept schema
30
- * @param [extensions] - Optional additional properties to include in the event
31
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
39
+ * @param [extensions] - Optional additional properties for the event
40
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
41
+ *
42
+ * @returns A validated ArvoEvent matching the contract's accept specification
32
43
  *
33
- * @returns A validated ArvoEvent instance conforming to the contract's accept specifications
44
+ * @throws {Error} If validation fails or OpenTelemetry operations fail
34
45
  *
35
- * @throws {Error} If event data validation fails against the contract schema
36
- * @throws {Error} If OpenTelemetry operations fail
46
+ * @example
47
+ * ```typescript
48
+ * const event = factory.accepts({
49
+ * source: 'api/users',
50
+ * data: { name: 'John', email: 'john@example.com' }
51
+ * });
52
+ * ```
37
53
  */
38
- accepts<V extends ArvoSemanticVersion & keyof TContract['versions'], TExtension extends Record<string, any>>(event: {
39
- version: V;
40
- } & Omit<CreateArvoEvent<z.input<TContract['versions'][V]['accepts']>, TContract['type']>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TContract["versions"][V]["accepts"]>, TExtension, TContract["type"]>;
54
+ accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TContract["accepts"]["schema"]>, TExtension, TContract["accepts"]["type"]>;
41
55
  /**
42
- * Creates a validated ArvoEvent that matches one of the contract's emit specifications.
43
- * This method ensures the created event conforms to the contract's output schema.
56
+ * Creates and validates an event matching one of the contract's emit specifications.
44
57
  *
45
- * @template V - The semantic version of the contract to use
46
58
  * @template U - The specific emit event type from the contract
47
- * @template TExtension - Additional custom properties to include in the event
59
+ * @template TExtension - Additional properties to include in the event
48
60
  *
49
61
  * @param event - The event configuration object
50
- * @param event.version - The semantic version of the contract to use
51
- * @param event.type - The type of emit event to create
52
- * @param event.data - The event payload that must conform to the contract's emit schema
53
- * @param [extensions] - Optional additional properties to include in the event
54
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
62
+ * @param [extensions] - Optional additional properties for the event
63
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
55
64
  *
56
- * @returns A validated ArvoEvent instance conforming to the contract's emit specifications
65
+ * @returns A validated ArvoEvent matching the specified emit type
57
66
  *
58
- * @throws {Error} If event data validation fails against the contract schema
59
- * @throws {Error} If the specified emit type doesn't exist in the contract
60
- * @throws {Error} If OpenTelemetry operations fail
67
+ * @throws {Error} If validation fails, emit type doesn't exist, or OpenTelemetry operations fail
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const event = factory.emits({
72
+ * type: 'user.created',
73
+ * source: 'api/users',
74
+ * data: { id: '123', timestamp: new Date() }
75
+ * });
76
+ * ```
61
77
  */
62
- emits<V extends ArvoSemanticVersion & keyof TContract['versions'], U extends string & keyof TContract['versions'][V]['emits'], TExtension extends Record<string, any>>(event: {
63
- version: V;
64
- } & Omit<CreateArvoEvent<z.input<TContract['versions'][V]['emits'][U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TContract["versions"][V]["emits"][U]>, TExtension, U>;
78
+ emits<U extends string & keyof TContract['emits'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TContract["emits"][U]>, TExtension, U>;
65
79
  /**
66
- * Creates a system error ArvoEvent for handling and reporting errors within the system.
80
+ * Creates a system error event for error reporting and handling.
81
+ *
82
+ * @template TExtension - Additional properties to include in the error event
67
83
  *
68
- * @template TExtension - Additional custom properties to include in the error event
84
+ * @param event - The error event configuration
85
+ * @param event.error - The Error instance to convert to an event
86
+ * @param [extensions] - Optional additional properties for the event
87
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
69
88
  *
70
- * @param event - The error event configuration object
71
- * @param event.error - The Error instance to be converted into an event
72
- * @param [extensions] - Optional additional properties to include in the event
73
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
89
+ * @returns A system error ArvoEvent
74
90
  *
75
- * @returns A system error ArvoEvent containing the error details
91
+ * @throws {Error} If event creation or OpenTelemetry operations fail
76
92
  *
77
- * @throws {Error} If event creation fails
78
- * @throws {Error} If OpenTelemetry operations fail
93
+ * @example
94
+ * ```typescript
95
+ * const errorEvent = factory.systemError({
96
+ * error: new Error('Validation failed'),
97
+ * source: 'api/validation'
98
+ * });
99
+ * ```
79
100
  */
80
101
  systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
81
102
  error: Error;
@@ -83,5 +104,5 @@ export default class ArvoEventFactory<TContract extends ArvoContract> {
83
104
  errorMessage: string;
84
105
  errorName: string;
85
106
  errorStack: string | null;
86
- }, TExtension, `sys.${TContract["type"]}.error`>;
107
+ }, TExtension, TContract["systemError"]["type"]>;
87
108
  }
@@ -31,54 +31,69 @@ var OpenTelemetry_1 = require("../OpenTelemetry");
31
31
  var api_1 = require("@opentelemetry/api");
32
32
  var ArvoOrchestrationSubject_1 = __importDefault(require("../ArvoOrchestrationSubject"));
33
33
  /**
34
- * Factory class for creating contractual ArvoEvents based on a given ArvoContract.
35
- * This class handles the creation and validation of events according to contract specifications.
34
+ * Factory class for creating and validating events based on a versioned Arvo contract.
35
+ * Handles event creation, validation, and OpenTelemetry integration for a specific
36
+ * contract version.
36
37
  *
37
- * @template TContract - The type of ArvoContract this factory is bound to
38
+ * @template TContract - The versioned contract type this factory is bound to
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const contract = createArvoContract({
43
+ * uri: 'example/api',
44
+ * type: 'user.create',
45
+ * versions: { '1.0.0': { ... } }
46
+ * });
47
+ *
48
+ * const factory = createArvoEventFactory(contract.version('1.0.0'));
49
+ * ```
38
50
  */
39
51
  var ArvoEventFactory = /** @class */ (function () {
40
52
  /**
41
- * Creates an instance of ArvoEventFactory.
53
+ * Creates an ArvoEventFactory instance for a specific version of a contract.
42
54
  *
43
- * @param contract - The ArvoContract to base the events on.
55
+ * @param contract - The versioned contract to use for event creation and validation
44
56
  */
45
57
  function ArvoEventFactory(contract) {
46
58
  this.contract = contract;
47
59
  }
48
60
  /**
49
- * Creates a validated ArvoEvent that matches the contract's accept specifications.
50
- * This method ensures the created event conforms to the contract's input schema.
61
+ * Creates and validates an event matching the contract's accept specification.
51
62
  *
52
- * @template V - The semantic version of the contract to use
53
- * @template TExtension - Additional custom properties to include in the event
63
+ * @template TExtension - Additional properties to include in the event
54
64
  *
55
65
  * @param event - The event configuration object
56
- * @param event.version - The semantic version of the contract to use
57
- * @param event.data - The event payload that must conform to the contract's accept schema
58
- * @param [extensions] - Optional additional properties to include in the event
59
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
66
+ * @param [extensions] - Optional additional properties for the event
67
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
60
68
  *
61
- * @returns A validated ArvoEvent instance conforming to the contract's accept specifications
69
+ * @returns A validated ArvoEvent matching the contract's accept specification
62
70
  *
63
- * @throws {Error} If event data validation fails against the contract schema
64
- * @throws {Error} If OpenTelemetry operations fail
71
+ * @throws {Error} If validation fails or OpenTelemetry operations fail
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const event = factory.accepts({
76
+ * source: 'api/users',
77
+ * data: { name: 'John', email: 'john@example.com' }
78
+ * });
79
+ * ```
65
80
  */
66
81
  ArvoEventFactory.prototype.accepts = function (event, extensions, opentelemetry) {
67
82
  var _this = this;
68
83
  opentelemetry = opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : {
69
84
  tracer: (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
70
85
  };
71
- var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, "/").concat(event.version, ">.accepts"));
86
+ var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, "/").concat(this.contract.version, ">.accepts"));
72
87
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
73
88
  var _a, _b, _c, _d;
74
89
  span.setStatus({ code: api_1.SpanStatusCode.OK });
75
90
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
76
91
  try {
77
- var validationResult = _this.contract.validateAccepts(event.version, _this.contract.type, event.data);
92
+ var validationResult = _this.contract.accepts.schema.safeParse(event.data);
78
93
  if (!validationResult.success) {
79
94
  throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
80
95
  }
81
- 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.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: "".concat(_this.contract.uri, "/").concat(event.version), data: validationResult.data }), extensions, opentelemetry);
96
+ 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: "".concat(_this.contract.uri, "/").concat(_this.contract.version), data: validationResult.data }), extensions, opentelemetry);
82
97
  }
83
98
  catch (error) {
84
99
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -94,42 +109,45 @@ var ArvoEventFactory = /** @class */ (function () {
94
109
  });
95
110
  };
96
111
  /**
97
- * Creates a validated ArvoEvent that matches one of the contract's emit specifications.
98
- * This method ensures the created event conforms to the contract's output schema.
112
+ * Creates and validates an event matching one of the contract's emit specifications.
99
113
  *
100
- * @template V - The semantic version of the contract to use
101
114
  * @template U - The specific emit event type from the contract
102
- * @template TExtension - Additional custom properties to include in the event
115
+ * @template TExtension - Additional properties to include in the event
103
116
  *
104
117
  * @param event - The event configuration object
105
- * @param event.version - The semantic version of the contract to use
106
- * @param event.type - The type of emit event to create
107
- * @param event.data - The event payload that must conform to the contract's emit schema
108
- * @param [extensions] - Optional additional properties to include in the event
109
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
118
+ * @param [extensions] - Optional additional properties for the event
119
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
120
+ *
121
+ * @returns A validated ArvoEvent matching the specified emit type
110
122
  *
111
- * @returns A validated ArvoEvent instance conforming to the contract's emit specifications
123
+ * @throws {Error} If validation fails, emit type doesn't exist, or OpenTelemetry operations fail
112
124
  *
113
- * @throws {Error} If event data validation fails against the contract schema
114
- * @throws {Error} If the specified emit type doesn't exist in the contract
115
- * @throws {Error} If OpenTelemetry operations fail
125
+ * @example
126
+ * ```typescript
127
+ * const event = factory.emits({
128
+ * type: 'user.created',
129
+ * source: 'api/users',
130
+ * data: { id: '123', timestamp: new Date() }
131
+ * });
132
+ * ```
116
133
  */
117
134
  ArvoEventFactory.prototype.emits = function (event, extensions, opentelemetry) {
118
135
  var _this = this;
119
136
  opentelemetry = opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : {
120
137
  tracer: (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
121
138
  };
122
- var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, "/").concat(event.version, ">.emits<").concat(event.type, ">"));
139
+ var span = opentelemetry.tracer.startSpan("ArvoEventFactory<".concat(this.contract.uri, "/").concat(this.contract.version, ">.emits<").concat(event.type, ">"));
123
140
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
124
- var _a, _b, _c, _d;
141
+ var _a, _b, _c, _d, _e, _f, _g, _h;
125
142
  span.setStatus({ code: api_1.SpanStatusCode.OK });
126
143
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
127
144
  try {
128
- var validationResult = _this.contract.validateEmits(event.version, event.type, event.data);
129
- if (!validationResult.success) {
130
- throw new Error("Emit Event data validation failed: ".concat(validationResult.error.message));
145
+ var validationResult = (_b = (_a = _this.contract.emits) === null || _a === void 0 ? void 0 : _a[event.type]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
146
+ if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
147
+ var msg = (_d = (_c = validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : "No contract available for ".concat(event.type);
148
+ throw new Error("Emit Event data validation failed: ".concat(msg));
131
149
  }
132
- 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: "".concat(_this.contract.uri, "/").concat(event.version), data: validationResult.data }), extensions, opentelemetry);
150
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { traceparent: (_f = (_e = event.traceparent) !== null && _e !== void 0 ? _e : otelHeaders.traceparent) !== null && _f !== void 0 ? _f : undefined, tracestate: (_h = (_g = event.tracestate) !== null && _g !== void 0 ? _g : otelHeaders.tracestate) !== null && _h !== void 0 ? _h : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: "".concat(_this.contract.uri, "/").concat(_this.contract.version), data: validationResult.data }), extensions, opentelemetry);
133
151
  }
134
152
  catch (error) {
135
153
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -145,19 +163,26 @@ var ArvoEventFactory = /** @class */ (function () {
145
163
  });
146
164
  };
147
165
  /**
148
- * Creates a system error ArvoEvent for handling and reporting errors within the system.
166
+ * Creates a system error event for error reporting and handling.
167
+ *
168
+ * @template TExtension - Additional properties to include in the error event
149
169
  *
150
- * @template TExtension - Additional custom properties to include in the error event
170
+ * @param event - The error event configuration
171
+ * @param event.error - The Error instance to convert to an event
172
+ * @param [extensions] - Optional additional properties for the event
173
+ * @param [opentelemetry] - Optional OpenTelemetry configuration
151
174
  *
152
- * @param event - The error event configuration object
153
- * @param event.error - The Error instance to be converted into an event
154
- * @param [extensions] - Optional additional properties to include in the event
155
- * @param [opentelemetry] - Optional OpenTelemetry configuration for tracing
175
+ * @returns A system error ArvoEvent
156
176
  *
157
- * @returns A system error ArvoEvent containing the error details
177
+ * @throws {Error} If event creation or OpenTelemetry operations fail
158
178
  *
159
- * @throws {Error} If event creation fails
160
- * @throws {Error} If OpenTelemetry operations fail
179
+ * @example
180
+ * ```typescript
181
+ * const errorEvent = factory.systemError({
182
+ * error: new Error('Validation failed'),
183
+ * source: 'api/validation'
184
+ * });
185
+ * ```
161
186
  */
162
187
  ArvoEventFactory.prototype.systemError = function (event, extensions, opentelemetry) {
163
188
  var _this = this;
@@ -171,7 +196,7 @@ var ArvoEventFactory = /** @class */ (function () {
171
196
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
172
197
  try {
173
198
  var error = event.error, _event = __rest(event, ["error"]);
174
- 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.type, ".error"), data: {
199
+ 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.systemError.type, data: {
175
200
  errorName: error.name,
176
201
  errorMessage: error.message,
177
202
  errorStack: (_e = error.stack) !== null && _e !== void 0 ? _e : null,
package/dist/types.d.ts CHANGED
@@ -152,7 +152,55 @@ export type InferArvoContract<T extends ArvoContract<string, string, Record<Arvo
152
152
  };
153
153
  systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
154
154
  } : never;
155
+ /**
156
+ * Represents the structure of an Arvo system error.
157
+ * This type is inferred from the ArvoErrorSchema and provides
158
+ * the standard error format used across all Arvo contracts.
159
+ *
160
+ * @property errorName - The classification or type of the error
161
+ * @property errorMessage - A human-readable description of what went wrong
162
+ * @property errorStack - Optional stack trace for debugging (null if not available)
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const error: ArvoErrorType = {
167
+ * errorName: 'ValidationError',
168
+ * errorMessage: 'Invalid input format',
169
+ * errorStack: 'Error: Invalid input format\n at validate (/app.js:10)'
170
+ * };
171
+ * ```
172
+ *
173
+ * @see {@link ArvoErrorSchema} for the underlying Zod schema definition
174
+ */
155
175
  export type ArvoErrorType = z.infer<typeof ArvoErrorSchema>;
176
+ /**
177
+ * A type utility that infers the complete event structure from a versioned Arvo contract.
178
+ * This type extracts and transforms all event types, schemas, and error definitions
179
+ * from a specific version of a contract into their fully resolved event forms.
180
+ *
181
+ * @template TVersion - The versioned contract to infer from, must extend VersionedArvoContract
182
+ *
183
+ * @property accepts - The fully resolved accept event type for this version
184
+ * @property systemError - The fully resolved system error event type
185
+ * @property emits - Record of all fully resolved emit event types
186
+ *
187
+ * This type utility:
188
+ * - Transforms Zod schemas into their inferred TypeScript types
189
+ * - Wraps all event types in the full ArvoEvent structure
190
+ * - Preserves all event type relationships and constraints
191
+ * - Includes OpenTelemetry and Arvo extensions
192
+ * - Maintains type safety across all transformations
193
+ *
194
+ * Common use cases:
195
+ * - Type-safe event handling in version-specific contexts
196
+ * - Generating TypeScript interfaces for API documentation
197
+ * - Validating event payload types at compile time
198
+ * - Creating type-safe event factories
199
+ *
200
+ * @see {@link VersionedArvoContract} for the input contract structure
201
+ * @see {@link InferArvoEvent} for the event inference utility
202
+ * @see {@link ArvoEvent} for the base event structure
203
+ */
156
204
  export type InferVersionedArvoContract<TVersion extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> = {
157
205
  accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['accepts']['schema']>, {}, TVersion['accepts']['type']>>;
158
206
  systemError: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['systemError']['schema']>, {}, TVersion['systemError']['type']>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
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": {