Validates data against the schemas a Featurevisor datafile carries, with the
same rules, messages and conditions as @featurevisor/schemas in JavaScript.
schemas = FeaturevisorSchemas.create(f)
case FeaturevisorSchemas.validate(schemas, "signUp", params) do
{:ok, params} -> create_account(params)
{:error, issues} -> render_errors(FeaturevisorSchemas.flatten(issues))
endIt holds no copy of the schemas: every call reads the current datafile, so a new datafile takes effect at the next validation. The struct is a plain term, safe to share between processes.
Summary
Types
A Schemas instance. Read it through this module's functions, since its fields may change.
Functions
Removes the module from the Featurevisor instance.
Schemas for a Featurevisor instance, not a child. Pass a child's context to validate instead.
Issues' messages grouped by field, in the shape of Zod's flattenError:
%{form_errors: [...], field_errors: %{"items.0.name" => [...]}}.
A schema's handle, or one with a form's messages by field path (:messages),
refinements (:refine) and option sources (:option_sources).
Whether the datafile carries a schema.
The keys of the schemas the datafile carries, sorted.
Whether a value passes.
Validates a value: {:ok, value} when it passes, or {:error, issues}.
The value when it passes, or raises FeaturevisorSchemas.ValidationError with the issues.
Types
Functions
@spec close(t()) :: :ok
Removes the module from the Featurevisor instance.
@spec create(Featurevisor.t(), keyword() | map()) :: t()
Schemas for a Featurevisor instance, not a child. Pass a child's context to validate instead.
Options:
:messages- the application's messages by issue code, such as%{"required" => "{title} is required"}, text with placeholders or a function of the params and theFeaturevisorSchemas.MessageInfo.:translate- a function of the issue and theMessageInfothat words every issue, returning nil to keep the chosen message.
@spec flatten([FeaturevisorSchemas.Issue.t()]) :: %{ form_errors: [String.t()], field_errors: %{required(String.t()) => [String.t()]} }
Issues' messages grouped by field, in the shape of Zod's flattenError:
%{form_errors: [...], field_errors: %{"items.0.name" => [...]}}.
@spec get(t(), String.t(), keyword()) :: FeaturevisorSchemas.Handle.t()
A schema's handle, or one with a form's messages by field path (:messages),
refinements (:refine) and option sources (:option_sources).
Whether the datafile carries a schema.
The keys of the schemas the datafile carries, sorted.
Whether a value passes.
@spec validate(t(), String.t(), term(), keyword()) :: {:ok, term()} | {:error, [FeaturevisorSchemas.Issue.t()]}
Validates a value: {:ok, value} when it passes, or {:error, issues}.
A :context given is merged over the instance's, for rules that change by segment.
The value when it passes, or raises FeaturevisorSchemas.ValidationError with the issues.