AuditLog.Subject (AuditLog v0.1.0)

Copy Markdown View Source

A durable subject identity and optional exact temporal version boundary.

Subject types and identifiers are application-owned codes stored as text. They are not foreign keys.

Summary

Functions

Casts a stored text identifier through a schema's single primary-key type.

Builds a subject from one loaded or deleted Ecto schema struct.

Builds a subject from an application-owned type and identifier.

Types

t()

@type t() :: %AuditLog.Subject{
  id: String.t(),
  type: String.t(),
  version_at: DateTime.t() | nil
}

Functions

cast_id!(schema, subject_or_id)

@spec cast_id!(module(), t() | String.t()) :: term()

Casts a stored text identifier through a schema's single primary-key type.

Accepts either an AuditLog.Subject or a stored subject ID. This is useful before querying an application schema whose primary key is an integer, UUID, or custom Ecto type.

from_schema!(struct, opts \\ [])

@spec from_schema!(
  Ecto.Schema.t(),
  keyword()
) :: t()

Builds a subject from one loaded or deleted Ecto schema struct.

The schema must have one non-nil primary key. The schema source becomes the subject type unless :type is supplied.

When no explicit :version_at is supplied, a structurally compatible sys_period.from is used without depending on a temporal-table package. An explicit :version_at takes precedence.

new!(type, id, opts \\ [])

@spec new!(String.Chars.t(), String.Chars.t(), keyword()) :: t()

Builds a subject from an application-owned type and identifier.

type and id must implement String.Chars; both are converted to strings, trimmed, and required to be non-blank.

Use :version_at to identify the lower boundary of an exact temporal row version:

AuditLog.Subject.new!("invoice", 42, version_at: version_boundary)