AshBackendDrivenOptimisticUi.Rules (AshBackendDrivenOptimisticUi v0.1.0)

Copy Markdown View Source

A resource's rules as JSON-ready data for the client.

Rules are keyed "<type>.<action>", where <type> is the resource's JSON:API type or, without one, its module's last segment underscored. Each rule is %{"effects" => [effect]}, effects in order:

  • %{"set" => %{"attr" => json_logic}, "source" => "derived" | "declared"}

  • %{"push" => %{"event" => "xp_awarded", "payload" => %{"key" => json_logic}}}; the payload also gets "id", {"var": "ctx.push_ids.<event>.<label>"} (see AshBackendDrivenOptimisticUi.PushId), except in the rule of a create action
  • %{"where" => json_logic, "effects" => [effect]}
  • %{"insert" => %{"at" => "start" | "end" | %{"sorted_by" => "field"}}}: put the record the sets build into the list, at an end or before the first row whose field sorts after its own

  • %{"remove" => %{}}: take the record out of the list
  • %{"clear" => %{"from" => path}}: empty the nested lists at path
  • %{"edit" => %{"from" => path}}: apply the sets to the record's own row in the nested lists at path

An insert with "into", or a remove with "from", works on a list nested inside the one record the client holds. The path is a list of steps, %{"key" => "exercises"} or %{"key" => "exercises", "match" => %{"field" => json_logic}}, the latter keeping only the rows whose field equals the value.

An expression AshBackendDrivenOptimisticUi.Compiler cannot compile raises, so a rule set is never half-built.

Summary

Functions

Every optimistic of resource, keyed "<type>.<action>".

Every on of resource, keyed by event name.

The JSON:API type of resource, or its module's last segment underscored.

Functions

for_resource(resource)

@spec for_resource(Ash.Resource.t()) :: %{required(String.t()) => map()}

Every optimistic of resource, keyed "<type>.<action>".

reactions_for_resource(resource)

@spec reactions_for_resource(Ash.Resource.t()) :: %{required(String.t()) => [map()]}

Every on of resource, keyed by event name.

type(resource)

@spec type(Ash.Resource.t()) :: String.t()

The JSON:API type of resource, or its module's last segment underscored.