mirror of https://github.com/grpc/grpc-node.git
change CompressionAlgorithms to an enum
This commit is contained in:
parent
9150bdfd24
commit
dc9752addc
|
@ -38,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'?: keyof typeof CompressionAlgorithms;
|
||||
'grpc.default_compression_algorithm'?: CompressionAlgorithms;
|
||||
'grpc-node.max_session_memory'?: number;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
export const CompressionAlgorithms = {
|
||||
0: 'identity',
|
||||
1: 'deflate',
|
||||
2: 'gzip'
|
||||
} as const;
|
||||
export enum CompressionAlgorithms {
|
||||
identity = 0,
|
||||
deflate = 1,
|
||||
gzip = 2
|
||||
};
|
||||
|
|
|
@ -26,13 +26,11 @@ import { BaseFilter, Filter, FilterFactory } from './filter';
|
|||
import * as logging from './logging';
|
||||
import { Metadata, MetadataValue } from './metadata';
|
||||
|
||||
const CompressionAlgorithKeys = new Set(Object.keys(CompressionAlgorithms));
|
||||
|
||||
const isCompressionAlgorithmKey = (key: number | undefined): key is keyof typeof CompressionAlgorithms => {
|
||||
return typeof key === 'number' && CompressionAlgorithKeys.has(key.toString());
|
||||
const isCompressionAlgorithmKey = (key: number): key is CompressionAlgorithms => {
|
||||
return typeof key === 'number' && typeof CompressionAlgorithms[key] === 'string';
|
||||
}
|
||||
|
||||
type CompressionAlgorithm = (typeof CompressionAlgorithms)[keyof typeof CompressionAlgorithms];
|
||||
type CompressionAlgorithm = keyof typeof CompressionAlgorithms;
|
||||
|
||||
type SharedCompressionFilterConfig = {
|
||||
serverSupportedEncodingHeader?: string;
|
||||
|
@ -191,7 +189,7 @@ export class CompressionFilter extends BaseFilter implements Filter {
|
|||
const compressionAlgorithmKey = channelOptions['grpc.default_compression_algorithm'];
|
||||
if (compressionAlgorithmKey !== undefined) {
|
||||
if (isCompressionAlgorithmKey(compressionAlgorithmKey)) {
|
||||
const clientSelectedEncoding = CompressionAlgorithms[compressionAlgorithmKey];
|
||||
const clientSelectedEncoding = CompressionAlgorithms[compressionAlgorithmKey] as CompressionAlgorithm;
|
||||
const serverSupportedEncodings = sharedFilterConfig.serverSupportedEncodingHeader?.split(',');
|
||||
/**
|
||||
* There are two possible situations here:
|
||||
|
|
Loading…
Reference in New Issue