AshAge.Type.Cast (AshAge v1.0.0)

Copy Markdown View Source

Cast functions for mapping AGE vertex data to Ash resource attributes.

Summary

Functions

Coerces a decoded agtype scalar to its Ash attribute type.

Converts a vertex to a map of resource attributes.

Functions

coerce_value(value, spec)

@spec coerce_value(term(), atom() | module() | tuple() | nil) :: term()

Coerces a decoded agtype scalar to its Ash attribute type.

Single source of truth for scalar coercion, shared by the vertex-read path (vertex_to_resource_attrs/3) and the traversal F3 source-key path (AshAge.ManualRelationships.Traverse). A nil/unknown type returns the value verbatim (identity), so callers may pass a type map that omits a field.

vertex_to_resource_attrs(vertex, attribute_map, attribute_types)

@spec vertex_to_resource_attrs(AshAge.Type.Vertex.t(), map(), map()) :: map()

Converts a vertex to a map of resource attributes.

  • Extracts vertex.properties
  • Includes vertex.id mapped to the resource's primary key
  • Applies attribute_map for any name remapping
  • Coerces types based on attribute_types (e.g., ISO8601 strings -> Date/DateTime)