Skip to content

Commit 1b5d53b

Browse files
committed
Renames Unsafe to WithoutValidation
1 parent cd7e09e commit 1b5d53b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
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)) {
@@ -180,11 +180,11 @@ DatabaseController.prototype.update = function(className, query, update, options
180180
.then(() => this.handleRelationUpdates(className, query.objectId, update))
181181
.then(() => adaptiveCollection(this, className))
182182
.then(collection => {
183-
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
183+
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
184184
if (options.acl) {
185185
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
186186
}
187-
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.unsafe});
187+
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
188188
if (options.many) {
189189
return collection.updateMany(mongoWhere, mongoUpdate);
190190
}else if (options.upsert) {
@@ -198,7 +198,7 @@ DatabaseController.prototype.update = function(className, query, update, options
198198
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
199199
'Object not found.'));
200200
}
201-
if (this.unsafe) {
201+
if (this.skipValidation) {
202202
return Promise.resolve(result);
203203
}
204204
return sanitizeDatabaseResult(originalUpdate, result);
@@ -320,7 +320,7 @@ DatabaseController.prototype.destroy = function(className, query, options = {})
320320
})
321321
.then(() => adaptiveCollection(this, className))
322322
.then(collection => {
323-
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.unsafe});
323+
let mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
324324
if (options.acl) {
325325
mongoWhere = this.transform.addWriteACL(mongoWhere, options.acl);
326326
}

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/Schema.js

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

511511
// for non-relations, remove all the data.
512512
// This is necessary to ensure that the data is still gone if they add the same field.
513-
let unsafeDB = database.Unsafe();
514-
let transformFieldName = unsafeDB.transform.transformKey(this, className, fieldName);
515-
return unsafeDB.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
513+
let db = database.WithoutValidation();
514+
let transformFieldName = db.transform.transformKey(this, className, fieldName);
515+
return db.update(className, {}, {[transformFieldName]: {__op: 'Delete'}}, {many: true});
516516
})
517517
// Save the _SCHEMA object
518518
.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)