Skip to content

Commit 6b960e3

Browse files
committed
feat(nestjs): export nestjs interceptor and decorators
1 parent 589200a commit 6b960e3

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/common/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Request } from 'express';
2+
3+
export type KeyGenFn = (req: Request) => string;

src/common/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Request } from 'express';
1+
import { KeyGenFn } from './types';
22

33
/**
44
* default cache key generator
55
*/
6-
export const defaultKeyGenerator = (name: string) => (req: Request) => {
7-
return `${name}-${req.method}-${req.originalUrl.replace(/[._~:/?#[\]@!$&'()*+,;=]/g, '')}`;
8-
};
6+
export const defaultKeyGenerator =
7+
(name: string): KeyGenFn =>
8+
req => {
9+
return `${name}-${req.method}-${req.originalUrl.replace(/[._~:/?#[\]@!$&'()*+,;=]/g, '')}`;
10+
};

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type { StalierOptions, StalierResult } from './stalier.types';
22
export * from './stalier';
33
export * from './express';
4+
export * from './nestjs';

src/nestjs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './decorators';
2+
export * from './interceptor';

src/nestjs/interceptor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { Cache } from 'cache-manager';
66
import { withStaleWhileRevalidate } from '../stalier';
77
import { MATCH_HEADER, STALIER_APP_NAME, STALIER_CACHE_KEY_GEN, STALIER_HEADER_KEY } from '../common/constants';
88
import { defaultKeyGenerator } from '../common/utils';
9-
10-
type KeyGenFn = (req: Request) => string;
9+
import { KeyGenFn } from '../common/types';
1110

1211
@Injectable()
1312
export class StalierInterceptor implements NestInterceptor {

0 commit comments

Comments
 (0)