AshHooks.InboundDelivery.LegacyAdoption (AshHooks v2.0.2)

Copy Markdown View Source

Plans and applies adoption of provider-defined inbound identities.

This is an explicit upgrade operation for rows created by the former raw body digest default. It never changes declarations with a host event_id extractor, never guesses an identity for an unavailable payload, and never processes a delivery. The caller must quiesce ingress and reapers before applying the reviewed plan.

Summary

Functions

Applies a reviewed adoption transaction for one provider/scope/tenant partition.

Builds a payload-free audit plan without changing any row.

Types

audit_row()

@type audit_row() :: %{
  before_key: map(),
  after_key: map(),
  before_external_event_id: String.t(),
  after_external_event_id: String.t(),
  before_status: atom(),
  after_status: atom(),
  payload_digest: String.t(),
  canonical_event_id: String.t(),
  representative: boolean(),
  representative_key: map()
}

plan()

@type plan() :: %{
  provider: atom(),
  scope: map(),
  tenant: term(),
  groups: [map()],
  audit: [audit_row()],
  unresolved: [map()],
  conflicts: [map()]
}

Functions

apply(resource, name, opts \\ [])

@spec apply(module(), atom(), keyword()) :: {:ok, plan()} | {:error, term()}

Applies a reviewed adoption transaction for one provider/scope/tenant partition.

quiesced?: true is mandatory. Any unresolved payload or canonical target conflict blocks the entire transaction. The resource data layer must support transactions; otherwise this returns {:error, :transactions_not_supported} before applying the plan. Each sibling remains stored with its original payload and digest but becomes terminal :superseded; the chosen representative receives the canonical provider identity and keeps its prior processing class. Use the same :scope, :tenant, and :canonical_ids reviewed through plan/3.

plan(resource, name, opts \\ [])

@spec plan(module(), atom(), keyword()) :: {:ok, plan()} | {:error, term()}

Builds a payload-free audit plan without changing any row.

Pass the declaration's exact :scope map and, for attribute-multitenant ledgers, :tenant. :canonical_ids may map a legacy external event ID to an explicitly recovered canonical ID for a missing or redacted payload. The result lists every proposed before/after key, identity, status, selected representative, unresolved row, and target conflict.