Skip to content

Commit

Permalink
Merge branch 'master' into try-eslint9
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed May 18, 2024
2 parents c9dbea9 + 113b9e4 commit 4f206ed
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 58 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Version 19

### v19.1.2

- Fixed a bug on logger instance recognition failure:
- When an instance of `winston` logger was assigned in config, it was not recognized as an actual logger;
- That led to using the built-in logger having reduced capabilities;
- Other loggers could be also affected by this issue;
- The issue was found and reported by [@boarush](https://github.com/boarush).

### v19.1.1

- Fixed a bug on duplicated or missing request header parameters in the generated Documentation:
Expand Down
2 changes: 1 addition & 1 deletion example/example.documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.1.0
info:
title: Example API
version: 19.1.1
version: 19.1.2
paths:
/v1/user/retrieve:
get:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-zod-api",
"version": "19.1.1",
"version": "19.1.2",
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
"license": "MIT",
"repository": {
Expand Down
13 changes: 2 additions & 11 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,9 @@ const severity: Record<keyof AbstractLogger, number> = {
error: 40,
};

export const isBuiltinLoggerConfig = (
subject: unknown,
): subject is BuiltinLoggerConfig =>
export const isActualLogger = (subject: unknown): subject is AbstractLogger =>
isObject(subject) &&
"level" in subject &&
("color" in subject ? typeof subject.color === "boolean" : true) &&
("depth" in subject
? typeof subject.depth === "number" || subject.depth === null
: true) &&
typeof subject.level === "string" &&
["silent", "warn", "info", "debug"].includes(subject.level) &&
!Object.values(subject).some((prop) => typeof prop === "function");
Object.keys(severity).some((method) => method in subject);

/**
* @desc Creates the built-in console logger with optional colorful inspections
Expand Down
8 changes: 4 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type compression from "compression";
import http from "node:http";
import https from "node:https";
import { AppConfig, CommonConfig, ServerConfig } from "./config-type";
import { createLogger, isBuiltinLoggerConfig } from "./logger";
import { createLogger, isActualLogger } from "./logger";
import { loadPeer } from "./peer-helpers";
import { defaultResultHandler } from "./result-handler";
import { Parsers, Routing, initRouting } from "./routing";
Expand All @@ -21,9 +21,9 @@ const makeCommonEntities = (config: CommonConfig) => {
console.log(getStartupLogo());
}
const errorHandler = config.errorHandler || defaultResultHandler;
const rootLogger = isBuiltinLoggerConfig(config.logger)
? createLogger(config.logger)
: config.logger;
const rootLogger = isActualLogger(config.logger)
? config.logger
: createLogger(config.logger);
rootLogger.debug("Running", process.env.TSUP_BUILD || "from sources");
const loggingMiddleware = createLoggingMiddleware({ rootLogger, config });
const notFoundHandler = createNotFoundHandler({ rootLogger, errorHandler });
Expand Down
30 changes: 15 additions & 15 deletions tests/unit/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import MockDate from "mockdate";
import { EventEmitter } from "node:events";
import {
AbstractLogger,
BuiltinLoggerConfig,
createLogger,
isBuiltinLoggerConfig,
isActualLogger,
} from "../../src/logger";
import {
afterAll,
Expand Down Expand Up @@ -104,31 +105,30 @@ describe("Logger", () => {
);
});

describe("isBuiltinLoggerConfig()", () => {
test.each([
describe("isActualLogger()", () => {
test.each<BuiltinLoggerConfig>([
{ level: "silent" },
{ level: "debug", color: false },
{ level: "info", color: true },
{ level: "warn", depth: 5 },
{ level: "warn", depth: null },
{ level: "warn", depth: Infinity },
])("should validate config %#", (sample) => {
expect(isBuiltinLoggerConfig(sample)).toBeTruthy();
])("should invalidate built-in logger config %#", (sample) => {
expect(isActualLogger(sample)).toBeFalsy();
});

test.each([
null,
undefined,
{},
{ level: null },
{ level: "wrong" },
{ level: "debug", color: null },
{ level: "debug", depth: "wrong" },
test.each<AbstractLogger>([
// issue #1605: should not allow methods
{ level: "debug", debug: () => {} },
{ level: "warn", error: () => {} },
])("should invalidate config %#", (sample) => {
expect(isBuiltinLoggerConfig(sample)).toBeFalsy();
// issue #1772: similar to #1605, but the methods are in prototype
new (class {
level = "debug";
debug() {}
})(),
Object.setPrototypeOf({ level: "debug" }, { debug: () => {} }),
])("should validate logger instances %#", (sample) => {
expect(isActualLogger(sample)).toBeTruthy();
});
});
});
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@
integrity sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==

"@eslint/eslintrc@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-3.0.2.tgz#36180f8e85bf34d2fe3ccc2261e8e204a411ab4e"
integrity sha512-wV19ZEGEMAC1eHgrS7UQPqsdEiCIbTKTasEfcXAigzoXICcqZSjBZEHlZwNVvKg6UBCjSlos84XiLqsRJnIcIg==
version "3.1.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-3.1.0.tgz#dbd3482bfd91efa663cbe7aa1f506839868207b6"
integrity sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
Expand Down Expand Up @@ -1329,9 +1329,9 @@ camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001587:
version "1.0.30001617"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001617.tgz#809bc25f3f5027ceb33142a7d6c40759d7a901eb"
integrity sha512-mLyjzNI9I+Pix8zwcrpxEbGlfqOkF9kM3ptzmKNw5tizSyYwMe+nGLTqMK9cO+0E+Bh6TsBxNAaHWEM8xwSsmA==
version "1.0.30001620"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz#78bb6f35b8fe315b96b8590597094145d0b146b4"
integrity sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew==

chai@^4.3.10:
version "4.4.1"
Expand Down Expand Up @@ -1534,9 +1534,9 @@ cookie@0.6.0:
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==

core-js-compat@^3.37.0:
version "3.37.0"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.37.0.tgz#d9570e544163779bb4dff1031c7972f44918dc73"
integrity sha512-vYq4L+T8aS5UuFg4UwDhc7YNRWVeVZwltad9C/jV3R2LgVOpS9BDr7l/WL6BN0dbV3k1XejPTHqqEzJgsa0frA==
version "3.37.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.37.1.tgz#c844310c7852f4bdf49b8d339730b97e17ff09ee"
integrity sha512-9TNiImhKvQqSUkOvk/mMRZzOANTiEVC7WaBNhHcKM7x+/5E1l5NvsysR19zuDQScE8k+kfQXWRN3AtS/eOSHpg==
dependencies:
browserslist "^4.23.0"

Expand Down Expand Up @@ -1688,9 +1688,9 @@ ee-first@1.1.1:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.668:
version "1.4.764"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.764.tgz#6e817e9d767434eb48a85cc9915566485c5ba2c3"
integrity sha512-ZXbPV46Y4dNCA+k7YHB+BYlzcoMtZ1yH6V0tQ1ul0wmA7RiwJfS29LSdRlE1myWBXRzEgm/Lz6tryj5WVQiLmg==
version "1.4.774"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.774.tgz#1017d1758aaeeefe5423aa9d67b4b1e5d1d0a856"
integrity sha512-132O1XCd7zcTkzS3FgkAzKmnBuNJjK8WjcTtNuoylj7MYbqw5eXehjQ5OK91g0zm7OTKIPeaAG4CPoRfD9M1Mg==

emoji-regex@^8.0.0:
version "8.0.0"
Expand Down Expand Up @@ -3574,10 +3574,10 @@ pathval@^1.1.1:
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.1.tgz#8534e77a77ce7ac5a2512ea21e0fdb8fcf6c3d8d"
integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==

picocolors@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
picocolors@^1.0.0, picocolors@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1"
integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==

picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
version "2.3.1"
Expand Down Expand Up @@ -4206,9 +4206,9 @@ supports-preserve-symlinks-flag@^1.0.0:
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

swagger-ui-dist@>=5.0.0:
version "5.17.9"
resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.17.9.tgz#4550c54f27ae61951199b5c890db4f6ff7e27242"
integrity sha512-qhZdoXIleblFxufohnd4ir4KmVA7/uFfd/9sDTtH8A6Qm1lEK40MhrMrDqy9AygGjw1bnJpZH4yZ5wu12vW1aw==
version "5.17.10"
resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.17.10.tgz#5c60c4fe00062723dccb9fcd7376d2c0f6397870"
integrity sha512-fp8SYeEK216KS1/noDvursUOGojEbkvtckOpOmAGZUjlx/ma7VLD2PLQwyermjlzFrlHI5uCt1V+M1C3qBvRyQ==

swagger-ui-express@^5.0.0:
version "5.0.0"
Expand Down Expand Up @@ -4371,9 +4371,9 @@ tsup@^8.0.0:
tree-kill "^1.2.2"

tsx@^4.6.2:
version "4.10.3"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.10.3.tgz#c0b1dac1e3ebb3db4465363dc8eef7b3ae0e7538"
integrity sha512-f0g60aFSVRVkzcQkEflh8fPLRfmt+HJHgWi/plG5UgvVaV+9TcpOwJ0sZJSACXmwmjMPg9yQR0BhTLbhkfV2uA==
version "4.10.5"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.10.5.tgz#157139bd2472dd64ff4118385f3eccd27868bb36"
integrity sha512-twDSbf7Gtea4I2copqovUiNTEDrT8XNFXsuHpfGbdpW/z9ZW4fTghzzhAG0WfrCuJmJiOEY1nLIjq4u3oujRWQ==
dependencies:
esbuild "~0.20.2"
get-tsconfig "^4.7.5"
Expand Down Expand Up @@ -4512,12 +4512,12 @@ unpipe@1.0.0, unpipe@~1.0.0:
integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==

update-browserslist-db@^1.0.13:
version "1.0.15"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.15.tgz#60ed9f8cba4a728b7ecf7356f641a31e3a691d97"
integrity sha512-K9HWH62x3/EalU1U6sjSZiylm9C8tgq2mSvshZpqc7QE69RaA2qjhkW2HlNA0tFpEbtyFz7HTqbSdN4MSwUodA==
version "1.0.16"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.16.tgz#f6d489ed90fb2f07d67784eb3f53d7891f736356"
integrity sha512-KVbTxlBYlckhF5wgfyZXTWnMn7MMZjMu9XG8bPlliUOP9ThaF4QnhP8qrjrH7DRzHfSk0oQv1wToW+iA5GajEQ==
dependencies:
escalade "^3.1.2"
picocolors "^1.0.0"
picocolors "^1.0.1"

uri-js@^4.2.2:
version "4.4.1"
Expand Down

0 comments on commit 4f206ed

Please sign in to comment.