[Experiment] Lite SDK - SQLite not included #758
Draft
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.
PowerSync Lite SDK - Experimental Package
Overview
This PR demonstrates an experimental SDK (
@powersync/lite-sdk) that provides a lightweight interface to connect to a PowerSync service and interact with its synchronization protocol. This SDK is designed to expose sync bucket and stream operations to agnostic data APIs, such as TanStack DB collections, enabling flexible integration with various data storage solutions.Design Philosophy
This implementation is similar to how Raw Tables work in the main PowerSync SDK. However, instead of funneling operations to SQL
putanddeletestatements, the Lite SDK provides direct access to the operations themselves. This allows users to handle the operations however they please - whether that's applying them to TanStack DB collections, custom databases, in-memory stores, or any other storage solution.Key Features
Architecture
The SDK consists of several key components:
SyncClient
The main interface for synchronizing data with a PowerSync service. It handles:
ConnectorinterfaceBucketStorage
An interface for managing bucket data and synchronization state. The SDK provides:
MemoryBucketStorageImpl: An in-memory implementation for cases where persistence is not requiredBucketStorageto integrate with your preferred storage solutionSyncOperationsHandler
Receives sync operations from the protocol and allows you to apply them to your external data storage. Each operation contains:
type: The table/collection nameid: The row identifierop: The operation type (PUTorREMOVE)data: The operation data (null forREMOVEoperations)Connector
Provides a way to dynamically fetch credentials for authentication, enabling:
Example Usage
System Dependencies
The SDK requires system-level dependencies for HTTP requests, streams, and cryptographic operations. The
DEFAULT_SYSTEM_DEPENDENCIES()function provides a default implementation that uses browser/Node.js globals (fetch,ReadableStream,TextDecoder,crypto).For custom environments (e.g., React Native), you can provide your own implementation.
Current Limitations
The following features are planned but not yet fully implemented:
Sync Status Indicators: The sync status tracking is partially implemented but needs completion. Status updates for connection state, sync progress, and error reporting are not fully functional.
CRUD Functionality: Client-side CRUD operations (create, read, update, delete) that need to be uploaded to the server are not yet fully implemented. The
ps_crudstorage layer exists but is not complete.Sync Streams Support: Support for sync streams is mentioned in the codebase but may need additional implementation work. The checkpoint structure includes streams, but full stream synchronization support may be pending.
Testing
The package includes unit tests demonstrating basic connection functionality. See
packages/lite-sdk/tests/powersync-lite.test.tsfor examples.TODOs