1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import { Call, StatusObject, WriteObject } from './call-stream';
|
19 | import { Metadata } from './metadata';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export interface Filter {
|
26 | sendMetadata(metadata: Promise<Metadata>): Promise<Metadata>;
|
27 |
|
28 | receiveMetadata(metadata: Metadata): Metadata;
|
29 |
|
30 | sendMessage(message: Promise<WriteObject>): Promise<WriteObject>;
|
31 |
|
32 | receiveMessage(message: Promise<Buffer>): Promise<Buffer>;
|
33 |
|
34 | receiveTrailers(status: StatusObject): StatusObject;
|
35 |
|
36 | refresh(): void;
|
37 | }
|
38 |
|
39 | export abstract class BaseFilter implements Filter {
|
40 | async sendMetadata(metadata: Promise<Metadata>): Promise<Metadata> {
|
41 | return metadata;
|
42 | }
|
43 |
|
44 | receiveMetadata(metadata: Metadata): Metadata {
|
45 | return metadata;
|
46 | }
|
47 |
|
48 | async sendMessage(message: Promise<WriteObject>): Promise<WriteObject> {
|
49 | return message;
|
50 | }
|
51 |
|
52 | async receiveMessage(message: Promise<Buffer>): Promise<Buffer> {
|
53 | return message;
|
54 | }
|
55 |
|
56 | receiveTrailers(status: StatusObject): StatusObject {
|
57 | return status;
|
58 | }
|
59 |
|
60 | refresh(): void {}
|
61 | }
|
62 |
|
63 | export interface FilterFactory<T extends Filter> {
|
64 | createFilter(callStream: Call): T;
|
65 | }
|