Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Jan 14, 2025
1 parent d40ff66 commit 411e69d
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 238 deletions.
23 changes: 13 additions & 10 deletions lib/drivers/node-mongodb-native/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype);
* @api public
*/

NativeConnection.prototype.useDb = function(name, options) {
NativeConnection.prototype.useDb = function (name, options) {

Check failure on line 64 in lib/drivers/node-mongodb-native/connection.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 64 in lib/drivers/node-mongodb-native/connection.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
// Return immediately if cached
options = options || {};
if (options.useCache && this.relatedDbs[name]) {
Expand Down Expand Up @@ -345,7 +345,7 @@ NativeConnection.prototype.createClient = async function createClient(uri, optio
* @returns a copy of the options object with a schemaMap and/or an encryptedFieldsMap added to the options' autoEncryption
* options.
*/
NativeConnection.prototype._buildEncryptionSchemas = function(options) {
NativeConnection.prototype._buildEncryptionSchemas = function (options) {

Check failure on line 348 in lib/drivers/node-mongodb-native/connection.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 348 in lib/drivers/node-mongodb-native/connection.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
const schemaMap = Object.values(this.models).filter(model => model.schema.encryptionType() === 'csfle').reduce(
schemaMapReducer.bind(this),
{}
Expand All @@ -355,14 +355,17 @@ NativeConnection.prototype._buildEncryptionSchemas = function(options) {
{}
);

return Object.assign(
clone(options), {
autoEncryption: {
...options.autoEncryption,
schemaMap,
encryptedFieldsMap
}
});
options = clone(options);

if (Object.keys(schemaMap).length > 0) {
options.autoEncryption.schemaMap = schemaMap;
}

if (Object.keys(encryptedFieldsMap).length > 0) {
options.autoEncryption.encryptedFieldsMap = encryptedFieldsMap;
}

return options;

/**
* @param {object} schemaMap the accumulation schemaMap
Expand Down
82 changes: 46 additions & 36 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const manySpaceRE = /\s+/;
* @api private
*/

exports.toCollectionName = function(name, pluralize) {
exports.toCollectionName = function (name, pluralize) {

Check failure on line 48 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 48 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
if (name === 'system.profile') {
return name;
}
Expand Down Expand Up @@ -89,19 +89,19 @@ exports.deepEqual = function deepEqual(a, b) {
}

if ((isBsonType(a, 'ObjectId') && isBsonType(b, 'ObjectId')) ||
(isBsonType(a, 'Decimal128') && isBsonType(b, 'Decimal128'))) {
(isBsonType(a, 'Decimal128') && isBsonType(b, 'Decimal128'))) {
return a.toString() === b.toString();
}

if (a instanceof RegExp && b instanceof RegExp) {
return a.source === b.source &&
a.ignoreCase === b.ignoreCase &&
a.multiline === b.multiline &&
a.global === b.global &&
a.dotAll === b.dotAll &&
a.unicode === b.unicode &&
a.sticky === b.sticky &&
a.hasIndices === b.hasIndices;
a.ignoreCase === b.ignoreCase &&
a.multiline === b.multiline &&
a.global === b.global &&
a.dotAll === b.dotAll &&
a.unicode === b.unicode &&
a.sticky === b.sticky &&
a.hasIndices === b.hasIndices;
}

if (a == null || b == null) {
Expand Down Expand Up @@ -190,7 +190,7 @@ exports.deepEqual = function deepEqual(a, b) {
* @param {Array} arr
*/

exports.last = function(arr) {
exports.last = function (arr) {

Check failure on line 193 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 193 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
if (arr.length > 0) {
return arr[arr.length - 1];
}
Expand Down Expand Up @@ -287,8 +287,8 @@ exports.merge = function merge(to, from, options, path) {
// base schema has a given path as a single nested but discriminator schema
// has the path as a document array, or vice versa (gh-9534)
if (options.isDiscriminatorSchemaMerge &&
(from[key].$isSingleNested && to[key].$isMongooseDocumentArray) ||
(from[key].$isMongooseDocumentArray && to[key].$isSingleNested)) {
(from[key].$isSingleNested && to[key].$isMongooseDocumentArray) ||
(from[key].$isMongooseDocumentArray && to[key].$isSingleNested)) {
continue;
} else if (from[key].instanceOfSchema) {
if (to[key].instanceOfSchema) {
Expand Down Expand Up @@ -397,7 +397,7 @@ exports.isNonBuiltinObject = function isNonBuiltinObject(val) {
* @param {Any} arg
*/

exports.isNativeObject = function(arg) {
exports.isNativeObject = function (arg) {

Check failure on line 400 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 400 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
return Array.isArray(arg) ||
arg instanceof Date ||
arg instanceof Boolean ||
Expand All @@ -410,7 +410,7 @@ exports.isNativeObject = function(arg) {
* @param {Any} val
*/

exports.isEmptyObject = function(val) {
exports.isEmptyObject = function (val) {

Check failure on line 413 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 413 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
return val != null &&
typeof val === 'object' &&
Object.keys(val).length === 0;
Expand Down Expand Up @@ -451,13 +451,13 @@ exports.tick = function tick(callback) {
if (typeof callback !== 'function') {
return;
}
return function() {
return function () {

Check failure on line 454 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 454 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
try {
callback.apply(this, arguments);
} catch (err) {
// only nextTick on err to get out of
// the event loop and avoid state corruption.
immediate(function() {
immediate(function () {

Check failure on line 460 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 460 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
throw err;
});
}
Expand All @@ -470,7 +470,7 @@ exports.tick = function tick(callback) {
* @param {Any} v
*/

exports.isMongooseType = function(v) {
exports.isMongooseType = function (v) {

Check failure on line 473 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 473 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
return isBsonType(v, 'ObjectId') || isBsonType(v, 'Decimal128') || v instanceof Buffer;
};

Expand Down Expand Up @@ -562,10 +562,10 @@ exports.populate = function populate(path, select, model, match, options, subPop
// an array, string, or object literal).
function makeSingles(arr) {
const ret = [];
arr.forEach(function(obj) {
arr.forEach(function (obj) {

Check failure on line 565 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses

Check failure on line 565 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Unexpected space before function parentheses
if (oneSpaceRE.test(obj.path)) {
const paths = obj.path.split(manySpaceRE);
paths.forEach(function(p) {
paths.forEach(function (p) {
const copy = Object.assign({}, obj);
copy.path = p;
ret.push(copy);
Expand All @@ -582,11 +582,11 @@ exports.populate = function populate(path, select, model, match, options, subPop
function _populateObj(obj) {
if (Array.isArray(obj.populate)) {
const ret = [];
obj.populate.forEach(function(obj) {
obj.populate.forEach(function (obj) {
if (oneSpaceRE.test(obj.path)) {
const copy = Object.assign({}, obj);
const paths = copy.path.split(manySpaceRE);
paths.forEach(function(p) {
paths.forEach(function (p) {
copy.path = p;
ret.push(exports.populate(copy)[0]);
});
Expand Down Expand Up @@ -620,7 +620,7 @@ function _populateObj(obj) {
* @param {Any} map
*/

exports.getValue = function(path, obj, map) {
exports.getValue = function (path, obj, map) {
return mpath.get(path, obj, getValueLookup, map);
};

Expand Down Expand Up @@ -653,7 +653,7 @@ function getValueLookup(obj, part) {
* @param {Any} _copying
*/

exports.setValue = function(path, val, obj, map, _copying) {
exports.setValue = function (path, val, obj, map, _copying) {
mpath.set(path, val, obj, '_doc', map, _copying);
};

Expand Down Expand Up @@ -687,7 +687,7 @@ const hop = Object.prototype.hasOwnProperty;
* @param {String} prop
*/

exports.object.hasOwnProperty = function(obj, prop) {
exports.object.hasOwnProperty = function (obj, prop) {
return hop.call(obj, prop);
};

Expand All @@ -698,7 +698,7 @@ exports.object.hasOwnProperty = function(obj, prop) {
* @return {Boolean}
*/

exports.isNullOrUndefined = function(val) {
exports.isNullOrUndefined = function (val) {
return val === null || val === undefined;
};

Expand All @@ -723,7 +723,7 @@ exports.array = {};
exports.array.flatten = function flatten(arr, filter, ret) {
ret || (ret = []);

arr.forEach(function(item) {
arr.forEach(function (item) {
if (Array.isArray(item)) {
flatten(item, filter, ret);
} else {
Expand All @@ -742,7 +742,7 @@ exports.array.flatten = function flatten(arr, filter, ret) {

const _hasOwnProperty = Object.prototype.hasOwnProperty;

exports.hasUserDefinedProperty = function(obj, key) {
exports.hasUserDefinedProperty = function (obj, key) {
if (obj == null) {
return false;
}
Expand Down Expand Up @@ -773,7 +773,7 @@ exports.hasUserDefinedProperty = function(obj, key) {

const MAX_ARRAY_INDEX = Math.pow(2, 32) - 1;

exports.isArrayIndex = function(val) {
exports.isArrayIndex = function (val) {
if (typeof val === 'number') {
return val >= 0 && val <= MAX_ARRAY_INDEX;
}
Expand All @@ -800,7 +800,7 @@ exports.isArrayIndex = function(val) {
* @api private
*/

exports.array.unique = function(arr) {
exports.array.unique = function (arr) {
const primitives = new Set();
const ids = new Set();
const ret = [];
Expand Down Expand Up @@ -835,7 +835,7 @@ exports.buffer = {};
* @param {Object} b
*/

exports.buffer.areEqual = function(a, b) {
exports.buffer.areEqual = function (a, b) {
if (!Buffer.isBuffer(a)) {
return false;
}
Expand All @@ -861,7 +861,7 @@ exports.getFunctionName = getFunctionName;
* @param {Object} source
*/

exports.decorate = function(destination, source) {
exports.decorate = function (destination, source) {
for (const key in source) {
if (specialProperties.has(key)) {
continue;
Expand All @@ -878,7 +878,7 @@ exports.decorate = function(destination, source) {
* @api private
*/

exports.mergeClone = function(to, fromObj) {
exports.mergeClone = function (to, fromObj) {
if (isMongooseObject(fromObj)) {
fromObj = fromObj.toObject({
transform: false,
Expand Down Expand Up @@ -943,7 +943,7 @@ exports.mergeClone = function(to, fromObj) {
* @api private
*/

exports.each = function(arr, fn) {
exports.each = function (arr, fn) {
for (const item of arr) {
fn(item);
}
Expand All @@ -957,7 +957,7 @@ exports.each = function(arr, fn) {
* @param {String|Number} newKey
* @api private
*/
exports.renameObjKey = function(oldObj, oldKey, newKey) {
exports.renameObjKey = function (oldObj, oldKey, newKey) {
const keys = Object.keys(oldObj);
return keys.reduce(
(acc, val) => {
Expand All @@ -976,7 +976,7 @@ exports.renameObjKey = function(oldObj, oldKey, newKey) {
* ignore
*/

exports.getOption = function(name) {
exports.getOption = function (name) {
const sources = Array.prototype.slice.call(arguments, 1);

for (const source of sources) {
Expand All @@ -995,7 +995,7 @@ exports.getOption = function(name) {
* ignore
*/

exports.noop = function() {};
exports.noop = function () { };

exports.errorToPOJO = function errorToPOJO(error) {
const isError = error instanceof Error;
Expand Down Expand Up @@ -1025,3 +1025,13 @@ exports.injectTimestampsOption = function injectTimestampsOption(writeOperation,
}
writeOperation.timestamps = timestampsOption;
};

exports.print = function (...args) {
const { inspect } = require('util');
console.error(
inspect(
...args,
{ depth: Infinity }
)
)
}

Check warning on line 1037 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Newline required at end of file but not found

Check warning on line 1037 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Lint JS-Files

Newline required at end of file but not found
Loading

0 comments on commit 411e69d

Please sign in to comment.