11defmodule Phoenix.Sync do
2- @ moduledoc """
3- Wrappers to ease integration of [Electric’s Postgres syncing
4- service](https://electric-sql.com) with [Phoenix
5- applications](https://www.phoenixframework.org/).
6-
7- There are currently 2 integration modes: [`Phoenix.LiveView`
8- streams](#module-phoenix-liveview-streams) and [configuration
9- gateway](#module-configuration-gateway).
10-
11- ## Phoenix.LiveView Streams
12-
13- `Phoenix.Sync.LiveView.sync_stream/4` integrates with
14- [`Phoenix.LiveView.stream/4`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#stream/4)
15- and provides a live updating collection of items.
16-
17- ## Configuration Gateway
18-
19- Using `Phoenix.Sync.Plug` you can create endpoints that
20- return configuration information for your Electric Typescript clients. See
21- [that module's documentation](`Phoenix.Sync.Plug`) for
22- more information.
23-
24- ## Installation
25-
26- Add `phoenix_sync` to your application dependencies:
27-
28- def deps do
29- [
30- {:phoenix_sync, "~> 0.1"}
31- ]
32- end
33-
34- ## Configuration
35-
36- In your `config/config.exs` or `config/runtime.exs` you **must** configure the
37- client for the Electric streaming API:
38-
39- import Config
40-
41- config :phoenix_sync, Electric.Client,
42- # one of `base_url` or `endpoint` is required
43- base_url: System.get_env("ELECTRIC_URL", "http://localhost:3000"),
44- # endpoint: System.get_env("ELECTRIC_ENDPOINT", "http://localhost:3000/v1/shape"),
45- # optional
46- database_id: System.get_env("ELECTRIC_DATABASE_ID", nil)
47-
48- See the documentation for [`Electric.Client.new/1`](`Electric.Client.new/1`)
49- for information on the client configuration.
50-
51- ## Embedding Electric
52-
53- **TODO**
54- """
55-
562 alias Electric.Client.ShapeDefinition
573
584 @ shape_keys [ :namespace , :where , :columns ]
@@ -73,31 +19,10 @@ defmodule Phoenix.Sync do
7319 @ type param_overrides :: [ param_override ( ) ]
7420
7521 defdelegate plug_opts ( ) , to: Phoenix.Sync.Application
76- @ doc false
77- defdelegate plug_opts ( opts ) , to: Phoenix.Sync.Application
78-
79- @ doc """
80- Create a new `Electric.Client` instance based on the application config.
81-
82- To connect your live streams to an externally hosted Electric instance over
83- HTTP, configure your app with the URL of the Electric server:
8422
85- # dev.exs
86- config :phoenix_sync, Electric.Client,
87- base_url: "http://localhost:3000"
23+ defdelegate client! ( ) , to: Phoenix.Sync.Client , as: :new!
8824
89- If Electric is installed as a dependency of your app, and you wish to connect
90- your live streams to this internal application, then you don't need to configure
91- anything -- `client!/0` will return an `Electric.Client` instance configured to
92- data directly from the running Electric application.
93-
94- See [`Electric.Client.new/1`](`Electric.Client.new/1`) for the available
95- options.
96-
97- """
98- defdelegate client! , to: Phoenix.Sync.Client , as: :new!
99-
100- @ doc """
25+ _ = """
10126 Use request query parameters to create a `Electric.Client.ShapeDefinition`.
10227
10328 Useful when creating authorization endpoints that validate a user's access to
@@ -149,9 +74,10 @@ defmodule Phoenix.Sync do
14974 {:ok, %Electric.Client.ShapeDefinition{table: "things"}}
15075
15176 """
77+
78+ @ doc false
15279 @ spec shape_from_params ( Plug.Conn . t ( ) | Plug.Conn . params ( ) , overrides :: param_overrides ( ) ) ::
15380 { :ok , Electric.Client.ShapeDefinition . t ( ) } | { :error , String . t ( ) }
154-
15581 def shape_from_params ( conn_or_map , overrides \\ [ ] )
15682
15783 def shape_from_params ( % Plug.Conn { } = conn , overrides ) do
0 commit comments