arvo-core
    Preparing search index...

    Class ArvoEventFactory<TContract>

    Factory class for creating and validating events based on a versioned Arvo contract. Handles event creation, validation, and OpenTelemetry integration for a specific contract version.

    const contract = createArvoContract({
    uri: 'example/api',
    type: 'user.create',
    versions: { '1.0.0': { ... } }
    });

    const factory = createArvoEventFactory(contract.version('1.0.0'));

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    _name: string = 'EventFactory'
    contract: TContract

    Methods

    • Creates and validates an event matching the contract's accept specification.

      Type Parameters

      • TExtension extends Record<string, any>

      Parameters

      • event: Omit<
            CreateArvoEvent<
                input<TContract["accepts"]["schema"]>,
                TContract["accepts"]["type"],
            >,
            "type" | "subject" | "datacontenttype" | "dataschema" | "domain",
        > & { domain?: string | null; subject?: string }

        The event configuration object

      • Optionalextensions: TExtension

        Optional additional properties for the event

      Returns ArvoEvent<
          TypeOf<TContract["accepts"]["schema"]>,
          TExtension,
          TContract["accepts"]["type"],
      >

      A validated ArvoEvent matching the contract's accept specification

      If validation fails or OpenTelemetry operations fail

      const event = factory.accepts({
      source: 'api/users',
      data: { name: 'John', email: 'john@example.com' }
      });
    • Creates and validates an event matching one of the contract's emit specifications.

      Type Parameters

      • U extends string
      • TExtension extends Record<string, any>

      Parameters

      • event: Omit<
            CreateArvoEvent<input<TContract["emits"][U]>, U>,
            "subject" | "datacontenttype" | "dataschema" | "domain",
        > & { domain?: string | null; subject?: string }

        The event configuration object

      • Optionalextensions: TExtension

        Optional additional properties for the event

      Returns ArvoEvent<TypeOf<TContract["emits"][U]>, TExtension, U>

      A validated ArvoEvent matching the specified emit type

      If validation fails, emit type doesn't exist, or OpenTelemetry operations fail

      const event = factory.emits({
      type: 'user.created',
      source: 'api/users',
      data: { id: '123', timestamp: new Date() }
      });
    • Creates a system error event for error reporting and handling.

      Type Parameters

      • TExtension extends Record<string, any>

      Parameters

      • event: Omit<
            CreateArvoEvent<any, any>,
            "type" | "subject" | "datacontenttype" | "dataschema" | "domain" | "data",
        > & { domain?: string | null; error: Error; subject?: string }

        The error event configuration

        • error

          The Error instance to convert to an event

        • Optionaldomain?: string | null
        • error: Error

          The Error instance to convert to an event

        • Optionalsubject?: string
      • Optionalextensions: TExtension

        Optional additional properties for the event

      Returns ArvoEvent<
          { errorMessage: string; errorName: string; errorStack: string
          | null },
          TExtension,
          TContract["systemError"]["type"],
      >

      A system error ArvoEvent

      If event creation or OpenTelemetry operations fail

      const errorEvent = factory.systemError({
      error: new Error('Validation failed'),
      source: 'api/validation'
      });