Skip to content

Commit 61b62e4

Browse files
committed
Rename Schema => SchemaController (#1542)
* Rename Schema to SchemaController * Rename Schema => SchemaController * Move to controllers folder * Move SchemasController to Controllers folder * remove ./..
1 parent 0708af1 commit 61b62e4

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

spec/Schema.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var Config = require('../src/Config');
4-
var Schema = require('../src/Schema');
4+
var SchemaController = require('../src/Controllers/SchemaController');
55
var dd = require('deep-diff');
66

77
var config = new Config('test');
@@ -19,7 +19,7 @@ var hasAllPODobject = () => {
1919
return obj;
2020
};
2121

22-
describe('Schema', () => {
22+
describe('SchemaController', () => {
2323
it('can validate one object', (done) => {
2424
config.database.loadSchema().then((schema) => {
2525
return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false});
@@ -751,7 +751,7 @@ describe('Schema', () => {
751751
});
752752

753753
it('can merge schemas', done => {
754-
expect(Schema.buildMergedSchemaObject({
754+
expect(SchemaController.buildMergedSchemaObject({
755755
_id: 'SomeClass',
756756
someType: { type: 'Number' }
757757
}, {
@@ -764,7 +764,7 @@ describe('Schema', () => {
764764
});
765765

766766
it('can merge deletions', done => {
767-
expect(Schema.buildMergedSchemaObject({
767+
expect(SchemaController.buildMergedSchemaObject({
768768
_id: 'SomeClass',
769769
someType: { type: 'Number' },
770770
outDatedType: { type: 'String' },
@@ -779,7 +779,7 @@ describe('Schema', () => {
779779
});
780780

781781
it('ignore default field when merge with system class', done => {
782-
expect(Schema.buildMergedSchemaObject({
782+
expect(SchemaController.buildMergedSchemaObject({
783783
_id: '_User',
784784
username: { type: 'String' },
785785
password: { type: 'String' },

src/Adapters/Storage/Mongo/MongoSchemaCollection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class MongoSchemaCollection {
191191

192192
// TODO: don't spend an extra query on finding the schema if the type we are trying to add isn't a GeoPoint.
193193
addFieldIfNotExists(className: string, fieldName: string, type: string) {
194-
return this.findSchema(className)
194+
return this._fechOneSchemaFrom_SCHEMA(className)
195195
.then(schema => {
196196
// The schema exists. Check for existing GeoPoints.
197197
if (type.type === 'GeoPoint') {

src/Controllers/DatabaseController.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import intersect from 'intersect';
66
var mongodb = require('mongodb');
77
var Parse = require('parse/node').Parse;
88

9-
var Schema = require('./../Schema');
9+
var SchemaController = require('../Controllers/SchemaController');
1010
const deepcopy = require('deepcopy');
1111

1212
function DatabaseController(adapter, { skipValidation } = {}) {
@@ -48,7 +48,7 @@ DatabaseController.prototype.validateClassName = function(className) {
4848
if (this.skipValidation) {
4949
return Promise.resolve();
5050
}
51-
if (!Schema.classNameIsValid(className)) {
51+
if (!SchemaController.classNameIsValid(className)) {
5252
const error = new Parse.Error(Parse.Error.INVALID_CLASS_NAME, 'invalid className: ' + className);
5353
return Promise.reject(error);
5454
}
@@ -63,7 +63,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) {
6363
if (!this.schemaPromise) {
6464
this.schemaPromise = this.schemaCollection().then(collection => {
6565
delete this.schemaPromise;
66-
return Schema.load(collection, this.adapter);
66+
return SchemaController.load(collection, this.adapter);
6767
});
6868
return this.schemaPromise;
6969
}
@@ -74,7 +74,7 @@ DatabaseController.prototype.loadSchema = function(acceptor = () => true) {
7474
}
7575
this.schemaPromise = this.schemaCollection().then(collection => {
7676
delete this.schemaPromise;
77-
return Schema.load(collection, this.adapter);
77+
return SchemaController.load(collection, this.adapter);
7878
});
7979
return this.schemaPromise;
8080
});

src/Schema.js renamed to src/Controllers/SchemaController.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// TODO: hide all schema logic inside the database adapter.
1616

1717
const Parse = require('parse/node').Parse;
18-
import MongoSchemaCollection from './Adapters/Storage/Mongo/MongoSchemaCollection';
19-
import _ from 'lodash';
18+
import _ from 'lodash';
2019

2120
const defaultColumns = Object.freeze({
2221
// Contain the default columns for every parse object type (except _Join collection)

src/RestQuery.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// An object that encapsulates everything we need to run a 'find'
22
// operation, encoded in the REST API format.
33

4-
var Schema = require('./Schema');
4+
var SchemaController = require('./Controllers/SchemaController');
55
var Parse = require('parse/node').Parse;
66

77
import { default as FilesController } from './Controllers/FilesController';
@@ -171,7 +171,7 @@ RestQuery.prototype.redirectClassNameForKey = function() {
171171

172172
// Validates this operation against the allowClientClassCreation config.
173173
RestQuery.prototype.validateClientClassCreation = function() {
174-
let sysClass = Schema.systemClasses;
174+
let sysClass = SchemaController.systemClasses;
175175
if (this.config.allowClientClassCreation === false && !this.auth.isMaster
176176
&& sysClass.indexOf(this.className) === -1) {
177177
return this.config.database.collectionExists(this.className).then((hasClass) => {

src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This could be either a "create" or an "update".
44

55
import cache from './cache';
6-
var Schema = require('./Schema');
6+
var SchemaController = require('./Controllers/SchemaController');
77
var deepcopy = require('deepcopy');
88

99
var Auth = require('./Auth');
@@ -111,7 +111,7 @@ RestWrite.prototype.getUserAndRoleACL = function() {
111111

112112
// Validates this operation against the allowClientClassCreation config.
113113
RestWrite.prototype.validateClientClassCreation = function() {
114-
let sysClass = Schema.systemClasses;
114+
let sysClass = SchemaController.systemClasses;
115115
if (this.config.allowClientClassCreation === false && !this.auth.isMaster
116116
&& sysClass.indexOf(this.className) === -1) {
117117
return this.config.database.collectionExists(this.className).then((hasClass) => {

src/Routers/SchemasRouter.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var express = require('express'),
44
Parse = require('parse/node').Parse,
5-
Schema = require('../Schema');
5+
SchemaController = require('../Controllers/SchemaController');
66

77
import PromiseRouter from '../PromiseRouter';
88
import * as middleware from "../middlewares";
@@ -76,8 +76,8 @@ var removeJoinTables = (database, mongoSchema) => {
7676
};
7777

7878
function deleteSchema(req) {
79-
if (!Schema.classNameIsValid(req.params.className)) {
80-
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, Schema.invalidClassNameMessage(req.params.className));
79+
if (!SchemaController.classNameIsValid(req.params.className)) {
80+
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, SchemaController.invalidClassNameMessage(req.params.className));
8181
}
8282

8383
return req.config.database.deleteSchema(req.params.className)

0 commit comments

Comments
 (0)