Skip to content

Add support for changeset shapes#70

Merged
magnetised merged 5 commits intomainfrom
changeset-shapes
Aug 13, 2025
Merged

Add support for changeset shapes#70
magnetised merged 5 commits intomainfrom
changeset-shapes

Conversation

@magnetised
Copy link
Contributor

Also clean up the shape definition path, removing Phoenix.Sync from the chain of "things that understand shapes" so now if you change the client's view of a shape it should propagate to Phoenix.Sync without changes

@thruflo
Copy link
Contributor

thruflo commented Aug 11, 2025

What's the status on this? Could an Elixir dev review the implementation?

@magnetised
Copy link
Contributor Author

Bit confusing since the interruptible shapes pr was based off it and has now been merged so this is showing both sets. This is the real pr: a6e5a6b (#70)

Most of the real work was done in the elixir client -- this pr mostly cleans up the shape definition path in phoenix.sync, so that it does less work when defining shapes and uses the client for the heavy lifting. should hopefully remove the need to change the shape definition api in 3 places when it evolves.

@magnetised magnetised requested a review from Copilot August 12, 2025 10:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive support for changeset shapes in Phoenix.Sync, enabling shapes to be defined using Ecto changeset functions alongside existing table and query-based definitions. It also refactors the shape definition path to remove Phoenix.Sync from the chain of shape understanding components, allowing client shape changes to propagate to Phoenix.Sync without requiring changes to the sync system itself.

  • Adds changeset function support for defining shapes from Ecto schemas with validation
  • Implements interruptible shape requests that can be dynamically updated during long-polling
  • Refactors PredefinedShape to use Electric.Client.ShapeDefinition for better separation of concerns

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
test/support/todo.ex Updates changeset function to provide default struct parameter
test/support/controllers/todo_controller.ex Adds controller endpoints demonstrating changeset and interruptible shapes
test/phoenix/sync_test.exs Adds comprehensive tests for shape interruption functionality
test/phoenix/sync/router_test.exs Tests parameterized where clauses in router definitions
test/phoenix/sync/predefined_shape_test.exs New test file for comprehensive PredefinedShape functionality
test/phoenix/sync/controller_test.exs Tests changeset support and interruptible request handling
test/phoenix/sync/client_test.exs Tests Ecto query support with additional shape options
test/phoenix/sync/application_test.exs Minor cleanup of storage path assertions
lib/phoenix/sync/shape_request_registry.ex New registry for managing interruptible shape requests
lib/phoenix/sync/predefined_shape.ex Major refactor to use Electric.Client.ShapeDefinition
lib/phoenix/sync/electric/client_adapter.ex Updates client adapter for new shape handling
lib/phoenix/sync/controller.ex Adds comprehensive interruptible request support
lib/phoenix/sync/client.ex Simplifies shape resolution using PredefinedShape
lib/phoenix/sync/application.ex Adds ShapeRequestRegistry to supervision tree
lib/phoenix/sync.ex Adds interrupt/2 and shape!/2 public API functions

magnetised and others added 3 commits August 12, 2025 11:46
and clean up the shape definition path, removing phoenix.sync from the
chain of "things that understand shapes" so now if you change the
client's view of a shape it should propagate to phoenix.sync without
changes
When building shape params on the server, for example using
`sync_render`, it's useful to be able to respond to database changes
that would cause the shape params to be different.

For example, `/sync/projects` -> looks up posts for user, syncs `where
id IN $userProjectIds`. Then the user joins another thread. Now, ... at
the moment, this can wait until 20s for a long poll to return before the
/sync/projects controller code runs to reconstruct the new shape params
with the new where clause.

What this PR does is provide a
`Phoenix.Sync.interrupt(Projects.Project)` function that other backend
code can call in order to interrupt current long polling requests. This
is similar to using the abort controller with the javascript client.

---------

Co-authored-by: Garry Hill <garry@magnetised.net>
@magnetised magnetised merged commit 02f7958 into main Aug 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants