Skip to content

Commit 54de86d

Browse files
committed
Remove legacy schema-related models and refactor schema name strategies
Deleted `SchemaNameUrn`, `MessageBuildersPrototypes`, and removed redundant `GetUriFromChannel` helper in tests. Introduced new schema name strategies (`NamespaceSchemaNameStrategy`, `CategorySchemaNameStrategy`, `MessageSchemaNameStrategy`) and the `ReadDirection` enum for stream navigation. Cleaned up test files and refactored to improve clarity and maintainability. Signed-off-by: Sérgio Silveira <sdsilveira@gmail.com>
1 parent 422f64a commit 54de86d

34 files changed

+1656
-1857
lines changed

CHANGELOG.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@
22

33
All notable changes to the KurrentDB .NET Client will be documented in this file.
44

5-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7-
85
## [Unreleased]
96

10-
### Added
11-
12-
### Changed
13-
14-
### Fixed
15-
16-
### Security
17-
187
## [23.0.0] - 2023-02-08
198

209
### Added

KurrentDB.Client.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kurrent.Grpc", "src\Kurrent
1717
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kurrent.Client", "src\Kurrent.Client\Kurrent.Client.csproj", "{FFB5B486-EEE7-41A6-9CDA-32A522DE1DE2}"
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasterPackage", "src\MasterPackage\MasterPackage.csproj", "{C8C1BB43-96E7-4AB3-87C3-4E17C84FB8C7}"
21-
EndProject
2220
Global
2321
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2422
Debug|x64 = Debug|x64
@@ -56,10 +54,6 @@ Global
5654
{FFB5B486-EEE7-41A6-9CDA-32A522DE1DE2}.Debug|x64.Build.0 = Debug|Any CPU
5755
{FFB5B486-EEE7-41A6-9CDA-32A522DE1DE2}.Release|x64.ActiveCfg = Release|Any CPU
5856
{FFB5B486-EEE7-41A6-9CDA-32A522DE1DE2}.Release|x64.Build.0 = Release|Any CPU
59-
{C8C1BB43-96E7-4AB3-87C3-4E17C84FB8C7}.Debug|x64.ActiveCfg = Debug|Any CPU
60-
{C8C1BB43-96E7-4AB3-87C3-4E17C84FB8C7}.Debug|x64.Build.0 = Debug|Any CPU
61-
{C8C1BB43-96E7-4AB3-87C3-4E17C84FB8C7}.Release|x64.ActiveCfg = Release|Any CPU
62-
{C8C1BB43-96E7-4AB3-87C3-4E17C84FB8C7}.Release|x64.Build.0 = Release|Any CPU
6357
EndGlobalSection
6458
GlobalSection(NestedProjects) = preSolution
6559
EndGlobalSection
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<PackageId>Kurrent.Client</PackageId>
4-
</PropertyGroup>
5-
<ItemGroup>
6-
<PackageReference Include="Google.Protobuf" Version="3.31.0"/>
7-
<PackageReference Include="Grpc.Net.Client" Version="2.71.0"/>
8-
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0"/>
9-
<PackageReference Include="Humanizer.Core" Version="2.14.1"/>
10-
<PackageReference Include="LruCacheNet" Version="1.2.0"/>
11-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5"/>
12-
<PackageReference Include="NJsonSchema" Version="11.3.2"/>
13-
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.3.2"/>
14-
<PackageReference Include="OneOf" Version="3.0.271"/>
15-
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271"/>
16-
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
17-
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0"/>
2+
<PropertyGroup>
3+
<PackageId>Kurrent.Client</PackageId>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="Google.Protobuf" Version="3.31.0" />
7+
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
8+
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0" />
9+
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
10+
<PackageReference Include="LruCacheNet" Version="1.2.0" />
11+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
12+
<PackageReference Include="NJsonSchema" Version="11.3.2" />
13+
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.3.2" />
14+
<PackageReference Include="OneOf" Version="3.0.271" />
15+
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271" />
16+
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
17+
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0" />
1818

19-
<PackageReference Include="Grpc.Tools" Version="2.72.0">
20-
<PrivateAssets>all</PrivateAssets>
21-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22-
</PackageReference>
23-
</ItemGroup>
19+
<PackageReference Include="Grpc.Tools" Version="2.72.0">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
</ItemGroup>
2424

