arvo-core 2.0.9 → 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 +5 -53
  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
package/dist/types.d.ts CHANGED
@@ -1,192 +1,72 @@
1
1
  import { z } from 'zod';
2
- import ArvoContract from './ArvoContract';
3
2
  import ArvoEvent from './ArvoEvent';
4
3
  import { ArvoExtension, OpenTelemetryExtension } from './ArvoEvent/types';
5
4
  import { ArvoErrorSchema } from './schema';
6
5
  import { VersionedArvoContract } from './ArvoContract/VersionedArvoContract';
7
6
  /**
8
- * Represents the version of Arvo components following Semantic Versioning (SemVer).
9
- *
10
- * Format:
11
- * MAJOR.MINOR.PATCH where each component is a non-negative integer
12
- *
13
- * Restrictions:
14
- * Must not contain semicolons (;)
15
- *
16
- * @example
17
- * ```typescript
18
- * const version: ArvoSemanticVersion = "1.0.0";
19
- * const preRelease: ArvoSemanticVersion = "0.5.2";
20
- * const major: ArvoSemanticVersion = "2.0.0";
21
- * ```
7
+ * Represents a semantic version string following the SemVer format (MAJOR.MINOR.PATCH).
22
8
  */
23
9
  export type ArvoSemanticVersion = `${number}.${number}.${number}`;
24
10
  /**
25
- * A type utility that infers the structure of an ArvoEvent.
26
- *
27
- * @template TData - The type of the event payload
28
- * @template TExtension - Additional extension properties for the event
29
- * @template TType - The literal type string identifying the event
30
- *
31
- * @property id - Unique identifier for the event (UUID v4 recommended)
32
- * @property source - Identifier for the context where the event occurred
33
- * @property specversion - CloudEvents specification version
34
- * @property type - Event type identifier
35
- * @property subject - Event subject in the producer's context
36
- * @property datacontenttype - MIME type of the event payload
37
- * @property dataschema - URI reference to the event's JSON schema
38
- * @property data - The actual event payload
39
- * @property time - ISO 8601 timestamp of event occurrence
11
+ * Infers the complete structure of an ArvoEvent by combining base CloudEvents fields,
12
+ * Arvo-specific extensions, OpenTelemetry extensions, and custom extensions.
40
13
  *
41
14
  * @example
42
15
  * ```typescript
43
- * type UserCreatedEvent = InferArvoEvent<ArvoEvent<
16
+ * type UserCreatedEvent = InferArvoEvent<ArvoEvent
44
17
  * { userId: string; email: string },
45
18
  * { region: string },
46
19
  * 'user.created'
47
20
  * >>;
48
- *
49
- * // Results in:
50
- * // {
51
- * // id: string;
52
- * // source: string;
53
- * // specversion: string;
54
- * // type: 'user.created';
55
- * // subject: string;
56
- * // datacontenttype: string;
57
- * // dataschema: string | null;
58
- * // data: { userId: string; email: string };
59
- * // time: string;
60
- * // region: string;
61
- * // // ... plus ArvoExtension & OpenTelemetryExtension properties
62
- * // }
63
21
  * ```
64
22
  */
