arvo-core 1.2.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/ArvoContract/helpers.d.ts +119 -20
  3. package/dist/ArvoContract/helpers.js +150 -32
  4. package/dist/ArvoContract/index.d.ts +32 -26
  5. package/dist/ArvoContract/index.js +69 -60
  6. package/dist/ArvoContract/types.d.ts +49 -35
  7. package/dist/ArvoEvent/schema.d.ts +2 -2
  8. package/dist/ArvoEventFactory/helpers.d.ts +39 -9
  9. package/dist/ArvoEventFactory/helpers.js +50 -8
  10. package/dist/ArvoEventFactory/index.d.ts +60 -33
  11. package/dist/ArvoEventFactory/index.js +62 -36
  12. package/dist/ArvoOrchestrationSubject/index.d.ts +5 -4
  13. package/dist/ArvoOrchestrationSubject/index.js +2 -2
  14. package/dist/ArvoOrchestrationSubject/schema.d.ts +1 -2
  15. package/dist/ArvoOrchestrationSubject/schema.js +4 -11
  16. package/dist/ArvoOrchestrationSubject/type.d.ts +2 -12
  17. package/dist/ArvoOrchestratorContract/index.d.ts +62 -56
  18. package/dist/ArvoOrchestratorContract/index.js +99 -93
  19. package/dist/ArvoOrchestratorContract/types.d.ts +64 -71
  20. package/dist/index.d.ts +14 -18
  21. package/dist/index.js +12 -14
  22. package/dist/schema.d.ts +1 -0
  23. package/dist/schema.js +6 -1
  24. package/dist/types.d.ts +107 -81
  25. package/dist/utils.d.ts +21 -0
  26. package/dist/utils.js +33 -0
  27. package/package.json +1 -1
  28. package/dist/ArvoContractLibrary/helpers.d.ts +0 -10
  29. package/dist/ArvoContractLibrary/helpers.js +0 -22
  30. package/dist/ArvoContractLibrary/index.d.ts +0 -61
  31. package/dist/ArvoContractLibrary/index.js +0 -87
  32. package/dist/ArvoOrchestratorContract/helpers.d.ts +0 -67
  33. package/dist/ArvoOrchestratorContract/helpers.js +0 -101
package/dist/types.d.ts CHANGED
@@ -2,18 +2,61 @@ import { z } from 'zod';
2
2
  import ArvoContract from './ArvoContract';
3
3
  import ArvoEvent from './ArvoEvent';
4
4
  import { ArvoExtension, OpenTelemetryExtension } from './ArvoEvent/types';
5
- import ArvoOrchestratorContract from './ArvoOrchestratorContract';
5
+ import { ArvoErrorSchema } from './schema';
6
+ /**
7
+ * Represents the version of Arvo components following Semantic Versioning (SemVer).
8
+ *
9
+ * @format MAJOR.MINOR.PATCH where each component is a non-negative integer
10
+ * @restriction Must not contain semicolons (;)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const version: ArvoSemanticVersion = "1.0.0";
15
+ * const preRelease: ArvoSemanticVersion = "0.5.2";
16
+ * const major: ArvoSemanticVersion = "2.0.0";
17
+ * ```
18
+ */
19
+ export type ArvoSemanticVersion = `${number}.${number}.${number}`;
6
20
  /**
7
21
  * A type utility that infers the structure of an ArvoEvent.
8
22
  *
9
- * @template T - The type to infer from, expected to be an ArvoEvent.
23
+ * @template TData - The type of the event payload
24
+ * @template TExtension - Additional extension properties for the event
25
+ * @template TType - The literal type string identifying the event
10
26
  *
11
- * @returns An object type that includes all properties of an ArvoEvent,
12
- * including its data, extensions, and standard CloudEvents properties.
27
+ * @property id - Unique identifier for the event (UUID v4 recommended)
28
+ * @property source - Identifier for the context where the event occurred
29
+ * @property specversion - CloudEvents specification version
30
+ * @property type - Event type identifier
31
+ * @property subject - Event subject in the producer's context
32
+ * @property datacontenttype - MIME type of the event payload
33
+ * @property dataschema - URI reference to the event's JSON schema
34
+ * @property data - The actual event payload
35
+ * @property time - ISO 8601 timestamp of event occurrence
13
36
  *
14
37
  * @example
15
- * type MyEvent = InferArvoEvent<ArvoEvent<{ message: string }, { customField: number }, 'my.event.type'>>;
16
- * // MyEvent will have properties like id, source, data.message, customField, etc.
38
+ * ```typescript
39
+ * type UserCreatedEvent = InferArvoEvent<ArvoEvent<
40
+ * { userId: string; email: string },
41
+ * { region: string },
42
+ * 'user.created'
43
+ * >>;
44
+ *
45
+ * // Results in:
46
+ * // {
47
+ * // id: string;
48
+ * // source: string;
49
+ * // specversion: string;
50
+ * // type: 'user.created';
51
+ * // subject: string;
52
+ * // datacontenttype: string;
53
+ * // dataschema: string | null;
54
+ * // data: { userId: string; email: string };
55
+ * // time: string;
56
+ * // region: string;
57
+ * // // ... plus ArvoExtension & OpenTelemetryExtension properties
58
+ * // }
59
+ * ```
17
60
  */
