Skip to content

Commit

Permalink
Migrate from grpc to @grpc/grpc-js
Browse files Browse the repository at this point in the history
This change updates the generated reflection files to use @grpc/grpc-js.
This feature is enabled by the addition of grpc-tools and
[email protected].

In addition to the generated code, this change updates the client module
to use @grpc/grpc-js in place of the grpc package.
  • Loading branch information
tatemz committed Oct 27, 2020
1 parent 27157da commit 3d849bd
Show file tree
Hide file tree
Showing 8 changed files with 8,281 additions and 674 deletions.
7,652 changes: 7,652 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"author": "[email protected]",
"license": "MIT",
"dependencies": {
"@grpc/grpc-js": "^1.1.7",
"@types/google-protobuf": "^3.7.2",
"@types/lodash.set": "^4.3.6",
"google-protobuf": "^3.12.2",
"grpc": "^1.24.2",
"lodash.set": "^4.3.2",
"protobufjs": "^6.9.0"
},
Expand All @@ -26,12 +26,12 @@
"eslint-plugin-jest": "^23.11.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"grpc_tools_node_protoc_ts": "^4.0.0",
"grpc-tools": "^1.9.1",
"grpc_tools_node_protoc_ts": "^5.0.0",
"gts": "^2.0.2",
"mocha": "^7.2.0",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"protoc-gen-grpc": "^1.4.0",
"sinon": "^9.0.2",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
Expand All @@ -46,9 +46,7 @@
"prepare": "yarn run compile",
"pretest": "yarn run compile && yarn run fix",
"posttest": "yarn run check",
"protoc-pb": "protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./src --ts_out=./src -I ./static/grpc/reflection/v1alpha reflection.proto",
"protoc-grpc": "protoc-gen-grpc --js_out=import_style=commonjs,binary:./src --grpc_out=./src -I ./static/grpc/reflection/v1alpha reflection.proto",
"protoc": "yarn run protoc-pb && yarn run protoc-grpc",
"protoc": "grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./src --grpc_out=grpc_js:./src --ts_out=grpc_js:./src --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts -I ./static/grpc/reflection/v1alpha reflection.proto",
"build": "yarn run compile && yarn run fix && yarn run check"
},
"files": [
Expand Down
8 changes: 2 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as grpc from 'grpc';
import {ChannelCredentials} from '@grpc/grpc-js';
import {getDescriptorRoot} from './descriptor';
import * as services from './reflection_grpc_pb';
import {
Expand All @@ -9,11 +9,7 @@ import {Root} from 'protobufjs';

export class Client {
grpcClient: services.IServerReflectionClient;
constructor(
url: string,
credentials: grpc.ChannelCredentials,
options?: object
) {
constructor(url: string, credentials: ChannelCredentials, options?: object) {
this.grpcClient = new services.ServerReflectionClient(
url,
credentials,
Expand Down
7 changes: 4 additions & 3 deletions src/reflection_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
/* tslint:disable */
/* eslint-disable */

import * as grpc from "grpc";
import * as grpc from "@grpc/grpc-js";
import {handleClientStreamingCall} from "@grpc/grpc-js/build/src/server-call";
import * as reflection_pb from "./reflection_pb";

interface IServerReflectionService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
serverReflectionInfo: IServerReflectionService_IServerReflectionInfo;
}

interface IServerReflectionService_IServerReflectionInfo extends grpc.MethodDefinition<reflection_pb.ServerReflectionRequest, reflection_pb.ServerReflectionResponse> {
path: string; // "/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo"
path: "/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo";
requestStream: true;
responseStream: true;
requestSerialize: grpc.serialize<reflection_pb.ServerReflectionRequest>;
Expand All @@ -34,7 +35,7 @@ export interface IServerReflectionClient {
}

export class ServerReflectionClient extends grpc.Client implements IServerReflectionClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
constructor(address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ClientOptions>);
public serverReflectionInfo(options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<reflection_pb.ServerReflectionRequest, reflection_pb.ServerReflectionResponse>;
public serverReflectionInfo(metadata?: grpc.Metadata, options?: Partial<grpc.CallOptions>): grpc.ClientDuplexStream<reflection_pb.ServerReflectionRequest, reflection_pb.ServerReflectionResponse>;
}
6 changes: 3 additions & 3 deletions src/reflection_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Service exported by server reflection
//
'use strict';
var grpc = require('grpc');
var grpc = require('@grpc/grpc-js');
var reflection_pb = require('./reflection_pb.js');

function serialize_grpc_reflection_v1alpha_ServerReflectionRequest(arg) {
Expand Down Expand Up @@ -46,8 +46,8 @@ function deserialize_grpc_reflection_v1alpha_ServerReflectionResponse(buffer_arg

var ServerReflectionService = exports.ServerReflectionService = {
// The reflection service is structured as a bidirectional stream, ensuring
// all related requests go to a single server.
serverReflectionInfo: {
// all related requests go to a single server.
serverReflectionInfo: {
path: '/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo',
requestStream: true,
responseStream: true,
Expand Down
Loading

0 comments on commit 3d849bd

Please sign in to comment.