Skip to content

Commit 2ec2bb5

Browse files
authored
Removes dependency upon babel-polyfills (#2731)
* Removes runtime dependency babel-polyfill (#2692) * Removes runtime dependency babel-polyfill * removes references to polyfilled array includes * Better support for polyfilling * Removes unnecessary log * Adds killswitch if tests are polyfilled * Reverts usage of includes on strings
1 parent 3ba6e61 commit 2ec2bb5

File tree

9 files changed

+36
-26
lines changed

9 files changed

+36
-26
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
],
1919
"license": "BSD-3-Clause",
2020
"dependencies": {
21-
"babel-polyfill": "6.13.0",
2221
"bcryptjs": "2.3.0",
2322
"body-parser": "1.15.2",
2423
"commander": "2.9.0",
@@ -66,10 +65,10 @@
6665
"scripts": {
6766
"dev": "npm run build && node bin/dev",
6867
"build": "babel src/ -d lib/",
69-
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 NODE_ENV=test TESTING=1 babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js",
70-
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 babel-node ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
68+
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 NODE_ENV=test TESTING=1 node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js",
69+
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 node ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
7170
"coverage": "cross-env COVERAGE_OPTION='./node_modules/.bin/istanbul cover' npm test",
72-
"coverage:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 babel-node ./node_modules/babel-istanbul/lib/cli.js cover ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
71+
"coverage:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 node ./node_modules/babel-istanbul/lib/cli.js cover ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
7372
"start": "node ./bin/parse-server",
7473
"prepublish": "npm run build"
7574
},

spec/helper.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ global.on_db = (db, callback, elseCallback) => {
1414
}
1515
}
1616

17+
if (global._babelPolyfill) {
18+
console.error('We should not use polyfilled tests');
19+
process.exit(1);
20+
}
21+
1722
var cache = require('../src/cache').default;
1823
var express = require('express');
1924
var facebook = require('../src/authDataManager/facebook');
@@ -214,7 +219,7 @@ afterEach(function(done) {
214219
} else {
215220
// Other system classes will break Parse.com, so make sure that we don't save anything to _SCHEMA that will
216221
// break it.
217-
return ['_User', '_Installation', '_Role', '_Session', '_Product'].includes(className);
222+
return ['_User', '_Installation', '_Role', '_Session', '_Product'].indexOf(className) >= 0;
218223
}
219224
}});
220225
});
@@ -387,15 +392,15 @@ global.jfail = function(err) {
387392
}
388393

389394
global.it_exclude_dbs = excluded => {
390-
if (excluded.includes(process.env.PARSE_SERVER_TEST_DB)) {
395+
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
391396
return xit;
392397
} else {
393398
return it;
394399
}
395400
}
396401

