# `A2UICore.Catalog.Function`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_core/lib/a2ui_core/catalog/function.ex#L1)

A function a catalog declares: its schema plus, when the catalog can
evaluate it, an implementation.

  * `:name` — the name a call uses (`formatString`, `@index`).
  * `:schema` — the function's definition as the catalog document
    writes it (a call schema with `call`/`@call` and `args`), or, for
    a function defined in code, possibly just the schema of its
    `args`.
  * `:return_type` — `"string"`, `"number"`, `"boolean"`, `"object"`,
    `"array"`, `"any"` or `"void"`, when declared (a top-level
    `returnType`, or the `returnType` constant of a v0.9 call schema);
    `nil` means `"any"`.
  * `:allowed_callers` — `"rendererOnly"`, `"agentOnly"` or
    `"rendererOrAgent"`; `nil` when the catalog omits it, which the
    protocol defines as `"rendererOnly"` (v1.0).
  * `:requires_user_activation` — v1.0.
  * `:description` — the definition's `description`.
  * `:is_definition` — whether `:schema` is the whole catalog entry;
    `nil` infers it from the schema's shape.
  * `:from_document` — whether the schema was read from a catalog
    document (see `A2UICore.Catalog.Component`).
  * `:execute` — `nil` for a schema-only function, else a function of
    `(args, context)` returning `{:ok, value}`, `{:ok, value, effects}`
    or `{:error, A2UICore.Error.t()}`. `args` are already resolved;
    `context` is the `A2UICore.Resolution.DataContext` of the call.

# `effects`
*since 0.1.0* 

```elixir
@type effects() :: [A2UICore.Resolution.DataContext.effect()]
```

# `execute`
*since 0.1.0* 

```elixir
@type execute() :: (map(), A2UICore.Resolution.DataContext.t() | nil -&gt;
                {:ok, term()}
                | {:ok, term(), effects()}
                | {:error, A2UICore.Error.t()})
```

# `t`
*since 0.1.0* 

```elixir
@type t() :: %A2UICore.Catalog.Function{
  allowed_callers: String.t() | nil,
  description: String.t() | nil,
  execute: execute() | nil,
  from_document: boolean(),
  is_definition: boolean() | nil,
  name: String.t(),
  requires_user_activation: boolean() | nil,
  return_type: String.t() | nil,
  schema: map()
}
```

# `declared_return_type`
*since 0.1.0* 

```elixir
@spec declared_return_type(map()) :: term()
```

The return type a catalog entry declares, or `nil`: a top-level
`returnType` (v1.0 and the v0.9 list form) or the `const` of the
call's `returnType` property (the v0.9 map form).

# `definition?`
*since 0.1.0* 

```elixir
@spec definition?(t()) :: boolean()
```

Whether the function's schema is its whole catalog entry rather than
the schema of its `args`: `:is_definition` when set, else a call
schema (`properties` naming `call`, `@call` or `args`) or one that
declares a keyword only entries write (`returnType`, …).

# `from_schema`
*since 0.1.0* 

```elixir
@spec from_schema(String.t(), map(), execute() | nil | keyword()) :: t()
```

Builds a function from a catalog document entry (`schema` is the
function's schema object).

Options: `:execute`, and `from_document: true` for an entry read from
a document (which is then also a definition).

# `with_execute`
*since 0.1.0* 

```elixir
@spec with_execute(t(), execute()) :: t()
```

Attaches an implementation.

---

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