-
Notifications
You must be signed in to change notification settings - Fork 6
Implement sync client #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simolus3
wants to merge
38
commits into
main
Choose a base branch
from
sync-state-machine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rkistner
reviewed
Apr 23, 2025
756f514
to
2ba3209
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the sync client logic in the core extension. Client SDKs will still be responsible for opening sockets to the sync service, but the core extension is now responsible for driving that logic. The central interface here is the
powersync_control
SQL function, which is invoked by clients for a request to start a sync stream or lines received by the sync service. In response, the core extension responds with a list of instruction for the SDK (like e.g. updating the sync status).We expect that implementing the stream client here will:
The most important are structured like this:
core/src/bson
contains a no-std implementation of the BSON format with serde support. Thebson
crate unfortunately only supports std environments and I couldn't find a decent alternative. We don't support all BSON types, but that should be fine since we only need the types supported by JSON (as well as byte arrays).core/src/sync
contains logic to implement the sync client:line.rs
defines the sync lines as structs supporting deserialization.storage_adapter.rs
is used as an interface for some common database operations. It's a bit simpler than theBucketStorage
interface in the SDK since we can mostly just call other core functions directly without going through SQL.sync_status.rs
implements theSyncStatus
interface from our other SDKs and logic to update it along with sending update notifications to the client.interface.rs
defines thepowersync_control
SQL function driving the sync client.streaming_sync.rs
contains the actual state machine for the sync client. I've implemented it as an async coroutine that is polled every timepowersync_control
is called, which allows an implementation that looks similar to the ones across our other SDKs.