@@ -6,7 +6,7 @@ use alloc::boxed::Box;
66use alloc:: rc:: Rc ;
77use alloc:: string:: ToString ;
88use alloc:: { string:: String , vec:: Vec } ;
9- use serde:: Serialize ;
9+ use serde:: { Deserialize , Serialize } ;
1010use sqlite:: { ResultCode , Value } ;
1111use sqlite_nostd:: { self as sqlite, ColumnType } ;
1212use sqlite_nostd:: { Connection , Context } ;
@@ -16,15 +16,20 @@ use crate::error::SQLiteError;
1616use super :: streaming_sync:: SyncClient ;
1717use super :: sync_status:: DownloadSyncStatus ;
1818
19+ /// Payload provided by SDKs when requesting a sync iteration.
20+ #[ derive( Default , Deserialize ) ]
21+ pub struct StartSyncStream {
22+ /// Bucket parameters to include in the request when opening a sync stream.
23+ #[ serde( default ) ]
24+ pub parameters : Option < serde_json:: Map < String , serde_json:: Value > > ,
25+ }
26+
1927/// A request sent from a client SDK to the [SyncClient] with a `powersync_control` invocation.
2028pub enum SyncControlRequest < ' a > {
2129 /// The client requests to start a sync iteration.
2230 ///
2331 /// Earlier iterations are implicitly dropped when receiving this request.
24- StartSyncStream {
25- /// Bucket parameters to include in the request when opening a sync stream.
26- parameters : Option < serde_json:: Map < String , serde_json:: Value > > ,
27- } ,
32+ StartSyncStream ( StartSyncStream ) ,
2833 /// The client requests to stop the current sync iteration.
2934 StopSyncStream ,
3035 /// The client is forwading a sync event to the core extension.
@@ -137,13 +142,13 @@ pub fn register(db: *mut sqlite::sqlite3) -> Result<(), ResultCode> {
137142
138143 let op = op. text ( ) ;
139144 let event = match op {
140- "start" => SyncControlRequest :: StartSyncStream {
141- parameters : if payload. value_type ( ) == ColumnType :: Text {
142- Some ( serde_json:: from_str ( payload. text ( ) ) ?)
145+ "start" => SyncControlRequest :: StartSyncStream ( {
146+ if payload. value_type ( ) == ColumnType :: Text {
147+ serde_json:: from_str ( payload. text ( ) ) ?
143148 } else {
144- None
145- } ,
146- } ,
149+ StartSyncStream :: default ( )
150+ }
151+ } ) ,
147152 "stop" => SyncControlRequest :: StopSyncStream ,
148153 "line_text" => SyncControlRequest :: SyncEvent ( SyncEvent :: TextLine {
149154 data : if payload. value_type ( ) == ColumnType :: Text {
0 commit comments