AshHooks.PrimaryKey (AshHooks v2.0.2)

Copy Markdown View Source

Complete, metadata-derived primary-key handling for AshHooks ledgers.

Ledger ownership always uses every primary-key component declared by the consumer resource. A writable attribute named :id has no special meaning unless it is itself part of that primary key. Encoded keys use the declared attribute names as strings for job and audit payloads; decoding accepts only that exact known set and casts values through the resource's Ash types without creating atoms from input.

Summary

Types

A complete atom-key primary-key map.

Functions

Decodes an encoded primary key against the resource's exact key metadata.

Encodes a record or key map as a JSON-safe string-key map.

Returns the complete primary-key filter for an Ash record.

Returns every declared primary-key component from an Ash record.

Returns the sole declared primary-key value from an Ash record.

Types

key_map()

@type key_map() :: %{required(atom()) => term()}

A complete atom-key primary-key map.

Functions

decode(resource, encoded)

@spec decode(module(), map()) ::
  {:ok, key_map()} | {:error, :primary_key_mismatch | :invalid_primary_key}

Decodes an encoded primary key against the resource's exact key metadata.

Unknown input names never become atoms. Values are cast and constrained by their declared Ash attribute type. Error reasons are fixed atoms so attacker input cannot escape through worker or telemetry diagnostics.

encode(record)

@spec encode(struct() | map()) :: %{required(String.t()) => term()}

Encodes a record or key map as a JSON-safe string-key map.

filter(record)

@spec filter(struct()) :: key_map()

Returns the complete primary-key filter for an Ash record.

map(record)

@spec map(struct()) :: key_map()

Returns every declared primary-key component from an Ash record.

scalar!(record)

@spec scalar!(struct()) :: term()

Returns the sole declared primary-key value from an Ash record.