StatifierRouter.Resolver.Static (StatifierRouter v0.9.2)

Copy Markdown View Source

A resolver over a fixed map of compiled charts, for tests and for a host whose charts are compiled at boot.

new/1 takes a map from {scope, document} to the Statifier.Machine new executions of that document start on under that scope, and returns a resolver in the arity-2 fun form StatifierRouter.Resolver accepts:

iex> {:ok, machine} =
...>   Statifier.compile(~s(<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="done"><final id="done"/></scxml>))
iex> {:ok, resolver} =
...>   StatifierRouter.Resolver.Static.new(%{{"7c1e", "impression_click_join"} => machine})
iex> {"sha256:" <> _, ^machine} = resolver.("7c1e", "impression_click_join")
iex> resolver.("91ab", "impression_click_join")
{:error, :not_found}

The resolver answers {content_hash, machine} for a pair in the map, the content hash being Statifier.Machine.identity/1's, which is the hash statifier_persistence records for an execution created on that machine. A pair the map does not hold answers {:error, :not_found}. The map is fixed when new/1 builds the resolver: a host that publishes new revisions while it runs implements StatifierRouter.Resolver.resolve/2 over its own store instead.

Every machine must carry the identity Statifier.compile/2 stamps, since statifier_persistence refuses to create an execution on a machine without one. new/1 refuses the first entry that breaks a rule, in the map's iteration order: {:invalid_entry, entry} for a key that is not a {scope, document} pair of strings or a value that is not a %Statifier.Machine{}, and {:unidentified_chart, {scope, document}} for a machine with no identity.

Summary

Types

Why new/1 refused a map.

Functions

Builds a resolver over charts, a map from {scope, document} to a compiled machine, as the module documentation describes.

Types

new_error()

@type new_error() ::
  {:invalid_entry, term()}
  | {:unidentified_chart, {String.t(), String.t()}}
  | {:invalid_charts, term()}

Why new/1 refused a map.

Functions

new(charts)

@spec new(%{optional({String.t(), String.t()}) => Statifier.Machine.t()}) ::
  {:ok, StatifierRouter.Resolver.t()} | {:error, new_error()}

Builds a resolver over charts, a map from {scope, document} to a compiled machine, as the module documentation describes.