25-
<ItemGroup>
26-
<!-- v2 -->
27-
<Protobuf
28-
ProtoRoot="../../proto/kurrentdb/protocol/v2"
29-
Include="../../proto/kurrentdb/protocol/v2/**/*.proto"
30-
Link="proto\kurrentdb\protocol\v2\%(RecursiveDir)/%(FileName)%(Extension)"
31-
GrpcServices="Client"
32-
Access="internal"
33-
/>
34-
</ItemGroup>
25+
<ItemGroup>
26+
<!-- v2 -->
27+
<Protobuf
28+
ProtoRoot="../../proto/kurrentdb/protocol/v2"
29+
Include="../../proto/kurrentdb/protocol/v2/**/*.proto"
30+
Link="proto\kurrentdb\protocol\v2\%(RecursiveDir)/%(FileName)%(Extension)"
31+
GrpcServices="Client"
32+
Access="internal"
33+
/>
34+
</ItemGroup>
3535

36-
<ItemGroup>
37-
<InternalsVisibleTo Include="Kurrent.Client.Tests.Testing"/>
38-
<InternalsVisibleTo Include="Kurrent.Client.Tests"/>
39-
</ItemGroup>
36+
<ItemGroup>
37+
<InternalsVisibleTo Include="Kurrent.Client.Tests.Testing" />
38+
<InternalsVisibleTo Include="Kurrent.Client.Tests" />
39+
</ItemGroup>
4040

41-
<ItemGroup>
42-
<ProjectReference Include="..\Kurrent.Grpc\Kurrent.Grpc.csproj"/>
43-
</ItemGroup>
41+
<ItemGroup>
42+
<ProjectReference Include="..\Kurrent.Grpc\Kurrent.Grpc.csproj" />
43+
</ItemGroup>
4444
</Project>

src/Kurrent.Grpc/Kurrent.Grpc.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<RootNamespace>Kurrent.Grpc</RootNamespace>
9+
<IsPackable>false</IsPackable>
910
</PropertyGroup>
1011

1112
<ItemGroup>

src/KurrentDB.Client/Client/KurrentDBClientBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Grpc.Core;
2+
using Kurrent.Client;
23
using Kurrent.Client.Model;
34
using Kurrent.Client.SchemaRegistry;
45
using Kurrent.Client.SchemaRegistry.Serialization;
Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,66 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
3-
<PropertyGroup>
4-
<PackageId>KurrentDB.Client</PackageId>
5-
</PropertyGroup>
3+
<PropertyGroup>
4+
<PackageId>KurrentDB.Client</PackageId>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
</PropertyGroup>
67

7-
<ItemGroup>
8-
<PackageReference Include="Google.Protobuf" Version="3.31.0" />
9-
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
10-
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0" />
11-
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
12-
<PackageReference Include="LruCacheNet" Version="1.2.0" />
13-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
14-
<PackageReference Include="NJsonSchema" Version="11.3.2" />
15-
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.3.2" />
16-
<PackageReference Include="OneOf" Version="3.0.271" />
17-
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271" />
18-
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
19-
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0"/>
8+
<ItemGroup>
9+
<PackageReference Include="Google.Protobuf" Version="3.31.0" />
10+
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
11+
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.71.0" />
12+
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
13+
<PackageReference Include="LruCacheNet" Version="1.2.0" />
14+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
15+
<PackageReference Include="NJsonSchema" Version="11.3.2" />
16+
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.3.2" />
17+
<PackageReference Include="OneOf" Version="3.0.271" />
18+
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271" />
19+
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
20+
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0" />
2021

21-
<PackageReference Include="Grpc.Tools" Version="2.72.0">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24-
</PackageReference>
25-
</ItemGroup>
22+
<PackageReference Include="Grpc.Tools" Version="2.72.0">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
</PackageReference>
26+
</ItemGroup>
2627

27-
<ItemGroup>
28-
<!-- v1 -->
29-
<Protobuf
30-
ProtoRoot="../../proto/kurrentdb/protocol/v1"
31-
Include="../../proto/kurrentdb/protocol/v1/**/*.proto"
32-
Link="proto\kurrentdb\protocol\v1\%(RecursiveDir)/%(FileName)%(Extension)"
33-
GrpcServices="Client"
34-
Access="internal"
35-
/>
28+
<ItemGroup>
29+
<!-- v1 -->
30+
<Protobuf
31+
ProtoRoot="../../proto/kurrentdb/protocol/v1"
32+
Include="../../proto/kurrentdb/protocol/v1/**/*.proto"
33+
Link="proto\kurrentdb\protocol\v1\%(RecursiveDir)/%(FileName)%(Extension)"
34+
GrpcServices="Client"
35+
Access="internal"
36+
/>
3637

37-
<!-- v2 -->
38-
<Protobuf
39-
ProtoRoot="../../proto/kurrentdb/protocol/v2"
40-
Include="../../proto/kurrentdb/protocol/v2/**/*.proto"
41-
Link="proto\kurrentdb\protocol\v2\%(RecursiveDir)/%(FileName)%(Extension)"
42-
GrpcServices="Client"
43-
Access="internal"
44-
/>
45-
</ItemGroup>
38+
<!-- v2 -->
39+
<Protobuf
40+
ProtoRoot="../../proto/kurrentdb/protocol/v2"
41+
Include="../../proto/kurrentdb/protocol/v2/**/*.proto"
42+
Link="proto\kurrentdb\protocol\v2\%(RecursiveDir)/%(FileName)%(Extension)"
43+
GrpcServices="Client"
44+
Access="internal"
45+
/>
46+
</ItemGroup>
4647