18
61
  export type InferArvoEvent<T> = T extends ArvoEvent<infer TData, infer TExtension, infer TType> ? {
19
62
  /** Unique identifier of the event */
@@ -35,92 +78,75 @@ export type InferArvoEvent<T> = T extends ArvoEvent<infer TData, infer TExtensio
35
78
  /** Timestamp of when the occurrence happened */
36
79
  time: string;
37
80
  } & ArvoExtension & OpenTelemetryExtension & TExtension : never;
38
- /**
39
- * Helper type to infer the TypeScript type from a Zod schema.
40
- *
41
- * @template T - The Zod schema type to infer from.
42
- *
43
- * @returns The TypeScript type that corresponds to the Zod schema.
44
- *
45
- * @example
46
- * const mySchema = z.object({ name: z.string(), age: z.number() });
47
- * type MyType = InferZodSchema<typeof mySchema>;
48
- * // MyType will be { name: string; age: number; }
49
- */
50
81
  type InferZodSchema<T> = T extends z.ZodTypeAny ? z.infer<T> : never;
51
82
  /**
52
- * A type utility that infers the structure of an ArvoContract.
83
+ * A comprehensive type utility that infers the complete structure of an ArvoContract,
84
+ * including versioned event types, accepted events, and emitted events.
53
85
  *
54
- * @template T - The type to infer from, expected to be an ArvoContract.
86
+ * @template T - The ArvoContract type to infer from
55
87
  *
56
- * @returns An object type that includes the URI, accepted event type, and emitted event types of the contract.
88
+ * @property uri - Unique identifier for the contract
89
+ * @property type - The event type this contract handles
90
+ * @property versions - Version-specific contract definitions
91
+ * @property versions[version].accepts - Events this contract version can handle
92
+ * @property versions[version].emits - Events this contract version can produce
93
+ * @property systemError - System error event definition for this contract
57
94
  *
58
95
  * @example
59
- * const myContract = new ArvoContract('my-uri', 'my-type', z.object({ input: z.string() }), {
60
- * 'output.event': z.object({ result: z.number() })
61
- * });
62
- * type MyContractType = InferArvoContract<typeof myContract>;
63
- * // MyContractType will have properties uri, accepts, and emits
64
- */
65
- export type InferArvoContract<T extends ArvoContract<string, string, z.ZodTypeAny, Record<string, z.ZodTypeAny>>> = T extends ArvoContract<infer TUri, infer TType, infer TAcceptSchema, infer TEmits> ? {
66
- /** The URI of the contract */
67
- uri: TUri;
68
- /** The event type that this contract accepts */
69
- accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TAcceptSchema>, {}, TType>>;
70
- /** The event types that this contract can emit */
71
- emits: {
72
- [K in keyof TEmits]: InferArvoEvent<ArvoEvent<InferZodSchema<TEmits[K]>, {}, K & string>>;
73
- };
74
- /** The system error event type for this contract */
75
- systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
76
- /** Union type of all emittable events, including regular events and system error */
77
- emittableEvents: ({
78
- [K in keyof TEmits]: InferArvoEvent<ArvoEvent<InferZodSchema<TEmits[K]>, {}, K & string>>;
79
- } & {
80
- [K in `sys.${TType}.error`]: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
81
- })[keyof TEmits | `sys.${TType}.error`];
82
- } : never;
83
- /**
84
- * A type utility that infers the structure of an ArvoOrchestratorContract.
85
- *
86
- * @template T - The type to infer from, expected to be an ArvoOrchestratorContract.
96
+ * ```typescript
97
+ * const userContract = new ArvoContract(
98
+ * 'user-service',
99
+ * 'user.operation',
100
+ * {
101
+ * '1.0.0': {
102
+ * accepts: z.object({ userId: z.string() }),
103
+ * emits: {
104
+ * 'user.created': z.object({ userId: z.string(), timestamp: z.string() }),
105
+ * 'user.failed': z.object({ error: z.string() })
106
+ * }
107
+ * }
108
+ * }
109
+ * );
87
110
  *
88
- * @returns An object type that includes the URI, accepted event type (init),
89
- * emitted event type (complete), system error event type, and other properties
90
- * of the orchestrator contract.
111
+ * type UserContractType = InferArvoContract<typeof userContract>;
112
+ * // Results in:
113
+ * // {
114
+ * // uri: 'user-service';
115
+ * // type: 'user.operation';
116
+ * // versions: {
117
+ * // '1.0.0': {
118
+ * // accepts: { ... inferred input event type ... };
119
+ * // emits: {
120
+ * // 'user.created': { ... inferred output event type ... };
121
+ * // 'user.failed': { ... inferred error event type ... };
122
+ * // }
123
+ * // }
124
+ * // };
125
+ * // systemError: { ... inferred system error event type ... };
126
+ * // }
127
+ * ```
91
128
  *
92
- * @example
93
- * const myOrchestratorContract = new ArvoOrchestratorContract({
94
- * uri: 'my-orchestrator',
95
- * init: { type: 'init', schema: z.object({ input: z.string() }) },
96
- * complete: { type: 'complete', schema: z.object({ result: z.number() }) }
97
- * });
98
- * type MyOrchestratorContractType = InferArvoOrchestratorContract<typeof myOrchestratorContract>;
99
- * // MyOrchestratorContractType will have properties uri, accepts, emits, systemError, etc.
129
+ * @remarks
130
+ * - All version keys must be valid {@link ArvoSemanticVersion} strings
131
+ * - The contract must define at least one version
132
+ * - Each version must specify both accepted and emitted event schemas
133
+ * - System error handling is automatically included for all contracts
100
134
  */
