From cfacae9e5da2ba6ac52578db7b50eb7264fb7820 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Sep 2023 23:45:10 +0300 Subject: [PATCH 1/2] chore(deps): bump graphql from 16.8.0 to 16.8.1 (#450) Bumps [graphql](https://github.com/graphql/graphql-js) from 16.8.0 to 16.8.1. - [Release notes](https://github.com/graphql/graphql-js/releases) - [Commits](https://github.com/graphql/graphql-js/compare/v16.8.0...v16.8.1) --- updated-dependencies: - dependency-name: graphql dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 672abb6d..3f717331 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12872,9 +12872,9 @@ "devOptional": true }, "node_modules/graphql": { - "version": "16.8.0", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.0.tgz", - "integrity": "sha512-0oKGaR+y3qcS5mCu1vb7KG+a89vjn06C7Ihq/dDl3jA+A8B3TKomvi3CiEcVLJQGalbu8F52LxkOym7U5sSfbg==", + "version": "16.8.1", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } From 8b99fce0e0bf298d1e754347d028dfee758e2a97 Mon Sep 17 00:00:00 2001 From: Sender Hodik <79198595+senderh55@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:41:19 +0300 Subject: [PATCH 2/2] Logger has been moved and implemented as an internal lib (#449) * Logger has been moved and implemented as an internal lib * Fixing lint issue and removing irrelevant lines in shortener.controller.spec * lint issue fixed in logger * fix: remove buildable target from logger * fix: prettier --------- Co-authored-by: orig <48911144+origranot@users.noreply.github.com> Co-authored-by: orig --- apps/backend/src/app.module.ts | 2 +- .../shortener/shortener.controller.spec.ts | 2 +- .../src/shortener/shortener.controller.ts | 2 +- libs/logger/.eslintrc.json | 18 +++++++++++ libs/logger/README.md | 7 +++++ libs/logger/jest.config.ts | 11 +++++++ libs/logger/project.json | 30 +++++++++++++++++++ libs/logger/src/index.ts | 2 ++ .../logger/src/lib}/logger.module.ts | 0 .../logger/src/lib}/logger.service.spec.ts | 0 .../logger/src/lib}/logger.service.ts | 20 ++++++------- libs/logger/tsconfig.json | 16 ++++++++++ libs/logger/tsconfig.lib.json | 11 +++++++ libs/logger/tsconfig.spec.json | 9 ++++++ tsconfig.base.json | 1 + 15 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 libs/logger/.eslintrc.json create mode 100644 libs/logger/README.md create mode 100644 libs/logger/jest.config.ts create mode 100644 libs/logger/project.json create mode 100644 libs/logger/src/index.ts rename {apps/backend/src/logger => libs/logger/src/lib}/logger.module.ts (100%) rename {apps/backend/src/logger => libs/logger/src/lib}/logger.service.spec.ts (100%) rename {apps/backend/src/logger => libs/logger/src/lib}/logger.service.ts (77%) create mode 100644 libs/logger/tsconfig.json create mode 100644 libs/logger/tsconfig.lib.json create mode 100644 libs/logger/tsconfig.spec.json diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index 63802839..a3dcc2bc 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -4,7 +4,7 @@ import { ThrottlerModule } from '@nestjs/throttler'; import { AuthModule } from './auth/auth.module'; import { AppCacheModule } from './cache/cache.module'; import { AppConfigModule, AppConfigService } from '@reduced.to/config'; -import { AppLoggerModule } from './logger/logger.module'; +import { AppLoggerModule } from '@reduced.to/logger'; import { NovuModule } from './novu/novu.module'; import { PrismaService } from '@reduced.to/prisma'; import { UniqueConstraint } from './shared/decorators/unique/unique.decorator'; diff --git a/apps/backend/src/shortener/shortener.controller.spec.ts b/apps/backend/src/shortener/shortener.controller.spec.ts index c8b35088..c44db0dc 100644 --- a/apps/backend/src/shortener/shortener.controller.spec.ts +++ b/apps/backend/src/shortener/shortener.controller.spec.ts @@ -5,7 +5,7 @@ import { ShortenerController } from './shortener.controller'; import { Test } from '@nestjs/testing'; import { ShortenerDto } from './dto'; import { Request } from 'express'; -import { AppLoggerModule } from '../logger/logger.module'; +import { AppLoggerModule } from '@reduced.to/logger'; describe('ShortenerController', () => { let shortenerController: ShortenerController; diff --git a/apps/backend/src/shortener/shortener.controller.ts b/apps/backend/src/shortener/shortener.controller.ts index 51180aaf..85a06087 100644 --- a/apps/backend/src/shortener/shortener.controller.ts +++ b/apps/backend/src/shortener/shortener.controller.ts @@ -4,7 +4,7 @@ import { ShortenerDto } from './dto'; import { ShortenerService } from './shortener.service'; import { UserContext } from '../auth/interfaces/user-context'; import { OptionalJwtAuthGuard } from '../auth/guards/optional-jwt-auth.guard'; -import { AppLoggerSerivce } from '../logger/logger.service'; +import { AppLoggerSerivce } from '@reduced.to/logger'; @Controller({ path: 'shortener', diff --git a/libs/logger/.eslintrc.json b/libs/logger/.eslintrc.json new file mode 100644 index 00000000..9d9c0db5 --- /dev/null +++ b/libs/logger/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/logger/README.md b/libs/logger/README.md new file mode 100644 index 00000000..116bb4a1 --- /dev/null +++ b/libs/logger/README.md @@ -0,0 +1,7 @@ +# logger + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test logger` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/logger/jest.config.ts b/libs/logger/jest.config.ts new file mode 100644 index 00000000..15a6db0f --- /dev/null +++ b/libs/logger/jest.config.ts @@ -0,0 +1,11 @@ +/* eslint-disable */ +export default { + displayName: 'logger', + preset: '../../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/libs/logger', +}; diff --git a/libs/logger/project.json b/libs/logger/project.json new file mode 100644 index 00000000..74ddc27f --- /dev/null +++ b/libs/logger/project.json @@ -0,0 +1,30 @@ +{ + "name": "logger", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/logger/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/logger/**/*.ts"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/logger/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + } + }, + "tags": [] +} diff --git a/libs/logger/src/index.ts b/libs/logger/src/index.ts new file mode 100644 index 00000000..99729a77 --- /dev/null +++ b/libs/logger/src/index.ts @@ -0,0 +1,2 @@ +export * from './lib/logger.module'; +export * from './lib/logger.service'; diff --git a/apps/backend/src/logger/logger.module.ts b/libs/logger/src/lib/logger.module.ts similarity index 100% rename from apps/backend/src/logger/logger.module.ts rename to libs/logger/src/lib/logger.module.ts diff --git a/apps/backend/src/logger/logger.service.spec.ts b/libs/logger/src/lib/logger.service.spec.ts similarity index 100% rename from apps/backend/src/logger/logger.service.spec.ts rename to libs/logger/src/lib/logger.service.spec.ts diff --git a/apps/backend/src/logger/logger.service.ts b/libs/logger/src/lib/logger.service.ts similarity index 77% rename from apps/backend/src/logger/logger.service.ts rename to libs/logger/src/lib/logger.service.ts index 8080d577..09e10b71 100644 --- a/apps/backend/src/logger/logger.service.ts +++ b/libs/logger/src/lib/logger.service.ts @@ -4,20 +4,18 @@ import { AppConfigService } from '@reduced.to/config'; @Injectable() export class AppLoggerSerivce implements LoggerService { + private readonly logger: Logger; + constructor(private readonly config: AppConfigService) { - if (!this.logger) { - this.logger = new Logger({ - transports: [ - new ConsoleTransport({ - threshold: this.config.getConfig().logger.console.threshold, - }), - ], - }); - } + this.logger = new Logger({ + transports: [ + new ConsoleTransport({ + threshold: this.config.getConfig().logger.console.threshold, + }), + ], + }); } - private readonly logger: Logger; - log = (message: any, ...optionalParams: any[]) => this.logger.info(message, ...optionalParams); error = (message: any, ...optionalParams: any[]) => this.logger.error(message, ...optionalParams); warn = (message: any, ...optionalParams: any[]) => this.logger.warn(message, ...optionalParams); diff --git a/libs/logger/tsconfig.json b/libs/logger/tsconfig.json new file mode 100644 index 00000000..19b9eece --- /dev/null +++ b/libs/logger/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/logger/tsconfig.lib.json b/libs/logger/tsconfig.lib.json new file mode 100644 index 00000000..3f06e802 --- /dev/null +++ b/libs/logger/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], + "include": ["src/**/*.ts"] +} diff --git a/libs/logger/tsconfig.spec.json b/libs/logger/tsconfig.spec.json new file mode 100644 index 00000000..f6d8ffcc --- /dev/null +++ b/libs/logger/tsconfig.spec.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index e1bf2755..30575df6 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,6 +16,7 @@ "baseUrl": ".", "paths": { "@reduced.to/config": ["libs/config/src/index.ts"], + "@reduced.to/logger": ["libs/logger/src/index.ts"], "@reduced.to/prisma": ["libs/prisma/src/index.ts"], "@reduced.to/queue-manager": ["libs/queue-manager/src/index.ts"] }