Skip to content

Commit f4b1f7b

Browse files
committed
Remove all dependencies on schemaController
1 parent d944255 commit f4b1f7b

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

spec/MongoTransform.spec.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,19 @@ describe('mongoObjectToParseObject', () => {
153153

154154
it('file', (done) => {
155155
var input = {picture: 'pic.jpg'};
156-
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
156+
var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
157+
fields: { picture: { type: 'File' }},
158+
});
157159
expect(typeof output.picture).toEqual('object');
158160
expect(output.picture).toEqual({__type: 'File', name: 'pic.jpg'});
159161
done();
160162
});
161163

162164
it('geopoint', (done) => {
163165
var input = {location: [180, -180]};
164-
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
166+
var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
167+
fields: { location: { type: 'GeoPoint' }},
168+
});
165169
expect(typeof output.location).toEqual('object');
166170
expect(output.location).toEqual(
167171
{__type: 'GeoPoint', longitude: 180, latitude: -180}
@@ -171,7 +175,9 @@ describe('mongoObjectToParseObject', () => {
171175

172176
it('nested array', (done) => {
173177
var input = {arr: [{_testKey: 'testValue' }]};
174-
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
178+
var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
179+
fields: { arr: { type: 'Array' } },
180+
});
175181
expect(Array.isArray(output.arr)).toEqual(true);
176182
expect(output.arr).toEqual([{ _testKey: 'testValue'}]);
177183
done();
@@ -189,7 +195,9 @@ describe('mongoObjectToParseObject', () => {
189195
},
190196
regularKey: "some data",
191197
}]}
192-
let output = transform.mongoObjectToParseObject(dummySchema, null, input);
198+
let output = transform.mongoObjectToParseObject(dummySchema, null, input, {
199+
fields: { array: { type: 'Array' }},
200+
});
193201
expect(dd(output, input)).toEqual(undefined);
194202
done();
195203
});
@@ -271,7 +279,12 @@ describe('transform schema key changes', () => {
271279
long: mongodb.Long.fromNumber(Number.MAX_SAFE_INTEGER),
272280
double: new mongodb.Double(Number.MAX_VALUE)
273281
}
274-
var output = transform.mongoObjectToParseObject(dummySchema, null, input);
282+
var output = transform.mongoObjectToParseObject(dummySchema, null, input, {
283+
fields: {
284+
long: { type: 'Number' },
285+
double: { type: 'Number' },
286+
},
287+
});
275288
expect(output.long).toBe(Number.MAX_SAFE_INTEGER);
276289
expect(output.double).toBe(Number.MAX_VALUE);
277290
done();

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,6 @@ const mongoObjectToParseObject = (schemaController, className, mongoObject, sche
830830

831831
if (key.indexOf('_p_') == 0) {
832832
var newKey = key.substring(3);
833-
var expected;
834-
if (schemaController && schemaController.getExpectedType) {
835-
expected = schemaController.getExpectedType(className, newKey);
836-
}
837833
if (!schema.fields[newKey]) {
838834
log.info('transform.js', 'Found a pointer column not in the schema, dropping it.', className, newKey);
839835
break;
@@ -858,13 +854,12 @@ const mongoObjectToParseObject = (schemaController, className, mongoObject, sche
858854
} else if (key[0] == '_' && key != '__type') {
859855
throw ('bad key in untransform: ' + key);
860856
} else {
861-
var expectedType = schemaController.getExpectedType(className, key);
862857
var value = mongoObject[key];
863-
if (expectedType && expectedType.type === 'File' && FileCoder.isValidDatabaseObject(value)) {
858+
if (schema.fields[key] && schema.fields[key].type === 'File' && FileCoder.isValidDatabaseObject(value)) {
864859
restObject[key] = FileCoder.databaseToJSON(value);
865860
break;
866861
}
867-
if (expectedType && expectedType.type === 'GeoPoint' && GeoPointCoder.isValidDatabaseObject(value)) {
862+
if (schema.fields[key] && schema.fields[key].type === 'GeoPoint' && GeoPointCoder.isValidDatabaseObject(value)) {
868863
restObject[key] = GeoPointCoder.databaseToJSON(value);
869864
break;
870865
}

0 commit comments

Comments
 (0)