arvo-core 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ import ArvoContract from '.';
2
+ import { ArvoErrorSchema } from '../schema';
3
+ import { ArvoSemanticVersion } from '../types';
4
+ /**
5
+ * Represents a version-specific view of an ArvoContract, providing a structured way to access
6
+ * all contract specifications for a particular semantic version. This type ensures type-safe
7
+ * access to version-specific schemas and event types.
8
+ *
9
+ * @template TContract - The base ArvoContract type to extract version-specific information from
10
+ * @template TVersion - The specific semantic version of the contract to extract
11
+ *
12
+ * @property uri - The URI identifying the contract
13
+ * @property version - The specific semantic version being represented
14
+ * @property description - Optional description of the contract version
15
+ * @property accepts - Specification for accepted events in this version
16
+ * @property accepts.type - The event type this version accepts
17
+ * @property accepts.schema - Zod schema for validating accepted events
18
+ * @property systemError - System error event specification
19
+ * @property systemError.type - System error event type (sys.[type].error)
20
+ * @property systemError.schema - Zod schema for system error events
21
+ * @property emits - Record of emittable event types and their Zod schemas
22
+ *
23
+ * @see {@link ArvoContract} for the base contract class
24
+ * @see {@link ArvoContract.version} for the method to create a versioned view
25
+ */
26
+ export type VersionedArvoContract<TContract extends ArvoContract, TVersion extends ArvoSemanticVersion & keyof TContract['versions']> = {
27
+ uri: TContract['uri'];
28
+ version: TVersion;
29
+ description: string | null;
30
+ accepts: {
31
+ type: TContract['type'];
32
+ schema: TContract['versions'][TVersion]['accepts'];
33
+ };
34
+ systemError: {
35
+ type: `sys.${TContract['type']}.error`;
36
+ schema: typeof ArvoErrorSchema;
37
+ };
38
+ emits: TContract['versions'][TVersion]['emits'];
39
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { ArvoContractJSONSchema, ArvoContractRecord, IArvoContract } from './types';
3
3
  import { ArvoErrorSchema } from '../schema';
4
4
  import { ArvoSemanticVersion } from '../types';
5
+ import { VersionedArvoContract } from './VersionedArvoContract';
5
6
  /**
6
7
  * ArvoContract class represents a contract with defined input and output schemas.
7
8
  * It provides methods for validating inputs and outputs based on the contract's specifications.
@@ -32,6 +33,21 @@ export default class ArvoContract<TUri extends string = string, TType extends st
32
33
  * Gets the URI of the contract.
33
34
  */
34
35
  get uri(): TUri;
36
+ /**
37
+ * Creates a version-specific view of the contract, providing easy access to all
38
+ * schemas and specifications for a particular semantic version.
39
+ *
40
+ * @template V - The semantic version to create a view for, must be a valid version in the contract
41
+ *
42
+ * @param ver - The semantic version string (e.g., "1.0.0")
43
+ * @returns A VersionedArvoContract instance containing all specifications for the requested version
44
+ *
45
+ * The returned object provides a simpler, flatter structure compared to
46
+ * accessing version-specific information through the main contract methods.
47
+ *
48
+ * @see {@link VersionedArvoContract} for the structure of the returned object
49
+ */
50
+ version<V extends ArvoSemanticVersion & keyof TVersions>(ver: V): VersionedArvoContract<typeof this, V>;
35
51
  /**
36
52
  * Get the type of the event the handler
37
53
  * bound to the contract accepts
@@ -55,6 +71,25 @@ export default class ArvoContract<TUri extends string = string, TType extends st
55
71
  * contract bound handler.
56
72
  */
57
73
  emits<V extends ArvoSemanticVersion & keyof TVersions>(version: V): TVersions[V]['emits'];
74
+ /**
75
+ * Gets the system error event specification for this contract.
76
+ * System errors follow a standardized format to handle exceptional conditions
77
+ * and failures in a consistent way across all contracts.
78
+ *
79
+ * The error schema includes:
80
+ * - errorName: The name/type of the error
81
+ * - errorMessage: A descriptive message about what went wrong
82
+ * - errorStack: Optional stack trace information (null if not available)
83
+ *
84
+ * System errors are special events that:
85
+ * - Are automatically prefixed with 'sys.' and suffixed with '.error'
86
+ * - Use a standardized schema across all contracts
87
+ * - Can capture error details, messages, and stack traces
88
+ * - Are version-independent (work the same across all contract versions)
89
+ *
90
+ * @see {@link ArvoErrorSchema} for the detailed error schema definition
91
+ * @see {@link ArvoContractRecord} for the structure of the returned record
92
+ */
58
93
  get systemError(): ArvoContractRecord<`sys.${TType}.error`, typeof ArvoErrorSchema>;
59
94
  /**
60
95
  * Validates the contract bound handler's input/ accept event against the
@@ -90,11 +125,7 @@ export default class ArvoContract<TUri extends string = string, TType extends st
90
125
  * This method provides a way to represent the contract's structure and validation rules
91
126
  * in a format that conforms to the JSON Schema specification.
92
127
  *
93
- * @returns An object representing the contract in JSON Schema format, including:
94
- * - uri: The contract's URI
95
- * - description: The contract's description (if available)
96
- * - accepts: An object containing the accepted input type and its JSON Schema representation
97
- * - emits: An array of objects, each containing an emitted event type and its JSON Schema representation
128
+ * @returns An object representing the contract in JSON Schema format:
98
129
  */
99
130
  toJsonSchema(): ArvoContractJSONSchema;
100
131
  }
