diff --git a/docs/docs/05_considerations/02_compatibility.md b/docs/docs/05_considerations/02_compatibility.md index 945b415..e581753 100644 --- a/docs/docs/05_considerations/02_compatibility.md +++ b/docs/docs/05_considerations/02_compatibility.md @@ -4,27 +4,27 @@ 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**
(uses `enterWith`) | ✔ | ✔ | ✔ | ✔ | -| **ClsInterceptor**
(context inaccessible
in _Guards_ and
in _Exception Filters_) | ✔ | ✔ | ✔ | ✔ | +| **ClsMiddleware** | ✔ | ✔ | ✖ | ✖ | +| **ClsGuard**
(uses `enterWith`) | ✔ | ✔ | ✔ | ✔ | +| **ClsInterceptor**
(context inaccessible
in _Guards_ and
in _Exception Filters_) | ✔ | ✔ | ✔ | ✔ | ## REST @@ -32,13 +32,13 @@ This package is compatible with Nest-supported REST controllers and the preferre 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 @@ -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` diff --git a/docs/docs/10_migration-guide/01_v4x-v5x.md b/docs/docs/10_migration-guide/01_v4x-v5x.md index aa9d772..2652387 100644 --- a/docs/docs/10_migration-guide/01_v4x-v5x.md +++ b/docs/docs/10_migration-guide/01_v4x-v5x.md @@ -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) { @@ -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. + +:::