arvo-core 2.0.10 → 2.1.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/ArvoContract/SimpleArvoContract/index.d.ts +55 -0
  3. package/dist/ArvoContract/SimpleArvoContract/index.js +81 -0
  4. package/dist/ArvoContract/SimpleArvoContract/types.d.ts +20 -0
  5. package/dist/ArvoContract/VersionedArvoContract/index.d.ts +32 -0
  6. package/dist/ArvoContract/VersionedArvoContract/index.js +120 -0
  7. package/dist/ArvoContract/VersionedArvoContract/types.d.ts +44 -0
  8. package/dist/ArvoContract/VersionedArvoContract/types.js +2 -0
  9. package/dist/ArvoContract/VersionedArvoContract/utils.d.ts +4 -0
  10. package/dist/ArvoContract/VersionedArvoContract/utils.js +13 -0
  11. package/dist/ArvoContract/WildCardArvoSemanticVersion.d.ts +14 -0
  12. package/dist/ArvoContract/WildCardArvoSemanticVersion.js +21 -0
  13. package/dist/ArvoContract/helpers.d.ts +18 -106
  14. package/dist/ArvoContract/helpers.js +29 -134
  15. package/dist/ArvoContract/index.d.ts +28 -29
  16. package/dist/ArvoContract/index.js +86 -57
  17. package/dist/ArvoContract/types.d.ts +14 -37
  18. package/dist/ArvoEvent/helpers.d.ts +3 -36
  19. package/dist/ArvoEvent/helpers.js +4 -52
  20. package/dist/ArvoEvent/index.d.ts +5 -39
  21. package/dist/ArvoEvent/index.js +5 -39
  22. package/dist/ArvoEvent/schema.d.ts +2 -2
  23. package/dist/ArvoEventFactory/helpers.d.ts +1 -29
  24. package/dist/ArvoEventFactory/helpers.js +1 -41
  25. package/dist/ArvoEventFactory/index.d.ts +3 -14
  26. package/dist/ArvoEventFactory/index.js +5 -17
  27. package/dist/ArvoOrchestrationSubject/index.d.ts +2 -7
  28. package/dist/ArvoOrchestrationSubject/index.js +5 -9
  29. package/dist/ArvoOrchestrationSubject/schema.d.ts +4 -4
  30. package/dist/ArvoOrchestratorContract/index.d.ts +4 -13
  31. package/dist/ArvoOrchestratorContract/index.js +32 -23
  32. package/dist/ArvoOrchestratorContract/typegen.d.ts +8 -0
  33. package/dist/ArvoOrchestratorContract/typegen.js +10 -0
  34. package/dist/ArvoOrchestratorContract/types.d.ts +28 -35
  35. package/dist/index.d.ts +13 -8
  36. package/dist/index.js +10 -3
  37. package/dist/schema.d.ts +3 -2
  38. package/dist/schema.js +6 -1
  39. package/dist/types.d.ts +28 -148
  40. package/dist/utils.d.ts +48 -0
  41. package/dist/utils.js +70 -1
  42. package/package.json +1 -1
  43. package/dist/ArvoContract/VersionedArvoContract.d.ts +0 -39
  44. /package/dist/ArvoContract/{VersionedArvoContract.js → SimpleArvoContract/types.js} +0 -0
