Rename Schema => SchemaController (#1542)

* Rename Schema to SchemaController

* Rename Schema => SchemaController

* Move to controllers folder

* Move SchemasController to Controllers folder

* remove ./..
This commit is contained in:
Drew
2016-04-18 18:59:57 -07:00
parent 0708af17d7
commit 61b62e4e9f
7 changed files with 18 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var Config = require('../src/Config'); var Config = require('../src/Config');
var Schema = require('../src/Schema'); var SchemaController = require('../src/Controllers/SchemaController');
var dd = require('deep-diff'); var dd = require('deep-diff');
var config = new Config('test'); var config = new Config('test');
@@ -19,7 +19,7 @@ var hasAllPODobject = () => {
return obj; return obj;
}; };
describe('Schema', () => { describe('SchemaController', () => {
it('can validate one object', (done) => { it('can validate one object', (done) => {
config.database.loadSchema().then((schema) => { config.database.loadSchema().then((schema) => {
return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false}); return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false});
@@ -751,7 +751,7 @@ describe('Schema', () => {
}); });
it('can merge schemas', done => { it('can merge schemas', done => {
expect(Schema.buildMergedSchemaObject({ expect(SchemaController.buildMergedSchemaObject({
_id: 'SomeClass', _id: 'SomeClass',
someType: { type: 'Number' } someType: { type: 'Number' }
}, { }, {
@@ -764,7 +764,7 @@ describe('Schema', () => {
}); });
it('can merge deletions', done => { it('can merge deletions', done => {
expect(Schema.buildMergedSchemaObject({ expect(SchemaController.buildMergedSchemaObject({
_id: 'SomeClass', _id: 'SomeClass',
someType: { type: 'Number' }, someType: { type: 'Number' },
outDatedType: { type: 'String' }, outDatedType: { type: 'String' },
@@ -779,7 +779,7 @@ describe('Schema', () => {
}); });
it('ignore default field when merge with system class', done => { it('ignore default field when merge with system class', done => {
expect(Schema.buildMergedSchemaObject({ expect(SchemaController.buildMergedSchemaObject({
_id: '_User', _id: '_User',
username: { type: 'String' }, username: { type: 'String' },
password: { type: 'String' }, password: { type: 'String' },

View File

@@ -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. // 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) { addFieldIfNotExists(className: string, fieldName: string, type: string) {
return this.findSchema(className) return this._fechOneSchemaFrom_SCHEMA(className)
.then(schema => { .then(schema => {
// The schema exists. Check for existing GeoPoints. // The schema exists. Check for existing GeoPoints.
if (type.type === 'GeoPoint') { if (type.type === 'GeoPoint') {

View File

@@ -6,7 +6,7 @@ import intersect from 'intersect';
var mongodb = require('mongodb'); var mongodb = require('mongodb');
var Parse = require('parse/node').Parse; var Parse = require('parse/node').Parse;
var Schema = require('./../Schema'); var SchemaController = require('../Controllers/SchemaController');
const deepcopy = require('deepcopy'); const deepcopy = require('deepcopy');
function DatabaseController(adapter, { skipValidation } = {}) { function DatabaseController(adapter, { skipValidation } = {}) {
@@ -48,7 +48,7 @@ DatabaseController.prototype.validateClassName = function(className) {
if (this.skipValidation) { if (this.skipValidation) {
return Promise.resolve(); return Promise.resolve();
} }
if (!Schema.classNameIsValid(className)) { if (!SchemaController.classNameIsValid(className)) {
const error = new Parse.Error(Parse.Error.INVALID_CLASS_NAME, 'invalid className: ' + className); const error = new Parse.Error(Parse.Error.INVALID_CLASS_NAME, 'invalid className: ' + className);
return Promise.reject(error); return Promise.reject(error);
} }
@@ -63,7 +63,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) {
if (!this.schemaPromise) { if (!this.schemaPromise) {
this.schemaPromise = this.schemaCollection().then(collection => { this.schemaPromise = this.schemaCollection().then(collection => {
delete this.schemaPromise; delete this.schemaPromise;
return Schema.load(collection, this.adapter); return SchemaController.load(collection, this.adapter);
}); });
return this.schemaPromise; return this.schemaPromise;
} }
@@ -74,7 +74,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) {
} }
this.schemaPromise = this.schemaCollection().then(collection => { this.schemaPromise = this.schemaCollection().then(collection => {
delete this.schemaPromise; delete this.schemaPromise;
return Schema.load(collection, this.adapter); return SchemaController.load(collection, this.adapter);
}); });
return this.schemaPromise; return this.schemaPromise;
}); });

View File

@@ -15,8 +15,7 @@
// TODO: hide all schema logic inside the database adapter. // TODO: hide all schema logic inside the database adapter.
const Parse = require('parse/node').Parse; const Parse = require('parse/node').Parse;
import MongoSchemaCollection from './Adapters/Storage/Mongo/MongoSchemaCollection'; import _ from 'lodash';
import _ from 'lodash';
const defaultColumns = Object.freeze({ const defaultColumns = Object.freeze({
// Contain the default columns for every parse object type (except _Join collection) // Contain the default columns for every parse object type (except _Join collection)

View File

@@ -1,7 +1,7 @@
// An object that encapsulates everything we need to run a 'find' // An object that encapsulates everything we need to run a 'find'
// operation, encoded in the REST API format. // operation, encoded in the REST API format.
var Schema = require('./Schema'); var SchemaController = require('./Controllers/SchemaController');
var Parse = require('parse/node').Parse; var Parse = require('parse/node').Parse;
import { default as FilesController } from './Controllers/FilesController'; import { default as FilesController } from './Controllers/FilesController';
@@ -171,7 +171,7 @@ RestQuery.prototype.redirectClassNameForKey = function() {
// Validates this operation against the allowClientClassCreation config. // Validates this operation against the allowClientClassCreation config.
RestQuery.prototype.validateClientClassCreation = function() { RestQuery.prototype.validateClientClassCreation = function() {
let sysClass = Schema.systemClasses; let sysClass = SchemaController.systemClasses;
if (this.config.allowClientClassCreation === false && !this.auth.isMaster if (this.config.allowClientClassCreation === false && !this.auth.isMaster
&& sysClass.indexOf(this.className) === -1) { && sysClass.indexOf(this.className) === -1) {
return this.config.database.collectionExists(this.className).then((hasClass) => { return this.config.database.collectionExists(this.className).then((hasClass) => {

View File

@@ -3,7 +3,7 @@
// This could be either a "create" or an "update". // This could be either a "create" or an "update".
import cache from './cache'; import cache from './cache';
var Schema = require('./Schema'); var SchemaController = require('./Controllers/SchemaController');
var deepcopy = require('deepcopy'); var deepcopy = require('deepcopy');
var Auth = require('./Auth'); var Auth = require('./Auth');
@@ -111,7 +111,7 @@ RestWrite.prototype.getUserAndRoleACL = function() {
// Validates this operation against the allowClientClassCreation config. // Validates this operation against the allowClientClassCreation config.
RestWrite.prototype.validateClientClassCreation = function() { RestWrite.prototype.validateClientClassCreation = function() {
let sysClass = Schema.systemClasses; let sysClass = SchemaController.systemClasses;
if (this.config.allowClientClassCreation === false && !this.auth.isMaster if (this.config.allowClientClassCreation === false && !this.auth.isMaster
&& sysClass.indexOf(this.className) === -1) { && sysClass.indexOf(this.className) === -1) {
return this.config.database.collectionExists(this.className).then((hasClass) => { return this.config.database.collectionExists(this.className).then((hasClass) => {

View File

@@ -2,7 +2,7 @@
var express = require('express'), var express = require('express'),
Parse = require('parse/node').Parse, Parse = require('parse/node').Parse,
Schema = require('../Schema'); SchemaController = require('../Controllers/SchemaController');
import PromiseRouter from '../PromiseRouter'; import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares"; import * as middleware from "../middlewares";
@@ -76,8 +76,8 @@ var removeJoinTables = (database, mongoSchema) => {
}; };
function deleteSchema(req) { function deleteSchema(req) {
if (!Schema.classNameIsValid(req.params.className)) { if (!SchemaController.classNameIsValid(req.params.className)) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(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) return req.config.database.deleteSchema(req.params.className)