Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/core/src/sync/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use powersync_sqlite_nostd::bindings::SQLITE_RESULT_SUBTYPE;
use powersync_sqlite_nostd::{self as sqlite, ColumnType};
use powersync_sqlite_nostd::{Connection, Context};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use sqlite::{ResultCode, Value};

use crate::sync::BucketPriority;
Expand All @@ -40,6 +41,8 @@ pub struct StartSyncStream {
/// We will increase the expiry date for those streams at the time we connect and disconnect.
#[serde(default)]
pub active_streams: Rc<Vec<StreamKey>>,
#[serde(default)]
pub app_metadata: Option<Box<RawValue>>,
}

impl StartSyncStream {
Expand All @@ -55,6 +58,7 @@ impl Default for StartSyncStream {
schema: Default::default(),
include_defaults: Self::include_defaults_by_default(),
active_streams: Default::default(),
app_metadata: Default::default(),
}
}
}
Expand Down Expand Up @@ -159,6 +163,8 @@ pub struct StreamingSyncRequest {
pub client_id: String,
pub parameters: Option<serde_json::Map<String, serde_json::Value>>,
pub streams: Rc<StreamSubscriptionRequest>,
#[serde(skip_serializing_if = "Option::is_none")]
pub app_metadata: Option<Box<RawValue>>,
}

#[derive(Debug, Serialize, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/sync/streaming_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ impl StreamingSyncIteration {
client_id: client_id(self.db)?,
parameters: self.options.parameters.take(),
streams: stream_subscriptions.request.clone(),
app_metadata: self.options.app_metadata.take(),
};

event
Expand Down
22 changes: 22 additions & 0 deletions dart/test/sync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ void _syncTests<T>({
});
});

syncTest('app_metadata is passed to EstablishSyncStream request', (_) {
final startInstructions = invokeControlRaw(
'start',
json.encode({
'app_metadata': {'key1': 'value1', 'key2': 'value2'}
}),
);

expect(
startInstructions,
contains(
containsPair(
'EstablishSyncStream',
containsPair(
'request',
containsPair('app_metadata', {'key1': 'value1', 'key2': 'value2'}),
),
),
),
);
});

test('handles connection events', () {
invokeControl('start', null);
expect(invokeControl('connection', 'established'), [
Expand Down