101
- export type InferArvoOrchestratorContract<T extends ArvoOrchestratorContract<string, string, z.ZodTypeAny, string, z.ZodTypeAny>> = T extends ArvoOrchestratorContract<infer TUri, infer TInitType, infer TInit, infer TCompleteType, infer TComplete> ? {
102
- /** The URI of the orchestrator contract */
135
+ export type InferArvoContract<T extends ArvoContract<string, string, Record<ArvoSemanticVersion, {
136
+ accepts: z.ZodTypeAny;
137
+ emits: Record<string, z.ZodTypeAny>;
138
+ }>>> = T extends ArvoContract<infer TUri, infer TType, infer TVersion> ? {
103
139
  uri: TUri;
104
- /** The event type that this orchestrator contract accepts to initiate the process */
105
- accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TInit>, {}, TInitType>>;
106
- /** The event type that this orchestrator contract emits upon completion */
107
- emits: {
108
- [K in TCompleteType]: InferArvoEvent<ArvoEvent<InferZodSchema<TComplete>, {}, K>>;
140
+ type: TType;
141
+ versions: {
142
+ [V in ArvoSemanticVersion & keyof TVersion]: {
143
+ accepts: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion[V]['accepts']>, {}, TType>>;
144
+ emits: {
145
+ [K in keyof TVersion[V]['emits']]: InferArvoEvent<ArvoEvent<InferZodSchema<TVersion[V]['emits'][K]>, {}, K & string>>;
146
+ };
147
+ };
109
148
  };
110
- /** The system error event type for this orchestrator contract */
111
149
  systemError: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
112
- /**
113
- * Union type of all emittable events, including the completion event and system error.
114
- * This can be used to represent all possible outcomes of the orchestration process.
115
- */
116
- emittableEvents: ({
117
- [K in TCompleteType]: InferArvoEvent<ArvoEvent<InferZodSchema<TComplete>, {}, K>>;
118
- } & {
119
- [K in `sys.${TInitType}.error`]: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
120
- })[TCompleteType | `sys.${TInitType}.error`];
121
- /** The initial event type and schema that starts the orchestration process */
122
- init: InferArvoEvent<ArvoEvent<InferZodSchema<TInit>, {}, TInitType>>;
123
- /** The completion event type and schema that signifies the end of the orchestration process */
124
- complete: InferArvoEvent<ArvoEvent<InferZodSchema<TComplete>, {}, TCompleteType>>;
125
150
  } : never;
151
+ export type ArvoErrorType = z.infer<typeof ArvoErrorSchema>;
126
152
  export {};
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ArvoSemanticVersion } from './types';
1
2
  /**
2
3
  * Cleans a string by removing leading/trailing whitespace from each line,
3
4
  * removing empty lines, and joining the remaining lines with newline characters.
@@ -48,3 +49,23 @@ export declare const validateURI: (value: string) => boolean;
48
49
  * createTimestamp(-5);
49
50
  */
50
51
  export declare const createTimestamp: (offsetHours?: number) => string;
52
+ /**
53
+ * Parse semantic version string into its numeric components
54
+ * @param version Semantic version string (e.g. "1.2.3")
55
+ * @returns Object containing major, minor, and patch numbers
56
+ */
57
+ interface VersionComponents {
58
+ major: number;
59
+ minor: number;
60
+ patch: number;
61
+ }
62
+ export declare function parseSemanticVersion(version: ArvoSemanticVersion): VersionComponents;
63
+ /**
64
+ * Compares two semantic versions according to semver rules
65
+ * Returns:
66
+ * - Positive number if version1 > version2
67
+ * - Negative number if version1 < version2
68
+ * - 0 if version1 === version2
69
+ */
70
+ export declare function compareSemanticVersions(version1: ArvoSemanticVersion, version2: ArvoSemanticVersion): number;
71
+ export {};
package/dist/utils.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTimestamp = exports.validateURI = void 0;
4
4
  exports.cleanString = cleanString;
5
+ exports.parseSemanticVersion = parseSemanticVersion;
6
+ exports.compareSemanticVersions = compareSemanticVersions;
5
7
  /**
6
8
  * Cleans a string by removing leading/trailing whitespace from each line,
7
9
  * removing empty lines, and joining the remaining lines with newline characters.
@@ -77,3 +79,34 @@ var createTimestamp = function (offsetHours) {
77
79
  : "-".concat(String(Math.abs(offsetHours)).padStart(2, '0'), ":00"));
78
80
  };
79
81
  exports.createTimestamp = createTimestamp;
82
+ function parseSemanticVersion(version) {
83
+ var _a = version.split('.').map(function (part) {
84
+ var num = parseInt(part, 10);
85
+ if (isNaN(num)) {
86
+ throw new Error("Invalid version number in ".concat(version));
87
+ }
88
+ return num;
89
+ }), major = _a[0], minor = _a[1], patch = _a[2];
90
+ if (major === undefined || minor === undefined || patch === undefined) {
91
+ throw new Error("Invalid semantic version format: ".concat(version));
92
+ }
93
+ return { major: major, minor: minor, patch: patch };
94
+ }
95
+ /**
96
+ * Compares two semantic versions according to semver rules
97
+ * Returns:
98
+ * - Positive number if version1 > version2
99
+ * - Negative number if version1 < version2
100
+ * - 0 if version1 === version2
101
+ */
102
+ function compareSemanticVersions(version1, version2) {
103
+ var v1 = parseSemanticVersion(version1);
104
+ var v2 = parseSemanticVersion(version2);
105
+ if (v1.major !== v2.major) {
106
+ return v1.major - v2.major;
107
+ }
108
+ if (v1.minor !== v2.minor) {
109
+ return v1.minor - v2.minor;
110
+ }
111
+ return v1.patch - v2.patch;
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.2.2",
3
+ "version": "2.0.1",
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,10 +0,0 @@
1
- import ArvoContractLibrary from '.';
2
- import ArvoContract from '../ArvoContract';
3
- /**
4
- * Creates a new ArvoContractLibrary instance with the given ArvoContract instances.
5
- *
6
- * @template T - The type of ArvoContract to be stored in the library.
7
- * @param {...T[]} args - One or more ArvoContract instances to initialize the library.
8
- * @returns {ArvoContractLibrary<T>} A new ArvoContractLibrary instance containing the provided contracts.
9
- */
10
- export declare const createArvoContractLibrary: <T extends ArvoContract>(...args: T[]) => ArvoContractLibrary<T>;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createArvoContractLibrary = void 0;
7
- var _1 = __importDefault(require("."));
8
- /**
9
- * Creates a new ArvoContractLibrary instance with the given ArvoContract instances.
10
- *
11
- * @template T - The type of ArvoContract to be stored in the library.
12
- * @param {...T[]} args - One or more ArvoContract instances to initialize the library.
13
- * @returns {ArvoContractLibrary<T>} A new ArvoContractLibrary instance containing the provided contracts.
14
- */
15
- var createArvoContractLibrary = function () {
16
- var args = [];
17
- for (var _i = 0; _i < arguments.length; _i++) {
18
- args[_i] = arguments[_i];
19
- }
20
- return new _1.default(args);
21
- };
22
- exports.createArvoContractLibrary = createArvoContractLibrary;
@@ -1,61 +0,0 @@
1
- import ArvoContract from '../ArvoContract';
2
- /**
3
- * Extracts the URI type from a given ArvoContract type.
4
- * @template T - The ArvoContract type to extract from.
5
- */
6
- type ExtractContractUri<T> = T extends {
7
- uri: infer U;
8
- } ? U : never;
9
- /**
10
- * A library class for managing and accessing ArvoContract instances.
11
- * @template T - The type of ArvoContract stored in the library.
12
- */
13
- export default class ArvoContractLibrary<T extends ArvoContract> {
14
- /**
15
- * The array of ArvoContract instances stored in the library.
16
- * @private
17
- * @readonly
18
- */
19
- private readonly _contracts;
20
- /**
21
- * Creates an instance of ArvoContractLibrary.
22
- * @param {T[]} contracts - An array of ArvoContract instances to initialize the library.
23
- * @throws An error in case the URI are duplicated
24
- */
25
- constructor(contracts: T[]);
26
- /**
27
- * Returns a readonly array of all ArvoContract instances in the library.
28
- * @returns {Array<T>} A readonly array of ArvoContract instances.
29
- */
30
- list(): Array<T>;
31
- /**
32
- * Retrieves an ArvoContract instance by its URI.
33
- * @template U - The type of the URI to search for.
34
- * @param {U} uri - The URI of the contract to retrieve.
35
- * @returns {Extract<T, { uri: U }>} A readonly ArvoContract instance matching the given URI.
36
- * @throws {Error} If no contract with the given URI is found in the library.
37
- */
38
- get<U extends ExtractContractUri<T>>(uri: U): Extract<T, {
39
- uri: U;
40
- }>;
41
- /**
42
- * Get an object where keys are contract URIs and values are readonly contract instances.
43
- */
44
- get contracts(): {
45
- [K in ExtractContractUri<T>]: Extract<T, {
46
- uri: K;
47
- }>;
48
- };
49
- /**
50
- * Checks if the library contains a contract with the given URI.
51
- * @param {string} uri - The URI to check for.
52
- * @returns {boolean} True if a contract with the given URI exists in the library, false otherwise.
53
- */
54
- has(uri: string): boolean;
55
- /**
56
- * Returns the number of contracts in the library.
57
- * @returns {number} The number of contracts in the library.
58
- */
59
- get size(): number;
60
- }
61
- export {};
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- /**
13
- * A library class for managing and accessing ArvoContract instances.
14
- * @template T - The type of ArvoContract stored in the library.
15
- */
16
- var ArvoContractLibrary = /** @class */ (function () {
17
- /**
18
- * Creates an instance of ArvoContractLibrary.
19
- * @param {T[]} contracts - An array of ArvoContract instances to initialize the library.
20
- * @throws An error in case the URI are duplicated
21
- */
22
- function ArvoContractLibrary(contracts) {
23
- var uriSet = new Set();
24
- contracts.forEach(function (contract) {
25
- if (uriSet.has(contract.uri)) {
26
- throw new Error("Duplicate contract URI found: ".concat(contract.uri));
27
- }
28
- uriSet.add(contract.uri);
29
- });
30
- this._contracts = __spreadArray([], contracts, true);
31
- }
32
- /**
33
- * Returns a readonly array of all ArvoContract instances in the library.
34
- * @returns {Array<T>} A readonly array of ArvoContract instances.
35
- */
36
- ArvoContractLibrary.prototype.list = function () {
37
- return Object.freeze(__spreadArray([], this._contracts, true));
38
- };
39
- /**
40
- * Retrieves an ArvoContract instance by its URI.
41
- * @template U - The type of the URI to search for.
42
- * @param {U} uri - The URI of the contract to retrieve.
43
- * @returns {Extract<T, { uri: U }>} A readonly ArvoContract instance matching the given URI.
44
- * @throws {Error} If no contract with the given URI is found in the library.
45
- */
46
- ArvoContractLibrary.prototype.get = function (uri) {
47
- var contract = this._contracts.find(function (item) { return item.uri === uri; });
48
- if (!contract) {
49
- throw new Error("ArvoContract with URI \"".concat(uri, "\" not found in the library"));
50
- }
51
- return Object.freeze(contract);
52
- };
53
- Object.defineProperty(ArvoContractLibrary.prototype, "contracts", {
54
- /**
55
- * Get an object where keys are contract URIs and values are readonly contract instances.
56
- */
57
- get: function () {
58
- return Object.freeze(Object.assign.apply(Object, __spreadArray([{}], this._contracts.map(function (item) {
59
- var _a;
60
- return (_a = {}, _a[item.uri] = Object.freeze(item), _a);
61
- }), false)));
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- /**
67
- * Checks if the library contains a contract with the given URI.
68
- * @param {string} uri - The URI to check for.
69
- * @returns {boolean} True if a contract with the given URI exists in the library, false otherwise.
70
- */
71
- ArvoContractLibrary.prototype.has = function (uri) {
72
- return this._contracts.some(function (contract) { return contract.uri === uri; });
73
- };
74
- Object.defineProperty(ArvoContractLibrary.prototype, "size", {
75
- /**
76
- * Returns the number of contracts in the library.
77
- * @returns {number} The number of contracts in the library.
78
- */
79
- get: function () {
80
- return this._contracts.length;
81
- },
82
- enumerable: false,
83
- configurable: true
84
- });
85
- return ArvoContractLibrary;
86
- }());
87
- exports.default = ArvoContractLibrary;
@@ -1,67 +0,0 @@
1
- import { z } from 'zod';
2
- import { ICreateArvoOrchestratorContract } from './types';
3
- import ArvoOrchestratorContract from '.';
4
- /**
5
- * Creates an ArvoOrchestratorContract with specified parameters.
6
- *
7
- * The ArvoOrchestratorContract is a specialized contract class designed to manage the lifecycle
8
- * of orchestration processes within the Arvo framework. It extends the base ArvoContract class
9
- * to provide specific functionality for orchestration scenarios.
10
- *
11
- * Key features:
12
- * 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
13
- * The init schema is automatically intersected with OrchestrationInitEventBaseSchema.
14
- * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
15
- * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
16
- * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
17
- *
18
- * Base Schema:
19
- * The OrchestrationInitEventBaseSchema is automatically intersected with the user-provided init schema.
20
- * This base schema includes essential fields for orchestration, such as:
21
- * - parentSubject$$: Identifies the subject of the parent process or event in the ArvoEvent system.
22
- *
23
- * This contract serves as a crucial component in maintaining consistency and type safety
24
- * throughout the orchestration process, from initiation to completion.
25
- *
26
- * @param param - The configuration object for creating the contract.
27
- * @param param.uri - The URI for the contract.
28
- * @param param.name - The name of the contract (must be lowercase alphanumeric with dots).
29
- * @param param.schema - The schema object containing init and complete Zod schemas.
30
- * @param param.schema.init - The Zod schema for initialization (will be intersected with OrchestrationInitEventBaseSchema).
31
- * @param param.schema.complete - The Zod schema for completion.
32
- *
33
- * @throws {Error} Throws an error if the name is not lowercase alphanumeric with dots.
34
- *
35
- * @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
36
- *
37
- * @example
38
- * ```typescript
39
- * import { createArvoOrchestratorContract } from 'arvo-core'
40
- * import { z } from 'zod'
41
- *
42
- * const contract = createArvoOrchestratorContract({
43
- * uri: '#/example/contract',
44
- * name: 'rag.orchestrator',
45
- * schema: {
46
- * init: z.object({
47
- * request: z.string(),
48
- * vectorStore: z.string(),
49
- * llm: z.string()
50
- * }),
51
- * complete: z.object({
52
- * response: z.string()
53
- * })
54
- * }
55
- * })
56
- * ```
57
- *
58
- * In this example, the actual init schema will be an intersection of the provided schema
59
- * and the OrchestrationInitEventBaseSchema, ensuring all necessary fields are included.
60
- */
61
- export declare const createArvoOrchestratorContract: <TUri extends string, TName extends string, TInit extends z.AnyZodObject, TComplete extends z.AnyZodObject>(param: ICreateArvoOrchestratorContract<TUri, TName, TInit, TComplete>) => ArvoOrchestratorContract<TUri, `arvo.orc.${TName}`, z.ZodObject<z.objectUtil.extendShape<{
62
- parentSubject$$: z.ZodNullable<z.ZodString>;
63
- }, TInit["shape"]>, TInit["_def"]["unknownKeys"], TInit["_def"]["catchall"], z.objectOutputType<z.objectUtil.extendShape<{
64
- parentSubject$$: z.ZodNullable<z.ZodString>;
65
- }, TInit["shape"]>, TInit["_def"]["catchall"], TInit["_def"]["unknownKeys"]>, z.objectInputType<z.objectUtil.extendShape<{
66
- parentSubject$$: z.ZodNullable<z.ZodString>;
67
- }, TInit["shape"]>, TInit["_def"]["catchall"], TInit["_def"]["unknownKeys"]>>, `arvo.orc.${TName}.done`, TComplete>;
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createArvoOrchestratorContract = void 0;
7
- var _1 = __importDefault(require("."));
8
- var typegen_1 = require("./typegen");
9
- var schema_1 = require("./schema");
10
- /**
11
- * Validates if a string contains only uppercase or lowercase alphanumeric characters.
12
- *
13
- * This function checks if the input string consists solely of:
14
- * - Lowercase letters (a-z)
15
- * - Numbers (0-9)
16
- * - Dot (.)
17
- *
18
- * It does not allow any special characters, spaces, or other non-alphanumeric characters.
19
- *
20
- * @param input - The string to be validated.
21
- * @returns True if the string contains only alphanumeric characters, false otherwise.
22
- */
23
- function isLowerAlphanumeric(input) {
24
- var alphanumericRegex = /^[a-z0-9.]+$/;
25
- return alphanumericRegex.test(input);
26
- }
27
- /**
28
- * Creates an ArvoOrchestratorContract with specified parameters.
29
- *
30
- * The ArvoOrchestratorContract is a specialized contract class designed to manage the lifecycle
31
- * of orchestration processes within the Arvo framework. It extends the base ArvoContract class
32
- * to provide specific functionality for orchestration scenarios.
33
- *
34
- * Key features:
35
- * 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
36
- * The init schema is automatically intersected with OrchestrationInitEventBaseSchema.
37
- * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
38
- * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
39
- * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
40
- *
41
- * Base Schema:
42
- * The OrchestrationInitEventBaseSchema is automatically intersected with the user-provided init schema.
43
- * This base schema includes essential fields for orchestration, such as:
44
- * - parentSubject$$: Identifies the subject of the parent process or event in the ArvoEvent system.
45
- *
46
- * This contract serves as a crucial component in maintaining consistency and type safety
47
- * throughout the orchestration process, from initiation to completion.
48
- *
49
- * @param param - The configuration object for creating the contract.
50
- * @param param.uri - The URI for the contract.
51
- * @param param.name - The name of the contract (must be lowercase alphanumeric with dots).
52
- * @param param.schema - The schema object containing init and complete Zod schemas.
53
- * @param param.schema.init - The Zod schema for initialization (will be intersected with OrchestrationInitEventBaseSchema).
54
- * @param param.schema.complete - The Zod schema for completion.
55
- *
56
- * @throws {Error} Throws an error if the name is not lowercase alphanumeric with dots.
57
- *
58
- * @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
59
- *
60
- * @example
61
- * ```typescript
62
- * import { createArvoOrchestratorContract } from 'arvo-core'
63
- * import { z } from 'zod'
64
- *
65
- * const contract = createArvoOrchestratorContract({
66
- * uri: '#/example/contract',
67
- * name: 'rag.orchestrator',
68
- * schema: {
69
- * init: z.object({
70
- * request: z.string(),
71
- * vectorStore: z.string(),
72
- * llm: z.string()
73
- * }),
74
- * complete: z.object({
75
- * response: z.string()
76
- * })
77
- * }
78
- * })
79
- * ```
80
- *
81
- * In this example, the actual init schema will be an intersection of the provided schema
82
- * and the OrchestrationInitEventBaseSchema, ensuring all necessary fields are included.
83
- */
84
- var createArvoOrchestratorContract = function (param) {
85
- if (!isLowerAlphanumeric(param.name)) {
86
- throw new Error("Invalid 'name' = '".concat(param.name, "'. The 'name' must only contain alphanumeric characters. e.g. test.orchestrator"));
87
- }
88
- var mergedSchema = schema_1.OrchestrationInitEventBaseSchema.merge(param.schema.init);
89
- return new _1.default({
90
- uri: param.uri,
91
- init: {
92
- type: typegen_1.ArvoOrchestratorEventTypeGen.init(param.name),
93
- schema: mergedSchema,
94
- },
95
- complete: {
96
- type: typegen_1.ArvoOrchestratorEventTypeGen.complete(param.name),
97
- schema: param.schema.complete,
98
- },
99
- });
100
- };
101
- exports.createArvoOrchestratorContract = createArvoOrchestratorContract;