SelectoComponents.ExportedViews behaviour (selecto_components v0.4.5)
Behavior and helpers for persisted exported views.
Exported views are signed, iframe-friendly snapshots of a SelectoComponents view that can be embedded into dashboard-like environments.
The persistence layer is intentionally app-owned. Host applications provide a module that implements this behavior, while SelectoComponents handles snapshot building, cache payload generation, signature verification, and management UI.
Link to this section Summary
Functions
Build attributes for create_exported_view/2 from current assigns.
Build the persisted snapshot payload from current SelectoComponents assigns.
Compute cache status from persisted timestamps.
Extract and decode the persisted render cache payload.
Extract and decode the persisted snapshot payload.
Decode a previously encoded persistence blob.
Default mount path used by generated embed snippets.
Return true when the exported view is disabled.
Encode an arbitrary Elixir term for persistence.
Fetch a field from a map/struct, supporting atom and string keys.
Generate a URL-safe public id.
Return the configured cache TTL in seconds.
Link to this section Types
exported_view()
@type exported_view() :: map()
Persisted exported view record/struct
term_blob()
@type term_blob() :: binary()
Opaque term blob persisted by the host app
Link to this section Callbacks
create_exported_view(attrs, opts)
@callback create_exported_view(attrs :: map(), opts :: keyword()) :: {:ok, exported_view()} | {:error, term()}
delete_exported_view(exported_view, opts)
@callback delete_exported_view(exported_view(), opts :: keyword()) :: {:ok, exported_view()} | {:error, term()}
get_exported_view_by_public_id(public_id, opts)
@callback get_exported_view_by_public_id(public_id :: String.t(), opts :: keyword()) :: exported_view() | nil
list_exported_views(context, opts)
@callback list_exported_views(context :: term(), opts :: keyword()) :: [exported_view()]
update_exported_view(exported_view, attrs, opts)
@callback update_exported_view(exported_view(), attrs :: map(), opts :: keyword()) :: {:ok, exported_view()} | {:error, term()}
Link to this section Functions
build_create_attrs(assigns, attrs)
Build attributes for create_exported_view/2 from current assigns.
build_snapshot(assigns)
Build the persisted snapshot payload from current SelectoComponents assigns.
cache_status(view, now \\ DateTime.utc_now())
@spec cache_status(map(), DateTime.t()) :: :disabled | :missing | :fresh | :stale | :error
Compute cache status from persisted timestamps.
decode_cache_payload(view)
Extract and decode the persisted render cache payload.
decode_snapshot(view)
Extract and decode the persisted snapshot payload.
decode_term(blob)
Decode a previously encoded persistence blob.
default_embed_path()
@spec default_embed_path() :: String.t()
Default mount path used by generated embed snippets.
disabled?(view)
Return true when the exported view is disabled.
encode_term(term)
Encode an arbitrary Elixir term for persistence.
field(record, key, default \\ nil)
Fetch a field from a map/struct, supporting atom and string keys.
generate_public_id()
@spec generate_public_id() :: String.t()
Generate a URL-safe public id.
ttl_seconds(view)
@spec ttl_seconds(map()) :: pos_integer()
Return the configured cache TTL in seconds.