65
- export type InferArvoEvent<T> = T extends ArvoEvent<infer TData, infer TExtension, infer TType> ? {
66
- /** Unique identifier of the event */
23
+ export type InferArvoEvent<TEvent extends ArvoEvent<any, any, any>> = {
67
24
  id: string;
68
- /** Identifies the context in which an event happened */
69
25
  source: string;
70
- /** The version of the CloudEvents specification */
71
26
  specversion: string;
72
- /** Describes the type of event related to the originating occurrence */
73
- type: TType;
74
- /** Describes the subject of the event in the context of the event producer */
27
+ type: TEvent['type'];
75
28
  subject: string;
76
- /** Content type of the data value */
77
29
  datacontenttype: string;
78
- /** A link to the schema that the data adheres to */
79
30
  dataschema: string | null;
80
- /** Event payload */
81
- data: TData;
82
- /** Timestamp of when the occurrence happened */
31
+ data: TEvent['data'];
83
32
  time: string;
84
- } & ArvoExtension & OpenTelemetryExtension & TExtension : never;
85
- type InferZodSchema<T> = T extends z.ZodTypeAny ? z.infer<T> : never;
33
+ } & ArvoExtension & OpenTelemetryExtension & TEvent['extensions'];
86
34
  /**
87
- * A comprehensive type utility that infers the complete structure of an ArvoContract,
88
- * including versioned event types, accepted events, and emitted events.
89
- *
90
- * @template T - The ArvoContract type to infer from
91
- *
92
- * @property uri - Unique identifier for the contract
93
- * @property type - The event type this contract handles
94
- * @property versions - Version-specific contract definitions
95
- * @property versions[version].accepts - Events this contract version can handle
96
- * @property versions[version].emits - Events this contract version can produce
97
- * @property systemError - System error event definition for this contract
98
- *
99
- * @example
100
- * ```typescript
101
- * const userContract = new ArvoContract(
102
- * 'user-service',
103
- * 'user.operation',
104
- * {
105
- * '1.0.0': {
106
- * accepts: z.object({ userId: z.string() }),
107
- * emits: {
108
- * 'user.created': z.object({ userId: z.string(), timestamp: z.string() }),
109
- * 'user.failed': z.object({ error: z.string() })
110
- * }
111
- * }
112
- * }
113
- * );
114
- *
115
- * type UserContractType = InferArvoContract<typeof userContract>;
116
- * // Results in:
117
- * // {
118
- * // uri: 'user-service';
119
- * // type: 'user.operation';
120
- * // versions: {
121
- * // '1.0.0': {
122
- * // accepts: { ... inferred input event type ... };
123
- * // emits: {
124
- * // 'user.created': { ... inferred output event type ... };
125
- * // 'user.failed': { ... inferred error event type ... };
126
- * // }
127
- * // }
128
- * // };
129
- * // systemError: { ... inferred system error event type ... };
130
- * // }
131
- * ```
35
+ * Utility type to infer the TypeScript type from a Zod schema.
132
36
  */
