grpc-js: Enable the noUnusedLocals TypeScript compiler option

This commit is contained in:
Michael Lumish 2023-07-12 15:22:15 -07:00
parent 45e277547f
commit 713a2c9bd1
25 changed files with 70 additions and 121 deletions

View File

@ -38,14 +38,6 @@ export type CheckServerIdentityCallback = (
cert: PeerCertificate
) => Error | undefined;
function bufferOrNullEqual(buf1: Buffer | null, buf2: Buffer | null) {
if (buf1 === null && buf2 === null) {
return true;
} else {
return buf1 !== null && buf2 !== null && buf1.equals(buf2);
}
}
/**
* Additional peer verification options that can be set when creating
* SSL credentials.

View File

@ -32,7 +32,6 @@ import {
import { Status } from './constants';
import { Channel } from './channel';
import { CallOptions } from './client';
import { CallCredentials } from './call-credentials';
import { ClientMethodDefinition } from './make-client';
import { getErrorMessage } from './error';

View File

@ -282,7 +282,7 @@ export class CompressionFilter extends BaseFilter implements Filter {
export class CompressionFilterFactory
implements FilterFactory<CompressionFilter> {
private sharedFilterConfig: SharedCompressionFilterConfig = {};
constructor(private readonly channel: Channel, private readonly options: ChannelOptions) {}
constructor(channel: Channel, private readonly options: ChannelOptions) {}
createFilter(): CompressionFilter {
return new CompressionFilter(this.options, this.sharedFilterConfig);
}

View File

@ -43,9 +43,7 @@ import {
loadPackageDefinition,
makeClientConstructor,
MethodDefinition,
ProtobufTypeDefinition,
Serialize,
ServiceClientConstructor,
ServiceDefinition,
} from './make-client';
import { Metadata, MetadataOptions, MetadataValue } from './metadata';

View File

@ -20,7 +20,7 @@ import { ChannelOptions } from './channel-options';
import { ResolvingLoadBalancer } from './resolving-load-balancer';
import { SubchannelPool, getSubchannelPool } from './subchannel-pool';
import { ChannelControlHelper } from './load-balancer';
import { UnavailablePicker, Picker, PickResultType } from './picker';
import { UnavailablePicker, Picker } from './picker';
import { Metadata } from './metadata';
import { Status, LogVerbosity, Propagate } from './constants';
import { FilterStackFactory } from './filter-stack';
@ -31,22 +31,19 @@ import {
getDefaultAuthority,
mapUriDefaultScheme,
} from './resolver';
import { trace, log } from './logging';
import { trace } from './logging';
import { SubchannelAddress } from './subchannel-address';
import { MaxMessageSizeFilterFactory } from './max-message-size-filter';
import { mapProxyName } from './http_proxy';
import { GrpcUri, parseUri, splitHostPort, uriToString } from './uri-parser';
import { GrpcUri, parseUri, uriToString } from './uri-parser';
import { ServerSurfaceCall } from './server-call';
import { Filter } from './filter';
import { ConnectivityState } from './connectivity-state';
import { ChannelInfo, ChannelRef, ChannelzCallTracker, ChannelzChildrenTracker, ChannelzTrace, registerChannelzChannel, SubchannelRef, unregisterChannelzRef } from './channelz';
import { Subchannel } from './subchannel';
import { LoadBalancingCall } from './load-balancing-call';
import { CallCredentials } from './call-credentials';
import { Call, CallStreamOptions, InterceptingListener, MessageContext, StatusObject } from './call-interface';
import { SubchannelCall } from './subchannel-call';
import { Deadline, deadlineToString, getDeadlineTimeoutString } from './deadline';
import { Call, CallStreamOptions, StatusObject } from './call-interface';
import { Deadline, deadlineToString } from './deadline';
import { ResolvingCall } from './resolving-call';
import { getNextCallNumber } from './call-number';
import { restrictControlPlaneStatusCode } from './control-plane-status';

View File

@ -20,11 +20,9 @@ import { ConnectivityState } from "./connectivity-state";
import { LogVerbosity, Status } from "./constants";
import { durationToMs, isDuration, msToDuration } from "./duration";
import { ChannelControlHelper, createChildChannelControlHelper, registerLoadBalancerType } from "./experimental";
import { BaseFilter, Filter, FilterFactory } from "./filter";
import { getFirstUsableConfig, LoadBalancer, LoadBalancingConfig, validateLoadBalancingConfig } from "./load-balancer";
import { ChildLoadBalancerHandler } from "./load-balancer-child-handler";
import { PickArgs, Picker, PickResult, PickResultType, QueuePicker, UnavailablePicker } from "./picker";
import { Subchannel } from "./subchannel";
import { PickArgs, Picker, PickResult, PickResultType } from "./picker";
import { SubchannelAddress, subchannelAddressToString } from "./subchannel-address";
import { BaseSubchannelWrapper, ConnectivityStateListener, SubchannelInterface } from "./subchannel-interface";
import * as logging from './logging';

View File

@ -16,7 +16,6 @@
*/
import { ChannelOptions } from './channel-options';
import { Subchannel } from './subchannel';
import { SubchannelAddress } from './subchannel-address';
import { ConnectivityState } from './connectivity-state';
import { Picker } from './picker';

