Spectre.GAM.Domain.Event (Spectre v0.4.0)

Copy Markdown View Source

Canonical envelope and decoder for facts stored in a Domain ledger.

This module is deliberately smaller than the semantics that consume an event. It owns the wire grammar shared by writers, live projections and the independent auditor: exact keys, event identity bindings and acquisition time. It does not decide whether an event is authorized or whether its transition is valid; those are governed-act semantics.

Keeping the durable grammar here gives both replay paths the same strict boundary while allowing them to fold the decoded event independently.

Summary

Functions

Decodes and validates an event envelope without ledger metadata.

Decodes an Entry payload and binds its trusted ledger metadata.

Encodes a governed Definition revision; publishing data alone does not activate it.

Encodes the causal cancellation of a pending dispatch, not cancellation of an already-attempted effect.

Encodes readiness for a committed world Act; creating this map does not mint a Grant.

Links disposal of the exact causal opening to its disposition Act; the fold verifies the closing route.

Builds the exact plain-map envelope persisted as an Entry payload.

Links a HostProfile revision to its predecessor and governance Act, without proving deployment isolation.

Links a subtractive Mandate successor to its predecessor and governance Act.

Binds revocation to the governance Act's effective time without changing past Acts or observations.

Returns ledger metadata from an event decoded with decode_entry/1.

Encodes the Act's exact reservation movement; the fold verifies the permitted accounting transition.

Encodes return of child allocation; ancestry and available quantity remain fold checks.

Binds a Meter resolution to its cause, open Duty and disposition Act; does not authorize disposal.

Encodes recontainment and its deficit after Evidence contradicts a no-effect Outcome.

Encodes Principal registration under an Act, not authentication or a new Mandate.

Builds a canonical envelope for a typed Domain record.

Encodes a validated Scope opening; parent authority and promise semantics remain governed checks.

Links a Surface successor and its exact predecessor to the governance Act.

Types

t()

@type t() :: %Spectre.GAM.Domain.Event{
  batch_id: String.t() | nil,
  batch_index: non_neg_integer() | nil,
  data: map(),
  identity: String.t(),
  recorded_at: non_neg_integer() | nil,
  revision: pos_integer() | nil,
  type: String.t()
}

Functions

decode(payload)

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

Decodes and validates an event envelope without ledger metadata.

decode_entry(entry)

@spec decode_entry(Spectre.GAM.Ledger.Entry.t()) :: {:ok, t()} | {:error, term()}

Decodes an Entry payload and binds its trusted ledger metadata.

definition_revised(act, definition)

@spec definition_revised(Spectre.GAM.Act.t(), Spectre.GAM.Definition.t()) ::
  {:ok, map()} | {:error, term()}

Encodes a governed Definition revision; publishing data alone does not activate it.

dispatch_cancelled(act, cause, reason)

@spec dispatch_cancelled(
  Spectre.GAM.Act.t(),
  Spectre.GAM.Act.t() | Spectre.GAM.Duty.t() | Spectre.GAM.Mandate.t(),
  atom()
) :: {:ok, map()} | {:error, term()}

Encodes the causal cancellation of a pending dispatch, not cancellation of an already-attempted effect.

dispatch_ready(act)

@spec dispatch_ready(Spectre.GAM.Act.t()) :: map()

Encodes readiness for a committed world Act; creating this map does not mint a Grant.

duty_disposed(disposition_act, cause_key)

@spec duty_disposed(Spectre.GAM.Act.t(), term()) :: {:ok, map()} | {:error, term()}

Links disposal of the exact causal opening to its disposition Act; the fold verifies the closing route.

envelope(type, identity, data)

@spec envelope(String.t(), String.t(), map()) :: map()

Builds the exact plain-map envelope persisted as an Entry payload.

host_profile_revised(act, previous_ref, profile)

@spec host_profile_revised(
  Spectre.GAM.Act.t(),
  String.t(),
  Spectre.GAM.HostProfile.t()
) ::
  {:ok, map()} | {:error, term()}

Links a HostProfile revision to its predecessor and governance Act, without proving deployment isolation.

mandate_restricted(act, predecessor_ref, successor)

@spec mandate_restricted(Spectre.GAM.Act.t(), String.t(), Spectre.GAM.Mandate.t()) ::
  {:ok, map()} | {:error, term()}

Links a subtractive Mandate successor to its predecessor and governance Act.

mandate_revoked(act, mandate_ref)

@spec mandate_revoked(Spectre.GAM.Act.t(), String.t()) ::
  {:ok, map()} | {:error, term()}

Binds revocation to the governance Act's effective time without changing past Acts or observations.

metadata(event)

@spec metadata(t()) ::
  {:ok, Spectre.GAM.Domain.Event.Metadata.t()}
  | {:error, :missing_event_metadata}

Returns ledger metadata from an event decoded with decode_entry/1.

meter(operation, act)

@spec meter(:reserve | :settle | :release | :suspend, Spectre.GAM.Act.t()) ::
  {:ok, map()} | {:error, term()}

Encodes the Act's exact reservation movement; the fold verifies the permitted accounting transition.

meter_devolved(act, child_mandate_ref, amounts)

@spec meter_devolved(Spectre.GAM.Act.t(), String.t(), map()) ::
  {:ok, map()} | {:error, term()}

Encodes return of child allocation; ancestry and available quantity remain fold checks.

meter_duty_resolved(cause_act, disposition_act, duty, operation, amounts)

@spec meter_duty_resolved(
  Spectre.GAM.Act.t(),
  Spectre.GAM.Act.t(),
  Spectre.GAM.Duty.t(),
  :settle | :release,
  map()
) :: {:ok, map()} | {:error, term()}

Binds a Meter resolution to its cause, open Duty and disposition Act; does not authorize disposal.

meter_recontained(act, outcome, recontained, deficits)

@spec meter_recontained(Spectre.GAM.Act.t(), Spectre.GAM.Outcome.t(), map(), map()) ::
  {:ok, map()} | {:error, term()}

Encodes recontainment and its deficit after Evidence contradicts a no-effect Outcome.

principal_registered(act, principal)

@spec principal_registered(Spectre.GAM.Act.t(), Spectre.GAM.Principal.t()) ::
  {:ok, map()} | {:error, term()}

Encodes Principal registration under an Act, not authentication or a new Mandate.

record(kind, record)

@spec record(
  atom(),
  struct()
) :: {:ok, map()} | {:error, term()}

Builds a canonical envelope for a typed Domain record.

scope_opened(opening)

@spec scope_opened(Spectre.GAM.Scope.Opening.t()) :: {:ok, map()} | {:error, term()}

Encodes a validated Scope opening; parent authority and promise semantics remain governed checks.

surface_revised(act, previous_ref, surface)

@spec surface_revised(Spectre.GAM.Act.t(), String.t(), Spectre.GAM.Surface.t()) ::
  {:ok, map()} | {:error, term()}

Links a Surface successor and its exact predecessor to the governance Act.