A2UICore.Catalog.Function (A2UICore v0.1.1)

Copy Markdown View Source

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.

Summary

Functions

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).

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, …).

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

Attaches an implementation.

Types

effects()

(since 0.1.0)

execute()

(since 0.1.0)
@type execute() :: (map(), A2UICore.Resolution.DataContext.t() | nil ->
                {:ok, term()}
                | {:ok, term(), effects()}
                | {:error, A2UICore.Error.t()})

t()

(since 0.1.0)
@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()
}

Functions

declared_return_type(arg1)

(since 0.1.0)
@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?(function)

(since 0.1.0)
@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(name, schema, options \\ [])

(since 0.1.0)
@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(function, execute)

(since 0.1.0)
@spec with_execute(t(), execute()) :: t()

Attaches an implementation.