diff --git a/spec/Schema.spec.js b/spec/Schema.spec.js index 7e87a72e..5e341845 100644 --- a/spec/Schema.spec.js +++ b/spec/Schema.spec.js @@ -1,7 +1,7 @@ 'use strict'; var Config = require('../src/Config'); -var Schema = require('../src/Schema'); +var SchemaController = require('../src/Controllers/SchemaController'); var dd = require('deep-diff'); var config = new Config('test'); @@ -19,7 +19,7 @@ var hasAllPODobject = () => { return obj; }; -describe('Schema', () => { +describe('SchemaController', () => { it('can validate one object', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false}); @@ -751,7 +751,7 @@ describe('Schema', () => { }); it('can merge schemas', done => { - expect(Schema.buildMergedSchemaObject({ + expect(SchemaController.buildMergedSchemaObject({ _id: 'SomeClass', someType: { type: 'Number' } }, { @@ -764,7 +764,7 @@ describe('Schema', () => { }); it('can merge deletions', done => { - expect(Schema.buildMergedSchemaObject({ + expect(SchemaController.buildMergedSchemaObject({ _id: 'SomeClass', someType: { type: 'Number' }, outDatedType: { type: 'String' }, @@ -779,7 +779,7 @@ describe('Schema', () => { }); it('ignore default field when merge with system class', done => { - expect(Schema.buildMergedSchemaObject({ + expect(SchemaController.buildMergedSchemaObject({ _id: '_User', username: { type: 'String' }, password: { type: 'String' }, diff --git a/src/Adapters/Storage/Mongo/MongoSchemaCollection.js b/src/Adapters/Storage/Mongo/MongoSchemaCollection.js index dada3eb7..a51edc2a 100644 --- a/src/Adapters/Storage/Mongo/MongoSchemaCollection.js +++ b/src/Adapters/Storage/Mongo/MongoSchemaCollection.js @@ -191,7 +191,7 @@ class MongoSchemaCollection { // TODO: don't spend an extra query on finding the schema if the type we are trying to add isn't a GeoPoint. addFieldIfNotExists(className: string, fieldName: string, type: string) { - return this.findSchema(className) + return this._fechOneSchemaFrom_SCHEMA(className) .then(schema => { // The schema exists. Check for existing GeoPoints. if (type.type === 'GeoPoint') { diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index 69929433..bc72c3f6 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -6,7 +6,7 @@ import intersect from 'intersect'; var mongodb = require('mongodb'); var Parse = require('parse/node').Parse; -var Schema = require('./../Schema'); +var SchemaController = require('../Controllers/SchemaController'); const deepcopy = require('deepcopy'); function DatabaseController(adapter, { skipValidation } = {}) { @@ -48,7 +48,7 @@ DatabaseController.prototype.validateClassName = function(className) { if (this.skipValidation) { return Promise.resolve(); } - if (!Schema.classNameIsValid(className)) { + if (!SchemaController.classNameIsValid(className)) { const error = new Parse.Error(Parse.Error.INVALID_CLASS_NAME, 'invalid className: ' + className); return Promise.reject(error); } @@ -63,7 +63,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) { if (!this.schemaPromise) { this.schemaPromise = this.schemaCollection().then(collection => { delete this.schemaPromise; - return Schema.load(collection, this.adapter); + return SchemaController.load(collection, this.adapter); }); return this.schemaPromise; } @@ -74,7 +74,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) { } this.schemaPromise = this.schemaCollection().then(collection => { delete this.schemaPromise; - return Schema.load(collection, this.adapter); + return SchemaController.load(collection, this.adapter); }); return this.schemaPromise; }); diff --git a/src/Schema.js b/src/Controllers/SchemaController.js similarity index 99% rename from src/Schema.js rename to src/Controllers/SchemaController.js index b8cd3478..3737db8b 100644 --- a/src/Schema.js +++ b/src/Controllers/SchemaController.js @@ -15,8 +15,7 @@ // TODO: hide all schema logic inside the database adapter. const Parse = require('parse/node').Parse; -import MongoSchemaCollection from './Adapters/Storage/Mongo/MongoSchemaCollection'; -import _ from 'lodash'; +import _ from 'lodash'; const defaultColumns = Object.freeze({ // Contain the default columns for every parse object type (except _Join collection) diff --git a/src/RestQuery.js b/src/RestQuery.js index 7f707fc4..34324f5e 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -1,7 +1,7 @@ // An object that encapsulates everything we need to run a 'find' // operation, encoded in the REST API format. -var Schema = require('./Schema'); +var SchemaController = require('./Controllers/SchemaController'); var Parse = require('parse/node').Parse; import { default as FilesController } from './Controllers/FilesController'; @@ -171,7 +171,7 @@ RestQuery.prototype.redirectClassNameForKey = function() { // Validates this operation against the allowClientClassCreation config. RestQuery.prototype.validateClientClassCreation = function() { - let sysClass = Schema.systemClasses; + let sysClass = SchemaController.systemClasses; if (this.config.allowClientClassCreation === false && !this.auth.isMaster && sysClass.indexOf(this.className) === -1) { return this.config.database.collectionExists(this.className).then((hasClass) => { diff --git a/src/RestWrite.js b/src/RestWrite.js index 3e5fa337..0b88b71a 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -3,7 +3,7 @@ // This could be either a "create" or an "update". import cache from './cache'; -var Schema = require('./Schema'); +var SchemaController = require('./Controllers/SchemaController'); var deepcopy = require('deepcopy'); var Auth = require('./Auth'); @@ -111,7 +111,7 @@ RestWrite.prototype.getUserAndRoleACL = function() { // Validates this operation against the allowClientClassCreation config. RestWrite.prototype.validateClientClassCreation = function() { - let sysClass = Schema.systemClasses; + let sysClass = SchemaController.systemClasses; if (this.config.allowClientClassCreation === false && !this.auth.isMaster && sysClass.indexOf(this.className) === -1) { return this.config.database.collectionExists(this.className).then((hasClass) => { diff --git a/src/Routers/SchemasRouter.js b/src/Routers/SchemasRouter.js index 36fd4360..e7b8cfcd 100644 --- a/src/Routers/SchemasRouter.js +++ b/src/Routers/SchemasRouter.js @@ -2,7 +2,7 @@ var express = require('express'), Parse = require('parse/node').Parse, - Schema = require('../Schema'); + SchemaController = require('../Controllers/SchemaController'); import PromiseRouter from '../PromiseRouter'; import * as middleware from "../middlewares"; @@ -76,8 +76,8 @@ var removeJoinTables = (database, mongoSchema) => { }; function deleteSchema(req) { - if (!Schema.classNameIsValid(req.params.className)) { - throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className)); + if (!SchemaController.classNameIsValid(req.params.className)) { + throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, SchemaController.invalidClassNameMessage(req.params.className)); } return req.config.database.deleteSchema(req.params.className)