Skip to content

Add Babel.js compiler support. #312

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 8 commits into from
Feb 9, 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
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ node_modules
*~

# WebStorm/IntelliJ
.idea
.idea

# Babel.js
lib/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We really want Parse to be yours, to see it grow and thrive in the open source c
##### Please Do's

* Take testing seriously! Aim to increase the test coverage with every pull request.
* Run the tests for the file you are working on with `TESTING=1 (repo-root)/node_modules/jasmine/bin/jasmine.js spec/MyFile.spec.js`
* Run the tests for the file you are working on with `npm test spec/MyFile.spec.js`
* Run the tests for the whole project and look at the coverage report to make sure your tests are exhaustive by running `npm test` and looking at (project-root)/lcov-report/parse-server/FileUnderTest.js.html

##### Code of Conduct
Expand Down
2 changes: 1 addition & 1 deletion bin/parse-server
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
var express = require('express');
var ParseServer = require("../index").ParseServer;
var ParseServer = require("../lib/index").ParseServer;

var app = express();

Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "parse-server",
"version": "2.0.7",
"description": "An express module providing a Parse-compatible API server",
"main": "index.js",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/ParsePlatform/parse-server"
Expand All @@ -11,6 +11,7 @@
"dependencies": {
"apn": "^1.7.5",
"aws-sdk": "~2.2.33",
"babel-runtime": "^6.5.0",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.14.2",
"deepcopy": "^0.6.1",
Expand All @@ -19,23 +20,29 @@
"mime": "^1.3.4",
"mongodb": "~2.1.0",
"multer": "^1.1.0",
"node-gcm": "^0.14.0",
"parse": "^1.7.0",
"randomstring": "^1.1.3",
"node-gcm": "^0.14.0",
"request": "^2.65.0"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-istanbul": "^0.6.0",
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.1",
"codecov": "^1.0.1",
"deep-diff": "^0.3.3",
"istanbul": "^0.4.2",
"jasmine": "^2.3.2",
"mongodb-runner": "^3.1.15"
},
"scripts": {
"build": "./node_modules/.bin/babel src/ -d lib/",
"pretest": "MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} mongodb-runner start",
"test": "NODE_ENV=test TESTING=1 ./node_modules/.bin/istanbul cover --include-all-sources -x **/spec/** ./node_modules/.bin/jasmine",
"test": "NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/.bin/babel-istanbul cover -x **/spec/** ./node_modules/.bin/jasmine",
"posttest": "mongodb-runner stop",
"start": "./bin/parse-server"
"start": "./bin/parse-server",
"prepublish": "npm run build"
},
"engines": {
"node": ">=4.1"
Expand Down
2 changes: 1 addition & 1 deletion spec/APNS.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var APNS = require('../APNS');
var APNS = require('../src/APNS');

describe('APNS', () => {
it('can generate APNS notification', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/ExportAdapter.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ExportAdapter = require('../ExportAdapter');
var ExportAdapter = require('../src/ExportAdapter');

describe('ExportAdapter', () => {
it('can be constructed', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/GCM.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var GCM = require('../GCM');
var GCM = require('../src/GCM');

describe('GCM', () => {
it('can generate GCM Payload without expiration time', (done) => {
Expand Down
3 changes: 3 additions & 0 deletions spec/ParseACL.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ describe('Parse.ACL', () => {
equal(results.length, 1);
var result = results[0];
ok(result);
if (!result) {
return fail();
}
equal(result.id, object.id);
equal(result.getACL().getReadAccess(user), true);
equal(result.getACL().getWriteAccess(user), true);
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// A bunch of different tests are in here - it isn't very thematic.
// It would probably be better to refactor them into different files.

var DatabaseAdapter = require('../DatabaseAdapter');
var DatabaseAdapter = require('../src/DatabaseAdapter');
var request = require('request');

describe('miscellaneous', function() {
Expand Down
10 changes: 5 additions & 5 deletions spec/ParseInstallation.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// These tests check the Installations functionality of the REST API.
// Ported from installation_collection_test.go

var auth = require('../Auth');
var cache = require('../cache');
var Config = require('../Config');
var DatabaseAdapter = require('../DatabaseAdapter');
var auth = require('../src/Auth');
var cache = require('../src/cache');
var Config = require('../src/Config');
var DatabaseAdapter = require('../src/DatabaseAdapter');
var Parse = require('parse/node').Parse;
var rest = require('../rest');
var rest = require('../src/rest');

var config = new Config('test');
var database = DatabaseAdapter.getDatabaseConnection('test');
Expand Down
2 changes: 1 addition & 1 deletion spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Tests that involve sending password reset emails.

var request = require('request');
var passwordCrypto = require('../password');
var passwordCrypto = require('../src/password');

describe('Parse.User testing', () => {
it("user sign up class method", (done) => {
Expand Down
10 changes: 5 additions & 5 deletions spec/RestCreate.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// These tests check the "create" functionality of the REST API.
var auth = require('../Auth');
var cache = require('../cache');
var Config = require('../Config');
var DatabaseAdapter = require('../DatabaseAdapter');
var auth = require('../src/Auth');
var cache = require('../src/cache');
var Config = require('../src/Config');
var DatabaseAdapter = require('../src/DatabaseAdapter');
var Parse = require('parse/node').Parse;
var rest = require('../rest');
var rest = require('../src/rest');
var request = require('request');

var config = new Config('test');
Expand Down
8 changes: 4 additions & 4 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// These tests check the "find" functionality of the REST API.
var auth = require('../Auth');
var cache = require('../cache');
var Config = require('../Config');
var rest = require('../rest');
var auth = require('../src/Auth');
var cache = require('../src/cache');
var Config = require('../src/Config');
var rest = require('../src/rest');

var config = new Config('test');
var nobody = auth.nobody(config);
Expand Down
8 changes: 4 additions & 4 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// These tests check that the Schema operates correctly.
var Config = require('../Config');
var Schema = require('../Schema');
var Config = require('../src/Config');
var Schema = require('../src/Schema');
var dd = require('deep-diff');

var config = new Config('test');
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('Schema', () => {
it('refuses to add fields with invalid pointer types', done => {
config.database.loadSchema()
.then(schema => schema.addClassIfNotExists('NewClass', {
foo: {type: 'Pointer'},
foo: {type: 'Pointer'}
}))
.catch(error => {
expect(error.code).toEqual(135);
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('Schema', () => {
config.database.loadSchema()
.then(schema => schema.addClassIfNotExists('NewClass', {
geo1: {type: 'GeoPoint'},
geo2: {type: 'GeoPoint'},
geo2: {type: 'GeoPoint'}
}))
.catch(error => {
expect(error.code).toEqual(Parse.Error.INCORRECT_TYPE);
Expand Down
8 changes: 4 additions & 4 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;

var cache = require('../cache');
var DatabaseAdapter = require('../DatabaseAdapter');
var cache = require('../src/cache');
var DatabaseAdapter = require('../src/DatabaseAdapter');
var express = require('express');
var facebook = require('../facebook');
var ParseServer = require('../index').ParseServer;
var facebook = require('../src/facebook');
var ParseServer = require('../src/index').ParseServer;

var databaseURI = process.env.DATABASE_URI;
var cloudMain = process.env.CLOUD_CODE_MAIN || './cloud/main.js';
Expand Down
2 changes: 1 addition & 1 deletion spec/push.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var push = require('../push');
var push = require('../src/push');

describe('push', () => {
it('can check valid master key of request', (done) => {
Expand Down
4 changes: 2 additions & 2 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var hasAllPODobject = () => {
objACL.setPublicWriteAccess(false);
obj.setACL(objACL);
return obj;
}
};

var plainOldDataSchema = {
className: 'HasAllPOD',
Expand All @@ -35,7 +35,7 @@ var plainOldDataSchema = {
aArray: {type: 'Array'},
aGeoPoint: {type: 'GeoPoint'},
aFile: {type: 'File'}
},
}
};

var pointersAndRelationsSchema = {
Expand Down
2 changes: 1 addition & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"*spec.js"
],
"helpers": [
"../node_modules/babel-core/register.js",
"helper.js"
]
}

2 changes: 1 addition & 1 deletion spec/transform.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// These tests are unit tests designed to only test transform.js.

var transform = require('../transform');
var transform = require('../src/transform');

var dummySchema = {
data: {},
Expand Down
2 changes: 1 addition & 1 deletion APNS.js → src/APNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ APNS.prototype.send = function(data, deviceTokens) {
var generateNotification = function(coreData, expirationTime) {
var notification = new apn.notification();
var payload = {};
for (key in coreData) {
for (var key in coreData) {
switch (key) {
case 'alert':
notification.setAlertText(coreData.alert);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 13 additions & 14 deletions Schema.js → src/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
var Parse = require('parse/node').Parse;
var transform = require('./transform');

defaultColumns = {
var defaultColumns = {
// Contain the default columns for every parse object type (except _Join collection)
_Default: {
"objectId": {type:'String'},
Expand All @@ -43,13 +43,13 @@ defaultColumns = {
"GCMSenderId": {type:'String'},
"timeZone": {type:'String'},
"localeIdentifier": {type:'String'},
"badge": {type:'Number'},
"badge": {type:'Number'}
},
// The additional default columns for the _User collection (in addition to DefaultCols)
_Role: {
"name": {type:'String'},
"users": {type:'Relation',className:'_User'},
"roles": {type:'Relation',className:'_Role'},
"roles": {type:'Relation',className:'_Role'}
},
// The additional default columns for the _User collection (in addition to DefaultCols)
_Session: {
Expand All @@ -58,9 +58,9 @@ defaultColumns = {
"installationId": {type:'String'},
"sessionToken": {type:'String'},
"expiresAt": {type:'Date'},
"createdWith": {type:'Object'},
},
}
"createdWith": {type:'Object'}
}
};

// Valid classes must:
// Be one of _User, _Installation, _Role, _Session OR
Expand Down Expand Up @@ -221,7 +221,7 @@ Schema.prototype.addClassIfNotExists = function(className, fields) {
error: invalidClassNameMessage(className),
});
}
for (fieldName in fields) {
for (var fieldName in fields) {
if (!fieldNameIsValid(fieldName)) {
return Promise.reject({
code: Parse.Error.INVALID_KEY_NAME,
Expand All @@ -240,26 +240,25 @@ Schema.prototype.addClassIfNotExists = function(className, fields) {
_id: className,
objectId: 'string',
updatedAt: 'string',
createdAt: 'string',
createdAt: 'string'
};
for (fieldName in defaultColumns[className]) {
validatedField = schemaAPITypeToMongoFieldType(defaultColumns[className][fieldName]);
for (var fieldName in defaultColumns[className]) {
var validatedField = schemaAPITypeToMongoFieldType(defaultColumns[className][fieldName]);
if (validatedField.code) {
return Promise.reject(validatedField);
}
mongoObject[fieldName] = validatedField.result;
}

for (fieldName in fields) {
validatedField = schemaAPITypeToMongoFieldType(fields[fieldName]);
for (var fieldName in fields) {
var validatedField = schemaAPITypeToMongoFieldType(fields[fieldName]);
if (validatedField.code) {
return Promise.reject(validatedField);
}
mongoObject[fieldName] = validatedField.result;
}

var geoPoints = Object.keys(mongoObject).filter(key => mongoObject[key] === 'geopoint');

if (geoPoints.length > 1) {
return Promise.reject({
code: Parse.Error.INCORRECT_TYPE,
Expand All @@ -278,7 +277,7 @@ Schema.prototype.addClassIfNotExists = function(className, fields) {
}
return Promise.reject(error);
});
}
};

// Returns a promise that resolves successfully to the new schema
// object or fails with a reason.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion classes.js → src/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function handleFind(req) {
req.params.className, body.where, options)
.then((response) => {
if (response && response.results) {
for (result of response.results) {
for (var result of response.results) {
if (result.sessionToken) {
result.sessionToken = req.info.sessionToken || result.sessionToken;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions schemas.js → src/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function mongoFieldTypeToSchemaAPIType(type) {
}

function mongoSchemaAPIResponseFields(schema) {
fieldNames = Object.keys(schema).filter(key => key !== '_id' && key !== '_metadata');
response = fieldNames.reduce((obj, fieldName) => {
var fieldNames = Object.keys(schema).filter(key => key !== '_id' && key !== '_metadata');
var response = fieldNames.reduce((obj, fieldName) => {
obj[fieldName] = mongoFieldTypeToSchemaAPIType(schema[fieldName])
return obj;
}, {});
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion transform.js → src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var Parse = require('parse/node').Parse;
// validate: true indicates that key names are to be validated.
//
// Returns an object with {key: key, value: value}.
function transformKeyValue(schema, className, restKey, restValue, options) {
export function transformKeyValue(schema, className, restKey, restValue, options) {
options = options || {};

// Check if the schema is known since it's a built-in field.
Expand Down
File renamed without changes.
File renamed without changes.