@@ -106,6 +106,13 @@ defmodule Phoenix.Sync.Client do
106106 columns: ["id", "title"]
107107 )
108108
109+ # consumer a pre-defined shape from a remote server, e.g.
110+ # one defined using `Phoenix.Sync.Controller.sync_render/3` or
111+ # `Phoenix.Sync.Router.sync/2`.
112+ stream = Phoenix.Sync.Client.stream(
113+ "https://myapp.com/sync/todos?user_id=1234"
114+ )
115+
109116 # once you have a stream, consume it as usual
110117 Enum.each(stream, &IO.inspect/1)
111118
@@ -116,18 +123,30 @@ defmodule Phoenix.Sync.Client do
116123 Elixir/Ecto types, rather than raw column data in the form `%{"column_name"
117124 => "column_value"}`.
118125 """
126+ # stream(Todo, replica: full, client: client)
127+ # stream("todos", where: "...", replica: full, client: client)
128+ # stream(table: "todos", where: "...", replica: full, client: client)
119129 @ spec stream ( Phoenix.Sync . shape_definition ( ) , Electric.Client . stream_options ( ) ) :: Enum . t ( )
120130 def stream ( shape , stream_opts \\ [ ] )
121131
122- def stream ( shape , stream_opts ) do
123- stream ( shape , stream_opts , nil )
132+ def stream ( shape , [ ] ) when is_list ( shape ) do
133+ { client , shape } = Keyword . pop_lazy ( shape , :client , & new! / 0 )
134+
135+ { shape , shape_stream_opts } = resolve_shape ( shape )
136+
137+ Electric.Client . stream ( client , shape , shape_stream_opts )
138+ end
139+
140+ def stream ( table , stream_opts ) when is_binary ( table ) and is_list ( stream_opts ) do
141+ stream ( Keyword . put ( stream_opts , :table , table ) , [ ] )
124142 end
125143
126- @ doc false
127- def stream ( shape , stream_opts , sync_opts ) do
128- client = new! ( sync_opts )
144+ def stream ( shape , stream_opts ) when not is_list ( shape ) and is_list ( stream_opts ) do
145+ { client , stream_opts } = Keyword . pop_lazy ( stream_opts , :client , & new! / 0 )
146+
129147 { shape , shape_stream_opts } = resolve_shape ( shape )
130- Electric.Client . stream ( client , shape , Keyword . merge ( shape_stream_opts , stream_opts ) )
148+ stream_opts = Keyword . merge ( shape_stream_opts , stream_opts )
149+ Electric.Client . stream ( client , shape , stream_opts )
131150 end
132151
133152 defp resolve_shape ( table ) when is_binary ( table ) do
0 commit comments