arvo-event-handler
Version:
A complete set of orthogonal event handler and orchestration primitives for Arvo based applications, featuring declarative state machines (XState), imperative resumables for agentic workflows, contract-based routing, OpenTelemetry observability, and in-me
42 lines (41 loc) • 2.06 kB
TypeScript
import type { Span } from '@opentelemetry/api';
import type { ArvoContract, ArvoEvent, ArvoOrchestratorContract, ArvoSemanticVersion, VersionedArvoContract } from 'arvo-core';
import type { AnyActorLogic } from 'xstate';
import { type EventValidationResult } from '../ArvoOrchestrationUtils/inputValidation';
/**
* Represents an ArvoMachine object that can be consumed by an Arvo orchestrator.
* ArvoMachine encapsulates the logic and metadata required for an Arvo-compatible
* state machine. It combines XState's actor logic with Arvo-specific contracts
* and versioning information.
*
* It is strongly recommended to use `setupArvoMachine(...).createMachine(...)`
* instead of creating this object directly. The setup function provides additional
* type safety and validation that helps prevent runtime errors.
*/
export default class ArvoMachine<TId extends string, TVersion extends ArvoSemanticVersion, TSelfContract extends VersionedArvoContract<ArvoOrchestratorContract, TVersion>, TServiceContract extends Record<string, VersionedArvoContract<ArvoContract, ArvoSemanticVersion>>, TLogic extends AnyActorLogic> {
readonly id: TId;
readonly version: TVersion;
readonly contracts: {
self: TSelfContract;
services: TServiceContract;
};
readonly logic: TLogic;
readonly requiresResourceLocking: boolean;
constructor(id: TId, version: TVersion, contracts: {
self: TSelfContract;
services: TServiceContract;
}, logic: TLogic, requiresResourceLocking?: boolean);
/**
* Gets the event type that this machine accepts, as defined in its contract.
*/
get source(): TSelfContract['accepts']['type'];
/**
* Validates an event against the machine's contracts and data schemas.
* Performs validation for both self-contract events and service contract events.
*
* @param event - The event to validate
*
* See {@link validateInputEvent} for more infromation
*/
validateInput(event: ArvoEvent, span?: Span): EventValidationResult;
}