From bd00ccf5f3a641d54bc92e7b793386f301c4b9ad 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 d6fbf8705..1e35ac828 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 57c8ca7c4..d9df0191a 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 16a6fb151..218b1ab44 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 29cd91f0e..5ccbaa673 100644 --- a/packages/grpc-js-xds/src/server.ts +++ b/packages/grpc-js-xds/src/server.ts @@ -493,7 +493,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)); @@ -506,14 +506,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); } } @@ -523,7 +523,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 dad503974..225b0b290 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) {} @@ -673,7 +673,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 731ef0541..79bf2627b 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, creds?: ChannelCredentials | undefined, options?: ChannelOptions) { this.client = new loadedProtos.grpc.testing.EchoTestService(target, creds ?? credentials.createInsecure(), {...options, [BOOTSTRAP_CONFIG_KEY]: bootstrapInfo});