@@ -46,6 +46,33 @@ var ArvoContract = /** @class */ (function () {
46
46
  enumerable: false,
47
47
  configurable: true
48
48
  });
49
+ /**
50
+ * Creates a version-specific view of the contract, providing easy access to all
51
+ * schemas and specifications for a particular semantic version.
52
+ *
53
+ * @template V - The semantic version to create a view for, must be a valid version in the contract
54
+ *
55
+ * @param ver - The semantic version string (e.g., "1.0.0")
56
+ * @returns A VersionedArvoContract instance containing all specifications for the requested version
57
+ *
58
+ * The returned object provides a simpler, flatter structure compared to
59
+ * accessing version-specific information through the main contract methods.
60
+ *
61
+ * @see {@link VersionedArvoContract} for the structure of the returned object
62
+ */
63
+ ArvoContract.prototype.version = function (ver) {
64
+ return {
65
+ uri: this._uri,
66
+ description: this.description,
67
+ version: ver,
68
+ accepts: {
69
+ type: this._type,
70
+ schema: this._versions[ver].accepts,
71
+ },
72
+ systemError: this.systemError,
73
+ emits: this._versions[ver].emits,
74
+ };
75
+ };
49
76
  Object.defineProperty(ArvoContract.prototype, "type", {
50
77
  /**
51
78
  * Get the type of the event the handler
@@ -97,6 +124,25 @@ var ArvoContract = /** @class */ (function () {
97
124
  return __assign({}, this._versions[version].emits);
98
125
  };
99
126
  Object.defineProperty(ArvoContract.prototype, "systemError", {
127
+ /**
128
+ * Gets the system error event specification for this contract.
129
+ * System errors follow a standardized format to handle exceptional conditions
130
+ * and failures in a consistent way across all contracts.
131
+ *
132
+ * The error schema includes:
133
+ * - errorName: The name/type of the error
134
+ * - errorMessage: A descriptive message about what went wrong
135
+ * - errorStack: Optional stack trace information (null if not available)
136
+ *
137
+ * System errors are special events that:
138
+ * - Are automatically prefixed with 'sys.' and suffixed with '.error'
139
+ * - Use a standardized schema across all contracts
140
+ * - Can capture error details, messages, and stack traces
141
+ * - Are version-independent (work the same across all contract versions)
142
+ *
143
+ * @see {@link ArvoErrorSchema} for the detailed error schema definition
144
+ * @see {@link ArvoContractRecord} for the structure of the returned record
145
+ */
100
146
  get: function () {
101
147
  return {
102
148
  type: "sys.".concat(this._type, ".error"),
@@ -159,11 +205,7 @@ var ArvoContract = /** @class */ (function () {
159
205
  * This method provides a way to represent the contract's structure and validation rules
160
206
  * in a format that conforms to the JSON Schema specification.
161
207
  *
162
- * @returns An object representing the contract in JSON Schema format, including:
163
- * - uri: The contract's URI
164
- * - description: The contract's description (if available)
165
- * - accepts: An object containing the accepted input type and its JSON Schema representation
166
- * - emits: An array of objects, each containing an emitted event type and its JSON Schema representation
208
+ * @returns An object representing the contract in JSON Schema format:
167
209
  */
168
210
  ArvoContract.prototype.toJsonSchema = function () {
169
211
  var _this = this;
@@ -178,6 +220,10 @@ var ArvoContract = /** @class */ (function () {
178
220
  type: _this._type,
179
221
  schema: (0, zod_to_json_schema_1.zodToJsonSchema)(contract.accepts),
180
222
  },
223
+ systemError: {
224
+ type: _this.systemError.type,
225
+ schema: (0, zod_to_json_schema_1.zodToJsonSchema)(_this.systemError.schema)
226
+ },
181
227
  emits: Object.entries(contract.emits).map(function (_a) {
182
228
  var key = _a[0], value = _a[1];
183
229
  return ({
@@ -62,6 +62,13 @@ export type ArvoContractJSONSchema = {
62
62
  /** JSON Schema representation of the input validation schema */
63
63
  schema: ReturnType<typeof zodToJsonSchema>;
64
64
  };
65
+ /** The system error event */
66
+ systemError: {
67
+ /** The type of the event */
68
+ type: string;
69
+ /** The schema of the error */
70
+ schema: ReturnType<typeof zodToJsonSchema>;
71
+ };
65
72
  /** Array of schemas for events that can be emitted in this version */
66
73
  emits: {
67
74
  /** The type identifier for the emitted event */
package/dist/index.d.ts CHANGED
@@ -21,10 +21,11 @@ import { ArvoOrchestrationSubjectContentSchema } from './ArvoOrchestrationSubjec
21
21
  import { ArvoOrchestrationSubjectContent } from './ArvoOrchestrationSubject/type';
22
22
  import ArvoEventHttp from './ArvoEventHttp';
23
23
  import { ArvoEventHttpConfig } from './ArvoEventHttp/types';
24
- import { InferArvoContract, InferArvoEvent, ArvoSemanticVersion, ArvoErrorType } from './types';
24
+ import { InferArvoContract, InferArvoEvent, ArvoSemanticVersion, ArvoErrorType, InferVersionedArvoContract } from './types';
25
25
  import { createArvoOrchestratorContract } from './ArvoOrchestratorContract';
26
26
  import { ICreateArvoOrchestratorContract, ArvoOrchestratorContract } from './ArvoOrchestratorContract/types';
27
27
  import { ArvoOrchestratorEventTypeGen } from './ArvoOrchestratorContract/typegen';
28
+ import { VersionedArvoContract } from './ArvoContract/VersionedArvoContract';
28
29
  /**
29
30
  * Collection of Zod schemas for validating various aspects of Arvo events.
30
31
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
@@ -99,4 +100,4 @@ declare const ArvoEventSchema: {
99
100
  parentSubject$$: string | null;
100
101
  }>;
101
102
  };
102
- export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchema, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoEventFactory, createArvoEventFactory, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContent, ArvoSemanticVersion, InferArvoEvent, InferArvoContract, createArvoOrchestratorContract, ICreateArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, ExecutionOpenTelemetryConfiguration, parseEventDataSchema, ArvoOrchestrationSubjectContentSchema, ArvoSemanticVersionSchema, ArvoErrorSchema, ArvoErrorType, compareSemanticVersions, parseSemanticVersion, createSimpleArvoContract, ArvoOrchestratorContract, };
103
+ export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchema, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoEventFactory, createArvoEventFactory, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContent, ArvoSemanticVersion, InferArvoEvent, InferArvoContract, createArvoOrchestratorContract, ICreateArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, ExecutionOpenTelemetryConfiguration, parseEventDataSchema, ArvoOrchestrationSubjectContentSchema, ArvoSemanticVersionSchema, ArvoErrorSchema, ArvoErrorType, compareSemanticVersions, parseSemanticVersion, createSimpleArvoContract, ArvoOrchestratorContract, VersionedArvoContract, InferVersionedArvoContract, };
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import ArvoContract from './ArvoContract';
3
3
  import ArvoEvent from './ArvoEvent';
4
4
  import { ArvoExtension, OpenTelemetryExtension } from './ArvoEvent/types';
5
5
  import { ArvoErrorSchema } from './schema';
6
+ import { VersionedArvoContract } from './ArvoContract/VersionedArvoContract';
6
7
  /**
7
8
  * Represents the version of Arvo components following Semantic Versioning (SemVer).
8
9
  *
@@ -152,4 +153,11 @@ export type InferArvoContract<T extends ArvoContract<string, string, Record<Arvo
152
153
  systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
153
154
  } : never;
154
155
  export type ArvoErrorType = z.infer<typeof ArvoErrorSchema>;
156
+ export type InferVersionedArvoContract<TVersion extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> = {
157
+ accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['accepts']['schema']>, {}, TVersion['accepts']['type']>>;
158
+ systemError: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['systemError']['schema']>, {}, TVersion['systemError']['type']>>;
159
+ emits: {
160
+ [K in string & keyof TVersion['emits']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['emits'][K]>, {}, K>>;
161
+ };
162
+ };
155
163
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
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": {