Skip to content

Split backend connector interface - #484

Merged
simolus3 merged 5 commits into
mainfrom
connector-split
Oct 28, 2026
Merged

simolus3 merged 5 commits into
mainfrom
connector-split

Conversation

@simolus3

@simolus3 simolus3 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

This implements the suggested API simplification discussed here for Dart. Instead of passing a PowerSyncBackendConnector, users can implement Authenticator and MutationUploader interfaces separately. For MutationUploader, a default constructor can also wrap simple callbacks.

Implementing this without breaking existing users requires a bit of creative API design: Dart doesn't have method overloading, so we can't simply add another connect() method taking authenticators and uploaders separately. Instead, this replaces the PowerSyncBackendConnector parameter with ConnectRequest, a new supertype. With dot shorthands, I think this looks okay:

await db.connect(connector: MyBackendConnector()); // continues to work

// With split types
await db.connect(connector: ConnectRequest(
  endpoint: 'https://<...>.powersync.com/',
  authenticator: MyAuthenticator(),
  uploader: MutationUploader((db) async { /* ... */ })
))

// Download only
await db.connect(connector: .downloadOnly(
  endpoint: 'https://<...>.powersync.com/',
  authenticator: MyAuthenticator(),
))

// Upload only
await db.connect(connector: .uploadOnly(MutationUploader((db) async {
  // ...
})))

Splitting the interface makes it easier to get started with PowerSync (one can start with a download-only use case and worry about uploads later), and allows more flexible compositions (e.g. with a default write API uploader and a custom authenticator).

The changes to the streaming sync client are comparable to our other SDKs. Most of this PR deals with the annoying problem that connector methods are also invoked over RPC channels for isolates and web workers. This refactors the InternalConnector interface to split the authenticator / uploader parts as well. In a connect method, we then use two booleans to indicate whether each half is present.

TODOs: A follow-up item is that the new interfaces should also receive abort signals.

AI use: Reviewed with Claude Code.

Comment thread packages/powersync/lib/src/sync/streaming_sync.dart
@simolus3
simolus3 marked this pull request as ready for review October 22, 2026 11:05
@simolus3
simolus3 requested a review from Chriztiaan October 28, 2026 11:53
@simolus3
simolus3 added this pull request to stack #493 October 28, 2026 14:12
@simolus3
simolus3 merged commit 2f5fe1c into main Oct 28, 2026
22 of 24 checks passed
@simolus3
simolus3 deleted the connector-split branch October 28, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants