From bc749acad8784bdbddadaa30bca6bd06d229ad8e Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 22 Nov 2024 14:35:40 -0800 Subject: [PATCH] grpc-js-xds: Update @types/node and update code for compatibility --- packages/grpc-js-xds/package.json | 2 +- packages/grpc-js-xds/src/load-balancer-priority.ts | 4 ++-- .../grpc-js-xds/src/load-balancer-weighted-target.ts | 2 +- packages/grpc-js-xds/src/server.ts | 10 +++++----- packages/grpc-js-xds/src/xds-client.ts | 4 ++-- packages/grpc-js-xds/test/client.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/grpc-js-xds/package.json b/packages/grpc-js-xds/package.json index b5321bd02..f6cb72352 100644 --- a/packages/grpc-js-xds/package.json +++ b/packages/grpc-js-xds/package.json @@ -37,7 +37,7 @@ "@types/gulp": "^4.0.6", "@types/gulp-mocha": "0.0.32", "@types/mocha": "^5.2.6", - "@types/node": "^13.11.1", + "@types/node": ">=20.11.20", "@types/yargs": "^15.0.5", "find-free-ports": "^3.1.1", "gts": "^5.0.1", diff --git a/packages/grpc-js-xds/src/load-balancer-priority.ts b/packages/grpc-js-xds/src/load-balancer-priority.ts index c70c606a2..d1a996982 100644 --- a/packages/grpc-js-xds/src/load-balancer-priority.ts +++ b/packages/grpc-js-xds/src/load-balancer-priority.ts @@ -184,8 +184,8 @@ export class PriorityLoadBalancer implements LoadBalancer { private connectivityState: ConnectivityState = ConnectivityState.IDLE; private picker: Picker; private childBalancer: ChildLoadBalancerHandler; - private failoverTimer: NodeJS.Timer | null = null; - private deactivationTimer: NodeJS.Timer | null = null; + private failoverTimer: NodeJS.Timeout | null = null; + private deactivationTimer: NodeJS.Timeout | null = null; private seenReadyOrIdleSinceTransientFailure = false; constructor(private parent: PriorityLoadBalancer, private name: string, ignoreReresolutionRequests: boolean) { this.childBalancer = new ChildLoadBalancerHandler(experimental.createChildChannelControlHelper(this.parent.channelControlHelper, { diff --git a/packages/grpc-js-xds/src/load-balancer-weighted-target.ts b/packages/grpc-js-xds/src/load-balancer-weighted-target.ts index 8d26538e7..9428c7d23 100644 --- a/packages/grpc-js-xds/src/load-balancer-weighted-target.ts +++ b/packages/grpc-js-xds/src/load-balancer-weighted-target.ts @@ -170,7 +170,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer { private connectivityState: ConnectivityState = ConnectivityState.IDLE; private picker: Picker; private childBalancer: ChildLoadBalancerHandler; - private deactivationTimer: NodeJS.Timer | null = null; + private deactivationTimer: NodeJS.Timeout | null = null; private weight: number = 0; constructor(private parent: WeightedTargetLoadBalancer, private name: string) { diff --git a/packages/grpc-js-xds/src/server.ts b/packages/grpc-js-xds/src/server.ts index 7c04122eb..d1bd2b5a1 100644 --- a/packages/grpc-js-xds/src/server.ts +++ b/packages/grpc-js-xds/src/server.ts @@ -460,7 +460,7 @@ interface MatchFieldEvaluator { isMoreSpecific: (matcher1: MatcherType, matcher2: MatcherType) => boolean; } -type FieldType = MatcherType extends CidrRange ? (string | undefined) : MatcherType extends (ConnectionSourceType) ? {localAddress: string, remoteAddress?: (string | undefined)} : MatcherType extends number ? number | undefined : never; +type FieldType = MatcherType extends CidrRange ? (string | undefined) : MatcherType extends (ConnectionSourceType) ? {localAddress?: (string | undefined), remoteAddress?: (string | undefined)} : MatcherType extends number ? number | undefined : never; function cidrRangeMatch(range: CidrRange | undefined, address: string | undefined): boolean { return !range || (!!address && inCidrRange(range, address)); @@ -473,14 +473,14 @@ function cidrRangeMoreSpecific(range1: CidrRange | undefined, range2: CidrRange return !!range1 && range1.prefixLen > range2.prefixLen; } -function sourceTypeMatch(sourceType: ConnectionSourceType, addresses: {localAddress: string, remoteAddress?: (string | undefined)}): boolean { +function sourceTypeMatch(sourceType: ConnectionSourceType, addresses: {localAddress?: (string | undefined), remoteAddress?: (string | undefined)}): boolean { switch (sourceType) { case "ANY": return true; case "SAME_IP_OR_LOOPBACK": - return !!addresses.remoteAddress && isSameIpOrLoopback(addresses.remoteAddress, addresses.localAddress); + return !!addresses.localAddress && !!addresses.remoteAddress && isSameIpOrLoopback(addresses.remoteAddress, addresses.localAddress); case "EXTERNAL": - return !!addresses.remoteAddress && !isSameIpOrLoopback(addresses.remoteAddress, addresses.localAddress); + return !!addresses.localAddress && !!addresses.remoteAddress && !isSameIpOrLoopback(addresses.remoteAddress, addresses.localAddress); } } @@ -490,7 +490,7 @@ const cidrRangeEvaluator: MatchFieldEvaluator = { +const sourceTypeEvaluator: MatchFieldEvaluator = { isMatch: sourceTypeMatch, matcherEqual: (matcher1, matcher2) => matcher1 === matcher2, isMoreSpecific: (matcher1, matcher2) => matcher1 !== 'ANY' && matcher2 === 'ANY' diff --git a/packages/grpc-js-xds/src/xds-client.ts b/packages/grpc-js-xds/src/xds-client.ts index f3df183ff..0879d6b27 100644 --- a/packages/grpc-js-xds/src/xds-client.ts +++ b/packages/grpc-js-xds/src/xds-client.ts @@ -104,7 +104,7 @@ export class Watcher implements ResourceWatcherInterface { const RESOURCE_TIMEOUT_MS = 15_000; class ResourceTimer { - private timer: NodeJS.Timer | null = null; + private timer: NodeJS.Timeout | null = null; private resourceSeen = false; constructor(private callState: AdsCallState, private type: XdsResourceType, private name: XdsResourceName) {} @@ -672,7 +672,7 @@ class ClusterLoadReportMap { } class LrsCallState { - private statsTimer: NodeJS.Timer | null = null; + private statsTimer: NodeJS.Timeout | null = null; private sentInitialMessage = false; constructor(private client: XdsSingleServerClient, private call: LrsCall, private node: Node) { call.on('data', (message: LoadStatsResponse__Output) => { diff --git a/packages/grpc-js-xds/test/client.ts b/packages/grpc-js-xds/test/client.ts index a09056c96..e11b65e2e 100644 --- a/packages/grpc-js-xds/test/client.ts +++ b/packages/grpc-js-xds/test/client.ts @@ -42,7 +42,7 @@ const BOOTSTRAP_CONFIG_KEY = 'grpc.TEST_ONLY_DO_NOT_USE_IN_PROD.xds_bootstrap_co export class XdsTestClient { private client: EchoTestServiceClient; - private callInterval: NodeJS.Timer; + private callInterval: NodeJS.Timeout; constructor(target: string, bootstrapInfo: string, options?: ChannelOptions) { this.client = new loadedProtos.grpc.testing.EchoTestService(target, credentials.createInsecure(), {...options, [BOOTSTRAP_CONFIG_KEY]: bootstrapInfo});