Skip to content

Removes dependency upon babel-polyfills #2731

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
Sep 24, 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
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
],
"license": "BSD-3-Clause",
"dependencies": {
"babel-polyfill": "6.13.0",
"bcryptjs": "2.3.0",
"body-parser": "1.15.2",
"commander": "2.9.0",
Expand Down Expand Up @@ -66,10 +65,10 @@
"scripts": {
"dev": "npm run build && node bin/dev",
"build": "babel src/ -d lib/",
"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",
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 babel-node ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
"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",
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 node ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
"coverage": "cross-env COVERAGE_OPTION='./node_modules/.bin/istanbul cover' npm test",
"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",
"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",
"start": "node ./bin/parse-server",
"prepublish": "npm run build"
},
Expand Down
11 changes: 8 additions & 3 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ global.on_db = (db, callback, elseCallback) => {
}
}

if (global._babelPolyfill) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sure nothing is poly filled before running the tests

console.error('We should not use polyfilled tests');
process.exit(1);
}

var cache = require('../src/cache').default;
var express = require('express');
var facebook = require('../src/authDataManager/facebook');
Expand Down Expand Up @@ -214,7 +219,7 @@ afterEach(function(done) {
} else {
// Other system classes will break Parse.com, so make sure that we don't save anything to _SCHEMA that will
// break it.
return ['_User', '_Installation', '_Role', '_Session', '_Product'].includes(className);
return ['_User', '_Installation', '_Role', '_Session', '_Product'].indexOf(className) >= 0;
}
}});
});
Expand Down Expand Up @@ -387,15 +392,15 @@ global.jfail = function(err) {
}

global.it_exclude_dbs = excluded => {
if (excluded.includes(process.env.PARSE_SERVER_TEST_DB)) {
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
return xit;
} else {
return it;
}
}

