Skip to content

Commit

Permalink
chore: lint prefer using nullish coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianwessel committed Feb 24, 2024
1 parent 2b3b316 commit e542a95
Show file tree
Hide file tree
Showing 70 changed files with 235 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getAllUsersCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetAllUsersOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', '/user')
.setCommandFunction(async function (context, _payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

return users
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const getUserByIdCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetUserByIdOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', 'user/:userId')
.setCommandFunction(async function (context, _payload, parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

const user = users.find((user) => (user.userId = parameter.userId))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1SignUpOutputPayloadSchema)
.exposeAsHttpEndpoint('POST', 'user/signup')
.setCommandFunction(async function (context, payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }

if (result.users?.some((user) => user.email === payload.email)) {
throw new HandledError(StatusCode.BadRequest, 'the user already exists')
Expand All @@ -31,7 +31,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
userId: randomUUID(),
}

const users = result.users || []
const users = result.users ?? []
users.push(user)

await context.states.setState(StateStoreKey.Users, users)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getAllUsersCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetAllUsersOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', '/user')
.setCommandFunction(async function (context, _payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

return users
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const getUserByIdCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetUserByIdOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', 'user/:userId')
.setCommandFunction(async function (context, _payload, parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

const user = users.find((user) => (user.userId = parameter.userId))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1SignUpOutputPayloadSchema)
.exposeAsHttpEndpoint('POST', 'user/signup')
.setCommandFunction(async function (context, payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }

if (result.users?.some((user) => user.email === payload.email)) {
throw new HandledError(StatusCode.BadRequest, 'the user already exists')
Expand All @@ -31,7 +31,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
userId: randomUUID(),
}

const users = result.users || []
const users = result.users ?? []
users.push(user)

await context.states.setState(StateStoreKey.Users, users)
Expand Down
2 changes: 1 addition & 1 deletion examples/kubernetes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const main = async () => {
// set up the eventbridge and start the event bridge
const eventBridge = new AmqpBridge({
spanProcessor,
instanceId: process.env.HOSTNAME || getNewInstanceId(),
instanceId: process.env.HOSTNAME ?? getNewInstanceId(),
url: process.env.AMQP_URL,
})
await eventBridge.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getAllUsersCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetAllUsersOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', '/user')
.setCommandFunction(async function (context, _payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

return users
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const getUserByIdCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetUserByIdOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', 'user/:userId')
.setCommandFunction(async function (context, _payload, parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

const user = users.find((user) => (user.userId = parameter.userId))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1SignUpOutputPayloadSchema)
.exposeAsHttpEndpoint('POST', 'user/signup')
.setCommandFunction(async function (context, payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }

if (result.users?.some((user) => user.email === payload.email)) {
throw new HandledError(StatusCode.BadRequest, 'the user already exists')
Expand All @@ -31,7 +31,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
userId: randomUUID(),
}

const users = result.users || []
const users = result.users ?? []
users.push(user)

await context.states.setState(StateStoreKey.Users, users)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getAllUsersCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetAllUsersOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', '/user')
.setCommandFunction(async function (context, _payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

return users
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const getUserByIdCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1GetUserByIdOutputPayloadSchema)
.exposeAsHttpEndpoint('GET', 'user/:userId')
.setCommandFunction(async function (context, _payload, parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const users = result.users || []
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }
const users = result.users ?? []

const user = users.find((user) => (user.userId = parameter.userId))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
.addOutputSchema(userV1SignUpOutputPayloadSchema)
.exposeAsHttpEndpoint('POST', 'user/signup')
.setCommandFunction(async function (context, payload, _parameter) {
const result: { users?: User[] } = await context.states.getState(StateStoreKey.Users)
const result = (await context.states.getState(StateStoreKey.Users)) as { [StateStoreKey.Users]: User[] | undefined }

if (result.users?.some((user) => user.email === payload.email)) {
throw new HandledError(StatusCode.BadRequest, 'the user already exists')
Expand All @@ -31,7 +31,7 @@ export const signUpCommandBuilder = userV1ServiceBuilder
userId: randomUUID(),
}

const users = result.users || []
const users = result.users ?? []
users.push(user)

await context.states.setState(StateStoreKey.Users, users)
Expand Down
6 changes: 3 additions & 3 deletions examples/nats-bridge/src/types/StateStoreKey.enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum StateStoreKey {
Users = 'users',
}
export const StateStoreKey = {
Users: 'users',
} as const
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scripts": {
"start": "npm run dev -w examples/fullexample",
"build": "npm run build --workspaces --if-present",
"lint": "eslint . --cache . --fix",
"lint:fix": "eslint . --cache .",
"lint": "eslint . --cache .",
"lint:fix": "eslint . --cache . --fix",
"test": "vitest -c vite.config.all.ts",
"test:unit": "vitest -c vite.config.ts",
"test:integration": "vitest -c vite.config.integration.ts",
Expand Down
18 changes: 9 additions & 9 deletions packages/amqpbridge/src/AmqpBridge.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement
async start() {
await super.start()
try {
this.connection = await amqplib.connect(this.config.url || getDefaultConfig().url, this.config.socketOptions)
this.connection = await amqplib.connect(this.config.url ?? getDefaultConfig().url, this.config.socketOptions)
} catch (err) {
this.emit(EventBridgeEventNames.EventbridgeConnectionError, err)
this.logger.fatal({ err }, 'unable to connect to broker')
Expand Down Expand Up @@ -173,13 +173,13 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement

this.logger.debug('ensured: default exchange')
await this.channel.assertExchange(
this.config.exchangeName || getDefaultConfig().exchangeName,
this.config.exchangeName ?? getDefaultConfig().exchangeName,
'headers',
this.config.exchangeOptions,
)
const responseQueue = await this.channel.assertQueue('', { exclusive: true, autoDelete: true, durable: false })
this.replyQueueName = responseQueue.queue
await this.channel.bindQueue(this.replyQueueName, this.config.exchangeName || getDefaultConfig().exchangeName, '', {
await this.channel.bindQueue(this.replyQueueName, this.config.exchangeName ?? getDefaultConfig().exchangeName, '', {
'x-match': 'all',
replyTo: this.replyQueueName,
})
Expand Down Expand Up @@ -337,7 +337,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement

const payload = await this.encodeContent(msg, contentType, contentEncoding)

await this.channel.publish(this.config.exchangeName || getDefaultConfig().exchangeName, '', payload, {
await this.channel.publish(this.config.exchangeName ?? getDefaultConfig().exchangeName, '', payload, {
messageId: msg.id,
timestamp: msg.timestamp,
contentType,
Expand Down Expand Up @@ -446,7 +446,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement

const content = await this.encodeContent(command, 'application/json', 'utf-8')

this.channel.publish(this.config.exchangeName || getDefaultConfig().exchangeName, '', content, {
this.channel.publish(this.config.exchangeName ?? getDefaultConfig().exchangeName, '', content, {
messageId: command.id,
timestamp: command.timestamp,
correlationId: command.correlationId,
Expand Down Expand Up @@ -483,7 +483,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement

const channel = await this.connection.createChannel()

const noAck = eventBridgeConfig.autoacknowledge === undefined ? true : eventBridgeConfig.autoacknowledge
const noAck = eventBridgeConfig.autoacknowledge ?? true

channel.on('close', () => {
this.healthy = false
Expand All @@ -498,7 +498,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement
})

const queue = await channel.assertQueue(queueName, { durable: !!eventBridgeConfig.durable, autoDelete: true })
await channel.bindQueue(queue.queue, this.config.exchangeName || getDefaultConfig().exchangeName, '', {
await channel.bindQueue(queue.queue, this.config.exchangeName ?? getDefaultConfig().exchangeName, '', {
'x-match': 'all',
messageType: EBMessageType.Command,
receiverServiceName: address.serviceName,
Expand Down Expand Up @@ -575,7 +575,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement

const payload = await this.encodeContent(responseMessage, contentType, contentEncoding)

this.channel?.publish(this.config.exchangeName || getDefaultConfig().exchangeName, '', payload, {
this.channel?.publish(this.config.exchangeName ?? getDefaultConfig().exchangeName, '', payload, {
messageId: responseMessage.id,
timestamp: responseMessage.timestamp,
correlationId: msg.properties.correlationId,
Expand Down Expand Up @@ -686,7 +686,7 @@ export class AmqpBridge extends EventBridgeBaseClass<AmqpBridgeConfig> implement
})

const queue = await channel.assertQueue(queueName, queueOptions)
await channel.bindQueue(queue.queue, this.config.exchangeName || getDefaultConfig().exchangeName, '', {
await channel.bindQueue(queue.queue, this.config.exchangeName ?? getDefaultConfig().exchangeName, '', {
'x-match': 'all',
messageType: subscription.messageType,
senderServiceName: subscription.sender?.serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class HttpEventBridge<CustomConfig extends HttpEventBridgeConfig>
...config,
}

super(conf.name || 'HttpEventBridge', conf)
super(conf.name ?? 'HttpEventBridge', conf)

this.client = client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getCommandHandler = function (
{ kind: SpanKind.CONSUMER },
parentContext,
async (span) => {
const hostname = process.env.HOSTNAME || 'unknown'
const hostname = process.env.HOSTNAME ?? 'unknown'
span.setAttribute(SemanticAttributes.HTTP_URL, c.req.url || '')
span.setAttribute(SemanticAttributes.HTTP_METHOD, c.req.method || '')
span.setAttribute(SemanticAttributes.HTTP_HOST, hostname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getCommandHandlerRestApi = function (
{ kind: SpanKind.CONSUMER },
parentContext,
async (span) => {
const hostname = process.env.HOSTNAME || 'unknown'
const hostname = process.env.HOSTNAME ?? 'unknown'
span.setAttribute(SemanticAttributes.HTTP_URL, c.req.url || '')
span.setAttribute(SemanticAttributes.HTTP_METHOD, c.req.method || '')
span.setAttribute(SemanticAttributes.HTTP_HOST, hostname)
Expand All @@ -67,7 +67,7 @@ export const getCommandHandlerRestApi = function (

let body: unknown
if (c.req.method === 'POST' || c.req.method === 'PUT' || c.req.method === 'PATCH') {
const contentType = metadata.expose.contentTypeRequest || 'application/json'
const contentType = metadata.expose.contentTypeRequest ?? 'application/json'

body = contentType.toLowerCase() === 'application/json' ? await c.req.json() : await c.req.text()
}
Expand All @@ -79,8 +79,8 @@ export const getCommandHandlerRestApi = function (
messageType: EBMessageType.Command,
correlationId: '',
timestamp: Date.now(),
contentType: metadata.expose.contentTypeResponse || 'application/json',
contentEncoding: metadata.expose.contentEncodingResponse || 'utf-8',
contentType: metadata.expose.contentTypeResponse ?? 'application/json',
contentEncoding: metadata.expose.contentEncodingResponse ?? 'utf-8',
otp: serializeOtp(),
receiver: {
...address,
Expand Down Expand Up @@ -131,7 +131,7 @@ export const getCommandHandlerRestApi = function (
statusText: getErrorMessageForCode(status),
headers: {
'content-type': `${metadata.expose.contentTypeResponse} || 'application/json'; charset=${
metadata.expose.contentEncodingResponse || 'utf-8'
metadata.expose.contentEncodingResponse ?? 'utf-8'
}`,
},
})
Expand All @@ -154,7 +154,7 @@ export const getCommandHandlerRestApi = function (
statusText: getErrorMessageForCode(status),
headers: {
'content-type': `${metadata.expose.contentTypeResponse} || 'application/json'; charset=${
metadata.expose.contentEncodingResponse || 'utf-8'
metadata.expose.contentEncodingResponse ?? 'utf-8'
}`,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getSubscriptionHandler = function (
{ kind: SpanKind.CONSUMER },
parentContext,
async (span) => {
const hostname = process.env.HOSTNAME || 'unknown'
const hostname = process.env.HOSTNAME ?? 'unknown'
span.setAttribute(SemanticAttributes.HTTP_URL, c.req.url || '')
span.setAttribute(SemanticAttributes.HTTP_METHOD, c.req.method || '')
span.setAttribute(SemanticAttributes.HTTP_HOST, hostname)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/helper/installInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const getServiceVersions = (startFolder: string, serviceName: string) => {
service.version = parseInt(versionInfo[1])
service.path = path.join(serviceName, path.basename(file))

service.builderFile = getBuilderFile(name) || ''
service.serviceFile = getServiceFile(name) || ''
service.builderFile = getBuilderFile(name) ?? ''
service.serviceFile = getServiceFile(name) ?? ''
}
} else {
const infoName = path.basename(file)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/DefaultLogger/DefaultLogger.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class DefaultLogger extends Logger implements ILogger {
const parameter: LoggerOptions = {
...options,
name: undefined,
module: options.module || options.name || prefix.join('-'),
module: options.module ?? options.name ?? prefix.join('-'),
}

const child = this.log.child(parameter)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/HttpClient/HttpClient.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class HttpClient<CustomConfig extends Record<string, unknown> = {}> imple
const name = config.name ?? this.name
this.name = name

const logger = config.logger?.getChildLogger({ name }) || initLogger(config.logLevel, { name })
const logger = config.logger?.getChildLogger({ name }) ?? initLogger(config.logLevel, { name })

this.config = {
logger,
Expand Down Expand Up @@ -137,7 +137,7 @@ export class HttpClient<CustomConfig extends Record<string, unknown> = {}> imple

const url = new URL(fullPath, this.baseUrl)

for (const [key, value] of Object.entries(options?.query || {})) {
for (const [key, value] of Object.entries(options?.query ?? {})) {
url.searchParams.set(key, value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,11 @@ export class SubscriptionDefinitionBuilder<
throw new Error(`SubscriptionDefinitionBuilder: missing function implementation for ${this.subscriptionName}`)
}

const inputPayloadSchema: Schema | undefined = this.hooks.transformInput?.transformInputSchema || this.inputSchema
const inputPayloadSchema: Schema | undefined = this.hooks.transformInput?.transformInputSchema ?? this.inputSchema
const inputParameterSchema: Schema | undefined =
this.hooks.transformInput?.transformParameterSchema || this.parameterSchema
this.hooks.transformInput?.transformParameterSchema ?? this.parameterSchema
const outputPayloadSchema: Schema | undefined =
this.hooks.transformOutput?.transformOutputSchema || this.outputSchema
this.hooks.transformOutput?.transformOutputSchema ?? this.outputSchema

const eventBridgeConfig: Complete<DefinitionEventBridgeConfig> = {
durable: this.durable,
Expand Down
Loading

0 comments on commit e542a95

Please sign in to comment.