UNPKG

2.54 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 push(filters) {
60 this.filters.unshift(...filters);
61 }
62 getFilters() {
63 return this.filters;
64 }
65}
66exports.FilterStack = FilterStack;
67class FilterStackFactory {
68 constructor(factories) {
69 this.factories = factories;
70 }
71 push(filterFactories) {
72 this.factories.unshift(...filterFactories);
73 }
74 clone() {
75 return new FilterStackFactory([...this.factories]);
76 }
77 createFilter() {
78 return new FilterStack(this.factories.map((factory) => factory.createFilter()));
79 }
80}
81exports.FilterStackFactory = FilterStackFactory;
82//# sourceMappingURL=filter-stack.js.map
\No newline at end of file