From 21b09e25ba9c430389d8c61e674c531757e6f2ae Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 26 Oct 2021 13:51:42 -0700 Subject: [PATCH] separate compression algorithms to avoid circular dependency --- packages/grpc-js/src/channel-options.ts | 4 +++- .../grpc-js/src/compression-algorithms.ts | 22 +++++++++++++++++++ packages/grpc-js/src/compression-filter.ts | 7 +----- packages/grpc-js/src/index.ts | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 packages/grpc-js/src/compression-algorithms.ts diff --git a/packages/grpc-js/src/channel-options.ts b/packages/grpc-js/src/channel-options.ts index f0b37d7a..b54ae4ed 100644 --- a/packages/grpc-js/src/channel-options.ts +++ b/packages/grpc-js/src/channel-options.ts @@ -15,6 +15,8 @@ * */ +import { CompressionAlgorithms } from './compression-algorithms'; + /** * An interface that contains options used when initializing a Channel instance. */ @@ -36,7 +38,7 @@ export interface ChannelOptions { 'grpc.enable_http_proxy'?: number; 'grpc.http_connect_target'?: string; 'grpc.http_connect_creds'?: string; - 'grpc.default_compression_algorithm'?: number; + 'grpc.default_compression_algorithm'?: keyof typeof CompressionAlgorithms; 'grpc-node.max_session_memory'?: number; // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; diff --git a/packages/grpc-js/src/compression-algorithms.ts b/packages/grpc-js/src/compression-algorithms.ts new file mode 100644 index 00000000..8ec283cf --- /dev/null +++ b/packages/grpc-js/src/compression-algorithms.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +export const CompressionAlgorithms = { + 0: 'identity', + 1: 'deflate', + 2: 'gzip' +} as const; diff --git a/packages/grpc-js/src/compression-filter.ts b/packages/grpc-js/src/compression-filter.ts index ae507d33..69fcf48d 100644 --- a/packages/grpc-js/src/compression-filter.ts +++ b/packages/grpc-js/src/compression-filter.ts @@ -19,16 +19,11 @@ import * as zlib from 'zlib'; import { Call, WriteObject, WriteFlags } from './call-stream'; import { Channel } from './channel'; +import { CompressionAlgorithms } from './compression-algorithms'; import { BaseFilter, Filter, FilterFactory } from './filter'; import { Metadata, MetadataValue } from './metadata'; import { ChannelOptions } from './channel-options'; -export const CompressionAlgorithms = { - 0: 'identity', - 1: 'deflate', - 2: 'gzip' -} as const; - const CompressionAlgorithKeys = new Set(Object.keys(CompressionAlgorithms)); const isCompressionAlgorithmKey = (key: number | undefined): key is keyof typeof CompressionAlgorithms => { diff --git a/packages/grpc-js/src/index.ts b/packages/grpc-js/src/index.ts index 7e1ed7a5..f34c19a1 100644 --- a/packages/grpc-js/src/index.ts +++ b/packages/grpc-js/src/index.ts @@ -25,7 +25,7 @@ import { import { CallCredentials, OAuth2Client } from './call-credentials'; import { Deadline, StatusObject } from './call-stream'; import { Channel, ChannelImplementation } from './channel'; -import { CompressionAlgorithms } from './compression-filter'; +import { CompressionAlgorithms } from './compression-algorithms'; import { ConnectivityState } from './connectivity-state'; import { ChannelCredentials } from './channel-credentials'; import {