arvo-core 1.1.6 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -60,3 +60,7 @@
60
60
 
61
61
  - Added support for ArvoEvent http formats and made ArvoEvent extensions more specific
62
62
 
63
+ ## [1.1.8] - 2024-09-26
64
+
65
+ - Added Arvo Orchestrator Contract primitive
66
+
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createArvoContract = void 0;
7
7
  var _1 = __importDefault(require("."));
8
+ var typegen_1 = require("../ArvoOrchestratorContract/typegen");
9
+ var utils_1 = require("../utils");
8
10
  /**
9
11
  * Creates an ArvoContract instance from the given contract specification.
10
12
  *
@@ -32,6 +34,17 @@ var _1 = __importDefault(require("."));
32
34
  * });
33
35
  */
34
36
  var createArvoContract = function (contract) {
37
+ var createErrorMessage = function (source, type) { return (0, utils_1.cleanString)("\n In contract (uri=".concat(contract.uri, "), the '").concat(source, "' event (type=").concat(type, ") must not start \n with '").concat(typegen_1.ArvoOrchestratorEventTypeGen.__prefix, "' becuase this a reserved pattern \n for Arvo orchestrators.\n ")); };
38
+ var validator = function (value) { return value.startsWith(typegen_1.ArvoOrchestratorEventTypeGen.__prefix); };
39
+ if (validator(contract.accepts.type)) {
40
+ throw new Error(createErrorMessage('accepts', contract.accepts.type));
41
+ }
42
+ for (var _i = 0, _a = Object.keys(contract.emits); _i < _a.length; _i++) {
43
+ var item = _a[_i];
44
+ if (validator(item)) {
45
+ throw new Error(createErrorMessage('emits', item));
46
+ }
47
+ }
35
48
  return new _1.default(contract);
36
49
  };
37
50
  exports.createArvoContract = createArvoContract;
@@ -26,9 +26,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
26
26
  * @returns The created ArvoEvent as per the accept record of the contract.
27
27
  * @throws If the event data fails validation against the contract.
28
28
  */
29
- accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TAcceptSchema>, TType>, 'type'> & {
30
- to: string;
31
- }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
29
+ accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TAcceptSchema>, TType>, 'type' | 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TAcceptSchema>, TExtension, TType>;
32
30
  /**
33
31
  * Creates an ArvoEvent as per one of the emits record in the contract.
34
32
  *
@@ -39,9 +37,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
39
37
  * @returns The created ArvoEvent as per one of the emits records of the contract.
40
38
  * @throws If the event data fails validation against the contract.
41
39
  */
42
- emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TEmits[U]>, U> & {
43
- to: string;
44
- }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
40
+ emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.infer<TEmits[U]>, U>, 'datacontenttype' | 'dataschema'>, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
45
41
  /**
46
42
  * Creates a system error ArvoEvent.
47
43
  *
@@ -50,9 +46,8 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
50
46
  * @param [extensions] - Optional extensions to add to the event.
51
47
  * @returns The created system error ArvoEvent.
52
48
  */
53
- systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type'> & {
49
+ systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema'> & {
54
50
  error: Error;
