Skip to content
Merged
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
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

34 changes: 0 additions & 34 deletions .eslintrc.js

This file was deleted.

81 changes: 81 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import eslint from '@eslint/js'
import tseslint from '@typescript-eslint/eslint-plugin'
import tsparser from '@typescript-eslint/parser'
import stylistic from '@stylistic/eslint-plugin'
import unicorn from 'eslint-plugin-unicorn'
import prettier from 'eslint-plugin-prettier/recommended'
import globals from 'globals'

export default [
{
ignores: ['node_modules/**', 'coverage/**', 'dist/**'],
},
{
files: ['**/*.ts', '**/*.js', '**/*.mjs', '**/*.cjs'],
...eslint.configs.recommended,
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
},
rules: {
'no-undef': 'error',
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
plugins: {
'@typescript-eslint': tseslint,
'@stylistic': stylistic,
unicorn: unicorn,
},
languageOptions: {
parser: tsparser,
parserOptions: {
project: ['./tsconfig.json'],
},
},
rules: {
...tseslint.configs.recommended.rules,
...unicorn.configs.recommended.rules,
'unicorn/no-null': 'off',
'unicorn/filename-case': 'off',
'unicorn/prefer-node-protocol': 'off',
'unicorn/import-style': [
'error',
{
extendDefaultStyles: false,
},
],
'unicorn/prefer-module': 'off',
'@stylistic/semi': ['error', 'never'],
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }],
'@stylistic/no-trailing-spaces': 'error',
'@stylistic/comma-dangle': ['error', 'only-multiline'],
'@stylistic/max-len': [
'error',
{
code: 120,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreRegExpLiterals: true,
ignorePattern: '^import .*',
},
],
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
plugins: {
unicorn: unicorn,
},
rules: {
'unicorn/prefer-module': 'off',
},
},
prettier,
]
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line unicorn/prefer-module,no-undef
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
Expand All @@ -19,6 +18,6 @@ module.exports = {
verbose: true,
setupFiles: ['<rootDir>/test/setup-tests.ts'],
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1'
'@/(.*)': '<rootDir>/src/$1',
},
}
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification-server",
"packageManager": "yarn@4.2.2",
"packageManager": "yarn@4.12.0",
"version": "1.1.0",
"description": "",
"license": "Apache-2.0",
Expand All @@ -15,8 +15,8 @@
"scripts": {
"ci": "run-s --print-name lint:tsc lint:eslint",
"lint": "yarn ci",
"lint:eslint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore",
"lint:eslint:fix": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"lint:eslint": "eslint .",
"lint:eslint:fix": "eslint . --fix",
"lint:prettier": "prettier -c \"./src/**/*.{ts,js}\"",
"lint:prettier:fix": "prettier -w \"./src/**/*.{ts,js}\"",
"lint:tsc": "tsc --noEmit -p tsconfig.json --composite false",
Expand All @@ -29,39 +29,39 @@
"test": "jest --coverage=true --runInBand"
},
"dependencies": {
"@google-cloud/pubsub": "^4.1.1",
"@google-cloud/pubsub": "^5.2.2",
"cookies": "^0.9.1",
"dotenv": "^16.3.1",
"jsonwebtoken": "^9.0.2",
"dotenv": "^17.2.3",
"jsonwebtoken": "^9.0.3",
"reflect-metadata": "^0.2.2",
"typedi": "^0.10.0",
"typescript": "^5.3.3",
"winston": "^3.11.0",
"ws": "^8.16.0"
"typescript": "^5.9.3",
"winston": "^3.19.0",
"ws": "^8.19.0"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^1.5.3",
"@types/cookies": "^0.7.10",
"@types/jest": "^29.5.11",
"@types/jsonwebtoken": "^9.0.5",
"@types/node": "^20.10.8",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^50.0.1",
"jest": "^29.7.0",
"@stylistic/eslint-plugin": "^5.7.1",
"@types/cookies": "^0.9.2",
"@types/jest": "^30.0.0",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^20.19.30",
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.54.0",
"@typescript-eslint/parser": "^8.54.0",
"eslint": "9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-unicorn": "^62.0.0",
"jest": "^30.2.0",
"jest-junit": "^16.0.0",
"nodemon": "^3.0.2",
"nodemon": "^3.1.11",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"rimraf": "^5.0.7",
"ts-jest": "^29.1.1",
"prettier": "^3.8.1",
"rimraf": "^6.1.2",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"tsc": "^2.0.4",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2"
"tslib": "^2.8.1"
}
}
28 changes: 20 additions & 8 deletions src/logger/app-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,31 @@ export default class AppLogger {
formats.push(winston.format.colorize())
}

interface LogInfo extends winston.Logform.TransformableInfo {
timestamp?: string
moduleName?: string
metadata: {
error?: {
stack?: string
}
[key: string]: unknown
}
}

formats.push(
winston.format.printf((info) => {
let out = `${info.timestamp} [${info.moduleName || 'app'}] ${info.level}: ${info.message}`
if (info.metadata.error) {
out = out + ' ' + info.metadata.error
if (info.metadata.error.stack) {
out = out + ' ' + info.metadata.error.stack
const logInfo = info as LogInfo
let out = `${logInfo.timestamp} [${logInfo.moduleName || 'app'}] ${logInfo.level}: ${logInfo.message}`
if (logInfo.metadata.error) {
out = out + ' ' + logInfo.metadata.error
if (logInfo.metadata.error.stack) {
out = out + ' ' + logInfo.metadata.error.stack
}
delete info.metadata.error
delete logInfo.metadata.error
}

if (info.metadata && Object.keys(info.metadata).length > 0) {
out = out + ' ' + JSON.stringify(info.metadata)
if (logInfo.metadata && Object.keys(logInfo.metadata).length > 0) {
out = out + ' ' + JSON.stringify(logInfo.metadata)
}

return out
Expand Down
1 change: 0 additions & 1 deletion test/_mock/mq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const pubSubTopicMock = jest.fn().mockImplementation(() => ({

export const pubSubSubscriptionMock = jest.fn().mockImplementation(() => ({
on: jest.fn().mockImplementation((test: string, function_: (asd: Message) => void) => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
publishedMessage.ack = (): void => {}
function_(publishedMessage)
}),
Expand Down
2 changes: 1 addition & 1 deletion test/server/websocket-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ describe('server/websocket-server test', () => {
})
const userConnection = userConnections.getAllForUser('123')
expect(userConnection.size).toEqual(1)
userConnection.values().next().value.send('hello')
userConnection.values().next().value?.send('hello')
})
})
11 changes: 8 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"ts-node": {
"require": ["tsconfig-paths/register"]
"require": [
"tsconfig-paths/register"
]
},
"compilerOptions": {
"module": "commonjs",
Expand Down Expand Up @@ -34,14 +36,17 @@
"node_modules/@types"
],
"paths": {
"@/*": ["./src/*"],
"@/*": [
"./src/*"
],
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*.ts",
"src/*.d.ts"
"src/*.d.ts",
"test/**/*.ts"
]
}
Loading