397402
global.fit_exclude_dbs = excluded => {
398-
if (excluded.includes(process.env.PARSE_SERVER_TEST_DB)) {
403+
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
399404
return xit;
400405
} else {
401406
return fit;

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSc
101101
}
102102

103103
const transformInteriorValue = restValue => {
104-
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
104+
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$')|| key.includes('.'))) {
105105
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
106106
}
107107
// Handle atomic values

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class PostgresStorageAdapter {
445445
relations.push(fieldName)
446446
return;
447447
}
448-
if (['_rperm', '_wperm'].includes(fieldName)) {
448+
if (['_rperm', '_wperm'].indexOf(fieldName) >= 0) {
449449
parseType.contents = { type: 'String' };
450450
}
451451
valuesArray.push(fieldName);
@@ -678,7 +678,7 @@ export class PostgresStorageAdapter {
678678
valuesArray.push(object[fieldName].objectId);
679679
break;
680680
case 'Array':
681-
if (['_rperm', '_wperm'].includes(fieldName)) {
681+
if (['_rperm', '_wperm'].indexOf(fieldName) >= 0) {
682682
valuesArray.push(object[fieldName]);
683683
} else {
684684
valuesArray.push(JSON.stringify(object[fieldName]));
@@ -707,7 +707,7 @@ export class PostgresStorageAdapter {
707707
let initialValues = valuesArray.map((val, index) => {
708708
let termination = '';
709709
let fieldName = columnsArray[index];
710-
if (['_rperm','_wperm'].includes(fieldName)) {
710+
if (['_rperm','_wperm'].indexOf(fieldName) >= 0) {
711711
termination = '::text[]';
712712
} else if (schema.fields[fieldName] && schema.fields[fieldName].type === 'Array') {
713713
termination = '::jsonb';

src/Controllers/DatabaseController.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const transformObjectACL = ({ ACL, ...result }) => {
4444
}
4545

4646
const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];
47+
48+
const isSpecialQueryKey = key => {
49+
return specialQuerykeys.indexOf(key) >= 0;
50+
}
51+
4752
const validateQuery = query => {
4853
if (query.ACL) {
4954
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
@@ -73,7 +78,7 @@ const validateQuery = query => {
7378
}
7479
}
7580
}
76-
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
81+
if (!isSpecialQueryKey(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
7782
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
7883
}
7984
});
@@ -185,6 +190,11 @@ const filterSensitiveData = (isMaster, aclGroup, className, object) => {
185190
// one of the provided strings must provide the caller with
186191
// write permissions.
187192
const specialKeysForUpdate = ['_hashed_password', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];
193+
194+
const isSpecialUpdateKey = key => {
195+
return specialKeysForUpdate.indexOf(key) >= 0;
196+
}
197+
188198
DatabaseController.prototype.update = function(className, query, update, {
189199
acl,
190200
many,
@@ -227,7 +237,7 @@ DatabaseController.prototype.update = function(className, query, update, {
227237
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
228238
}
229239
fieldName = fieldName.split('.')[0];
230-
if (!SchemaController.fieldNameIsValid(fieldName) && !specialKeysForUpdate.includes(fieldName)) {
240+
if (!SchemaController.fieldNameIsValid(fieldName) && !isSpecialUpdateKey(fieldName)) {
231241
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
232242
}
233243
});

src/Controllers/SchemaController.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const validNonRelationOrPointerTypes = [
218218
];
219219
// Returns an error suitable for throwing if the type is invalid
220220
const fieldTypeIsInvalid = ({ type, targetClass }) => {
221-
if (['Pointer', 'Relation'].includes(type)) {
221+
if (['Pointer', 'Relation'].indexOf(type) >= 0) {
222222
if (!targetClass) {
223223
return new Parse.Error(135, `type ${type} needs a class name`);
224224
} else if (typeof targetClass !== 'string') {
@@ -232,7 +232,7 @@ const fieldTypeIsInvalid = ({ type, targetClass }) => {
232232
if (typeof type !== 'string') {
233233
return invalidJsonError;
234234
}
235-
if (!validNonRelationOrPointerTypes.includes(type)) {
235+
if (validNonRelationOrPointerTypes.indexOf(type) < 0) {
236236
return new Parse.Error(Parse.Error.INCORRECT_TYPE, `invalid field type: ${type}`);
237237
}
238238
return undefined;
@@ -520,7 +520,6 @@ export default class SchemaController {
520520
}
521521
})
522522
.catch(error => {
523-
console.error(error);
524523
// The schema still doesn't validate. Give up
525524
throw new Parse.Error(Parse.Error.INVALID_JSON, 'schema class name does not revalidate');
526525
});
@@ -541,7 +540,7 @@ export default class SchemaController {
541540

542541
validateSchemaData(className, fields, classLevelPermissions, existingFieldNames) {
543542
for (let fieldName in fields) {
544-
if (!existingFieldNames.includes(fieldName)) {
543+
if (existingFieldNames.indexOf(fieldName) < 0) {
545544
if (!fieldNameIsValid(fieldName)) {
546545
return {
547546
code: Parse.Error.INVALID_KEY_NAME,

src/LiveQuery/ParseLiveQueryServer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import RequestSchema from './RequestSchema';
88
import { matchesQuery, queryHash } from './QueryTools';
99
import { ParsePubSub } from './ParsePubSub';
1010
import { SessionTokenCache } from './SessionTokenCache';
11+
import _ from 'lodash';
1112

1213
class ParseLiveQueryServer {
1314
clientId: number;
@@ -122,7 +123,7 @@ class ParseLiveQueryServer {
122123
if (!isSubscriptionMatched) {
123124
continue;
124125
}
125-
for (let [clientId, requestIds] of subscription.clientRequestIds.entries()) {
126+
for (let [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
126127
let client = this.clients.get(clientId);
127128
if (typeof client === 'undefined') {
128129
continue;
@@ -165,7 +166,7 @@ class ParseLiveQueryServer {
165166
for (let subscription of classSubscriptions.values()) {
166167
let isOriginalSubscriptionMatched = this._matchesSubscription(originalParseObject, subscription);
167168
let isCurrentSubscriptionMatched = this._matchesSubscription(currentParseObject, subscription);
168-
for (let [clientId, requestIds] of subscription.clientRequestIds.entries()) {
169+
for (let [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
169170
let client = this.clients.get(clientId);
170171
if (typeof client === 'undefined') {
171172
continue;
@@ -280,7 +281,7 @@ class ParseLiveQueryServer {
280281
this.clients.delete(clientId);
281282

282283
// Delete client from subscriptions
283-
for (let [requestId, subscriptionInfo] of client.subscriptionInfos.entries()) {
284+
for (let [requestId, subscriptionInfo] of _.entries(client.subscriptionInfos)) {
284285
let subscription = subscriptionInfo.subscription;
285286
subscription.deleteClientSubscription(clientId, requestId);
286287

src/ParseServer.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ var batch = require('./batch'),
99
path = require('path'),
1010
authDataManager = require('./authDataManager');
1111

12-
if (!global._babelPolyfill) {
13-
require('babel-polyfill');
14-
}
15-
1612
import defaults from './defaults';
1713
import * as logging from './logger';
1814
import AppCache from './cache';

src/Routers/ClassesRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import PromiseRouter from '../PromiseRouter';
33
import rest from '../rest';
4-
4+
import _ from 'lodash';
55
import url from 'url';
66

77
const ALLOWED_GET_QUERY_KEYS = ['keys', 'include'];
@@ -115,7 +115,7 @@ export class ClassesRouter extends PromiseRouter {
115115

116116
static JSONFromQuery(query) {
117117
let json = {};
118-
for (let [key, value] of Object.entries(query)) {
118+
for (let [key, value] of _.entries(query)) {
119119
try {
120120
json[key] = JSON.parse(value);
121121
} catch (e) {

0 commit comments

Comments
 (0)