From 9dc4abb63b3cb3a3d3a86283256c023a84c4dd27 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Tue, 1 Oct 2024 07:34:23 +0200 Subject: [PATCH] feat: add @tsed/platform-log-request --- .husky/pre-commit | 2 +- .../platform/platform-log-request/.npmignore | 8 + .../platform-log-request/package.json | 53 +++++ .../platform/platform-log-request/readme.md | 184 ++++++++++++++++++ .../src/domain/PlatformLogRequestSettings.ts | 28 +++ .../platform-log-request/src/index.ts | 7 + .../PlatformLogRequestFactory.spec.ts | 139 +++++++++++++ .../src/services/PlatformLogRequestFactory.ts | 41 ++++ .../src/utils/defaultAlterLog.spec.ts | 66 +++++++ .../src/utils/defaultAlterLog.ts | 22 +++ .../src/utils/defaultLogResponse.spec.ts | 98 ++++++++++ .../src/utils/defaultLogResponse.ts | 30 +++ .../platform-log-request/tsconfig.esm.json | 26 +++ .../platform-log-request/tsconfig.json | 25 +++ .../platform-log-request/tsconfig.spec.json | 35 ++++ .../platform-log-request/vitest.config.mts | 21 ++ tsconfig.json | 13 +- yarn.lock | 27 +++ 18 files changed, 816 insertions(+), 9 deletions(-) create mode 100644 packages/platform/platform-log-request/.npmignore create mode 100644 packages/platform/platform-log-request/package.json create mode 100644 packages/platform/platform-log-request/readme.md create mode 100644 packages/platform/platform-log-request/src/domain/PlatformLogRequestSettings.ts create mode 100644 packages/platform/platform-log-request/src/index.ts create mode 100644 packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.spec.ts create mode 100644 packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.ts create mode 100644 packages/platform/platform-log-request/src/utils/defaultAlterLog.spec.ts create mode 100644 packages/platform/platform-log-request/src/utils/defaultAlterLog.ts create mode 100644 packages/platform/platform-log-request/src/utils/defaultLogResponse.spec.ts create mode 100644 packages/platform/platform-log-request/src/utils/defaultLogResponse.ts create mode 100644 packages/platform/platform-log-request/tsconfig.esm.json create mode 100644 packages/platform/platform-log-request/tsconfig.json create mode 100644 packages/platform/platform-log-request/tsconfig.spec.json create mode 100644 packages/platform/platform-log-request/vitest.config.mts diff --git a/.husky/pre-commit b/.husky/pre-commit index 49088de7558..a644cbfbb5e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx lint-staged $1 +yarn lint-staged $1 diff --git a/packages/platform/platform-log-request/.npmignore b/packages/platform/platform-log-request/.npmignore new file mode 100644 index 00000000000..672ed765244 --- /dev/null +++ b/packages/platform/platform-log-request/.npmignore @@ -0,0 +1,8 @@ +src +test +coverage +tsconfig.json +tsconfig.*.json +__mock__ +*.spec.js +*.tsbuildinfo diff --git a/packages/platform/platform-log-request/package.json b/packages/platform/platform-log-request/package.json new file mode 100644 index 00000000000..653621bcf04 --- /dev/null +++ b/packages/platform/platform-log-request/package.json @@ -0,0 +1,53 @@ +{ + "name": "@tsed/platform-log-request", + "description": "Log request module for Ts.ED Framework (Express, Koa, Serverless)", + "type": "module", + "version": "8.0.0-alpha.7", + "source": "./src/index.ts", + "main": "./lib/esm/index.js", + "module": "./lib/esm/index.js", + "typings": "./lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "default": "./lib/cjs/index.js" + } + }, + "scripts": { + "build": "yarn barrels && yarn build:ts", + "barrels": "barrels", + "test": "vitest run", + "build:ts": "tsc --build tsconfig.json", + "test:ci": "vitest run --coverage.thresholds.autoUpdate=true" + }, + "dependencies": { + "tslib": "2.7.0" + }, + "devDependencies": { + "@tsed/barrels": "workspace:*", + "@tsed/di": "workspace:*", + "@tsed/platform-middlewares": "workspace:*", + "@tsed/platform-params": "workspace:*", + "@tsed/typescript": "workspace:*", + "eslint": "9.11.1", + "typescript": "5.4.5", + "vitest": "2.0.4" + }, + "peerDependencies": { + "@tsed/di": "8.0.0-alpha.7", + "@tsed/platform-middlewares": "8.0.0-alpha.7", + "@tsed/platform-params": "8.0.0-alpha.7" + }, + "peerDependenciesMeta": { + "@tsed/di": { + "optional": false + }, + "@tsed/platform-middlewares": { + "optional": false + }, + "@tsed/platform-params": { + "optional": false + } + } +} diff --git a/packages/platform/platform-log-request/readme.md b/packages/platform/platform-log-request/readme.md new file mode 100644 index 00000000000..1667accd3a0 --- /dev/null +++ b/packages/platform/platform-log-request/readme.md @@ -0,0 +1,184 @@ +

+ Ts.ED logo +

+ +
+

@tsed/platform-log-request

+ +[![Build & Release](https://github.com/tsedio/tsed/workflows/Build%20&%20Release/badge.svg)](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22) +[![PR Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md) +[![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) +[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) +[![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita) +[![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed) + +
+ +
+ Website +   •   + Getting started +   •   + Slack +   •   + Twitter +
+ +
+ +A package of Ts.ED framework. See website: https://tsed.io/ + +# Installation + +```bash +npm install --save @tsed/platform-log-request +``` + +## Configuration + +```ts +import {Configuration} from "@tsed/di"; +import "@tsed/platform-log-request"; +import {levels} from "@tsed/logger"; + +@Configuration({ + /** + * Log all incoming request. By default, is true and print the configured `logger.requestFields`. + * @optional + */ + // logRequest: true, + /** + * A function to alter the log object before it's logged. + * @optional + */ + // alterLog: (level, data, $ctx) => { + // /// see example above + // }, + /** + * A function to alter the log object before it's logged. + * @optional + */ + // onLogEnd? : ($ctx: BaseContext) => void; +}) +class Server {} +``` + +## Alter log request + +By default, Ts.ED provide a default log object. You can alter this object by providing a function to the `alterLog` property. + +Here his the default implementation: + +```typescript +export function defaultAlterLog(level: string, obj: Record, ctx: BaseContext) { + const minimalLog = { + method: ctx.request.method, + url: ctx.request.url, + route: ctx.request.route || ctx.request.url, + ...obj + }; + + if (level === "info") { + return minimalLog; + } + + return { + ...minimalLog, + headers: ctx.request.headers, + body: ctx.request.body, + query: ctx.request.query, + params: ctx.request.params + }; +} +``` + +Just give your own implementation to the `alterLog` property. + +```typescript +import {Configuration} from "@tsed/di"; +import "@tsed/platform-log-request"; +import {customAlterLog} from "./utils/customAlterLog.js"; + +@Configuration({ + alterLog: customAlterLog +}) +class Server {} +``` + +## Customize log response + +By default, Ts.ED provide a default log response implementation. + +Here his the default implementation: + +```typescript +export function defaultLogResponse($ctx: BaseContext) { + if ($ctx.response.statusCode >= 400) { + const error = $ctx.error as any | undefined; + + $ctx.logger.error({ + event: "request.end", + status: $ctx.response.statusCode, + status_code: String($ctx.response.statusCode), + state: "KO", + ...cleanObject({ + error_name: error?.name || error?.code, + error_message: error?.message, + error_errors: error?.errors, + error_stack: error?.stack, + error_body: error?.body, + error_headers: error?.headers + }) + }); + } else { + $ctx.logger.info({ + event: "request.end", + status: $ctx.response.statusCode, + status_code: String($ctx.response.statusCode), + state: "OK" + }); + } +} +``` + +Just give your own implementation to the `onLogResponse` property. + +```typescript +import {Configuration} from "@tsed/di"; +import "@tsed/platform-log-request"; +import {customOnLogResponse} from "./utils/customOnLogResponse.js"; + +@Configuration({ + onLogResponse: customOnLogResponse +}) +class Server {} +``` + +## Contributors + +Please read [contributing guidelines here](https://tsed.io/contributing.html). + + + +## Backers + +Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)] + + + +## Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)] + +## License + +The MIT License (MIT) + +Copyright (c) 2016 - 2022 Romain Lenzotti + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/platform/platform-log-request/src/domain/PlatformLogRequestSettings.ts b/packages/platform/platform-log-request/src/domain/PlatformLogRequestSettings.ts new file mode 100644 index 00000000000..f103f346e64 --- /dev/null +++ b/packages/platform/platform-log-request/src/domain/PlatformLogRequestSettings.ts @@ -0,0 +1,28 @@ +import type {BaseContext} from "@tsed/di"; + +export type AlterLogCallback = ( + level: "debug" | "info" | "warn" | "error" | "all", + obj: Record, + ctx: BaseContext +) => Record; + +export interface PlatformLogRequestSettings { + /** + * Log all incoming request. By default, is true and print the configured `logger.requestFields`. + */ + logRequest?: boolean; + /** + * A function to alter the log object before it's logged. + */ + alterLog?: AlterLogCallback; + /** + * A function to log the server response. + */ + onLogResponse?: ($ctx: BaseContext) => void; +} + +declare global { + namespace TsED { + interface LoggerConfiguration extends Partial {} + } +} diff --git a/packages/platform/platform-log-request/src/index.ts b/packages/platform/platform-log-request/src/index.ts new file mode 100644 index 00000000000..154291e37da --- /dev/null +++ b/packages/platform/platform-log-request/src/index.ts @@ -0,0 +1,7 @@ +/** + * @file Automatically generated by @tsed/barrels. + */ +export * from "./domain/PlatformLogRequestSettings.js"; +export * from "./services/PlatformLogRequestFactory.js"; +export * from "./utils/defaultAlterLog.js"; +export * from "./utils/defaultLogResponse.js"; diff --git a/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.spec.ts b/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.spec.ts new file mode 100644 index 00000000000..98cc56cc684 --- /dev/null +++ b/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.spec.ts @@ -0,0 +1,139 @@ +import "../domain/PlatformLogRequestSettings.js"; + +import {DITest} from "@tsed/di"; + +import {PlatformLogRequestFactory} from "./PlatformLogRequestFactory.js"; + +describe("PlatformLogRequestFactory", () => { + describe("when logger is enabled", () => { + beforeEach(() => + DITest.create({ + logger: {} + }) + ); + afterEach(() => DITest.reset()); + + it("should create logger factory", async () => { + const factory = await DITest.invoke(PlatformLogRequestFactory); + + expect(factory).toEqual({ + alterLog: expect.any(Function), + onLogResponse: expect.any(Function) + }); + + const ctx: any = { + request: { + method: "GET" + }, + logger: { + alterLog: vi.fn(), + info: vi.fn() + } + }; + + vi.spyOn(factory!, "alterLog").mockReturnValue({}); + vi.spyOn(factory!, "onLogResponse").mockReturnValue(undefined); + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onRequest(factory!, ctx); + + expect(ctx.logger.alterLog).toHaveBeenCalledWith(expect.any(Function)); + + ctx.logger.alterLog.mock.calls[0][0]({test: "test"}, "info"); + + expect(ctx.logStarted).toBe(true); + expect(factory!.alterLog).toHaveBeenCalledWith( + "info", + { + test: "test" + }, + ctx + ); + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onResponse(factory!, ctx); + + expect(factory!.onLogResponse).toHaveBeenCalledWith(ctx); + }); + }); + describe("when logger is enabled with options", () => { + beforeEach(() => + DITest.create({ + logger: { + logRequest: true, + alterLog: vi.fn().mockReturnValue({}), + onLogResponse: vi.fn() + } + }) + ); + afterEach(() => DITest.reset()); + + it("should create logger factory", async () => { + const factory = await DITest.invoke(PlatformLogRequestFactory); + + expect(factory).toEqual({ + alterLog: expect.any(Function), + onLogResponse: expect.any(Function) + }); + + const ctx: any = { + request: { + method: "GET" + }, + logger: { + alterLog: vi.fn(), + info: vi.fn() + } + }; + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onRequest(factory!, ctx); + + expect(ctx.logger.alterLog).toHaveBeenCalledWith(expect.any(Function)); + + ctx.logger.alterLog.mock.calls[0][0]({test: "test"}, "info"); + + expect(ctx.logStarted).toBe(true); + expect(factory!.alterLog).toHaveBeenCalledWith( + "info", + { + test: "test" + }, + ctx + ); + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onResponse(factory!, ctx); + + expect(factory!.onLogResponse).toHaveBeenCalledWith(ctx); + }); + }); + describe("when logger is disabled", () => { + beforeEach(() => + DITest.create({ + logger: { + logRequest: false + } + }) + ); + afterEach(() => DITest.reset()); + + it("should create logger factory", async () => { + const factory = await DITest.invoke(PlatformLogRequestFactory); + + expect(factory).toEqual(null); + + const ctx: any = { + request: { + method: "GET" + }, + logger: { + alterLog: vi.fn(), + info: vi.fn() + } + }; + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onRequest(factory!, ctx); + + expect(ctx.logger.alterLog).not.toHaveBeenCalled(); + + DITest.injector.getProvider(PlatformLogRequestFactory)?.hooks?.$onResponse(factory!, ctx); + }); + }); +}); diff --git a/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.ts b/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.ts new file mode 100644 index 00000000000..14cb1a062f5 --- /dev/null +++ b/packages/platform/platform-log-request/src/services/PlatformLogRequestFactory.ts @@ -0,0 +1,41 @@ +import {type BaseContext, Configuration, registerProvider} from "@tsed/di"; + +import {defaultAlterLog} from "../utils/defaultAlterLog.js"; +import {defaultLogResponse} from "../utils/defaultLogResponse.js"; + +function factory(configuration: Configuration) { + const { + logRequest = true, + alterLog = defaultAlterLog, + onLogResponse = defaultLogResponse + } = configuration.get("logger"); + + return logRequest + ? { + alterLog, + onLogResponse + } + : null; +} + +export const PlatformLogRequestFactory = Symbol.for("PLATFORM:LOGGER:REQUEST"); +export type PlatformLogRequestFactory = ReturnType; + +registerProvider({ + provide: PlatformLogRequestFactory, + deps: [Configuration], + useFactory: factory, + hooks: { + $onRequest(instance: ReturnType, $ctx: BaseContext) { + if (instance) { + $ctx.logger.alterLog((obj: any, level) => instance.alterLog(level, obj, $ctx)); + $ctx.logStarted = true; + } + }, + $onResponse(instance: ReturnType, $ctx: BaseContext) { + if (instance && $ctx.logStarted) { + instance.onLogResponse($ctx); + } + } + } +}); diff --git a/packages/platform/platform-log-request/src/utils/defaultAlterLog.spec.ts b/packages/platform/platform-log-request/src/utils/defaultAlterLog.spec.ts new file mode 100644 index 00000000000..1724f74744c --- /dev/null +++ b/packages/platform/platform-log-request/src/utils/defaultAlterLog.spec.ts @@ -0,0 +1,66 @@ +import {defaultAlterLog} from "./defaultAlterLog.js"; + +describe("defaultAlterLog", () => { + it("should return the expected log object", () => { + expect( + defaultAlterLog("info", {test: "test"}, { + request: { + method: "GET", + url: "url", + headers: { + "x-forwarded-for": "value" + }, + route: "route" + } + } as never) + ).toEqual({ + method: "GET", + route: "route", + test: "test", + url: "url" + }); + }); + it("should return the expected log object (without route)", () => { + expect( + defaultAlterLog("info", {test: "test"}, { + request: { + method: "GET", + url: "url", + headers: { + "x-forwarded-for": "value" + } + } + } as never) + ).toEqual({ + method: "GET", + route: "url", + test: "test", + url: "url" + }); + }); + it("should return the expected log object with extras info", () => { + expect( + defaultAlterLog("error", {test: "test"}, { + request: { + method: "GET", + url: "url", + headers: { + "x-forwarded-for": "value" + }, + route: "route" + } + } as never) + ).toEqual({ + method: "GET", + route: "route", + test: "test", + url: "url", + body: undefined, + headers: { + "x-forwarded-for": "value" + }, + params: undefined, + query: undefined + }); + }); +}); diff --git a/packages/platform/platform-log-request/src/utils/defaultAlterLog.ts b/packages/platform/platform-log-request/src/utils/defaultAlterLog.ts new file mode 100644 index 00000000000..859f0213a83 --- /dev/null +++ b/packages/platform/platform-log-request/src/utils/defaultAlterLog.ts @@ -0,0 +1,22 @@ +import type {BaseContext} from "@tsed/di"; + +export function defaultAlterLog(level: string, obj: Record, ctx: BaseContext) { + const minimalLog = { + method: ctx.request.method, + url: ctx.request.url, + route: ctx.request.route || ctx.request.url, + ...obj + }; + + if (level === "info") { + return minimalLog; + } + + return { + ...minimalLog, + headers: ctx.request.headers, + body: ctx.request.body, + query: ctx.request.query, + params: ctx.request.params + }; +} diff --git a/packages/platform/platform-log-request/src/utils/defaultLogResponse.spec.ts b/packages/platform/platform-log-request/src/utils/defaultLogResponse.spec.ts new file mode 100644 index 00000000000..961e10922e8 --- /dev/null +++ b/packages/platform/platform-log-request/src/utils/defaultLogResponse.spec.ts @@ -0,0 +1,98 @@ +import {defaultLogResponse} from "./defaultLogResponse.js"; + +describe("defaultLogEnd", () => { + it("should log the request end", () => { + // GIVEN + const $ctx = { + response: { + statusCode: 200 + }, + logger: { + info: vi.fn() + } + }; + + // WHEN + defaultLogResponse($ctx as any); + + // THEN + expect($ctx.logger.info).toHaveBeenCalledWith({ + event: "request.end", + status: 200, + status_code: "200", + state: "OK" + }); + }); + it("should log the request end with error", () => { + // GIVEN + const $ctx = { + response: { + statusCode: 500 + }, + error: { + name: "name", + message: "message", + errors: "errors", + stack: "stack", + body: "body", + headers: "headers" + }, + logger: { + error: vi.fn() + } + }; + + // WHEN + defaultLogResponse($ctx as any); + + // THEN + expect($ctx.logger.error).toHaveBeenCalledWith({ + event: "request.end", + status: 500, + status_code: "500", + state: "KO", + error_name: "name", + error_message: "message", + error_errors: "errors", + error_stack: "stack", + error_body: "body", + error_headers: "headers" + }); + }); + it("should log the request end with error code", () => { + // GIVEN + const $ctx = { + response: { + statusCode: 500 + }, + error: { + code: "code", + message: "message", + errors: "errors", + stack: "stack", + body: "body", + headers: "headers" + }, + logger: { + error: vi.fn() + } + }; + + // WHEN + defaultLogResponse($ctx as any); + + // THEN + expect($ctx.logger.error).toHaveBeenCalledWith({ + event: "request.end", + status: 500, + status_code: "500", + state: "KO", + error_name: "code", + error_message: "message", + error_errors: "errors", + error_stack: "stack", + error_body: "body", + error_headers: "headers" + }); + }); +}); diff --git a/packages/platform/platform-log-request/src/utils/defaultLogResponse.ts b/packages/platform/platform-log-request/src/utils/defaultLogResponse.ts new file mode 100644 index 00000000000..91b41ce62ef --- /dev/null +++ b/packages/platform/platform-log-request/src/utils/defaultLogResponse.ts @@ -0,0 +1,30 @@ +import {cleanObject} from "@tsed/core"; +import type {BaseContext} from "@tsed/di"; + +export function defaultLogResponse($ctx: BaseContext) { + if ($ctx.response.statusCode >= 400) { + const error = $ctx.error as any | undefined; + + $ctx.logger.error({ + event: "request.end", + status: $ctx.response.statusCode, + status_code: String($ctx.response.statusCode), + state: "KO", + ...cleanObject({ + error_name: error?.name || error?.code, + error_message: error?.message, + error_errors: error?.errors, + error_stack: error?.stack, + error_body: error?.body, + error_headers: error?.headers + }) + }); + } else { + $ctx.logger.info({ + event: "request.end", + status: $ctx.response.statusCode, + status_code: String($ctx.response.statusCode), + state: "OK" + }); + } +} diff --git a/packages/platform/platform-log-request/tsconfig.esm.json b/packages/platform/platform-log-request/tsconfig.esm.json new file mode 100644 index 00000000000..8954049da4a --- /dev/null +++ b/packages/platform/platform-log-request/tsconfig.esm.json @@ -0,0 +1,26 @@ +{ + "extends": "@tsed/typescript/tsconfig.node.json", + "compilerOptions": { + "baseUrl": ".", + "rootDir": "src", + "outDir": "./lib/esm", + "declarationDir": "./lib/types", + "declaration": true, + "composite": true, + "noEmit": false + }, + "include": ["src/**/*.ts", "src/**/*.json"], + "exclude": [ + "node_modules", + "test", + "lib", + "benchmark", + "coverage", + "spec", + "**/*.benchmark.ts", + "**/*.spec.ts", + "keys", + "**/__mock__/**", + "webpack.config.js" + ] +} diff --git a/packages/platform/platform-log-request/tsconfig.json b/packages/platform/platform-log-request/tsconfig.json new file mode 100644 index 00000000000..d548a61b586 --- /dev/null +++ b/packages/platform/platform-log-request/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "@tsed/typescript/tsconfig.node.json", + "compilerOptions": { + "baseUrl": ".", + "noEmit": true + }, + "include": [], + "references": [ + { + "path": "../../di/tsconfig.json" + }, + { + "path": "../platform-middlewares/tsconfig.json" + }, + { + "path": "../platform-params/tsconfig.json" + }, + { + "path": "./tsconfig.esm.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/platform/platform-log-request/tsconfig.spec.json b/packages/platform/platform-log-request/tsconfig.spec.json new file mode 100644 index 00000000000..4093230fb5d --- /dev/null +++ b/packages/platform/platform-log-request/tsconfig.spec.json @@ -0,0 +1,35 @@ +{ + "extends": "@tsed/typescript/tsconfig.node.json", + "compilerOptions": { + "baseUrl": ".", + "rootDir": "../..", + "declaration": false, + "composite": false, + "noEmit": true, + "paths": { + "@tsed/openspec": ["../../specs/openspec/src/index.ts"], + "@tsed/schema": ["../../specs/schema/src/index.ts"], + "@tsed/di": ["../../di/src/index.ts"], + "@tsed/exceptions": ["../../specs/exceptions/src/index.ts"], + "@tsed/json-mapper": ["../../specs/json-mapper/src/index.ts"], + "@tsed/platform-exceptions": ["../platform-exceptions/src/index.ts"], + "@tsed/platform-middlewares": ["../platform-middlewares/src/index.ts"], + "@tsed/platform-params": ["../platform-params/src/index.ts"], + "@tsed/platform-response-filter": ["../platform-response-filter/src/index.ts"], + "@tsed/platform-router": ["../platform-router/src/index.ts"], + "@tsed/platform-views": ["../platform-views/src/index.ts"], + "@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"], + "@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"], + "@tsed/common": ["../common/src/index.ts"], + "@tsed/ajv": ["../../specs/ajv/src/index.ts"], + "@tsed/platform-cache": ["../platform-cache/src/index.ts"], + "@tsed/swagger": ["../../specs/swagger/src/index.ts"], + "@tsed/platform-test-sdk": ["../platform-test-sdk/src/index.ts"], + "@tsed/platform-express": ["../platform-express/src/index.ts"], + "@tsed/platform-koa": ["../platform-koa/src/index.ts"] + }, + "types": ["vite/client", "vitest/globals"] + }, + "include": ["src/**/*.spec.ts", "test/**/*.spec.ts", "vitest.config.mts"], + "exclude": ["node_modules", "test", "lib", "benchmark", "coverage"] +} diff --git a/packages/platform/platform-log-request/vitest.config.mts b/packages/platform/platform-log-request/vitest.config.mts new file mode 100644 index 00000000000..7d6f87fae21 --- /dev/null +++ b/packages/platform/platform-log-request/vitest.config.mts @@ -0,0 +1,21 @@ +// @ts-ignore +import {presets} from "@tsed/vitest/presets"; +import {defineConfig} from "vitest/config"; + +export default defineConfig( + { + ...presets, + test: { + ...presets.test, + coverage: { + ...presets.test.coverage, + thresholds: { + statements: 100, + branches: 100, + functions: 100, + lines: 100 + } + } + } + } +); diff --git a/tsconfig.json b/tsconfig.json index 94ba2ac0232..8cb64691375 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,9 +12,7 @@ "moduleResolution": "node", "skipLibCheck": true }, - "include": [ - "vite.workspace.mts" - ], + "include": ["vite.workspace.mts"], "references": [ { "path": "./packages/core/tsconfig.json" @@ -52,6 +50,9 @@ { "path": "./packages/platform/platform-log-middleware/tsconfig.json" }, + { + "path": "./packages/platform/platform-log-request/tsconfig.json" + }, { "path": "./packages/platform/platform-response-filter/tsconfig.json" }, @@ -188,9 +189,5 @@ "path": "./tools/integration/tsconfig.json" } ], - "exclude": [ - "**/node_modules/**", - "docs", - "docs-references" - ] + "exclude": ["**/node_modules/**", "docs", "docs-references"] } diff --git a/yarn.lock b/yarn.lock index a7bc3c2ab24..f2ee82a12ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7683,6 +7683,33 @@ __metadata: languageName: unknown linkType: soft +"@tsed/platform-log-request@workspace:packages/platform/platform-log-request": + version: 0.0.0-use.local + resolution: "@tsed/platform-log-request@workspace:packages/platform/platform-log-request" + dependencies: + "@tsed/barrels": "workspace:*" + "@tsed/di": "workspace:*" + "@tsed/platform-middlewares": "workspace:*" + "@tsed/platform-params": "workspace:*" + "@tsed/typescript": "workspace:*" + eslint: "npm:9.11.1" + tslib: "npm:2.7.0" + typescript: "npm:5.4.5" + vitest: "npm:2.0.4" + peerDependencies: + "@tsed/di": 8.0.0-alpha.7 + "@tsed/platform-middlewares": 8.0.0-alpha.7 + "@tsed/platform-params": 8.0.0-alpha.7 + peerDependenciesMeta: + "@tsed/di": + optional: false + "@tsed/platform-middlewares": + optional: false + "@tsed/platform-params": + optional: false + languageName: unknown + linkType: soft + "@tsed/platform-middlewares@workspace:*, @tsed/platform-middlewares@workspace:packages/platform/platform-middlewares": version: 0.0.0-use.local resolution: "@tsed/platform-middlewares@workspace:packages/platform/platform-middlewares"