arvo-core
Version:
This core package contains all the core classes and components of the Arvo Event Driven System
66 lines (65 loc) • 2.56 kB
TypeScript
import type { z } from 'zod';
import type { ArvoSemanticVersion } from '../types';
import type { ArvoOrchestratorContract, ICreateArvoOrchestratorContract } from './types';
/**
* Creates an ArvoOrchestratorContract with specified parameters.
*
* The ArvoOrchestratorContract is a specialized contract designed to manage the lifecycle
* of orchestration processes within the Arvo framework. It creates a contract with an init event
* type and a corresponding complete event type.
*
* Key features:
* 1. Type Validation: Ensures the type parameter follows lowercase alphanumeric with dots format
* 2. Event Type Generation: Automatically generates init and complete event types based on the provided type
* 3. Schema Merging: Merges provided init schemas with the OrchestrationInitEventBaseSchema
* 4. Version Support: Handles multiple versions of the contract with their respective schemas
*
* @param contract - Configuration object for the orchestrator contract
*
* @throws {Error} If the type parameter contains invalid characters (must be lowercase alphanumeric with dots)
*
* @returns An ArvoOrchestratorContract instance configured with the specified parameters
*
* @example
* ```typescript
* const contract = createArvoOrchestratorContract({
* uri: '#/orchestrators/data/processor',
* name: 'data.processor',
* versions: {
* '1.0.0': {
* init: z.object({
* data: z.string(),
* options: z.object({
* format: z.string()
* })
* }),
* complete: z.object({
* processedData: z.string(),
* metadata: z.record(z.string())
* })
* },
* '1.1.0': {
* init: z.object({
* data: z.string(),
* options: z.object({
* format: z.string(),
* compression: z.boolean().optional()
* })
* }),
* complete: z.object({
* processedData: z.string(),
* metadata: z.record(z.string()),
* performance: z.object({
* duration: z.number(),
* bytesProcessed: z.number()
* })
* })
* }
* }
* });
* ```
*/
export declare const createArvoOrchestratorContract: <TUri extends string, TName extends string, TVersions extends Record<ArvoSemanticVersion, {
init: z.ZodObject<any, any, any>;
complete: z.ZodObject<any, any, any>;
}>, TMetaData extends Record<string, any>>(contract: ICreateArvoOrchestratorContract<TUri, TName, TVersions, TMetaData>) => ArvoOrchestratorContract<TUri, TName, TVersions, TMetaData>;