Dsxir.RuntimeProgram.Store behaviour (dsxir v0.2.0)

Copy Markdown

Behaviour for runtime-program persistence.

Two reference implementations ship in dsxir:

Production users plug their own backend (Postgres, S3, etc.) by implementing the three callbacks.

Filter shape

list/2 accepts a keyword filter with at most two keys:

  • :tenant_id - matches against metadata.tenant_id; both string ("tenant_id") and atom (:tenant_id) keys are supported in the program's metadata map.
  • :id - exact match against the program's :id field.

No other filters are recognized in v1; extra keys are ignored.

Summary

Functions

Filter a list of %RuntimeProgram{} structs by a filter/0 keyword.

Types

filter()

@type filter() :: keyword()

id()

@type id() :: String.t()

t()

@type t() :: term()

version()

@type version() :: <<_::256>>

Callbacks

get(t, tuple)

@callback get(
  t(),
  {id(), version()}
) :: {:ok, Dsxir.RuntimeProgram.t()} | {:error, :not_found}

list(t, filter)

@callback list(t(), filter()) :: {:ok, [Dsxir.RuntimeProgram.t()]}

put(t, t)

@callback put(t(), Dsxir.RuntimeProgram.t()) :: :ok | {:error, term()}

Functions

apply_filter(rps, filter)

@spec apply_filter([Dsxir.RuntimeProgram.t()], filter()) :: [Dsxir.RuntimeProgram.t()]

Filter a list of %RuntimeProgram{} structs by a filter/0 keyword.

Shared helper used by reference impls; production backends may push the filter into their query layer instead.