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

Types

Persisted exported view record/struct

Opaque term blob persisted by the host app

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

Link to this type

exported_view()

@type exported_view() :: map()

Persisted exported view record/struct

@type term_blob() :: binary()

Opaque term blob persisted by the host app

Link to this section Callbacks

Link to this callback

create_exported_view(attrs, opts)

@callback create_exported_view(attrs :: map(), opts :: keyword()) ::
  {:ok, exported_view()} | {:error, term()}
Link to this callback

delete_exported_view(exported_view, opts)

@callback delete_exported_view(exported_view(), opts :: keyword()) ::
  {:ok, exported_view()} | {:error, term()}
Link to this callback

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
Link to this callback

list_exported_views(context, opts)

@callback list_exported_views(context :: term(), opts :: keyword()) :: [exported_view()]
Link to this callback

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

Link to this function

build_create_attrs(assigns, attrs)

@spec build_create_attrs(map(), map()) :: map()

Build attributes for create_exported_view/2 from current assigns.

Link to this function

build_snapshot(assigns)

@spec build_snapshot(map()) :: map()

Build the persisted snapshot payload from current SelectoComponents assigns.

Link to this function

cache_status(view, now \\ DateTime.utc_now())

@spec cache_status(map(), DateTime.t()) ::
  :disabled | :missing | :fresh | :stale | :error

Compute cache status from persisted timestamps.

Link to this function

decode_cache_payload(view)

@spec decode_cache_payload(map()) :: {:ok, map()} | {:error, :invalid_blob | :missing}

Extract and decode the persisted render cache payload.

Link to this function

decode_snapshot(view)

@spec decode_snapshot(map()) :: {:ok, map()} | {:error, :invalid_blob | :missing}

Extract and decode the persisted snapshot payload.

Link to this function

decode_term(blob)

@spec decode_term(term_blob() | nil) ::
  {:ok, term()} | {:error, :invalid_blob | :missing}

Decode a previously encoded persistence blob.

Link to this function

default_embed_path()

@spec default_embed_path() :: String.t()

Default mount path used by generated embed snippets.

Link to this function

disabled?(view)

@spec disabled?(map()) :: boolean()

Return true when the exported view is disabled.

Link to this function

encode_term(term)

@spec encode_term(term()) :: term_blob()

Encode an arbitrary Elixir term for persistence.

Link to this function

field(record, key, default \\ nil)

@spec field(map() | nil, atom(), term()) :: term()

Fetch a field from a map/struct, supporting atom and string keys.

Link to this function

generate_public_id()

@spec generate_public_id() :: String.t()

Generate a URL-safe public id.

Link to this function

ttl_seconds(view)

@spec ttl_seconds(map()) :: pos_integer()

Return the configured cache TTL in seconds.