From c18cb47290bc9d9fd13312d14ed44eb4af263b51 Mon Sep 17 00:00:00 2001 From: Masum Date: Sat, 12 Mar 2022 00:17:11 +0600 Subject: [PATCH] fix: avoid mutating passed options objects fixes #246 --- src/expressCassandra.js | 6 +++--- src/helpers/driver.js | 4 ++-- src/orm/apollo.js | 4 ++-- src/orm/base_model.js | 26 +++++++++++++------------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/expressCassandra.js b/src/expressCassandra.js index 574a448e..b159e263 100644 --- a/src/expressCassandra.js +++ b/src/expressCassandra.js @@ -159,7 +159,7 @@ CassandraClient.import = function f(fixtureDirectory, options, callback) { batchSize: 1, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); const systemClient = this.orm.get_system_client(); const keyspace = this.orm.get_keyspace_name(); @@ -217,7 +217,7 @@ CassandraClient.prototype.doBatch = function f(queries, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); const randomModel = this.modelInstance[Object.keys(this.modelInstance)[0]]; const beforeHooks = []; @@ -263,7 +263,7 @@ CassandraClient.doBatch = function f(queries, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); CassandraClient.prototype.doBatch.call(CassandraClient, queries, options, callback); }; diff --git a/src/helpers/driver.js b/src/helpers/driver.js index f23ed678..e39c70bc 100644 --- a/src/helpers/driver.js +++ b/src/helpers/driver.js @@ -38,7 +38,7 @@ Driver.prototype = { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); this.ensure_init((err) => { if (err) { @@ -66,7 +66,7 @@ Driver.prototype = { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); this.ensure_init((err) => { if (err) { diff --git a/src/orm/apollo.js b/src/orm/apollo.js index 55d0e379..0a9b879f 100644 --- a/src/orm/apollo.js +++ b/src/orm/apollo.js @@ -96,7 +96,7 @@ Apollo.prototype = { defaultHosts.push({ host }); }); - const esClientConfig = _.defaults(this._connection.elasticsearch, { + const esClientConfig = _.defaults({}, this._connection.elasticsearch, { hosts: defaultHosts, sniffOnStart: true, }); @@ -119,7 +119,7 @@ Apollo.prototype = { const defaultHosts = this._connection.contactPoints; - const gremlinConfig = _.defaults(this._connection.gremlin, { + const gremlinConfig = _.defaults({}, this._connection.gremlin, { host: defaultHosts[0], port: 8182, storage: { diff --git a/src/orm/base_model.js b/src/orm/base_model.js index bbc4e328..35b20e15 100644 --- a/src/orm/base_model.js +++ b/src/orm/base_model.js @@ -273,7 +273,7 @@ BaseModel._execute_table_query = function f(query, params, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); const doExecuteQuery = function f1(doquery, docallback) { this.execute_query(doquery, params, options, docallback); @@ -434,7 +434,7 @@ BaseModel.eachRow = function f(queryObject, options, onReadable, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); options.return_query = true; const selectQuery = this.find(queryObject, options); @@ -495,7 +495,7 @@ BaseModel.stream = function f(queryObject, options, onReadable, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); options.return_query = true; const selectQuery = this.find(queryObject, options); @@ -560,7 +560,7 @@ BaseModel.createVertex = function f(vertexProperties, callback) { script += `vertex.property('${property}', ${property});`; }); script += 'vertex'; - const bindings = _.defaults(vertexProperties, { + const bindings = _.defaults({}, vertexProperties, { __graphName, __vertexLabel, }); @@ -594,7 +594,7 @@ BaseModel.updateVertex = function f(__vertexId, vertexProperties, callback) { script += `vertex.property('${property}', ${property});`; }); script += 'vertex'; - const bindings = _.defaults(vertexProperties, { + const bindings = _.defaults({}, vertexProperties, { __graphName, __vertexId, }); @@ -635,7 +635,7 @@ BaseModel.createEdge = function f(__edgeLabel, __fromVertexId, __toVertexId, edg script += `edge.property('${property}', ${property});`; }); script += 'edge'; - const bindings = _.defaults(edgeProperties, { + const bindings = _.defaults({}, edgeProperties, { __graphName, __fromVertexId, __toVertexId, @@ -671,7 +671,7 @@ BaseModel.updateEdge = function f(__edgeId, edgeProperties, callback) { script += `edge.property('${property}', ${property});`; }); script += 'edge'; - const bindings = _.defaults(edgeProperties, { + const bindings = _.defaults({}, edgeProperties, { __graphName, __edgeId, }); @@ -704,7 +704,7 @@ BaseModel.graphQuery = function f(query, params, callback) { vertices = g.V().hasLabel(__vertexLabel); `; script += query; - const bindings = _.defaults(params, { + const bindings = _.defaults({}, params, { __graphName, __vertexLabel, }); @@ -715,7 +715,7 @@ BaseModel.search = function f(queryObject, callback) { const esClient = this.get_es_client(); const indexName = `${this._properties.keyspace}_${this._properties.table_name}`; - const query = _.defaults(queryObject, { + const query = _.defaults({}, queryObject, { index: indexName, type: this._properties.table_name, }); @@ -742,7 +742,7 @@ BaseModel.find = function f(queryObject, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); // set raw true if select is used, // because casting to model instances may lead to problems @@ -828,7 +828,7 @@ BaseModel.update = function f(queryObject, updateValues, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); if (typeof schema.before_update === 'function' && schema.before_update(queryObject, updateValues, options) === false) { parser.callback_or_throw(buildError('model.update.before.error'), callback); @@ -925,7 +925,7 @@ BaseModel.delete = function f(queryObject, options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); if (typeof schema.before_delete === 'function' && schema.before_delete(queryObject, options) === false) { parser.callback_or_throw(buildError('model.delete.before.error'), callback); @@ -1036,7 +1036,7 @@ BaseModel.prototype.save = function fn(options, callback) { prepare: true, }; - options = _.defaultsDeep(options, defaults); + options = _.defaultsDeep({}, options, defaults); if (typeof schema.before_save === 'function' && schema.before_save(this, options) === false) { parser.callback_or_throw(buildError('model.save.before.error'), callback);