UNPKG

2.59 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2019 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.FilterStackFactory = exports.FilterStack = void 0;
20class FilterStack {
21 constructor(filters) {
22 this.filters = filters;
23 }
24 sendMetadata(metadata) {
25 let result = metadata;
26 for (let i = 0; i < this.filters.length; i++) {
27 result = this.filters[i].sendMetadata(result);
28 }
29 return result;
30 }
31 receiveMetadata(metadata) {
32 let result = metadata;
33 for (let i = this.filters.length - 1; i >= 0; i--) {
34 result = this.filters[i].receiveMetadata(result);
35 }
36 return result;
37 }
38 sendMessage(message) {
39 let result = message;
40 for (let i = 0; i < this.filters.length; i++) {
41 result = this.filters[i].sendMessage(result);
42 }
43 return result;
44 }
45 receiveMessage(message) {
46 let result = message;
47 for (let i = this.filters.length - 1; i >= 0; i--) {
48 result = this.filters[i].receiveMessage(result);
49 }
50 return result;
51 }
52 receiveTrailers(status) {
53 let result = status;
54 for (let i = this.filters.length - 1; i >= 0; i--) {
55 result = this.filters[i].receiveTrailers(result);
56 }
57 return result;
58 }
59 refresh() {
60 for (const filter of this.filters) {
61 filter.refresh();
62 }
63 }
64 push(filters) {
65 this.filters.unshift(...filters);
66 }
67 getFilters() {
68 return this.filters;
69 }
70}
71exports.FilterStack = FilterStack;
72class FilterStackFactory {
73 constructor(factories) {
74 this.factories = factories;
75 }
76 push(filterFactories) {
77 this.factories.unshift(...filterFactories);
78 }
79 createFilter(callStream) {
80 return new FilterStack(this.factories.map((factory) => factory.createFilter(callStream)));
81 }
82}
83exports.FilterStackFactory = FilterStackFactory;
84//# sourceMappingURL=filter-stack.js.map
\No newline at end of file