133
- export type InferArvoContract<T extends ArvoContract<string, string, Record<ArvoSemanticVersion, {
134
- accepts: z.ZodTypeAny;
135
- emits: Record<string, z.ZodTypeAny>;
136
- }>>> = T extends ArvoContract<infer TUri, infer TType, infer TVersion> ? {
137
- uri: TUri;
138
- type: TType;
139
- versions: {
140
- [V in ArvoSemanticVersion & keyof TVersion]: {
141
- accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion[V]['accepts']>, {}, TType>>;
142
- emits: {
143
- [K in keyof TVersion[V]['emits']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion[V]['emits'][K]>, {}, K & string>>;
144
- };
145
- };
146
- };
147
- systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
148
- } : never;
37
+ type InferZodSchema<T extends z.ZodTypeAny> = z.infer<T>;
149
38
  /**
150
- * Represents the structure of an Arvo system error.
151
- * This type is inferred from the ArvoErrorSchema and provides
152
- * the standard error format used across all Arvo contracts.
153
- *
154
- * @property errorName - The classification or type of the error
155
- * @property errorMessage - A human-readable description of what went wrong
156
- * @property errorStack - Optional stack trace for debugging (null if not available)
157
- *
158
- * @example
159
- * ```typescript
160
- * const error: ArvoErrorType = {
161
- * errorName: 'ValidationError',
162
- * errorMessage: 'Invalid input format',
163
- * errorStack: 'Error: Invalid input format\n at validate (/app.js:10)'
164
- * };
165
- * ```
39
+ * Represents the structure of an Arvo system error, inferred from the ArvoErrorSchema.
40
+ * Provides the standard error format used across all Arvo contracts.
166
41
  *
167
42
  * @see {@link ArvoErrorSchema} for the underlying Zod schema definition
168
43
  */
169
44
  export type ArvoErrorType = z.infer<typeof ArvoErrorSchema>;
170
45
  /**
171
- * A type utility that infers the complete event structure from a versioned Arvo contract.
172
- * This type extracts and transforms all event types, schemas, and error definitions
173
- * from a specific version of a contract into their fully resolved event forms.
174
- *
175
- * @template TVersion - The versioned contract to infer from, must extend VersionedArvoContract
46
+ * Infers the complete contract structure from a versioned Arvo contract.
47
+ * This provides type-safe access to all events, schemas, and metadata defined in a contract.
176
48
  *
177
- * @property accepts - The fully resolved accept event type for this version
178
- * @property systemError - The fully resolved system error event type
179
- * @property emits - Record of all fully resolved emit event types
49
+ * @remarks
50
+ * The inferred contract includes:
51
+ * - `accepts`: Events the contract can receive
52
+ * - `systemError`: Standard error events
53
+ * - `emitMap`: Dictionary of all possible emit events
54
+ * - `emits`: Array type containing all possible emit events
55
+ * - `metadata`: Contract metadata
180
56
  *
181
57
  * @see {@link VersionedArvoContract} for the input contract structure
182
58
  * @see {@link InferArvoEvent} for the event inference utility
183
59
  * @see {@link ArvoEvent} for the base event structure
184
60
  */
185
- export type InferVersionedArvoContract<TVersion extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> = {
61
+ export type InferVersionedArvoContract<TVersion extends VersionedArvoContract<any, any, any>> = {
186
62
  accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['accepts']['schema']>, {}, TVersion['accepts']['type']>>;
187
63
  systemError: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['systemError']['schema']>, {}, TVersion['systemError']['type']>>;
188
- emits: {
189
- [K in string & keyof TVersion['emits']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['emits'][K]>, {}, K>>;
64
+ emitMap: {
65
+ [K in string & keyof TVersion['emitMap']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['emitMap'][K]>, {}, K>>;
190
66
  };
67
+ emits: Array<{
68
+ [K in string & keyof TVersion['emitMap']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion['emitMap'][K]>, {}, K>>;
69
+ }[string & keyof TVersion['emitMap']]>;
70
+ metadata: TVersion['metadata'];
191
71
  };
192
72
  export {};
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import ArvoContract from './ArvoContract';
2
+ import { VersionedArvoContract } from './ArvoContract/VersionedArvoContract';
3
+ import ArvoEvent from './ArvoEvent';
1
4
  import { ArvoSemanticVersion } from './types';
2
5
  /**
3
6
  * Cleans a string by removing leading/trailing whitespace from each line,
@@ -68,4 +71,49 @@ export declare function parseSemanticVersion(version: ArvoSemanticVersion): Vers
68
71
  * - 0 if version1 === version2
69
72
  */
70
73
  export declare function compareSemanticVersions(version1: ArvoSemanticVersion, version2: ArvoSemanticVersion): number;
74
+ /**
75
+ * Manages event dataschema strings for versioned contracts.
76
+ * Handles creation and parsing of dataschema identifiers.
77
+ */
78
+ export declare class EventDataschemaUtil {
79
+ /**
80
+ * Creates a dataschema string from a versioned contract.
81
+ * Format: `{contract.uri}/{contract.version}`
82
+ *
83
+ * @param contract - Versioned contract instance
84
+ * @returns Formatted dataschema string
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const schema = EventDataschema.create(versionedContract);
89
+ * // Returns: "my-contract/1.0.0"
90
+ * ```
91
+ */
92
+ static create(contract: VersionedArvoContract<ArvoContract, ArvoSemanticVersion>): string;
93
+ /**
94
+ * Creates dataschema string with wildcard version.
95
+ * @param contract Versioned contract
96
+ * @returns `{contract.uri}/{WildCardArvoSemanticVersion}`
97
+ */
98
+ static createWithWildCardVersion(contract: VersionedArvoContract<ArvoContract, ArvoSemanticVersion>): string;
99
+ /**
100
+ * Extracts URI and version from dataschema string.
101
+ *
102
+ * @param data - Event object or dataschema string
103
+ * @returns Parsed URI and version, or null if invalid
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const result = EventDataschema.parse("my-contract/1.0.0");
108
+ * // Returns: { uri: "my-contract", version: "1.0.0" }
109
+ *
110
+ * const invalid = EventDataschema.parse("invalid-schema");
111
+ * // Returns: null
112
+ * ```
113
+ */
114
+ static parse(data: ArvoEvent | string): {
115
+ uri: string;
116
+ version: ArvoSemanticVersion;
117
+ } | null;
118
+ }
71
119
  export {};
package/dist/utils.js CHANGED
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTimestamp = exports.validateURI = void 0;
3
+ exports.EventDataschemaUtil = exports.createTimestamp = exports.validateURI = void 0;
4
4
  exports.cleanString = cleanString;
5
5
  exports.parseSemanticVersion = parseSemanticVersion;
6
6
  exports.compareSemanticVersions = compareSemanticVersions;
7
+ var WildCardArvoSemanticVersion_1 = require("./ArvoContract/WildCardArvoSemanticVersion");
8
+ var OpenTelemetry_1 = require("./OpenTelemetry");
9
+ var schema_1 = require("./schema");
7
10
  /**
8
11
  * Cleans a string by removing leading/trailing whitespace from each line,
9
12
  * removing empty lines, and joining the remaining lines with newline characters.
@@ -110,3 +113,69 @@ function compareSemanticVersions(version1, version2) {
110
113
  }
111
114
  return v1.patch - v2.patch;
112
115
  }
116
+ /**
117
+ * Manages event dataschema strings for versioned contracts.
118
+ * Handles creation and parsing of dataschema identifiers.
119
+ */
120
+ var EventDataschemaUtil = /** @class */ (function () {
121
+ function EventDataschemaUtil() {
122
+ }
123
+ /**
124
+ * Creates a dataschema string from a versioned contract.
125
+ * Format: `{contract.uri}/{contract.version}`
126
+ *
127
+ * @param contract - Versioned contract instance
128
+ * @returns Formatted dataschema string
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const schema = EventDataschema.create(versionedContract);
133
+ * // Returns: "my-contract/1.0.0"
134
+ * ```
135
+ */
136
+ EventDataschemaUtil.create = function (contract) {
137
+ return "".concat(contract.uri, "/").concat(contract.version);
138
+ };
139
+ /**
140
+ * Creates dataschema string with wildcard version.
141
+ * @param contract Versioned contract
142
+ * @returns `{contract.uri}/{WildCardArvoSemanticVersion}`
143
+ */
144
+ EventDataschemaUtil.createWithWildCardVersion = function (contract) {
145
+ return "".concat(contract.uri, "/").concat(WildCardArvoSemanticVersion_1.WildCardArvoSemanticVersion);
146
+ };
147
+ /**
148
+ * Extracts URI and version from dataschema string.
149
+ *
150
+ * @param data - Event object or dataschema string
151
+ * @returns Parsed URI and version, or null if invalid
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const result = EventDataschema.parse("my-contract/1.0.0");
156
+ * // Returns: { uri: "my-contract", version: "1.0.0" }
157
+ *
158
+ * const invalid = EventDataschema.parse("invalid-schema");
159
+ * // Returns: null
160
+ * ```
161
+ */
162
+ EventDataschemaUtil.parse = function (data) {
163
+ var _a;
164
+ try {
165
+ var dataschema = typeof data === 'string' ? data : ((_a = data.dataschema) !== null && _a !== void 0 ? _a : '');
166
+ var items = dataschema.split('/');
167
+ var version = schema_1.ArvoSemanticVersionSchema.parse(items.pop());
168
+ var uri = items.join('/');
169
+ return { uri: uri, version: version };
170
+ }
171
+ catch (e) {
172
+ (0, OpenTelemetry_1.logToSpan)({
173
+ level: 'ERROR',
174
+ message: "Unable to parse the event dataschema: ".concat(e.message),
175
+ });
176
+ return null;
177
+ }
178
+ };
179
+ return EventDataschemaUtil;
180
+ }());
181
+ exports.EventDataschemaUtil = EventDataschemaUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "2.0.9",
3
+ "version": "2.1.0",
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": {
@@ -1,39 +0,0 @@
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
- };