Enable prefer-const lint rule (#3202)
This commit is contained in:
committed by
Florent Vilmart
parent
a6c988176e
commit
ca286b7108
@@ -1,5 +1,5 @@
|
||||
let mongodb = require('mongodb');
|
||||
let Collection = mongodb.Collection;
|
||||
const mongodb = require('mongodb');
|
||||
const Collection = mongodb.Collection;
|
||||
|
||||
export default class MongoCollection {
|
||||
_mongoCollection:Collection;
|
||||
@@ -21,7 +21,7 @@ export default class MongoCollection {
|
||||
throw error;
|
||||
}
|
||||
// Figure out what key needs an index
|
||||
let key = error.message.match(/field=([A-Za-z_0-9]+) /)[1];
|
||||
const key = error.message.match(/field=([A-Za-z_0-9]+) /)[1];
|
||||
if (!key) {
|
||||
throw error;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export default class MongoCollection {
|
||||
}
|
||||
|
||||
count(query, { skip, limit, sort, maxTimeMS } = {}) {
|
||||
let countOperation = this._mongoCollection.count(query, { skip, limit, sort, maxTimeMS });
|
||||
const countOperation = this._mongoCollection.count(query, { skip, limit, sort, maxTimeMS });
|
||||
|
||||
return countOperation;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ function mongoSchemaToParseSchema(mongoSchema) {
|
||||
}
|
||||
|
||||
function _mongoSchemaQueryFromNameQuery(name: string, query) {
|
||||
let object = { _id: name };
|
||||
const object = { _id: name };
|
||||
if (query) {
|
||||
Object.keys(query).forEach(key => {
|
||||
object[key] = query[key];
|
||||
|
||||
@@ -15,8 +15,8 @@ import Parse from 'parse/node';
|
||||
import _ from 'lodash';
|
||||
import defaults from '../../../defaults';
|
||||
|
||||
let mongodb = require('mongodb');
|
||||
let MongoClient = mongodb.MongoClient;
|
||||
const mongodb = require('mongodb');
|
||||
const MongoClient = mongodb.MongoClient;
|
||||
|
||||
const MongoSchemaCollectionName = '_SCHEMA';
|
||||
|
||||
@@ -53,14 +53,14 @@ const convertParseSchemaToMongoSchema = ({...schema}) => {
|
||||
// Returns { code, error } if invalid, or { result }, an object
|
||||
// suitable for inserting into _SCHEMA collection, otherwise.
|
||||
const mongoSchemaFromFieldsAndClassNameAndCLP = (fields, className, classLevelPermissions) => {
|
||||
let mongoObject = {
|
||||
const mongoObject = {
|
||||
_id: className,
|
||||
objectId: 'string',
|
||||
updatedAt: 'string',
|
||||
createdAt: 'string'
|
||||
};
|
||||
|
||||
for (let fieldName in fields) {
|
||||
for (const fieldName in fields) {
|
||||
mongoObject[fieldName] = MongoSchemaCollection.parseFieldTypeToMongoFieldType(fields[fieldName]);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ export class MongoStorageAdapter {
|
||||
|
||||
createClass(className, schema) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
let mongoObject = mongoSchemaFromFieldsAndClassNameAndCLP(schema.fields, className, schema.classLevelPermissions);
|
||||
const mongoObject = mongoSchemaFromFieldsAndClassNameAndCLP(schema.fields, className, schema.classLevelPermissions);
|
||||
mongoObject._id = className;
|
||||
return this._schemaCollection()
|
||||
.then(schemaCollection => schemaCollection._collection.insertOne(mongoObject))
|
||||
@@ -282,7 +282,7 @@ export class MongoStorageAdapter {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection => {
|
||||
let mongoWhere = transformWhere(className, query, schema);
|
||||
const mongoWhere = transformWhere(className, query, schema);
|
||||
return collection.deleteMany(mongoWhere)
|
||||
})
|
||||
.then(({ result }) => {
|
||||
@@ -327,9 +327,9 @@ export class MongoStorageAdapter {
|
||||
// Executes a find. Accepts: className, query in Parse format, and { skip, limit, sort }.
|
||||
find(className, schema, query, { skip, limit, sort, keys }) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
let mongoWhere = transformWhere(className, query, schema);
|
||||
let mongoSort = _.mapKeys(sort, (value, fieldName) => transformKey(className, fieldName, schema));
|
||||
let mongoKeys = _.reduce(keys, (memo, key) => {
|
||||
const mongoWhere = transformWhere(className, query, schema);
|
||||
const mongoSort = _.mapKeys(sort, (value, fieldName) => transformKey(className, fieldName, schema));
|
||||
const mongoKeys = _.reduce(keys, (memo, key) => {
|
||||
memo[transformKey(className, key, schema)] = 1;
|
||||
return memo;
|
||||
}, {});
|
||||
@@ -351,8 +351,8 @@ export class MongoStorageAdapter {
|
||||
// which is why we use sparse indexes.
|
||||
ensureUniqueness(className, schema, fieldNames) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
let indexCreationRequest = {};
|
||||
let mongoFieldNames = fieldNames.map(fieldName => transformKey(className, fieldName, schema));
|
||||
const indexCreationRequest = {};
|
||||
const mongoFieldNames = fieldNames.map(fieldName => transformKey(className, fieldName, schema));
|
||||
mongoFieldNames.forEach(fieldName => {
|
||||
indexCreationRequest[fieldName] = 1;
|
||||
});
|
||||
|
||||
@@ -243,9 +243,9 @@ function transformQueryKeyValue(className, key, value, schema) {
|
||||
// restWhere is the "where" clause in REST API form.
|
||||
// Returns the mongo form of the query.
|
||||
function transformWhere(className, restWhere, schema) {
|
||||
let mongoWhere = {};
|
||||
for (let restKey in restWhere) {
|
||||
let out = transformQueryKeyValue(className, restKey, restWhere[restKey], schema);
|
||||
const mongoWhere = {};
|
||||
for (const restKey in restWhere) {
|
||||
const out = transformQueryKeyValue(className, restKey, restWhere[restKey], schema);
|
||||
mongoWhere[out.key] = out.value;
|
||||
}
|
||||
return mongoWhere;
|
||||
@@ -331,12 +331,12 @@ const parseObjectKeyValueToMongoObjectKeyValue = (restKey, restValue, schema) =>
|
||||
|
||||
const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
|
||||
restCreate = addLegacyACL(restCreate);
|
||||
let mongoCreate = {}
|
||||
for (let restKey in restCreate) {
|
||||
const mongoCreate = {}
|
||||
for (const restKey in restCreate) {
|
||||
if (restCreate[restKey] && restCreate[restKey].__type === 'Relation') {
|
||||
continue;
|
||||
}
|
||||
let { key, value } = parseObjectKeyValueToMongoObjectKeyValue(
|
||||
const { key, value } = parseObjectKeyValueToMongoObjectKeyValue(
|
||||
restKey,
|
||||
restCreate[restKey],
|
||||
schema
|
||||
@@ -361,8 +361,8 @@ const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
|
||||
|
||||
// Main exposed method to help update old objects.
|
||||
const transformUpdate = (className, restUpdate, parseFormatSchema) => {
|
||||
let mongoUpdate = {};
|
||||
let acl = addLegacyACL(restUpdate);
|
||||
const mongoUpdate = {};
|
||||
const acl = addLegacyACL(restUpdate);
|
||||
if (acl._rperm || acl._wperm || acl._acl) {
|
||||
mongoUpdate.$set = {};
|
||||
if (acl._rperm) {
|
||||
@@ -398,8 +398,8 @@ const transformUpdate = (className, restUpdate, parseFormatSchema) => {
|
||||
|
||||
// Add the legacy _acl format.
|
||||
const addLegacyACL = restObject => {
|
||||
let restObjectCopy = {...restObject};
|
||||
let _acl = {};
|
||||
const restObjectCopy = {...restObject};
|
||||
const _acl = {};
|
||||
|
||||
if (restObject._wperm) {
|
||||
restObject._wperm.forEach(entry => {
|
||||
@@ -532,12 +532,12 @@ function transformConstraint(constraint, inArray) {
|
||||
|
||||
case '$in':
|
||||
case '$nin': {
|
||||
let arr = constraint[key];
|
||||
const arr = constraint[key];
|
||||
if (!(arr instanceof Array)) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + key + ' value');
|
||||
}
|
||||
answer[key] = arr.map(value => {
|
||||
let result = inArray ? transformInteriorAtom(value) : transformTopLevelAtom(value);
|
||||
const result = inArray ? transformInteriorAtom(value) : transformTopLevelAtom(value);
|
||||
if (result === CannotTransform) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad atom: ${value}`);
|
||||
}
|
||||
@@ -546,7 +546,7 @@ function transformConstraint(constraint, inArray) {
|
||||
break;
|
||||
}
|
||||
case '$all': {
|
||||
let arr = constraint[key];
|
||||
const arr = constraint[key];
|
||||
if (!(arr instanceof Array)) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON,
|
||||
'bad ' + key + ' value');
|
||||
@@ -761,7 +761,7 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
return BytesCoder.databaseToJSON(mongoObject);
|
||||
}
|
||||
|
||||
let restObject = {};
|
||||
const restObject = {};
|
||||
if (mongoObject._rperm || mongoObject._wperm) {
|
||||
restObject._rperm = mongoObject._rperm || [];
|
||||
restObject._wperm = mongoObject._wperm || [];
|
||||
@@ -861,7 +861,7 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
}
|
||||
|
||||
const relationFieldNames = Object.keys(schema.fields).filter(fieldName => schema.fields[fieldName].type === 'Relation');
|
||||
let relationFields = {};
|
||||
const relationFields = {};
|
||||
relationFieldNames.forEach(relationFieldName => {
|
||||
relationFields[relationFieldName] = {
|
||||
__type: 'Relation',
|
||||
|
||||
Reference in New Issue
Block a user