47-
<ItemGroup>
48-
<InternalsVisibleTo Include="Kurrent.Client"/>
49-
<InternalsVisibleTo Include="Kurrent.Client.Tests"/>
48+
<ItemGroup>
49+
<InternalsVisibleTo Include="Kurrent.Client" />
50+
<InternalsVisibleTo Include="Kurrent.Client.Tests" />
5051

51-
<InternalsVisibleTo Include="KurrentDB.Client.Tests"/>
52-
<InternalsVisibleTo Include="KurrentDB.Client.Tests.Common"/>
53-
<InternalsVisibleTo Include="KurrentDB.Client.Operations.Tests" />
54-
<InternalsVisibleTo Include="KurrentDB.Client.PersistentSubscriptions.Tests" />
55-
<InternalsVisibleTo Include="KurrentDB.Client.ProjectionManagement.Tests" />
56-
<InternalsVisibleTo Include="KurrentDB.Client.Streams.Tests" />
57-
<InternalsVisibleTo Include="KurrentDB.Client.UserManagement.Tests" />
58-
<InternalsVisibleTo Include="KurrentDB.Client.Extensions.OpenTelemetry" />
59-
</ItemGroup>
52+
<InternalsVisibleTo Include="KurrentDB.Client.Tests" />
53+
<InternalsVisibleTo Include="KurrentDB.Client.Tests.Common" />
54+
<InternalsVisibleTo Include="KurrentDB.Client.Operations.Tests" />
55+
<InternalsVisibleTo Include="KurrentDB.Client.PersistentSubscriptions.Tests" />
56+
<InternalsVisibleTo Include="KurrentDB.Client.ProjectionManagement.Tests" />
57+
<InternalsVisibleTo Include="KurrentDB.Client.Streams.Tests" />
58+
<InternalsVisibleTo Include="KurrentDB.Client.UserManagement.Tests" />
59+
<InternalsVisibleTo Include="KurrentDB.Client.Extensions.OpenTelemetry" />
60+
</ItemGroup>
6061

61-
<ItemGroup>
62-
<ProjectReference Include="..\Kurrent.Grpc\Kurrent.Grpc.csproj" />
63-
</ItemGroup>
62+
<ItemGroup>
63+
<ProjectReference Include="..\Kurrent.Grpc\Kurrent.Grpc.csproj" />
64+
</ItemGroup>
6465

6566
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ReSharper disable CheckNamespace
2+
3+
namespace Kurrent.Client.Model;
4+
5+
/// <summary>
6+
/// Specifies the direction in which to read data.
7+
/// </summary>
8+
public enum ReadDirection {
9+
/// <summary>
10+
/// Read backwards.
11+
/// </summary>
12+
Backwards = 0,
13+
14+
/// <summary>
15+
/// Read forwards.
16+
/// </summary>
17+
Forwards = 1
18+
}

src/KurrentDB.Client/Modules/V2/SchemaRegistry/ISchemaExporter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ public sealed class SchemaExporter(SystemTextJsonSchemaGeneratorSettings? settin
1414
};
1515

1616
public string Export(Type messageType, SchemaDataFormat dataFormat) {
17-
if (dataFormat != SchemaDataFormat.Json) {
17+
if (dataFormat != SchemaDataFormat.Json)
1818
throw new NotSupportedException($"Unsupported schema data format. Expected {SchemaDataFormat.Json} but got {dataFormat}.");
19-
}
20-
2119

2220
var schema = NJsonSchema.JsonSchema.FromType(messageType, _settings);
21+
2322
return schema.ToJson();
2423
}
2524
}

src/KurrentDB.Client/Modules/V2/SchemaRegistry/KurrentRegistryClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using Grpc.Core;
55
using Kurrent.Client.SchemaRegistry;
66
using KurrentDB.Client;
7+
using Kurrent.Client.Model;
78
using static KurrentDB.Protocol.Registry.V2.SchemaRegistryService;
9+
810
using Contracts = KurrentDB.Protocol.Registry.V2;
911

10-
namespace Kurrent.Client.Model;
12+
namespace Kurrent.Client;
1113

