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

Few forEach to for of loop #453

Merged
merged 4 commits into from
Nov 21, 2024
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
4 changes: 2 additions & 2 deletions package/collection2/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function flattenSelector(selector) {

const obj = {};

Object.entries(selector).forEach(([key, value]) => {
for (const [key, value] of Object.entries(selector) || []) {
// Ignoring logical selectors (https://docs.mongodb.com/manual/reference/operator/query/#logical)
if (!key.startsWith('$')) {
if (typeof value === 'object' && value !== null) {
Expand All @@ -25,7 +25,7 @@ export function flattenSelector(selector) {
obj[key] = value;
}
}
});
}

return obj;
}
Expand Down
26 changes: 12 additions & 14 deletions package/collection2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
Collection2.emit('schema.attached', this, ss, options);
};

[Mongo.Collection, LocalCollection].forEach((obj) => {
for (const obj of [Mongo.Collection, LocalCollection]) {
/**
* simpleSchema
* @description function detect the correct schema by given params. If it
Expand All @@ -129,15 +129,15 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
obj.prototype.simpleSchema = function (doc, options, query) {
if (!this._c2) return null;
if (this._c2._simpleSchema) return this._c2._simpleSchema;

const schemas = this._c2._simpleSchemas;
if (schemas && schemas.length > 0) {
let schema, selector, target;
// Position 0 reserved for base schema
for (let i = 1; i < schemas.length; i++) {
schema = schemas[i];
selector = Object.keys(schema.selector)[0];

// We will set this to undefined because in theory, you might want to select
// on a null value.
target = undefined;
Expand All @@ -153,7 +153,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
// on upsert/update operations
target = query[selector];
}

// we need to compare given selector with doc property or option to
// find the right schema
if (target !== undefined && target === schema.selector[selector]) {
Expand All @@ -166,12 +166,12 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
throw new Error('No default schema');
}
}

return null;
};
});
}

function getArgumentsAndValidationContext(methodName, args, async) {
function getArgumentsAndValidationContext(methodName, args, async) {
let options = isInsertType(methodName) ? args[1] : args[2];

// Support missing options arg
Expand Down Expand Up @@ -421,14 +421,12 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
};

const cleanOptionsForThisOperation = {};
['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings'].forEach(
(prop) => {
if (typeof options[prop] === 'boolean') {
cleanOptionsForThisOperation[prop] = options[prop];
}
for (const prop of ['autoConvert', 'filter', 'removeEmptyStrings', 'removeNullsFromArrays', 'trimStrings']) {
if (typeof options[prop] === 'boolean') {
cleanOptionsForThisOperation[prop] = options[prop];
}
);
}

// Preliminary cleaning on both client and server. On the server and for local
// collections, automatic values will also be set at this point.
schema.clean(doc, {
Expand Down