Class ArvoMachine<TId, TVersion, TSelfContract, TServiceContract, TLogic>

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.

Type Parameters

  • TId extends string
  • TVersion extends ArvoSemanticVersion
  • TSelfContract extends VersionedArvoContract<ArvoOrchestratorContract, TVersion>
  • TServiceContract extends Record<string, VersionedArvoContract<ArvoContract, ArvoSemanticVersion>>
  • TLogic extends AnyActorLogic

Constructors

  • Creates a new ArvoMachine instance.

    Type Parameters

    • TId extends string
    • TVersion extends `${number}.${number}.${number}`
    • TSelfContract extends VersionedArvoContract<ArvoOrchestratorContract, TVersion>
    • TServiceContract extends Record<string, VersionedArvoContract<ArvoContract<string, string, Record<`${number}.${number}.${number}`, {
          accepts: ZodTypeAny;
          emits: Record<string, ZodTypeAny>;
      }>, Record<string, any>>, `${number}.${number}.${number}`>>
    • TLogic extends AnyActorLogic

    Parameters

    • id: TId

      A unique identifier for the machine. This ID must be unique within the scope of an orchestrator and is used for routing and logging.

    • version: TVersion

      The semantic version of the machine. Must follow semver format and match the version specified in the contract.

    • contracts: {
          self: TSelfContract;
          services: TServiceContract;
      }

      Configuration object containing contract definitions

      • self: TSelfContract

        The contract defining this machine's interface and capabilities

      • services: TServiceContract

        Record of contracts for services this machine can interact with

    • logic: TLogic

      The XState actor logic that defines the machine's behavior, including states, transitions, and actions.

    • OptionalrequiresResourceLocking: boolean = true

      Optional flag indicating if the machine needs distributed locks. False when machine has no parallel states and executes sequentially. Defaults to true.

    Returns ArvoMachine<TId, TVersion, TSelfContract, TServiceContract, TLogic>

    When contracts are invalid or incompatible with the specified version

Properties

contracts: {
    self: TSelfContract;
    services: TServiceContract;
}

Configuration object containing contract definitions

id: TId

A unique identifier for the machine. This ID must be unique within the scope of an orchestrator and is used for routing and logging.

logic: TLogic

The XState actor logic that defines the machine's behavior, including states, transitions, and actions.

requiresResourceLocking: boolean = true

Optional flag indicating if the machine needs distributed locks. False when machine has no parallel states and executes sequentially. Defaults to true.

version: TVersion

The semantic version of the machine. Must follow semver format and match the version specified in the contract.

Accessors

Methods

  • Validates an event against the machine's contracts and data schemas. Performs validation for both self-contract events and service contract events.

    Parameters

    • event: ArvoEvent<Record<string, any>, Record<string,
          | null
          | string
          | number
          | boolean>, string>

      The event to validate

    Returns
        | {
            type: "VALID";
        }
        | {
            type: "CONTRACT_UNRESOLVED";
        }
        | {
            error: Error;
            type: "INVALID";
        }
        | {
            error: ZodError<any>;
            type: "INVALID_DATA";
        }

    A validation result object:

    • "VALID" - Event is valid and can be processed
    • "CONTRACT_UNRESOLVED" - No matching contract found for the event
    • "INVALID" - Event dataschema conflict with contract
    • "INVALID_DATA" - Event data conflicts with contract
    const result = machine.validateInput(event);
    if (result.type === "VALID") {
    // Process the event
    } else if (result.type === "INVALID") {
    console.error(result.error);
    } else {
    // Handle unresolved contract
    }

    The validation process includes:

    • Finding a matching contract (self or service)
    • Validating dataschema URI and version if present
    • Validating event data against the contract schema