1214
[PublicAPI]
1315
public class KurrentRegistryClient(KurrentDBClientSettings? settings) : KurrentDBClientBase(settings) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Kurrent.Client.SchemaRegistry;
2+
3+
/// <summary>
4+
/// Schema naming strategy that derives the schema name based on a specified
5+
/// category from the stream name and the name of the message type.
6+
/// </summary>
7+
/// <remarks>
8+
/// This strategy uses the first segment of the stream name, separated by a hyphen ('-'),
9+
/// as the namespace identifier and combines it with the name of the message type.
10+
/// A non-empty stream name is required for this strategy to function correctly.
11+
/// </remarks>
12+
/// <param name="format">The format specification for the schema name, determining how the schema name is structured.</param>
13+
/// <exception cref="ArgumentException">Thrown if the stream name is empty or white space.</exception>
14+
public class CategorySchemaNameStrategy(SchemaNameOutputFormat format = SchemaNameOutputFormat.None) : SchemaNameStrategyBase(format) {
15+
protected override (string Namespace, string MessageName) Generate(Type messageType, string streamName) {
16+
if (string.IsNullOrWhiteSpace(streamName))
17+
throw new ArgumentException("Stream name cannot be empty or whitespace", nameof(streamName));
18+
19+
return (streamName.Split('-').First(), messageType.Name);
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Kurrent.Client.SchemaRegistry;
2+
3+
/// <summary>
4+
/// A schema naming strategy that generates schema names based on the type's full name,
5+
/// optionally formatted according to the specified schema name format.
6+
/// </summary>
7+
/// <param name="format">The format specification for the schema name, determining how the schema name is structured.</param>
8+
public class MessageSchemaNameStrategy(bool urnFormat = false) : SchemaNameStrategyBase(urnFormat ? SchemaNameOutputFormat.Urn : SchemaNameOutputFormat.None) {
9+
protected override (string Namespace, string MessageName) Generate(Type messageType, string streamName) {
10+
return (messageType.Namespace!, messageType.Name);
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Kurrent.Client.SchemaRegistry;
2+
3+
/// <summary>
4+
/// Schema naming strategy that generates schema names by combining a fixed namespace identifier with a category derived
5+
/// from the stream name and the message type name.
6+
/// </summary>
7+
public class NamespaceCategorySchemaNameStrategy : SchemaNameStrategyBase {
8+
readonly string _namespaceIdentifier;
9+
10+
/// <summary>
11+
/// Schema naming strategy that generates schema names by combining a fixed namespace identifier with a category derived
12+
/// from the stream name and the message type name.
13+
/// </summary>
14+
public NamespaceCategorySchemaNameStrategy(string namespaceIdentifier, SchemaNameOutputFormat format = SchemaNameOutputFormat.None) : base(format) {
15+
if (string.IsNullOrWhiteSpace(namespaceIdentifier))
16+
throw new ArgumentException("Namespace Identifier cannot be null or whitespace", nameof(namespaceIdentifier));
17+
18+
_namespaceIdentifier = namespaceIdentifier;
19+
}
20+
21+
protected override (string Namespace, string MessageName) Generate(Type messageType, string streamName) {
22+
if (string.IsNullOrWhiteSpace(streamName))
23+
throw new ArgumentException("Stream name cannot be empty or whitespace", nameof(streamName));
24+
25+
return ($"{_namespaceIdentifier}.{streamName.Split('-').First()}", messageType.Name);
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace Kurrent.Client.SchemaRegistry;
2+
3+
/// <summary>
4+
/// A schema naming strategy that uses the provided namespace identifier combined with the message type name
5+
/// to generate a unique schema name.
6+
/// </summary>
7+
public class NamespaceSchemaNameStrategy : SchemaNameStrategyBase {
8+
readonly string _namespaceIdentifier;
9+
10+
/// <summary>
11+
/// A schema naming strategy that uses the provided namespace identifier combined with the message type name
12+
/// to generate a unique schema name.
13+
/// </summary>
14+
/// <param name="namespaceIdentifier">The fixed namespace identifier to be used as part of the schema name.</param>
15+
/// <param name="format">The format specification for the schema name, determining how the schema name is structured.</param>
16+
/// <exception cref="ArgumentException">Thrown if the namespace identifier is empty or white space.</exception>
17+
public NamespaceSchemaNameStrategy(string namespaceIdentifier, SchemaNameOutputFormat format = SchemaNameOutputFormat.None) : base(format) {
18+
if (string.IsNullOrWhiteSpace(namespaceIdentifier))
19+
throw new ArgumentException("Namespace Identifier cannot be null or whitespace", nameof(namespaceIdentifier));
20+
21+
_namespaceIdentifier = namespaceIdentifier;
22+
}
23+
24+
protected override (string Namespace, string MessageName) Generate(Type messageType, string streamName) =>
25+
(_namespaceIdentifier, messageType.Name);
26+
}

0 commit comments

Comments
 (0)