Syntropy.Persistence
(syntropy v0.3.0)
Copy Markdown
Optional Postgres-backed durability for Syntropy replay-critical read models.
Summary
Functions
Decodes an opaque cursor back into {timestamp, id}.
Encodes a {timestamp, id} pagination cursor as an opaque URL-safe string.
Lists structural recommendations newest-first with cursor pagination.
Lists run envelopes newest-first with cursor pagination.
Lists lattice snapshots newest-first with cursor pagination.
Deletes replay data older than cutoff (or all replay data with :all).
Types
@type cursor() :: {DateTime.t(), String.t()}
@type event() :: Syntropy.EventRecorder.event()
@type recommendation() :: Syntropy.RecommendationStore.recommendation()
@type run_envelope() :: map()
@type snapshot() :: Syntropy.HistoryStore.snapshot()
@type task_result() :: Syntropy.TaskScheduler.task_result()
@type webhook() :: Syntropy.Webhooks.Registry.webhook()
@type write_result() :: :ok | {:error, term()}
Functions
@spec clear_all!() :: :ok
@spec counter_from_ids([map()], atom(), String.t()) :: non_neg_integer()
Decodes an opaque cursor back into {timestamp, id}.
@spec enabled?() :: boolean()
@spec encode_cursor({DateTime.t(), term()}) :: String.t()
Encodes a {timestamp, id} pagination cursor as an opaque URL-safe string.
@spec find_active_api_token(String.t()) :: Syntropy.Persistence.ApiToken.t() | nil
@spec get_recommendation(String.t()) :: recommendation() | nil
@spec get_run_envelope(String.t()) :: run_envelope() | nil
@spec hydrate_limit() :: pos_integer()
@spec list_api_tokens() :: [Syntropy.Persistence.ApiToken.t()]
Lists structural recommendations newest-first with cursor pagination.
Options: :limit, :cursor, :status, :kind, :q (matches the
recommendation id or candidate agent ids).
Lists run envelopes newest-first with cursor pagination.
Options: :limit, :cursor ({timestamp, id}), :status, :kind, :q
(matches the run id or prompt).
Lists lattice snapshots newest-first with cursor pagination.
Options: :limit, :cursor, :kind (trigger kind), :q (matches the
snapshot or task id).
@spec load_recent_events(non_neg_integer()) :: [event()]
@spec load_recent_recommendations(non_neg_integer()) :: [recommendation()]
@spec load_recent_run_envelopes(non_neg_integer()) :: [run_envelope()]
@spec load_recent_snapshots(non_neg_integer()) :: [snapshot()]
@spec load_recent_tasks(non_neg_integer()) :: [task_result()]
@spec load_webhooks() :: [webhook()]
@spec observe_write(write_result(), String.t()) :: write_result()
@spec persist_recommendation(recommendation()) :: :ok | {:error, term()}
@spec persist_run_envelope(run_envelope()) :: :ok | {:error, term()}
@spec persist_task_run(task_result()) :: :ok | {:error, term()}
@spec purge_replay_data(DateTime.t() | :all) :: {:ok, %{required(String.t()) => non_neg_integer()}} | {:error, term()}
Deletes replay data older than cutoff (or all replay data with :all).
Returns per-table deletion counts. Failures are observed through
PersistenceHealth and returned; callers decide whether to tolerate them.
@spec recent_usage_records(non_neg_integer()) :: [ Syntropy.Persistence.UsageRecord.t() ]
@spec require_write!(write_result(), String.t()) :: :ok
@spec tolerate_write(write_result(), String.t()) :: :ok
@spec usage_by_model_since(DateTime.t()) :: [map()]
@spec usage_daily_since(DateTime.t()) :: [map()]
@spec usage_totals_since(DateTime.t()) :: map() | nil