Class ArvoContract<TUri, TType, TVersions, TMetaData>

Represents a contract with defined input and output schemas for event-driven architectures. The ArvoContract class provides type-safe validation and versioning capabilities for event handling, ensuring consistency in message passing between different parts of the system.

const contract = createArvoContract({
uri: '#/my/service/data',
type: 'com.process.data',
description: 'An example contract',
metadata: {
visibility: "public"
}
versions: {
'1.0.0': {
accepts: z.object({ data: z.string() }),
emits: {
'data.processed': z.object({ result: z.string() })
}
},
'2.0.0': {
accepts: z.object({ data: z.number() }),
emits: {
'data.processed': z.object({ result: z.number() })
}
}
}
});

Type Parameters

  • TUri extends string = string
  • TType extends string = string
  • TVersions extends Record<ArvoSemanticVersion, {
        accepts: z.ZodTypeAny;
        emits: Record<string, z.ZodTypeAny>;
    }> = Record<ArvoSemanticVersion, {
        accepts: z.ZodTypeAny;
        emits: Record<string, z.ZodTypeAny>;
    }>
  • TMetaData extends Record<string, any> = Record<string, any>

Constructors

  • Creates a new ArvoContract instance with validated parameters.

    Type Parameters

    • TUri extends string = string
    • TType extends string = string
    • TVersions extends Record<`${number}.${number}.${number}`, {
          accepts: ZodTypeAny;
          emits: Record<string, ZodTypeAny>;
      }> = Record<`${number}.${number}.${number}`, {
          accepts: ZodTypeAny;
          emits: Record<string, ZodTypeAny>;
      }>
    • TMetaData extends Record<string, any> = Record<string, any>

    Parameters

    Returns ArvoContract<TUri, TType, TVersions, TMetaData>

    When URI format is invalid

    When event type format is invalid

    When version string is not valid semantic version

    When version is a reserved wildcard version

    When emit type format is invalid

    When no versions are provided

    When domain does not have follow the condition Domain must contain only lowercase letters, numbers, and dots

Properties

_description: null | string
_domain: null | string
_metadata: TMetaData
_type: TType
_uri: TUri
_versions: TVersions

Accessors

  • get systemError(): ArvoContractRecord<`sys.${TType}.error`, ZodObject<{
        errorMessage: ZodString;
        errorName: ZodString;
        errorStack: ZodNullable<ZodString>;
    }, "strip", ZodTypeAny, {
        errorMessage: string;
        errorName: string;
        errorStack: null | string;
    }, {
        errorMessage: string;
        errorName: string;
        errorStack: null | string;
    }>>
  • Gets the system error event specification for this contract. System errors follow a standardized format to handle exceptional conditions and failures in a consistent way across all contracts.

    The error schema includes:

    • errorName: The name/type of the error
    • errorMessage: A descriptive message about what went wrong
    • errorStack: Optional stack trace information (null if not available)

    System errors are special events that:

    • Are automatically prefixed with 'sys.' and suffixed with '.error'
    • Use a standardized schema across all contracts
    • Can capture error details, messages, and stack traces
    • Are version-independent (work the same across all contract versions)

    Returns ArvoContractRecord<`sys.${TType}.error`, ZodObject<{
        errorMessage: ZodString;
        errorName: ZodString;
        errorStack: ZodNullable<ZodString>;
    }, "strip", ZodTypeAny, {
        errorMessage: string;
        errorName: string;
        errorStack: null | string;
    }, {
        errorMessage: string;
        errorName: string;
        errorStack: null | string;
    }>>

Methods

  • Retrieves version numbers in sorted order based on semantic versioning rules.

    Parameters

    • ordering: "ASC" | "DESC"

    Returns `${number}.${number}.${number}`[]

    Array of semantic versions sorted according to specified ordering