# `Masu.Query`
[🔗](https://github.com/hattoriai/masu/blob/v0.1.0/lib/masu/query.ex#L1)

What a person asked of a grid: its order, its filters and its search.

A source (`Masu.Source`) gets the query with every key and value
already checked against the grid's columns: each sort names a column
that sorts, each filter a column that filters, with its value read for
the column's type. `search` is text to find in the columns that are
searchable, or `nil`.

`groups` are the keys of the columns the rows are grouped by, the
first the outermost (`Masu.Group`).

In a tree (`Masu.Tree`), `expanded` holds the ids of the rows the
person opened, and `collapsed` those they closed while a filter or a
search shows every row it keeps open. Neither goes to the browser with
the query, nor into a view's params.

A grid starts with the query of its `sort` and `filters` attributes,
and changes it as the person sorts and searches. `Masu.Test` changes it
the same way.

# `t`

```elixir
@type t() :: %Masu.Query{
  collapsed: MapSet.t(),
  expanded: MapSet.t(),
  filters: [Masu.Filter.t()],
  groups: [String.t()],
  search: String.t() | nil,
  sorts: [Masu.Sort.t()]
}
```

# `from_wire`

```elixir
@spec from_wire(map(), [Masu.Column.t()]) :: {:ok, t()} | {:error, String.t()}
```

Makes a query from what the browser sends, and checks it against the
columns: sorts `[%{"key" => key, "dir" => "asc" | "desc"}]`, filters
`[%{"key" => key, "op" => op, "value" => value}]` and a `"search"`.

The sorts on a column that does not sort, and the repeated ones, are
left out. A filter that does not check is an error, so that a grid
never shows rows the person did not ask for.

# `new`

```elixir
@spec new(keyword(), [Masu.Column.t()]) :: {:ok, t()} | {:error, String.t()}
```

Makes a query from Elixir terms (the grid's attributes, or `Masu.Test`)
and checks it the same way: `sort` is a list of keys, `{key, direction}`
or `Masu.Sort` structs; `filters` a list of `Masu.Filter` structs or
`{key, op, value}`.

# `to_wire`

```elixir
@spec to_wire(t()) :: map()
```

The query as the browser gets it.

---

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