Spectre.Event.Envelope (Spectre v0.3.0)

Copy Markdown View Source

Portable event envelope whose owner is fixed at Instance admission time.

Origins are evidence; they never select the Definition that consumes an event. A continuation owns replies, policy answers and operational progress. Events without a continuation are owned by the active Definition after the admission and schema-compatibility checks have succeeded.

Summary

Functions

Applies the sequencer-owned admission fields to a pending envelope.

Returns true only after the Instance sequencer admitted or quarantined the event.

Returns the event classes understood by this release.

Decodes and validates canonical Event Envelope bytes.

Encodes an envelope into canonical portable bytes.

Restores and verifies an envelope from decoded canonical data.

Returns a digest of fields supplied before Instance admission.

Builds and validates a pending or admitted event envelope.

Builds an envelope or raises with its stable validation reason.

Returns the Event Envelope schema version.

Returns portable canonical data.

Types

continuation_ref()

@type continuation_ref() :: Spectre.Run.Ref.t() | Spectre.Operation.Ref.t() | nil

event_class()

@type event_class() ::
  :input
  | :reply
  | :policy_answer
  | :flow_progress
  | :flow_completion
  | :work_progress
  | :work_completion
  | :vigil_progress
  | :vigil_completion
  | :global

status()

@type status() :: :pending | :admitted | :quarantined

t()

@type t() :: %Spectre.Event.Envelope{
  admission_receipt: String.t() | nil,
  admission_revision: pos_integer() | nil,
  admitted_activation_generation: non_neg_integer() | nil,
  admitted_at: non_neg_integer() | nil,
  authenticity: map(),
  authority_epoch: non_neg_integer() | nil,
  causation_id: String.t() | nil,
  class_ref: String.t(),
  continuation_ref: continuation_ref(),
  correlation_id: String.t(),
  emitted_at: non_neg_integer(),
  event_class: event_class(),
  id: String.t(),
  origin_definition_ref: Spectre.Definition.Ref.t() | nil,
  owner_definition_ref: Spectre.Definition.Ref.t() | nil,
  owner_fencing_token: pos_integer() | nil,
  payload: term(),
  payload_schema_ref: String.t(),
  provenance: map(),
  quarantine_reason: term(),
  schema_version: pos_integer(),
  status: status()
}

Functions

admit(envelope, admission)

@spec admit(t(), map() | keyword()) :: {:ok, t()} | {:error, term()}

Applies the sequencer-owned admission fields to a pending envelope.

admitted?(envelope)

@spec admitted?(t()) :: boolean()

Returns true only after the Instance sequencer admitted or quarantined the event.

classes()

@spec classes() :: [event_class()]

Returns the event classes understood by this release.

decode(encoded)

@spec decode(binary()) :: {:ok, t()} | {:error, term()}

Decodes and validates canonical Event Envelope bytes.

encode(envelope)

@spec encode(t()) :: {:ok, binary()} | {:error, term()}

Encodes an envelope into canonical portable bytes.

from_data(data)

@spec from_data(map()) :: {:ok, t()} | {:error, term()}

Restores and verifies an envelope from decoded canonical data.

intent_digest(envelope)

@spec intent_digest(t()) :: String.t()

Returns a digest of fields supplied before Instance admission.

new(envelope)

@spec new(t() | map() | keyword()) :: {:ok, t()} | {:error, term()}

Builds and validates a pending or admitted event envelope.

new!(attrs)

@spec new!(t() | map() | keyword()) :: t()

Builds an envelope or raises with its stable validation reason.

schema_version()

@spec schema_version() :: pos_integer()

Returns the Event Envelope schema version.

to_data(envelope)

@spec to_data(t()) :: map()

Returns portable canonical data.