Threadline.Semantics.ActorRef (Threadline v0.4.0)

Copy Markdown View Source

Value object representing the actor who performed an audited operation.

Implements Ecto.ParameterizedType for use as a JSONB field in Ecto schemas. Stored as %{"type" => "user", "id" => "123"} in PostgreSQL; loaded back as %ActorRef{type: :user, id: "123"} in Elixir.

Actor types

  • :user — end user with a non-empty id
  • :admin — administrator with a non-empty id
  • :service_account — service account with a non-empty id
  • :job — background job with a non-empty id
  • :system — system process with a non-empty id
  • :anonymous — unauthenticated actor; id is nil

Summary

Functions

Deserializes an ActorRef from a plain map. Returns {:ok, ref} or {:error, reason}.

Constructs a validated ActorRef.

Serializes an ActorRef to a plain map for JSONB storage.

Functions

from_map(arg1)

Deserializes an ActorRef from a plain map. Returns {:ok, ref} or {:error, reason}.

new(type, id \\ nil)

Constructs a validated ActorRef.

Returns {:ok, %ActorRef{}} or {:error, reason} where reason is one of:

  • :unknown_actor_type — type not in the supported list
  • :missing_actor_id — non-anonymous actor with nil or empty id

to_map(actor_ref)

Serializes an ActorRef to a plain map for JSONB storage.