arvo-core 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -20,3 +20,11 @@
20
20
 
21
21
  - Updated README documentation
22
22
 
23
+ ## [1.0.6] - 2024-09-01
24
+
25
+ - Updated ArvoContract typing mechanism
26
+
27
+ ## [1.0.7] - 2024-09-01
28
+
29
+ - Updates to OpenTelemetry functions
30
+
@@ -1,5 +1,5 @@
1
1
  import { IArvoContract } from './types';
2
- import ArvoContract, { ExtractEventType } from '.';
2
+ import ArvoContract from '.';
3
3
  import { CreateArvoEvent } from '../ArvoEvent/types';
4
4
  import { TelemetryContext } from '../OpenTelemetry/types';
5
5
  import { ArvoContractRecord } from './types';
@@ -41,12 +41,12 @@ export declare const createArvoContract: <const TContract extends IArvoContract>
41
41
  * Creates a contractual ArvoEvent factory based on the provided contract.
42
42
  *
43
43
  * @template T - The type of the contract.
44
- * @template TAccepts - The type of events the contract accepts.
45
- * @template TEmits - The type of events the contract emits.
44
+ * @template TAccepts - The type of record the contract bound handler accepts, defaults to ArvoContractRecord.
45
+ * @template TEmits - The type of records the contract bound handler emits.
46
46
  * @param {ArvoContract<T, TAccepts, TEmits>} contract - The ArvoContract to base the events on.
47
47
  * @returns {Object} An object with 'accepts' and 'emits' methods for creating events.
48
48
  */
