arvo-core 1.0.26 → 1.0.27

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.
package/README.md CHANGED
@@ -73,6 +73,7 @@ import {
73
73
  createArvoEvent,
74
74
  createArvoContract,
75
75
  createArvoContractLibrary,
76
+ createArvoEventFactory,
76
77
  } from 'arvo-core';
77
78
  ```
78
79
 
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ArvoContractRecord, IArvoContract } from './types';
2
+ import { ArvoContractJSONSchema, ArvoContractRecord, IArvoContract } from './types';
3
3
  import { ArvoErrorSchema } from '../schema';
4
4
  /**
5
5
  * ArvoContract class represents a contract with defined input and output schemas.
@@ -39,7 +39,7 @@ export default class ArvoContract<TUri extends string = string, TType extends st
39
39
  get emits(): TEmits;
40
40
  get systemError(): ArvoContractRecord<`sys.${TType}.error`, typeof ArvoErrorSchema>;
41
41
  /**
42
- * Validates the contract bound handler's input against the
42
+ * Validates the contract bound handler's input/ accept event against the
43
43
  * contract's accept schema.
44
44
  * @template U - The type of the input to validate.
45
45
  * @param type - The type of the input event.
@@ -47,9 +47,9 @@ export default class ArvoContract<TUri extends string = string, TType extends st
47
47
  * @returns The validation result.
48
48
  * @throws If the accept type is not found in the contract.
49
49
  */
50
- validateInput<U>(type: TType, input: U): z.SafeParseReturnType<any, any>;
50
+ validateAccepts<U>(type: TType, input: U): z.SafeParseReturnType<any, any>;
51
51
  /**
52
- * Validates the contract bound handler's output against the
52
+ * Validates the contract bound handler's output/ emits against the
53
53
  * contract's emit schema.
54
54
  * @template U - The type of the output to validate.
55
55
  * @param type - The type of the output event.
@@ -57,21 +57,21 @@ export default class ArvoContract<TUri extends string = string, TType extends st
57
57
  * @returns The validation result.
58
58
  * @throws If the emit type is not found in the contract.
59
59
  */
60
- validateOutput<U extends keyof TEmits>(type: U, output: unknown): z.SafeParseReturnType<any, any>;
60
+ validateEmits<U extends keyof TEmits>(type: U, output: unknown): z.SafeParseReturnType<any, any>;
61
61
  /**
62
62
  * Validates the accepts record.
63
63
  * @param accepts - The accepts record to validate.
64
64
  * @returns The validated accepts record.
65
65
  * @private
66
66
  */
67
- private validateAccepts;
67
+ private _validateAccepts;
68
68
  /**
69
69
  * Validates the emits records.
70
70
  * @param emits - The emits records to validate.
71
71
  * @returns The validated emits records.
72
72
  * @private
73
73
  */
74
- private validateEmits;
74
+ private _validateEmits;
75
75
  /**
76
76
  * Exports the ArvoContract instance as a plain object conforming to the IArvoContract interface.
77
77
  * This method can be used to serialize the contract or to create a new instance with the same parameters.
@@ -90,5 +90,5 @@ export default class ArvoContract<TUri extends string = string, TType extends st
90
90
  * - accepts: An object containing the accepted input type and its JSON Schema representation
91
91
  * - emits: An array of objects, each containing an emitted event type and its JSON Schema representation
92
92
  */
93
- toJsonSchema(): Record<string, any>;
93
+ toJsonSchema(): ArvoContractJSONSchema;
94
94
  }
@@ -32,8 +32,8 @@ var ArvoContract = /** @class */ (function () {
32
32
  */
33
33
  function ArvoContract(params) {
34
34
  this._uri = validators_1.ArvoContractValidators.contract.uri.parse(params.uri);
35
- this._accepts = this.validateAccepts(params.accepts);
36
- this._emits = this.validateEmits(params.emits);
35
+ this._accepts = this._validateAccepts(params.accepts);
36
+ this._emits = this._validateEmits(params.emits);
37
37
  this.description = params.description || null;
38
38
  }
39
39
  Object.defineProperty(ArvoContract.prototype, "uri", {
@@ -79,7 +79,7 @@ var ArvoContract = /** @class */ (function () {
79
79
  configurable: true
80
80
  });
81
81
  /**
82
- * Validates the contract bound handler's input against the
82
+ * Validates the contract bound handler's input/ accept event against the
83
83
  * contract's accept schema.
84
84
  * @template U - The type of the input to validate.
85
85
  * @param type - The type of the input event.
@@ -87,14 +87,14 @@ var ArvoContract = /** @class */ (function () {
87
87
  * @returns The validation result.
88
88
  * @throws If the accept type is not found in the contract.
89
89
  */
90
- ArvoContract.prototype.validateInput = function (type, input) {
90
+ ArvoContract.prototype.validateAccepts = function (type, input) {
91
91
  if (type !== this._accepts.type) {
92
92
  throw new Error("Accept type \"".concat(type, "\" not found in contract"));
93
93
  }
94
94
  return this._accepts.schema.safeParse(input);
95
95
  };
96
96
  /**
97
- * Validates the contract bound handler's output against the
97
+ * Validates the contract bound handler's output/ emits against the
98
98
  * contract's emit schema.
99
99
  * @template U - The type of the output to validate.
100
100
  * @param type - The type of the output event.
@@ -102,7 +102,7 @@ var ArvoContract = /** @class */ (function () {
102
102
  * @returns The validation result.
103
103
  * @throws If the emit type is not found in the contract.
104
104
  */
105
- ArvoContract.prototype.validateOutput = function (type, output) {
105
+ ArvoContract.prototype.validateEmits = function (type, output) {
106
106
  var emit = this.emits[type];
107
107
  if (!emit) {
108
108
  throw new Error("Emit type \"".concat(type.toString(), "\" not found in contract"));
@@ -115,7 +115,7 @@ var ArvoContract = /** @class */ (function () {
115
115
  * @returns The validated accepts record.
116
116
  * @private
117
117
  */
118
- ArvoContract.prototype.validateAccepts = function (accepts) {
118
+ ArvoContract.prototype._validateAccepts = function (accepts) {
119
119
  return {
120
120
  type: validators_1.ArvoContractValidators.record.type.parse(accepts.type),
121
121
  schema: accepts.schema,
@@ -127,7 +127,7 @@ var ArvoContract = /** @class */ (function () {
127
127
  * @returns The validated emits records.
128
128
  * @private
129
129
  */
130
- ArvoContract.prototype.validateEmits = function (emits) {
130
+ ArvoContract.prototype._validateEmits = function (emits) {
131
131
  Object.entries(emits).forEach(function (_a) {
132
132
  var key = _a[0];
133
133
  return validators_1.ArvoContractValidators.record.type.parse(key);
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import zodToJsonSchema from 'zod-to-json-schema';
2
3
  /**
3
4
  * Represents a record in an Arvo contract.
4
5
  * @template TType - The type of the record, defaults to string.
@@ -33,3 +34,26 @@ export interface IArvoContract<TUri extends string = string, TType extends strin
33
34
  * @template T - The ArvoContractRecord to resolve.
34
35
  */
35
36
  export type ResolveArvoContractRecord<T extends ArvoContractRecord> = z.infer<T['schema']>;
37
+ /**
38
+ * Represents the JSON Schema representation of an ArvoContract.
39
+ */
40
+ export type ArvoContractJSONSchema = {
41
+ /** The unique identifier (URI) of the contract */
42
+ uri: string;
43
+ /** The description of the contract (null if not provided) */
44
+ description: string | null;
45
+ /** The accepted input schema for the contract */
46
+ accepts: {
47
+ /** The type identifier for the accepted input */
48
+ type: string;
49
+ /** The JSON Schema representation of the accepted input schema */
50
+ schema: ReturnType<typeof zodToJsonSchema>;
51
+ };
52
+ /** An array of emitted event schemas for the contract */
53
+ emits: {
54
+ /** The type identifier for the emitted event */
55
+ type: string;
56
+ /** The JSON Schema representation of the emitted event schema */
57
+ schema: ReturnType<typeof zodToJsonSchema>;
58
+ }[];
59
+ };
@@ -137,7 +137,7 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
137
137
  *
138
138
  * @remark
139
139
  * This is a convenience getter for the data in `this.extensions.traceparent` as this
140
- * is an ArvoEvent object which natively defined this extension on the CloudEvent
140
+ * is an ArvoEvent object which natively defines this extension on the CloudEvent
141
141
  * spec.
142
142
  */
143
143
  get traceparent(): string | null;
@@ -148,7 +148,7 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
148
148
  *
149
149
  * @remark
150
150
  * This is a convenience getter for the data in `this.extensions.tracestate` as this
151
- * is an ArvoEvent object which natively defined this extension on the CloudEvent
151
+ * is an ArvoEvent object which natively defines this extension on the CloudEvent
152
152
  * spec.
153
153
  */
154
154
  get tracestate(): string | null;
@@ -198,7 +198,7 @@ var ArvoEvent = /** @class */ (function () {
198
198
  *
199
199
  * @remark
200
200
  * This is a convenience getter for the data in `this.extensions.traceparent` as this
201
- * is an ArvoEvent object which natively defined this extension on the CloudEvent
201
+ * is an ArvoEvent object which natively defines this extension on the CloudEvent
202
202
  * spec.
203
203
  */
204
204
  get: function () {
@@ -215,7 +215,7 @@ var ArvoEvent = /** @class */ (function () {
215
215
  *
216
216
  * @remark
217
217
  * This is a convenience getter for the data in `this.extensions.tracestate` as this
218
- * is an ArvoEvent object which natively defined this extension on the CloudEvent
218
+ * is an ArvoEvent object which natively defines this extension on the CloudEvent
219
219
  * spec.
220
220
  */
221
221
  get: function () {
@@ -54,8 +54,8 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
54
54
  error: Error;
55
55
  to: string;
56
56
  }, extensions?: TExtension): import("..").ArvoEvent<{
57
- errorName: string;
58
57
  errorMessage: string;
58
+ errorName: string;
59
59
  errorStack: string | null;
60
60
  }, TExtension, `sys.${TType}.error`>;
61
61
  }
@@ -58,7 +58,7 @@ var ArvoEventFactory = /** @class */ (function () {
58
58
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
59
59
  span.setStatus({ code: api_1.SpanStatusCode.OK });
60
60
  try {
61
- var validationResult = _this.contract.validateInput(_this.contract.accepts.type, event.data);
61
+ var validationResult = _this.contract.validateAccepts(_this.contract.accepts.type, event.data);
62
62
  if (!validationResult.success) {
63
63
  throw new Error("Accept Event data validation failed: ".concat(validationResult.error.message));
64
64
  }
@@ -93,7 +93,7 @@ var ArvoEventFactory = /** @class */ (function () {
93
93
  return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () {
94
94
  span.setStatus({ code: api_1.SpanStatusCode.OK });
95
95
  try {
96
- var validationResult = _this.contract.validateOutput(event.type, event.data);
96
+ var validationResult = _this.contract.validateEmits(event.type, event.data);
97
97
  if (!validationResult.success) {
98
98
  throw new Error("Emit Event data validation failed: ".concat(validationResult.error.message));
99
99
  }
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import { validateURI, cleanString } from './utils';
8
8
  import ArvoContract from './ArvoContract';
9
9
  import { createArvoContract, InferArvoContract } from './ArvoContract/helpers';
10
10
  import { ArvoContractValidators } from './ArvoContract/validators';
11
- import { ArvoContractRecord, IArvoContract, ResolveArvoContractRecord } from './ArvoContract/types';
11
+ import { ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractJSONSchema } from './ArvoContract/types';
12
12
  import ArvoContractLibrary from './ArvoContractLibrary';
13
13
  import { createArvoContractLibrary } from './ArvoContractLibrary/helpers';
14
14
  import ArvoEventFactory from './ArvoEventFactory';
@@ -84,4 +84,4 @@ declare const ArvoEventSchemas: {
84
84
  tracestate: string | null;
85
85
  }>;
86
86
  };
87
- export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, };
87
+ export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, };
package/dist/schema.d.ts CHANGED
@@ -10,11 +10,11 @@ export declare const ArvoErrorSchema: z.ZodObject<{
10
10
  errorMessage: z.ZodString;
11
11
  errorStack: z.ZodNullable<z.ZodString>;
12
12
  }, "strip", z.ZodTypeAny, {
13
- errorName: string;
14
13
  errorMessage: string;
14
+ errorName: string;
15
15
  errorStack: string | null;
16
16
  }, {
17
- errorName: string;
18
17
  errorMessage: string;
18
+ errorName: string;
19
19
  errorStack: string | null;
20
20
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
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": {