From 3bad9ae8f5b01cf98b77882531b951573eaef7c4 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Mon, 12 Nov 2018 22:23:48 -0800 Subject: [PATCH 1/2] refactor: use Object.assign --- packages/grpc-native-core/index.js | 6 +++--- packages/grpc-native-core/src/server.js | 4 ++-- packages/grpc-native-core/test/common_test.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/grpc-native-core/index.js b/packages/grpc-native-core/index.js index b01736b1..096e7459 100644 --- a/packages/grpc-native-core/index.js +++ b/packages/grpc-native-core/index.js @@ -72,8 +72,8 @@ grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii')); * @return {Object} The resulting gRPC object. */ exports.loadObject = function loadObject(value, options) { - options = _.defaults(options, common.defaultGrpcOptions); - options = _.defaults(options, {'protobufjsVersion': 'detect'}); + options = Object.assign(common.defaultGrpcOptions, options); + options = Object.assign({'protobufjsVersion': 'detect'}, options); var protobufjsVersion; if (options.protobufjsVersion === 'detect') { if (protobuf_js_6_common.isProbablyProtobufJs6(value)) { @@ -122,7 +122,7 @@ var loadObject = exports.loadObject; * @return {Object} The resulting gRPC object */ exports.load = util.deprecate(function load(filename, format, options) { - options = _.defaults(options, common.defaultGrpcOptions); + options = Object.assign(common.defaultGrpcOptions, options); options.protobufjsVersion = 5; if (!format) { format = 'proto'; diff --git a/packages/grpc-native-core/src/server.js b/packages/grpc-native-core/src/server.js index 9f1715e0..795b6772 100644 --- a/packages/grpc-native-core/src/server.js +++ b/packages/grpc-native-core/src/server.js @@ -932,12 +932,12 @@ Server.prototype.addProtoService = util.deprecate(function(service, var protobuf_js_5_common = require('./protobuf_js_5_common'); var protobuf_js_6_common = require('./protobuf_js_6_common'); if (protobuf_js_5_common.isProbablyProtobufJs5(service)) { - options = _.defaults(service.grpc_options, common.defaultGrpcOptions); + options = Object.assign(common.defaultGrpcOptions, service.grpc_options); this.addService( protobuf_js_5_common.getProtobufServiceAttrs(service, options), implementation); } else if (protobuf_js_6_common.isProbablyProtobufJs6(service)) { - options = _.defaults(service.grpc_options, common.defaultGrpcOptions); + options = Object.assign(common.defaultGrpcOptions, service.grpc_options); this.addService( protobuf_js_6_common.getProtobufServiceAttrs(service, options), implementation); diff --git a/packages/grpc-native-core/test/common_test.js b/packages/grpc-native-core/test/common_test.js index d50c1a27..5251320a 100644 --- a/packages/grpc-native-core/test/common_test.js +++ b/packages/grpc-native-core/test/common_test.js @@ -81,7 +81,7 @@ describe('Proto message long int serialize and deserialize', function() { neg_value); }); it('should deserialize as a number with the right option set', function() { - var num_options = _.defaults({longsAsStrings: false}, default_options); + var num_options = Object.assign(default_options, {longsAsStrings: false}); var longNumDeserialize = deserializeCls(messages_proto.LongValues, num_options); var serialized = longSerialize({int_64: pos_value}); @@ -95,7 +95,7 @@ describe('Proto message bytes serialize and deserialize', function() { var sequenceSerialize = serializeCls(messages_proto.SequenceValues); var sequenceDeserialize = deserializeCls( messages_proto.SequenceValues, default_options); - var b64_options = _.defaults({binaryAsBase64: true}, default_options); + var b64_options = Object.assign(default_options, {binaryAsBase64: true}); var sequenceBase64Deserialize = deserializeCls( messages_proto.SequenceValues, b64_options); var buffer_val = new Buffer([0x69, 0xb7]); @@ -169,7 +169,7 @@ describe('Proto message enum serialize and deserialize', function() { var enumSerialize = serializeCls(messages_proto.EnumValues); var enumDeserialize = deserializeCls( messages_proto.EnumValues, default_options); - var enumIntOptions = _.defaults({enumsAsStrings: false}, default_options); + var enumIntOptions = Object.assign(default_options, {enumsAsStrings: false}); var enumIntDeserialize = deserializeCls( messages_proto.EnumValues, enumIntOptions); it('Should accept both names and numbers', function() { From b85a63c7c977c8f8112297e80f455336a8b151ad Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 14 Nov 2018 16:15:55 -0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=91=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/grpc-native-core/index.js | 6 +++--- packages/grpc-native-core/src/server.js | 4 ++-- packages/grpc-native-core/test/common_test.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/grpc-native-core/index.js b/packages/grpc-native-core/index.js index 096e7459..e6105534 100644 --- a/packages/grpc-native-core/index.js +++ b/packages/grpc-native-core/index.js @@ -72,8 +72,8 @@ grpc.setDefaultRootsPem(fs.readFileSync(SSL_ROOTS_PATH, 'ascii')); * @return {Object} The resulting gRPC object. */ exports.loadObject = function loadObject(value, options) { - options = Object.assign(common.defaultGrpcOptions, options); - options = Object.assign({'protobufjsVersion': 'detect'}, options); + options = Object.assign({}, common.defaultGrpcOptions, options); + options = Object.assign({}, {'protobufjsVersion': 'detect'}, options); var protobufjsVersion; if (options.protobufjsVersion === 'detect') { if (protobuf_js_6_common.isProbablyProtobufJs6(value)) { @@ -122,7 +122,7 @@ var loadObject = exports.loadObject; * @return {Object} The resulting gRPC object */ exports.load = util.deprecate(function load(filename, format, options) { - options = Object.assign(common.defaultGrpcOptions, options); + options = Object.assign({}, common.defaultGrpcOptions, options); options.protobufjsVersion = 5; if (!format) { format = 'proto'; diff --git a/packages/grpc-native-core/src/server.js b/packages/grpc-native-core/src/server.js index 795b6772..c4e205bb 100644 --- a/packages/grpc-native-core/src/server.js +++ b/packages/grpc-native-core/src/server.js @@ -932,12 +932,12 @@ Server.prototype.addProtoService = util.deprecate(function(service, var protobuf_js_5_common = require('./protobuf_js_5_common'); var protobuf_js_6_common = require('./protobuf_js_6_common'); if (protobuf_js_5_common.isProbablyProtobufJs5(service)) { - options = Object.assign(common.defaultGrpcOptions, service.grpc_options); + options = Object.assign({}, common.defaultGrpcOptions, service.grpc_options); this.addService( protobuf_js_5_common.getProtobufServiceAttrs(service, options), implementation); } else if (protobuf_js_6_common.isProbablyProtobufJs6(service)) { - options = Object.assign(common.defaultGrpcOptions, service.grpc_options); + options = Object.assign({}, common.defaultGrpcOptions, service.grpc_options); this.addService( protobuf_js_6_common.getProtobufServiceAttrs(service, options), implementation); diff --git a/packages/grpc-native-core/test/common_test.js b/packages/grpc-native-core/test/common_test.js index 5251320a..404ca2c3 100644 --- a/packages/grpc-native-core/test/common_test.js +++ b/packages/grpc-native-core/test/common_test.js @@ -81,7 +81,7 @@ describe('Proto message long int serialize and deserialize', function() { neg_value); }); it('should deserialize as a number with the right option set', function() { - var num_options = Object.assign(default_options, {longsAsStrings: false}); + var num_options = Object.assign({}, default_options, {longsAsStrings: false}); var longNumDeserialize = deserializeCls(messages_proto.LongValues, num_options); var serialized = longSerialize({int_64: pos_value}); @@ -95,7 +95,7 @@ describe('Proto message bytes serialize and deserialize', function() { var sequenceSerialize = serializeCls(messages_proto.SequenceValues); var sequenceDeserialize = deserializeCls( messages_proto.SequenceValues, default_options); - var b64_options = Object.assign(default_options, {binaryAsBase64: true}); + var b64_options = Object.assign({}, default_options, {binaryAsBase64: true}); var sequenceBase64Deserialize = deserializeCls( messages_proto.SequenceValues, b64_options); var buffer_val = new Buffer([0x69, 0xb7]); @@ -169,7 +169,7 @@ describe('Proto message enum serialize and deserialize', function() { var enumSerialize = serializeCls(messages_proto.EnumValues); var enumDeserialize = deserializeCls( messages_proto.EnumValues, default_options); - var enumIntOptions = Object.assign(default_options, {enumsAsStrings: false}); + var enumIntOptions = Object.assign({}, default_options, {enumsAsStrings: false}); var enumIntDeserialize = deserializeCls( messages_proto.EnumValues, enumIntOptions); it('Should accept both names and numbers', function() {