Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Wikström committed Aug 15, 2022
1 parent aa8b3d5 commit d22057e
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 113 deletions.
2 changes: 1 addition & 1 deletion components/Consumers.js
@@ -1,7 +1,7 @@
import { toPascalCase } from '../utils/common';

export function Consumers({ channels }) {
if (channels?.length == 0) {
if (channels.length === 0) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion components/Publishers.js
@@ -1,7 +1,7 @@
import { toPascalCase } from '../utils/common';

export function Publishers({ channels }) {
if (channels?.length == 0) {
if (channels.length === 0) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions components/Worker.js
Expand Up @@ -11,8 +11,8 @@ namespace ${params.namespace}
{
/// <summary>
/// Generated worker for ${asyncapi.info().title()}, ${asyncapi
.info()
.version()}
.info()
.version()}
/// </summary>
public class Worker : BackgroundService
{
Expand Down
20 changes: 10 additions & 10 deletions components/templates/amqpservice.interface.js
Expand Up @@ -8,32 +8,32 @@ namespace ${params.namespace}.Services.Interfaces;
public interface IAmqpService : IDisposable
{
${publishers
.map(
(publisher) => `
.map(
(publisher) => `
/// <summary>
/// Operations from async api specification
/// </summary>
/// <param name="message">The message to be handled by this amqp operation</param>
void ${toPascalCase(publisher.operationId)}(${
publisher.messageType
} message);
publisher.messageType
} message);
`
)
.join('')}
)
.join('')}
${consumers
.map(
(consumer) => `
.map(
(consumer) => `
/// <summary>
/// Operations from async api specification
/// </summary>
/// <param name="message">The message to be handled by this amqp operation</param>
void ${toPascalCase(consumer.operationId)}();
`
)
.join('')}
)
.join('')}
}`;

export function IAmqpService({ asyncapi, params }) {
Expand Down
48 changes: 24 additions & 24 deletions components/templates/amqpservice.js
Expand Up @@ -31,8 +31,8 @@ namespace ${params.namespace}.Services;
/// <summary>
/// Generated consumer for ${asyncapi.info().title()}, ${asyncapi
.info()
.version()}
.info()
.version()}
/// </summary>
public class AmqpService : IAmqpService
{
Expand Down Expand Up @@ -60,21 +60,21 @@ public class AmqpService : IAmqpService
}
${publishers
.map(
(publisher) => `/// <summary>
.map(
(publisher) => `/// <summary>
/// Operations from async api specification
/// </summary>
/// <param name="message">The message to be handled by this amqp operation</param>
public void ${toPascalCase(publisher.operationId)}(${
publisher.messageType
} message)
publisher.messageType
} message)
{
var exchange = "${publisher.exchange}";
var routingKey = "${publisher.routingKey}";
var channel = _channelPool.GetChannel("${toPascalCase(
publisher.operationId
)}");
publisher.operationId
)}");
var exchangeProps = new Dictionary<string, object>
{
{"CC", "${publisher.cc}"},
Expand All @@ -99,8 +99,8 @@ public class AmqpService : IAmqpService
props.Expiration = "${publisher.expiration}";
_logger.Verbose("Sending message {@${
publisher.messageType
}} with correlation id {CorrelationId}",
publisher.messageType
}} with correlation id {CorrelationId}",
message,
props.CorrelationId);
Expand All @@ -114,17 +114,17 @@ public class AmqpService : IAmqpService
}
`
)
.join('')}
)
.join('')}
${consumers
.map(
(consumer) => `public void ${toPascalCase(consumer.operationId)}()
.map(
(consumer) => `public void ${toPascalCase(consumer.operationId)}()
{
var queue = "${consumer.queue}"; // queue from specification
var channel = _channelPool.GetChannel("${toPascalCase(
consumer.operationId
)}");
consumer.operationId
)}");
// TODO: declare passive?
channel.QueueDeclare(queue);
Expand All @@ -138,11 +138,11 @@ public class AmqpService : IAmqpService
{
var body = ea.Body.ToArray();
var message = JsonSerializer.Deserialize<${
consumer.messageType
}>(Encoding.UTF8.GetString(body));
consumer.messageType
}>(Encoding.UTF8.GetString(body));
_logger.Verbose("${toPascalCase(
consumer.messageType
)} received, {@${toPascalCase(consumer.messageType)}}", message);
consumer.messageType
)} received, {@${toPascalCase(consumer.messageType)}}", message);
try
{
Expand All @@ -153,8 +153,8 @@ public class AmqpService : IAmqpService
catch (Exception e)
{
_logger.Error(e, "Something went wrong trying to process message {@${toPascalCase(
consumer.messageType
)}},", message);
consumer.messageType
)}},", message);
channel.BasicReject(ea.DeliveryTag, false);
}
};
Expand All @@ -164,8 +164,8 @@ public class AmqpService : IAmqpService
consumer: consumer);
}
`
)
.join('')}
)
.join('')}
public void Dispose()
{
Expand Down
8 changes: 4 additions & 4 deletions components/templates/channelpool.js
Expand Up @@ -53,20 +53,20 @@ public class ChannelPool : IChannelPool
// creating producer channels
${publishers.map(
(publisher) => `_channels.Add(
(publisher) => `_channels.Add(
"${toPascalCase(publisher.operationId)}",
CreateChannel(connection));`
)}
)}
// creating consumer channels
${consumers.map(
(consumer) => `_channels.Add(
(consumer) => `_channels.Add(
"${toPascalCase(consumer.operationId)}",
CreateChannel(
connection,
${consumer.prefetchCount},
${consumer.confirm}));`
)}
)}
}
Expand Down
4 changes: 0 additions & 4 deletions template/src/Services/Interfaces/iamqpservice.js
Expand Up @@ -2,10 +2,6 @@ import { File, render } from '@asyncapi/generator-react-sdk';
import { IAmqpService } from '../../../../components/templates/amqpservice.interface';

export default function ({ asyncapi, params }) {
// if (!asyncapi.hasComponents()) {
// return null;
// }

return (
<File name="IAmqpService.cs">
{render(<IAmqpService asyncapi={asyncapi} params={params} />)}
Expand Down
4 changes: 0 additions & 4 deletions template/src/Services/Interfaces/ichannelpool.js
Expand Up @@ -2,10 +2,6 @@ import { File, render } from '@asyncapi/generator-react-sdk';
import { IChannelPool } from '../../../../components/templates/channelpool.interface';

export default function ({ asyncapi, params }) {
// if (!asyncapi.hasComponents()) {
// return null;
// }

return (
<File name="IChannelPool.cs">
{render(<IChannelPool asyncapi={asyncapi} params={params} />)}
Expand Down
4 changes: 0 additions & 4 deletions template/src/Services/amqpservice.js
Expand Up @@ -2,10 +2,6 @@ import { File, render } from '@asyncapi/generator-react-sdk';
import { AmqpService } from '../../../components/templates/amqpservice';

export default function ({ asyncapi, params }) {
// if (!asyncapi.hasComponents()) {
// return null;
// }

return (
<File name="AmqpService.cs">
{render(<AmqpService asyncapi={asyncapi} params={params} />)}
Expand Down
4 changes: 0 additions & 4 deletions template/src/Services/channelpool.js
Expand Up @@ -2,10 +2,6 @@ import { File, render } from '@asyncapi/generator-react-sdk';
import { ChannelPool } from '../../../components/templates/channelpool';

export default function ({ asyncapi, params }) {
// if (!asyncapi.hasComponents()) {
// return null;
// }

return (
<File name="ChannelPool.cs">
{render(<ChannelPool asyncapi={asyncapi} params={params} />)}
Expand Down
8 changes: 4 additions & 4 deletions template/src/appconfig.js
Expand Up @@ -18,7 +18,7 @@ export default function({ asyncapi, params }) {

const server = Object.entries(asyncapi.servers())
.map(([serverName, server]) => {
if(serverName === params.server){
if (serverName === params.server) {
return server.url();
}
})
Expand All @@ -27,8 +27,8 @@ export default function({ asyncapi, params }) {
// Notice that root component is the `File` component.
return (
<File name="appsettings.json">
{
`{
{
`{
"Serilog": {
"MinimumLevel": {
"Default": "Verbose",
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function({ asyncapi, params }) {
"Host": "${server}"
}
}`
}
}
</File>
);
}
8 changes: 4 additions & 4 deletions template/src/docker.js
Expand Up @@ -7,7 +7,7 @@ export default function({ asyncapi, params }) {

return (
<File name="Dockerfile">
{`FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
{`FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
Expand All @@ -31,7 +31,7 @@ WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "${params.namespace}.dll"]`
}
</File>
);
}
</File>
);
}
8 changes: 4 additions & 4 deletions template/src/program.js
Expand Up @@ -7,7 +7,7 @@ export default function({ asyncapi, params }) {

return (
<File name="Program.cs">
{`using Masking.Serilog;
{`using Masking.Serilog;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -37,7 +37,7 @@ namespace ${params.namespace}
});
}
}`
}
</File>
);
}
</File>
);
}
8 changes: 4 additions & 4 deletions template/src/project.js
Expand Up @@ -7,7 +7,7 @@ export default function({ asyncapi, params }) {

return (
<File name={`${params.namespace}.csproj`}>
{`<Project Sdk="Microsoft.NET.Sdk.Web">
{`<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
Expand All @@ -23,7 +23,7 @@ export default function({ asyncapi, params }) {
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.0" />
</ItemGroup>
</Project>`
}
</File>
);
}
</File>
);
}
8 changes: 4 additions & 4 deletions template/src/startup.js
Expand Up @@ -7,7 +7,7 @@ export default function({ asyncapi, params }) {

return (
<File name="Startup.cs">
{`using Microsoft.AspNetCore.Builder;
{`using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace ${params.namespace}
}
}
}`
}
</File>
);
}
</File>
);
}

0 comments on commit d22057e

Please sign in to comment.