Skip to content

Commit 69c5961

Browse files
authored
v18 is for Victoria (#1639)
# Dedication ![image](https://github.com/RobinTail/express-zod-api/assets/13189514/7ce8a788-6254-4d01-8e7a-6dc7a82a2b05) **Victoria Carmen White**, a black trans woman, was murdered in New Jersey, US, on 12 September 2010. Her boyfriend was brought to trial for her death, but he was acquitted and blamed another man for the murder. The gun used in the killing was never found. Transgender women suffer too frequently from transphobic violence and cruelty, being the less protected social group. I'd like to raise an awareness of this problem. Humans should be creators — not killers. But most importantly, I want every transgender girl to have an opportunity to create applications quickly and, in general, learn to write code easily in order to receive job offers and leave dangerously transphobic territories for more favorable and civilized ones, and live happily there. Protect transgender women. --- # Version 18 ## Description This version is focused on making the quick start with Express Zod API even faster by replacing Winston with a built-in console logger having the same basic functionality needed to begin the development. Migration should be easy in most cases. ## What's included - #1636 - #1640, later overridden by: - #1654 - #1671
1 parent a6ae064 commit 69c5961

24 files changed

+250
-673
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ master, v14, v15, v16 ]
16+
branches: [ master, v15, v16, v17 ]
1717
pull_request:
1818
# The branches below must be a subset of the branches above
19-
branches: [ master, v14, v15, v16 ]
19+
branches: [ master, v15, v16, v17 ]
2020
schedule:
2121
- cron: '26 8 * * 1'
2222

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master, v14, v15, v16 ]
8+
branches: [ master, v15, v16, v17 ]
99
pull_request:
10-
branches: [ master, v14, v15, v16 ]
10+
branches: [ master, v15, v16, v17 ]
1111

1212
jobs:
1313
build:

.github/workflows/swagger.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: OpenAPI Validation
22

33
on:
44
push:
5-
branches: [ master, v14, v15, v16 ]
5+
branches: [ master, v15, v16, v17 ]
66
pull_request:
7-
branches: [ master, v14, v15, v16 ]
7+
branches: [ master, v15, v16, v17 ]
88

99

1010
jobs:

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Changelog
22

3+
## Version 18
4+
5+
### v18.0.0
6+
7+
- **Breaking changes**:
8+
- `winston` is no longer a default logger;
9+
- `createLogger()` argument is changed, and it now returns a built-in logger instead of `winston`.
10+
- Features:
11+
- New built-in console logger with colorful pretty inspections and basic methods only.
12+
- Non-breaking significant changes:
13+
- Due to detaching from `winston`, the `attachRouting()` method is back to being synchronous.
14+
- How to migrate confidently:
15+
- If you're using `attachRouting()` method:
16+
- Remove `await` before it (and possible async IIFE wrapper if present) — no longer required.
17+
- If you're using a custom logger in config:
18+
- No action required.
19+
- If you're using `createLogger()` method in your code:
20+
- Remove the `winston` property from its argument.
21+
- If you're using the default logger in config (which used to be `winston` as a peer dependency):
22+
- If you're only using its `info()`, `debug()`, `error()` and `warn()` methods:
23+
- You can now uninstall `winston` — no further action required.
24+
- If you're using its other methods, like `.child()` or `profile()`:
25+
- Configure `winston` as a custom logger [according to the documentation](README.md#customizing-logger),
26+
- Or consider any other compatible logger, like `pino` for example, which is easier to configure.
27+
328
## Version 17
429

530
### v17.7.1

README.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Therefore, many basic tasks can be accomplished faster and easier, in particular
8989
- Web server — [Express.js](https://expressjs.com/).
9090
- Schema validation — [Zod 3.x](https://github.com/colinhacks/zod).
9191
- Supports any logger having `info()`, `debug()`, `error()` and `warn()` methods;
92-
- [Winston](https://github.com/winstonjs/winston) is default.
92+
- Built-in console logger with colorful and pretty inspections by default.
9393
- Generators:
9494
- Documentation — [OpenAPI 3.1](https://github.com/metadevpro/openapi3-ts) (former Swagger);
9595
- Client side types — inspired by [zod-to-ts](https://github.com/sachinraja/zod-to-ts).
@@ -118,14 +118,14 @@ Much can be customized to fit your needs.
118118
Run one of the following commands to install the library, its peer dependencies and packages for types assistance.
119119

120120
```shell
121-
yarn add express-zod-api express zod winston typescript http-errors
121+
yarn add express-zod-api express zod typescript http-errors
122122
yarn add --dev @types/express @types/node @types/http-errors
123123
```
124124

125125
or
126126

127127
```shell
128-
npm install express-zod-api express zod winston typescript http-errors
128+
npm install express-zod-api express zod typescript http-errors
129129
npm install -D @types/express @types/node @types/http-errors
130130
```
131131

@@ -147,7 +147,6 @@ Create a minimal configuration. _See all available options
147147

148148
```typescript
149149
import { createConfig } from "express-zod-api";
150-
import type { Logger } from "winston";
151150

152151
const config = createConfig({
153152
server: {
@@ -156,11 +155,6 @@ const config = createConfig({
156155
cors: true,
157156
logger: { level: "debug", color: true },
158157
});
159-
160-
// Setting the type of the logger used
161-
declare module "express-zod-api" {
162-
interface LoggerOverrides extends Logger {}
163-
}
164158
```
165159

166160
## Create an endpoints factory
@@ -526,8 +520,9 @@ your API at [Let's Encrypt](https://letsencrypt.org/).
526520

527521
## Customizing logger
528522

529-
You can uninstall `winston` (which is the default and recommended logger) and use another compatible one, having
530-
`info()`, `debug()`, `error()` and `warn()` methods. For example, `pino` logger with `pino-pretty` extension:
523+
If the simple console output of the built-in logger is not enough for you, you can connect any other compatible one.
524+
It must support at least the following methods: `info()`, `debug()`, `error()` and `warn()`.
525+
Winston and Pino support is well known. Here is an example configuring `pino` logger with `pino-pretty` extension:
531526

532527
```typescript
533528
import pino, { Logger } from "pino";
@@ -560,7 +555,7 @@ import { randomUUID } from "node:crypto";
560555
const config = createConfig({
561556
// logger: ...,
562557
childLoggerProvider: ({ parent, request }) =>
563-
parent.child({ requestId: randomUUID() }),
558+
parent.child({ requestId: randomUUID() }), // assuming a custom logger having .child() method
564559
});
565560
```
566561

@@ -793,7 +788,7 @@ Some options are forced in order to ensure the correct workflow:
793788
{
794789
abortOnLimit: false,
795790
parseNested: true,
796-
logger: {}, // the configured logger (default: winston), using its .debug() method
791+
logger: {}, // the configured logger, using its .debug() method
797792
}
798793
```
799794

@@ -878,15 +873,11 @@ const app = express(); // or express.Router()
878873
const config = createConfig({ app /* cors, logger, ... */ });
879874
const routing: Routing = {}; // your endpoints go here
880875

881-
// This async IIFE is only required for the top level CommonJS
882-
(async () => {
883-
const { notFoundHandler, logger } = await attachRouting(config, routing);
884-
885-
app.use(notFoundHandler); // optional
886-
app.listen();
876+
const { notFoundHandler, logger } = attachRouting(config, routing);
887877

888-
logger.info("Glory to science!");
889-
})();
878+
app.use(notFoundHandler); // optional
879+
app.listen();
880+
logger.info("Glory to science!");
890881
```
891882

892883
**Please note** that in this case you probably need to parse `request.body`, call `app.listen()` and handle `404`

SECURITY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
| Version | Release | Supported |
66
| ------: | :------ | :----------------: |
7+
| 18.x.x | 04.2024 | :white_check_mark: |
78
| 17.x.x | 02.2024 | :white_check_mark: |
89
| 16.x.x | 12.2023 | :white_check_mark: |
910
| 15.x.x | 12.2023 | :white_check_mark: |
10-
| 14.x.x | 10.2023 | :white_check_mark: |
11+
| 14.x.x | 10.2023 | :x: |
1112
| 12.x.x | 09.2023 | :x: |
1213
| 11.x.x | 06.2023 | :x: |
1314
| 10.x.x | 03.2023 | :x: |

example/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const config = createConfig({
3535
},
3636
});
3737

38-
// Uncomment these lines to set the type of logger used:
38+
// Uncomment these lines when using a custom logger, for example winston:
3939
/*
4040
declare module "express-zod-api" {
4141
interface LoggerOverrides extends winston.Logger {}

example/example.documentation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
openapi: 3.1.0
22
info:
33
title: Example API
4-
version: 17.7.1
4+
version: 18.0.0-beta3
55
paths:
66
/v1/user/retrieve:
77
get:

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-zod-api",
3-
"version": "17.7.1",
3+
"version": "18.0.0-beta3",
44
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
55
"license": "MIT",
66
"repository": {
@@ -25,7 +25,6 @@
2525
"build:docs": "tsx example/generate-documentation.ts",
2626
"build:client": "tsx example/generate-client.ts",
2727
"build:license": "tsx tools/license.ts",
28-
"build:logo": "tsx tools/startup-logo.ts",
2928
"test": "yarn test:types && yarn test:unit && yarn test:badge",
3029
"test:cjs": "yarn --cwd tests/cjs && vitest run -r tests/cjs",
3130
"test:esm": "yarn --cwd tests/esm && vitest run -r tests/esm",
@@ -68,6 +67,7 @@
6867
"node": "^18.0.0 || ^20.0.0"
6968
},
7069
"dependencies": {
70+
"ansis": "^3.1.0",
7171
"openapi3-ts": "^4.2.1",
7272
"ramda": "^0.29.1"
7373
},
@@ -86,7 +86,6 @@
8686
"prettier": "^3.1.0",
8787
"typescript": "^5.1.3",
8888
"vitest": "^1.0.4",
89-
"winston": "^3.10.0",
9089
"zod": "^3.22.3"
9190
},
9291
"peerDependenciesMeta": {
@@ -122,9 +121,6 @@
122121
},
123122
"vitest": {
124123
"optional": true
125-
},
126-
"winston": {
127-
"optional": true
128124
}
129125
},
130126
"devDependencies": {
@@ -142,7 +138,6 @@
142138
"@typescript-eslint/eslint-plugin": "^7.1.0",
143139
"@typescript-eslint/parser": "^7.1.0",
144140
"@vitest/coverage-istanbul": "^1.5.0",
145-
"chalk": "^5.3.0",
146141
"compression": "^1.7.4",
147142
"cors": "^2.8.5",
148143
"eslint": "^8.48.0",
@@ -165,7 +160,6 @@
165160
"tsx": "^4.6.2",
166161
"typescript": "^5.2.2",
167162
"vitest": "^1.5.0",
168-
"winston": "^3.10.0",
169163
"zod": "^3.22.3"
170164
},
171165
"keywords": [

src/config-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IRouter, Request, RequestHandler } from "express";
33
import type fileUpload from "express-fileupload";
44
import { ServerOptions } from "node:https";
55
import { AbstractEndpoint } from "./endpoint";
6-
import { AbstractLogger, SimplifiedWinstonConfig } from "./logger";
6+
import { AbstractLogger, BuiltinLoggerConfig } from "./logger";
77
import { Method } from "./method";
88
import { AnyResultHandlerDefinition } from "./result-handler";
99
import { ListenOptions } from "node:net";
@@ -47,10 +47,10 @@ export interface CommonConfig<TAG extends string = string> {
4747
*/
4848
errorHandler?: AnyResultHandlerDefinition;
4949
/**
50-
* @desc Logger configuration (winston) or instance of any other logger.
50+
* @desc Built-in logger configuration or an instance of any compatible logger.
5151
* @example { level: "debug", color: true }
5252
* */
53-
logger: SimplifiedWinstonConfig | AbstractLogger;
53+
logger: BuiltinLoggerConfig | AbstractLogger;
5454
/**
5555
* @desc A child logger returned by this function can override the logger in all handlers for each request
5656
* @example ({ parent }) => parent.child({ requestId: uuid() })

0 commit comments

Comments
 (0)