PhoenixAssets.Types.Walker (PhoenixAssets v0.1.0)

View Source

Walks Ash resources and renders TypeScript row types.

Given the declarations from PhoenixAssets.Types.Schema, this resolves each resource's exposed fields (public attributes by default, minus sensitive ones, adjusted by :omit/:expose, plus whitelisted calculations) and maps each Ash type to TypeScript. The exposure model is deterministic -- it never tries to evaluate Ash field policies (which are dynamic); instead PhoenixAssets.Types cross-checks exposed fields against declared field policies and warns.

Type mapping highlights

  • uuid, ci_string, datetimes, decimal, binary -> string
  • integer, float -> number
  • atom with one_of, or an Ash.Type.Enum module -> a string-literal union
  • {:array, t} -> Array<t>; map with :fields -> a typed object
  • nullable attributes gain | null
  • embedded resources are inlined structurally; a cyclic embedding renders as unknown at the point of recursion (defense in depth -- current Ash rejects declared type cycles at compile time)

Unknown names in :expose or :calculations raise an ArgumentError naming the resource and the field, rather than emitting a silently wrong contract.

Summary

Functions

Resolves the exposed {field_name, ts_type} pairs for a resource declaration.

Renders the full types.ts body from the declared types.

Functions

fields(resource, opts)

@spec fields(
  module(),
  keyword()
) :: [{atom(), String.t()}]

Resolves the exposed {field_name, ts_type} pairs for a resource declaration.

Public so PhoenixAssets.Types can cross-check the exposed field set against the resource's field policies.

render(type_decls)

@spec render([{String.t() | atom(), keyword()}]) :: binary()

Renders the full types.ts body from the declared types.