|
4 | 4 |
|
5 | 5 | ### v19.0.0 |
6 | 6 |
|
7 | | -- Minimum supported versions: |
8 | | - - Node: 18.18.0 or 20.9.0, |
9 | | - - `zod`: 3.23.0. |
10 | | -- The deprecated ~~`withMeta()`~~ is removed: |
11 | | - - See the changes to [v18.5.0](#v1850) on details. |
12 | | -- Several public methods and properties exposing arrays from class instances made readonly and frozen: |
13 | | - - On `Endpoint`: `.getMethods()`, `.getMimeTypes()`, `.getResponses()`, `.getScopes()`, `.getTags()`, |
14 | | - - On `DependsOnMethod`: `.pairs`, `.siblingMethods`. |
| 7 | +- **Breaking changes**: |
| 8 | + - Increased minimum supported versions: |
| 9 | + - Node: 18.18.0 or 20.9.0; |
| 10 | + - `zod`: 3.23.0. |
| 11 | + - Removed the deprecated ~~`withMeta()`~~ is removed (see [v18.5.0](#v1850) for details); |
| 12 | + - Freezed the arrays returned by the following methods or exposed by properties that supposed to be readonly: |
| 13 | + - For `Endpoint` class: `getMethods()`, `getMimeTypes()`, `getResponses()`, `getScopes()`, `getTags()`; |
| 14 | + - For `DependsOnMethod` class: `pairs`, `siblingMethods`. |
| 15 | + - Changed the `ServerConfig` option `server.upload.beforeUpload`: |
| 16 | + - The assigned function now accepts `request` instead of `app` and being called only for eligible requests; |
| 17 | + - Restricting the upload can be achieved now by throwing an error from within. |
| 18 | + - Changed interface for `ez.raw()`: additional properties should be supplied as its argument, not via `.extend()`. |
| 19 | +- Features: |
| 20 | + - New configurable level `info` for built-in logger (higher than `debug`, but lower than `warn`); |
| 21 | + - Selective parsers equipped with a child logger: |
| 22 | + - There are 3 types of endpoints depending on their input schema: having `ez.upload()`, having `ez.raw()`, others; |
| 23 | + - Depending on that type, only the parsers needed for certain endpoint are processed; |
| 24 | + - This makes all requests eligible for the assigned parsers and reverts changes made in [v18.5.2](#v1852). |
| 25 | +- Non-breaking significant changes: |
| 26 | + - Request logging reflects the actual path instead of the configured route, and it's placed in front of parsing: |
| 27 | + - The severity of those messaged reduced from `info` to `debug`; |
| 28 | + - The debug messages from uploader are enabled by default when the logger level is set to `debug`; |
| 29 | + - Specifying `rawParser` in config is no longer needed to enable the feature. |
| 30 | +- How to migrate confidently: |
| 31 | + - Upgrade Node to latest version of 18.x, 20.x or 22.x; |
| 32 | + - Upgrade `zod` to its latest version of 3.x; |
| 33 | + - Avoid mutating the readonly arrays; |
| 34 | + - If you're using ~~`withMeta()`~~: |
| 35 | + - Remove it and unwrap your schemas — you can use `.example()` method directly. |
| 36 | + - If you're using `ez.raw().extend()` for additional properties: |
| 37 | + - Supply them directly as an argument to `ez.raw()` — see the example below. |
| 38 | + - If you're using `beforeUpload` in your config: |
| 39 | + - Adjust the implementation according to the example below. |
| 40 | + - If you're having `rawParser: express.raw()` in your config: |
| 41 | + - You can now remove this line (it's the default value now), unless you're having any customizations. |
| 42 | + |
| 43 | +```ts |
| 44 | +import createHttpError from "http-errors"; |
| 45 | +import { createConfig } from "express-zod-api"; |
| 46 | + |
| 47 | +const before = createConfig({ |
| 48 | + server: { |
| 49 | + upload: { |
| 50 | + beforeUpload: ({ app, logger }) => { |
| 51 | + app.use((req, res, next) => { |
| 52 | + if (req.is("multipart/form-data") && !canUpload(req)) { |
| 53 | + return next(createHttpError(403, "Not authorized")); |
| 54 | + } |
| 55 | + next(); |
| 56 | + }); |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | +}); |
| 61 | + |
| 62 | +const after = createConfig({ |
| 63 | + server: { |
| 64 | + upload: { |
| 65 | + beforeUpload: ({ request, logger }) => { |
| 66 | + if (!canUpload(request)) { |
| 67 | + throw createHttpError(403, "Not authorized"); |
| 68 | + } |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +```ts |
| 76 | +import { z } from "zod"; |
| 77 | +import { ez } from "express-zod-api"; |
| 78 | + |
| 79 | +const before = ez.raw().extend({ |
| 80 | + pathParameter: z.string(), |
| 81 | +}); |
| 82 | + |
| 83 | +const after = ez.raw({ |
| 84 | + pathParameter: z.string(), |
| 85 | +}); |
| 86 | +``` |
15 | 87 |
|
16 | 88 | ## Version 18 |
17 | 89 |
|
|
0 commit comments