Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: updated client #72

Merged
merged 14 commits into from
Apr 10, 2023
Merged

v2: updated client #72

merged 14 commits into from
Apr 10, 2023

Conversation

OptimumDev
Copy link
Collaborator

No description provided.

/// <remarks>
/// Default is "Tochka.JsonRpc.Client"
/// </remarks>
public virtual string UserAgent => typeof(JsonRpcClientBase).Namespace!;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, may be cache in static this useless reflection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// <param name="cancellationToken"></param>
/// <returns>Raw HTTP response</returns>
/// <exception cref="System.ArgumentException">When requestUrl starts with '/'</exception>
Task<HttpResponseMessage> Send(string requestUrl, ICall call, CancellationToken cancellationToken);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for what?
if we don't need response - it's a SendNotification, i suppose...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated doc to clarify what is this method for.
Also added simmilar methods for batch, that were missing

default:
var message = $"Expected single response, got [{responseWrapper}]";
Log.LogTrace("Request id [{requestId}] failed: {errorMessage}", request.Id, message);
throw new JsonRpcException(message, context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for inline optimization and standardization prefere to use throw helper method in libs
https://learn.microsoft.com/en-us/dotnet/communitytoolkit/diagnostics/throwhelper
or custom.
it applies to the whole project

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It spoils compiler checks for nullable types and asks for additional break/return statements. Not worth it.

{
var context = CreateContext();
context.WithRequestUrl(requestUrl);
var data = calls.Select(x => x.WithSerializedParams(DataJsonSerializerOptions)).ToList();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suppose list is overkill type for this collection. You don't need mutate this, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Set HttpClient properties from base options
/// </summary>
[ExcludeFromCodeCoverage]
protected internal virtual void InitializeClient(HttpClient client, JsonRpcClientOptionsBase options)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why virtual? for tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace Tochka.JsonRpc.Client.Models;

[PublicAPI]
public interface ISingleJsonRpcResult

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be added later with all other documentation

throw new InvalidOperationException("Can not add batch response when no response is expected");
}

BatchResponse = batchResponse;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to bottom of method

assignation gets lost here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace Tochka.JsonRpc.Client.Models;

[PublicAPI]
public class JsonRpcCallContext : IJsonRpcCallContext

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be seal it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public T? GetResponseOrThrow<T>()
{
switch (response)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch expression instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't possible because of context.WithError call.
Added chaining to context and changed it


public class JsonRpcIdGenerator : IJsonRpcIdGenerator
{
private readonly ILogger<JsonRpcIdGenerator> log;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, this is too much. instal log class for what? One unneeded log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
namespace Tochka.JsonRpc.Common.Models.Id;

public record NullRpcId : IRpcId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be sealed for contract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
namespace Tochka.JsonRpc.Common.Models.Id;

public record NumberRpcId(long Value) : IRpcId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be sealed for contract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
namespace Tochka.JsonRpc.Common.Models.Id;

public record StringRpcId(string Value) : IRpcId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be sealed for contract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="1.0.0" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe depending on an external package with a small number of stars is a bad idea?

Copy link
Collaborator Author

@OptimumDev OptimumDev Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the best variant that exists. Unfortunatly System.Text.Json doesn't support snake_case for two versions of .net already and it will be added only in .net8 (I hope). This library is full copy of PR that Microsoft accepted to System.Text.Json (but not released yet)


<IsPackable>false</IsPackable>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand what's wrong here

@Rast1234 Rast1234 merged commit 698be6c into v2 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants