From 8c32104a8522cfe2febcf2338d51710021d837ff Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Thu, 23 Dec 2021 11:23:37 -0600 Subject: [PATCH] fix: Add service to the client constructor. (#455) --- integration/grpc-js/grpc-js-test.ts | 14 ++++++++------ integration/grpc-js/simple.ts | 1 + src/generate-grpc-js.ts | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/integration/grpc-js/grpc-js-test.ts b/integration/grpc-js/grpc-js-test.ts index 67204c0ef..fd9a265a5 100644 --- a/integration/grpc-js/grpc-js-test.ts +++ b/integration/grpc-js/grpc-js-test.ts @@ -73,17 +73,17 @@ describe('grpc-js-test', () => { }, struct( call: ServerUnaryCall<{ [key: string]: any } | undefined, { [key: string]: any }>, - callback: sendUnaryData<{ [key: string]: any } | undefined>){ + callback: sendUnaryData<{ [key: string]: any } | undefined> + ) { callback(null, call.request); }, - value( - call: ServerUnaryCall, - callback: sendUnaryData) { + value(call: ServerUnaryCall, callback: sendUnaryData) { callback(null, call.request); }, listValue( call: ServerUnaryCall | undefined, Array | undefined>, - callback: sendUnaryData | undefined>) { + callback: sendUnaryData | undefined> + ) { callback(null, call.request); }, serverStreaming(call) { @@ -147,7 +147,9 @@ describe('grpc-js-test', () => { const client = new TestClient(`localhost:${port}`, ChannelCredentials.createInsecure()); - expect.assertions(25); + expect.assertions(26); + + expect(TestClient.service).toEqual(TestService); client.unary({}, (err, res) => { expect(res).toEqual({}); diff --git a/integration/grpc-js/simple.ts b/integration/grpc-js/simple.ts index c8eb3ede9..17d981c54 100644 --- a/integration/grpc-js/simple.ts +++ b/integration/grpc-js/simple.ts @@ -619,6 +619,7 @@ export interface TestClient extends Client { export const TestClient = (makeGenericClientConstructor(TestService, 'simple.Test') as unknown) as { new (address: string, credentials: ChannelCredentials, options?: Partial): TestClient; + service: typeof TestService; }; type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; diff --git a/src/generate-grpc-js.ts b/src/generate-grpc-js.ts index e26d1a882..c2d9f2be6 100644 --- a/src/generate-grpc-js.ts +++ b/src/generate-grpc-js.ts @@ -229,6 +229,7 @@ function generateClientConstructor(fileDesc: FileDescriptorProto, serviceDesc: S credentials: ${ChannelCredentials}, options?: Partial<${ChannelOptions}>, ): ${serviceDesc.name}Client; + service: typeof ${serviceDesc.name}Service; } `; }