-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix durable context id resolution for enhancers (#11305)
- Loading branch information
1 parent
b106733
commit aa6baa4
Showing
8 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
Scope, | ||
} from '@nestjs/common'; | ||
import { DurableService } from './durable.service'; | ||
|
||
@Injectable({ scope: Scope.REQUEST, durable: true }) | ||
export class DurableGuard implements CanActivate { | ||
public instanceCounter = 0; | ||
constructor(private readonly durableService: DurableService) {} | ||
|
||
public async canActivate(context: ExecutionContext): Promise<boolean> { | ||
if (typeof this.durableService === 'undefined') { | ||
throw new Error('Durable service is undefined'); | ||
} | ||
this.instanceCounter++; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { APP_GUARD } from '@nestjs/core'; | ||
import { DurableController } from './durable.controller'; | ||
import { DurableGuard } from './durable.guard'; | ||
import { DurableService } from './durable.service'; | ||
|
||
@Module({ | ||
controllers: [DurableController], | ||
providers: [DurableService], | ||
providers: [ | ||
DurableService, | ||
{ | ||
provide: APP_GUARD, | ||
useClass: DurableGuard, | ||
}, | ||
], | ||
}) | ||
export class DurableModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters