Skip to content

grpc-{surface, protobufjs, js}: help JS client pass tests #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion packages/grpc-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,48 @@

'use strict';

module.exports = require('@grpc/surface')(require('@grpc/js-core'));
import {
CallCredentials,
ChannelCredentials,
Metadata,
Status,
PropagateFlags,
Client
} from '@grpc/js-core';

const compose = <S extends { compose: (other: T) => S }, T>(a: S, b: T) => a.compose(b);

const notImplementedFn = () => { throw new Error('Not implemented'); }

module.exports = require('@grpc/surface')({
Client,
Metadata,
propagate: PropagateFlags,
status: Status,
credentials: {
createSsl: ChannelCredentials.createSsl,
createFromMetadataGenerator: CallCredentials.createFromMetadataGenerator,
createFromGoogleCredential: notImplementedFn,
combineChannelCredentials: (channelCredentials: ChannelCredentials,
...callCredentialsList: CallCredentials[]): ChannelCredentials => {
return callCredentialsList.reduce(compose, channelCredentials);
},
combineCallCredentials: (...callCredentialsList: CallCredentials[]): CallCredentials => {
return callCredentialsList.slice(1).reduce(compose, callCredentialsList[0]);
},
createInsecure: ChannelCredentials.createInsecure
},
get setLogger() { return notImplementedFn; },
get setLogVerbosity() { return notImplementedFn; },
get ServerCredentials() { return notImplementedFn; },
get callError() { return notImplementedFn; },
get writeFlags() { return notImplementedFn; },
get logVerbosity() { return notImplementedFn; },
getClientChannel(client: Client) {
return client.getChannel();
},
waitForClientReady(client: Client, deadline: number|Date, callback: (err: Error|null) => {}) {
client.waitForReady(deadline, callback);
},
closeClient(client: Client) { return client.close(); }
});
4 changes: 2 additions & 2 deletions packages/grpc-protobufjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = function(grpc) {

let exports = {};

const protobuf_js_5_common = require('protobuf_js_5_common')(grpc);
const protobuf_js_6_common = require('protobuf_js_6_common')(grpc);
const protobuf_js_5_common = require('./protobuf_js_5_common')(grpc);
const protobuf_js_6_common = require('./protobuf_js_6_common')(grpc);

/**
* Default options for loading proto files into gRPC
Expand Down
4 changes: 2 additions & 2 deletions packages/grpc-protobufjs/protobuf_js_6_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function(grpc) {
* @return {Buffer} The serialized object
*/
return function serialize(arg) {
var message = cls.fromObject(arg);
var message = arg ? cls.fromObject(arg) : {};
return cls.encode(message).finish();
};
};
Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports = function(grpc) {
if (value.hasOwnProperty('methods')) {
// It's a service object
var service_attrs = getProtobufServiceAttrs(value, options);
return grpc..makeGenericClientConstructor(service_attrs);
return grpc.makeGenericClientConstructor(service_attrs);
}

if (value.hasOwnProperty('nested')) {
Expand Down
2 changes: 2 additions & 0 deletions packages/grpc-surface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,7 @@ module.exports = function(grpc) {
return ServiceClient;
};

exports.makeGenericClientConstructor = exports.makeClientConstructor;

return Object.assign(exports, grpc);
};