Skip to content

Commit

Permalink
docs: update compatibility matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Papooch committed Feb 10, 2025
1 parent 44b19cc commit 2803ce6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
44 changes: 22 additions & 22 deletions docs/docs/05_considerations/02_compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@

This table lists the compatibility of major versions of `nestjs-cls` with versions of NestJS and other related packages.

| `nestjs-cls` | `<= 4.x` | `5.x` |
| :------------------------: | :-------: | :-------: |
| `@nestjs/core,common` | `<= 10.x` | `>= 11` |
| `@nestjs/platform-express` | `<= 10.x` | `>= 11` |
| `@nestjs/platform-fastify` | `<= 10.x` | `>= 11` |
| `@nestjs/graphql` | `<= 12.x` | `>= 13` |
| `graphql` | `<= 16.x` | `>= 16.x` |
| `@nestjs/apollo` | `<= 12.x` | `>= 13.x` |
| `@apollo/server` | `<= 4.x` | `>= 4.x` |
| `@nestjs/mercurius` | `<= 12.x` | `>= 13.x` |
| `mercurius` | `<= 13.x` | `>= 16.x` |
| `@nestjs/websockets` | `<= 10.x` | `>= 11.x` |
| `@nestjs/platform-ws` | `<= 10.x` | `>= 11.x` |
| `nestjs-cls` | `<= 4.x` | `>= 5.0 <= 5.1` | `>= 5.2` |
| :------------------------: | :------: | :-------------: | :------: |
| `@nestjs/core,common` | `<= 10` | `>= 11` | `>= 10` |
| `@nestjs/platform-express` | `<= 10` | `>= 11` | `>= 10` |
| `@nestjs/platform-fastify` | `<= 10` | `>= 11` | `>= 10` |
| `@nestjs/graphql` | `<= 12` | `>= 13` | `>= 12` |
| `graphql` | `<= 16` | `>= 16` | `>= 16` |
| `@nestjs/apollo` | `<= 12` | `>= 13` | `<= 12` |
| `@apollo/server` | `<= 4` | `>= 4` | `>= 4` |
| `@nestjs/mercurius` | `<= 12` | `>= 13` | `>= 12` |
| `mercurius` | `<= 13` | `>= 16` | `>= 10` |
| `@nestjs/websockets` | `<= 10` | `>= 11` | `>= 10` |
| `@nestjs/platform-ws` | `<= 10` | `>= 11` | `>= 10` |

The table below outlines the compatibility of different ways of initializing the CLS context with various transports:

| | REST | GQL | WS[\*](#websockets) | Microservices |
| :--------------------------------------------------------------------------------------------: | :--: | :-: | :-----------------: | :-----------: |
| **ClsMiddleware** | | | | |
| **ClsGuard** <br/>(uses `enterWith`) | | | | |
| **ClsInterceptor** <br/>(context inaccessible<br/>in _Guards_ and<br/> in _Exception Filters_) | | | | |
| **ClsMiddleware** || |||
| **ClsGuard** <br/>(uses `enterWith`) || |||
| **ClsInterceptor** <br/>(context inaccessible<br/>in _Guards_ and<br/> in _Exception Filters_) || |||

## REST

This package is compatible with Nest-supported REST controllers and the preferred way is to use the `ClsMiddleware` with the `mount` option set to `true`.

Tested with:

- ✔ Express
- ✔ Fastify
- ✔ Express
- ✔ Fastify

Known issues:

- In case API versioning is used, the automatic mounting of the `ClsMiddleware` does not work and it needs to be mounted manually. See issue [#67](https://github.com/Papooch/nestjs-cls/issues/67) for details.
- Some existing Express middlewares may cause context loss, if that happens, mount the `ClsMiddleware` manually _after_ those offending ones ([#50](https://github.com/Papooch/nestjs-cls/issues/50#issuecomment-1368162870))
- In case API versioning is used, the automatic mounting of the `ClsMiddleware` does not work and it needs to be mounted manually. See issue [#67](https://github.com/Papooch/nestjs-cls/issues/67) for details.
- Some existing Express middlewares may cause context loss, if that happens, mount the `ClsMiddleware` manually _after_ those offending ones ([#50](https://github.com/Papooch/nestjs-cls/issues/50#issuecomment-1368162870))

## GraphQL

Expand All @@ -48,8 +48,8 @@ Due to this, you should ensure that any operation on the CLS store within enhanc

Tested with:

- ✔ Apollo (Express)
- ✔ Mercurius (Fastify)
- ✔ Apollo (Express)
- ✔ Mercurius (Fastify)

### `@nestjs/graphql >= 10`

Expand Down
33 changes: 28 additions & 5 deletions docs/docs/10_migration-guide/01_v4x-v5x.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# `v4.x``v5.x`

The `v5` major version is backwards compatible with `v4`, unless you relied on the `@nestjs/platform-express` with manually-mounted `ClsMiddleware` to initialize the context.
The `v5` major version is backwards compatible with `v4`, unless you used it with _manually-mounted_ `ClsMiddleware` to initialize the context.

The breaking change _does not_ affect `@nestjs/platform-fastify`.
The initial release of `v5.x` only supported NestJS 11, but backward support for NestJS 10 was added in `v5.2`

Compatibility with plugins remain unaffected and they only require a patch version bump to satisfy the peer dependency on `nestjs-cls`.
Compatibility with plugins remains unaffected and they only require a patch version bump to satisfy the peer dependency on `nestjs-cls`.

## Changed default ClsMiddleware mount point (Express)
## Changed default ClsMiddleware mount point

Since NestJS v11 [now ships with Express v5](https://docs.nestjs.com/migration-guide#express-v5), which changes the route matching algorithm, the default mount point of the `ClsMiddleware` was changed from `'*'` to `'/'` in `v5`.
Since NestJS v11 [now ships with Express v5 and Fastify v5](https://docs.nestjs.com/migration-guide) which changes the route matching algorithm, the default mount point of the `ClsMiddleware` was changed from `'*'` to `'/'` (and from `(.*)` to `{*splat}` for Fastify).

If you used the automatic middleware mounting option in `ClsModule.forRoot` (i.e. `middleware: { mount: true }`), then you don't need to do anything.

If you manually mounted the middleware, you should adjust the mount point to `'/'` (or any other route that is relevant to you, according to the new matching algorithm).

For _Express_:

```diff
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
Expand All @@ -26,3 +28,24 @@ export class AppModule implements NestModule {
}
}
```

For _Fastify_

```diff
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ClsMiddleware)
// highlight-start
- .forRoutes('(.*)');
+ .forRoutes('{*splat}');
// highlight-end
}
}
```

:::info

Since `v5.2`, `nestjs-cls` adds back support for NestJS v10. The correct mount point will be decided automatically by detecting the version of either Express or Fastify.

:::

0 comments on commit 2803ce6

Please sign in to comment.