PhoenixAssets.Electric.Shapes (PhoenixAssets v0.1.0)

View Source

DSL for declaring ElectricSQL shapes that drive generated TypeScript clients.

A host module uses this and declares each shape with the Phoenix endpoint that serves it and the row type it yields:

defmodule MyApp.Assets.ElectricShapes do
  use PhoenixAssets.Electric.Shapes

  shape :public_articles, route: "/shapes/articles", type: "ArticleRow"
  shape :user_articles,
    route: "/shapes/users/:user_id/articles",
    type: "ArticleRow",
    params: [:user_id]
end

Declarations are validated at compile time: a missing route:/type:, an unknown option, a glob (*) segment, or a params: list that does not match the route's :placeholders is a compile error. params: is optional documentation of the route's placeholders; the generated factory always derives its parameters from the route itself.

The declarations are metadata only -- the server side (running the query through sync_render/3) stays in the host's controller, exactly where its policies and tenancy already live. This DSL exists so the client contract can be generated from one place and validated against the router.

use PhoenixAssets.Electric.Shapes

Using this module imports shape/2 and defines __phoenix_assets_shapes__/0 with the validated declarations.

Summary

Functions

Declares an Electric shape: route:, type:, and optional params:.

Functions

shape(name, opts)

(macro)

Declares an Electric shape: route:, type:, and optional params:.