Skip to content

Commit 962e1de

Browse files
committed
Added AppMetadata option when calling Connect().
1 parent bce3024 commit 962e1de

7 files changed

Lines changed: 58 additions & 3 deletions

File tree

PowerSync/PowerSync.Common/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# PowerSync.Common Changelog
22

3+
## 0.0.6-alpha.1
4+
- Added ability to specify `AppMetadata` for sync/stream requests.
5+
6+
Note: This requires a PowerSync service version `>=1.17.0` in order for logs to display metadata.
7+
8+
```csharp
9+
db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions
10+
{
11+
// This will be included in PowerSync service logs
12+
AppMetadata = new Dictionary<string, string>
13+
{
14+
{ "app_version", myAppVersion },
15+
16+
}
17+
});
18+
```
19+
320
## 0.0.5-alpha.1
421
- 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()`.
522

PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ public class StreamingSyncImplementationOptions : AdditionalConnectionOptions
6666
public ILogger? Logger { get; init; }
6767
}
6868

69-
public class BaseConnectionOptions(Dictionary<string, object>? parameters = null, SyncClientImplementation? clientImplementation = null)
69+
public class BaseConnectionOptions(Dictionary<string, object>? parameters = null, SyncClientImplementation? clientImplementation = null, Dictionary<string, string>? appMetadata = null)
7070
{
71+
/// <summary>
72+
/// A set of metadata to be included in service logs.
73+
/// </summary>
74+
public Dictionary<string, string>? AppMetadata { get; set; } = appMetadata;
75+
7176
/// <summary>
7277
/// These parameters are passed to the sync rules and will be available under the `user_parameters` object.
7378
/// </summary>
@@ -81,6 +86,9 @@ public class BaseConnectionOptions(Dictionary<string, object>? parameters = null
8186

8287
public class RequiredPowerSyncConnectionOptions : BaseConnectionOptions
8388
{
89+
90+
public new Dictionary<string, string> AppMetadata { get; set; } = new();
91+
8492
public new Dictionary<string, object> Params { get; set; } = new();
8593

8694
public new SyncClientImplementation ClientImplementation { get; set; } = new();
@@ -120,6 +128,7 @@ public class StreamingSyncImplementation : EventStream<StreamingSyncImplementati
120128
{
121129
public static RequiredPowerSyncConnectionOptions DEFAULT_STREAM_CONNECTION_OPTIONS = new()
122130
{
131+
AppMetadata = [],
123132
Params = [],
124133
ClientImplementation = SyncClientImplementation.RUST
125134
};
@@ -405,6 +414,7 @@ protected async Task<StreamingSyncIterationResult> StreamingSyncIteration(Cancel
405414
{
406415
var resolvedOptions = new RequiredPowerSyncConnectionOptions
407416
{
417+
AppMetadata = options?.AppMetadata ?? DEFAULT_STREAM_CONNECTION_OPTIONS.AppMetadata,
408418
Params = options?.Params ?? DEFAULT_STREAM_CONNECTION_OPTIONS.Params,
409419
ClientImplementation = options?.ClientImplementation ?? DEFAULT_STREAM_CONNECTION_OPTIONS.ClientImplementation
410420
};
@@ -581,7 +591,7 @@ async Task HandleInstruction(Instruction instruction)
581591

582592
try
583593
{
584-
await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params }));
594+
await Control(PowerSyncControlCommand.START, JsonConvert.SerializeObject(new { parameters = resolvedOptions.Params, app_metadata = resolvedOptions.AppMetadata }));
585595

586596
notifyCompletedUploads = () =>
587597
{

PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncTypes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class StreamingSyncRequest
6666
[JsonProperty("raw_data")]
6767
public bool RawData { get; set; }
6868

69+
[JsonProperty("app_metadata")]
70+
public Dictionary<string, string>? AppMetadata { get; set; }
71+
6972
[JsonProperty("parameters")]
7073
public Dictionary<string, object>? Parameters { get; set; }
7174

PowerSync/PowerSync.Maui/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# PowerSync.Maui Changelog
22

3+
## 0.0.4-alpha.1
4+
- Upstream PowerSync.Common version bump
5+
- Added ability to specify `AppMetadata` sync/stream requests (see Common changelog).
6+
37
## 0.0.3-alpha.1
48
- Upstream PowerSync.Common version bump
59
- 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()`.

Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public async Task InitializeAsync()
4848
await db.Connect(connector, new PowerSyncConnectionOptions
4949
{
5050
ClientImplementation = SyncClientImplementation.RUST,
51+
AppMetadata = new Dictionary<string, string>
52+
{
53+
{ "app_version", "1.0.0-integration-tests" },
54+
{ "environment", "integration-tests" }
55+
}
5156
});
5257
await db.WaitForFirstSync();
5358
}

demos/CommandLine/CommandLine.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5+
<Version>0.0.1</Version>
56
<TargetFramework>net8.0</TargetFramework>
67
<LangVersion>12</LangVersion>
78
<ImplicitUsings>enable</ImplicitUsings>

demos/CommandLine/Demo.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace CommandLine;
22

3+
using System.Reflection;
34
using CommandLine.Utils;
45
using PowerSync.Common.Client;
56
using PowerSync.Common.Client.Connection;
@@ -96,7 +97,15 @@ static async Task Main()
9697
}
9798
});
9899

99-
await db.Connect(connector);
100+
await db.Connect(connector, new PowerSync.Common.Client.Sync.Stream.PowerSyncConnectionOptions
101+
{
102+
ClientImplementation = PowerSync.Common.Client.Sync.Stream.SyncClientImplementation.RUST,
103+
AppMetadata = new Dictionary<string, string>
104+
{
105+
{ "app_version", GetAppVersion() },
106+
107+
}
108+
});
100109
await db.WaitForFirstSync();
101110

102111
var panel = new Panel(table)
@@ -128,4 +137,10 @@ await AnsiConsole.Live(panel)
128137

129138
Console.WriteLine("\nExited live table. Press any key to exit.");
130139
}
140+
141+
private static string GetAppVersion()
142+
{
143+
var version = Assembly.GetExecutingAssembly().GetName().Version;
144+
return version?.ToString() ?? "unknown";
145+
}
131146
}

0 commit comments

Comments
 (0)