VerifiedPubSub.Transformers.ValidateFields (VerifiedPubSub v0.1.0)

Copy Markdown View Source

Validates the type of each declared field at compile time.

The Spark schema gives the type of a field the Spark type :any, because no Spark type accepts a {:list, type} tuple or a struct module. Without this check, field :id, :strng compiles with no error, and the field then matches no value at runtime.

Summary

Functions

Callback implementation for Spark.Dsl.Transformer.before?/1.

The primitive types that a manifest can give a field.

Whether atom names a module rather than a plain atom.

Whether type is a valid field type.

Functions

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.

primitives()

@spec primitives() :: [atom()]

The primitive types that a manifest can give a field.

struct_module?(atom)

@spec struct_module?(atom()) :: boolean()

Whether atom names a module rather than a plain atom.

valid_type?(type)

@spec valid_type?(term()) :: boolean()

Whether type is a valid field type.

The compiler may not have compiled a struct module yet when this check runs. So the check finds a struct module by its Elixir. prefix, and does not load the module.