global.fit_exclude_dbs = excluded => {
if (excluded.includes(process.env.PARSE_SERVER_TEST_DB)) {
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
return xit;
} else {
return fit;
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSc
}

const transformInteriorValue = restValue => {
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$')|| key.includes('.'))) {
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
}
// Handle atomic values
Expand Down
6 changes: 3 additions & 3 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class PostgresStorageAdapter {
relations.push(fieldName)
return;
}
if (['_rperm', '_wperm'].includes(fieldName)) {
if (['_rperm', '_wperm'].indexOf(fieldName) >= 0) {
parseType.contents = { type: 'String' };
}
valuesArray.push(fieldName);
Expand Down Expand Up @@ -678,7 +678,7 @@ export class PostgresStorageAdapter {
valuesArray.push(object[fieldName].objectId);
break;
case 'Array':
if (['_rperm', '_wperm'].includes(fieldName)) {
if (['_rperm', '_wperm'].indexOf(fieldName) >= 0) {
valuesArray.push(object[fieldName]);
} else {
valuesArray.push(JSON.stringify(object[fieldName]));
Expand Down Expand Up @@ -707,7 +707,7 @@ export class PostgresStorageAdapter {
let initialValues = valuesArray.map((val, index) => {
let termination = '';
let fieldName = columnsArray[index];
if (['_rperm','_wperm'].includes(fieldName)) {
if (['_rperm','_wperm'].indexOf(fieldName) >= 0) {
termination = '::text[]';
} else if (schema.fields[fieldName] && schema.fields[fieldName].type === 'Array') {
termination = '::jsonb';
Expand Down
14 changes: 12 additions & 2 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const transformObjectACL = ({ ACL, ...result }) => {
}

const specialQuerykeys = ['$and', '$or', '_rperm', '_wperm', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];

const isSpecialQueryKey = key => {
return specialQuerykeys.indexOf(key) >= 0;
}

const validateQuery = query => {
if (query.ACL) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot query on ACL.');
Expand Down Expand Up @@ -73,7 +78,7 @@ const validateQuery = query => {
}
}
}
if (!specialQuerykeys.includes(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
if (!isSpecialQueryKey(key) && !key.match(/^[a-zA-Z][a-zA-Z0-9_\.]*$/)) {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: ${key}`);
}
});
Expand Down Expand Up @@ -185,6 +190,11 @@ const filterSensitiveData = (isMaster, aclGroup, className, object) => {
// one of the provided strings must provide the caller with
// write permissions.
const specialKeysForUpdate = ['_hashed_password', '_perishable_token', '_email_verify_token', '_email_verify_token_expires_at', '_account_lockout_expires_at', '_failed_login_count'];

const isSpecialUpdateKey = key => {
return specialKeysForUpdate.indexOf(key) >= 0;
}

DatabaseController.prototype.update = function(className, query, update, {
acl,
many,
Expand Down Expand Up @@ -227,7 +237,7 @@ DatabaseController.prototype.update = function(className, query, update, {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
}
fieldName = fieldName.split('.')[0];
if (!SchemaController.fieldNameIsValid(fieldName) && !specialKeysForUpdate.includes(fieldName)) {
if (!SchemaController.fieldNameIsValid(fieldName) && !isSpecialUpdateKey(fieldName)) {
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
}
});
Expand Down
7 changes: 3 additions & 4 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const validNonRelationOrPointerTypes = [
];
// Returns an error suitable for throwing if the type is invalid
const fieldTypeIsInvalid = ({ type, targetClass }) => {
if (['Pointer', 'Relation'].includes(type)) {
if (['Pointer', 'Relation'].indexOf(type) >= 0) {
if (!targetClass) {
return new Parse.Error(135, `type ${type} needs a class name`);
} else if (typeof targetClass !== 'string') {
Expand All @@ -232,7 +232,7 @@ const fieldTypeIsInvalid = ({ type, targetClass }) => {
if (typeof type !== 'string') {
return invalidJsonError;
}
if (!validNonRelationOrPointerTypes.includes(type)) {
if (validNonRelationOrPointerTypes.indexOf(type) < 0) {
return new Parse.Error(Parse.Error.INCORRECT_TYPE, `invalid field type: ${type}`);
}
return undefined;
Expand Down Expand Up @@ -520,7 +520,6 @@ export default class SchemaController {
}
})
.catch(error => {
console.error(error);
// The schema still doesn't validate. Give up
throw new Parse.Error(Parse.Error.INVALID_JSON, 'schema class name does not revalidate');
});
Expand All @@ -541,7 +540,7 @@ export default class SchemaController {

validateSchemaData(className, fields, classLevelPermissions, existingFieldNames) {
for (let fieldName in fields) {
if (!existingFieldNames.includes(fieldName)) {
if (existingFieldNames.indexOf(fieldName) < 0) {
if (!fieldNameIsValid(fieldName)) {
return {
code: Parse.Error.INVALID_KEY_NAME,
Expand Down
7 changes: 4 additions & 3 deletions src/LiveQuery/ParseLiveQueryServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RequestSchema from './RequestSchema';
import { matchesQuery, queryHash } from './QueryTools';
import { ParsePubSub } from './ParsePubSub';
import { SessionTokenCache } from './SessionTokenCache';
import _ from 'lodash';

class ParseLiveQueryServer {
clientId: number;
Expand Down Expand Up @@ -116,7 +117,7 @@ class ParseLiveQueryServer {
if (!isSubscriptionMatched) {
continue;
}
for (let [clientId, requestIds] of subscription.clientRequestIds.entries()) {
for (let [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
let client = this.clients.get(clientId);
if (typeof client === 'undefined') {
continue;
Expand Down Expand Up @@ -159,7 +160,7 @@ class ParseLiveQueryServer {
for (let subscription of classSubscriptions.values()) {
let isOriginalSubscriptionMatched = this._matchesSubscription(originalParseObject, subscription);
let isCurrentSubscriptionMatched = this._matchesSubscription(currentParseObject, subscription);
for (let [clientId, requestIds] of subscription.clientRequestIds.entries()) {
for (let [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
let client = this.clients.get(clientId);
if (typeof client === 'undefined') {
continue;
Expand Down Expand Up @@ -269,7 +270,7 @@ class ParseLiveQueryServer {
this.clients.delete(clientId);

// Delete client from subscriptions
for (let [requestId, subscriptionInfo] of client.subscriptionInfos.entries()) {
for (let [requestId, subscriptionInfo] of _.entries(client.subscriptionInfos)) {
let subscription = subscriptionInfo.subscription;
subscription.deleteClientSubscription(clientId, requestId);

Expand Down
4 changes: 0 additions & 4 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ var batch = require('./batch'),
path = require('path'),
authDataManager = require('./authDataManager');

if (!global._babelPolyfill) {
require('babel-polyfill');
}

import defaults from './defaults';
import * as logging from './logger';
import AppCache from './cache';
Expand Down
4 changes: 2 additions & 2 deletions src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import PromiseRouter from '../PromiseRouter';
import rest from '../rest';

import _ from 'lodash';
import url from 'url';

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

static JSONFromQuery(query) {
let json = {};
for (let [key, value] of Object.entries(query)) {
for (let [key, value] of _.entries(query)) {
try {
json[key] = JSON.parse(value);
} catch (e) {
Expand Down