@@ -4,17 +4,15 @@ import { ExecutionOpenTelemetryConfiguration } from '../OpenTelemetry/types';
4
4
  /**
5
5
  * Creates a strongly-typed ArvoEvent with configurable telemetry options.
6
6
  *
7
- * @template TData - Event data type extending ArvoEventData
8
- * @template TExtension - Cloud event extension type
9
- * @template TType - String literal type for event type
10
- *
11
7
  * @param event - Event configuration and data
12
8
  * @param [extensions] - Optional cloud event extensions
13
9
  * @param [opentelemetry] - OpenTelemetry configuration with options:
14
10
  * - disable - Completely disables telemetry if true
15
11
  * - tracer - Custom OpenTelemetry tracer instance
16
12
  *
17
- * @returns ArvoEvent instance
13
+ * @throw {Error} In case any validation in {@link ArvoEvent} fails.
14
+ *
15
+ * @returns ArvoEvent with type-safety
18
16
  *
19
17
  * @example
20
18
  * ```typescript
@@ -50,37 +48,6 @@ import { ExecutionOpenTelemetryConfiguration } from '../OpenTelemetry/types';
50
48
  * { tracer: customTracer }
51
49
  * );
52
50
  * ```
53
- *
54
- * @remarks
55
- * This function provides several key features:
56
- *
57
- * 1. **Type Safety**:
58
- * - Ensures event data matches specified type
59
- * - Validates extension structure
60
- * - Provides type-safe event type strings
61
- *
62
- * 2. **Default Handling**:
63
- * - Generates UUID if no ID provided
64
- * - Sets current timestamp if no time provided
65
- * - Uses default ArvoDataContentType if none specified
66
- *
67
- * 3. **URI Handling**:
68
- * - Automatically encodes URI components (source, subject, to, redirectto, dataschema)
69
- * - Validates URI format
70
- *
71
- * 4. **OpenTelemetry Integration**:
72
- * - Creates spans for event creation
73
- * - Tracks errors and warnings
74
- * - Propagates trace context
75
- *
76
- * 5. **Validation**:
77
- * - Checks data content type compatibility
78
- * - Validates required fields
79
- * - Ensures URI format correctness
80
- *
81
- * @see {@link ArvoEvent} For the structure of the created event
82
- * @see {@link ArvoDataContentType} For supported content types
83
- * @see {@link CloudEventExtension} For extension structure
84
51
  */
85
52
  export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension, TType extends string>(event: CreateArvoEvent<TData, TType>, extensions?: TExtension, opentelemetry?: Partial<ExecutionOpenTelemetryConfiguration & {
86
53
  disable: boolean;
@@ -11,22 +11,7 @@ var utils_1 = require("../utils");
11
11
  var schema_1 = require("./schema");
12
12
  var uuid_1 = require("uuid");
13
13
  /**
14
- * Internal generator function for creating ArvoEvent instances.
15
- *
16
- * @template TData - Type of the event data
17
- * @template TExtension - Type of cloud event extensions
18
- * @param {CreateArvoEvent<any, any>} event - The event configuration and data
19
- * @param {any} extensions - Cloud event extensions
20
- * @param {ReturnType<typeof currentOpenTelemetryHeaders>} otelHeaders - OpenTelemetry headers
21
- * @returns {ArvoEvent<any, any, any>} A new ArvoEvent instance
22
- *
23
- * @remarks
24
- * This function handles the actual creation of the ArvoEvent instance, including:
25
- * - Generation of default values for optional fields
26
- * - URI encoding of relevant fields
27
- * - Validation of data content type
28
- * - Integration with OpenTelemetry headers
29
- * ```
14
+ * Internal generator function for creating instances.
30
15
  */
31
16
  var generator = function (event, extensions, otelHeaders) {
32
17
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -57,17 +42,15 @@ var generator = function (event, extensions, otelHeaders) {
57
42
  /**
58
43
  * Creates a strongly-typed ArvoEvent with configurable telemetry options.
59
44
  *
60
- * @template TData - Event data type extending ArvoEventData
61
- * @template TExtension - Cloud event extension type
62
- * @template TType - String literal type for event type
63
- *
64
45
  * @param event - Event configuration and data
65
46
  * @param [extensions] - Optional cloud event extensions
66
47
  * @param [opentelemetry] - OpenTelemetry configuration with options:
67
48
  * - disable - Completely disables telemetry if true
68
49
  * - tracer - Custom OpenTelemetry tracer instance
69
50
  *
70
- * @returns ArvoEvent instance
51
+ * @throw {Error} In case any validation in {@link ArvoEvent} fails.
52
+ *
53
+ * @returns ArvoEvent with type-safety
71
54
  *
72
55
  * @example
73
56
  * ```typescript
@@ -103,37 +86,6 @@ var generator = function (event, extensions, otelHeaders) {
103
86
  * { tracer: customTracer }
104
87
  * );
105
88
  * ```
106
- *
107
- * @remarks
108
- * This function provides several key features:
109
- *
110
- * 1. **Type Safety**:
111
- * - Ensures event data matches specified type
112
- * - Validates extension structure
113
- * - Provides type-safe event type strings
114
- *
115
- * 2. **Default Handling**:
116
- * - Generates UUID if no ID provided
117
- * - Sets current timestamp if no time provided
118
- * - Uses default ArvoDataContentType if none specified
119
- *
120
- * 3. **URI Handling**:
121
- * - Automatically encodes URI components (source, subject, to, redirectto, dataschema)
122
- * - Validates URI format
123
- *
124
- * 4. **OpenTelemetry Integration**:
125
- * - Creates spans for event creation
126
- * - Tracks errors and warnings
127
- * - Propagates trace context
128
- *
129
- * 5. **Validation**:
130
- * - Checks data content type compatibility
131
- * - Validates required fields
132
- * - Ensures URI format correctness
133
- *
134
- * @see {@link ArvoEvent} For the structure of the created event
135
- * @see {@link ArvoDataContentType} For supported content types
136
- * @see {@link CloudEventExtension} For extension structure
137
89
  */
138
90
  var createArvoEvent = function (event, extensions, opentelemetry) {
139
91
  var _a;
@@ -2,9 +2,6 @@ import { ArvoEventData, ArvoExtension, CloudEventContext, CloudEventExtension, O
2
2
  import { InferArvoEvent } from '../types';
3
3
  /**
4
4
  * Represents an ArvoEvent, which extends the CloudEvent specification.
5
- * @template TData - The type of the event data, extending ArvoEventData.
6
- * @template TExtension - The type of additional extensions, extending CloudEventExtension.
7
- * @template TType - The type name of the event
8
5
  */
9
6
  export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExtension extends CloudEventExtension = CloudEventExtension, TType extends string = string> {
10
7
  readonly id: string;
@@ -22,6 +19,9 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
22
19
  * @param context - The CloudEvent context along with Arvo and OpenTelemetry extensions.
23
20
  * @param data - The event data.
24
21
  * @param extensions - Optional additional extensions.
22
+ *
23
+ * @throws {Error} If the datacontenttype is {@link ArvoDataContentType} but the `to` field
24
+ * is not defined
25
25
  */
26
26
  constructor(context: CloudEventContext & ArvoExtension & OpenTelemetryExtension, data: TData, extensions?: TExtension);
27
27
  /**
@@ -65,8 +65,6 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
65
65
  * (including Arvo and OpenTelemetry extensions) into a single object.
66
66
  * If you need to access the CloudEvent fields and extensions separately,
67
67
  * use the `cloudevent` getter instead.
68
- *
69
- * @returns A plain object representation of the ArvoEvent, including all fields and extensions.
70
68
  */
71
69
  toJSON(): InferArvoEvent<typeof this>;
72
70
  /**
@@ -79,9 +77,9 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
79
77
  * Gets OpenTelemetry attributes derived from the ArvoEvent.
80
78
  * @returns An object containing OpenTelemetry attributes.
81
79
  * The OpenTelemetry attributes for CloudEvents is as per
82
- * the spec provided [here](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/)
80
+ * the spec provided [in the official documentation](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/).
83
81
  * Additionally, the Arvo extension attributed are also returned
84
- * as `cloudevents.arvo.event_*` fields
82
+ * as `cloudevents.arvo.event_*` fields.
85
83
  */
86
84
  get otelAttributes(): {
87
85
  'cloudevents.event_id': string;
@@ -96,41 +94,11 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
96
94
  'cloudevents.arvo.event_to': string;
97
95
  'cloudevents.arvo.event_executionunits': string | number;
98
96
  };
99
- /**
100
- * Gets the 'to' field from the ArvoExtension.
101
- * This field represents the intended recipient or destination of the event.
102
- * @returns The value of the 'to' field.
103
- */
104
97
  get to(): string | null;
105
- /**
106
- * Gets the 'accesscontrol' field from the ArvoExtension.
107
- * This field contains access control information for the event.
108
- * @returns The value of the 'accesscontrol' field.
109
- */
110
98
  get accesscontrol(): string | null;
111
- /**
112
- * Gets the 'redirectto' field from the ArvoExtension.
113
- * This field indicate an alternative destination for the event.
114
- * @returns The value of the 'redirectto' field.
115
- */
116
99
  get redirectto(): string | null;
117
- /**
118
- * Gets the 'executionunits' field from the ArvoExtension.
119
- * This field contains information about the execution units associated with the event.
120
- * @returns The value of the 'executionunits' field.
121
- */
122
100
  get executionunits(): number | null;
123
- /**
124
- * Gets the 'traceparent' field from the OpenTelemetryExtension.
125
- * This field contains the W3C Trace Context traceparent header.
126
- * @returns The value of the 'traceparent' field.
127
- */
128
101
  get traceparent(): string | null;
129
- /**
130
- * Gets the 'tracestate' field from the OpenTelemetryExtension.
131
- * This field contains the W3C Trace Context tracestate header.
132
- * @returns The value of the 'tracestate' field, or undefined if not set.
133
- */
134
102
  get tracestate(): string | null;
135
103
  /**
136
104
  * Gets the custom extensions of the ArvoEvent.
@@ -141,8 +109,6 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
141
109
  * For accessing all extensions including Arvo and OpenTelemetry,
142
110
  * use `<ArvoEvent>.cloudevent.extensions`.
143
111
  * For accessing the basic CloudEvent fields, use `<ArvoEvent>.cloudevent.default`.
144
- *
145
- * @returns An object containing only the custom extensions (TExtension) of the ArvoEvent.
146
112
  */
147
113
  get extensions(): TExtension;
148
114
  }
@@ -26,9 +26,6 @@ var schema_1 = require("./schema");
26
26
  var OpenTelemetry_1 = require("../OpenTelemetry");
27
27
  /**
28
28
  * Represents an ArvoEvent, which extends the CloudEvent specification.
29
- * @template TData - The type of the event data, extending ArvoEventData.
30
- * @template TExtension - The type of additional extensions, extending CloudEventExtension.
31
- * @template TType - The type name of the event
32
29
  */
33
30
  var ArvoEvent = /** @class */ (function () {
34
31
  /**
@@ -36,6 +33,9 @@ var ArvoEvent = /** @class */ (function () {
36
33
  * @param context - The CloudEvent context along with Arvo and OpenTelemetry extensions.
37
34
  * @param data - The event data.
38
35
  * @param extensions - Optional additional extensions.
36
+ *
37
+ * @throws {Error} If the datacontenttype is {@link ArvoDataContentType} but the `to` field
38
+ * is not defined
39
39
  */
40
40
  function ArvoEvent(context, data, extensions) {
41
41
  var cloudEventContext = schema_1.CloudEventContextSchema.parse(context);
@@ -100,8 +100,6 @@ var ArvoEvent = /** @class */ (function () {
100
100
  * (including Arvo and OpenTelemetry extensions) into a single object.
101
101
  * If you need to access the CloudEvent fields and extensions separately,
102
102
  * use the `cloudevent` getter instead.
103
- *
104
- * @returns A plain object representation of the ArvoEvent, including all fields and extensions.
105
103
  */
106
104
  ArvoEvent.prototype.toJSON = function () {
107
105
  return __assign(__assign({}, this.cloudevent.default), this._extensions);
@@ -120,9 +118,9 @@ var ArvoEvent = /** @class */ (function () {
120
118
  * Gets OpenTelemetry attributes derived from the ArvoEvent.
121
119
  * @returns An object containing OpenTelemetry attributes.
122
120
  * The OpenTelemetry attributes for CloudEvents is as per
123
- * the spec provided [here](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/)
121
+ * the spec provided [in the official documentation](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/).
124
122
  * Additionally, the Arvo extension attributed are also returned
125
- * as `cloudevents.arvo.event_*` fields
123
+ * as `cloudevents.arvo.event_*` fields.
126
124
  */
127
125
  get: function () {
128
126
  var _a, _b, _c, _d;
@@ -144,11 +142,6 @@ var ArvoEvent = /** @class */ (function () {
144
142
  configurable: true
145
143
  });
146
144
  Object.defineProperty(ArvoEvent.prototype, "to", {
147
- /**
148
- * Gets the 'to' field from the ArvoExtension.
149
- * This field represents the intended recipient or destination of the event.
150
- * @returns The value of the 'to' field.
151
- */
152
145
  get: function () {
153
146
  return this._extensions.to;
154
147
  },
@@ -156,11 +149,6 @@ var ArvoEvent = /** @class */ (function () {
156
149
  configurable: true
157
150
  });
158
151
  Object.defineProperty(ArvoEvent.prototype, "accesscontrol", {
159
- /**
160
- * Gets the 'accesscontrol' field from the ArvoExtension.
161
- * This field contains access control information for the event.
162
- * @returns The value of the 'accesscontrol' field.
163
- */
164
152
  get: function () {
165
153
  return this._extensions.accesscontrol;
166
154
  },
@@ -168,11 +156,6 @@ var ArvoEvent = /** @class */ (function () {
168
156
  configurable: true
169
157
  });
170
158
  Object.defineProperty(ArvoEvent.prototype, "redirectto", {
171
- /**
172
- * Gets the 'redirectto' field from the ArvoExtension.
173
- * This field indicate an alternative destination for the event.
174
- * @returns The value of the 'redirectto' field.
175
- */
176
159
  get: function () {
177
160
  return this._extensions.redirectto;
178
161
  },
@@ -180,11 +163,6 @@ var ArvoEvent = /** @class */ (function () {
180
163
  configurable: true
181
164
  });
182
165
  Object.defineProperty(ArvoEvent.prototype, "executionunits", {
183
- /**
184
- * Gets the 'executionunits' field from the ArvoExtension.
185
- * This field contains information about the execution units associated with the event.
186
- * @returns The value of the 'executionunits' field.
187
- */
188
166
  get: function () {
189
167
  return this._extensions.executionunits;
190
168
  },
@@ -192,11 +170,6 @@ var ArvoEvent = /** @class */ (function () {
192
170
  configurable: true
193
171
  });
194
172
  Object.defineProperty(ArvoEvent.prototype, "traceparent", {
195
- /**
196
- * Gets the 'traceparent' field from the OpenTelemetryExtension.
197
- * This field contains the W3C Trace Context traceparent header.
198
- * @returns The value of the 'traceparent' field.
199
- */
200
173
  get: function () {
201
174
  return this._extensions.traceparent;
202
175
  },
@@ -204,11 +177,6 @@ var ArvoEvent = /** @class */ (function () {
204
177
  configurable: true
205
178
  });
206
179
  Object.defineProperty(ArvoEvent.prototype, "tracestate", {
207
- /**
208
- * Gets the 'tracestate' field from the OpenTelemetryExtension.
209
- * This field contains the W3C Trace Context tracestate header.
210
- * @returns The value of the 'tracestate' field, or undefined if not set.
211
- */
212
180
  get: function () {
213
181
  return this._extensions.tracestate;
214
182
  },
@@ -225,8 +193,6 @@ var ArvoEvent = /** @class */ (function () {
225
193
  * For accessing all extensions including Arvo and OpenTelemetry,
226
194
  * use `<ArvoEvent>.cloudevent.extensions`.
227
195
  * For accessing the basic CloudEvent fields, use `<ArvoEvent>.cloudevent.default`.
228
- *
229
- * @returns An object containing only the custom extensions (TExtension) of the ArvoEvent.
230
196
  */
231
197
  get: function () {
232
198
  var _a = this._extensions, traceparent = _a.traceparent, tracestate = _a.tracestate, to = _a.to, redirectto = _a.redirectto, accesscontrol = _a.accesscontrol, executionunits = _a.executionunits, rest = __rest(_a, ["traceparent", "tracestate", "to", "redirectto", "accesscontrol", "executionunits"]);
@@ -21,20 +21,20 @@ export declare const CloudEventContextSchema: z.ZodObject<{
21
21
  }, "strip", z.ZodTypeAny, {
22
22
  type: string;
23
23
  id: string;
24
- time: string;
25
24
  source: string;
26
25
  specversion: "1.0";
27
26
  subject: string;
28
27
  datacontenttype: string;
29
28
  dataschema: string | null;
29
+ time: string;
30
30
  }, {
31
31
  type: string;
32
32
  id: string;
33
- time: string;
34
33
  source: string;
35
34
  specversion: string;
36
35
  subject: string;
37
36
  dataschema: string | null;
37
+ time: string;
38
38
  datacontenttype?: string | undefined;
39
39
  }>;
40
40
  /**
@@ -1,13 +1,10 @@
1
1
  import ArvoEventFactory from '.';
2
2
  import ArvoContract from '../ArvoContract';
3
3
  import { ArvoSemanticVersion } from '../types';
4
- import ArvoEvent from '../ArvoEvent';
5
4
  import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
6
5
  /**
7
6
  * Creates an ArvoEventFactory for a specific version of a contract.
8
7
  *
9
- * @template TContract - The versioned contract type
10
- *
11
8
  * @param contract - The versioned contract to create a factory for
12
9
  * @returns An ArvoEventFactory instance for the specified contract version
13
10
  *
@@ -18,29 +15,4 @@ import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
18
15
  * const factory = createArvoEventFactory(v1Contract);
19
16
  * ```
20
17
  */
21
- export declare const createArvoEventFactory: <TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>>(contract: TContract) => ArvoEventFactory<TContract>;
22
- /**
23
- * Parses an event data schema string or ArvoEvent object to extract the URI and version.
24
- * The schema is expected to be in the format "uri/version" where version follows semantic versioning.
25
- *
26
- * @param data - The input to parse, either a string containing the schema or an ArvoEvent object
27
- * If an ArvoEvent is provided, its dataschema property will be used
28
- *
29
- * @returns An object containing the parsed URI and semantic version, or null if parsing fails
30
- * The URI is everything before the last "/" and the version is everything after
31
- *
32
- * @example
33
- * // String input
34
- * parseEventDataSchema("com.example/schema/1.0.0")
35
- * // Returns: { uri: "com.example/schema", version: "1.0.0" }
36
- *
37
- * // ArvoEvent input
38
- * parseEventDataSchema({ dataschema: "com.example/schema/1.0.0" })
39
- * // Returns: { uri: "com.example/schema", version: "1.0.0" }
40
- *
41
- * @throws Will not throw errors directly, but converts any parsing errors to spans
42
- */
43
- export declare const parseEventDataSchema: (data: string | ArvoEvent) => {
44
- uri: string;
45
- version: ArvoSemanticVersion;
46
- } | null;
18
+ export declare const createArvoEventFactory: <TContract extends VersionedArvoContract<ArvoContract<any, any, any, any>, ArvoSemanticVersion, Record<string, any>>>(contract: TContract) => ArvoEventFactory<TContract>;
@@ -3,15 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseEventDataSchema = exports.createArvoEventFactory = void 0;
6
+ exports.createArvoEventFactory = void 0;
7
7
  var _1 = __importDefault(require("."));
8
- var OpenTelemetry_1 = require("../OpenTelemetry");
9
- var schema_1 = require("../schema");
10
8
  /**
11
9
  * Creates an ArvoEventFactory for a specific version of a contract.
12
10
  *
13
- * @template TContract - The versioned contract type
14
- *
15
11
  * @param contract - The versioned contract to create a factory for
16
12
  * @returns An ArvoEventFactory instance for the specified contract version
17
13
  *
@@ -24,39 +20,3 @@ var schema_1 = require("../schema");
24
20
  */
25
21
  var createArvoEventFactory = function (contract) { return new _1.default(contract); };
26
22
  exports.createArvoEventFactory = createArvoEventFactory;
27
- /**
28
- * Parses an event data schema string or ArvoEvent object to extract the URI and version.
29
- * The schema is expected to be in the format "uri/version" where version follows semantic versioning.
30
- *
31
- * @param data - The input to parse, either a string containing the schema or an ArvoEvent object
32
- * If an ArvoEvent is provided, its dataschema property will be used
33
- *
34
- * @returns An object containing the parsed URI and semantic version, or null if parsing fails
35
- * The URI is everything before the last "/" and the version is everything after
36
- *
37
- * @example
38
- * // String input
39
- * parseEventDataSchema("com.example/schema/1.0.0")
40
- * // Returns: { uri: "com.example/schema", version: "1.0.0" }
41
- *
42
- * // ArvoEvent input
43
- * parseEventDataSchema({ dataschema: "com.example/schema/1.0.0" })
44
- * // Returns: { uri: "com.example/schema", version: "1.0.0" }
45
- *
46
- * @throws Will not throw errors directly, but converts any parsing errors to spans
47
- */
48
- var parseEventDataSchema = function (data) {
49
- var _a;
50
- try {
51
- var dataschema = typeof data === 'string' ? data : ((_a = data.dataschema) !== null && _a !== void 0 ? _a : '');
52
- var items = dataschema.split('/');
53
- var version = schema_1.ArvoSemanticVersionSchema.parse(items.pop());
54
- var uri = items.join('/');
55
- return { uri: uri, version: version };
56
- }
57
- catch (e) {
58
- (0, OpenTelemetry_1.exceptionToSpan)(e);
59
- return null;
60
- }
61
- };
62
- exports.parseEventDataSchema = parseEventDataSchema;
@@ -1,16 +1,12 @@
1
- import ArvoContract from '../ArvoContract';
2
1
  import { z } from 'zod';
3
2
  import { CreateArvoEvent } from '../ArvoEvent/types';
4
3
  import { ExecutionOpenTelemetryConfiguration } from '../OpenTelemetry/types';
5
- import { ArvoSemanticVersion } from '../types';
6
4
  import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
7
5
  /**
8
6
  * Factory class for creating and validating events based on a versioned Arvo contract.
9
7
  * Handles event creation, validation, and OpenTelemetry integration for a specific
10
8
  * contract version.
11
9
  *
12
- * @template TContract - The versioned contract type this factory is bound to
13
- *
14
10
  * @example
15
11
  * ```typescript
16
12
  * const contract = createArvoContract({
@@ -22,7 +18,7 @@ import { VersionedArvoContract } from '../ArvoContract/VersionedArvoContract';
22
18
  * const factory = createArvoEventFactory(contract.version('1.0.0'));
23
19
  * ```
24
20
  */
25
- export default class ArvoEventFactory<TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> {
21
+ export default class ArvoEventFactory<TContract extends VersionedArvoContract<any, any, any>> {
26
22
  private readonly contract;
27
23
  /**
28
24
  * Creates an ArvoEventFactory instance for a specific version of a contract.
@@ -33,8 +29,6 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<Ar
33
29
  /**
34
30
  * Creates and validates an event matching the contract's accept specification.
35
31
  *
36
- * @template TExtension - Additional properties to include in the event
37
- *
38
32
  * @param event - The event configuration object
39
33
  * @param [extensions] - Optional additional properties for the event
40
34
  * @param [opentelemetry] - Optional OpenTelemetry configuration
@@ -55,9 +49,6 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<Ar
55
49
  /**
56
50
  * Creates and validates an event matching one of the contract's emit specifications.
57
51
  *
58
- * @template U - The specific emit event type from the contract
59
- * @template TExtension - Additional properties to include in the event
60
- *
61
52
  * @param event - The event configuration object
62
53
  * @param [extensions] - Optional additional properties for the event
63
54
  * @param [opentelemetry] - Optional OpenTelemetry configuration
@@ -75,12 +66,10 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<Ar
75
66
  * });
76
67
  * ```
77
68
  */
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>;
69
+ emits<U extends string & keyof TContract['emitMap'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emitMap'][U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<z.TypeOf<TContract["emitMap"][U]>, TExtension, U>;
79
70
  /**
80
71
  * Creates a system error event for error reporting and handling.
81
72
  *
82
- * @template TExtension - Additional properties to include in the error event
83
- *
84
73
  * @param event - The error event configuration
85
74
  * @param event.error - The Error instance to convert to an event
86
75
  * @param [extensions] - Optional additional properties for the event
@@ -101,8 +90,8 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<Ar
101
90
  systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
102
91
  error: Error;
103
92
  }, extensions?: TExtension, opentelemetry?: ExecutionOpenTelemetryConfiguration): import("..").ArvoEvent<{
104
- errorMessage: string;
105
93
  errorName: string;
94
+ errorMessage: string;
106
95
  errorStack: string | null;
107
96
  }, TExtension, TContract["systemError"]["type"]>;
108
97
  }
@@ -21,22 +21,17 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
24
  Object.defineProperty(exports, "__esModule", { value: true });
28
25
  var helpers_1 = require("../ArvoEvent/helpers");
29
26
  var schema_1 = require("../ArvoEvent/schema");
30
27
  var OpenTelemetry_1 = require("../OpenTelemetry");
31
28
  var api_1 = require("@opentelemetry/api");
32
- var ArvoOrchestrationSubject_1 = __importDefault(require("../ArvoOrchestrationSubject"));
29
+ var utils_1 = require("../utils");
33
30
  /**
34
31
  * Factory class for creating and validating events based on a versioned Arvo contract.
35
32
  * Handles event creation, validation, and OpenTelemetry integration for a specific
36
33
  * contract version.
37
34
  *
38
- * @template TContract - The versioned contract type this factory is bound to
39
- *
40
35
  * @example
41
36
  * ```typescript
42
37
  * const contract = createArvoContract({
@@ -60,8 +55,6 @@ var ArvoEventFactory = /** @class */ (function () {
60
55
  /**
61
56
  * Creates and validates an event matching the contract's accept specification.
62
57
  *
63
- * @template TExtension - Additional properties to include in the event
64
- *
65
58
  * @param event - The event configuration object
66
59
  * @param [extensions] - Optional additional properties for the event
67
60
  * @param [opentelemetry] - Optional OpenTelemetry configuration
@@ -93,7 +86,7 @@ var ArvoEventFactory = /** @class */ (function () {
93
86
  if (!validationResult.success) {
94
87
  throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
95
88
  }
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, { disable: true });
89
+ 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: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
97
90
  }
98
91
  catch (error) {
99
92
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -111,9 +104,6 @@ var ArvoEventFactory = /** @class */ (function () {
111
104
  /**
112
105
  * Creates and validates an event matching one of the contract's emit specifications.
113
106
  *
114
- * @template U - The specific emit event type from the contract
115
- * @template TExtension - Additional properties to include in the event
116
- *
117
107
  * @param event - The event configuration object
118
108
  * @param [extensions] - Optional additional properties for the event
119
109
  * @param [opentelemetry] - Optional OpenTelemetry configuration
@@ -142,12 +132,12 @@ var ArvoEventFactory = /** @class */ (function () {
142
132
  span.setStatus({ code: api_1.SpanStatusCode.OK });
143
133
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
144
134
  try {
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);
135
+ var validationResult = (_b = (_a = _this.contract.emitMap) === null || _a === void 0 ? void 0 : _a[event.type]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
146
136
  if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
147
137
  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
138
  throw new Error("Emit Event data validation failed: ".concat(msg));
149
139
  }
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, { disable: true });
140
+ 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: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
151
141
  }
152
142
  catch (error) {
153
143
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -165,8 +155,6 @@ var ArvoEventFactory = /** @class */ (function () {
165
155
  /**
166
156
  * Creates a system error event for error reporting and handling.
167
157
  *
168
- * @template TExtension - Additional properties to include in the error event
169
- *
170
158
  * @param event - The error event configuration
171
159
  * @param event.error - The Error instance to convert to an event
172
160
  * @param [extensions] - Optional additional properties for the event
@@ -200,7 +188,7 @@ var ArvoEventFactory = /** @class */ (function () {
200
188
  errorName: error.name,
201
189
  errorMessage: error.message,
202
190
  errorStack: (_e = error.stack) !== null && _e !== void 0 ? _e : null,
203
- }, datacontenttype: schema_1.ArvoDataContentType, dataschema: "".concat(_this.contract.uri, "/").concat(ArvoOrchestrationSubject_1.default.WildCardMachineVersion) }), extensions, { disable: true });
191
+ }, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.createWithWildCardVersion(_this.contract) }), extensions, { disable: true });
204
192
  }
205
193
  catch (error) {
206
194
  (0, OpenTelemetry_1.exceptionToSpan)(error);
@@ -4,18 +4,13 @@ import { ArvoSemanticVersion } from '../types';
4
4
  * Handles the creation and parsing of Arvo orchestration subjects.
5
5
  */
6
6
  export default class ArvoOrchestrationSubject {
7
- /**
8
- * Represents a wildcard version number used when version matching is not required.
9
- * Format follows semantic versioning pattern.
10
- */
11
- static readonly WildCardMachineVersion: ArvoSemanticVersion;
12
7
  /**
13
8
  * Creates a new Arvo orchestration subject with basic required parameters.
14
9
  * This is a convenience method that wraps the more detailed {@link create} method.
15
10
  *
16
11
  * @param param - Configuration object for the orchestration subject
17
12
  * @param param.orchestator - Name identifier of the orchestrator
18
- * @param param.version - Version of the orchestrator. If null, defaults to {@link WildCardMachineVersion}
13
+ * @param param.version - Version of the orchestrator. If null, defaults to {@link WildCardArvoSemanticVersion}
19
14
  * @param param.initiator - Identifier of the entity initiating the orchestration
20
15
  * @param param.meta - Optional metadata key-value pairs for additional orchestration context
21
16
  * @returns A base64 encoded string containing the compressed orchestration subject data
@@ -55,7 +50,7 @@ export default class ArvoOrchestrationSubject {
55
50
  *
56
51
  * @param param - Configuration object for creating a new subject from a parent
57
52
  * @param param.orchestator - Name identifier of the new orchestrator
58
- * @param param.version - Version of the new orchestrator. If null, defaults to {@link WildCardMachineVersion}
53
+ * @param param.version - Version of the new orchestrator. If null, defaults to {@link WildCardArvoSemanticVersion}
59
54
  * @param param.subject - Base64 encoded string of the parent orchestration subject
60
55
  * @param param.meta - Optional additional metadata to merge with the parent's metadata
61
56
  * @returns A new base64 encoded string containing the compressed orchestration subject data