diff --git a/PowerSync/PowerSync.Common/CHANGELOG.md b/PowerSync/PowerSync.Common/CHANGELOG.md index 4fc0f47..990830e 100644 --- a/PowerSync/PowerSync.Common/CHANGELOG.md +++ b/PowerSync/PowerSync.Common/CHANGELOG.md @@ -1,5 +1,21 @@ # PowerSync.Common Changelog +## 0.0.6-alpha.1 +- Added ability to specify `AppMetadata` for sync/stream requests. + +Note: This requires a PowerSync service version `>=1.17.0` in order for logs to display metadata. + +```csharp +db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions +{ + // This will be included in PowerSync service logs + AppMetadata = new Dictionary + { + { "app_version", myAppVersion }, + } +}); +``` + ## 0.0.5-alpha.1 - Using the latest (0.4.9) version of the core extension, it introduces support for the Rust Sync implementation and also makes it the default - users can still opt out and use the legacy C# sync implementation as option when calling `connect()`. diff --git a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs index 62466cc..34d9132 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs @@ -74,8 +74,13 @@ public class StreamingSyncImplementationOptions : AdditionalConnectionOptions public ILogger? Logger { get; init; } } -public class BaseConnectionOptions(Dictionary? parameters = null, SyncClientImplementation? clientImplementation = null) +public class BaseConnectionOptions(Dictionary? parameters = null, SyncClientImplementation? clientImplementation = null, Dictionary? appMetadata = null) { + /// + /// A set of metadata to be included in service logs. + /// + public Dictionary? AppMetadata { get; set; } = appMetadata; + /// /// These parameters are passed to the sync rules and will be available under the `user_parameters` object. /// @@ -89,6 +94,9 @@ public class BaseConnectionOptions(Dictionary? parameters = null public class RequiredPowerSyncConnectionOptions : BaseConnectionOptions { + + public new Dictionary AppMetadata { get; set; } = new(); + public new Dictionary Params { get; set; } = new(); public new SyncClientImplementation ClientImplementation { get; set; } = new(); @@ -128,6 +136,7 @@ public class StreamingSyncImplementation : EventStream StreamingSyncIteration(Cancel { var resolvedOptions = new RequiredPowerSyncConnectionOptions { + AppMetadata = options?.AppMetadata ?? DEFAULT_STREAM_CONNECTION_OPTIONS.AppMetadata, Params = options?.Params ?? DEFAULT_STREAM_CONNECTION_OPTIONS.Params, ClientImplementation = options?.ClientImplementation ?? DEFAULT_STREAM_CONNECTION_OPTIONS.ClientImplementation }; @@ -611,7 +621,7 @@ async Task HandleInstruction(Instruction instruction) try { - await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params })); + await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params, app_metadata = resolvedOptions.AppMetadata })); notifyCompletedUploads = () => { @@ -682,6 +692,7 @@ protected async Task LegacyStreamingSyncIteration( IncludeChecksum = true, RawData = true, Parameters = resolvedOptions.Params, + AppMetadata = resolvedOptions.AppMetadata, ClientId = clientId } }; diff --git a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs index 6f78059..5502c8d 100644 --- a/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs +++ b/PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs @@ -66,6 +66,9 @@ public class StreamingSyncRequest [JsonProperty("raw_data")] public bool RawData { get; set; } + [JsonProperty("app_metadata")] + public Dictionary? AppMetadata { get; set; } + [JsonProperty("parameters")] public Dictionary? Parameters { get; set; } diff --git a/PowerSync/PowerSync.Maui/CHANGELOG.md b/PowerSync/PowerSync.Maui/CHANGELOG.md index ee6b964..7144d9c 100644 --- a/PowerSync/PowerSync.Maui/CHANGELOG.md +++ b/PowerSync/PowerSync.Maui/CHANGELOG.md @@ -1,5 +1,9 @@ # PowerSync.Maui Changelog +## 0.0.4-alpha.1 +- Upstream PowerSync.Common version bump +- Added ability to specify `AppMetadata` sync/stream requests (see Common changelog). + ## 0.0.3-alpha.1 - Upstream PowerSync.Common version bump - Using the latest (0.4.9) version of the core extension, it introduces support for the Rust Sync implementation and also makes it the default - users can still opt out and use the legacy C# sync implementation as option when calling `connect()`. diff --git a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs index 6e2da0e..1316a7c 100644 --- a/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs +++ b/Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs @@ -50,6 +50,11 @@ public async Task InitializeAsync() await db.Connect(connector, new PowerSyncConnectionOptions { ClientImplementation = SyncClientImplementation.RUST, + AppMetadata = new Dictionary + { + { "app_version", "1.0.0-integration-tests" }, + { "environment", "integration-tests" } + } }); await db.WaitForFirstSync(); } diff --git a/demos/CommandLine/CommandLine.csproj b/demos/CommandLine/CommandLine.csproj index 28c7d9a..b5e0281 100644 --- a/demos/CommandLine/CommandLine.csproj +++ b/demos/CommandLine/CommandLine.csproj @@ -2,6 +2,7 @@ Exe + 0.0.1 net8.0 12 enable diff --git a/demos/CommandLine/Demo.cs b/demos/CommandLine/Demo.cs index 347edd3..2dff5c8 100644 --- a/demos/CommandLine/Demo.cs +++ b/demos/CommandLine/Demo.cs @@ -1,5 +1,6 @@ namespace CommandLine; +using System.Reflection; using CommandLine.Utils; using PowerSync.Common.Client; using PowerSync.Common.Client.Connection; @@ -96,7 +97,14 @@ static async Task Main() } }); - await db.Connect(connector); + await db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions + { + ClientImplementation = PowerSync.Common.Client.Sync.Stream.SyncClientImplementation.RUST, + AppMetadata = new Dictionary + { + { "app_version", GetAppVersion() }, + } + }); await db.WaitForFirstSync(); var panel = new Panel(table) @@ -128,4 +136,10 @@ await AnsiConsole.Live(panel) Console.WriteLine("\nExited live table. Press any key to exit."); } + + private static string GetAppVersion() + { + var version = Assembly.GetExecutingAssembly().GetName().Version; + return version?.ToString() ?? "unknown"; + } } \ No newline at end of file