Skip to content

Commit a568a98

Browse files
committed
Renames Unsafe to WithoutValidation
1 parent 43805f5 commit a568a98

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

src/Controllers/DatabaseController.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const deepcopy = require('deepcopy');
1111

1212
// options can contain:
1313
// collectionPrefix: the string to put in front of every collection name.
14-
function DatabaseController(adapter, { collectionPrefix, unsafe } = {}) {
14+
function DatabaseController(adapter, { collectionPrefix, skipValidation } = {}) {
1515
this.adapter = adapter;
1616

1717
this.collectionPrefix = collectionPrefix;
@@ -20,7 +20,7 @@ function DatabaseController(adapter, { collectionPrefix, unsafe } = {}) {
2020
// one request that uses different schemas for different parts of
2121
// it. Instead, use loadSchema to get a schema.
2222
this.schemaPromise = null;
23-
this.unsafe = !!unsafe;
23+
this.skipValidation = !!skipValidation;
2424
this.connect();
2525

2626
Object.defineProperty(this, 'transform', {
@@ -30,8 +30,8 @@ function DatabaseController(adapter, { collectionPrefix, unsafe } = {}) {
3030
})
3131
}
3232

33-
DatabaseController.prototype.Unsafe = function() {
34-
return new DatabaseController(this.adapter, {collectionPrefix: this.collectionPrefix, unsafe: true});
33+
DatabaseController.prototype.WithoutValidation = function() {
34+
return new DatabaseController(this.adapter, {collectionPrefix: this.collectionPrefix, skipValidation: true});
3535
}
3636

3737
// Connects to the database. Returns a promise that resolves when the
@@ -61,7 +61,7 @@ function returnsTrue() {
6161
}
6262

6363
DatabaseController.prototype.validateClassName = function(className) {
64-
if (this.unsafe) {
64+
if (this.skipValidation) {
6565
return Promise.resolve();
6666
}
6767
if (!Schema.classNameIsValid(className)) {
@@ -179,11 +179,11 @@ DatabaseController.prototype.update = function(className, query, update, options
179179
.then(() => this.handleRelationUpdates(className, query.objectId, update))
180180
.then(() => adaptiveCollection(this, className))
181181
.then(collection => {
182-
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
182+
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
183183
if (options.acl) {
184184
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
185185
}
186-
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.unsafe});
186+
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
187187
if (options.many) {
188188
return collection.updateMany(mongoWhere, mongoUpdate);
189189
}else if (options.upsert) {
@@ -197,7 +197,7 @@ DatabaseController.prototype.update = function(className, query, update, options
197197
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
198198
'Object not found.'));
199199
}
200-
if (this.unsafe) {
200+
if (this.skipValidation) {
201201
return Promise.resolve(result);
202202
}
203203
return sanitizeDatabaseResult(originalUpdate, result);
@@ -319,7 +319,7 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
319319
})
320320
.then(() => adaptiveCollection(this, className))
321321
.then(collection => {
322-
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
322+
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
323323
if (options.acl) {
324324
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
325325
}

src/Controllers/HooksController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class HooksController {
1515
constructor(applicationId:string, collectionPrefix:string = '') {
1616
this._applicationId = applicationId;
1717
this._collectionPrefix = collectionPrefix;
18-
this.database = DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix).Unsafe();
18+
this.database = DatabaseAdapter.getDatabaseConnection(this._applicationId, this._collectionPrefix).WithoutValidation();
1919
}
2020

2121
load() {

src/Controllers/UserController.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class UserController extends AdaptableController {
4545
// TODO: Better error here.
4646
return Promise.reject();
4747
}
48-
let database = this.config.database.Unsafe();
48+
let database = this.config.database.WithoutValidation();
4949
return database.update('_User', {
5050
username: username,
5151
_email_verify_token: token
@@ -58,7 +58,7 @@ export class UserController extends AdaptableController {
5858
}
5959

6060
checkResetTokenValidity(username, token) {
61-
let database = this.config.database.Unsafe();
61+
let database = this.config.database.WithoutValidation();
6262
return database.find('_User', {
6363
username: username,
6464
_perishable_token: token
@@ -115,7 +115,7 @@ export class UserController extends AdaptableController {
115115

116116
setPasswordResetToken(email) {
117117
let token = randomString(25);
118-
let database = this.config.database.Unsafe();
118+
let database = this.config.database.WithoutValidation();
119119
return database.update('_User', {email: email}, {_perishable_token: token});
120120
}
121121

@@ -153,7 +153,7 @@ export class UserController extends AdaptableController {
153153
return updateUserPassword(user.objectId, password, this.config);
154154
}).then(() => {
155155
// clear reset password token
156-
return this.config.database.Unsafe().update('_User', { username }, {
156+
return this.config.database.WithoutValidation().update('_User', { username }, {
157157
_perishable_token: {__op: 'Delete'}
158158
});
159159
});

src/Routers/GlobalConfigRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as middleware from "../middlewares";
55

66
export class GlobalConfigRouter extends PromiseRouter {
77
getGlobalConfig(req) {
8-
let database = req.config.database.Unsafe();
8+
let database = req.config.database.WithoutValidation();
99
return database.find('_GlobalConfig', { '_id': 1 }, { limit: 1 }).then((results) => {
1010
if (results.length != 1) {
1111
// If there is no config in the database - return empty config.
@@ -23,7 +23,7 @@ export class GlobalConfigRouter extends PromiseRouter {
2323
acc[`params.${key}`] = params[key];
2424
return acc;
2525
}, {});
26-
let database = req.config.database.Unsafe();
26+
let database = req.config.database.WithoutValidation();
2727
return database.update('_GlobalConfig', {_id: 1}, update, {upsert: true}).then(() => {
2828
return Promise.resolve({ response: { result: true } });
2929
});

src/Schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ class Schema {
538538

539539
// for non-relations, remove all the data.
540540
// This is necessary to ensure that the data is still gone if they add the same field.
541-
let unsafeDB = database.Unsafe();
542-
let transformFieldName = unsafeDB.transform.transformKey(this, className, fieldName);
543-
return unsafeDB.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
541+
let db = database.WithoutValidation();
542+
let transformFieldName = db.transform.transformKey(this, className, fieldName);
543+
return db.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
544544
})
545545
// Save the _SCHEMA object
546546
.then(() => this._collection.updateSchema(className, { $unset: { [fieldName]: null } }));

src/pushStatusHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function pushStatusHandler(config) {
1919
let initialPromise;
2020
let pushStatus;
2121
let objectId = newObjectId();
22-
let database = config.database.Unsafe();
22+
let database = config.database.WithoutValidation();
2323

2424
let setInitial = function(body = {}, where, options = {source: 'rest'}) {
2525
let now = new Date();

0 commit comments

Comments
 (0)