1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import { StatusObject, WriteObject } from './call-interface';
|
19 | import { Metadata } from './metadata';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export interface Filter {
|
28 | sendMetadata(metadata: Promise<Metadata>): Promise<Metadata>;
|
29 |
|
30 | receiveMetadata(metadata: Metadata): Metadata;
|
31 |
|
32 | sendMessage(message: Promise<WriteObject>): Promise<WriteObject>;
|
33 |
|
34 | receiveMessage(message: Promise<Buffer>): Promise<Buffer>;
|
35 |
|
36 | receiveTrailers(status: StatusObject): StatusObject;
|
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 |
|
61 | export interface FilterFactory<T extends Filter> {
|
62 | createFilter(): T;
|
63 | }
|