Skip to content

Rename Schema => SchemaController #1542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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});
Expand Down Expand Up @@ -751,7 +751,7 @@ describe('Schema', () => {
});

it('can merge schemas', done => {
expect(Schema.buildMergedSchemaObject({
expect(SchemaController.buildMergedSchemaObject({
_id: 'SomeClass',
someType: { type: 'Number' }
}, {
Expand All @@ -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' },
Expand All @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoSchemaCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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;
});
Expand Down
3 changes: 1 addition & 2 deletions src/Schema.js → src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const defaultColumns = Object.freeze({
// Contain the default columns for every parse object type (except _Join collection)
Expand Down
4 changes: 2 additions & 2 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/Routers/SchemasRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down