Skip to content
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

chore(assign): replace assign with native Object.assign #1618

Merged
merged 1 commit into from
Dec 18, 2017
Merged
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
7 changes: 3 additions & 4 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var checkCollectionName = require('./utils').checkCollectionName,
Cursor = require('./cursor'),
unordered = require('./bulk/unordered'),
ordered = require('./bulk/ordered'),
assign = require('./utils').assign,
ChangeStream = require('./change_stream'),
executeOperation = require('./utils').executeOperation;

Expand Down Expand Up @@ -1375,7 +1374,7 @@ define.classMethod('findOne', { callback: true, promise: true });
*/
Collection.prototype.rename = function(newName, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = assign({}, options, { readPreference: ReadPreference.PRIMARY });
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });

return executeOperation(this.s.topology, rename, [this, newName, options, callback]);
};
Expand Down Expand Up @@ -1579,7 +1578,7 @@ var createIndexes = function(self, indexSpecs, options, callback) {
}
}

options = assign({}, options, { readPreference: ReadPreference.PRIMARY });
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });

// Execute the index
self.s.db.command(
Expand Down Expand Up @@ -1996,7 +1995,7 @@ Collection.prototype.indexes = function(options, callback) {
};

var indexes = function(self, options, callback) {
options = assign({}, { full: true }, options);
options = Object.assign({}, { full: true }, options);
self.s.db.indexInformation(self.s.name, options, callback);
};

Expand Down
9 changes: 6 additions & 3 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var EventEmitter = require('events').EventEmitter,
Collection = require('./collection'),
crypto = require('crypto'),
mergeOptionsAndWriteConcern = require('./utils').mergeOptionsAndWriteConcern,
assign = require('./utils').assign,
executeOperation = require('./utils').executeOperation;

var debugFields = [
Expand Down Expand Up @@ -865,7 +864,7 @@ Db.prototype.dropCollection = function(name, options, callback) {
decorateWithWriteConcern(cmd, this, options);

// options
const opts = assign({}, this.s.options, { readPreference: ReadPreference.PRIMARY });
const opts = Object.assign({}, this.s.options, { readPreference: ReadPreference.PRIMARY });
if (options.session) opts.session = options.session;

return executeOperation(this.s.topology, dropCollection, [this, cmd, opts, callback]);
Expand Down Expand Up @@ -905,7 +904,11 @@ Db.prototype.dropDatabase = function(options, callback) {
decorateWithWriteConcern(cmd, this, options);

// Ensure primary only
const finalOptions = assign({}, { readPreference: ReadPreference.PRIMARY }, this.s.options);
const finalOptions = Object.assign(
{},
{ readPreference: ReadPreference.PRIMARY },
this.s.options
);
if (options.session) {
finalOptions.session = options.session;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/mongo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var parse = require('./url_parser'),
handleCallback = require('./utils').handleCallback,
Db = require('./db'),
f = require('util').format,
assign = require('./utils').assign,
shallowClone = require('./utils').shallowClone,
authenticate = require('./authenticate'),
ServerSessionPool = require('mongodb-core').Sessions.ServerSessionPool,
Expand Down Expand Up @@ -349,7 +348,7 @@ MongoClient.prototype.db = function(dbName, options) {
options = options || {};

// Copy the options and add out internal override of the not shared flag
var finalOptions = assign({}, this.s.options, options);
var finalOptions = Object.assign({}, this.s.options, options);

// Do we have the db in the cache already
if (this.s.dbCache[dbName] && finalOptions.returnNonCachedInstance !== true) {
Expand Down
5 changes: 2 additions & 3 deletions lib/topologies/mongos.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ var ServerCapabilities = require('./topology_base').ServerCapabilities,
MAX_JS_INT = require('../utils').MAX_JS_INT,
translateOptions = require('../utils').translateOptions,
filterOptions = require('../utils').filterOptions,
mergeOptions = require('../utils').mergeOptions,
assign = require('../utils').assign;
mergeOptions = require('../utils').mergeOptions;

/**
* @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is
Expand Down Expand Up @@ -214,7 +213,7 @@ class Mongos extends TopologyBase {
if ('function' === typeof _options) (callback = _options), (_options = {});
if (_options == null) _options = {};
if (!('function' === typeof callback)) callback = null;
_options = assign({}, this.s.clonedOptions, _options);
_options = Object.assign({}, this.s.clonedOptions, _options);
self.s.options = _options;

// Update bufferMaxEntries
Expand Down
5 changes: 2 additions & 3 deletions lib/topologies/replset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ var Server = require('./server'),
MAX_JS_INT = require('../utils').MAX_JS_INT,
translateOptions = require('../utils').translateOptions,
filterOptions = require('../utils').filterOptions,
mergeOptions = require('../utils').mergeOptions,
assign = require('../utils').assign;
mergeOptions = require('../utils').mergeOptions;

/**
* @fileOverview The **ReplSet** class is a class that represents a Replicaset topology and is
Expand Down Expand Up @@ -241,7 +240,7 @@ class ReplSet extends TopologyBase {
if ('function' === typeof _options) (callback = _options), (_options = {});
if (_options == null) _options = {};
if (!('function' === typeof callback)) callback = null;
_options = assign({}, this.s.clonedOptions, _options);
_options = Object.assign({}, this.s.clonedOptions, _options);
self.s.options = _options;

// Update bufferMaxEntries
Expand Down
5 changes: 2 additions & 3 deletions lib/topologies/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ var CServer = require('mongodb-core').Server,
MAX_JS_INT = require('../utils').MAX_JS_INT,
translateOptions = require('../utils').translateOptions,
filterOptions = require('../utils').filterOptions,
mergeOptions = require('../utils').mergeOptions,
assign = require('../utils').assign;
mergeOptions = require('../utils').mergeOptions;

/**
* @fileOverview The **Server** class is a class that represents a single server topology and is
Expand Down Expand Up @@ -220,7 +219,7 @@ class Server extends TopologyBase {
if ('function' === typeof _options) (callback = _options), (_options = {});
if (_options == null) _options = this.s.clonedOptions;
if (!('function' === typeof callback)) callback = null;
_options = assign({}, this.s.clonedOptions, _options);
_options = Object.assign({}, this.s.clonedOptions, _options);
self.s.options = _options;

// Update bufferMaxEntries
Expand Down
30 changes: 1 addition & 29 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,33 +312,6 @@ var filterOptions = function(options, names) {
return filterOptions;
};

// Object.assign method or polyfill
var assign = Object.assign
? Object.assign
: function assign(target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}

var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}

var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
};

// Write concern keys
var writeConcernKeys = ['w', 'j', 'wtimeout', 'fsync'];

Expand Down Expand Up @@ -410,7 +383,7 @@ const executeOperation = (topology, operation, args, options) => {
opOptions = args[args.length - 2];
if (opOptions == null || opOptions.session == null) {
session = topology.startSession();
assign(args[args.length - 2], { session: session });
Object.assign(args[args.length - 2], { session: session });
} else if (opOptions.session && opOptions.session.hasEnded) {
throw new MongoError('Use of expired sessions is not permitted');
}
Expand Down Expand Up @@ -475,7 +448,6 @@ exports.decorateCommand = decorateCommand;
exports.isObject = isObject;
exports.debugOptions = debugOptions;
exports.MAX_JS_INT = 0x20000000000000;
exports.assign = assign;
exports.mergeOptionsAndWriteConcern = mergeOptionsAndWriteConcern;
exports.translateReadPreference = translateReadPreference;
exports.executeOperation = executeOperation;
5 changes: 2 additions & 3 deletions test/functional/buffering_proxy_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var test = require('./shared').assert;
var co = require('co');
var mock = require('../mock');
var assign = require('../../lib/utils').assign;

var extend = function(template, fields) {
var object = {};
Expand Down Expand Up @@ -38,7 +37,7 @@ describe.skip('Buffering Proxy', function() {
var electionIds = [new ObjectId(0), new ObjectId(1)];

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
setName: 'rs',
setVersion: 1,
electionId: electionIds[0],
Expand Down Expand Up @@ -264,7 +263,7 @@ describe.skip('Buffering Proxy', function() {
var electionIds = [new ObjectId(0), new ObjectId(1)];

// Default message fields
var defaultFields = assign({}, mock.DEFAULT_ISMASTER, {
var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, {
setName: 'rs',
setVersion: 1,
electionId: electionIds[0],
Expand Down
9 changes: 4 additions & 5 deletions test/functional/change_stream_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var Transform = require('stream').Transform;
var MongoNetworkError = require('mongodb-core').MongoNetworkError;
var setupDatabase = require('./shared').setupDatabase;
var delay = require('./shared').delay;
var assign = require('../../lib/utils').assign;
var co = require('co');
var mock = require('../mock');

Expand Down Expand Up @@ -697,7 +696,7 @@ describe('Change Streams', function() {

if (doc.ismaster) {
request.reply(
assign(
Object.assign(
{
ismaster: true,
secondary: false,
Expand Down Expand Up @@ -801,7 +800,7 @@ describe('Change Streams', function() {
request.connection.destroy();
} else if (doc.ismaster) {
request.reply(
assign(
Object.assign(
{
ismaster: true,
secondary: false,
Expand Down Expand Up @@ -902,7 +901,7 @@ describe('Change Streams', function() {
// Create a server that responds to the initial aggregation to connect to the server, but not to subsequent getMore requests
if (doc.ismaster) {
request.reply(
assign(
Object.assign(
{
ismaster: true,
secondary: false,
Expand Down Expand Up @@ -1338,7 +1337,7 @@ describe('Change Streams', function() {
// Create a server that responds to the initial aggregation to connect to the server, but not to subsequent getMore requests
if (doc.ismaster) {
request.reply(
assign(
Object.assign(
{
ismaster: true,
secondary: false,
Expand Down
Loading