Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
<Project>
<!-- https://learn.microsoft.com/nuget/consume-packages/central-package-management -->
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AspNetCore.SignalR.OpenTelemetry" Version="1.8.0" />
<PackageVersion Include="Cocona" Version="2.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.22" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.22" />
<PackageVersion Include="Microsoft.Build" Version="17.11.48" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.10.12" />
<PackageVersion Include="System.Text.Json" Version="10.0.0" />
<PackageVersion Include="Tapper" Version="1.14.0" />
<PackageVersion Include="Tapper.Attributes" Version="1.14.0" />
<PackageVersion Include="TypedSignalR.Client" Version="3.6.0" />
<PackageVersion Include="TypedSignalR.Client.Attributes" Version="1.1.0" />
<PackageVersion Include="TypedSignalR.Client.DevTools" Version="1.2.4" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
<PackageVersion Include="MessagePack" Version="2.5.187" />
<PackageVersion Include="MessagePack.AspNetCoreMvcFormatter" Version="2.5.129" />
</ItemGroup>
</Project>
<!-- https://learn.microsoft.com/nuget/consume-packages/central-package-management -->
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AspNetCore.SignalR.OpenTelemetry" Version="1.8.0" />
<PackageVersion Include="Cocona" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Core" Version="1.2.11" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.14.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.22" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="10.0.7" />
<PackageVersion Include="Microsoft.Build" Version="17.11.48" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.10.12" />
<PackageVersion Include="System.Text.Json" Version="10.0.7" />
<PackageVersion Include="Tapper" Version="1.14.0" />
<PackageVersion Include="Tapper.Attributes" Version="1.14.0" />
<PackageVersion Include="TypedSignalR.Client" Version="3.6.0" />
<PackageVersion Include="TypedSignalR.Client.Attributes" Version="1.1.0" />
<PackageVersion Include="TypedSignalR.Client.DevTools" Version="1.2.4" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
<PackageVersion Include="MessagePack" Version="2.5.187" />
<PackageVersion Include="MessagePack.AspNetCoreMvcFormatter" Version="2.5.129" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ public constructor(
this.Write("\r\n");
foreach(var method in receiverType.Methods) {
this.Write(" connection.on(\"");
this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
this.Write(this.ToStringHelper.ToStringWithCulture(method.GetSignalRMethodName()));
this.Write("\", __");
this.Write(this.ToStringHelper.ToStringWithCulture(method.Name.Format(Options.NamingStyle)));
this.Write(");\r\n");
}
this.Write("\r\n const methodList: ReceiverMethod[] = [\r\n");
for(int i = 0; i < receiverType.Methods.Count; i++) {
this.Write(" { methodName: \"");
this.Write(this.ToStringHelper.ToStringWithCulture(receiverType.Methods[i].Name));
this.Write(this.ToStringHelper.ToStringWithCulture(receiverType.Methods[i].GetSignalRMethodName()));
this.Write("\", method: __");
this.Write(this.ToStringHelper.ToStringWithCulture(receiverType.Methods[i].Name.Format(Options.NamingStyle)));
this.Write(" }");
Expand Down
4 changes: 2 additions & 2 deletions src/TypedSignalR.Client.TypeScript/Templates/ApiTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class <#= receiverType.Name #>_Binder implements ReceiverRegister<<#= receiverTy
<# } #>

<# foreach(var method in receiverType.Methods) { #>
connection.on("<#= method.Name #>", __<#= method.Name.Format(Options.NamingStyle) #>);
connection.on("<#= method.GetSignalRMethodName() #>", __<#= method.Name.Format(Options.NamingStyle) #>);
<# } #>

const methodList: ReceiverMethod[] = [
<# for(int i = 0; i < receiverType.Methods.Count; i++) { #>
{ methodName: "<#= receiverType.Methods[i].Name #>", method: __<#= receiverType.Methods[i].Name.Format(Options.NamingStyle) #> }<#= i != receiverType.Methods.Count - 1 ? "," : "" #>
{ methodName: "<#= receiverType.Methods[i].GetSignalRMethodName() #>", method: __<#= receiverType.Methods[i].Name.Format(Options.NamingStyle) #> }<#= i != receiverType.Methods.Count - 1 ? "," : "" #>
<# } #>
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ namespace TypedSignalR.Client.TypeScript.Templates;

internal static class MethodSymbolExtensions
{
public static string GetSignalRMethodName(this IMethodSymbol methodSymbol)
{
var hubMethodName = methodSymbol
.GetAttributes()
.FirstOrDefault(x =>
x.AttributeClass?.ToDisplayString() ==
"Microsoft.AspNetCore.SignalR.HubMethodNameAttribute");

if (hubMethodName?.ConstructorArguments.Length == 1 &&
hubMethodName.ConstructorArguments[0].Value is string name)
{
return name;
}

return methodSymbol.Name;
}

public static string TranslateReceiverMethodIntoLambdaExpressionSyntax(this IMethodSymbol receiverMethodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
if (receiverMethodSymbol.Parameters.Length == 0)
Expand Down Expand Up @@ -100,39 +117,42 @@ private static string ReturnTypeToTypeScriptString(this IMethodSymbol methodSymb
private static string CreateUnaryMethodString(IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
var name = methodSymbol.Name.Format(options.MethodStyle);
var signalRMethodName = methodSymbol.GetSignalRMethodName();
var parameters = methodSymbol.ParametersToTypeScriptString(specialSymbols, options);
var returnType = methodSymbol.ReturnTypeToTypeScriptString(specialSymbols, options);
var args = methodSymbol.ParametersToTypeScriptArgumentString(specialSymbols, options);

return $@"
public readonly {name} = async ({parameters}): {returnType} => {{
return await this.connection.invoke(""{methodSymbol.Name}""{args});
return await this.connection.invoke(""{signalRMethodName}""{args});
}}";
}

private static string CreateServerToClientStreamingMethodString(IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
var name = methodSymbol.Name.Format(options.MethodStyle);
var signalRMethodName = methodSymbol.GetSignalRMethodName();
var parameters = methodSymbol.ParametersToTypeScriptString(specialSymbols, options);
var returnType = methodSymbol.ReturnTypeToTypeScriptString(specialSymbols, options);
var args = methodSymbol.ParametersToTypeScriptArgumentString(specialSymbols, options);

return $@"
public readonly {name} = ({parameters}): {returnType} => {{
return this.connection.stream(""{methodSymbol.Name}""{args});
return this.connection.stream(""{signalRMethodName}""{args});
}}";
}

private static string CreateClientToServerStreamingMethodString(IMethodSymbol methodSymbol, SpecialSymbols specialSymbols, ITypedSignalRTranspilationOptions options)
{
var name = methodSymbol.Name.Format(options.MethodStyle);
var signalRMethodName = methodSymbol.GetSignalRMethodName();
var parameters = methodSymbol.ParametersToTypeScriptString(specialSymbols, options);
var returnType = methodSymbol.ReturnTypeToTypeScriptString(specialSymbols, options);
var args = methodSymbol.ParametersToTypeScriptArgumentString(specialSymbols, options);

return $@"
public readonly {name} = async ({parameters}): {returnType} => {{
return await this.connection.send(""{methodSymbol.Name}""{args});
return await this.connection.send(""{signalRMethodName}""{args});
}}";
}
}
3 changes: 3 additions & 0 deletions tests/TypeScriptTests/src/json/unary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const testMethod = async () => {
const r1 = await hubProxy.get();
expect(r1).toEqual("TypedSignalR.Client.TypeScript");

const renamed = await hubProxy.getWithCustomName();
expect(renamed).toEqual("HubMethodNameAttribute");

const x = getRandomInt(1000);
const y = getRandomInt(1000);

Expand Down
3 changes: 3 additions & 0 deletions tests/TypeScriptTests/src/msgpack/unary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const testMethod = async () => {
const r1 = await hubProxy.get();
expect(r1).toEqual("TypedSignalR.Client.TypeScript");

const renamed = await hubProxy.getWithCustomName();
expect(renamed).toEqual("HubMethodNameAttribute");

const x = getRandomInt(1000);
const y = getRandomInt(1000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public Task<string> Get()
return Task.FromResult("TypedSignalR.Client.TypeScript");
}

[HubMethodName("UnaryHub_GetWithCustomName")]
public Task<string> GetWithCustomName()
{
_logger.Log(LogLevel.Information, "UnaryHub.GetWithCustomName");

return Task.FromResult("HubMethodNameAttribute");
}

public Task<MyResponseItem[]> RequestArray(MyRequestItem[] array)
{
var buffer = new MyResponseItem[array.Length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MyResponseItem2
public partial interface IUnaryHub
{
Task<string> Get();
[Microsoft.AspNetCore.SignalR.HubMethodName("UnaryHub_GetWithCustomName")]
Task<string> GetWithCustomName();
Task<int> Add(int x, int y);
Task<string> Cat(string x, string y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<ProjectReference Include="..\..\src\TypedSignalR.Client.TypeScript.Attributes\TypedSignalR.Client.TypeScript.Attributes.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" />
</ItemGroup>

</Project>