-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge pull request #58 from interceptor
Interceptor
- Loading branch information
Showing
16 changed files
with
187 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './rmq-message.decorator'; | ||
export * from './transform.decorator'; | ||
export * from './serdes.decorator'; | ||
export * from './interceptor.decorator'; |
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,6 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
import { INTERCEPTOR_KEY } from '../constants'; | ||
import { TypeRmqInterceptor } from 'lib/interfaces'; | ||
|
||
export const RmqInterceptor = (options: TypeRmqInterceptor) => | ||
SetMetadata(INTERCEPTOR_KEY, options); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './rmq-options.interface'; | ||
export * from './interceptor.interface'; | ||
export * from './serdes.interface'; | ||
export * from './metategs'; | ||
export * from './rmqService'; |
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,13 @@ | ||
import { ConsumeMessage } from 'amqplib'; | ||
|
||
export type ReverseFunction = ( | ||
content: any, | ||
message: ConsumeMessage, | ||
) => Promise<void>; | ||
export abstract class IRmqInterceptor { | ||
abstract intercept( | ||
content: any, | ||
message: ConsumeMessage, | ||
): Promise<ReverseFunction>; | ||
} | ||
export type TypeRmqInterceptor = typeof IRmqInterceptor; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ConsumeMessage } from 'amqplib'; | ||
import { | ||
ReverseFunction, | ||
IRmqInterceptor, | ||
} from '../../lib/interfaces/interceptor.interface'; | ||
|
||
export class EventInterceptorModule implements IRmqInterceptor { | ||
async intercept( | ||
message: ConsumeMessage, | ||
content: any, | ||
): Promise<ReverseFunction> { | ||
if (content?.array) content.array.push(1); | ||
return async (content: any, message: ConsumeMessage) => { | ||
if (content?.array) content.array.push(6); | ||
}; | ||
} | ||
} | ||
|
||
export class EventInterceptorClass implements IRmqInterceptor { | ||
async intercept( | ||
message: ConsumeMessage, | ||
content: any, | ||
): Promise<ReverseFunction> { | ||
if (content?.array) content.array.push(2); | ||
return async (content: any, message: ConsumeMessage) => { | ||
if (content?.array) content.array.push(5); | ||
}; | ||
} | ||
} | ||
|
||
export class EventInterceptorEndpoint implements IRmqInterceptor { | ||
async intercept( | ||
message: ConsumeMessage, | ||
content: any, | ||
): Promise<ReverseFunction> { | ||
content.array.push(3); | ||
return async (content: any, message: ConsumeMessage) => { | ||
content.array.push(4); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.