49
- export declare const createContractualArvoEvent: <T extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends ArvoContractRecord = ArvoContractRecord>(contract: ArvoContract<T, TAccepts, TEmits>) => {
49
+ export declare const contractualArvoEventFactory: <T extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends Record<string, z.ZodTypeAny> = Record<string, z.ZodTypeAny>>(contract: ArvoContract<T, TAccepts, TEmits>) => {
50
50
  /**
51
51
  * Creates an ArvoEvent as per the accept record of the contract.
52
52
  *
@@ -69,9 +69,7 @@ export declare const createContractualArvoEvent: <T extends string = string, TAc
69
69
  * @returns The created ArvoEvent as per one of the emits records of the contract.
70
70
  * @throws {Error} If the event data fails validation against the contract.
71
71
  */
72
- emits: <U extends ExtractEventType<TEmits>, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<Extract<TEmits, {
73
- type: U;
74
- }>["schema"]>, U>, extensions?: TExtension, telemetry?: TelemetryContext) => import("..").ArvoEvent<z.TypeOf<Extract<TEmits, {
72
+ 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<Extract<TEmits, {
75
73
  type: U;
76
74
  }>["schema"]>, TExtension, string>;
77
75
  };
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createContractualArvoEvent = exports.createArvoContract = void 0;
17
+ exports.contractualArvoEventFactory = exports.createArvoContract = void 0;
18
18
  var _1 = __importDefault(require("."));
19
19
  var helpers_1 = require("../ArvoEvent/helpers");
20
20
  var OpenTelemetry_1 = require("../OpenTelemetry");
@@ -54,12 +54,12 @@ exports.createArvoContract = createArvoContract;
54
54
  * Creates a contractual ArvoEvent factory based on the provided contract.
55
55
  *
56
56
  * @template T - The type of the contract.
57
- * @template TAccepts - The type of events the contract accepts.
58
- * @template TEmits - The type of events the contract emits.
57
+ * @template TAccepts - The type of record the contract bound handler accepts, defaults to ArvoContractRecord.
58
+ * @template TEmits - The type of records the contract bound handler emits.
59
59
  * @param {ArvoContract<T, TAccepts, TEmits>} contract - The ArvoContract to base the events on.
60
60
  * @returns {Object} An object with 'accepts' and 'emits' methods for creating events.
61
61
  */
62
- var createContractualArvoEvent = function (contract) { return ({
62
+ var contractualArvoEventFactory = function (contract) { return ({
63
63
  /**
64
64
  * Creates an ArvoEvent as per the accept record of the contract.
65
65
  *
@@ -71,7 +71,7 @@ var createContractualArvoEvent = function (contract) { return ({
71
71
  * @throws {Error} If the event data fails validation against the contract.
72
72
  */
73
73
  accepts: function (event, extensions, telemetry) {
74
- return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'createArvoContractEvent.accepts', {}, function () {
74
+ return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'contractualArvoEventFactory.accepts', {}, function () {
75
75
  var validationResult = contract.validateInput(event.type, event.data);
76
76
  if (!validationResult.success) {
77
77
  throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
@@ -91,7 +91,7 @@ var createContractualArvoEvent = function (contract) { return ({
91
91
  * @throws {Error} If the event data fails validation against the contract.
92
92
  */
93
93
  emits: function (event, extensions, telemetry) {
94
- return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'createArvoContractEvent.emits', {}, function () {
94
+ return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'contractualArvoEventFactory.emits', {}, function () {
95
95
  var validationResult = contract.validateOutput(event.type, event.data);
96
96
  if (!validationResult.success) {
97
97
  throw new Error("Emit Event data validation failed: ".concat(validationResult.error.message));
@@ -100,4 +100,4 @@ var createContractualArvoEvent = function (contract) { return ({
100
100
  });
101
101
  },
102
102
  }); };
103
- exports.createContractualArvoEvent = createContractualArvoEvent;
103
+ exports.contractualArvoEventFactory = contractualArvoEventFactory;
@@ -1,21 +1,16 @@
1
1
  import { z } from 'zod';
2
2
  import { ArvoContractRecord, IArvoContract } from './types';
3
- /**
4
- * Extracts the event type from a given type T.
5
- * @template T - The type to extract the event type from.
6
- */
7
- export type ExtractEventType<T> = T extends {
8
- type: infer U;
9
- } ? U : never;
10
3
  /**
11
4
  * ArvoContract class represents a contract with defined input and output schemas.
12
5
  * It provides methods for validating inputs and outputs based on the contract's specifications.
6
+ * An event handler can be bound to it so the this contract may impose the types
7
+ * on inputs and outputs of it
13
8
  *
14
- * @template T - The URI type.
15
- * @template TAccepts - The accepted record type.
16
- * @template TEmits - The emitted record type.
9
+ * @template TUri - The URI type, defaults to string.
10
+ * @template TAccepts - The type of record the contract bound handler accepts, defaults to ArvoContractRecord.
11
+ * @template TEmits - The type of records the contract bound handler emits.
17
12
  */
18
- export default class ArvoContract<T extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends ArvoContractRecord = ArvoContractRecord> {
13
+ export default class ArvoContract<TUri extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends Record<string, z.ZodTypeAny> = Record<string, z.ZodTypeAny>> {
19
14
  private readonly _uri;
20
15
  private readonly _accepts;
21
16
  private readonly _emits;
@@ -23,54 +18,47 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
23
18
  readonly description: string | null;
24
19
  /**
25
20
  * Creates an instance of ArvoContract.
26
- * @param {IArvoContract<T, TAccepts, TEmits>} params - The contract parameters.
21
+ * @param {IArvoContract<TUri, TAccepts, TEmits>} params - The contract parameters.
27
22
  */
28
- constructor(params: IArvoContract<T, TAccepts, TEmits>);
23
+ constructor(params: IArvoContract<TUri, TAccepts, TEmits>);
29
24
  /**
30
25
  * Gets the URI of the contract.
31
26
  * @returns {T} The contract's URI.
32
27
  */
33
- get uri(): T;
28
+ get uri(): TUri;
34
29
  /**
35
- * Gets the accepted record type and schema.
30
+ * Gets the type and schema of the event that the contact
31
+ * bound handler listens to.
36
32
  * @returns {TAccepts} The frozen accepts object.
37
33
  */
38
34
  get accepts(): TAccepts;
39
35
  /**
40
- * Gets all emitted event types and schemas as a readonly record.
41
- * Use this when you need to access all emitted events at once.
42
- * @returns {Record<ExtractEventType<TEmits>, TEmits>} A frozen record of all emitted events.
43
- */
44
- get emits(): Record<ExtractEventType<TEmits>, TEmits>;
45
- /**
46
- * Gets a specific emitted event type and schema.
47
- * Use this when you need to access a single emitted event by its type.
48
- * @template U - The type of the emit record to retrieve.
49
- * @param {U} type - The type of the emit record.
50
- * @returns {Extract<TEmits, { type: U }>} The emit record.
51
- * @throws {Error} If the emit type is not found in the contract.
36
+ * Gets all event types and schemas that can be emitted by the
37
+ * contract bound handler.
38
+ *
39
+ * @returns {TEmits} A record of all emitted events.
52
40
  */
53
- getEmit<U extends ExtractEventType<TEmits>>(type: U): Extract<TEmits, {
54
- type: U;
55
- }>;
41
+ get emits(): TEmits;
56
42
  /**
57
- * Validates the input against the contract's accept schema.
43
+ * Validates the contract bound handler's input against the
44
+ * contract's accept schema.
58
45
  * @template U - The type of the input to validate.
59
- * @param {TAccepts['type']} type - The type of the input.
60
- * @param {U} input - The input to validate.
46
+ * @param {TAccepts['type']} type - The type of the input event.
47
+ * @param {U} input - The input data to validate.
61
48
  * @returns {z.SafeParseReturnType<U, z.infer<TAccepts['schema']>>} The validation result.
62
49
  * @throws {Error} If the accept type is not found in the contract.
63
50
  */
64
51
  validateInput<U>(type: TAccepts['type'], input: U): z.SafeParseReturnType<U, z.infer<TAccepts['schema']>>;
65
52
  /**
66
- * Validates the output against the contract's emit schema.
53
+ * Validates the contract bound handler's output against the
54
+ * contract's emit schema.
67
55
  * @template U - The type of the output to validate.
68
- * @param {U} type - The type of the output.
69
- * @param {unknown} output - The output to validate.
56
+ * @param {U} type - The type of the output event.
57
+ * @param {unknown} output - The output data to validate.
70
58
  * @returns {z.SafeParseReturnType<unknown, z.infer<Extract<TEmits, { type: U }>['schema']>>} The validation result.
71
59
  * @throws {Error} If the emit type is not found in the contract.
72
60
  */
73
- validateOutput<U extends ExtractEventType<TEmits>>(type: U, output: unknown): z.SafeParseReturnType<unknown, z.infer<Extract<TEmits, {
61
+ validateOutput<U extends keyof TEmits>(type: U, output: unknown): z.SafeParseReturnType<unknown, z.infer<Extract<TEmits, {
74
62
  type: U;
75
63
  }>['schema']>>;
76
64
  /**
@@ -82,8 +70,8 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
82
70
  private validateAccepts;
83
71
  /**
84
72
  * Validates the emits records.
85
- * @param {TEmits[]} emits - The emits records to validate.
86
- * @returns {Array<TEmits>} The validated emits records.
73
+ * @param {TEmits} emits - The emits records to validate.
74
+ * @returns {TEmits} The validated emits records.
87
75
  * @private
88
76
  */
89
77
  private validateEmits;
@@ -91,9 +79,9 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
91
79
  * Exports the ArvoContract instance as a plain object conforming to the IArvoContract interface.
92
80
  * This method can be used to serialize the contract or to create a new instance with the same parameters.
93
81
  *
94
- * @returns {IArvoContract<T, TAccepts, TEmits>} An object representing the contract, including its URI, accepts, and emits properties.
82
+ * @returns {IArvoContract<TUri, TAccepts, TEmits>} An object representing the contract, including its URI, accepts, and emits properties.
95
83
  */
96
- export(): IArvoContract<T, TAccepts, TEmits>;
84
+ export(): IArvoContract<TUri, TAccepts, TEmits>;
97
85
  /**
98
86
  * Converts the ArvoContract instance to a JSON Schema representation.
99
87
  * This method provides a way to represent the contract's structure and validation rules
@@ -106,7 +94,7 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
106
94
  * - emits: An array of objects, each containing an emitted event type and its JSON Schema representation
107
95
  */
108
96
  toJsonSchema(): {
109
- uri: T;
97
+ uri: TUri;
110
98
  description: string | null;
111
99
  accepts: {
112
100
  type: string;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  var zod_1 = require("zod");
4
15
  var validators_1 = require("./validators");
@@ -6,15 +17,17 @@ var zod_to_json_schema_1 = require("zod-to-json-schema");
6
17
  /**
7
18
  * ArvoContract class represents a contract with defined input and output schemas.
8
19
  * It provides methods for validating inputs and outputs based on the contract's specifications.
20
+ * An event handler can be bound to it so the this contract may impose the types
21
+ * on inputs and outputs of it
9
22
  *
10
- * @template T - The URI type.
11
- * @template TAccepts - The accepted record type.
12
- * @template TEmits - The emitted record type.
23
+ * @template TUri - The URI type, defaults to string.
24
+ * @template TAccepts - The type of record the contract bound handler accepts, defaults to ArvoContractRecord.
25
+ * @template TEmits - The type of records the contract bound handler emits.
13
26
  */
14
27
  var ArvoContract = /** @class */ (function () {
15
28
  /**
16
29
  * Creates an instance of ArvoContract.
17
- * @param {IArvoContract<T, TAccepts, TEmits>} params - The contract parameters.
30
+ * @param {IArvoContract<TUri, TAccepts, TEmits>} params - The contract parameters.
18
31
  */
19
32
  function ArvoContract(params) {
20
33
  this._uri = validators_1.ArvoContractValidators.contract.uri.parse(params.uri);
@@ -36,7 +49,8 @@ var ArvoContract = /** @class */ (function () {
36
49
  });
37
50
  Object.defineProperty(ArvoContract.prototype, "accepts", {
38
51
  /**
39
- * Gets the accepted record type and schema.
52
+ * Gets the type and schema of the event that the contact
53
+ * bound handler listens to.
40
54
  * @returns {TAccepts} The frozen accepts object.
41
55
  */
42
56
  get: function () {
@@ -47,40 +61,23 @@ var ArvoContract = /** @class */ (function () {
47
61
  });
48
62
  Object.defineProperty(ArvoContract.prototype, "emits", {
49
63
  /**
50
- * Gets all emitted event types and schemas as a readonly record.
51
- * Use this when you need to access all emitted events at once.
52
- * @returns {Record<ExtractEventType<TEmits>, TEmits>} A frozen record of all emitted events.
64
+ * Gets all event types and schemas that can be emitted by the
65
+ * contract bound handler.
66
+ *
67
+ * @returns {TEmits} A record of all emitted events.
53
68
  */
54
69
  get: function () {
55
- return Object.freeze(this._emits.reduce(function (acc, emit) {
56
- // @ts-ignore
57
- acc[emit.type] = emit;
58
- return acc;
59
- }, {}));
70
+ return __assign({}, this._emits);
60
71
  },
61
72
  enumerable: false,
62
73
  configurable: true
63
74
  });
64
75
  /**
65
- * Gets a specific emitted event type and schema.
66
- * Use this when you need to access a single emitted event by its type.
67
- * @template U - The type of the emit record to retrieve.
68
- * @param {U} type - The type of the emit record.
69
- * @returns {Extract<TEmits, { type: U }>} The emit record.
70
- * @throws {Error} If the emit type is not found in the contract.
71
- */
72
- ArvoContract.prototype.getEmit = function (type) {
73
- var emit = this._emits.find(function (item) { return item.type === type; });
74
- if (!emit) {
75
- throw new Error("Emit type \"".concat(type, "\" not found in contract"));
76
- }
77
- return Object.freeze(emit);
78
- };
79
- /**
80
- * Validates the input against the contract's accept schema.
76
+ * Validates the contract bound handler's input against the
77
+ * contract's accept schema.
81
78
  * @template U - The type of the input to validate.
82
- * @param {TAccepts['type']} type - The type of the input.
83
- * @param {U} input - The input to validate.
79
+ * @param {TAccepts['type']} type - The type of the input event.
80
+ * @param {U} input - The input data to validate.
84
81
  * @returns {z.SafeParseReturnType<U, z.infer<TAccepts['schema']>>} The validation result.
85
82
  * @throws {Error} If the accept type is not found in the contract.
86
83
  */
@@ -91,19 +88,20 @@ var ArvoContract = /** @class */ (function () {
91
88
  return this._accepts.schema.safeParse(input);
92
89
  };
93
90
  /**
94
- * Validates the output against the contract's emit schema.
91
+ * Validates the contract bound handler's output against the
92
+ * contract's emit schema.
95
93
  * @template U - The type of the output to validate.
96
- * @param {U} type - The type of the output.
97
- * @param {unknown} output - The output to validate.
94
+ * @param {U} type - The type of the output event.
95
+ * @param {unknown} output - The output data to validate.
98
96
  * @returns {z.SafeParseReturnType<unknown, z.infer<Extract<TEmits, { type: U }>['schema']>>} The validation result.
99
97
  * @throws {Error} If the emit type is not found in the contract.
100
98
  */
101
99
  ArvoContract.prototype.validateOutput = function (type, output) {
102
100
  var emit = this.emits[type];
103
101
  if (!emit) {
104
- throw new Error("Emit type \"".concat(type, "\" not found in contract"));
102
+ throw new Error("Emit type \"".concat(type.toString(), "\" not found in contract"));
105
103
  }
106
- return emit.schema.safeParse(output);
104
+ return emit.safeParse(output);
107
105
  };
108
106
  /**
109
107
  * Validates the accepts record.
@@ -119,21 +117,22 @@ var ArvoContract = /** @class */ (function () {
119
117
  };
120
118
  /**
121
119
  * Validates the emits records.
122
- * @param {TEmits[]} emits - The emits records to validate.
123
- * @returns {Array<TEmits>} The validated emits records.
120
+ * @param {TEmits} emits - The emits records to validate.
121
+ * @returns {TEmits} The validated emits records.
124
122
  * @private
125
123
  */
126
124
  ArvoContract.prototype.validateEmits = function (emits) {
127
- return Object.freeze(emits.map(function (item) { return ({
128
- type: validators_1.ArvoContractValidators.record.type.parse(item.type),
129
- schema: item.schema,
130
- }); }));
125
+ Object.entries(emits).forEach(function (_a) {
126
+ var key = _a[0];
127
+ return validators_1.ArvoContractValidators.record.type.parse(key);
128
+ });
129
+ return Object.freeze(emits);
131
130
  };
132
131
  /**
133
132
  * Exports the ArvoContract instance as a plain object conforming to the IArvoContract interface.
134
133
  * This method can be used to serialize the contract or to create a new instance with the same parameters.
135
134
  *
136
- * @returns {IArvoContract<T, TAccepts, TEmits>} An object representing the contract, including its URI, accepts, and emits properties.
135
+ * @returns {IArvoContract<TUri, TAccepts, TEmits>} An object representing the contract, including its URI, accepts, and emits properties.
137
136
  */
138
137
  ArvoContract.prototype.export = function () {
139
138
  return {
@@ -143,10 +142,7 @@ var ArvoContract = /** @class */ (function () {
143
142
  type: this._accepts.type,
144
143
  schema: this._accepts.schema,
145
144
  },
146
- emits: this._emits.map(function (emit) { return ({
147
- type: emit.type,
148
- schema: emit.schema,
149
- }); }),
145
+ emits: __assign({}, this._emits),
150
146
  };
151
147
  };
152
148
  /**
@@ -168,10 +164,13 @@ var ArvoContract = /** @class */ (function () {
168
164
  type: this._accepts.type,
169
165
  schema: (0, zod_to_json_schema_1.zodToJsonSchema)(this._accepts.schema),
170
166
  },
171
- emits: this._emits.map(function (item) { return ({
172
- type: zod_1.z.literal(item.type),
173
- schema: (0, zod_to_json_schema_1.zodToJsonSchema)(item.schema),
174
- }); }),
167
+ emits: Object.entries(this._emits).map(function (_a) {
168
+ var key = _a[0], value = _a[1];
169
+ return ({
170
+ type: zod_1.z.literal(key),
171
+ schema: (0, zod_to_json_schema_1.zodToJsonSchema)(value),
172
+ });
173
+ }),
175
174
  };
176
175
  };
177
176
  return ArvoContract;
@@ -13,16 +13,16 @@ export type ArvoContractRecord<TType extends string = string, TSchema extends z.
13
13
  /**
14
14
  * Interface for an Arvo contract.
15
15
  * @template TUri - The URI type, defaults to string.
16
- * @template TAccepts - The type of record the contract accepts, defaults to ArvoContractRecord.
17
- * @template TEmits - The type of record the contract emits, defaults to ArvoContractRecord.
16
+ * @template TAccepts - The type of record the contract bound handler accepts, defaults to ArvoContractRecord.
17
+ * @template TEmits - The type of records the contract bound handler emits.
18
18
  */
19
- export interface IArvoContract<TUri extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends ArvoContractRecord = ArvoContractRecord> {
19
+ export interface IArvoContract<TUri extends string = string, TAccepts extends ArvoContractRecord = ArvoContractRecord, TEmits extends Record<string, z.ZodTypeAny> = Record<string, z.ZodTypeAny>> {
20
20
  /** The unique identifier for the contract */
21
21
  uri: TUri;
22
22
  /** The record type that the contract accepts */
23
23
  accepts: TAccepts;
24
24
  /** An array of record types that the contract can emit */
25
- emits: TEmits[];
25
+ emits: TEmits;
26
26
  /** (Optional) The description of the contract or its handler */
27
27
  description?: string | null;
28
28
  }
@@ -47,11 +47,11 @@ var uuid_1 = require("uuid");
47
47
  * );
48
48
  */
49
49
  var createArvoEvent = function (event, extensions, telemetry) {
50
- return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'createArvoEvent', {}, function (span) {
50
+ return (0, OpenTelemetry_1.createOtelSpan)(telemetry || 'ArvoEvent Creation Tracer', 'createArvoEvent', {}, function (telemetryContext) {
51
51
  if (event.datacontenttype &&
52
52
  event.datacontenttype !== schema_1.ArvoDataContentType) {
53
53
  var warning = (0, utils_1.cleanString)("\n Warning! The provided datacontenttype(=".concat(event.datacontenttype, ")\n is not ArvoEvent compatible (=").concat(schema_1.ArvoDataContentType, "). There may \n be some limited functionality.\n "));
54
- (0, OpenTelemetry_1.logToSpan)(span, {
54
+ (0, OpenTelemetry_1.logToSpan)(telemetryContext.span, {
55
55
  level: 'WARNING',
56
56
  message: warning,
57
57
  });
@@ -86,7 +86,7 @@ export declare const exceptionToSpan: (span: Span, level: TelemetryLogLevel, err
86
86
  * '12345'
87
87
  * );
88
88
  */
89
- export declare const createOtelSpan: <TArgs extends unknown[], TReturn>(telemetryContext: TelemetryContext | string, spanName: string, spanOptions: SpanOptions | undefined, wrappedFunction: (currentSpan: Span, ...args: TArgs) => TReturn, thisArg?: ThisParameterType<typeof wrappedFunction>, ...args: TArgs) => TReturn;
89
+ export declare const createOtelSpan: <TArgs extends unknown[], TReturn>(telemetryContext: TelemetryContext | string, spanName: string, spanOptions: SpanOptions | undefined, wrappedFunction: (telemetryContext: TelemetryContext, ...args: TArgs) => TReturn, thisArg?: ThisParameterType<typeof wrappedFunction>, ...args: TArgs) => TReturn;
90
90
  /**
91
91
  * A constant representing a null or not applicable value in OpenTelemetry context.
92
92
  */
@@ -148,13 +148,17 @@ var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedF
148
148
  activeTracer = api_1.trace.getTracer(telemetryContext);
149
149
  }
150
150
  else {
151
- activeContext = (0, exports.getTelemetryContext)(telemetryContext.context.traceparent);
151
+ activeContext = (0, exports.getTelemetryContext)(telemetryContext.carrier.traceparent);
152
152
  activeTracer = telemetryContext.tracer;
153
153
  }
154
154
  var newSpan = activeTracer.startSpan(spanName, spanOptions, activeContext);
155
155
  try {
156
156
  var result = api_1.context.with(api_1.trace.setSpan(activeContext, newSpan), function () {
157
- return wrappedFunction.call.apply(wrappedFunction, __spreadArray([thisArg, newSpan], args, false));
157
+ return wrappedFunction.call.apply(wrappedFunction, __spreadArray([thisArg, {
158
+ span: newSpan,
159
+ tracer: activeTracer,
160
+ carrier: (0, exports.getTelemetryCarrier)(newSpan, activeContext)
161
+ }], args, false));
158
162
  });
159
163
  newSpan.setStatus({
160
164
  code: api_1.SpanStatusCode.OK,
@@ -36,5 +36,5 @@ export type TelemetryContext = {
36
36
  /**
37
37
  * The telemetry headers
38
38
  */
39
- context: TelemetryCarrier;
39
+ carrier: TelemetryCarrier;
40
40
  };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import { exceptionToSpan, logToSpan, getTelemetryContext, getTelemetryCarrier, c
6
6
  import { TelemetryCarrier, TelemetryContext, TelemetryLogLevel } from './OpenTelemetry/types';
7
7
  import { validateURI, cleanString } from './utils';
8
8
  import ArvoContract from './ArvoContract';
9
- import { createArvoContract, InferArvoContract, createContractualArvoEvent } from './ArvoContract/helpers';
9
+ import { createArvoContract, InferArvoContract, contractualArvoEventFactory } from './ArvoContract/helpers';
10
10
  import { ArvoContractValidators } from './ArvoContract/validators';
11
11
  import { ArvoContractRecord, IArvoContract, ResolveArvoContractRecord } from './ArvoContract/types';
12
12
  import ArvoContractLibrary from './ArvoContractLibrary';
@@ -77,4 +77,4 @@ declare const ArvoEventSchemas: {
77
77
  tracestate: string | null;
78
78
  }>;
79
79
  };
80
- export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, getTelemetryCarrier, getTelemetryContext, createOtelSpan, TelemetryCarrier, TelemetryContext, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, createContractualArvoEvent, };
80
+ export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, getTelemetryCarrier, getTelemetryContext, createOtelSpan, TelemetryCarrier, TelemetryContext, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, contractualArvoEventFactory, };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ 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.createContractualArvoEvent = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.createOtelSpan = exports.getTelemetryContext = exports.getTelemetryCarrier = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
6
+ exports.contractualArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.createOtelSpan = exports.getTelemetryContext = exports.getTelemetryCarrier = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
7
7
  var ArvoEvent_1 = __importDefault(require("./ArvoEvent"));
8
8
  exports.ArvoEvent = ArvoEvent_1.default;
9
9
  var schema_1 = require("./ArvoEvent/schema");
@@ -24,7 +24,7 @@ var ArvoContract_1 = __importDefault(require("./ArvoContract"));
24
24
  exports.ArvoContract = ArvoContract_1.default;
25
25
  var helpers_2 = require("./ArvoContract/helpers");
26
26
  Object.defineProperty(exports, "createArvoContract", { enumerable: true, get: function () { return helpers_2.createArvoContract; } });
27
- Object.defineProperty(exports, "createContractualArvoEvent", { enumerable: true, get: function () { return helpers_2.createContractualArvoEvent; } });
27
+ Object.defineProperty(exports, "contractualArvoEventFactory", { enumerable: true, get: function () { return helpers_2.contractualArvoEventFactory; } });
28
28
  var validators_1 = require("./ArvoContract/validators");
29
29
  Object.defineProperty(exports, "ArvoContractValidators", { enumerable: true, get: function () { return validators_1.ArvoContractValidators; } });
30
30
  var ArvoContractLibrary_1 = __importDefault(require("./ArvoContractLibrary"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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": {