FeaturevisorSchemas.Handle (featurevisor_schemas v2.1.0)

Copy Markdown View Source

A schema's handle, or a field's. Everything it does reads the current datafile when it is used, so one handle stays right for the life of an application. A handle is a plain term, safe to keep and share.

Summary

Types

t()

A handle. Read it through this module's functions, since its fields may change.

Functions

Its annotations, over those of a schema its field references.

The HTML validation attributes its rules imply, with required from the object it sits in.

The handle for a field at a path, such as address.city, items[].name or labels.*.

An object's fields' constraints by dot path, such as address.city.

An object's fields' choices by dot path, for the fields that list some.

An object's fields' handles, in its order, or none for any other value.

The schema's key, such as signUp.

The choice for a value: {:ok, option} from the schema's own choices or else the field's option source, :error for none, or the source's {:error, reason}.

Its own key in the object it sits in, such as city, or empty for the schema itself.

The schema's own choice for a value, or nil.

The choices the field allows, in the order its rules list them, empty when it lists none.

The field's path in its schema, such as address.city or items[].name, or empty for the schema.

The fields, relative to this handle, that its mutations' and issues' conditions read.

What the rules say the field renders as, such as text, select or date-time, or nil for a oneOf of shapes.

Suggestions from the field's option source for a query: {:ok, options}, empty without a source that searches, or the source's {:error, reason}.

Whether an option source suggests choices for this field.

Calls back when the datafile changes this handle's schema, until the returned function is called.

Whether a value passes.

Validates a value: {:ok, value} when it passes, or {:error, issues}. Maps with string or atom keys, lists, primitives and structs are read as JSON has them. Checks in code run in order, after the rules. A :context given is merged over the instance's.

The value when it passes, or raises FeaturevisorSchemas.ValidationError with the issues.

The same handle with an input, such as the values a form has so far: its members describe the rules with every mutation whose conditions match that input, and the :context, applied at every depth.

Types

t()

@type t() :: %FeaturevisorSchemas.Handle{
  form: term(),
  key: term(),
  options: term(),
  path: term(),
  schemas: term(),
  steps: term(),
  view: term()
}

A handle. Read it through this module's functions, since its fields may change.

Functions

annotations(handle)

@spec annotations(t()) :: map()

Its annotations, over those of a schema its field references.

constraints(handle)

@spec constraints(t()) :: FeaturevisorSchemas.Constraints.t()

The HTML validation attributes its rules imply, with required from the object it sits in.

field(handle, path)

@spec field(t(), String.t()) :: t()

The handle for a field at a path, such as address.city, items[].name or labels.*.

field_constraints(handle)

@spec field_constraints(t()) :: %{
  required(String.t()) => FeaturevisorSchemas.Constraints.t()
}

An object's fields' constraints by dot path, such as address.city.

field_options(handle)

@spec field_options(t()) :: %{
  required(String.t()) => [FeaturevisorSchemas.Option.t()]
}

An object's fields' choices by dot path, for the fields that list some.

fields(handle)

@spec fields(t()) :: [t()]

An object's fields' handles, in its order, or none for any other value.

key(handle)

@spec key(t()) :: String.t()

The schema's key, such as signUp.

lookup(handle, value, options \\ [])

@spec lookup(t(), term(), keyword()) ::
  {:ok, FeaturevisorSchemas.Option.t()} | :error | {:error, term()}

The choice for a value: {:ok, option} from the schema's own choices or else the field's option source, :error for none, or the source's {:error, reason}.

name(handle)

@spec name(t()) :: String.t()

Its own key in the object it sits in, such as city, or empty for the schema itself.

option(handle, value)

@spec option(t(), term()) :: FeaturevisorSchemas.Option.t() | nil

The schema's own choice for a value, or nil.

options(handle)

@spec options(t()) :: [FeaturevisorSchemas.Option.t()]

The choices the field allows, in the order its rules list them, empty when it lists none.

path(handle)

@spec path(t()) :: String.t()

The field's path in its schema, such as address.city or items[].name, or empty for the schema.

reads(handle)

@spec reads(t()) :: [String.t()]

The fields, relative to this handle, that its mutations' and issues' conditions read.

render_as(handle)

@spec render_as(t()) :: String.t() | nil

What the rules say the field renders as, such as text, select or date-time, or nil for a oneOf of shapes.

search(handle, query, options \\ [])

@spec search(t(), String.t(), keyword()) ::
  {:ok, [FeaturevisorSchemas.Option.t()]} | {:error, term()}

Suggestions from the field's option source for a query: {:ok, options}, empty without a source that searches, or the source's {:error, reason}.

searchable?(handle)

@spec searchable?(t()) :: boolean()

Whether an option source suggests choices for this field.

subscribe(handle, listener)

@spec subscribe(t(), (-> any())) :: (-> :ok)

Calls back when the datafile changes this handle's schema, until the returned function is called.

valid?(handle, value, options \\ [])

@spec valid?(t(), term(), keyword()) :: boolean()

Whether a value passes.

validate(handle, value, options \\ [])

@spec validate(t(), term(), keyword()) ::
  {:ok, term()} | {:error, [FeaturevisorSchemas.Issue.t()]}

Validates a value: {:ok, value} when it passes, or {:error, issues}. Maps with string or atom keys, lists, primitives and structs are read as JSON has them. Checks in code run in order, after the rules. A :context given is merged over the instance's.

validate!(handle, value, options \\ [])

@spec validate!(t(), term(), keyword()) :: term()

The value when it passes, or raises FeaturevisorSchemas.ValidationError with the issues.

with_input(handle, input, options \\ [])

@spec with_input(t(), term(), keyword()) :: t()

The same handle with an input, such as the values a form has so far: its members describe the rules with every mutation whose conditions match that input, and the :context, applied at every depth.