55
- to: string;
56
51
  }, extensions?: TExtension): import("..").ArvoEvent<{
57
52
  errorMessage: string;
58
53
  errorName: string;
@@ -127,8 +127,8 @@ var ArvoEventFactory = /** @class */ (function () {
127
127
  var _a;
128
128
  span.setStatus({ code: api_1.SpanStatusCode.OK });
129
129
  try {
130
- var error = event.error, _events = __rest(event, ["error"]);
131
- return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { type: "sys.".concat(_this.contract.accepts.type, ".error"), data: {
130
+ var error = event.error, _event = __rest(event, ["error"]);
131
+ return (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { type: "sys.".concat(_this.contract.accepts.type, ".error"), data: {
132
132
  errorName: error.name,
133
133
  errorMessage: error.message,
134
134
  errorStack: (_a = error.stack) !== null && _a !== void 0 ? _a : null,
@@ -88,7 +88,7 @@ var ArvoEventHttp = /** @class */ (function () {
88
88
  */
89
89
  ArvoEventHttp.importFromBinary = function (config) {
90
90
  var _a, _b;
91
- this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "", 'application/json');
91
+ this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '', 'application/json');
92
92
  var event = this.extractEventFieldsFromHeaders(config.headers);
93
93
  this.validateRequiredFields(event, true);
94
94
  var extensions = this.extractExtensions(config.headers);
@@ -102,7 +102,7 @@ var ArvoEventHttp = /** @class */ (function () {
102
102
  */
103
103
  ArvoEventHttp.importFromStructured = function (config) {
104
104
  var _a, _b;
105
- this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "", schema_1.ArvoDataContentType);
105
+ this.validateContentType((_b = (_a = config.headers['content-type']) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '', schema_1.ArvoDataContentType);
106
106
  var eventData = config.data;
107
107
  this.validateRequiredFields(eventData, false);
108
108
  return this.createArvoEventFromStructured(eventData);
@@ -124,7 +124,22 @@ var ArvoEventHttp = /** @class */ (function () {
124
124
  * @returns An object with extracted event fields.
125
125
  */
126
126
  ArvoEventHttp.extractEventFieldsFromHeaders = function (headers) {
127
- var eventFields = ['id', 'type', 'accesscontrol', 'executionunits', 'traceparent', 'tracestate', 'datacontenttype', 'specversion', 'time', 'source', 'subject', 'to', 'redirectto', 'dataschema'];
127
+ var eventFields = [
128
+ 'id',
129
+ 'type',
130
+ 'accesscontrol',
131
+ 'executionunits',
132
+ 'traceparent',
133
+ 'tracestate',
134
+ 'datacontenttype',
135
+ 'specversion',
136
+ 'time',
137
+ 'source',
138
+ 'subject',
139
+ 'to',
140
+ 'redirectto',
141
+ 'dataschema',
142
+ ];
128
143
  return Object.fromEntries(eventFields
129
144
  .map(function (field) { return ["ce-".concat(field), headers["ce-".concat(field)]]; })
130
145
  .filter(function (_a) {
@@ -167,7 +182,22 @@ var ArvoEventHttp = /** @class */ (function () {
167
182
  * @returns An object with extracted extension fields.
168
183
  */
169
184
  ArvoEventHttp.extractExtensions = function (headers) {
170
- var eventFields = ['id', 'type', 'accesscontrol', 'executionunits', 'traceparent', 'tracestate', 'datacontenttype', 'specversion', 'time', 'source', 'subject', 'to', 'redirectto', 'dataschema'];
185
+ var eventFields = [
186
+ 'id',
187
+ 'type',
188
+ 'accesscontrol',
189
+ 'executionunits',
190
+ 'traceparent',
191
+ 'tracestate',
192
+ 'datacontenttype',
193
+ 'specversion',
194
+ 'time',
195
+ 'source',
196
+ 'subject',
197
+ 'to',
198
+ 'redirectto',
199
+ 'dataschema',
200
+ ];
171
201
  return Object.fromEntries(Object.entries(headers)
172
202
  .filter(function (_a) {
173
203
  var key = _a[0];
@@ -191,7 +221,9 @@ var ArvoEventHttp = /** @class */ (function () {
191
221
  id: (_a = event.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
192
222
  type: event.type,
193
223
  accesscontrol: (_b = event.accesscontrol) !== null && _b !== void 0 ? _b : null,
194
- executionunits: event.executionunits ? Number(event.executionunits) : null,
224
+ executionunits: event.executionunits
225
+ ? Number(event.executionunits)
226
+ : null,
195
227
  traceparent: (_c = event.traceparent) !== null && _c !== void 0 ? _c : null,
196
228
  tracestate: (_d = event.tracestate) !== null && _d !== void 0 ? _d : null,
197
229
  datacontenttype: (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : schema_1.ArvoDataContentType,
@@ -0,0 +1,31 @@
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
+ * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
14
+ * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
15
+ * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
16
+ *
17
+ * This contract serves as a crucial component in maintaining consistency and type safety
18
+ * throughout the orchestration process, from initiation to completion.
19
+ *
20
+ * @param param - The configuration object for creating the contract.
21
+ * @param param.uri - The URI for the contract.
22
+ * @param param.name - The name of the contract (must be alphanumeric).
23
+ * @param param.schema - The schema object containing init and complete Zod schemas.
24
+ * @param param.schema.init - The Zod schema for initialization.
25
+ * @param param.schema.complete - The Zod schema for completion.
26
+ *
27
+ * @throws {Error} Throws an error if the name is not alphanumeric.
28
+ *
29
+ * @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
30
+ */
31
+ export declare const createArvoOrchestratorContract: <TUri extends string, TName extends string, TInit extends z.ZodTypeAny, TComplete extends z.ZodTypeAny>(param: ICreateArvoOrchestratorContract<TUri, TName, TInit, TComplete>) => ArvoOrchestratorContract<TUri, `arvo.orc.${TName}`, TInit, `arvo.orc.${TName}.done`, TComplete>;
@@ -0,0 +1,69 @@
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
+ /**
10
+ * Validates if a string contains only uppercase or lowercase alphanumeric characters.
11
+ *
12
+ * This function checks if the input string consists solely of:
13
+ * - Lowercase letters (a-z)
14
+ * - Numbers (0-9)
15
+ * - Dot (.)
16
+ *
17
+ * It does not allow any special characters, spaces, or other non-alphanumeric characters.
18
+ *
19
+ * @param input - The string to be validated.
20
+ * @returns True if the string contains only alphanumeric characters, false otherwise.
21
+ */
22
+ function isLowerAlphanumeric(input) {
23
+ var alphanumericRegex = /^[a-z0-9.]+$/;
24
+ return alphanumericRegex.test(input);
25
+ }
26
+ /**
27
+ * Creates an ArvoOrchestratorContract with specified parameters.
28
+ *
29
+ * The ArvoOrchestratorContract is a specialized contract class designed to manage the lifecycle
30
+ * of orchestration processes within the Arvo framework. It extends the base ArvoContract class
31
+ * to provide specific functionality for orchestration scenarios.
32
+ *
33
+ * Key features:
34
+ * 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
35
+ * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
36
+ * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
37
+ * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
38
+ *
39
+ * This contract serves as a crucial component in maintaining consistency and type safety
40
+ * throughout the orchestration process, from initiation to completion.
41
+ *
42
+ * @param param - The configuration object for creating the contract.
43
+ * @param param.uri - The URI for the contract.
44
+ * @param param.name - The name of the contract (must be alphanumeric).
45
+ * @param param.schema - The schema object containing init and complete Zod schemas.
46
+ * @param param.schema.init - The Zod schema for initialization.
47
+ * @param param.schema.complete - The Zod schema for completion.
48
+ *
49
+ * @throws {Error} Throws an error if the name is not alphanumeric.
50
+ *
51
+ * @returns Returns a new ArvoOrchestratorContract instance with the specified parameters.
52
+ */
53
+ var createArvoOrchestratorContract = function (param) {
54
+ if (!isLowerAlphanumeric(param.name)) {
55
+ throw new Error("Invalid 'name' = '".concat(param.name, "'. The 'name' must only contain alphanumeric characters."));
56
+ }
57
+ return new _1.default({
58
+ uri: param.uri,
59
+ init: {
60
+ type: typegen_1.ArvoOrchestratorEventTypeGen.init(param.name),
61
+ schema: param.schema.init,
62
+ },
63
+ complete: {
64
+ type: typegen_1.ArvoOrchestratorEventTypeGen.complete(param.name),
65
+ schema: param.schema.complete,
66
+ }
67
+ });
68
+ };
69
+ exports.createArvoOrchestratorContract = createArvoOrchestratorContract;
@@ -0,0 +1,68 @@
1
+ import { z } from 'zod';
2
+ import ArvoContract from '../ArvoContract';
3
+ import { IArvoOrchestratorContract } from './types';
4
+ /**
5
+ * Defines the contract for the Arvo Orchestrator, specifying accepted events and emitted events.
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
+ * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
14
+ * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
15
+ * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
16
+ *
17
+ * This contract serves as a crucial component in maintaining consistency and type safety
18
+ * throughout the orchestration process, from initiation to completion.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { createArvoOrchestratorContract } from 'arvo-core'
23
+ * import { z } from 'zod'
24
+ *
25
+ * const contract = createArvoOrchestratorContract({
26
+ * uri: '#/example/contract',
27
+ * name: 'rag',
28
+ * schema: {
29
+ * init: z.object({
30
+ * request: z.string()
31
+ * vectorStore: z.string(),
32
+ * llm: z.string()
33
+ * }),
34
+ * complete: z.object({
35
+ * response: z.string()
36
+ * })
37
+ * }
38
+ * })
39
+ * ```
40
+ */
41
+ export default class ArvoOrchestratorContract<TUri extends string = string, TInitType extends string = string, TInit extends z.ZodTypeAny = z.ZodTypeAny, TCompleteType extends string = string, TComplete extends z.ZodTypeAny = z.ZodTypeAny> extends ArvoContract<TUri, TInitType, TInit, {
42
+ [K in TCompleteType]: TComplete;
43
+ }> {
44
+ /**
45
+ * Constructs a new ArvoOrchestratorContract instance.
46
+ *
47
+ * @param param - The configuration object for the contract.
48
+ */
49
+ constructor(param: IArvoOrchestratorContract<TUri, TInitType, TInit, TCompleteType, TComplete>);
50
+ /**
51
+ * Gets the initialization event configuration.
52
+ *
53
+ * @returns An object containing the type and schema for the initialization event.
54
+ */
55
+ get init(): {
56
+ type: TInitType;
57
+ schema: TInit;
58
+ };
59
+ /**
60
+ * Gets the completion event configuration.
61
+ *
62
+ * @returns An object containing the type and schema for the completion event.
63
+ */
64
+ get complete(): {
65
+ type: TCompleteType;
66
+ schema: TComplete;
67
+ };
68
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var ArvoContract_1 = __importDefault(require("../ArvoContract"));
22
+ /**
23
+ * Defines the contract for the Arvo Orchestrator, specifying accepted events and emitted events.
24
+ *
25
+ * The ArvoOrchestratorContract is a specialized contract class designed to manage the lifecycle
26
+ * of orchestration processes within the Arvo framework. It extends the base ArvoContract class
27
+ * to provide specific functionality for orchestration scenarios.
28
+ *
29
+ * Key features:
30
+ * 1. Initialization: Defines the structure and validation for the initial event that starts the orchestration.
31
+ * 2. Completion: Specifies the event type and data emitted when the orchestration process concludes.
32
+ * 3. Type Safety: Utilizes TypeScript generics to ensure type consistency across the contract definition.
33
+ * 4. Runtime Validation: Employs Zod schemas for robust runtime type checking and data validation.
34
+ *
35
+ * This contract serves as a crucial component in maintaining consistency and type safety
36
+ * throughout the orchestration process, from initiation to completion.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { createArvoOrchestratorContract } from 'arvo-core'
41
+ * import { z } from 'zod'
42
+ *
43
+ * const contract = createArvoOrchestratorContract({
44
+ * uri: '#/example/contract',
45
+ * name: 'rag',
46
+ * schema: {
47
+ * init: z.object({
48
+ * request: z.string()
49
+ * vectorStore: z.string(),
50
+ * llm: z.string()
51
+ * }),
52
+ * complete: z.object({
53
+ * response: z.string()
54
+ * })
55
+ * }
56
+ * })
57
+ * ```
58
+ */
59
+ var ArvoOrchestratorContract = /** @class */ (function (_super) {
60
+ __extends(ArvoOrchestratorContract, _super);
61
+ /**
62
+ * Constructs a new ArvoOrchestratorContract instance.
63
+ *
64
+ * @param param - The configuration object for the contract.
65
+ */
66
+ function ArvoOrchestratorContract(param) {
67
+ var _a;
68
+ return _super.call(this, {
69
+ uri: param.uri,
70
+ accepts: param.init,
71
+ // @ts-ignore
72
+ emits: (_a = {},
73
+ _a[param.complete.type] = param.complete.schema,
74
+ _a),
75
+ }) || this;
76
+ }
77
+ Object.defineProperty(ArvoOrchestratorContract.prototype, "init", {
78
+ /**
79
+ * Gets the initialization event configuration.
80
+ *
81
+ * @returns An object containing the type and schema for the initialization event.
82
+ */
83
+ get: function () {
84
+ return this.accepts;
85
+ },
86
+ enumerable: false,
87
+ configurable: true
88
+ });
89
+ Object.defineProperty(ArvoOrchestratorContract.prototype, "complete", {
90
+ /**
91
+ * Gets the completion event configuration.
92
+ *
93
+ * @returns An object containing the type and schema for the completion event.
94
+ */
95
+ get: function () {
96
+ var _a = Object.entries(this.emits)[0], type = _a[0], schema = _a[1];
97
+ return {
98
+ type: type,
99
+ schema: schema,
100
+ };
101
+ },
102
+ enumerable: false,
103
+ configurable: true
104
+ });
105
+ return ArvoOrchestratorContract;
106
+ }(ArvoContract_1.default));
107
+ exports.default = ArvoOrchestratorContract;
@@ -0,0 +1,6 @@
1
+ export declare const ArvoOrchestratorEventTypeGen: {
2
+ __prefix: `arvo.orc`;
3
+ init: <T extends string>(name: T) => `${typeof ArvoOrchestratorEventTypeGen.__prefix}.${T}`;
4
+ complete: <T extends string>(name: T) => `${ReturnType<typeof ArvoOrchestratorEventTypeGen.init<T>>}.done`;
5
+ systemError: <T extends string>(name: T) => `sys.${ReturnType<typeof ArvoOrchestratorEventTypeGen.init<T>>}.error`;
6
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArvoOrchestratorEventTypeGen = void 0;
4
+ exports.ArvoOrchestratorEventTypeGen = {
5
+ __prefix: "arvo.orc",
6
+ init: function (name) { return "".concat(exports.ArvoOrchestratorEventTypeGen.__prefix, ".").concat(name); },
7
+ complete: function (name) { return "".concat(exports.ArvoOrchestratorEventTypeGen.init(name), ".done"); },
8
+ systemError: function (name) { return "sys.".concat(exports.ArvoOrchestratorEventTypeGen.init(name), ".error"); }
9
+ };
@@ -0,0 +1,85 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Represents the configuration interface for an Arvo Orchestrator Contract.
4
+ *
5
+ * This interface defines the structure of the configuration object used to initialize
6
+ * an ArvoOrchestratorContract. It specifies the types and schemas for both the
7
+ * initialization event and the completion event of the orchestration process.
8
+ *
9
+ * @template TUri - The type for the URI string that uniquely identifies the contract.
10
+ * @template TInitType - The literal type for the initialization event type.
11
+ * @template TInit - The Zod schema type for validating the initialization event data.
12
+ * @template TCompleteType - The literal type for the completion event type.
13
+ * @template TComplete - The Zod schema type for validating the completion event data.
14
+ */
15
+ export interface IArvoOrchestratorContract<TUri extends string, TInitType extends string, TInit extends z.ZodTypeAny, TCompleteType extends string, TComplete extends z.ZodTypeAny> {
16
+ /**
17
+ * The unique identifier for the contract.
18
+ */
19
+ uri: TUri;
20
+ /**
21
+ * Configuration for the initialization event.
22
+ */
23
+ init: {
24
+ /**
25
+ * The type identifier for the initialization event.
26
+ */
27
+ type: TInitType;
28
+ /**
29
+ * The Zod schema used to validate the initialization event data.
30
+ */
31
+ schema: TInit;
32
+ };
33
+ /**
34
+ * Configuration for the completion event.
35
+ */
36
+ complete: {
37
+ /**
38
+ * The type identifier for the completion event.
39
+ */
40
+ type: TCompleteType;
41
+ /**
42
+ * The Zod schema used to validate the completion event data.
43
+ */
44
+ schema: TComplete;
45
+ };
46
+ }
47
+ /**
48
+ * Interface for creating an Arvo Orchestrator Contract.
49
+ *
50
+ * This interface defines the structure of the configuration object used to create
51
+ * an ArvoOrchestratorContract. It specifies the URI, name, and schemas for both
52
+ * the initialization and completion events of the orchestration process.
53
+ *
54
+ * @template TUri - The type for the URI string that uniquely identifies the contract.
55
+ * @template TName - The type for the name of the contract.
56
+ * @template TInit - The Zod schema type for validating the initialization event data.
57
+ * @template TComplete - The Zod schema type for validating the completion event data.
58
+ */
59
+ export interface ICreateArvoOrchestratorContract<TUri extends string, TName extends string, TInit extends z.ZodTypeAny, TComplete extends z.ZodTypeAny> {
60
+ /**
61
+ * The unique identifier for the contract.
62
+ * This URI should be used to reference the contract within the system.
63
+ */
64
+ uri: TUri;
65
+ /**
66
+ * The name of the contract.
67
+ * This can be used for display purposes or for easier identification of the contract.
68
+ */
69
+ name: TName;
70
+ /**
71
+ * The schema definitions for the contract events.
72
+ */
73
+ schema: {
74
+ /**
75
+ * The Zod schema used to validate the initialization event data.
76
+ * This schema defines the structure and types of the data required to start the orchestration process.
77
+ */
78
+ init: TInit;
79
+ /**
80
+ * The Zod schema used to validate the completion event data.
81
+ * This schema defines the structure and types of the data emitted when the orchestration process completes.
82
+ */
83
+ complete: TComplete;
84
+ };
85
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -23,7 +23,11 @@ import { ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema } f
23
23
  import { ArvoOrchestrationSubjectContent, ArvoOchestratorVersion } from './ArvoOrchestrationSubject/type';
24
24
  import ArvoEventHttp from './ArvoEventHttp';
25
25
  import { ArvoEventHttpConfig } from './ArvoEventHttp/types';
26
- import { InferArvoContract, InferArvoEvent } from './types';
26
+ import { InferArvoContract, InferArvoEvent, InferArvoOrchestratorContract } from './types';
27
+ import { createArvoOrchestratorContract } from './ArvoOrchestratorContract/helpers';
28
+ import ArvoOrchestratorContract from './ArvoOrchestratorContract';
29
+ import { ICreateArvoOrchestratorContract, IArvoOrchestratorContract } from './ArvoOrchestratorContract/types';
30
+ import { ArvoOrchestratorEventTypeGen } from './ArvoOrchestratorContract/typegen';
27
31
  /**
28
32
  * Collection of Zod schemas for validating various aspects of Arvo events.
29
33
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
@@ -90,4 +94,4 @@ declare const ArvoEventSchemas: {
90
94
  tracestate: string | null;
91
95
  }>;
92
96
  };
93
- export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, };
97
+ export { ArvoEventHttpConfig, ArvoEventHttp, ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOchestratorVersion, InferArvoEvent, InferArvoContract, InferArvoContractType, createArvoOrchestratorContract, ArvoOrchestratorContract, ICreateArvoOrchestratorContract, IArvoOrchestratorContract, InferArvoOrchestratorContract, ArvoOrchestratorEventTypeGen };
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.ArvoOchestratorVersionSchema = exports.ArvoOrchestrationSubjectContentSchema = exports.ArvoOrchestrationSubject = exports.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = exports.ArvoEventHttp = void 0;
6
+ exports.ArvoOrchestratorEventTypeGen = exports.ArvoOrchestratorContract = exports.createArvoOrchestratorContract = exports.ArvoOchestratorVersionSchema = exports.ArvoOrchestrationSubjectContentSchema = exports.ArvoOrchestrationSubject = exports.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = exports.ArvoEventHttp = 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");
@@ -49,6 +49,12 @@ Object.defineProperty(exports, "ArvoOrchestrationSubjectContentSchema", { enumer
49
49
  Object.defineProperty(exports, "ArvoOchestratorVersionSchema", { enumerable: true, get: function () { return schema_3.ArvoOchestratorVersionSchema; } });
50
50
  var ArvoEventHttp_1 = __importDefault(require("./ArvoEventHttp"));
51
51
  exports.ArvoEventHttp = ArvoEventHttp_1.default;
52
+ var helpers_5 = require("./ArvoOrchestratorContract/helpers");
53
+ Object.defineProperty(exports, "createArvoOrchestratorContract", { enumerable: true, get: function () { return helpers_5.createArvoOrchestratorContract; } });
54
+ var ArvoOrchestratorContract_1 = __importDefault(require("./ArvoOrchestratorContract"));
55
+ exports.ArvoOrchestratorContract = ArvoOrchestratorContract_1.default;
56
+ var typegen_1 = require("./ArvoOrchestratorContract/typegen");
57
+ Object.defineProperty(exports, "ArvoOrchestratorEventTypeGen", { enumerable: true, get: function () { return typegen_1.ArvoOrchestratorEventTypeGen; } });
52
58
  /**
53
59
  * Collection of Zod schemas for validating various aspects of Arvo events.
54
60
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ 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
6
  /**
6
7
  * A type utility that infers the structure of an ArvoEvent.
7
8
  *
@@ -79,4 +80,47 @@ export type InferArvoContract<T extends ArvoContract<string, string, z.ZodTypeAn
79
80
  [K in `sys.${TType}.error`]: InferArvoEvent<ArvoEvent<InferZodSchema<T['systemError']['schema']>, {}, T['systemError']['type']>>;
80
81
  })[keyof TEmits | `sys.${TType}.error`];
81
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.
87
+ *
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.
91
+ *
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.
100
+ */
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 */
103
+ 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>>;
109
+ };
110
+ /** The system error event type for this orchestrator contract */
111
+ 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
+ } : never;
82
126
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
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": {