# `AshLua.Fields`
[🔗](https://github.com/ash-project/ash_lua/blob/v0.1.0/lib/ash_lua/fields.ex#L5)

Manifest-driven field selection for Lua-side queries.

Translates a `fields` tree supplied by a Lua script into the three things Ash needs:

  * `select` — the list of attribute atoms to pass to `Ash.Query.select/2`
  * `load`   — the load statement to pass to `Ash.Query.load/2` (or `Ash.Changeset.load/2`)
  * `template` — an opaque structure the encoder walks to emit only the requested fields

The Lua side accepts a list of strings and one-key maps:

    fields = {
      "id", "title",
      { author = { "id", "name" } },                          -- nested relationship
      { comments = { "id", "body" } },                        -- has_many
      { title_prefixed = { args = { prefix = "x: " } } },     -- calc with args
      { metadata = { "priority", "category" } },              -- typed map sub-selection
      { coordinates = { "latitude", "longitude" } },          -- typed tuple
      { content = { text = { "body" } } },                    -- union member sub-selection
    }

Default (no `fields` provided) returns primary-key attributes only for resource records.
For non-resource return types (typed map, tuple, primitive, etc.) the whole value is
rendered.

Type dispatch and template construction are driven entirely from
`Ash.Info.Manifest.generate/1` IR — no `Ash.Resource.Info.*` traversal here.

# `for_action`

```elixir
@spec for_action(Ash.Info.Manifest.t(), atom(), Ash.Info.Manifest.Action.t(), term()) ::
  {:ok, {[atom()], term(), term()}} | {:error, term()}
```

Builds `{select, load, template}` for the given resource + action.

`requested` is the already-decoded Lua input (the value of the `fields` key) — either
`nil`/empty (defaults apply) or a list of items produced by `AshLua.Encoder.decode_input/1`.

# `parse`

```elixir
@spec parse(term()) :: {:ok, :default | list()} | {:error, term()}
```

Parses a Lua-decoded fields input into the internal AST.

Returns `{:ok, :default}` when no fields were supplied, `{:ok, ast}` otherwise.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
