@@ -12,6 +12,7 @@ use crate::sync::storage_adapter::StorageAdapter;
1212use crate :: sync:: subscriptions:: { StreamKey , apply_subscriptions} ;
1313use alloc:: borrow:: Cow ;
1414use alloc:: boxed:: Box ;
15+ use alloc:: collections:: btree_map:: BTreeMap ;
1516use alloc:: rc:: Rc ;
1617use alloc:: { string:: String , vec:: Vec } ;
1718use powersync_sqlite_nostd:: bindings:: SQLITE_RESULT_SUBTYPE ;
@@ -40,6 +41,19 @@ pub struct StartSyncStream {
4041 /// We will increase the expiry date for those streams at the time we connect and disconnect.
4142 #[ serde( default ) ]
4243 pub active_streams : Rc < Vec < StreamKey > > ,
44+ /// Application metadata to include in the request when opening a sync stream.
45+ ///
46+ /// This should only contain a JSON map of strings.
47+ ///
48+ /// We use `BTreeMap<String, String>` instead of `serde_json::Map<String, serde_json::Value>`
49+ /// (like `parameters` uses) because:
50+ /// 1. It enforces type safety at compile time - values must be strings, not arbitrary JSON
51+ /// 2. It requires no runtime validation to ensure values are strings
52+ /// 3. It serializes to the same JSON format (a map with string values)
53+ /// 4. `serde_json::Map<String, String>` doesn't implement `Serialize`/`Deserialize` - the
54+ /// `serde_json::Map` type only supports `serde_json::Value` as the value type, not `String`
55+ #[ serde( default ) ]
56+ pub app_metadata : Option < BTreeMap < String , String > > ,
4357}
4458
4559impl StartSyncStream {
@@ -55,6 +69,7 @@ impl Default for StartSyncStream {
5569 schema : Default :: default ( ) ,
5670 include_defaults : Self :: include_defaults_by_default ( ) ,
5771 active_streams : Default :: default ( ) ,
72+ app_metadata : Default :: default ( ) ,
5873 }
5974 }
6075}
@@ -159,6 +174,8 @@ pub struct StreamingSyncRequest {
159174 pub client_id : String ,
160175 pub parameters : Option < serde_json:: Map < String , serde_json:: Value > > ,
161176 pub streams : Rc < StreamSubscriptionRequest > ,
177+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
178+ pub app_metadata : Option < BTreeMap < String , String > > ,
162179}
163180
164181#[ derive( Debug , Serialize , PartialEq ) ]
0 commit comments