View File

@ -21,7 +21,6 @@ import { SubchannelCall } from "./subchannel-call";
import { ConnectivityState } from "./connectivity-state";
import { LogVerbosity, Status } from "./constants";
import { Deadline, getDeadlineTimeoutString } from "./deadline";
import { FilterStack, FilterStackFactory } from "./filter-stack";
import { InternalChannel } from "./internal-channel";
import { Metadata } from "./metadata";
import { PickResultType } from "./picker";
@ -48,7 +47,6 @@ export class LoadBalancingCall implements Call {
private readPending = false;
private pendingMessage: {context: MessageContext, message: Buffer} | null = null;
private pendingHalfClose = false;
private pendingChildStatus: StatusObject | null = null;
private ended = false;
private serviceUrl: string;
private metadata: Metadata | null = null;

View File

@ -29,7 +29,7 @@ export class MaxMessageSizeFilter extends BaseFilter implements Filter {
private maxSendMessageSize: number = DEFAULT_MAX_SEND_MESSAGE_LENGTH;
private maxReceiveMessageSize: number = DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH;
constructor(
private readonly options: ChannelOptions
options: ChannelOptions
) {
super();
if ('grpc.max_send_message_length' in options) {

View File

@ -229,11 +229,6 @@ export class Metadata {
return result;
}
// For compatibility with the other Metadata implementation
private _getCoreRepresentation() {
return this.internalRepr;
}
/**
* This modifies the behavior of JSON.stringify to show an object
* representation of the metadata map.

View File

@ -15,7 +15,7 @@
*
*/
import { Duplex, Readable, Writable } from 'stream';
import { Readable, Writable } from 'stream';
import { EmitterAugmentation1 } from './events';
/* eslint-disable @typescript-eslint/no-explicit-any */

View File

@ -42,7 +42,7 @@ class IpResolver implements Resolver {
private addresses: SubchannelAddress[] = [];
private error: StatusObject | null = null;
constructor(
private target: GrpcUri,
target: GrpcUri,
private listener: ResolverListener,
channelOptions: ChannelOptions
) {

View File

@ -18,7 +18,7 @@
import { CallCredentials } from "./call-credentials";
import { Call, CallStreamOptions, InterceptingListener, MessageContext, StatusObject } from "./call-interface";
import { LogVerbosity, Propagate, Status } from "./constants";
import { Deadline, deadlineToString, getDeadlineTimeoutString, getRelativeTimeout, minDeadline } from "./deadline";
import { Deadline, deadlineToString, getRelativeTimeout, minDeadline } from "./deadline";
import { FilterStack, FilterStackFactory } from "./filter-stack";
import { InternalChannel } from "./internal-channel";
import { Metadata } from "./metadata";

View File

@ -36,7 +36,6 @@ import { SubchannelAddress } from './subchannel-address';
import { GrpcUri, uriToString } from './uri-parser';
import { ChildLoadBalancerHandler } from './load-balancer-child-handler';
import { ChannelOptions } from './channel-options';
import { PickFirstLoadBalancingConfig } from './load-balancer-pick-first';
const TRACER_NAME = 'resolving_load_balancer';
@ -44,8 +43,6 @@ function trace(text: string): void {
logging.trace(LogVerbosity.DEBUG, TRACER_NAME, text);
}
const DEFAULT_LOAD_BALANCER_NAME = 'pick_first';
function getDefaultConfigSelector(
serviceConfig: ServiceConfig | null
): ConfigSelector {
@ -137,7 +134,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
constructor(
private readonly target: GrpcUri,
private readonly channelControlHelper: ChannelControlHelper,
private readonly channelOptions: ChannelOptions,
channelOptions: ChannelOptions,
private readonly onSuccessfulResolution: ResolutionCallback,
private readonly onFailedResolution: ResolutionFailureCallback
) {

View File

@ -268,6 +268,9 @@ export class ServerDuplexStreamImpl<RequestType, ResponseType>
implements ServerDuplexStream<RequestType, ResponseType>
{
cancelled: boolean;
/* This field appears to be unsued, but it is actually used in _final, which is assiged from
* ServerWritableStreamImpl.prototype._final below. */
// @ts-ignore noUnusedLocals
private trailingMetadata: Metadata;
constructor(
@ -419,7 +422,7 @@ export class Http2ServerCallStream<
constructor(
private stream: http2.ServerHttp2Stream,
private handler: Handler<RequestType, ResponseType>,
private options: ChannelOptions
options: ChannelOptions
) {
super();

View File

@ -141,10 +141,6 @@ interface ChannelzSessionInfo {
lastMessageReceivedTimestamp: Date | null;
}
interface ChannelzListenerInfo {
ref: SocketRef;
}
export class Server {
private http2ServerList: { server: (http2.Http2Server | http2.Http2SecureServer), channelzRef: SocketRef }[] = [];

View File

@ -23,19 +23,11 @@ import { Metadata } from './metadata';
import { StreamDecoder } from './stream-decoder';
import * as logging from './logging';
import { LogVerbosity } from './constants';
import { ServerSurfaceCall } from './server-call';
import { Deadline } from './deadline';
import { InterceptingListener, MessageContext, StatusObject, WriteCallback } from './call-interface';
import { CallEventTracker, Transport } from './transport';
const TRACER_NAME = 'subchannel_call';
const {
HTTP2_HEADER_STATUS,
HTTP2_HEADER_CONTENT_TYPE,
NGHTTP2_CANCEL,
} = http2.constants;
/**
* https://nodejs.org/api/errors.html#errors_class_systemerror
*/

View File

@ -46,10 +46,6 @@ const {
HTTP2_HEADER_USER_AGENT,
} = http2.constants;
/* setInterval and setTimeout only accept signed 32 bit integers. JS doesn't
* have a constant for the max signed 32 bit integer, so this is a simple way
* to calculate it */
const KEEPALIVE_MAX_TIME_MS = ~(1 << 31);
const KEEPALIVE_TIMEOUT_MS = 20000;
export interface CallEventTracker {
@ -108,11 +104,6 @@ class Http2Transport implements Transport {
// Channelz info
private channelzRef: SocketRef;
private readonly channelzEnabled: boolean = true;
/**
* Name of the remote server, if it is not the same as the subchannel
* address, i.e. if connecting through an HTTP CONNECT proxy.
*/
private remoteName: string | null = null;
private streamTracker = new ChannelzCallTracker();
private keepalivesSent = 0;
private messagesSent = 0;
@ -123,7 +114,12 @@ class Http2Transport implements Transport {
constructor(
private session: http2.ClientHttp2Session,
subchannelAddress: SubchannelAddress,
options: ChannelOptions
options: ChannelOptions,
/**
* Name of the remote server, if it is not the same as the subchannel
* address, i.e. if connecting through an HTTP CONNECT proxy.
*/
private remoteName: string | null
) {
// Build user-agent string.
this.userAgent = [
@ -596,7 +592,7 @@ export class Http2SubchannelConnector implements SubchannelConnector {
session.unref();
session.once('connect', () => {
session.removeAllListeners();
resolve(new Http2Transport(session, address, options));
resolve(new Http2Transport(session, address, options, remoteName));
this.session = null;
});
session.once('close', () => {

View File

@ -165,7 +165,6 @@ describe('Call propagation', () => {
describe('Deadlines', () => {
it('should work with unary requests', (done) => {
done = multiDone(done, 2);
let call: grpc.ClientUnaryCall;
proxyServer.addService(Client.service, {
unary: (parent: grpc.ServerUnaryCall<any, any>, callback: grpc.sendUnaryData<any>) => {
client.unary(parent.request, {parent: parent, propagate_flags: grpc.propagate.DEADLINE}, (error: grpc.ServiceError, value: unknown) => {
@ -178,7 +177,7 @@ describe('Call propagation', () => {
});
const deadline = new Date();
deadline.setMilliseconds(deadline.getMilliseconds() + 100);
call = proxyClient.unary({}, {deadline}, (error: grpc.ServiceError, value: unknown) => {
proxyClient.unary({}, {deadline}, (error: grpc.ServiceError, value: unknown) => {
assert(error);
assert.strictEqual(error.code, grpc.status.DEADLINE_EXCEEDED);
done();
@ -186,7 +185,6 @@ describe('Call propagation', () => {
});
it('Should work with client streaming requests', (done) => {
done = multiDone(done, 2);
let call: grpc.ClientWritableStream<unknown>;
proxyServer.addService(Client.service, {
clientStream: (parent: grpc.ServerReadableStream<any, any>, callback: grpc.sendUnaryData<any>) => {
client.clientStream({parent: parent, propagate_flags: grpc.propagate.DEADLINE}, (error: grpc.ServiceError, value: unknown) => {
@ -199,7 +197,7 @@ describe('Call propagation', () => {
});
const deadline = new Date();
deadline.setMilliseconds(deadline.getMilliseconds() + 100);
call = proxyClient.clientStream({deadline, propagate_flags: grpc.propagate.DEADLINE}, (error: grpc.ServiceError, value: unknown) => {
proxyClient.clientStream({deadline, propagate_flags: grpc.propagate.DEADLINE}, (error: grpc.ServiceError, value: unknown) => {
assert(error);
assert.strictEqual(error.code, grpc.status.DEADLINE_EXCEEDED);
done();

View File

@ -19,14 +19,11 @@ import * as assert from 'assert';
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
import * as protoLoader from '@grpc/proto-loader';
import { CallCredentials } from '../src/call-credentials';
import { ChannelCredentials } from '../src/channel-credentials';
import * as grpc from '../src';
import { ServiceClient, ServiceClientConstructor } from '../src/make-client';
import { TestServiceClient, TestServiceHandlers } from './generated/TestService';
import { ProtoGrpcType as TestServiceGrpcType } from './generated/test_service';
import { assert2, loadProtoFile, mockFunction } from './common';
import { sendUnaryData, ServerUnaryCall, ServiceError } from '../src';

View File

@ -21,8 +21,6 @@ import * as grpc from '../src';
import { ProtoGrpcType } from '../src/generated/channelz'
import { ChannelzClient } from '../src/generated/grpc/channelz/v1/Channelz';
import { Channel__Output } from '../src/generated/grpc/channelz/v1/Channel';
import { Server__Output } from '../src/generated/grpc/channelz/v1/Server';
import { ServiceClient, ServiceClientConstructor } from '../src/make-client';
import { loadProtoFile } from './common';

View File

@ -19,14 +19,10 @@ import * as assert from 'assert';
import * as grpc from '../src';
import { experimental } from '../src';
import { ServerCredentials } from '../src';
import { ServiceClient, ServiceClientConstructor } from '../src/make-client';
import { loadProtoFile } from './common';
import ServiceConfig = experimental.ServiceConfig;
const clientInsecureCreds = grpc.credentials.createInsecure();
const serverInsecureCreds = ServerCredentials.createInsecure();
const TIMEOUT_SERVICE_CONFIG: ServiceConfig = {
loadBalancingConfig: [],
methodConfig: [{

View File

@ -20,7 +20,6 @@ import * as path from 'path';
import * as grpc from '../src';
import { loadProtoFile } from './common';
import { OutlierDetectionLoadBalancingConfig } from '../src/load-balancer-outlier-detection'
import { ServiceClient } from '../src/make-client';
function multiDone(done: Mocha.Done, target: number) {
let count = 0;

View File

@ -686,7 +686,7 @@ describe('Compressed requests', () => {
},
ServerStream(call) {
const { metadata, request } = call;
const { request } = call;
for (let i = 0; i < 5; i++) {
call.write({ count: request.message.length });

View File

@ -7,7 +7,8 @@
"module": "commonjs",
"resolveJsonModule": true,
"incremental": true,
"types": ["mocha"]
"types": ["mocha"],
"noUnusedLocals": true
},
"include": [
"src/**/*.ts",