Skip to content

Commit

Permalink
fix: avoid mutating passed options objects
Browse files Browse the repository at this point in the history
fixes #246
  • Loading branch information
masumsoft committed Mar 11, 2022
1 parent 8a2f85e commit c18cb47
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/expressCassandra.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
};
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Driver.prototype = {
prepare: true,
};

options = _.defaultsDeep(options, defaults);
options = _.defaultsDeep({}, options, defaults);

this.ensure_init((err) => {
if (err) {
Expand Down Expand Up @@ -66,7 +66,7 @@ Driver.prototype = {
prepare: true,
};

options = _.defaultsDeep(options, defaults);
options = _.defaultsDeep({}, options, defaults);

this.ensure_init((err) => {
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/orm/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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: {
Expand Down
26 changes: 13 additions & 13 deletions src/orm/base_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c18cb47

Please sign in to comment.