diff --git a/demos/django-todolist/pubspec.lock b/demos/django-todolist/pubspec.lock index ac133247..ead7f88f 100644 --- a/demos/django-todolist/pubspec.lock +++ b/demos/django-todolist/pubspec.lock @@ -262,7 +262,7 @@ packages: path: "../../packages/powersync" relative: true source: path - version: "1.5.0" + version: "1.5.3" powersync_flutter_libs: dependency: "direct overridden" description: diff --git a/demos/supabase-anonymous-auth/pubspec.lock b/demos/supabase-anonymous-auth/pubspec.lock index aad42402..9b694697 100644 --- a/demos/supabase-anonymous-auth/pubspec.lock +++ b/demos/supabase-anonymous-auth/pubspec.lock @@ -318,7 +318,7 @@ packages: path: "../../packages/powersync" relative: true source: path - version: "1.5.0" + version: "1.5.3" powersync_flutter_libs: dependency: "direct overridden" description: diff --git a/demos/supabase-edge-function-auth/pubspec.lock b/demos/supabase-edge-function-auth/pubspec.lock index aad42402..9b694697 100644 --- a/demos/supabase-edge-function-auth/pubspec.lock +++ b/demos/supabase-edge-function-auth/pubspec.lock @@ -318,7 +318,7 @@ packages: path: "../../packages/powersync" relative: true source: path - version: "1.5.0" + version: "1.5.3" powersync_flutter_libs: dependency: "direct overridden" description: diff --git a/demos/supabase-simple-chat/pubspec.lock b/demos/supabase-simple-chat/pubspec.lock index 5f7d683e..62390b64 100644 --- a/demos/supabase-simple-chat/pubspec.lock +++ b/demos/supabase-simple-chat/pubspec.lock @@ -358,7 +358,7 @@ packages: path: "../../packages/powersync" relative: true source: path - version: "1.5.0" + version: "1.5.3" powersync_flutter_libs: dependency: "direct overridden" description: diff --git a/demos/supabase-simple-chat/pubspec.yaml b/demos/supabase-simple-chat/pubspec.yaml index 7f73f8bf..33467f96 100644 --- a/demos/supabase-simple-chat/pubspec.yaml +++ b/demos/supabase-simple-chat/pubspec.yaml @@ -37,7 +37,7 @@ dependencies: supabase_flutter: ^1.10.25 timeago: ^3.6.0 - powersync: ^1.4.2 + powersync: ^1.5.0 path_provider: ^2.1.1 path: ^1.8.3 logging: ^1.2.0 diff --git a/demos/supabase-todolist/ios/Podfile.lock b/demos/supabase-todolist/ios/Podfile.lock index 1be61f39..2b36a5a6 100644 --- a/demos/supabase-todolist/ios/Podfile.lock +++ b/demos/supabase-todolist/ios/Podfile.lock @@ -17,6 +17,8 @@ PODS: - "sqlite3 (3.46.0+1)": - "sqlite3/common (= 3.46.0+1)" - "sqlite3/common (3.46.0+1)" + - "sqlite3/dbstatvtab (3.46.0+1)": + - sqlite3/common - "sqlite3/fts5 (3.46.0+1)": - sqlite3/common - "sqlite3/perf-threadsafe (3.46.0+1)": @@ -25,7 +27,8 @@ PODS: - sqlite3/common - sqlite3_flutter_libs (0.0.1): - Flutter - - sqlite3 (~> 3.46.0) + - "sqlite3 (~> 3.46.0+1)" + - sqlite3/dbstatvtab - sqlite3/fts5 - sqlite3/perf-threadsafe - sqlite3/rtree @@ -74,7 +77,7 @@ SPEC CHECKSUMS: powersync_flutter_libs: 5d6b132a398de442c0853a8b14bfbb62cd4ff5a1 shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 sqlite3: 292c3e1bfe89f64e51ea7fc7dab9182a017c8630 - sqlite3_flutter_libs: 0d611efdf6d1c9297d5ab03dab21b75aeebdae31 + sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586 PODFILE CHECKSUM: f7b3cb7384a2d5da4b22b090e1f632de7f377987 diff --git a/demos/supabase-todolist/pubspec.lock b/demos/supabase-todolist/pubspec.lock index 8e064ecc..8dd98be0 100644 --- a/demos/supabase-todolist/pubspec.lock +++ b/demos/supabase-todolist/pubspec.lock @@ -398,7 +398,7 @@ packages: path: "../../packages/powersync" relative: true source: path - version: "1.5.0" + version: "1.5.3" powersync_attachments_helper: dependency: "direct main" description: diff --git a/packages/powersync/CHANGELOG.md b/packages/powersync/CHANGELOG.md index fce52716..e0c18f20 100644 --- a/packages/powersync/CHANGELOG.md +++ b/packages/powersync/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.5.3 + +- Added support for client parameters when connecting. + ## 1.5.2 - Refactor `waitForFirstSync()` to iterate through the stream and remove the use of a `Future`. diff --git a/packages/powersync/lib/src/powersync_database.dart b/packages/powersync/lib/src/powersync_database.dart index 99e837ad..0dfd96d8 100644 --- a/packages/powersync/lib/src/powersync_database.dart +++ b/packages/powersync/lib/src/powersync_database.dart @@ -77,6 +77,8 @@ class PowerSyncDatabase with SqliteQueries implements SqliteConnection { /// Use [attachedLogger] to propagate logs to [Logger.root] for custom logging. late final Logger logger; + Map? clientParams; + /// Open a [PowerSyncDatabase]. /// /// Only a single [PowerSyncDatabase] per [path] should be opened at a time. @@ -219,7 +221,8 @@ class PowerSyncDatabase with SqliteQueries implements SqliteConnection { /// Throttle time between CRUD operations /// Defaults to 10 milliseconds. - Duration crudThrottleTime = const Duration(milliseconds: 10)}) async { + Duration crudThrottleTime = const Duration(milliseconds: 10), + Map? params}) async { Zone current = Zone.current; Future reconnect() { @@ -228,7 +231,8 @@ class PowerSyncDatabase with SqliteQueries implements SqliteConnection { crudThrottleTime: crudThrottleTime, // The reconnect function needs to run in the original zone, // to avoid recursive lock errors. - reconnect: current.bindCallback(reconnect))); + reconnect: current.bindCallback(reconnect), + params: params)); } await reconnect(); @@ -237,7 +241,9 @@ class PowerSyncDatabase with SqliteQueries implements SqliteConnection { Future _connect( {required PowerSyncBackendConnector connector, required Duration crudThrottleTime, - required Future Function() reconnect}) async { + required Future Function() reconnect, + Map? params}) async { + clientParams = params; await initialize(); // Disconnect if connected @@ -330,8 +336,10 @@ class PowerSyncDatabase with SqliteQueries implements SqliteConnection { return; } - Isolate.spawn(_powerSyncDatabaseIsolate, - _PowerSyncDatabaseIsolateArgs(rPort.sendPort, dbref, retryDelay), + Isolate.spawn( + _powerSyncDatabaseIsolate, + _PowerSyncDatabaseIsolateArgs( + rPort.sendPort, dbref, retryDelay, clientParams), debugName: 'PowerSyncDatabase', onError: errorPort.sendPort, onExit: exitPort.sendPort); @@ -562,8 +570,10 @@ class _PowerSyncDatabaseIsolateArgs { final SendPort sPort; final IsolateConnectionFactory dbRef; final Duration retryDelay; + final Map? parameters; - _PowerSyncDatabaseIsolateArgs(this.sPort, this.dbRef, this.retryDelay); + _PowerSyncDatabaseIsolateArgs( + this.sPort, this.dbRef, this.retryDelay, this.parameters); } Future _powerSyncDatabaseIsolate( @@ -638,7 +648,9 @@ Future _powerSyncDatabaseIsolate( invalidCredentialsCallback: invalidateCredentials, uploadCrud: uploadCrud, updateStream: updateController.stream, - retryDelay: args.retryDelay); + retryDelay: args.retryDelay, + syncParameters: args.parameters); + openedStreamingSync = sync; sync.streamingSync(); sync.statusStream.listen((event) { diff --git a/packages/powersync/lib/src/streaming_sync.dart b/packages/powersync/lib/src/streaming_sync.dart index 71325377..5bc4d0a5 100644 --- a/packages/powersync/lib/src/streaming_sync.dart +++ b/packages/powersync/lib/src/streaming_sync.dart @@ -38,6 +38,8 @@ class StreamingSyncImplementation { final Duration retryDelay; + final Map? syncParameters; + SyncStatus lastStatus = const SyncStatus(); AbortController? _abort; @@ -50,7 +52,8 @@ class StreamingSyncImplementation { this.invalidCredentialsCallback, required this.uploadCrud, required this.updateStream, - required this.retryDelay}) { + required this.retryDelay, + this.syncParameters}) { _client = http.Client(); statusStream = _statusStreamController.stream; } @@ -233,9 +236,9 @@ class StreamingSyncImplementation { initialBucketStates[entry.bucket] = entry.opId; } - final List req = []; + final List buckets = []; for (var entry in initialBucketStates.entries) { - req.add(BucketRequest(entry.key, entry.value)); + buckets.add(BucketRequest(entry.key, entry.value)); } Checkpoint? targetCheckpoint; @@ -243,7 +246,8 @@ class StreamingSyncImplementation { Checkpoint? appliedCheckpoint; var bucketSet = Set.from(initialBucketStates.keys); - var requestStream = streamingSyncRequest(StreamingSyncRequest(req)); + var requestStream = + streamingSyncRequest(StreamingSyncRequest(buckets, syncParameters)); var merged = addBroadcast(requestStream, _localPingController.stream); diff --git a/packages/powersync/lib/src/sync_types.dart b/packages/powersync/lib/src/sync_types.dart index 9dda592a..627d0987 100644 --- a/packages/powersync/lib/src/sync_types.dart +++ b/packages/powersync/lib/src/sync_types.dart @@ -112,15 +112,23 @@ Object? parseStreamingSyncLine(Map line) { class StreamingSyncRequest { List buckets; bool includeChecksum = true; + Map? parameters; - StreamingSyncRequest(this.buckets); + StreamingSyncRequest(this.buckets, this.parameters); - Map toJson() => { - 'buckets': buckets, - 'include_checksum': includeChecksum, - // We want the JSON row data as a string - 'raw_data': true - }; + Map toJson() { + final Map json = { + 'buckets': buckets, + 'include_checksum': includeChecksum, + 'raw_data': true, + }; + + if (parameters != null) { + json['parameters'] = parameters; + } + + return json; + } } class BucketRequest { diff --git a/packages/powersync/pubspec.yaml b/packages/powersync/pubspec.yaml index 071915ca..444649a1 100644 --- a/packages/powersync/pubspec.yaml +++ b/packages/powersync/pubspec.yaml @@ -1,5 +1,5 @@ name: powersync -version: 1.5.2 +version: 1.5.3 homepage: https://powersync.com repository: https://github.com/powersync-ja/powersync.dart description: PowerSync Flutter SDK - keep PostgreSQL databases in sync with on-device SQLite databases.