Lotus.Web.Actor (Lotus Web v1.2.0)

Copy Markdown View Source

Who the dashboard is acting for, in the shape Lotus core expects.

Core accepts :context and :scope on every call that runs a query or lists schema objects. :context reaches middleware and telemetry, :scope reaches the visibility resolver and the cache key. The dashboard resolves both at mount through Lotus.Web.Resolver and carries them as assigns; this module turns those assigns into the option list core takes.

A nil context and a nil scope produce [], so an unscoped dashboard calls core exactly as it did before an actor existed — same middleware payloads, same cache keys.

Catching an actor that never arrived

A Phoenix.LiveComponent holds only what its parent passes, so a component nobody handed the actor to calls core unscoped, and silently. Set

config :lotus_web, strict_actor: true

in dev and test and opts/1 raises for assigns that carry no :context key at all, which tells that mistake apart from a dashboard that has no actor to give. Leave it off in production, where an unscoped call beats a crash.

Summary

Types

t()

The actor as the dashboard carries it between components: {context, scope}.

Functions

Merge the actor options into an existing option list.

Build the :context / :scope options for a core call.

Resolve the actor for a user through the given resolver.

Types

t()

@type t() :: {term(), term()}

The actor as the dashboard carries it between components: {context, scope}.

Functions

merge(opts, source)

@spec merge(keyword(), map() | t()) :: keyword()

Merge the actor options into an existing option list.

Options already present win, so a caller can override the actor for a single call.

opts(assigns)

@spec opts(map() | t()) :: keyword()

Build the :context / :scope options for a core call.

Takes either the socket assigns or an explicit {context, scope} pair. Keys whose value is nil are left out.

resolve(resolver, user)

@spec resolve(module() | nil, Lotus.Web.Resolver.user()) :: {term(), term()}

Resolve the actor for a user through the given resolver.

Returns {context, scope}. Both are nil unless the resolver implements Lotus.Web.Resolver.resolve_context/1 or Lotus.Web.Resolver.resolve_scope/1.