PhoenixAssets.Types.Schema (PhoenixAssets v0.1.0)

View Source

DSL for declaring which Ash resources become generated TypeScript row types.

A host module uses this and declares each type:

defmodule MyApp.Assets.Types do
  use PhoenixAssets.Types.Schema

  type "ArticleRow",
    resource: MyApp.Content.Article,
    only: :public,
    omit: [:internal_score],
    calculations: [:like_count]
end

Options per type/2:

  • :resource (required) -- the Ash resource module.
  • :only -- :public (default) or :all.
  • :omit -- attribute names to drop even if otherwise included.
  • :expose -- non-public attribute names to add (opt-in escape hatch).
  • :calculations -- calculation names to include.

Declarations are validated at compile time: a missing :resource or an unknown option is a compile error. Field-level names (:expose, :calculations) are checked at generation time against the resource, which raises a clear error for unknown names.

use PhoenixAssets.Types.Schema

Using this module imports type/2 and defines __phoenix_assets_types__/0 with the validated declarations.

Summary

Functions

Declares a generated TypeScript type from an Ash resource.

Functions

type(name, opts)

(macro)

Declares a generated TypeScript type from an Ash resource.