Remove mongo object create format from Parse Server (#1516)
This commit is contained in:
@@ -23,11 +23,11 @@ var dummySchema = {
|
||||
};
|
||||
|
||||
|
||||
describe('transformCreate', () => {
|
||||
describe('parseObjectToMongoObject', () => {
|
||||
|
||||
it('a basic number', (done) => {
|
||||
var input = {five: 5};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
jequal(input, output);
|
||||
done();
|
||||
});
|
||||
@@ -37,7 +37,7 @@ describe('transformCreate', () => {
|
||||
createdAt: "2015-10-06T21:24:50.332Z",
|
||||
updatedAt: "2015-10-06T21:24:50.332Z"
|
||||
};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
expect(output._created_at instanceof Date).toBe(true);
|
||||
expect(output._updated_at instanceof Date).toBe(true);
|
||||
done();
|
||||
@@ -49,21 +49,21 @@ describe('transformCreate', () => {
|
||||
objectId: 'myId',
|
||||
className: 'Blah',
|
||||
};
|
||||
var out = transform.transformCreate(dummySchema, null, {pointers: [pointer]});
|
||||
var out = transform.parseObjectToMongoObject(dummySchema, null, {pointers: [pointer]});
|
||||
jequal([pointer], out.pointers);
|
||||
done();
|
||||
});
|
||||
|
||||
it('a delete op', (done) => {
|
||||
var input = {deleteMe: {__op: 'Delete'}};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
jequal(output, {});
|
||||
done();
|
||||
});
|
||||
|
||||
it('basic ACL', (done) => {
|
||||
var input = {ACL: {'0123': {'read': true, 'write': true}}};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
// This just checks that it doesn't crash, but it should check format.
|
||||
done();
|
||||
});
|
||||
@@ -71,21 +71,21 @@ describe('transformCreate', () => {
|
||||
describe('GeoPoints', () => {
|
||||
it('plain', (done) => {
|
||||
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
|
||||
var out = transform.transformCreate(dummySchema, null, {location: geoPoint});
|
||||
var out = transform.parseObjectToMongoObject(dummySchema, null, {location: geoPoint});
|
||||
expect(out.location).toEqual([180, -180]);
|
||||
done();
|
||||
});
|
||||
|
||||
it('in array', (done) => {
|
||||
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
|
||||
var out = transform.transformCreate(dummySchema, null, {locations: [geoPoint, geoPoint]});
|
||||
var out = transform.parseObjectToMongoObject(dummySchema, null, {locations: [geoPoint, geoPoint]});
|
||||
expect(out.locations).toEqual([geoPoint, geoPoint]);
|
||||
done();
|
||||
});
|
||||
|
||||
it('in sub-object', (done) => {
|
||||
var geoPoint = {__type: 'GeoPoint', longitude: 180, latitude: -180};
|
||||
var out = transform.transformCreate(dummySchema, null, { locations: { start: geoPoint }});
|
||||
var out = transform.parseObjectToMongoObject(dummySchema, null, { locations: { start: geoPoint }});
|
||||
expect(out).toEqual({ locations: { start: geoPoint } });
|
||||
done();
|
||||
});
|
||||
@@ -196,7 +196,7 @@ describe('transform schema key changes', () => {
|
||||
var input = {
|
||||
somePointer: {__type: 'Pointer', className: 'Micro', objectId: 'oft'}
|
||||
};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
expect(typeof output._p_somePointer).toEqual('string');
|
||||
expect(output._p_somePointer).toEqual('Micro$oft');
|
||||
done();
|
||||
@@ -206,7 +206,7 @@ describe('transform schema key changes', () => {
|
||||
var input = {
|
||||
userPointer: {__type: 'Pointer', className: '_User', objectId: 'qwerty'}
|
||||
};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
expect(typeof output._p_userPointer).toEqual('string');
|
||||
expect(output._p_userPointer).toEqual('_User$qwerty');
|
||||
done();
|
||||
@@ -219,7 +219,7 @@ describe('transform schema key changes', () => {
|
||||
"Kevin": { "write": true }
|
||||
}
|
||||
};
|
||||
var output = transform.transformCreate(dummySchema, null, input);
|
||||
var output = transform.parseObjectToMongoObject(dummySchema, null, input);
|
||||
expect(typeof output._rperm).toEqual('object');
|
||||
expect(typeof output._wperm).toEqual('object');
|
||||
expect(output.ACL).toBeUndefined();
|
||||
|
||||
@@ -127,6 +127,15 @@ export class MongoStorageAdapter {
|
||||
.then(schemaCollection => schemaCollection.updateSchema(className, schemaUpdate));
|
||||
}
|
||||
|
||||
// TODO: As yet not particularly well specified. Creates an object. Does it really need the schema?
|
||||
// or can it fetch the schema itself? Also the schema is not currently a Parse format schema, and it
|
||||
// should be, if we are passing it at all.
|
||||
createObject(className, object, schema) {
|
||||
const mongoObject = transform.parseObjectToMongoObject(schema, className, object);
|
||||
return this.adaptiveCollection(className)
|
||||
.then(collection => collection.insertOne(mongoObject));
|
||||
}
|
||||
|
||||
get transform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ import _ from 'lodash';
|
||||
var mongodb = require('mongodb');
|
||||
var Parse = require('parse/node').Parse;
|
||||
|
||||
// TODO: Turn this into a helper library for the database adapter.
|
||||
|
||||
// Transforms a key-value pair from REST API form to Mongo form.
|
||||
// This is the main entry point for converting anything from REST form
|
||||
// to Mongo form; no conversion should happen that doesn't pass
|
||||
@@ -203,7 +201,7 @@ function transformWhere(schema, className, restWhere, options = {validate: true}
|
||||
// Main exposed method to create new objects.
|
||||
// restCreate is the "create" clause in REST API form.
|
||||
// Returns the mongo form of the object.
|
||||
function transformCreate(schema, className, restCreate) {
|
||||
function parseObjectToMongoObject(schema, className, restCreate) {
|
||||
if (className == '_User') {
|
||||
restCreate = transformAuthData(restCreate);
|
||||
}
|
||||
@@ -940,7 +938,7 @@ var FileCoder = {
|
||||
|
||||
module.exports = {
|
||||
transformKey,
|
||||
transformCreate,
|
||||
parseObjectToMongoObject,
|
||||
transformUpdate,
|
||||
transformWhere,
|
||||
transformSelect,
|
||||
|
||||
@@ -344,11 +344,7 @@ DatabaseController.prototype.create = function(className, object, options = {})
|
||||
return Promise.resolve();
|
||||
})
|
||||
.then(() => this.handleRelationUpdates(className, null, object))
|
||||
.then(() => this.adapter.adaptiveCollection(className))
|
||||
.then(coll => {
|
||||
var mongoObject = this.transform.transformCreate(schema, className, object);
|
||||
return coll.insertOne(mongoObject);
|
||||
})
|
||||
.then(() => this.adapter.createObject(className, object, schema))
|
||||
.then(result => {
|
||||
return sanitizeDatabaseResult(originalObject, result.ops[0]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user