@@ -3,6 +3,11 @@ import 'package:meta/meta.dart';
33
44/// Options that affect how the sync client connects to the sync service.
55final class SyncOptions {
6+ /// A map of application metadata that is passed to the PowerSync service.
7+ ///
8+ /// Application metadata that will be displayed in PowerSync service logs.
9+ final Map <String , String >? appMetadata;
10+
611 /// A JSON object that is passed to the sync service and forwarded to sync
712 /// rules.
813 ///
@@ -39,19 +44,22 @@ final class SyncOptions {
3944 this .params,
4045 this .syncImplementation = SyncClientImplementation .defaultClient,
4146 this .includeDefaultStreams,
47+ this .appMetadata,
4248 });
4349
4450 SyncOptions _copyWith ({
4551 Duration ? crudThrottleTime,
4652 Duration ? retryDelay,
4753 Map <String , dynamic >? params,
54+ Map <String , String >? appMetadata,
4855 }) {
4956 return SyncOptions (
5057 crudThrottleTime: crudThrottleTime ?? this .crudThrottleTime,
5158 retryDelay: retryDelay,
5259 params: params ?? this .params,
5360 syncImplementation: syncImplementation,
5461 includeDefaultStreams: includeDefaultStreams,
62+ appMetadata: appMetadata ?? this .appMetadata,
5563 );
5664 }
5765}
@@ -88,14 +96,18 @@ extension type ResolvedSyncOptions(SyncOptions source) {
8896 Duration ? crudThrottleTime,
8997 Duration ? retryDelay,
9098 Map <String , dynamic >? params,
99+ Map <String , String >? appMetadata,
91100 }) {
92101 return ResolvedSyncOptions ((source ?? SyncOptions ())._copyWith (
93102 crudThrottleTime: crudThrottleTime,
94103 retryDelay: retryDelay,
95104 params: params,
105+ appMetadata: appMetadata,
96106 ));
97107 }
98108
109+ Map <String , String > get appMetadata => source.appMetadata ?? const {};
110+
99111 Duration get crudThrottleTime =>
100112 source.crudThrottleTime ?? const Duration (milliseconds: 10 );
101113
@@ -113,13 +125,15 @@ extension type ResolvedSyncOptions(SyncOptions source) {
113125 syncImplementation: other.syncImplementation,
114126 includeDefaultStreams:
115127 other.includeDefaultStreams ?? includeDefaultStreams,
128+ appMetadata: other.appMetadata ?? appMetadata,
116129 );
117130
118131 final didChange = ! _mapEquality.equals (newOptions.params, params) ||
119132 newOptions.crudThrottleTime != crudThrottleTime ||
120133 newOptions.retryDelay != retryDelay ||
121134 newOptions.syncImplementation != source.syncImplementation ||
122- newOptions.includeDefaultStreams != includeDefaultStreams;
135+ newOptions.includeDefaultStreams != includeDefaultStreams ||
136+ ! _mapEquality.equals (newOptions.appMetadata, appMetadata);
123137 return (ResolvedSyncOptions (newOptions), didChange);
124138 }
125139
0 commit comments