From f64867efdfdf6bbb6b2ea5694da754e843658b30 Mon Sep 17 00:00:00 2001 From: Lev Bezborodov Date: Tue, 19 Nov 2024 19:57:49 +0300 Subject: [PATCH] Yet another declaration + tests (w/o grpc-js-xds) --- packages/grpc-health-check/package.json | 4 +- .../src/generated/grpc/health/v1/Health.ts | 121 ++++++++++++- .../grpc-health-check/src/generated/health.ts | 26 +++ packages/grpc-health-check/src/health.ts | 9 +- packages/grpc-health-check/src/server-type.ts | 6 +- .../test/generated/grpc/health/v1/Health.ts | 2 +- .../test/generated/health.ts | 10 +- .../test/test-health-load-sync.ts | 163 ++++++++++++++++++ ...t-health.ts => test-health-make-client.ts} | 7 +- packages/grpc-js/src/channelz.ts | 7 +- packages/grpc-js/src/generated/channelz.ts | 12 +- .../src/generated/grpc/channelz/v1/Address.ts | 2 +- .../src/generated/grpc/channelz/v1/Channel.ts | 8 +- .../generated/grpc/channelz/v1/ChannelData.ts | 6 +- .../grpc/channelz/v1/ChannelTrace.ts | 4 +- .../grpc/channelz/v1/ChannelTraceEvent.ts | 6 +- .../generated/grpc/channelz/v1/Channelz.ts | 30 ++-- .../grpc/channelz/v1/GetChannelResponse.ts | 2 +- .../grpc/channelz/v1/GetServerResponse.ts | 2 +- .../channelz/v1/GetServerSocketsResponse.ts | 2 +- .../grpc/channelz/v1/GetServersResponse.ts | 2 +- .../grpc/channelz/v1/GetSocketResponse.ts | 2 +- .../grpc/channelz/v1/GetSubchannelResponse.ts | 2 +- .../channelz/v1/GetTopChannelsResponse.ts | 2 +- .../generated/grpc/channelz/v1/Security.ts | 2 +- .../src/generated/grpc/channelz/v1/Server.ts | 6 +- .../generated/grpc/channelz/v1/ServerData.ts | 4 +- .../src/generated/grpc/channelz/v1/Socket.ts | 8 +- .../generated/grpc/channelz/v1/SocketData.ts | 6 +- .../grpc/channelz/v1/SocketOption.ts | 2 +- .../grpc/channelz/v1/SocketOptionLinger.ts | 2 +- .../grpc/channelz/v1/SocketOptionTimeout.ts | 2 +- .../generated/grpc/channelz/v1/Subchannel.ts | 8 +- packages/grpc-js/test/generated/Request.ts | 2 + .../grpc-js/test/generated/TestService.ts | 2 +- .../grpc-js/test/generated/test_service.ts | 10 +- packages/grpc-js/test/test-channelz.ts | 4 +- packages/grpc-js/test/test-server.ts | 4 +- packages/proto-loader/README.md | 4 +- .../bin/proto-loader-gen-types.ts | 8 +- .../proto-loader/golden-generated/echo.ts | 12 +- .../google/longrunning/Operations.ts | 2 +- .../google/showcase/v1beta1/Echo.ts | 2 +- 43 files changed, 418 insertions(+), 109 deletions(-) create mode 100644 packages/grpc-health-check/src/generated/health.ts create mode 100644 packages/grpc-health-check/test/test-health-load-sync.ts rename packages/grpc-health-check/test/{test-health.ts => test-health-make-client.ts} (96%) diff --git a/packages/grpc-health-check/package.json b/packages/grpc-health-check/package.json index 181057d6d..3a6fd7fc9 100644 --- a/packages/grpc-health-check/package.json +++ b/packages/grpc-health-check/package.json @@ -17,7 +17,9 @@ "scripts": { "compile": "tsc -p .", "prepare": "npm run generate-types && npm run compile", - "generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O src/generated health/v1/health.proto", + "test": "gulp test", + "pretest": "npm run generate-types && npm run generate-test-types && npm run compile", + "generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O src/generated --grpcLib=@grpc/grpc-js health/v1/health.proto", "generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O test/generated --grpcLib=@grpc/grpc-js health/v1/health.proto" }, "dependencies": { diff --git a/packages/grpc-health-check/src/generated/grpc/health/v1/Health.ts b/packages/grpc-health-check/src/generated/grpc/health/v1/Health.ts index a308498f4..f869ee103 100644 --- a/packages/grpc-health-check/src/generated/grpc/health/v1/Health.ts +++ b/packages/grpc-health-check/src/generated/grpc/health/v1/Health.ts @@ -1,10 +1,129 @@ // Original file: proto/health/v1/health.proto +import type * as grpc from '@grpc/grpc-js' import type { MethodDefinition } from '@grpc/proto-loader' import type { HealthCheckRequest as _grpc_health_v1_HealthCheckRequest, HealthCheckRequest__Output as _grpc_health_v1_HealthCheckRequest__Output } from '../../../grpc/health/v1/HealthCheckRequest'; import type { HealthCheckResponse as _grpc_health_v1_HealthCheckResponse, HealthCheckResponse__Output as _grpc_health_v1_HealthCheckResponse__Output } from '../../../grpc/health/v1/HealthCheckResponse'; -export interface HealthDefinition { +/** + * Health is gRPC's mechanism for checking whether a server is able to handle + * RPCs. Its semantics are documented in + * https://github.com/grpc/grpc/blob/master/doc/health-checking.md. + */ +export interface HealthClient extends grpc.ServiceClient { + /** + * Check gets the health of the specified service. If the requested service + * is unknown, the call will fail with status NOT_FOUND. If the caller does + * not specify a service name, the server should respond with its overall + * health status. + * + * Clients should set a deadline when calling Check, and can declare the + * server unhealthy if they do not receive a timely response. + * + * Check implementations should be idempotent and side effect free. + */ + Check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + Check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + Check(argument: _grpc_health_v1_HealthCheckRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + Check(argument: _grpc_health_v1_HealthCheckRequest, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + /** + * Check gets the health of the specified service. If the requested service + * is unknown, the call will fail with status NOT_FOUND. If the caller does + * not specify a service name, the server should respond with its overall + * health status. + * + * Clients should set a deadline when calling Check, and can declare the + * server unhealthy if they do not receive a timely response. + * + * Check implementations should be idempotent and side effect free. + */ + check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + check(argument: _grpc_health_v1_HealthCheckRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + check(argument: _grpc_health_v1_HealthCheckRequest, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall; + + /** + * Performs a watch for the serving status of the requested service. + * The server will immediately send back a message indicating the current + * serving status. It will then subsequently send a new message whenever + * the service's serving status changes. + * + * If the requested service is unknown when the call is received, the + * server will send a message setting the serving status to + * SERVICE_UNKNOWN but will *not* terminate the call. If at some + * future point, the serving status of the service becomes known, the + * server will send a new message with the service's serving status. + * + * If the call terminates with status UNIMPLEMENTED, then clients + * should assume this method is not supported and should not retry the + * call. If the call terminates with any other status (including OK), + * clients should retry the call with appropriate exponential backoff. + */ + Watch(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>; + Watch(argument: _grpc_health_v1_HealthCheckRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>; + /** + * Performs a watch for the serving status of the requested service. + * The server will immediately send back a message indicating the current + * serving status. It will then subsequently send a new message whenever + * the service's serving status changes. + * + * If the requested service is unknown when the call is received, the + * server will send a message setting the serving status to + * SERVICE_UNKNOWN but will *not* terminate the call. If at some + * future point, the serving status of the service becomes known, the + * server will send a new message with the service's serving status. + * + * If the call terminates with status UNIMPLEMENTED, then clients + * should assume this method is not supported and should not retry the + * call. If the call terminates with any other status (including OK), + * clients should retry the call with appropriate exponential backoff. + */ + watch(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>; + watch(argument: _grpc_health_v1_HealthCheckRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>; + +} + +/** + * Health is gRPC's mechanism for checking whether a server is able to handle + * RPCs. Its semantics are documented in + * https://github.com/grpc/grpc/blob/master/doc/health-checking.md. + */ +export interface HealthHandlers extends grpc.UntypedServiceImplementation { + /** + * Check gets the health of the specified service. If the requested service + * is unknown, the call will fail with status NOT_FOUND. If the caller does + * not specify a service name, the server should respond with its overall + * health status. + * + * Clients should set a deadline when calling Check, and can declare the + * server unhealthy if they do not receive a timely response. + * + * Check implementations should be idempotent and side effect free. + */ + Check: grpc.handleUnaryCall<_grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse>; + + /** + * Performs a watch for the serving status of the requested service. + * The server will immediately send back a message indicating the current + * serving status. It will then subsequently send a new message whenever + * the service's serving status changes. + * + * If the requested service is unknown when the call is received, the + * server will send a message setting the serving status to + * SERVICE_UNKNOWN but will *not* terminate the call. If at some + * future point, the serving status of the service becomes known, the + * server will send a new message with the service's serving status. + * + * If the call terminates with status UNIMPLEMENTED, then clients + * should assume this method is not supported and should not retry the + * call. If the call terminates with any other status (including OK), + * clients should retry the call with appropriate exponential backoff. + */ + Watch: grpc.handleServerStreamingCall<_grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse>; + +} + +export interface HealthDefinition extends grpc.ServiceDefinition { Check: MethodDefinition<_grpc_health_v1_HealthCheckRequest, _grpc_health_v1_HealthCheckResponse, _grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse__Output> Watch: MethodDefinition<_grpc_health_v1_HealthCheckRequest, _grpc_health_v1_HealthCheckResponse, _grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse__Output> } diff --git a/packages/grpc-health-check/src/generated/health.ts b/packages/grpc-health-check/src/generated/health.ts new file mode 100644 index 000000000..222cbddc6 --- /dev/null +++ b/packages/grpc-health-check/src/generated/health.ts @@ -0,0 +1,26 @@ +import type * as grpc from '@grpc/grpc-js'; +import type { MessageTypeDefinition } from '@grpc/proto-loader'; + +import type { HealthClient as _grpc_health_v1_HealthClient, HealthDefinition as _grpc_health_v1_HealthDefinition } from './grpc/health/v1/Health'; + +type SubtypeConstructor = { + new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype; +} & grpc.ServiceClientConstructor; + +export interface ProtoGrpcType extends grpc.GrpcObject { + grpc: { + health: { + v1: { + /** + * Health is gRPC's mechanism for checking whether a server is able to handle + * RPCs. Its semantics are documented in + * https://github.com/grpc/grpc/blob/master/doc/health-checking.md. + */ + Health: SubtypeConstructor<_grpc_health_v1_HealthClient> & { service: _grpc_health_v1_HealthDefinition } + HealthCheckRequest: MessageTypeDefinition + HealthCheckResponse: MessageTypeDefinition + } + } + } +} + diff --git a/packages/grpc-health-check/src/health.ts b/packages/grpc-health-check/src/health.ts index 86ca1af0d..3bd5c1e65 100644 --- a/packages/grpc-health-check/src/health.ts +++ b/packages/grpc-health-check/src/health.ts @@ -17,12 +17,14 @@ */ import * as path from 'path'; -import { loadSync, ServiceDefinition } from '@grpc/proto-loader'; +import * as grpc from '@grpc/grpc-js'; +import * as protoLoader from '@grpc/proto-loader'; +import type { ProtoGrpcType as HealthGrpc } from './generated/health'; import { HealthCheckRequest__Output } from './generated/grpc/health/v1/HealthCheckRequest'; import { HealthCheckResponse } from './generated/grpc/health/v1/HealthCheckResponse'; import { sendUnaryData, Server, ServerUnaryCall, ServerWritableStream } from './server-type'; -const loadedProto = loadSync('health/v1/health.proto', { +const healthProto = protoLoader.loadSync('health/v1/health.proto', { keepCase: true, longs: String, enums: String, @@ -30,8 +32,9 @@ const loadedProto = loadSync('health/v1/health.proto', { oneofs: true, includeDirs: [`${__dirname}/../../proto`], }); +const healthGrpc = grpc.loadPackageDefinition(healthProto) as HealthGrpc; -export const service = loadedProto['grpc.health.v1.Health'] as ServiceDefinition; +export const service = healthGrpc.grpc.health.v1.Health.service; const GRPC_STATUS_NOT_FOUND = 5; diff --git a/packages/grpc-health-check/src/server-type.ts b/packages/grpc-health-check/src/server-type.ts index f07704e87..2188fe0e8 100644 --- a/packages/grpc-health-check/src/server-type.ts +++ b/packages/grpc-health-check/src/server-type.ts @@ -15,7 +15,8 @@ * */ -import { ServiceDefinition } from '@grpc/proto-loader'; +import * as grpc from '@grpc/grpc-js'; +import * as protoLoader from '@grpc/proto-loader'; import { ObjectReadable, ObjectWritable } from './object-stream'; import { EventEmitter } from 'events'; @@ -99,5 +100,6 @@ export interface UntypedServiceImplementation { } export interface Server { - addService(service: ServiceDefinition, implementation: UntypedServiceImplementation): void; + addService(service: protoLoader.ServiceDefinition, implementation: UntypedServiceImplementation): void; + addService(service: grpc.ServiceDefinition, implementation: ImplType): void; } diff --git a/packages/grpc-health-check/test/generated/grpc/health/v1/Health.ts b/packages/grpc-health-check/test/generated/grpc/health/v1/Health.ts index 320958e3c..f869ee103 100644 --- a/packages/grpc-health-check/test/generated/grpc/health/v1/Health.ts +++ b/packages/grpc-health-check/test/generated/grpc/health/v1/Health.ts @@ -10,7 +10,7 @@ import type { HealthCheckResponse as _grpc_health_v1_HealthCheckResponse, Health * RPCs. Its semantics are documented in * https://github.com/grpc/grpc/blob/master/doc/health-checking.md. */ -export interface HealthClient extends grpc.Client { +export interface HealthClient extends grpc.ServiceClient { /** * Check gets the health of the specified service. If the requested service * is unknown, the call will fail with status NOT_FOUND. If the caller does diff --git a/packages/grpc-health-check/test/generated/health.ts b/packages/grpc-health-check/test/generated/health.ts index afb2ced5f..222cbddc6 100644 --- a/packages/grpc-health-check/test/generated/health.ts +++ b/packages/grpc-health-check/test/generated/health.ts @@ -3,11 +3,11 @@ import type { MessageTypeDefinition } from '@grpc/proto-loader'; import type { HealthClient as _grpc_health_v1_HealthClient, HealthDefinition as _grpc_health_v1_HealthDefinition } from './grpc/health/v1/Health'; -type SubtypeConstructor any, Subtype> = { - new(...args: ConstructorParameters): Subtype; -}; +type SubtypeConstructor = { + new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype; +} & grpc.ServiceClientConstructor; -export interface ProtoGrpcType { +export interface ProtoGrpcType extends grpc.GrpcObject { grpc: { health: { v1: { @@ -16,7 +16,7 @@ export interface ProtoGrpcType { * RPCs. Its semantics are documented in * https://github.com/grpc/grpc/blob/master/doc/health-checking.md. */ - Health: SubtypeConstructor & { service: _grpc_health_v1_HealthDefinition } + Health: SubtypeConstructor<_grpc_health_v1_HealthClient> & { service: _grpc_health_v1_HealthDefinition } HealthCheckRequest: MessageTypeDefinition HealthCheckResponse: MessageTypeDefinition } diff --git a/packages/grpc-health-check/test/test-health-load-sync.ts b/packages/grpc-health-check/test/test-health-load-sync.ts new file mode 100644 index 000000000..1e63bcdfd --- /dev/null +++ b/packages/grpc-health-check/test/test-health-load-sync.ts @@ -0,0 +1,163 @@ +/* + * + * Copyright 2023 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. + * + */ + +import * as assert from 'assert'; +import * as grpc from '@grpc/grpc-js'; +import * as protoLoader from '@grpc/proto-loader'; +import { HealthImplementation, ServingStatusMap } from '../src/health'; +import type { ProtoGrpcType as HealthGrpc } from './generated/health'; +import type { HealthClient } from './generated/grpc/health/v1/Health'; +import { HealthCheckResponse__Output, _grpc_health_v1_HealthCheckResponse_ServingStatus__Output } from './generated/grpc/health/v1/HealthCheckResponse'; + +describe('Health checking', () => { + const statusMap: ServingStatusMap = { + '': 'SERVING', + 'grpc.test.TestServiceNotServing': 'NOT_SERVING', + 'grpc.test.TestServiceServing': 'SERVING' + }; + const healthProto = protoLoader.loadSync('health/v1/health.proto', { + keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true, + includeDirs: [`${__dirname}/../../proto`], + }); + const healthGrpc = grpc.loadPackageDefinition(healthProto) as HealthGrpc; + let healthServer: grpc.Server; + let healthClient: HealthClient; + let healthImpl: HealthImplementation; + beforeEach(done => { + healthServer = new grpc.Server(); + healthImpl = new HealthImplementation(statusMap); + healthImpl.addToServer(healthServer); + healthServer.bindAsync('localhost:0', grpc.ServerCredentials.createInsecure(), (error, port) => { + if (error) { + done(error); + return; + } + + healthClient = new healthGrpc.grpc.health.v1.Health(`localhost:${port}`, grpc.credentials.createInsecure()); + healthServer.start(); + done(); + }); + }); + afterEach((done) => { + healthClient.close(); + healthServer.tryShutdown(done); + }); + describe('check', () => { + it('Should say that an enabled service is SERVING', done => { + healthClient.check({service: ''}, (error, value) => { + assert.ifError(error); + assert.strictEqual(value?.status, 'SERVING'); + done(); + }); + }); + it('Should say that a disabled service is NOT_SERVING', done => { + healthClient.check({service: 'grpc.test.TestServiceNotServing'}, (error, value) => { + assert.ifError(error); + assert.strictEqual(value?.status, 'NOT_SERVING'); + done(); + }); + }); + it('Should get NOT_FOUND if the service is not registered', done => { + healthClient.check({service: 'not_registered'}, (error, value) => { + assert(error); + assert.strictEqual(error?.code, grpc.status.NOT_FOUND); + done(); + }); + }); + it('Should get a different response if the health status changes', done => { + healthClient.check({service: 'transient'}, (error, value) => { + assert(error); + assert.strictEqual(error?.code, grpc.status.NOT_FOUND); + healthImpl.setStatus('transient', 'SERVING'); + healthClient.check({service: 'transient'}, (error, value) => { + assert.ifError(error); + assert.strictEqual(value?.status, 'SERVING'); + done(); + }); + }); + }); + }); + describe('watch', () => { + it('Should respond with the health status for an existing service', done => { + const call = healthClient.watch({service: ''}); + call.on('data', (response: HealthCheckResponse__Output) => { + assert.strictEqual(response.status, 'SERVING'); + call.cancel(); + }); + call.on('error', () => {}); + call.on('status', status => { + assert.strictEqual(status.code, grpc.status.CANCELLED); + done(); + }); + }); + it('Should send a new update when the status changes', done => { + const receivedStatusList: _grpc_health_v1_HealthCheckResponse_ServingStatus__Output[] = []; + const call = healthClient.watch({service: 'grpc.test.TestServiceServing'}); + call.on('data', (response: HealthCheckResponse__Output) => { + switch (receivedStatusList.length) { + case 0: + assert.strictEqual(response.status, 'SERVING'); + healthImpl.setStatus('grpc.test.TestServiceServing', 'NOT_SERVING'); + break; + case 1: + assert.strictEqual(response.status, 'NOT_SERVING'); + call.cancel(); + break; + default: + assert.fail(`Unexpected third status update ${response.status}`); + } + receivedStatusList.push(response.status); + }); + call.on('error', () => {}); + call.on('status', status => { + assert.deepStrictEqual(receivedStatusList, ['SERVING', 'NOT_SERVING']); + assert.strictEqual(status.code, grpc.status.CANCELLED); + done(); + }); + }); + it('Should update when a service that did not exist is added', done => { + const receivedStatusList: _grpc_health_v1_HealthCheckResponse_ServingStatus__Output[] = []; + const call = healthClient.watch({service: 'transient'}); + call.on('data', (response: HealthCheckResponse__Output) => { + switch (receivedStatusList.length) { + case 0: + assert.strictEqual(response.status, 'SERVICE_UNKNOWN'); + healthImpl.setStatus('transient', 'SERVING'); + break; + case 1: + assert.strictEqual(response.status, 'SERVING'); + call.cancel(); + break; + default: + assert.fail(`Unexpected third status update ${response.status}`); + } + receivedStatusList.push(response.status); + }); + call.on('error', () => {}); + call.on('status', status => { + assert.deepStrictEqual(receivedStatusList, ['SERVICE_UNKNOWN', 'SERVING']); + assert.strictEqual(status.code, grpc.status.CANCELLED); + done(); + }); + }) + }); +}); diff --git a/packages/grpc-health-check/test/test-health.ts b/packages/grpc-health-check/test/test-health-make-client.ts similarity index 96% rename from packages/grpc-health-check/test/test-health.ts rename to packages/grpc-health-check/test/test-health-make-client.ts index 80d60a234..0e30e4e48 100644 --- a/packages/grpc-health-check/test/test-health.ts +++ b/packages/grpc-health-check/test/test-health-make-client.ts @@ -19,7 +19,7 @@ import * as assert from 'assert'; import * as grpc from '@grpc/grpc-js'; import { HealthImplementation, ServingStatusMap, service as healthServiceDefinition } from '../src/health'; -import { HealthClient } from './generated/grpc/health/v1/Health'; +import type { HealthClient } from './generated/grpc/health/v1/Health'; import { HealthCheckResponse__Output, _grpc_health_v1_HealthCheckResponse_ServingStatus__Output } from './generated/grpc/health/v1/HealthCheckResponse'; describe('Health checking', () => { @@ -40,6 +40,7 @@ describe('Health checking', () => { done(error); return; } + const HealthClientConstructor = grpc.makeClientConstructor(healthServiceDefinition, 'grpc.health.v1.HealthService'); healthClient = new HealthClientConstructor(`localhost:${port}`, grpc.credentials.createInsecure()) as unknown as HealthClient; healthServer.start(); @@ -68,14 +69,14 @@ describe('Health checking', () => { it('Should get NOT_FOUND if the service is not registered', done => { healthClient.check({service: 'not_registered'}, (error, value) => { assert(error); - assert.strictEqual(error.code, grpc.status.NOT_FOUND); + assert.strictEqual(error?.code, grpc.status.NOT_FOUND); done(); }); }); it('Should get a different response if the health status changes', done => { healthClient.check({service: 'transient'}, (error, value) => { assert(error); - assert.strictEqual(error.code, grpc.status.NOT_FOUND); + assert.strictEqual(error?.code, grpc.status.NOT_FOUND); healthImpl.setStatus('transient', 'SERVING'); healthClient.check({service: 'transient'}, (error, value) => { assert.ifError(error); diff --git a/packages/grpc-js/src/channelz.ts b/packages/grpc-js/src/channelz.ts index c207e567c..263ba00b6 100644 --- a/packages/grpc-js/src/channelz.ts +++ b/packages/grpc-js/src/channelz.ts @@ -881,11 +881,8 @@ export function getChannelzServiceDefinition(): ChannelzDefinition { oneofs: true, includeDirs: [`${__dirname}/../../proto`], }); - const channelzGrpcObject = loadPackageDefinition( - loadedProto - ) as unknown as ChannelzProtoGrpcType; - loadedChannelzDefinition = - channelzGrpcObject.grpc.channelz.v1.Channelz.service; + const channelzGrpcObject = loadPackageDefinition(loadedProto) as ChannelzProtoGrpcType; + loadedChannelzDefinition = channelzGrpcObject.grpc.channelz.v1.Channelz.service; return loadedChannelzDefinition; } diff --git a/packages/grpc-js/src/generated/channelz.ts b/packages/grpc-js/src/generated/channelz.ts index a81ffae5b..88f5b7574 100644 --- a/packages/grpc-js/src/generated/channelz.ts +++ b/packages/grpc-js/src/generated/channelz.ts @@ -1,13 +1,13 @@ import type * as grpc from '../index'; import type { MessageTypeDefinition } from '@grpc/proto-loader'; -import type { ChannelzClient as _grpc_channelz_v1_ChannelzClient, ChannelzDefinition as _grpc_channelz_v1_ChannelzDefinition } from './grpc/channelz/v1/Channelz.ts'; +import type { ChannelzClient as _grpc_channelz_v1_ChannelzClient, ChannelzDefinition as _grpc_channelz_v1_ChannelzDefinition } from './grpc/channelz/v1/Channelz'; -type SubtypeConstructor any, Subtype> = { - new(...args: ConstructorParameters): Subtype; -}; +type SubtypeConstructor = { + new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype; +} & grpc.ServiceClientConstructor; -export interface ProtoGrpcType { +export interface ProtoGrpcType extends grpc.GrpcObject { google: { protobuf: { Any: MessageTypeDefinition @@ -38,7 +38,7 @@ export interface ProtoGrpcType { * Channelz is a service exposed by gRPC servers that provides detailed debug * information. */ - Channelz: SubtypeConstructor & { service: _grpc_channelz_v1_ChannelzDefinition } + Channelz: SubtypeConstructor<_grpc_channelz_v1_ChannelzClient> & { service: _grpc_channelz_v1_ChannelzDefinition } GetChannelRequest: MessageTypeDefinition GetChannelResponse: MessageTypeDefinition GetServerRequest: MessageTypeDefinition diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Address.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Address.ts index 5215e42ef..259cfeabe 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Address.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Address.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any.ts'; +import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any'; /** * An address type not included above. diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Channel.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Channel.ts index 5be617e11..93b4a261d 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Channel.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Channel.ts @@ -1,9 +1,9 @@ // Original file: proto/channelz.proto -import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef.ts'; -import type { ChannelData as _grpc_channelz_v1_ChannelData, ChannelData__Output as _grpc_channelz_v1_ChannelData__Output } from '../../../grpc/channelz/v1/ChannelData.ts'; -import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef.ts'; -import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef.ts'; +import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef'; +import type { ChannelData as _grpc_channelz_v1_ChannelData, ChannelData__Output as _grpc_channelz_v1_ChannelData__Output } from '../../../grpc/channelz/v1/ChannelData'; +import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef'; +import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef'; /** * Channel is a logical grouping of channels, subchannels, and sockets. diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelData.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelData.ts index d1de968a1..6d6824af4 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelData.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelData.ts @@ -1,8 +1,8 @@ // Original file: proto/channelz.proto -import type { ChannelConnectivityState as _grpc_channelz_v1_ChannelConnectivityState, ChannelConnectivityState__Output as _grpc_channelz_v1_ChannelConnectivityState__Output } from '../../../grpc/channelz/v1/ChannelConnectivityState.ts'; -import type { ChannelTrace as _grpc_channelz_v1_ChannelTrace, ChannelTrace__Output as _grpc_channelz_v1_ChannelTrace__Output } from '../../../grpc/channelz/v1/ChannelTrace.ts'; -import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp.ts'; +import type { ChannelConnectivityState as _grpc_channelz_v1_ChannelConnectivityState, ChannelConnectivityState__Output as _grpc_channelz_v1_ChannelConnectivityState__Output } from '../../../grpc/channelz/v1/ChannelConnectivityState'; +import type { ChannelTrace as _grpc_channelz_v1_ChannelTrace, ChannelTrace__Output as _grpc_channelz_v1_ChannelTrace__Output } from '../../../grpc/channelz/v1/ChannelTrace'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; import type { Long } from '@grpc/proto-loader'; /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTrace.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTrace.ts index 60c8e682a..7dbc8d924 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTrace.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTrace.ts @@ -1,7 +1,7 @@ // Original file: proto/channelz.proto -import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp.ts'; -import type { ChannelTraceEvent as _grpc_channelz_v1_ChannelTraceEvent, ChannelTraceEvent__Output as _grpc_channelz_v1_ChannelTraceEvent__Output } from '../../../grpc/channelz/v1/ChannelTraceEvent.ts'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import type { ChannelTraceEvent as _grpc_channelz_v1_ChannelTraceEvent, ChannelTraceEvent__Output as _grpc_channelz_v1_ChannelTraceEvent__Output } from '../../../grpc/channelz/v1/ChannelTraceEvent'; import type { Long } from '@grpc/proto-loader'; /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTraceEvent.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTraceEvent.ts index 33c6230ef..403e4f123 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTraceEvent.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/ChannelTraceEvent.ts @@ -1,8 +1,8 @@ // Original file: proto/channelz.proto -import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp.ts'; -import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef.ts'; -import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef.ts'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef'; +import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef'; // Original file: proto/channelz.proto diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Channelz.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Channelz.ts index deafde315..d562f7307 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Channelz.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Channelz.ts @@ -2,26 +2,26 @@ import type * as grpc from '../../../../index' import type { MethodDefinition } from '@grpc/proto-loader' -import type { GetChannelRequest as _grpc_channelz_v1_GetChannelRequest, GetChannelRequest__Output as _grpc_channelz_v1_GetChannelRequest__Output } from '../../../grpc/channelz/v1/GetChannelRequest.ts'; -import type { GetChannelResponse as _grpc_channelz_v1_GetChannelResponse, GetChannelResponse__Output as _grpc_channelz_v1_GetChannelResponse__Output } from '../../../grpc/channelz/v1/GetChannelResponse.ts'; -import type { GetServerRequest as _grpc_channelz_v1_GetServerRequest, GetServerRequest__Output as _grpc_channelz_v1_GetServerRequest__Output } from '../../../grpc/channelz/v1/GetServerRequest.ts'; -import type { GetServerResponse as _grpc_channelz_v1_GetServerResponse, GetServerResponse__Output as _grpc_channelz_v1_GetServerResponse__Output } from '../../../grpc/channelz/v1/GetServerResponse.ts'; -import type { GetServerSocketsRequest as _grpc_channelz_v1_GetServerSocketsRequest, GetServerSocketsRequest__Output as _grpc_channelz_v1_GetServerSocketsRequest__Output } from '../../../grpc/channelz/v1/GetServerSocketsRequest.ts'; -import type { GetServerSocketsResponse as _grpc_channelz_v1_GetServerSocketsResponse, GetServerSocketsResponse__Output as _grpc_channelz_v1_GetServerSocketsResponse__Output } from '../../../grpc/channelz/v1/GetServerSocketsResponse.ts'; -import type { GetServersRequest as _grpc_channelz_v1_GetServersRequest, GetServersRequest__Output as _grpc_channelz_v1_GetServersRequest__Output } from '../../../grpc/channelz/v1/GetServersRequest.ts'; -import type { GetServersResponse as _grpc_channelz_v1_GetServersResponse, GetServersResponse__Output as _grpc_channelz_v1_GetServersResponse__Output } from '../../../grpc/channelz/v1/GetServersResponse.ts'; -import type { GetSocketRequest as _grpc_channelz_v1_GetSocketRequest, GetSocketRequest__Output as _grpc_channelz_v1_GetSocketRequest__Output } from '../../../grpc/channelz/v1/GetSocketRequest.ts'; -import type { GetSocketResponse as _grpc_channelz_v1_GetSocketResponse, GetSocketResponse__Output as _grpc_channelz_v1_GetSocketResponse__Output } from '../../../grpc/channelz/v1/GetSocketResponse.ts'; -import type { GetSubchannelRequest as _grpc_channelz_v1_GetSubchannelRequest, GetSubchannelRequest__Output as _grpc_channelz_v1_GetSubchannelRequest__Output } from '../../../grpc/channelz/v1/GetSubchannelRequest.ts'; -import type { GetSubchannelResponse as _grpc_channelz_v1_GetSubchannelResponse, GetSubchannelResponse__Output as _grpc_channelz_v1_GetSubchannelResponse__Output } from '../../../grpc/channelz/v1/GetSubchannelResponse.ts'; -import type { GetTopChannelsRequest as _grpc_channelz_v1_GetTopChannelsRequest, GetTopChannelsRequest__Output as _grpc_channelz_v1_GetTopChannelsRequest__Output } from '../../../grpc/channelz/v1/GetTopChannelsRequest.ts'; -import type { GetTopChannelsResponse as _grpc_channelz_v1_GetTopChannelsResponse, GetTopChannelsResponse__Output as _grpc_channelz_v1_GetTopChannelsResponse__Output } from '../../../grpc/channelz/v1/GetTopChannelsResponse.ts'; +import type { GetChannelRequest as _grpc_channelz_v1_GetChannelRequest, GetChannelRequest__Output as _grpc_channelz_v1_GetChannelRequest__Output } from '../../../grpc/channelz/v1/GetChannelRequest'; +import type { GetChannelResponse as _grpc_channelz_v1_GetChannelResponse, GetChannelResponse__Output as _grpc_channelz_v1_GetChannelResponse__Output } from '../../../grpc/channelz/v1/GetChannelResponse'; +import type { GetServerRequest as _grpc_channelz_v1_GetServerRequest, GetServerRequest__Output as _grpc_channelz_v1_GetServerRequest__Output } from '../../../grpc/channelz/v1/GetServerRequest'; +import type { GetServerResponse as _grpc_channelz_v1_GetServerResponse, GetServerResponse__Output as _grpc_channelz_v1_GetServerResponse__Output } from '../../../grpc/channelz/v1/GetServerResponse'; +import type { GetServerSocketsRequest as _grpc_channelz_v1_GetServerSocketsRequest, GetServerSocketsRequest__Output as _grpc_channelz_v1_GetServerSocketsRequest__Output } from '../../../grpc/channelz/v1/GetServerSocketsRequest'; +import type { GetServerSocketsResponse as _grpc_channelz_v1_GetServerSocketsResponse, GetServerSocketsResponse__Output as _grpc_channelz_v1_GetServerSocketsResponse__Output } from '../../../grpc/channelz/v1/GetServerSocketsResponse'; +import type { GetServersRequest as _grpc_channelz_v1_GetServersRequest, GetServersRequest__Output as _grpc_channelz_v1_GetServersRequest__Output } from '../../../grpc/channelz/v1/GetServersRequest'; +import type { GetServersResponse as _grpc_channelz_v1_GetServersResponse, GetServersResponse__Output as _grpc_channelz_v1_GetServersResponse__Output } from '../../../grpc/channelz/v1/GetServersResponse'; +import type { GetSocketRequest as _grpc_channelz_v1_GetSocketRequest, GetSocketRequest__Output as _grpc_channelz_v1_GetSocketRequest__Output } from '../../../grpc/channelz/v1/GetSocketRequest'; +import type { GetSocketResponse as _grpc_channelz_v1_GetSocketResponse, GetSocketResponse__Output as _grpc_channelz_v1_GetSocketResponse__Output } from '../../../grpc/channelz/v1/GetSocketResponse'; +import type { GetSubchannelRequest as _grpc_channelz_v1_GetSubchannelRequest, GetSubchannelRequest__Output as _grpc_channelz_v1_GetSubchannelRequest__Output } from '../../../grpc/channelz/v1/GetSubchannelRequest'; +import type { GetSubchannelResponse as _grpc_channelz_v1_GetSubchannelResponse, GetSubchannelResponse__Output as _grpc_channelz_v1_GetSubchannelResponse__Output } from '../../../grpc/channelz/v1/GetSubchannelResponse'; +import type { GetTopChannelsRequest as _grpc_channelz_v1_GetTopChannelsRequest, GetTopChannelsRequest__Output as _grpc_channelz_v1_GetTopChannelsRequest__Output } from '../../../grpc/channelz/v1/GetTopChannelsRequest'; +import type { GetTopChannelsResponse as _grpc_channelz_v1_GetTopChannelsResponse, GetTopChannelsResponse__Output as _grpc_channelz_v1_GetTopChannelsResponse__Output } from '../../../grpc/channelz/v1/GetTopChannelsResponse'; /** * Channelz is a service exposed by gRPC servers that provides detailed debug * information. */ -export interface ChannelzClient extends grpc.Client { +export interface ChannelzClient extends grpc.ServiceClient { /** * Returns a single Channel, or else a NOT_FOUND code. */ diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetChannelResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetChannelResponse.ts index 48fb040ec..2e967a458 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetChannelResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetChannelResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Channel as _grpc_channelz_v1_Channel, Channel__Output as _grpc_channelz_v1_Channel__Output } from '../../../grpc/channelz/v1/Channel.ts'; +import type { Channel as _grpc_channelz_v1_Channel, Channel__Output as _grpc_channelz_v1_Channel__Output } from '../../../grpc/channelz/v1/Channel'; export interface GetChannelResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerResponse.ts index ee853985c..fe0078209 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Server as _grpc_channelz_v1_Server, Server__Output as _grpc_channelz_v1_Server__Output } from '../../../grpc/channelz/v1/Server.ts'; +import type { Server as _grpc_channelz_v1_Server, Server__Output as _grpc_channelz_v1_Server__Output } from '../../../grpc/channelz/v1/Server'; export interface GetServerResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerSocketsResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerSocketsResponse.ts index 577b2ca13..112f277e3 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerSocketsResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServerSocketsResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef.ts'; +import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef'; export interface GetServerSocketsResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServersResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServersResponse.ts index d232b6654..b07893b8c 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetServersResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetServersResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Server as _grpc_channelz_v1_Server, Server__Output as _grpc_channelz_v1_Server__Output } from '../../../grpc/channelz/v1/Server.ts'; +import type { Server as _grpc_channelz_v1_Server, Server__Output as _grpc_channelz_v1_Server__Output } from '../../../grpc/channelz/v1/Server'; export interface GetServersResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetSocketResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetSocketResponse.ts index 2e62b04e0..b6304b7f0 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetSocketResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetSocketResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Socket as _grpc_channelz_v1_Socket, Socket__Output as _grpc_channelz_v1_Socket__Output } from '../../../grpc/channelz/v1/Socket.ts'; +import type { Socket as _grpc_channelz_v1_Socket, Socket__Output as _grpc_channelz_v1_Socket__Output } from '../../../grpc/channelz/v1/Socket'; export interface GetSocketResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetSubchannelResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetSubchannelResponse.ts index 4896a1196..57d2bf2dc 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetSubchannelResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetSubchannelResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Subchannel as _grpc_channelz_v1_Subchannel, Subchannel__Output as _grpc_channelz_v1_Subchannel__Output } from '../../../grpc/channelz/v1/Subchannel.ts'; +import type { Subchannel as _grpc_channelz_v1_Subchannel, Subchannel__Output as _grpc_channelz_v1_Subchannel__Output } from '../../../grpc/channelz/v1/Subchannel'; export interface GetSubchannelResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/GetTopChannelsResponse.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/GetTopChannelsResponse.ts index 8a3c8dbf2..d96e63673 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/GetTopChannelsResponse.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/GetTopChannelsResponse.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Channel as _grpc_channelz_v1_Channel, Channel__Output as _grpc_channelz_v1_Channel__Output } from '../../../grpc/channelz/v1/Channel.ts'; +import type { Channel as _grpc_channelz_v1_Channel, Channel__Output as _grpc_channelz_v1_Channel__Output } from '../../../grpc/channelz/v1/Channel'; export interface GetTopChannelsResponse { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Security.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Security.ts index a084dbe0f..e555d698e 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Security.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Security.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any.ts'; +import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any'; export interface _grpc_channelz_v1_Security_OtherSecurity { /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Server.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Server.ts index a96d79b4a..958343358 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Server.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Server.ts @@ -1,8 +1,8 @@ // Original file: proto/channelz.proto -import type { ServerRef as _grpc_channelz_v1_ServerRef, ServerRef__Output as _grpc_channelz_v1_ServerRef__Output } from '../../../grpc/channelz/v1/ServerRef.ts'; -import type { ServerData as _grpc_channelz_v1_ServerData, ServerData__Output as _grpc_channelz_v1_ServerData__Output } from '../../../grpc/channelz/v1/ServerData.ts'; -import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef.ts'; +import type { ServerRef as _grpc_channelz_v1_ServerRef, ServerRef__Output as _grpc_channelz_v1_ServerRef__Output } from '../../../grpc/channelz/v1/ServerRef'; +import type { ServerData as _grpc_channelz_v1_ServerData, ServerData__Output as _grpc_channelz_v1_ServerData__Output } from '../../../grpc/channelz/v1/ServerData'; +import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef'; /** * Server represents a single server. There may be multiple servers in a single diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/ServerData.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/ServerData.ts index 588f6ae8e..ce48e36f5 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/ServerData.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/ServerData.ts @@ -1,7 +1,7 @@ // Original file: proto/channelz.proto -import type { ChannelTrace as _grpc_channelz_v1_ChannelTrace, ChannelTrace__Output as _grpc_channelz_v1_ChannelTrace__Output } from '../../../grpc/channelz/v1/ChannelTrace.ts'; -import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp.ts'; +import type { ChannelTrace as _grpc_channelz_v1_ChannelTrace, ChannelTrace__Output as _grpc_channelz_v1_ChannelTrace__Output } from '../../../grpc/channelz/v1/ChannelTrace'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; import type { Long } from '@grpc/proto-loader'; /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Socket.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Socket.ts index b2eec20af..5829afe98 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Socket.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Socket.ts @@ -1,9 +1,9 @@ // Original file: proto/channelz.proto -import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef.ts'; -import type { SocketData as _grpc_channelz_v1_SocketData, SocketData__Output as _grpc_channelz_v1_SocketData__Output } from '../../../grpc/channelz/v1/SocketData.ts'; -import type { Address as _grpc_channelz_v1_Address, Address__Output as _grpc_channelz_v1_Address__Output } from '../../../grpc/channelz/v1/Address.ts'; -import type { Security as _grpc_channelz_v1_Security, Security__Output as _grpc_channelz_v1_Security__Output } from '../../../grpc/channelz/v1/Security.ts'; +import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef'; +import type { SocketData as _grpc_channelz_v1_SocketData, SocketData__Output as _grpc_channelz_v1_SocketData__Output } from '../../../grpc/channelz/v1/SocketData'; +import type { Address as _grpc_channelz_v1_Address, Address__Output as _grpc_channelz_v1_Address__Output } from '../../../grpc/channelz/v1/Address'; +import type { Security as _grpc_channelz_v1_Security, Security__Output as _grpc_channelz_v1_Security__Output } from '../../../grpc/channelz/v1/Security'; /** * Information about an actual connection. Pronounced "sock-ay". diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketData.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketData.ts index 807d8a2a9..c62d4d10c 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketData.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketData.ts @@ -1,8 +1,8 @@ // Original file: proto/channelz.proto -import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp.ts'; -import type { Int64Value as _google_protobuf_Int64Value, Int64Value__Output as _google_protobuf_Int64Value__Output } from '../../../google/protobuf/Int64Value.ts'; -import type { SocketOption as _grpc_channelz_v1_SocketOption, SocketOption__Output as _grpc_channelz_v1_SocketOption__Output } from '../../../grpc/channelz/v1/SocketOption.ts'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import type { Int64Value as _google_protobuf_Int64Value, Int64Value__Output as _google_protobuf_Int64Value__Output } from '../../../google/protobuf/Int64Value'; +import type { SocketOption as _grpc_channelz_v1_SocketOption, SocketOption__Output as _grpc_channelz_v1_SocketOption__Output } from '../../../grpc/channelz/v1/SocketOption'; import type { Long } from '@grpc/proto-loader'; /** diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOption.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOption.ts index a2a545a4c..115b36aae 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOption.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOption.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any.ts'; +import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../../google/protobuf/Any'; /** * SocketOption represents socket options for a socket. Specifically, these diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionLinger.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionLinger.ts index ca0d801fe..d83fa3238 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionLinger.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionLinger.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration.ts'; +import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; /** * For use with SocketOption's additional field. This is primarily used for diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionTimeout.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionTimeout.ts index b49a68374..185839b2c 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionTimeout.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/SocketOptionTimeout.ts @@ -1,6 +1,6 @@ // Original file: proto/channelz.proto -import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration.ts'; +import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; /** * For use with SocketOption's additional field. This is primarily used for diff --git a/packages/grpc-js/src/generated/grpc/channelz/v1/Subchannel.ts b/packages/grpc-js/src/generated/grpc/channelz/v1/Subchannel.ts index 937d39749..7122fac83 100644 --- a/packages/grpc-js/src/generated/grpc/channelz/v1/Subchannel.ts +++ b/packages/grpc-js/src/generated/grpc/channelz/v1/Subchannel.ts @@ -1,9 +1,9 @@ // Original file: proto/channelz.proto -import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef.ts'; -import type { ChannelData as _grpc_channelz_v1_ChannelData, ChannelData__Output as _grpc_channelz_v1_ChannelData__Output } from '../../../grpc/channelz/v1/ChannelData.ts'; -import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef.ts'; -import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef.ts'; +import type { SubchannelRef as _grpc_channelz_v1_SubchannelRef, SubchannelRef__Output as _grpc_channelz_v1_SubchannelRef__Output } from '../../../grpc/channelz/v1/SubchannelRef'; +import type { ChannelData as _grpc_channelz_v1_ChannelData, ChannelData__Output as _grpc_channelz_v1_ChannelData__Output } from '../../../grpc/channelz/v1/ChannelData'; +import type { ChannelRef as _grpc_channelz_v1_ChannelRef, ChannelRef__Output as _grpc_channelz_v1_ChannelRef__Output } from '../../../grpc/channelz/v1/ChannelRef'; +import type { SocketRef as _grpc_channelz_v1_SocketRef, SocketRef__Output as _grpc_channelz_v1_SocketRef__Output } from '../../../grpc/channelz/v1/SocketRef'; /** * Subchannel is a logical grouping of channels, subchannels, and sockets. diff --git a/packages/grpc-js/test/generated/Request.ts b/packages/grpc-js/test/generated/Request.ts index d64ebb6ea..e4b28270f 100644 --- a/packages/grpc-js/test/generated/Request.ts +++ b/packages/grpc-js/test/generated/Request.ts @@ -5,10 +5,12 @@ export interface Request { 'error'?: (boolean); 'message'?: (string); 'errorAfter'?: (number); + 'responseLength'?: (number); } export interface Request__Output { 'error': (boolean); 'message': (string); 'errorAfter': (number); + 'responseLength': (number); } diff --git a/packages/grpc-js/test/generated/TestService.ts b/packages/grpc-js/test/generated/TestService.ts index e477c99b5..30386fe7b 100644 --- a/packages/grpc-js/test/generated/TestService.ts +++ b/packages/grpc-js/test/generated/TestService.ts @@ -5,7 +5,7 @@ import type { MethodDefinition } from '@grpc/proto-loader' import type { Request as _Request, Request__Output as _Request__Output } from './Request'; import type { Response as _Response, Response__Output as _Response__Output } from './Response'; -export interface TestServiceClient extends grpc.Client { +export interface TestServiceClient extends grpc.ServiceClient { BidiStream(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_Request, _Response__Output>; BidiStream(options?: grpc.CallOptions): grpc.ClientDuplexStream<_Request, _Response__Output>; bidiStream(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_Request, _Response__Output>; diff --git a/packages/grpc-js/test/generated/test_service.ts b/packages/grpc-js/test/generated/test_service.ts index 364acddeb..f6b387b8b 100644 --- a/packages/grpc-js/test/generated/test_service.ts +++ b/packages/grpc-js/test/generated/test_service.ts @@ -3,13 +3,13 @@ import type { MessageTypeDefinition } from '@grpc/proto-loader'; import type { TestServiceClient as _TestServiceClient, TestServiceDefinition as _TestServiceDefinition } from './TestService'; -type SubtypeConstructor any, Subtype> = { - new(...args: ConstructorParameters): Subtype; -}; +type SubtypeConstructor = { + new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype; +} & grpc.ServiceClientConstructor; -export interface ProtoGrpcType { +export interface ProtoGrpcType extends grpc.GrpcObject { Request: MessageTypeDefinition Response: MessageTypeDefinition - TestService: SubtypeConstructor & { service: _TestServiceDefinition } + TestService: SubtypeConstructor<_TestServiceClient> & { service: _TestServiceDefinition } } diff --git a/packages/grpc-js/test/test-channelz.ts b/packages/grpc-js/test/test-channelz.ts index 5c3dc3d7d..9093100a6 100644 --- a/packages/grpc-js/test/test-channelz.ts +++ b/packages/grpc-js/test/test-channelz.ts @@ -32,9 +32,7 @@ const loadedChannelzProto = protoLoader.loadSync('channelz.proto', { oneofs: true, includeDirs: [`${__dirname}/../../proto`], }); -const channelzGrpcObject = grpc.loadPackageDefinition( - loadedChannelzProto -) as unknown as ProtoGrpcType; +const channelzGrpcObject = grpc.loadPackageDefinition(loadedChannelzProto) as ProtoGrpcType; const TestServiceClient = loadProtoFile( `${__dirname}/fixtures/test_service.proto` diff --git a/packages/grpc-js/test/test-server.ts b/packages/grpc-js/test/test-server.ts index 1ea14097f..da3b3855a 100644 --- a/packages/grpc-js/test/test-server.ts +++ b/packages/grpc-js/test/test-server.ts @@ -55,9 +55,7 @@ const loadedTestServiceProto = protoLoader.loadSync( } ); -const testServiceGrpcObject = grpc.loadPackageDefinition( - loadedTestServiceProto -) as unknown as TestServiceGrpcType; +const testServiceGrpcObject: TestServiceGrpcType = grpc.loadPackageDefinition(loadedTestServiceProto) as TestServiceGrpcType; const ca = fs.readFileSync(path.join(__dirname, 'fixtures', 'ca.pem')); const key = fs.readFileSync(path.join(__dirname, 'fixtures', 'server1.key')); diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 3ee672725..7bcac911a 100644 --- a/packages/proto-loader/README.md +++ b/packages/proto-loader/README.md @@ -122,9 +122,7 @@ const exampleServer: ExampleHandlers = { }; const packageDefinition = protoLoader.loadSync('./proto/example.proto'); -const proto = (grpc.loadPackageDefinition( - packageDefinition -) as unknown) as ProtoGrpcType; +const proto: ProtoGrpcType = grpc.loadPackageDefinition(packageDefinition); const server = new grpc.Server(); server.addService(proto.example_package.Example.service, exampleServer); diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 1e02eefd7..bd53c9e1d 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -729,7 +729,7 @@ function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Pr formatComment(formatter, nested.comment, nested.options); } const typeInterfaceName = getTypeInterfaceName(nested); - formatter.writeLine(`${nested.name}: SubtypeConstructor & { service: ${typeInterfaceName}Definition }`); + formatter.writeLine(`${nested.name}: SubtypeConstructor<${typeInterfaceName}Client> & { service: ${typeInterfaceName}Definition }`); } else if (nested instanceof Protobuf.Enum) { formatter.writeLine(`${nested.name}: EnumTypeDefinition`); } else if (nested instanceof Protobuf.Type) { @@ -760,9 +760,9 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options generateServiceImports(formatter, root, options); formatter.writeLine(''); - formatter.writeLine('type SubtypeConstructor any, Subtype> = grpc.ServiceClientConstructor & {'); - formatter.writeLine(' new(...args: ConstructorParameters): Subtype;'); - formatter.writeLine('};'); + formatter.writeLine('type SubtypeConstructor = {'); + formatter.writeLine(' new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype;'); + formatter.writeLine('} & grpc.ServiceClientConstructor;'); formatter.writeLine(''); formatter.writeLine('export interface ProtoGrpcType extends grpc.GrpcObject {'); diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index 600e2864c..93f28c066 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -4,11 +4,11 @@ import type { EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-load import type { OperationsClient as _google_longrunning_OperationsClient, OperationsDefinition as _google_longrunning_OperationsDefinition } from './google/longrunning/Operations'; import type { EchoClient as _google_showcase_v1beta1_EchoClient, EchoDefinition as _google_showcase_v1beta1_EchoDefinition } from './google/showcase/v1beta1/Echo'; -type SubtypeConstructor any, Subtype> = { - new(...args: ConstructorParameters): Subtype; -}; +type SubtypeConstructor = { + new (address: string, credentials: grpc.ChannelCredentials, options?: Partial): Subtype; +} & grpc.ServiceClientConstructor; -export interface ProtoGrpcType { +export interface ProtoGrpcType extends grpc.GrpcObject { google: { api: { CustomHttpPattern: MessageTypeDefinition @@ -35,7 +35,7 @@ export interface ProtoGrpcType { * returns long-running operations should implement the `Operations` interface * so developers can have a consistent client experience. */ - Operations: SubtypeConstructor & { service: _google_longrunning_OperationsDefinition } + Operations: SubtypeConstructor<_google_longrunning_OperationsClient> & { service: _google_longrunning_OperationsDefinition } WaitOperationRequest: MessageTypeDefinition } protobuf: { @@ -78,7 +78,7 @@ export interface ProtoGrpcType { * paginated calls. Set the 'showcase-trailer' metadata key on any method * to have the values echoed in the response trailers. */ - Echo: SubtypeConstructor & { service: _google_showcase_v1beta1_EchoDefinition } + Echo: SubtypeConstructor<_google_showcase_v1beta1_EchoClient> & { service: _google_showcase_v1beta1_EchoDefinition } EchoRequest: MessageTypeDefinition EchoResponse: MessageTypeDefinition ExpandRequest: MessageTypeDefinition diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index 00d6a95d2..a21f88be4 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -22,7 +22,7 @@ import type { IWaitOperationRequest as I_google_longrunning_WaitOperationRequest * returns long-running operations should implement the `Operations` interface * so developers can have a consistent client experience. */ -export interface OperationsClient extends grpc.Client { +export interface OperationsClient extends grpc.ServiceClient { /** * Starts asynchronous cancellation on a long-running operation. The server * makes a best effort to cancel the operation, but success is not diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index a0330fe68..bf51bfdbe 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -19,7 +19,7 @@ import type { IWaitRequest as I_google_showcase_v1beta1_WaitRequest, OWaitReques * paginated calls. Set the 'showcase-trailer' metadata key on any method * to have the values echoed in the response trailers. */ -export interface EchoClient extends grpc.Client { +export interface EchoClient extends grpc.ServiceClient { /** * This method will block (wait) for the requested amount of time * and then return the response or error.