Fix Prettier (#7066)
This commit is contained in:
@@ -15,17 +15,7 @@ export default class MongoCollection {
|
||||
// idea. Or even if this behavior is a good idea.
|
||||
find(
|
||||
query,
|
||||
{
|
||||
skip,
|
||||
limit,
|
||||
sort,
|
||||
keys,
|
||||
maxTimeMS,
|
||||
readPreference,
|
||||
hint,
|
||||
caseInsensitive,
|
||||
explain,
|
||||
} = {}
|
||||
{ skip, limit, sort, keys, maxTimeMS, readPreference, hint, caseInsensitive, explain } = {}
|
||||
) {
|
||||
// Support for Full Text Search - $text
|
||||
if (keys && keys.$score) {
|
||||
@@ -44,10 +34,7 @@ export default class MongoCollection {
|
||||
explain,
|
||||
}).catch(error => {
|
||||
// Check for "no geoindex" error
|
||||
if (
|
||||
error.code != 17007 &&
|
||||
!error.message.match(/unable to find index for .geoNear/)
|
||||
) {
|
||||
if (error.code != 17007 && !error.message.match(/unable to find index for .geoNear/)) {
|
||||
throw error;
|
||||
}
|
||||
// Figure out what key needs an index
|
||||
@@ -88,17 +75,7 @@ export default class MongoCollection {
|
||||
|
||||
_rawFind(
|
||||
query,
|
||||
{
|
||||
skip,
|
||||
limit,
|
||||
sort,
|
||||
keys,
|
||||
maxTimeMS,
|
||||
readPreference,
|
||||
hint,
|
||||
caseInsensitive,
|
||||
explain,
|
||||
} = {}
|
||||
{ skip, limit, sort, keys, maxTimeMS, readPreference, hint, caseInsensitive, explain } = {}
|
||||
) {
|
||||
let findOperation = this._mongoCollection.find(query, {
|
||||
skip,
|
||||
@@ -113,9 +90,7 @@ export default class MongoCollection {
|
||||
}
|
||||
|
||||
if (caseInsensitive) {
|
||||
findOperation = findOperation.collation(
|
||||
MongoCollection.caseInsensitiveCollation()
|
||||
);
|
||||
findOperation = findOperation.collation(MongoCollection.caseInsensitiveCollation());
|
||||
}
|
||||
|
||||
if (maxTimeMS) {
|
||||
|
||||
@@ -41,9 +41,7 @@ function mongoFieldToParseSchemaField(type) {
|
||||
|
||||
const nonFieldSchemaKeys = ['_id', '_metadata', '_client_permissions'];
|
||||
function mongoSchemaFieldsToParseSchemaFields(schema) {
|
||||
var fieldNames = Object.keys(schema).filter(
|
||||
(key) => nonFieldSchemaKeys.indexOf(key) === -1
|
||||
);
|
||||
var fieldNames = Object.keys(schema).filter(key => nonFieldSchemaKeys.indexOf(key) === -1);
|
||||
var response = fieldNames.reduce((obj, fieldName) => {
|
||||
obj[fieldName] = mongoFieldToParseSchemaField(schema[fieldName]);
|
||||
if (
|
||||
@@ -110,7 +108,7 @@ function mongoSchemaToParseSchema(mongoSchema) {
|
||||
function _mongoSchemaQueryFromNameQuery(name: string, query) {
|
||||
const object = { _id: name };
|
||||
if (query) {
|
||||
Object.keys(query).forEach((key) => {
|
||||
Object.keys(query).forEach(key => {
|
||||
object[key] = query[key];
|
||||
});
|
||||
}
|
||||
@@ -156,15 +154,13 @@ class MongoSchemaCollection {
|
||||
}
|
||||
|
||||
_fetchAllSchemasFrom_SCHEMA() {
|
||||
return this._collection
|
||||
._rawFind({})
|
||||
.then((schemas) => schemas.map(mongoSchemaToParseSchema));
|
||||
return this._collection._rawFind({}).then(schemas => schemas.map(mongoSchemaToParseSchema));
|
||||
}
|
||||
|
||||
_fetchOneSchemaFrom_SCHEMA(name: string) {
|
||||
return this._collection
|
||||
._rawFind(_mongoSchemaQueryFromNameQuery(name), { limit: 1 })
|
||||
.then((results) => {
|
||||
.then(results => {
|
||||
if (results.length === 1) {
|
||||
return mongoSchemaToParseSchema(results[0]);
|
||||
} else {
|
||||
@@ -175,22 +171,17 @@ class MongoSchemaCollection {
|
||||
|
||||
// Atomically find and delete an object based on query.
|
||||
findAndDeleteSchema(name: string) {
|
||||
return this._collection._mongoCollection.findOneAndDelete(
|
||||
_mongoSchemaQueryFromNameQuery(name)
|
||||
);
|
||||
return this._collection._mongoCollection.findOneAndDelete(_mongoSchemaQueryFromNameQuery(name));
|
||||
}
|
||||
|
||||
insertSchema(schema: any) {
|
||||
return this._collection
|
||||
.insertOne(schema)
|
||||
.then((result) => mongoSchemaToParseSchema(result.ops[0]))
|
||||
.catch((error) => {
|
||||
.then(result => mongoSchemaToParseSchema(result.ops[0]))
|
||||
.catch(error => {
|
||||
if (error.code === 11000) {
|
||||
//Mongo's duplicate key error
|
||||
throw new Parse.Error(
|
||||
Parse.Error.DUPLICATE_VALUE,
|
||||
'Class already exists.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Class already exists.');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -198,17 +189,11 @@ class MongoSchemaCollection {
|
||||
}
|
||||
|
||||
updateSchema(name: string, update) {
|
||||
return this._collection.updateOne(
|
||||
_mongoSchemaQueryFromNameQuery(name),
|
||||
update
|
||||
);
|
||||
return this._collection.updateOne(_mongoSchemaQueryFromNameQuery(name), update);
|
||||
}
|
||||
|
||||
upsertSchema(name: string, query: string, update) {
|
||||
return this._collection.upsertOne(
|
||||
_mongoSchemaQueryFromNameQuery(name, query),
|
||||
update
|
||||
);
|
||||
return this._collection.upsertOne(_mongoSchemaQueryFromNameQuery(name, query), update);
|
||||
}
|
||||
|
||||
// Add a field to the schema. If database does not support the field
|
||||
@@ -225,7 +210,7 @@ class MongoSchemaCollection {
|
||||
addFieldIfNotExists(className: string, fieldName: string, fieldType: string) {
|
||||
return this._fetchOneSchemaFrom_SCHEMA(className)
|
||||
.then(
|
||||
(schema) => {
|
||||
schema => {
|
||||
// If a field with this name already exists, it will be handled elsewhere.
|
||||
if (schema.fields[fieldName] != undefined) {
|
||||
return;
|
||||
@@ -235,8 +220,7 @@ class MongoSchemaCollection {
|
||||
// Make sure there are not other geopoint fields
|
||||
if (
|
||||
Object.keys(schema.fields).some(
|
||||
(existingField) =>
|
||||
schema.fields[existingField].type === 'GeoPoint'
|
||||
existingField => schema.fields[existingField].type === 'GeoPoint'
|
||||
)
|
||||
) {
|
||||
throw new Parse.Error(
|
||||
@@ -247,7 +231,7 @@ class MongoSchemaCollection {
|
||||
}
|
||||
return;
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
// If error is undefined, the schema doesn't exist, and we can create the schema with the field.
|
||||
// If some other error, reject with it.
|
||||
if (error === undefined) {
|
||||
|
||||
@@ -2,16 +2,8 @@
|
||||
import MongoCollection from './MongoCollection';
|
||||
import MongoSchemaCollection from './MongoSchemaCollection';
|
||||
import { StorageAdapter } from '../StorageAdapter';
|
||||
import type {
|
||||
SchemaType,
|
||||
QueryType,
|
||||
StorageClass,
|
||||
QueryOptions,
|
||||
} from '../StorageAdapter';
|
||||
import {
|
||||
parse as parseUrl,
|
||||
format as formatUrl,
|
||||
} from '../../../vendor/mongodbUrl';
|
||||
import type { SchemaType, QueryType, StorageClass, QueryOptions } from '../StorageAdapter';
|
||||
import { parse as parseUrl, format as formatUrl } from '../../../vendor/mongodbUrl';
|
||||
import {
|
||||
parseObjectToMongoObjectForCreate,
|
||||
mongoObjectToParseObject,
|
||||
@@ -45,9 +37,7 @@ const storageAdapterAllCollections = mongoAdapter => {
|
||||
}
|
||||
// TODO: If you have one app with a collection prefix that happens to be a prefix of another
|
||||
// apps prefix, this will go very very badly. We should fix that somehow.
|
||||
return (
|
||||
collection.collectionName.indexOf(mongoAdapter._collectionPrefix) == 0
|
||||
);
|
||||
return collection.collectionName.indexOf(mongoAdapter._collectionPrefix) == 0;
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -85,16 +75,13 @@ const mongoSchemaFromFieldsAndClassNameAndCLP = (
|
||||
|
||||
for (const fieldName in fields) {
|
||||
const { type, targetClass, ...fieldOptions } = fields[fieldName];
|
||||
mongoObject[
|
||||
fieldName
|
||||
] = MongoSchemaCollection.parseFieldTypeToMongoFieldType({
|
||||
mongoObject[fieldName] = MongoSchemaCollection.parseFieldTypeToMongoFieldType({
|
||||
type,
|
||||
targetClass,
|
||||
});
|
||||
if (fieldOptions && Object.keys(fieldOptions).length > 0) {
|
||||
mongoObject._metadata = mongoObject._metadata || {};
|
||||
mongoObject._metadata.fields_options =
|
||||
mongoObject._metadata.fields_options || {};
|
||||
mongoObject._metadata.fields_options = mongoObject._metadata.fields_options || {};
|
||||
mongoObject._metadata.fields_options[fieldName] = fieldOptions;
|
||||
}
|
||||
}
|
||||
@@ -108,11 +95,7 @@ const mongoSchemaFromFieldsAndClassNameAndCLP = (
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
indexes &&
|
||||
typeof indexes === 'object' &&
|
||||
Object.keys(indexes).length > 0
|
||||
) {
|
||||
if (indexes && typeof indexes === 'object' && Object.keys(indexes).length > 0) {
|
||||
mongoObject._metadata = mongoObject._metadata || {};
|
||||
mongoObject._metadata.indexes = indexes;
|
||||
}
|
||||
@@ -137,11 +120,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
_maxTimeMS: ?number;
|
||||
canSortOnJoinTables: boolean;
|
||||
|
||||
constructor({
|
||||
uri = defaults.DefaultMongoURI,
|
||||
collectionPrefix = '',
|
||||
mongoOptions = {},
|
||||
}: any) {
|
||||
constructor({ uri = defaults.DefaultMongoURI, collectionPrefix = '', mongoOptions = {} }: any) {
|
||||
this._uri = uri;
|
||||
this._collectionPrefix = collectionPrefix;
|
||||
this._mongoOptions = mongoOptions;
|
||||
@@ -225,9 +204,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
classExists(name: string) {
|
||||
return this.connect()
|
||||
.then(() => {
|
||||
return this.database
|
||||
.listCollections({ name: this._collectionPrefix + name })
|
||||
.toArray();
|
||||
return this.database.listCollections({ name: this._collectionPrefix + name }).toArray();
|
||||
})
|
||||
.then(collections => {
|
||||
return collections.length > 0;
|
||||
@@ -262,10 +239,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
Object.keys(submittedIndexes).forEach(name => {
|
||||
const field = submittedIndexes[name];
|
||||
if (existingIndexes[name] && field.__op !== 'Delete') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Index ${name} exists, cannot update.`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Index ${name} exists, cannot update.`);
|
||||
}
|
||||
if (!existingIndexes[name] && field.__op === 'Delete') {
|
||||
throw new Parse.Error(
|
||||
@@ -349,26 +323,15 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
schema.indexes
|
||||
);
|
||||
mongoObject._id = className;
|
||||
return this.setIndexesWithSchemaFormat(
|
||||
className,
|
||||
schema.indexes,
|
||||
{},
|
||||
schema.fields
|
||||
)
|
||||
return this.setIndexesWithSchemaFormat(className, schema.indexes, {}, schema.fields)
|
||||
.then(() => this._schemaCollection())
|
||||
.then(schemaCollection => schemaCollection.insertSchema(mongoObject))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
addFieldIfNotExists(
|
||||
className: string,
|
||||
fieldName: string,
|
||||
type: any
|
||||
): Promise<void> {
|
||||
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void> {
|
||||
return this._schemaCollection()
|
||||
.then(schemaCollection =>
|
||||
schemaCollection.addFieldIfNotExists(className, fieldName, type)
|
||||
)
|
||||
.then(schemaCollection => schemaCollection.addFieldIfNotExists(className, fieldName, type))
|
||||
.then(() => this.createIndexesIfNeeded(className, fieldName, type))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
@@ -388,9 +351,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
})
|
||||
// We've dropped the collection, now remove the _SCHEMA document
|
||||
.then(() => this._schemaCollection())
|
||||
.then(schemaCollection =>
|
||||
schemaCollection.findAndDeleteSchema(className)
|
||||
)
|
||||
.then(schemaCollection => schemaCollection.findAndDeleteSchema(className))
|
||||
.catch(err => this.handleError(err))
|
||||
);
|
||||
}
|
||||
@@ -398,9 +359,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
deleteAllClasses(fast: boolean) {
|
||||
return storageAdapterAllCollections(this).then(collections =>
|
||||
Promise.all(
|
||||
collections.map(collection =>
|
||||
fast ? collection.deleteMany({}) : collection.drop()
|
||||
)
|
||||
collections.map(collection => (fast ? collection.deleteMany({}) : collection.drop()))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -450,13 +409,9 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
});
|
||||
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.updateMany(collectionFilter, collectionUpdate)
|
||||
)
|
||||
.then(collection => collection.updateMany(collectionFilter, collectionUpdate))
|
||||
.then(() => this._schemaCollection())
|
||||
.then(schemaCollection =>
|
||||
schemaCollection.updateSchema(className, schemaUpdate)
|
||||
)
|
||||
.then(schemaCollection => schemaCollection.updateSchema(className, schemaUpdate))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
@@ -465,9 +420,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
// rejection reason are TBD.
|
||||
getAllClasses(): Promise<StorageClass[]> {
|
||||
return this._schemaCollection()
|
||||
.then(schemasCollection =>
|
||||
schemasCollection._fetchAllSchemasFrom_SCHEMA()
|
||||
)
|
||||
.then(schemasCollection => schemasCollection._fetchAllSchemasFrom_SCHEMA())
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
@@ -476,31 +429,18 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
// undefined as the reason.
|
||||
getClass(className: string): Promise<StorageClass> {
|
||||
return this._schemaCollection()
|
||||
.then(schemasCollection =>
|
||||
schemasCollection._fetchOneSchemaFrom_SCHEMA(className)
|
||||
)
|
||||
.then(schemasCollection => schemasCollection._fetchOneSchemaFrom_SCHEMA(className))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
// TODO: As yet not particularly well specified. Creates an object. Maybe shouldn't even need the schema,
|
||||
// and should infer from the type. Or maybe does need the schema for validations. Or maybe needs
|
||||
// the schema only for the legacy mongo format. We'll figure that out later.
|
||||
createObject(
|
||||
className: string,
|
||||
schema: SchemaType,
|
||||
object: any,
|
||||
transactionalSession: ?any
|
||||
) {
|
||||
createObject(className: string, schema: SchemaType, object: any, transactionalSession: ?any) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const mongoObject = parseObjectToMongoObjectForCreate(
|
||||
className,
|
||||
object,
|
||||
schema
|
||||
);
|
||||
const mongoObject = parseObjectToMongoObjectForCreate(className, object, schema);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.insertOne(mongoObject, transactionalSession)
|
||||
)
|
||||
.then(collection => collection.insertOne(mongoObject, transactionalSession))
|
||||
.catch(error => {
|
||||
if (error.code === 11000) {
|
||||
// Duplicate value
|
||||
@@ -510,9 +450,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
);
|
||||
err.underlyingError = error;
|
||||
if (error.message) {
|
||||
const matches = error.message.match(
|
||||
/index:[\sa-zA-Z0-9_\-\.]+\$?([a-zA-Z_-]+)_1/
|
||||
);
|
||||
const matches = error.message.match(/index:[\sa-zA-Z0-9_\-\.]+\$?([a-zA-Z_-]+)_1/);
|
||||
if (matches && Array.isArray(matches)) {
|
||||
err.userInfo = { duplicated_field: matches[1] };
|
||||
}
|
||||
@@ -543,18 +481,12 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
.then(
|
||||
({ result }) => {
|
||||
if (result.n === 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
'Object not found.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
() => {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INTERNAL_SERVER_ERROR,
|
||||
'Database adapter error'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Database adapter error');
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -571,9 +503,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
const mongoUpdate = transformUpdate(className, update, schema);
|
||||
const mongoWhere = transformWhere(className, query, schema);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.updateMany(mongoWhere, mongoUpdate, transactionalSession)
|
||||
)
|
||||
.then(collection => collection.updateMany(mongoWhere, mongoUpdate, transactionalSession))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
@@ -621,9 +551,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
const mongoUpdate = transformUpdate(className, update, schema);
|
||||
const mongoWhere = transformWhere(className, query, schema);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.upsertOne(mongoWhere, mongoUpdate, transactionalSession)
|
||||
)
|
||||
.then(collection => collection.upsertOne(mongoWhere, mongoUpdate, transactionalSession))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
@@ -632,16 +560,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
className: string,
|
||||
schema: SchemaType,
|
||||
query: QueryType,
|
||||
{
|
||||
skip,
|
||||
limit,
|
||||
sort,
|
||||
keys,
|
||||
readPreference,
|
||||
hint,
|
||||
caseInsensitive,
|
||||
explain,
|
||||
}: QueryOptions
|
||||
{ skip, limit, sort, keys, readPreference, hint, caseInsensitive, explain }: QueryOptions
|
||||
): Promise<any> {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const mongoWhere = transformWhere(className, query, schema);
|
||||
@@ -689,9 +608,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
if (explain) {
|
||||
return objects;
|
||||
}
|
||||
return objects.map(object =>
|
||||
mongoObjectToParseObject(className, object, schema)
|
||||
);
|
||||
return objects.map(object => mongoObjectToParseObject(className, object, schema));
|
||||
})
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
@@ -706,18 +623,14 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
): Promise<any> {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const indexCreationRequest = {};
|
||||
const mongoFieldNames = fieldNames.map(fieldName =>
|
||||
transformKey(className, fieldName, schema)
|
||||
);
|
||||
const mongoFieldNames = fieldNames.map(fieldName => transformKey(className, fieldName, schema));
|
||||
mongoFieldNames.forEach(fieldName => {
|
||||
indexCreationRequest[fieldName] =
|
||||
options.indexType !== undefined ? options.indexType : 1;
|
||||
indexCreationRequest[fieldName] = options.indexType !== undefined ? options.indexType : 1;
|
||||
});
|
||||
|
||||
const defaultOptions: Object = { background: true, sparse: true };
|
||||
const indexNameOptions: Object = indexName ? { name: indexName } : {};
|
||||
const ttlOptions: Object =
|
||||
options.ttl !== undefined ? { expireAfterSeconds: options.ttl } : {};
|
||||
const ttlOptions: Object = options.ttl !== undefined ? { expireAfterSeconds: options.ttl } : {};
|
||||
const caseInsensitiveOptions: Object = caseInsensitive
|
||||
? { collation: MongoCollection.caseInsensitiveCollation() }
|
||||
: {};
|
||||
@@ -732,10 +645,8 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
.then(
|
||||
collection =>
|
||||
new Promise((resolve, reject) =>
|
||||
collection._mongoCollection.createIndex(
|
||||
indexCreationRequest,
|
||||
indexOptions,
|
||||
error => (error ? reject(error) : resolve())
|
||||
collection._mongoCollection.createIndex(indexCreationRequest, indexOptions, error =>
|
||||
error ? reject(error) : resolve()
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -747,23 +658,15 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
// As such, we shouldn't expose this function to users of parse until we have an out-of-band
|
||||
// Way of determining if a field is nullable. Undefined doesn't count against uniqueness,
|
||||
// which is why we use sparse indexes.
|
||||
ensureUniqueness(
|
||||
className: string,
|
||||
schema: SchemaType,
|
||||
fieldNames: string[]
|
||||
) {
|
||||
ensureUniqueness(className: string, schema: SchemaType, fieldNames: string[]) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const indexCreationRequest = {};
|
||||
const mongoFieldNames = fieldNames.map(fieldName =>
|
||||
transformKey(className, fieldName, schema)
|
||||
);
|
||||
const mongoFieldNames = fieldNames.map(fieldName => transformKey(className, fieldName, schema));
|
||||
mongoFieldNames.forEach(fieldName => {
|
||||
indexCreationRequest[fieldName] = 1;
|
||||
});
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection._ensureSparseUniqueIndexInBackground(indexCreationRequest)
|
||||
)
|
||||
.then(collection => collection._ensureSparseUniqueIndexInBackground(indexCreationRequest))
|
||||
.catch(error => {
|
||||
if (error.code === 11000) {
|
||||
throw new Parse.Error(
|
||||
@@ -808,23 +711,14 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
distinct(
|
||||
className: string,
|
||||
schema: SchemaType,
|
||||
query: QueryType,
|
||||
fieldName: string
|
||||
) {
|
||||
distinct(className: string, schema: SchemaType, query: QueryType, fieldName: string) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const isPointerField =
|
||||
schema.fields[fieldName] && schema.fields[fieldName].type === 'Pointer';
|
||||
const isPointerField = schema.fields[fieldName] && schema.fields[fieldName].type === 'Pointer';
|
||||
const transformField = transformKey(className, fieldName, schema);
|
||||
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.distinct(
|
||||
transformField,
|
||||
transformWhere(className, query, schema)
|
||||
)
|
||||
collection.distinct(transformField, transformWhere(className, query, schema))
|
||||
)
|
||||
.then(objects => {
|
||||
objects = objects.filter(obj => obj != null);
|
||||
@@ -862,16 +756,10 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
stage.$match = this._parseAggregateArgs(schema, stage.$match);
|
||||
}
|
||||
if (stage.$project) {
|
||||
stage.$project = this._parseAggregateProjectArgs(
|
||||
schema,
|
||||
stage.$project
|
||||
);
|
||||
stage.$project = this._parseAggregateProjectArgs(schema, stage.$project);
|
||||
}
|
||||
if (stage.$geoNear && stage.$geoNear.query) {
|
||||
stage.$geoNear.query = this._parseAggregateArgs(
|
||||
schema,
|
||||
stage.$geoNear.query
|
||||
);
|
||||
stage.$geoNear.query = this._parseAggregateArgs(schema, stage.$geoNear.query);
|
||||
}
|
||||
return stage;
|
||||
});
|
||||
@@ -894,8 +782,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
if (
|
||||
result._id == null ||
|
||||
result._id == undefined ||
|
||||
(['object', 'string'].includes(typeof result._id) &&
|
||||
_.isEmpty(result._id))
|
||||
(['object', 'string'].includes(typeof result._id) && _.isEmpty(result._id))
|
||||
) {
|
||||
result._id = null;
|
||||
}
|
||||
@@ -905,11 +792,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
});
|
||||
return results;
|
||||
})
|
||||
.then(objects =>
|
||||
objects.map(object =>
|
||||
mongoObjectToParseObject(className, object, schema)
|
||||
)
|
||||
)
|
||||
.then(objects => objects.map(object => mongoObjectToParseObject(className, object, schema)))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
@@ -945,20 +828,12 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
// Pass objects down to MongoDB...this is more than likely an $exists operator.
|
||||
returnValue[`_p_${field}`] = pipeline[field];
|
||||
} else {
|
||||
returnValue[
|
||||
`_p_${field}`
|
||||
] = `${schema.fields[field].targetClass}$${pipeline[field]}`;
|
||||
returnValue[`_p_${field}`] = `${schema.fields[field].targetClass}$${pipeline[field]}`;
|
||||
}
|
||||
} else if (
|
||||
schema.fields[field] &&
|
||||
schema.fields[field].type === 'Date'
|
||||
) {
|
||||
} else if (schema.fields[field] && schema.fields[field].type === 'Date') {
|
||||
returnValue[field] = this._convertToDate(pipeline[field]);
|
||||
} else {
|
||||
returnValue[field] = this._parseAggregateArgs(
|
||||
schema,
|
||||
pipeline[field]
|
||||
);
|
||||
returnValue[field] = this._parseAggregateArgs(schema, pipeline[field]);
|
||||
}
|
||||
|
||||
if (field === 'objectId') {
|
||||
@@ -1011,16 +886,11 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
// updatedAt or objectId and change it accordingly.
|
||||
_parseAggregateGroupArgs(schema: any, pipeline: any): any {
|
||||
if (Array.isArray(pipeline)) {
|
||||
return pipeline.map(value =>
|
||||
this._parseAggregateGroupArgs(schema, value)
|
||||
);
|
||||
return pipeline.map(value => this._parseAggregateGroupArgs(schema, value));
|
||||
} else if (typeof pipeline === 'object') {
|
||||
const returnValue = {};
|
||||
for (const field in pipeline) {
|
||||
returnValue[field] = this._parseAggregateGroupArgs(
|
||||
schema,
|
||||
pipeline[field]
|
||||
);
|
||||
returnValue[field] = this._parseAggregateGroupArgs(schema, pipeline[field]);
|
||||
}
|
||||
return returnValue;
|
||||
} else if (typeof pipeline === 'string') {
|
||||
@@ -1077,10 +947,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
case '':
|
||||
break;
|
||||
default:
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
'Not supported read preference.'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Not supported read preference.');
|
||||
}
|
||||
return readPreference;
|
||||
}
|
||||
@@ -1111,11 +978,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
createTextIndexesIfNeeded(
|
||||
className: string,
|
||||
query: QueryType,
|
||||
schema: any
|
||||
): Promise<void> {
|
||||
createTextIndexesIfNeeded(className: string, query: QueryType, schema: any): Promise<void> {
|
||||
for (const fieldName in query) {
|
||||
if (!query[fieldName] || !query[fieldName].$text) {
|
||||
continue;
|
||||
|
||||
@@ -20,27 +20,16 @@ const transformKey = (className, fieldName, schema) => {
|
||||
return 'times_used';
|
||||
}
|
||||
|
||||
if (
|
||||
schema.fields[fieldName] &&
|
||||
schema.fields[fieldName].__type == 'Pointer'
|
||||
) {
|
||||
if (schema.fields[fieldName] && schema.fields[fieldName].__type == 'Pointer') {
|
||||
fieldName = '_p_' + fieldName;
|
||||
} else if (
|
||||
schema.fields[fieldName] &&
|
||||
schema.fields[fieldName].type == 'Pointer'
|
||||
) {
|
||||
} else if (schema.fields[fieldName] && schema.fields[fieldName].type == 'Pointer') {
|
||||
fieldName = '_p_' + fieldName;
|
||||
}
|
||||
|
||||
return fieldName;
|
||||
};
|
||||
|
||||
const transformKeyValueForUpdate = (
|
||||
className,
|
||||
restKey,
|
||||
restValue,
|
||||
parseFormatSchema
|
||||
) => {
|
||||
const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSchema) => {
|
||||
// Check if the schema is known since it's a built-in field.
|
||||
var key = restKey;
|
||||
var timeField = false;
|
||||
@@ -109,11 +98,8 @@ const transformKeyValueForUpdate = (
|
||||
}
|
||||
|
||||
if (
|
||||
(parseFormatSchema.fields[key] &&
|
||||
parseFormatSchema.fields[key].type === 'Pointer') ||
|
||||
(!parseFormatSchema.fields[key] &&
|
||||
restValue &&
|
||||
restValue.__type == 'Pointer')
|
||||
(parseFormatSchema.fields[key] && parseFormatSchema.fields[key].type === 'Pointer') ||
|
||||
(!parseFormatSchema.fields[key] && restValue && restValue.__type == 'Pointer')
|
||||
) {
|
||||
key = '_p_' + key;
|
||||
}
|
||||
@@ -179,7 +165,7 @@ const isAllValuesRegexOrNone = values => {
|
||||
};
|
||||
|
||||
const isAnyValueRegex = values => {
|
||||
return values.some(function(value) {
|
||||
return values.some(function (value) {
|
||||
return isRegex(value);
|
||||
});
|
||||
};
|
||||
@@ -292,9 +278,7 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
|
||||
case '$nor':
|
||||
return {
|
||||
key: key,
|
||||
value: value.map(subQuery =>
|
||||
transformWhere(className, subQuery, schema, count)
|
||||
),
|
||||
value: value.map(subQuery => transformWhere(className, subQuery, schema, count)),
|
||||
};
|
||||
case 'lastUsed':
|
||||
if (valueAsDate(value)) {
|
||||
@@ -315,17 +299,13 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
|
||||
}
|
||||
}
|
||||
|
||||
const expectedTypeIsArray =
|
||||
schema && schema.fields[key] && schema.fields[key].type === 'Array';
|
||||
const expectedTypeIsArray = schema && schema.fields[key] && schema.fields[key].type === 'Array';
|
||||
|
||||
const expectedTypeIsPointer =
|
||||
schema && schema.fields[key] && schema.fields[key].type === 'Pointer';
|
||||
|
||||
const field = schema && schema.fields[key];
|
||||
if (
|
||||
expectedTypeIsPointer ||
|
||||
(!schema && value && value.__type === 'Pointer')
|
||||
) {
|
||||
if (expectedTypeIsPointer || (!schema && value && value.__type === 'Pointer')) {
|
||||
key = '_p_' + key;
|
||||
}
|
||||
|
||||
@@ -362,23 +342,13 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
|
||||
function transformWhere(className, restWhere, schema, count = false) {
|
||||
const mongoWhere = {};
|
||||
for (const restKey in restWhere) {
|
||||
const out = transformQueryKeyValue(
|
||||
className,
|
||||
restKey,
|
||||
restWhere[restKey],
|
||||
schema,
|
||||
count
|
||||
);
|
||||
const out = transformQueryKeyValue(className, restKey, restWhere[restKey], schema, count);
|
||||
mongoWhere[out.key] = out.value;
|
||||
}
|
||||
return mongoWhere;
|
||||
}
|
||||
|
||||
const parseObjectKeyValueToMongoObjectKeyValue = (
|
||||
restKey,
|
||||
restValue,
|
||||
schema
|
||||
) => {
|
||||
const parseObjectKeyValueToMongoObjectKeyValue = (restKey, restValue, schema) => {
|
||||
// Check if the schema is known since it's a built-in field.
|
||||
let transformedValue;
|
||||
let coercedToDate;
|
||||
@@ -388,37 +358,27 @@ const parseObjectKeyValueToMongoObjectKeyValue = (
|
||||
case 'expiresAt':
|
||||
transformedValue = transformTopLevelAtom(restValue);
|
||||
coercedToDate =
|
||||
typeof transformedValue === 'string'
|
||||
? new Date(transformedValue)
|
||||
: transformedValue;
|
||||
typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue;
|
||||
return { key: 'expiresAt', value: coercedToDate };
|
||||
case '_email_verify_token_expires_at':
|
||||
transformedValue = transformTopLevelAtom(restValue);
|
||||
coercedToDate =
|
||||
typeof transformedValue === 'string'
|
||||
? new Date(transformedValue)
|
||||
: transformedValue;
|
||||
typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue;
|
||||
return { key: '_email_verify_token_expires_at', value: coercedToDate };
|
||||
case '_account_lockout_expires_at':
|
||||
transformedValue = transformTopLevelAtom(restValue);
|
||||
coercedToDate =
|
||||
typeof transformedValue === 'string'
|
||||
? new Date(transformedValue)
|
||||
: transformedValue;
|
||||
typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue;
|
||||
return { key: '_account_lockout_expires_at', value: coercedToDate };
|
||||
case '_perishable_token_expires_at':
|
||||
transformedValue = transformTopLevelAtom(restValue);
|
||||
coercedToDate =
|
||||
typeof transformedValue === 'string'
|
||||
? new Date(transformedValue)
|
||||
: transformedValue;
|
||||
typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue;
|
||||
return { key: '_perishable_token_expires_at', value: coercedToDate };
|
||||
case '_password_changed_at':
|
||||
transformedValue = transformTopLevelAtom(restValue);
|
||||
coercedToDate =
|
||||
typeof transformedValue === 'string'
|
||||
? new Date(transformedValue)
|
||||
: transformedValue;
|
||||
typeof transformedValue === 'string' ? new Date(transformedValue) : transformedValue;
|
||||
return { key: '_password_changed_at', value: coercedToDate };
|
||||
case '_failed_login_count':
|
||||
case '_rperm':
|
||||
@@ -432,10 +392,7 @@ const parseObjectKeyValueToMongoObjectKeyValue = (
|
||||
default:
|
||||
// Auth data should have been transformed already
|
||||
if (restKey.match(/^authData\.([a-zA-Z0-9_]+)\.id$/)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_KEY_NAME,
|
||||
'can only query on ' + restKey
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'can only query on ' + restKey);
|
||||
}
|
||||
// Trust that the auth data has been transformed and save it directly
|
||||
if (restKey.match(/^_auth_data_[a-zA-Z0-9_]+$/)) {
|
||||
@@ -473,9 +430,7 @@ const parseObjectKeyValueToMongoObjectKeyValue = (
|
||||
}
|
||||
|
||||
// Handle normal objects by recursing
|
||||
if (
|
||||
Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))
|
||||
) {
|
||||
if (Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_NESTED_KEY,
|
||||
"Nested keys should not contain the '$' or '.' characters"
|
||||
@@ -504,15 +459,11 @@ const parseObjectToMongoObjectForCreate = (className, restCreate, schema) => {
|
||||
|
||||
// Use the legacy mongo format for createdAt and updatedAt
|
||||
if (mongoCreate.createdAt) {
|
||||
mongoCreate._created_at = new Date(
|
||||
mongoCreate.createdAt.iso || mongoCreate.createdAt
|
||||
);
|
||||
mongoCreate._created_at = new Date(mongoCreate.createdAt.iso || mongoCreate.createdAt);
|
||||
delete mongoCreate.createdAt;
|
||||
}
|
||||
if (mongoCreate.updatedAt) {
|
||||
mongoCreate._updated_at = new Date(
|
||||
mongoCreate.updatedAt.iso || mongoCreate.updatedAt
|
||||
);
|
||||
mongoCreate._updated_at = new Date(mongoCreate.updatedAt.iso || mongoCreate.updatedAt);
|
||||
delete mongoCreate.updatedAt;
|
||||
}
|
||||
|
||||
@@ -593,22 +544,14 @@ function CannotTransform() {}
|
||||
|
||||
const transformInteriorAtom = atom => {
|
||||
// TODO: check validity harder for the __type-defined types
|
||||
if (
|
||||
typeof atom === 'object' &&
|
||||
atom &&
|
||||
!(atom instanceof Date) &&
|
||||
atom.__type === 'Pointer'
|
||||
) {
|
||||
if (typeof atom === 'object' && atom && !(atom instanceof Date) && atom.__type === 'Pointer') {
|
||||
return {
|
||||
__type: 'Pointer',
|
||||
className: atom.className,
|
||||
objectId: atom.objectId,
|
||||
};
|
||||
} else if (typeof atom === 'function' || typeof atom === 'symbol') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`cannot transform value: ${atom}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `cannot transform value: ${atom}`);
|
||||
} else if (DateCoder.isValidJSON(atom)) {
|
||||
return DateCoder.JSONToDatabase(atom);
|
||||
} else if (BytesCoder.isValidJSON(atom)) {
|
||||
@@ -640,10 +583,7 @@ function transformTopLevelAtom(atom, field) {
|
||||
return atom;
|
||||
case 'symbol':
|
||||
case 'function':
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`cannot transform value: ${atom}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `cannot transform value: ${atom}`);
|
||||
case 'object':
|
||||
if (atom instanceof Date) {
|
||||
// Technically dates are not rest format, but, it seems pretty
|
||||
@@ -822,16 +762,11 @@ function transformConstraint(constraint, field, count = false) {
|
||||
if (typeof constraint !== 'object' || !constraint) {
|
||||
return CannotTransform;
|
||||
}
|
||||
const transformFunction = inArray
|
||||
? transformInteriorAtom
|
||||
: transformTopLevelAtom;
|
||||
const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom;
|
||||
const transformer = atom => {
|
||||
const result = transformFunction(atom, field);
|
||||
if (result === CannotTransform) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad atom: ${JSON.stringify(atom)}`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad atom: ${JSON.stringify(atom)}`);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -839,9 +774,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
// This is a hack so that:
|
||||
// $regex is handled before $options
|
||||
// $nearSphere is handled before $maxDistance
|
||||
var keys = Object.keys(constraint)
|
||||
.sort()
|
||||
.reverse();
|
||||
var keys = Object.keys(constraint).sort().reverse();
|
||||
var answer = {};
|
||||
for (var key of keys) {
|
||||
switch (key) {
|
||||
@@ -892,10 +825,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
case '$nin': {
|
||||
const arr = constraint[key];
|
||||
if (!(arr instanceof Array)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'bad ' + key + ' value'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + key + ' value');
|
||||
}
|
||||
answer[key] = _.flatMap(arr, value => {
|
||||
return (atom => {
|
||||
@@ -911,10 +841,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
case '$all': {
|
||||
const arr = constraint[key];
|
||||
if (!(arr instanceof Array)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'bad ' + key + ' value'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad ' + key + ' value');
|
||||
}
|
||||
answer[key] = arr.map(transformInteriorAtom);
|
||||
|
||||
@@ -939,10 +866,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
case '$containedBy': {
|
||||
const arr = constraint[key];
|
||||
if (!(arr instanceof Array)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $containedBy: should be an array`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $containedBy: should be an array`);
|
||||
}
|
||||
answer.$elemMatch = {
|
||||
$nin: arr.map(transformer),
|
||||
@@ -956,33 +880,21 @@ function transformConstraint(constraint, field, count = false) {
|
||||
case '$text': {
|
||||
const search = constraint[key].$search;
|
||||
if (typeof search !== 'object') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $text: $search, should be object`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $search, should be object`);
|
||||
}
|
||||
if (!search.$term || typeof search.$term !== 'string') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $text: $term, should be string`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $term, should be string`);
|
||||
} else {
|
||||
answer[key] = {
|
||||
$search: search.$term,
|
||||
};
|
||||
}
|
||||
if (search.$language && typeof search.$language !== 'string') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $text: $language, should be string`
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad $text: $language, should be string`);
|
||||
} else if (search.$language) {
|
||||
answer[key].$language = search.$language;
|
||||
}
|
||||
if (
|
||||
search.$caseSensitive &&
|
||||
typeof search.$caseSensitive !== 'boolean'
|
||||
) {
|
||||
if (search.$caseSensitive && typeof search.$caseSensitive !== 'boolean') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $text: $caseSensitive, should be boolean`
|
||||
@@ -990,10 +902,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
} else if (search.$caseSensitive) {
|
||||
answer[key].$caseSensitive = search.$caseSensitive;
|
||||
}
|
||||
if (
|
||||
search.$diacriticSensitive &&
|
||||
typeof search.$diacriticSensitive !== 'boolean'
|
||||
) {
|
||||
if (search.$diacriticSensitive && typeof search.$diacriticSensitive !== 'boolean') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
`bad $text: $diacriticSensitive, should be boolean`
|
||||
@@ -1007,10 +916,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
const point = constraint[key];
|
||||
if (count) {
|
||||
answer.$geoWithin = {
|
||||
$centerSphere: [
|
||||
[point.longitude, point.latitude],
|
||||
constraint.$maxDistance,
|
||||
],
|
||||
$centerSphere: [[point.longitude, point.latitude], constraint.$maxDistance],
|
||||
};
|
||||
} else {
|
||||
answer[key] = [point.longitude, point.latitude];
|
||||
@@ -1046,10 +952,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
case '$within':
|
||||
var box = constraint[key]['$box'];
|
||||
if (!box || box.length != 2) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'malformatted $within arg'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'malformatted $within arg');
|
||||
}
|
||||
answer[key] = {
|
||||
$box: [
|
||||
@@ -1092,10 +995,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
return point;
|
||||
}
|
||||
if (!GeoPointCoder.isValidJSON(point)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'bad $geoWithin value'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
|
||||
} else {
|
||||
Parse.GeoPoint._validate(point.latitude, point.longitude);
|
||||
}
|
||||
@@ -1156,10 +1056,7 @@ function transformConstraint(constraint, field, count = false) {
|
||||
}
|
||||
default:
|
||||
if (key.match(/^\$+/)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'bad constraint: ' + key
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad constraint: ' + key);
|
||||
}
|
||||
return CannotTransform;
|
||||
}
|
||||
@@ -1188,10 +1085,7 @@ function transformUpdateOperator({ __op, amount, objects }, flatten) {
|
||||
|
||||
case 'Increment':
|
||||
if (typeof amount !== 'number') {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'incrementing must provide a number'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'incrementing must provide a number');
|
||||
}
|
||||
if (flatten) {
|
||||
return amount;
|
||||
@@ -1202,10 +1096,7 @@ function transformUpdateOperator({ __op, amount, objects }, flatten) {
|
||||
case 'Add':
|
||||
case 'AddUnique':
|
||||
if (!(objects instanceof Array)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'objects to add must be an array'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'objects to add must be an array');
|
||||
}
|
||||
var toAdd = objects.map(transformInteriorAtom);
|
||||
if (flatten) {
|
||||
@@ -1220,10 +1111,7 @@ function transformUpdateOperator({ __op, amount, objects }, flatten) {
|
||||
|
||||
case 'Remove':
|
||||
if (!(objects instanceof Array)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_JSON,
|
||||
'objects to remove must be an array'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_JSON, 'objects to remove must be an array');
|
||||
}
|
||||
var toRemove = objects.map(transformInteriorAtom);
|
||||
if (flatten) {
|
||||
@@ -1379,15 +1267,11 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
break;
|
||||
case 'updatedAt':
|
||||
case '_updated_at':
|
||||
restObject['updatedAt'] = Parse._encode(
|
||||
new Date(mongoObject[key])
|
||||
).iso;
|
||||
restObject['updatedAt'] = Parse._encode(new Date(mongoObject[key])).iso;
|
||||
break;
|
||||
case 'createdAt':
|
||||
case '_created_at':
|
||||
restObject['createdAt'] = Parse._encode(
|
||||
new Date(mongoObject[key])
|
||||
).iso;
|
||||
restObject['createdAt'] = Parse._encode(new Date(mongoObject[key])).iso;
|
||||
break;
|
||||
case 'expiresAt':
|
||||
case '_expiresAt':
|
||||
@@ -1395,9 +1279,7 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
break;
|
||||
case 'lastUsed':
|
||||
case '_last_used':
|
||||
restObject['lastUsed'] = Parse._encode(
|
||||
new Date(mongoObject[key])
|
||||
).iso;
|
||||
restObject['lastUsed'] = Parse._encode(new Date(mongoObject[key])).iso;
|
||||
break;
|
||||
case 'timesUsed':
|
||||
case 'times_used':
|
||||
@@ -1445,11 +1327,7 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
if (mongoObject[key] === null) {
|
||||
break;
|
||||
}
|
||||
restObject[newKey] = transformPointerString(
|
||||
schema,
|
||||
newKey,
|
||||
mongoObject[key]
|
||||
);
|
||||
restObject[newKey] = transformPointerString(schema, newKey, mongoObject[key]);
|
||||
break;
|
||||
} else if (key[0] == '_' && key != '__type') {
|
||||
throw 'bad key in untransform: ' + key;
|
||||
@@ -1488,9 +1366,7 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
restObject[key] = nestedMongoObjectToNestedParseObject(
|
||||
mongoObject[key]
|
||||
);
|
||||
restObject[key] = nestedMongoObjectToNestedParseObject(mongoObject[key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1518,16 +1394,12 @@ var DateCoder = {
|
||||
},
|
||||
|
||||
isValidJSON(value) {
|
||||
return (
|
||||
typeof value === 'object' && value !== null && value.__type === 'Date'
|
||||
);
|
||||
return typeof value === 'object' && value !== null && value.__type === 'Date';
|
||||
},
|
||||
};
|
||||
|
||||
var BytesCoder = {
|
||||
base64Pattern: new RegExp(
|
||||
'^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'
|
||||
),
|
||||
base64Pattern: new RegExp('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$'),
|
||||
isBase64Value(object) {
|
||||
if (typeof object !== 'string') {
|
||||
return false;
|
||||
@@ -1557,9 +1429,7 @@ var BytesCoder = {
|
||||
},
|
||||
|
||||
isValidJSON(value) {
|
||||
return (
|
||||
typeof value === 'object' && value !== null && value.__type === 'Bytes'
|
||||
);
|
||||
return typeof value === 'object' && value !== null && value.__type === 'Bytes';
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1581,9 +1451,7 @@ var GeoPointCoder = {
|
||||
},
|
||||
|
||||
isValidJSON(value) {
|
||||
return (
|
||||
typeof value === 'object' && value !== null && value.__type === 'GeoPoint'
|
||||
);
|
||||
return typeof value === 'object' && value !== null && value.__type === 'GeoPoint';
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1648,9 +1516,7 @@ var PolygonCoder = {
|
||||
},
|
||||
|
||||
isValidJSON(value) {
|
||||
return (
|
||||
typeof value === 'object' && value !== null && value.__type === 'Polygon'
|
||||
);
|
||||
return typeof value === 'object' && value !== null && value.__type === 'Polygon';
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1671,9 +1537,7 @@ var FileCoder = {
|
||||
},
|
||||
|
||||
isValidJSON(value) {
|
||||
return (
|
||||
typeof value === 'object' && value !== null && value.__type === 'File'
|
||||
);
|
||||
return typeof value === 'object' && value !== null && value.__type === 'File';
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user