/**
* Parse JavaScript SDK v1.6.4
*
* The source tree of this library can be found at
* https://github.com/ParsePlatform/Parse-SDK-JS
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Parse = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
* Some functions are only available from Cloud Code.
* An ACL, or Access Control List can be added to any
* Represents a latitude / longitude point that may be associated
* with a key in a ParseObject or used as a reference point for geo queries.
* This allows proximity-based queries on the key. Only one key in a class may contain a GeoPoint. Example:
*
* FB.init()
. Parse.FacebookUtils will invoke FB.init() for you
* with these arguments.
*
* @method init
* @param {Object} options Facebook options argument as described here:
*
* FB.init(). The status flag will be coerced to 'false' because it
* interferes with Parse Facebook integration. Call FB.getLoginStatus()
* explicitly if this behavior is required by your application.
*/
init: function init(options) {
if (typeof FB === 'undefined') {
throw new Error('The Facebook JavaScript SDK must be loaded before calling init.');
}
initOptions = {};
if (options) {
for (var key in options) {
initOptions[key] = options[key];
}
}
if (initOptions.status && typeof console !== 'undefined') {
var warn = console.warn || console.log || function () {};
warn.call(console, 'The "status" flag passed into' + ' FB.init, when set to true, can interfere with Parse Facebook' + ' integration, so it has been suppressed. Please call' + ' FB.getLoginStatus() explicitly if you require this behavior.');
}
initOptions.status = false;
FB.init(initOptions);
_ParseUser2['default']._registerAuthenticationProvider({
authenticate: function authenticate(options) {
var _this = this;
if (typeof FB === 'undefined') {
options.error(this, 'Facebook SDK not found.');
}
FB.login(function (response) {
if (response.authResponse) {
if (options.success) {
options.success(_this, {
id: response.authResponse.userID,
access_token: response.authResponse.accessToken,
expiration_date: new Date(response.authResponse.expiresIn * 1000 + new Date().getTime()).toJSON()
});
}
} else {
if (options.error) {
options.error(_this, response);
}
}
}, {
scope: requestedPermissions
});
},
restoreAuthentication: function restoreAuthentication(authData) {
if (authData) {
var expiration = (0, _parseDate2['default'])(authData.expiration_date);
var expiresIn = expiration ? (expiration.getTime() - new Date().getTime()) / 1000 : 0;
var authResponse = {
userID: authData.id,
accessToken: authData.access_token,
expiresIn: expiresIn
};
var newOptions = {};
if (initOptions) {
for (var key in initOptions) {
newOptions[key] = initOptions[key];
}
}
newOptions.authResponse = authResponse;
// Suppress checks for login status from the browser.
newOptions.status = false;
// If the user doesn't match the one known by the FB SDK, log out.
// Most of the time, the users will match -- it's only in cases where
// the FB SDK knows of a different user than the one being restored
// from a Parse User that logged in with username/password.
var existingResponse = FB.getAuthResponse();
if (existingResponse && existingResponse.userID !== authResponse.userID) {
FB.logout();
}
FB.init(newOptions);
}
return true;
},
getAuthType: function getAuthType() {
return 'facebook';
},
deauthenticate: function deauthenticate() {
this.restoreAuthentication(null);
}
});
initialized = true;
},
/**
* Gets whether the user has their account linked to Facebook.
*
* @method isLinked
* @param {Parse.User} user User to check for a facebook link.
* The user must be logged in on this device.
* @return {Boolean} true
if the user has their account
* linked to Facebook.
*/
isLinked: function isLinked(user) {
return user._isLinked('facebook');
},
/**
* Logs in a user using Facebook. This method delegates to the Facebook
* SDK to authenticate the user, and then automatically logs in (or
* creates, in the case where it is a new user) a Parse.User.
*
* @method logIn
* @param {String, Object} permissions The permissions required for Facebook
* log in. This is a comma-separated string of permissions.
* Alternatively, supply a Facebook authData object as described in our
* REST API docs if you want to handle getting facebook auth tokens
* yourself.
* @param {Object} options Standard options object with success and error
* callbacks.
*/
logIn: function logIn(permissions, options) {
if (!permissions || typeof permissions === 'string') {
if (!initialized) {
throw new Error('You must initialize FacebookUtils before calling logIn.');
}
requestedPermissions = permissions;
return _ParseUser2['default']._logInWith('facebook', options);
} else {
var newOptions = {};
if (options) {
for (var key in options) {
newOptions[key] = options[key];
}
}
newOptions.authData = permissions;
return _ParseUser2['default']._logInWith('facebook', newOptions);
}
},
/**
* Links Facebook to an existing PFUser. This method delegates to the
* Facebook SDK to authenticate the user, and then automatically links
* the account to the Parse.User.
*
* @method link
* @param {Parse.User} user User to link to Facebook. This must be the
* current user.
* @param {String, Object} permissions The permissions required for Facebook
* log in. This is a comma-separated string of permissions.
* Alternatively, supply a Facebook authData object as described in our
* REST API docs if you want to handle getting facebook auth tokens
* yourself.
* @param {Object} options Standard options object with success and error
* callbacks.
*/
link: function link(user, permissions, options) {
if (!permissions || typeof permissions === 'string') {
if (!initialized) {
throw new Error('You must initialize FacebookUtils before calling link.');
}
requestedPermissions = permissions;
return user._linkWith('facebook', options);
} else {
var newOptions = {};
if (options) {
for (var key in options) {
newOptions[key] = options[key];
}
}
newOptions.authData = permissions;
return user._linkWith('facebook', newOptions);
}
},
/**
* Unlinks the Parse.User from a Facebook account.
*
* @method unlink
* @param {Parse.User} user User to unlink from Facebook. This must be the
* current user.
* @param {Object} options Standard options object with success and error
* callbacks.
*/
unlink: function unlink(user, options) {
if (!initialized) {
throw new Error('You must initialize FacebookUtils before calling unlink.');
}
return user._unlinkFrom('facebook', options);
}
};
module.exports = exports['default'];
},{"./ParseUser":21,"./parseDate":34,"babel-runtime/helpers/interop-require-default":47}],5:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
var _CoreManager = _dereq_('./CoreManager');
var _CoreManager2 = _interopRequireDefault(_CoreManager);
var _ParsePromise = _dereq_('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
var _Storage = _dereq_('./Storage');
var _Storage2 = _interopRequireDefault(_Storage);
var iidCache = null;
function hexOctet() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
function generateId() {
return hexOctet() + hexOctet() + '-' + hexOctet() + '-' + hexOctet() + '-' + hexOctet() + '-' + hexOctet() + hexOctet() + hexOctet();
}
module.exports = {
currentInstallationId: function currentInstallationId() {
if (typeof iidCache === 'string') {
return _ParsePromise2['default'].as(iidCache);
}
var path = _Storage2['default'].generatePath('installationId');
return _Storage2['default'].getItemAsync(path).then(function (iid) {
if (!iid) {
iid = generateId();
return _Storage2['default'].setItemAsync(path, iid).then(function () {
iidCache = iid;
return iid;
});
}
iidCache = iid;
return iid;
});
},
_clearCache: function _clearCache() {
iidCache = null;
},
_setInstallationIdCache: function _setInstallationIdCache(iid) {
iidCache = iid;
}
};
},{"./CoreManager":3,"./ParsePromise":16,"./Storage":24,"babel-runtime/helpers/interop-require-default":47}],6:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.getState = getState;
exports.initializeState = initializeState;
exports.removeState = removeState;
exports.getServerData = getServerData;
exports.setServerData = setServerData;
exports.getPendingOps = getPendingOps;
exports.setPendingOp = setPendingOp;
exports.pushPendingState = pushPendingState;
exports.popPendingState = popPendingState;
exports.mergeFirstPendingState = mergeFirstPendingState;
exports.getObjectCache = getObjectCache;
exports.estimateAttribute = estimateAttribute;
exports.estimateAttributes = estimateAttributes;
exports.commitServerChanges = commitServerChanges;
exports.enqueueTask = enqueueTask;
exports._clearAllState = _clearAllState;
var _encode = _dereq_('./encode');
var _encode2 = _interopRequireDefault(_encode);
var _ParseFile = _dereq_('./ParseFile');
var _ParseFile2 = _interopRequireDefault(_ParseFile);
var _ParseObject = _dereq_('./ParseObject');
var _ParseObject2 = _interopRequireDefault(_ParseObject);
var _ParsePromise = _dereq_('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
var _ParseRelation = _dereq_('./ParseRelation');
var _ParseRelation2 = _interopRequireDefault(_ParseRelation);
var _TaskQueue = _dereq_('./TaskQueue');
var _TaskQueue2 = _interopRequireDefault(_TaskQueue);
var _ParseOp = _dereq_('./ParseOp');
var objectState = {};
function getState(className, id) {
var classData = objectState[className];
if (classData) {
return classData[id] || null;
}
return null;
}
function initializeState(className, id, initial) {
var state = getState(className, id);
if (state) {
return state;
}
if (!objectState[className]) {
objectState[className] = {};
}
if (!initial) {
initial = {
serverData: {},
pendingOps: [{}],
objectCache: {},
tasks: new _TaskQueue2['default'](),
existed: false
};
}
state = objectState[className][id] = initial;
return state;
}
function removeState(className, id) {
var state = getState(className, id);
if (state === null) {
return null;
}
delete objectState[className][id];
return state;
}
function getServerData(className, id) {
var state = getState(className, id);
if (state) {
return state.serverData;
}
return {};
}
function setServerData(className, id, attributes) {
var data = initializeState(className, id).serverData;
for (var attr in attributes) {
if (typeof attributes[attr] !== 'undefined') {
data[attr] = attributes[attr];
} else {
delete data[attr];
}
}
}
function getPendingOps(className, id) {
var state = getState(className, id);
if (state) {
return state.pendingOps;
}
return [{}];
}
function setPendingOp(className, id, attr, op) {
var pending = initializeState(className, id).pendingOps;
var last = pending.length - 1;
if (op) {
pending[last][attr] = op;
} else {
delete pending[last][attr];
}
}
function pushPendingState(className, id) {
var pending = initializeState(className, id).pendingOps;
pending.push({});
}
function popPendingState(className, id) {
var pending = initializeState(className, id).pendingOps;
var first = pending.shift();
if (!pending.length) {
pending[0] = {};
}
return first;
}
function mergeFirstPendingState(className, id) {
var first = popPendingState(className, id);
var pending = getPendingOps(className, id);
var next = pending[0];
for (var attr in first) {
if (next[attr] && first[attr]) {
var merged = next[attr].mergeWith(first[attr]);
if (merged) {
next[attr] = merged;
}
} else {
next[attr] = first[attr];
}
}
}
function getObjectCache(className, id) {
var state = getState(className, id);
if (state) {
return state.objectCache;
}
return {};
}
function estimateAttribute(className, id, attr) {
var serverData = getServerData(className, id);
var value = serverData[attr];
var pending = getPendingOps(className, id);
for (var i = 0; i < pending.length; i++) {
if (pending[i][attr]) {
if (pending[i][attr] instanceof _ParseOp.RelationOp) {
value = pending[i][attr].applyTo(value, { className: className, id: id }, attr);
} else {
value = pending[i][attr].applyTo(value);
}
}
}
return value;
}
function estimateAttributes(className, id) {
var data = {};
var attr;
var serverData = getServerData(className, id);
for (attr in serverData) {
data[attr] = serverData[attr];
}
var pending = getPendingOps(className, id);
for (var i = 0; i < pending.length; i++) {
for (attr in pending[i]) {
if (pending[i][attr] instanceof _ParseOp.RelationOp) {
data[attr] = pending[i][attr].applyTo(data[attr], { className: className, id: id }, attr);
} else {
data[attr] = pending[i][attr].applyTo(data[attr]);
}
}
}
return data;
}
function commitServerChanges(className, id, changes) {
var state = initializeState(className, id);
for (var attr in changes) {
var val = changes[attr];
state.serverData[attr] = val;
if (val && typeof val === 'object' && !(val instanceof _ParseObject2['default']) && !(val instanceof _ParseFile2['default']) && !(val instanceof _ParseRelation2['default'])) {
var json = (0, _encode2['default'])(val, false, true);
state.objectCache[attr] = JSON.stringify(json);
}
}
}
function enqueueTask(className, id, task) {
var state = initializeState(className, id);
return state.tasks.enqueue(task);
}
function _clearAllState() {
objectState = {};
}
},{"./ParseFile":11,"./ParseObject":14,"./ParseOp":15,"./ParsePromise":16,"./ParseRelation":18,"./TaskQueue":26,"./encode":30,"babel-runtime/helpers/interop-require-default":47}],7:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
var _interopRequireWildcard = _dereq_('babel-runtime/helpers/interop-require-wildcard')['default'];
var _decode = _dereq_('./decode');
var _decode2 = _interopRequireDefault(_decode);
var _encode = _dereq_('./encode');
var _encode2 = _interopRequireDefault(_encode);
var _CoreManager = _dereq_('./CoreManager');
var _CoreManager2 = _interopRequireDefault(_CoreManager);
var _InstallationController = _dereq_('./InstallationController');
var _InstallationController2 = _interopRequireDefault(_InstallationController);
var _ParseOp = _dereq_('./ParseOp');
var ParseOp = _interopRequireWildcard(_ParseOp);
var _RESTController = _dereq_('./RESTController');
var _RESTController2 = _interopRequireDefault(_RESTController);
/**
* Contains all Parse API classes and functions.
* @class Parse
* @static
*/
var Parse = {
/**
* Call this method first to set up your authentication tokens for Parse.
* You can get your keys from the Data Browser on parse.com.
* @method initialize
* @param {String} applicationId Your Parse Application ID.
* @param {String} javaScriptKey Your Parse JavaScript Key.
* @param {String} masterKey (optional) Your Parse Master Key. (Node.js only!)
* @static
*/
initialize: function initialize(applicationId, javaScriptKey) {
if ('browser' === 'browser' && _CoreManager2['default'].get('IS_NODE')) {
console.log('It looks like you\'re using the browser version of the SDK in a ' + 'node.js environment. You should require(\'parse/node\') instead.');
}
Parse._initialize(applicationId, javaScriptKey);
},
_initialize: function _initialize(applicationId, javaScriptKey, masterKey) {
_CoreManager2['default'].set('APPLICATION_ID', applicationId);
_CoreManager2['default'].set('JAVASCRIPT_KEY', javaScriptKey);
_CoreManager2['default'].set('MASTER_KEY', masterKey);
_CoreManager2['default'].set('USE_MASTER_KEY', false);
}
};
/** These legacy setters may eventually be deprecated **/
Object.defineProperty(Parse, 'applicationId', {
get: function get() {
return _CoreManager2['default'].get('APPLICATION_ID');
},
set: function set(value) {
_CoreManager2['default'].set('APPLICATION_ID', value);
}
});
Object.defineProperty(Parse, 'javaScriptKey', {
get: function get() {
return _CoreManager2['default'].get('JAVASCRIPT_KEY');
},
set: function set(value) {
_CoreManager2['default'].set('JAVASCRIPT_KEY', value);
}
});
Object.defineProperty(Parse, 'masterKey', {
get: function get() {
return _CoreManager2['default'].get('MASTER_KEY');
},
set: function set(value) {
_CoreManager2['default'].set('MASTER_KEY', value);
}
});
Object.defineProperty(Parse, 'serverURL', {
get: function get() {
return _CoreManager2['default'].get('SERVER_URL');
},
set: function set(value) {
_CoreManager2['default'].set('SERVER_URL', value);
}
});
/** End setters **/
Parse.ACL = _dereq_('./ParseACL');
Parse.Analytics = _dereq_('./Analytics');
Parse.Cloud = _dereq_('./Cloud');
Parse.CoreManager = _dereq_('./CoreManager');
Parse.Config = _dereq_('./ParseConfig');
Parse.Error = _dereq_('./ParseError');
Parse.FacebookUtils = _dereq_('./FacebookUtils');
Parse.File = _dereq_('./ParseFile');
Parse.GeoPoint = _dereq_('./ParseGeoPoint');
Parse.Installation = _dereq_('./ParseInstallation');
Parse.Object = _dereq_('./ParseObject');
Parse.Op = {
Set: ParseOp.SetOp,
Unset: ParseOp.UnsetOp,
Increment: ParseOp.IncrementOp,
Add: ParseOp.AddOp,
Remove: ParseOp.RemoveOp,
AddUnique: ParseOp.AddUniqueOp,
Relation: ParseOp.RelationOp
};
Parse.Promise = _dereq_('./ParsePromise');
Parse.Push = _dereq_('./Push');
Parse.Query = _dereq_('./ParseQuery');
Parse.Relation = _dereq_('./ParseRelation');
Parse.Role = _dereq_('./ParseRole');
Parse.Session = _dereq_('./ParseSession');
Parse.Storage = _dereq_('./Storage');
Parse.User = _dereq_('./ParseUser');
Parse._request = function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _CoreManager2['default'].getRESTController().request.apply(null, args);
};
Parse._ajax = function () {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _CoreManager2['default'].getRESTController().ajax.apply(null, args);
};
// We attempt to match the signatures of the legacy versions of these methods
Parse._decode = function (_, value) {
return (0, _decode2['default'])(value);
};
Parse._encode = function (value, _, disallowObjects) {
return (0, _encode2['default'])(value, disallowObjects);
};
Parse._getInstallationId = function () {
return _CoreManager2['default'].getInstallationController().currentInstallationId();
};
_CoreManager2['default'].setInstallationController(_InstallationController2['default']);
_CoreManager2['default'].setRESTController(_RESTController2['default']);
// For legacy requires, of the form `var Parse = require('parse').Parse`
Parse.Parse = Parse;
module.exports = Parse;
},{"./Analytics":1,"./Cloud":2,"./CoreManager":3,"./FacebookUtils":4,"./InstallationController":5,"./ParseACL":8,"./ParseConfig":9,"./ParseError":10,"./ParseFile":11,"./ParseGeoPoint":12,"./ParseInstallation":13,"./ParseObject":14,"./ParseOp":15,"./ParsePromise":16,"./ParseQuery":17,"./ParseRelation":18,"./ParseRole":19,"./ParseSession":20,"./ParseUser":21,"./Push":22,"./RESTController":23,"./Storage":24,"./decode":29,"./encode":30,"babel-runtime/helpers/interop-require-default":47,"babel-runtime/helpers/interop-require-wildcard":48}],8:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _createClass = _dereq_('babel-runtime/helpers/create-class')['default'];
var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default'];
var _Object$keys = _dereq_('babel-runtime/core-js/object/keys')['default'];
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
Object.defineProperty(exports, '__esModule', {
value: true
});
var _ParseRole = _dereq_('./ParseRole');
var _ParseRole2 = _interopRequireDefault(_ParseRole);
var _ParseUser = _dereq_('./ParseUser');
var _ParseUser2 = _interopRequireDefault(_ParseUser);
var PUBLIC_KEY = '*';
/**
* Creates a new ACL.
* If no argument is given, the ACL has no permissions for anyone.
* If the argument is a Parse.User, the ACL will have read and write
* permission for only that user.
* If the argument is any other JSON object, that object will be interpretted
* as a serialized ACL created with toJSON().
* @class Parse.ACL
* @constructor
*
* Parse.Object
to restrict access to only a subset of users
* of your application.
*
* @return {Parse.Promise} A promise that is resolved with a newly-created
* configuration object when the get completes.
*/
}, {
key: 'get',
value: function get(options) {
options = options || {};
var controller = _CoreManager2['default'].getConfigController();
return controller.get()._thenRunCallbacks(options);
}
}]);
return ParseConfig;
})();
exports['default'] = ParseConfig;
var currentConfig = null;
var CURRENT_CONFIG_KEY = 'currentConfig';
function decodePayload(data) {
try {
var json = JSON.parse(data);
if (json && typeof json === 'object') {
return (0, _decode2['default'])(json);
}
} catch (e) {
return null;
}
}
_CoreManager2['default'].setConfigController({
current: function current() {
if (currentConfig) {
return currentConfig;
}
var config = new ParseConfig();
var storagePath = _Storage2['default'].generatePath(CURRENT_CONFIG_KEY);
var configData;
if (!_Storage2['default'].async()) {
configData = _Storage2['default'].getItem(storagePath);
if (configData) {
var attributes = decodePayload(configData);
if (attributes) {
config.attributes = attributes;
currentConfig = config;
}
}
return config;
}
// Return a promise for async storage controllers
return _Storage2['default'].getItemAsync(storagePath).then(function (configData) {
if (configData) {
var attributes = decodePayload(configData);
if (attributes) {
config.attributes = attributes;
currentConfig = config;
}
}
return config;
});
},
get: function get() {
var RESTController = _CoreManager2['default'].getRESTController();
return RESTController.request('GET', 'config', {}, {}).then(function (response) {
if (!response || !response.params) {
var error = new _ParseError2['default'](_ParseError2['default'].INVALID_JSON, 'Config JSON response invalid.');
return _ParsePromise2['default'].error(error);
}
var config = new ParseConfig();
config.attributes = {};
for (var attr in response.params) {
config.attributes[attr] = (0, _decode2['default'])(response.params[attr]);
}
currentConfig = config;
return _Storage2['default'].setItemAsync(_Storage2['default'].generatePath(CURRENT_CONFIG_KEY), JSON.stringify(response.params)).then(function () {
return config;
});
});
}
});
module.exports = exports['default'];
},{"./CoreManager":3,"./ParseError":10,"./ParsePromise":16,"./Storage":24,"./decode":29,"./encode":30,"./escape":32,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/interop-require-default":47}],10:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/**
* Constructs a new Parse.Error object with the given code and message.
* @class Parse.Error
* @constructor
* @param {Number} code An error code constant from Parse.Error
.
* @param {String} message A detailed description of the error.
*/
"use strict";
var _classCallCheck = _dereq_("babel-runtime/helpers/class-call-check")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
var ParseError = function ParseError(code, message) {
_classCallCheck(this, ParseError);
this.code = code;
this.message = message;
}
/**
* Error code indicating some error other than those enumerated here.
* @property OTHER_CAUSE
* @static
* @final
*/
;
exports["default"] = ParseError;
ParseError.OTHER_CAUSE = -1;
/**
* Error code indicating that something has gone wrong with the server.
* If you get this error code, it is Parse's fault. Contact us at
* https://parse.com/help
* @property INTERNAL_SERVER_ERROR
* @static
* @final
*/
ParseError.INTERNAL_SERVER_ERROR = 1;
/**
* Error code indicating the connection to the Parse servers failed.
* @property CONNECTION_FAILED
* @static
* @final
*/
ParseError.CONNECTION_FAILED = 100;
/**
* Error code indicating the specified object doesn't exist.
* @property OBJECT_NOT_FOUND
* @static
* @final
*/
ParseError.OBJECT_NOT_FOUND = 101;
/**
* Error code indicating you tried to query with a datatype that doesn't
* support it, like exact matching an array or object.
* @property INVALID_QUERY
* @static
* @final
*/
ParseError.INVALID_QUERY = 102;
/**
* Error code indicating a missing or invalid classname. Classnames are
* case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the
* only valid characters.
* @property INVALID_CLASS_NAME
* @static
* @final
*/
ParseError.INVALID_CLASS_NAME = 103;
/**
* Error code indicating an unspecified object id.
* @property MISSING_OBJECT_ID
* @static
* @final
*/
ParseError.MISSING_OBJECT_ID = 104;
/**
* Error code indicating an invalid key name. Keys are case-sensitive. They
* must start with a letter, and a-zA-Z0-9_ are the only valid characters.
* @property INVALID_KEY_NAME
* @static
* @final
*/
ParseError.INVALID_KEY_NAME = 105;
/**
* Error code indicating a malformed pointer. You should not see this unless
* you have been mucking about changing internal Parse code.
* @property INVALID_POINTER
* @static
* @final
*/
ParseError.INVALID_POINTER = 106;
/**
* Error code indicating that badly formed JSON was received upstream. This
* either indicates you have done something unusual with modifying how
* things encode to JSON, or the network is failing badly.
* @property INVALID_JSON
* @static
* @final
*/
ParseError.INVALID_JSON = 107;
/**
* Error code indicating that the feature you tried to access is only
* available internally for testing purposes.
* @property COMMAND_UNAVAILABLE
* @static
* @final
*/
ParseError.COMMAND_UNAVAILABLE = 108;
/**
* You must call Parse.initialize before using the Parse library.
* @property NOT_INITIALIZED
* @static
* @final
*/
ParseError.NOT_INITIALIZED = 109;
/**
* Error code indicating that a field was set to an inconsistent type.
* @property INCORRECT_TYPE
* @static
* @final
*/
ParseError.INCORRECT_TYPE = 111;
/**
* Error code indicating an invalid channel name. A channel name is either
* an empty string (the broadcast channel) or contains only a-zA-Z0-9_
* characters and starts with a letter.
* @property INVALID_CHANNEL_NAME
* @static
* @final
*/
ParseError.INVALID_CHANNEL_NAME = 112;
/**
* Error code indicating that push is misconfigured.
* @property PUSH_MISCONFIGURED
* @static
* @final
*/
ParseError.PUSH_MISCONFIGURED = 115;
/**
* Error code indicating that the object is too large.
* @property OBJECT_TOO_LARGE
* @static
* @final
*/
ParseError.OBJECT_TOO_LARGE = 116;
/**
* Error code indicating that the operation isn't allowed for clients.
* @property OPERATION_FORBIDDEN
* @static
* @final
*/
ParseError.OPERATION_FORBIDDEN = 119;
/**
* Error code indicating the result was not found in the cache.
* @property CACHE_MISS
* @static
* @final
*/
ParseError.CACHE_MISS = 120;
/**
* Error code indicating that an invalid key was used in a nested
* JSONObject.
* @property INVALID_NESTED_KEY
* @static
* @final
*/
ParseError.INVALID_NESTED_KEY = 121;
/**
* Error code indicating that an invalid filename was used for ParseFile.
* A valid file name contains only a-zA-Z0-9_. characters and is between 1
* and 128 characters.
* @property INVALID_FILE_NAME
* @static
* @final
*/
ParseError.INVALID_FILE_NAME = 122;
/**
* Error code indicating an invalid ACL was provided.
* @property INVALID_ACL
* @static
* @final
*/
ParseError.INVALID_ACL = 123;
/**
* Error code indicating that the request timed out on the server. Typically
* this indicates that the request is too expensive to run.
* @property TIMEOUT
* @static
* @final
*/
ParseError.TIMEOUT = 124;
/**
* Error code indicating that the email address was invalid.
* @property INVALID_EMAIL_ADDRESS
* @static
* @final
*/
ParseError.INVALID_EMAIL_ADDRESS = 125;
/**
* Error code indicating a missing content type.
* @property MISSING_CONTENT_TYPE
* @static
* @final
*/
ParseError.MISSING_CONTENT_TYPE = 126;
/**
* Error code indicating a missing content length.
* @property MISSING_CONTENT_LENGTH
* @static
* @final
*/
ParseError.MISSING_CONTENT_LENGTH = 127;
/**
* Error code indicating an invalid content length.
* @property INVALID_CONTENT_LENGTH
* @static
* @final
*/
ParseError.INVALID_CONTENT_LENGTH = 128;
/**
* Error code indicating a file that was too large.
* @property FILE_TOO_LARGE
* @static
* @final
*/
ParseError.FILE_TOO_LARGE = 129;
/**
* Error code indicating an error saving a file.
* @property FILE_SAVE_ERROR
* @static
* @final
*/
ParseError.FILE_SAVE_ERROR = 130;
/**
* Error code indicating that a unique field was given a value that is
* already taken.
* @property DUPLICATE_VALUE
* @static
* @final
*/
ParseError.DUPLICATE_VALUE = 137;
/**
* Error code indicating that a role's name is invalid.
* @property INVALID_ROLE_NAME
* @static
* @final
*/
ParseError.INVALID_ROLE_NAME = 139;
/**
* Error code indicating that an application quota was exceeded. Upgrade to
* resolve.
* @property EXCEEDED_QUOTA
* @static
* @final
*/
ParseError.EXCEEDED_QUOTA = 140;
/**
* Error code indicating that a Cloud Code script failed.
* @property SCRIPT_FAILED
* @static
* @final
*/
ParseError.SCRIPT_FAILED = 141;
/**
* Error code indicating that a Cloud Code validation failed.
* @property VALIDATION_ERROR
* @static
* @final
*/
ParseError.VALIDATION_ERROR = 142;
/**
* Error code indicating that invalid image data was provided.
* @property INVALID_IMAGE_DATA
* @static
* @final
*/
ParseError.INVALID_IMAGE_DATA = 143;
/**
* Error code indicating an unsaved file.
* @property UNSAVED_FILE_ERROR
* @static
* @final
*/
ParseError.UNSAVED_FILE_ERROR = 151;
/**
* Error code indicating an invalid push time.
* @property INVALID_PUSH_TIME_ERROR
* @static
* @final
*/
ParseError.INVALID_PUSH_TIME_ERROR = 152;
/**
* Error code indicating an error deleting a file.
* @property FILE_DELETE_ERROR
* @static
* @final
*/
ParseError.FILE_DELETE_ERROR = 153;
/**
* Error code indicating that the application has exceeded its request
* limit.
* @property REQUEST_LIMIT_EXCEEDED
* @static
* @final
*/
ParseError.REQUEST_LIMIT_EXCEEDED = 155;
/**
* Error code indicating an invalid event name.
* @property INVALID_EVENT_NAME
* @static
* @final
*/
ParseError.INVALID_EVENT_NAME = 160;
/**
* Error code indicating that the username is missing or empty.
* @property USERNAME_MISSING
* @static
* @final
*/
ParseError.USERNAME_MISSING = 200;
/**
* Error code indicating that the password is missing or empty.
* @property PASSWORD_MISSING
* @static
* @final
*/
ParseError.PASSWORD_MISSING = 201;
/**
* Error code indicating that the username has already been taken.
* @property USERNAME_TAKEN
* @static
* @final
*/
ParseError.USERNAME_TAKEN = 202;
/**
* Error code indicating that the email has already been taken.
* @property EMAIL_TAKEN
* @static
* @final
*/
ParseError.EMAIL_TAKEN = 203;
/**
* Error code indicating that the email is missing, but must be specified.
* @property EMAIL_MISSING
* @static
* @final
*/
ParseError.EMAIL_MISSING = 204;
/**
* Error code indicating that a user with the specified email was not found.
* @property EMAIL_NOT_FOUND
* @static
* @final
*/
ParseError.EMAIL_NOT_FOUND = 205;
/**
* Error code indicating that a user object without a valid session could
* not be altered.
* @property SESSION_MISSING
* @static
* @final
*/
ParseError.SESSION_MISSING = 206;
/**
* Error code indicating that a user can only be created through signup.
* @property MUST_CREATE_USER_THROUGH_SIGNUP
* @static
* @final
*/
ParseError.MUST_CREATE_USER_THROUGH_SIGNUP = 207;
/**
* Error code indicating that an an account being linked is already linked
* to another user.
* @property ACCOUNT_ALREADY_LINKED
* @static
* @final
*/
ParseError.ACCOUNT_ALREADY_LINKED = 208;
/**
* Error code indicating that the current session token is invalid.
* @property INVALID_SESSION_TOKEN
* @static
* @final
*/
ParseError.INVALID_SESSION_TOKEN = 209;
/**
* Error code indicating that a user cannot be linked to an account because
* that account's id could not be found.
* @property LINKED_ID_MISSING
* @static
* @final
*/
ParseError.LINKED_ID_MISSING = 250;
/**
* Error code indicating that a user with a linked (e.g. Facebook) account
* has an invalid session.
* @property INVALID_LINKED_SESSION
* @static
* @final
*/
ParseError.INVALID_LINKED_SESSION = 251;
/**
* Error code indicating that a service being linked (e.g. Facebook or
* Twitter) is unsupported.
* @property UNSUPPORTED_SERVICE
* @static
* @final
*/
ParseError.UNSUPPORTED_SERVICE = 252;
/**
* Error code indicating that there were multiple errors. Aggregate errors
* have an "errors" property, which is an array of error objects with more
* detail about each error that occurred.
* @property AGGREGATE_ERROR
* @static
* @final
*/
ParseError.AGGREGATE_ERROR = 600;
/**
* Error code indicating the client was unable to read an input file.
* @property FILE_READ_ERROR
* @static
* @final
*/
ParseError.FILE_READ_ERROR = 601;
/**
* Error code indicating a real error code is unavailable because
* we had to use an XDomainRequest object to allow CORS requests in
* Internet Explorer, which strips the body from HTTP responses that have
* a non-2XX status code.
* @property X_DOMAIN_REQUEST
* @static
* @final
*/
ParseError.X_DOMAIN_REQUEST = 602;
module.exports = exports["default"];
},{"babel-runtime/helpers/class-call-check":43}],11:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _createClass = _dereq_('babel-runtime/helpers/create-class')['default'];
var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default'];
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
Object.defineProperty(exports, '__esModule', {
value: true
});
var _CoreManager = _dereq_('./CoreManager');
var _CoreManager2 = _interopRequireDefault(_CoreManager);
var _ParsePromise = _dereq_('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
function b64Digit(number) {
if (number < 26) {
return String.fromCharCode(65 + number);
}
if (number < 52) {
return String.fromCharCode(97 + (number - 26));
}
if (number < 62) {
return String.fromCharCode(48 + (number - 52));
}
if (number === 62) {
return '+';
}
if (number === 63) {
return '/';
}
throw new TypeError('Tried to encode large digit ' + number + ' in base64.');
}
/**
* A Parse.File is a local representation of a file that is saved to the Parse
* cloud.
* @class Parse.File
* @constructor
* @param name {String} The file's name. This will be prefixed by a unique
* value once the file has finished saving. The file name must begin with
* an alphanumeric character, and consist of alphanumeric characters,
* periods, spaces, underscores, or dashes.
* @param data {Array} The data for the file, as either:
* 1. an Array of byte value Numbers, or
* 2. an Object like { base64: "..." } with a base64-encoded String.
* 3. a File object selected with a file upload control. (3) only works
* in Firefox 3.6+, Safari 6.0.2+, Chrome 7+, and IE 10+.
* For example:
* var fileUploadControl = $("#profilePhotoFileUpload")[0];
* if (fileUploadControl.files.length > 0) {
* var file = fileUploadControl.files[0];
* var name = "photo.jpg";
* var parseFile = new Parse.File(name, file);
* parseFile.save().then(function() {
* // The file has been saved to Parse.
* }, function(error) {
* // The file either could not be read, or could not be saved to Parse.
* });
* }
* @param type {String} Optional Content-Type header to use for the file. If
* this is omitted, the content type will be inferred from the name's
* extension.
*/
var ParseFile = (function () {
function ParseFile(name, data, type) {
_classCallCheck(this, ParseFile);
var specifiedType = type || '';
this._name = name;
if (Array.isArray(data)) {
this._source = {
format: 'base64',
base64: ParseFile.encodeBase64(data),
type: specifiedType
};
} else if (typeof File !== 'undefined' && data instanceof File) {
this._source = {
format: 'file',
file: data,
type: specifiedType
};
} else if (data && data.hasOwnProperty('base64')) {
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,(\S+)/.exec(data.base64);
if (matches && matches.length > 0) {
// if data URI with type and charset, there will be 4 matches.
this._source = {
format: 'base64',
base64: matches.length === 4 ? matches[3] : matches[2],
type: matches[1]
};
} else {
this._source = {
format: 'base64',
base64: data.base64,
type: specifiedType
};
}
} else if (typeof data !== 'undefined') {
throw new TypeError('Cannot create a Parse.File with that data.');
}
}
/**
* Gets the name of the file. Before save is called, this is the filename
* given by the user. After save is called, that name gets prefixed with a
* unique identifier.
* @method name
* @return {String}
*/
_createClass(ParseFile, [{
key: 'name',
value: function name() {
return this._name;
}
/**
* Gets the url of the file. It is only available after you save the file or
* after you get the file from a Parse.Object.
* @method url
* @return {String}
*/
}, {
key: 'url',
value: function url() {
return this._url;
}
/**
* Saves the file to the Parse cloud.
* @method save
* @param {Object} options A Backbone-style options object.
* @return {Parse.Promise} Promise that is resolved when the save finishes.
*/
}, {
key: 'save',
value: function save(options) {
var _this = this;
options = options || {};
var controller = _CoreManager2['default'].getFileController();
if (!this._previousSave) {
if (this._source.format === 'file') {
this._previousSave = controller.saveFile(this._name, this._source).then(function (res) {
_this._name = res.name;
_this._url = res.url;
return _this;
});
} else {
this._previousSave = controller.saveBase64(this._name, this._source).then(function (res) {
_this._name = res.name;
_this._url = res.url;
return _this;
});
}
}
if (this._previousSave) {
return this._previousSave._thenRunCallbacks(options);
}
}
}, {
key: 'toJSON',
value: function toJSON() {
return {
__type: 'File',
name: this._name,
url: this._url
};
}
}, {
key: 'equals',
value: function equals(other) {
if (this === other) {
return true;
}
// Unsaved Files are never equal, since they will be saved to different URLs
return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== 'undefined';
}
}], [{
key: 'fromJSON',
value: function fromJSON(obj) {
if (obj.__type !== 'File') {
throw new TypeError('JSON object does not represent a ParseFile');
}
var file = new ParseFile(obj.name);
file._url = obj.url;
return file;
}
}, {
key: 'encodeBase64',
value: function encodeBase64(bytes) {
var chunks = [];
chunks.length = Math.ceil(bytes.length / 3);
for (var i = 0; i < chunks.length; i++) {
var b1 = bytes[i * 3];
var b2 = bytes[i * 3 + 1] || 0;
var b3 = bytes[i * 3 + 2] || 0;
var has2 = i * 3 + 1 < bytes.length;
var has3 = i * 3 + 2 < bytes.length;
chunks[i] = [b64Digit(b1 >> 2 & 0x3F), b64Digit(b1 << 4 & 0x30 | b2 >> 4 & 0x0F), has2 ? b64Digit(b2 << 2 & 0x3C | b3 >> 6 & 0x03) : '=', has3 ? b64Digit(b3 & 0x3F) : '='].join('');
}
return chunks.join('');
}
}]);
return ParseFile;
})();
exports['default'] = ParseFile;
_CoreManager2['default'].setFileController({
saveFile: function saveFile(name, source) {
if (source.format !== 'file') {
throw new Error('saveFile can only be used with File-type sources.');
}
// To directly upload a File, we use a REST-style AJAX request
var headers = {
'X-Parse-Application-ID': _CoreManager2['default'].get('APPLICATION_ID'),
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY')
};
var url = _CoreManager2['default'].get('SERVER_URL');
url += '/1/files/' + name;
return _CoreManager2['default'].getRESTController().ajax('POST', url, source.file, headers);
},
saveBase64: function saveBase64(name, source) {
if (source.format !== 'base64') {
throw new Error('saveBase64 can only be used with Base64-type sources.');
}
var data = {
base64: source.base64
};
if (source.type) {
data._ContentType = source.type;
}
return _CoreManager2['default'].getRESTController().request('POST', 'files/' + name, data);
}
});
module.exports = exports['default'];
},{"./CoreManager":3,"./ParsePromise":16,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/interop-require-default":47}],12:[function(_dereq_,module,exports){
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';
var _createClass = _dereq_('babel-runtime/helpers/create-class')['default'];
var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default'];
var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default'];
Object.defineProperty(exports, '__esModule', {
value: true
});
var _ParsePromise = _dereq_('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
/**
* Creates a new GeoPoint with any of the following forms:
*
* new GeoPoint(otherGeoPoint)
* new GeoPoint(30, 30)
* new GeoPoint([30, 30])
* new GeoPoint({latitude: 30, longitude: 30})
* new GeoPoint() // defaults to (0, 0)
*
* @class Parse.GeoPoint
* @constructor
*
*
* var point = new Parse.GeoPoint(30.0, -20.0);
* var object = new Parse.Object("PlaceObject");
* object.set("location", point);
* object.save();
You won't normally call this method directly. It is recommended that
* you use a subclass of Parse.Object
instead, created by calling
* extend
.
However, if you don't want to use a subclass, or aren't sure which * subclass is appropriate, you can use this form:
* var object = new Parse.Object("ClassName"); ** That is basically equivalent to:
* var MyClass = Parse.Object.extend("ClassName"); * var object = new MyClass(); ** * @class Parse.Object * @constructor * @param {String} className The class name for the object * @param {Object} attributes The initial set of data to store in the object. */ var ParseObject = (function () { function ParseObject(className, attributes) { _classCallCheck(this, ParseObject); var toSet = null; this._objCount = objectCount++; if (typeof className === 'string') { this.className = className; if (attributes && typeof attributes === 'object') { toSet = attributes; } } else if (className && typeof className === 'object') { this.className = className.className; toSet = {}; for (var attr in className) { if (attr !== 'className') { toSet[attr] = className[attr]; } } } if (toSet && !this.set(toSet)) { throw new Error('Can\'t create an invalid Parse Object'); } // Enable legacy initializers if (typeof this.initialize === 'function') { this.initialize.apply(this, arguments); } } /** Prototype getters / setters **/ _createClass(ParseObject, [{ key: '_getId', /** Private methods **/ /** * Returns a local or server Id used uniquely identify this object */ value: function _getId() { if (typeof this.id === 'string') { return this.id; } if (typeof this._localId === 'string') { return this._localId; } var localId = 'local' + String(localCount++); this._localId = localId; return localId; } /** * Returns a local or server Id used to pull data from the Object State store * If single instance objects are disabled, it will use the object's unique * count to separate its data from other objects with the same server Id. */ }, { key: '_getStateIdentifier', value: function _getStateIdentifier() { if (typeof this.id === 'string') { if (singleInstance) { return this.id; } return this.id + '_' + String(this._objCount); } return this._getId(); } }, { key: '_getServerData', value: function _getServerData() { return ObjectState.getServerData(this.className, this._getStateIdentifier()); } }, { key: '_clearServerData', value: function _clearServerData() { var serverData = this._getServerData(); var unset = {}; for (var attr in serverData) { unset[attr] = undefined; } ObjectState.setServerData(this.className, this._getStateIdentifier(), unset); } }, { key: '_getPendingOps', value: function _getPendingOps() { return ObjectState.getPendingOps(this.className, this._getStateIdentifier()); } }, { key: '_clearPendingOps', value: function _clearPendingOps() { var pending = this._getPendingOps(); var latest = pending[pending.length - 1]; var keys = _Object$keys(latest); keys.forEach(function (key) { delete latest[key]; }); } }, { key: '_getDirtyObjectAttributes', value: function _getDirtyObjectAttributes() { var attributes = this.attributes; var objectCache = ObjectState.getObjectCache(this.className, this._getStateIdentifier()); var dirty = {}; for (var attr in attributes) { var val = attributes[attr]; if (val && typeof val === 'object' && !(val instanceof ParseObject) && !(val instanceof _ParseFile2['default']) && !(val instanceof _ParseRelation2['default'])) { // Due to the way browsers construct maps, the key order will not change // unless the object is changed var json = (0, _encode2['default'])(val, false, true); var stringified = JSON.stringify(json); if (objectCache[attr] !== stringified) { dirty[attr] = val; } } } return dirty; } }, { key: '_toFullJSON', value: function _toFullJSON() { var json = this.toJSON(); json.__type = 'Object'; json.className = this.className; return json; } }, { key: '_getSaveJSON', value: function _getSaveJSON() { var pending = this._getPendingOps(); var dirtyObjects = this._getDirtyObjectAttributes(); var json = {}; var attr; for (attr in dirtyObjects) { json[attr] = new _ParseOp.SetOp(dirtyObjects[attr]).toJSON(); } for (attr in pending[0]) { json[attr] = pending[0][attr].toJSON(); } return json; } }, { key: '_getSaveParams', value: function _getSaveParams() { var method = this.id ? 'PUT' : 'POST'; var body = this._getSaveJSON(); var path = 'classes/' + this.className; if (this.id) { path += '/' + this.id; } else if (this.className === '_User') { path = 'users'; } return { method: method, body: body, path: path }; } }, { key: '_finishFetch', value: function _finishFetch(serverData) { if (!this.id && serverData.objectId) { this.id = serverData.objectId; } ObjectState.initializeState(this.className, this._getStateIdentifier()); var decoded = {}; for (var attr in serverData) { if (attr === 'ACL') { decoded[attr] = new _ParseACL2['default'](serverData[attr]); } else if (attr !== 'objectId') { decoded[attr] = (0, _decode2['default'])(serverData[attr]); if (decoded[attr] instanceof _ParseRelation2['default']) { decoded[attr]._ensureParentAndKey(this, attr); } } } if (decoded.createdAt && typeof decoded.createdAt === 'string') { decoded.createdAt = (0, _parseDate2['default'])(decoded.createdAt); } if (decoded.updatedAt && typeof decoded.updatedAt === 'string') { decoded.updatedAt = (0, _parseDate2['default'])(decoded.updatedAt); } if (!decoded.updatedAt && decoded.createdAt) { decoded.updatedAt = decoded.createdAt; } ObjectState.commitServerChanges(this.className, this._getStateIdentifier(), decoded); } }, { key: '_setExisted', value: function _setExisted(existed) { var state = ObjectState.getState(this.className, this._getStateIdentifier()); if (state) { state.existed = existed; } } }, { key: '_migrateId', value: function _migrateId(serverId) { if (this._localId && serverId) { var oldState = ObjectState.removeState(this.className, this._getStateIdentifier()); this.id = serverId; delete this._localId; if (oldState) { ObjectState.initializeState(this.className, this._getStateIdentifier(), oldState); } } } }, { key: '_handleSaveResponse', value: function _handleSaveResponse(response, status) { var changes = {}; var attr; var pending = ObjectState.popPendingState(this.className, this._getStateIdentifier()); for (attr in pending) { if (pending[attr] instanceof _ParseOp.RelationOp) { changes[attr] = pending[attr].applyTo(undefined, this, attr); } else if (!(attr in response)) { // Only SetOps and UnsetOps should not come back with results changes[attr] = pending[attr].applyTo(undefined); } } for (attr in response) { if ((attr === 'createdAt' || attr === 'updatedAt') && typeof response[attr] === 'string') { changes[attr] = (0, _parseDate2['default'])(response[attr]); } else if (attr !== 'objectId') { changes[attr] = (0, _decode2['default'])(response[attr]); } } if (changes.createdAt && !changes.updatedAt) { changes.updatedAt = changes.createdAt; } this._migrateId(response.objectId); if (status !== 201) { this._setExisted(true); } ObjectState.commitServerChanges(this.className, this._getStateIdentifier(), changes); } }, { key: '_handleSaveError', value: function _handleSaveError() { var pending = this._getPendingOps(); if (pending.length > 2) { // There are more saves on the queue ObjectState.mergeFirstPendingState(this.className, this._getStateIdentifier()); } } /** Public methods **/ }, { key: 'initialize', value: function initialize() {} // NOOP /** * Returns a JSON version of the object suitable for saving to Parse. * @method toJSON * @return {Object} */ }, { key: 'toJSON', value: function toJSON() { var json = {}; var attrs = this.attributes; for (var attr in attrs) { if ((attr === 'createdAt' || attr === 'updatedAt') && attrs[attr].toJSON) { json[attr] = attrs[attr].toJSON(); } else { json[attr] = (0, _encode2['default'])(attrs[attr], false, true); } } var pending = this._getPendingOps(); for (var attr in pending[0]) { json[attr] = pending[0][attr].toJSON(); } if (this.id) { json.objectId = this.id; } return json; } /** * Determines whether this ParseObject is equal to another ParseObject * @method equals * @return {Boolean} */ }, { key: 'equals', value: function equals(other) { if (this === other) { return true; } return other instanceof ParseObject && this.className === other.className && this.id === other.id && typeof this.id !== 'undefined'; } /** * Returns true if this object has been modified since its last * save/refresh. If an attribute is specified, it returns true only if that * particular attribute has been modified since the last save/refresh. * @method dirty * @param {String} attr An attribute name (optional). * @return {Boolean} */ }, { key: 'dirty', value: function dirty(attr) { if (!this.id) { return true; } var pendingOps = this._getPendingOps(); var dirtyObjects = this._getDirtyObjectAttributes(); if (attr) { if (dirtyObjects.hasOwnProperty(attr)) { return true; } for (var i = 0; i < pendingOps.length; i++) { if (pendingOps[i].hasOwnProperty(attr)) { return true; } } return false; } if (_Object$keys(pendingOps[0]).length !== 0) { return true; } if (_Object$keys(dirtyObjects).length !== 0) { return true; } return false; } /** * Returns an array of keys that have been modified since last save/refresh * @method dirtyKeys * @return {Array of string} */ }, { key: 'dirtyKeys', value: function dirtyKeys() { var pendingOps = this._getPendingOps(); var keys = {}; for (var i = 0; i < pendingOps.length; i++) { for (var attr in pendingOps[i]) { keys[attr] = true; } } var dirtyObjects = this._getDirtyObjectAttributes(); for (var attr in dirtyObjects) { keys[attr] = true; } return _Object$keys(keys); } /** * Gets a Pointer referencing this Object. * @method toPointer * @return {Object} */ }, { key: 'toPointer', value: function toPointer() { if (!this.id) { throw new Error('Cannot create a pointer to an unsaved ParseObject'); } return { __type: 'Pointer', className: this.className, objectId: this.id }; } /** * Gets the value of an attribute. * @method get * @param {String} attr The string name of an attribute. */ }, { key: 'get', value: function get(attr) { return this.attributes[attr]; } /** * Gets a relation on the given class for the attribute. * @method relation * @param String attr The attribute to get the relation for. */ }, { key: 'relation', value: function relation(attr) { var value = this.get(attr); if (value) { if (!(value instanceof _ParseRelation2['default'])) { throw new Error('Called relation() on non-relation field ' + attr); } value._ensureParentAndKey(this, attr); return value; } return new _ParseRelation2['default'](this, attr); } /** * Gets the HTML-escaped value of an attribute. * @method escape * @param {String} attr The string name of an attribute. */ }, { key: 'escape', value: function escape(attr) { var val = this.attributes[attr]; if (val == null) { return ''; } var str = val; if (typeof val !== 'string') { if (typeof val.toString !== 'function') { return ''; } val = val.toString(); } return (0, _escape3['default'])(val); } /** * Returns
true
if the attribute contains a value that is not
* null or undefined.
* @method has
* @param {String} attr The string name of the attribute.
* @return {Boolean}
*/
}, {
key: 'has',
value: function has(attr) {
var attributes = this.attributes;
if (attributes.hasOwnProperty(attr)) {
return attributes[attr] != null;
}
return false;
}
/**
* Sets a hash of model attributes on the object.
*
* You can call it with an object containing keys and values, or with one * key and value. For example:
* gameTurn.set({ * player: player1, * diceRoll: 2 * }, { * error: function(gameTurnAgain, error) { * // The set failed validation. * } * }); * * game.set("currentPlayer", player2, { * error: function(gameTurnAgain, error) { * // The set failed validation. * } * }); * * game.set("finished", true);* * @method set * @param {String} key The key to set. * @param {} value The value to give it. * @param {Object} options A set of options for the set. * The only supported option is
error
.
* @return {Boolean} true if the set succeeded.
*/
}, {
key: 'set',
value: function set(key, value, options) {
var changes = {};
var newOps = {};
if (key && typeof key === 'object') {
changes = key;
options = value;
} else if (typeof key === 'string') {
changes[key] = value;
} else {
return this;
}
options = options || {};
var readonly = [];
if (typeof this.constructor.readOnlyAttributes === 'function') {
readonly = readonly.concat(this.constructor.readOnlyAttributes());
}
for (var k in changes) {
if (k === 'createdAt' || k === 'updatedAt') {
// This property is read-only, but for legacy reasons we silently
// ignore it
continue;
}
if (readonly.indexOf(k) > -1) {
throw new Error('Cannot modify readonly attribute: ' + k);
}
if (options.unset) {
newOps[k] = new _ParseOp.UnsetOp();
} else if (changes[k] instanceof _ParseOp.Op) {
newOps[k] = changes[k];
} else if (changes[k] && typeof changes[k] === 'object' && typeof changes[k].__op === 'string') {
newOps[k] = (0, _ParseOp.opFromJSON)(changes[k]);
} else if (k === 'objectId' || k === 'id') {
this.id = changes[k];
} else {
newOps[k] = new _ParseOp.SetOp(changes[k]);
}
}
// Calculate new values
var currentAttributes = this.attributes;
var newValues = {};
for (var attr in newOps) {
if (newOps[attr] instanceof _ParseOp.RelationOp) {
newValues[attr] = newOps[attr].applyTo(currentAttributes[attr], this, attr);
} else if (!(newOps[attr] instanceof _ParseOp.UnsetOp)) {
newValues[attr] = newOps[attr].applyTo(currentAttributes[attr]);
}
}
// Validate changes
var validation = this.validate(newValues);
if (validation) {
if (typeof options.error === 'function') {
options.error(this, validation);
}
return false;
}
// Consolidate Ops
var pendingOps = this._getPendingOps();
var last = pendingOps.length - 1;
for (var attr in newOps) {
var nextOp = newOps[attr].mergeWith(pendingOps[last][attr]);
ObjectState.setPendingOp(this.className, this._getStateIdentifier(), attr, nextOp);
}
return this;
}
/**
* Remove an attribute from the model. This is a noop if the attribute doesn't
* exist.
* @method unset
* @param {String} attr The string name of an attribute.
*/
}, {
key: 'unset',
value: function unset(attr, options) {
options = options || {};
options.unset = true;
return this.set(attr, null, options);
}
/**
* Atomically increments the value of the given attribute the next time the
* object is saved. If no amount is specified, 1 is used by default.
*
* @method increment
* @param attr {String} The key.
* @param amount {Number} The amount to increment by (optional).
*/
}, {
key: 'increment',
value: function increment(attr, amount) {
if (typeof amount === 'undefined') {
amount = 1;
}
if (typeof amount !== 'number') {
throw new Error('Cannot increment by a non-numeric amount.');
}
return this.set(attr, new _ParseOp.IncrementOp(amount));
}
/**
* Atomically add an object to the end of the array associated with a given
* key.
* @method add
* @param attr {String} The key.
* @param item {} The item to add.
*/
}, {
key: 'add',
value: function add(attr, item) {
return this.set(attr, new _ParseOp.AddOp([item]));
}
/**
* Atomically add an object to the array associated with a given key, only
* if it is not already present in the array. The position of the insert is
* not guaranteed.
*
* @method addUnique
* @param attr {String} The key.
* @param item {} The object to add.
*/
}, {
key: 'addUnique',
value: function addUnique(attr, item) {
return this.set(attr, new _ParseOp.AddUniqueOp([item]));
}
/**
* Atomically remove all instances of an object from the array associated
* with a given key.
*
* @method remove
* @param attr {String} The key.
* @param item {} The object to remove.
*/
}, {
key: 'remove',
value: function remove(attr, item) {
return this.set(attr, new _ParseOp.RemoveOp([item]));
}
/**
* Returns an instance of a subclass of Parse.Op describing what kind of
* modification has been performed on this field since the last time it was
* saved. For example, after calling object.increment("x"), calling
* object.op("x") would return an instance of Parse.Op.Increment.
*
* @method op
* @param attr {String} The key.
* @returns {Parse.Op} The operation, or undefined if none.
*/
}, {
key: 'op',
value: function op(attr) {
var pending = this._getPendingOps();
for (var i = pending.length; i--;) {
if (pending[i][attr]) {
return pending[i][attr];
}
}
}
/**
* Creates a new model with identical attributes to this one.
* @method clone
* @return {Parse.Object}
*/
}, {
key: 'clone',
value: function clone() {
var clone = new this.constructor();
if (clone.set) {
clone.set(this.attributes);
}
if (!clone.className) {
clone.className = this.className;
}
return clone;
}
/**
* Returns true if this object has never been saved to Parse.
* @method isNew
* @return {Boolean}
*/
}, {
key: 'isNew',
value: function isNew() {
return !this.id;
}
/**
* Returns true if this object was created by the Parse server when the
* object might have already been there (e.g. in the case of a Facebook
* login)
* @method existed
* @return {Boolean}
*/
}, {
key: 'existed',
value: function existed() {
if (!this.id) {
return false;
}
var state = ObjectState.getState(this.className, this._getStateIdentifier());
if (state) {
return state.existed;
}
return false;
}
/**
* Checks if the model is currently in a valid state.
* @method isValid
* @return {Boolean}
*/
}, {
key: 'isValid',
value: function isValid() {
return !this.validate(this.attributes);
}
/**
* You should not call this function directly unless you subclass
* Parse.Object
, in which case you can override this method
* to provide additional validation on set
and
* save
. Your implementation should return
*
* @method validate
* @param {Object} attrs The current data to validate.
* @return {} False if the data is valid. An error object otherwise.
* @see Parse.Object#set
*/
}, {
key: 'validate',
value: function validate(attrs) {
if (attrs.hasOwnProperty('ACL') && !(attrs.ACL instanceof _ParseACL2['default'])) {
return new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'ACL must be a Parse ACL.');
}
for (var key in attrs) {
if (!/^[A-Za-z][0-9A-Za-z_]*$/.test(key)) {
return new _ParseError2['default'](_ParseError2['default'].INVALID_KEY_NAME);
}
}
return false;
}
/**
* Returns the ACL for this object.
* @method getACL
* @returns {Parse.ACL} An instance of Parse.ACL.
* @see Parse.Object#get
*/
}, {
key: 'getACL',
value: function getACL() {
var acl = this.get('ACL');
if (acl instanceof _ParseACL2['default']) {
return acl;
}
return null;
}
/**
* Sets the ACL to be used for this object.
* @method setACL
* @param {Parse.ACL} acl An instance of Parse.ACL.
* @param {Object} options Optional Backbone-like options object to be
* passed in to set.
* @return {Boolean} Whether the set passed validation.
* @see Parse.Object#set
*/
}, {
key: 'setACL',
value: function setACL(acl, options) {
return this.set('ACL', acl, options);
}
/**
* Clears all attributes on a model
* @method clear
*/
}, {
key: 'clear',
value: function clear() {
var attributes = this.attributes;
var erasable = {};
var readonly = ['createdAt', 'updatedAt'];
if (typeof this.constructor.readOnlyAttributes === 'function') {
readonly = readonly.concat(this.constructor.readOnlyAttributes());
}
for (var attr in attributes) {
if (readonly.indexOf(attr) < 0) {
erasable[attr] = true;
}
}
return this.set(erasable, { unset: true });
}
/**
* Fetch the model from the server. If the server's representation of the
* model differs from its current attributes, they will be overriden.
*
* @method fetch
* @param {Object} options A Backbone-style callback object.
* Valid options are:* object.save();* or
* object.save(null, options);* or
* object.save(attrs, options);* or
* object.save(key, value, options);* * For example,
* gameTurn.save({ * player: "Jake Cutter", * diceRoll: 2 * }, { * success: function(gameTurnAgain) { * // The save was successful. * }, * error: function(gameTurnAgain, error) { * // The save failed. Error is an instance of Parse.Error. * } * });* or with promises:
* gameTurn.save({ * player: "Jake Cutter", * diceRoll: 2 * }).then(function(gameTurnAgain) { * // The save was successful. * }, function(error) { * // The save failed. Error is an instance of Parse.Error. * });* * @method save * @param {Object} options A Backbone-style callback object. * Valid options are:
* Parse.Object.fetchAll([object1, object2, ...], { * success: function(list) { * // All the objects were fetched. * }, * error: function(error) { * // An error occurred while fetching one of the objects. * }, * }); ** * @method fetchAll * @param {Array} list A list of
Parse.Object
.
* @param {Object} options A Backbone-style callback object.
* @static
* Valid options are:* Parse.Object.fetchAllIfNeeded([object1, ...], { * success: function(list) { * // Objects were fetched and updated. * }, * error: function(error) { * // An error occurred while fetching one of the objects. * }, * }); ** * @method fetchAllIfNeeded * @param {Array} list A list of
Parse.Object
.
* @param {Object} options A Backbone-style callback object.
* @static
* Valid options are:Unlike saveAll, if an error occurs while deleting an individual model, * this method will continue trying to delete the rest of the models if * possible, except in the case of a fatal error like a connection error. * *
In particular, the Parse.Error object returned in the case of error may * be one of two types: * *
* Parse.Object.destroyAll([object1, object2, ...], { * success: function() { * // All the objects were deleted. * }, * error: function(error) { * // An error occurred while deleting one or more of the objects. * // If this is an aggregate error, then we can inspect each error * // object individually to determine the reason why a particular * // object was not deleted. * if (error.code === Parse.Error.AGGREGATE_ERROR) { * for (var i = 0; i < error.errors.length; i++) { * console.log("Couldn't delete " + error.errors[i].object.id + * "due to " + error.errors[i].message); * } * } else { * console.log("Delete aborted because of " + error.message); * } * }, * }); ** * @method destroyAll * @param {Array} list A list of
Parse.Object
.
* @param {Object} options A Backbone-style callback object.
* @static
* Valid options are:* Parse.Object.saveAll([object1, object2, ...], { * success: function(list) { * // All the objects were saved. * }, * error: function(error) { * // An error occurred while saving one of the objects. * }, * }); ** * @method saveAll * @param {Array} list A list of
Parse.Object
.
* @param {Object} options A Backbone-style callback object.
* @static
* Valid options are:A shortcut for:
* var Foo = Parse.Object.extend("Foo"); * var pointerToFoo = new Foo(); * pointerToFoo.id = "myObjectId"; ** * @method createWithoutData * @param {String} id The ID of the object to create a reference to. * @static * @return {Parse.Object} A Parse.Object reference. */ }, { key: 'createWithoutData', value: function createWithoutData(id) { var obj = new this(); obj.id = id; return obj; } /** * Creates a new instance of a Parse Object from a JSON representation. * @method fromJSON * @param {Object} json The JSON map of the Object's data * @static * @return {Parse.Object} A Parse.Object reference */ }, { key: 'fromJSON', value: function fromJSON(json) { if (!json.className) { throw new Error('Cannot create an object without a className'); } var constructor = classMap[json.className]; var o = constructor ? new constructor() : new ParseObject(json.className); var otherAttributes = {}; for (var attr in json) { if (attr !== 'className' && attr !== '__type') { otherAttributes[attr] = json[attr]; } } o._finishFetch(otherAttributes); return o; } /** * Registers a subclass of Parse.Object with a specific class name. * When objects of that class are retrieved from a query, they will be * instantiated with this subclass. * This is only necessary when using ES6 subclassing. * @method registerSubclass * @param {String} className The class name of the subclass * @param {Class} constructor The subclass */ }, { key: 'registerSubclass', value: function registerSubclass(className, constructor) { if (typeof className !== 'string') { throw new TypeError('The first argument must be a valid class name.'); } if (typeof constructor === 'undefined') { throw new TypeError('You must supply a subclass constructor.'); } if (typeof constructor !== 'function') { throw new TypeError('You must register the subclass constructor. ' + 'Did you attempt to register an instance of the subclass?'); } classMap[className] = constructor; if (!constructor.className) { constructor.className = className; } } /** * Creates a new subclass of Parse.Object for the given Parse class name. * *
Every extension of a Parse class will inherit from the most recent * previous extension of that class. When a Parse.Object is automatically * created by parsing JSON, it will use the most recent extension of that * class.
* *You should call either:
* var MyClass = Parse.Object.extend("MyClass", { * Instance methods, * initialize: function(attrs, options) { * this.someInstanceProperty = [], * Other instance properties * } * }, { * Class properties * });* or, for Backbone compatibility:
* var MyClass = Parse.Object.extend({ * className: "MyClass", * Instance methods, * initialize: function(attrs, options) { * this.someInstanceProperty = [], * Other instance properties * } * }, { * Class properties * });* * @method extend * @param {String} className The name of the Parse class backing this model. * @param {Object} protoProps Instance properties to add to instances of the * class returned from this method. * @param {Object} classProps Class properties to add the class returned from * this method. * @return {Class} A new subclass of Parse.Object. */ }, { key: 'extend', value: function extend(className, protoProps, classProps) { if (typeof className !== 'string') { if (className && typeof className.className === 'string') { return ParseObject.extend(className.className, className, protoProps); } else { throw new Error('Parse.Object.extend\'s first argument should be the className.'); } } var adjustedClassName = className; if (adjustedClassName === 'User' && _CoreManager2['default'].get('PERFORM_USER_REWRITE')) { adjustedClassName = '_User'; } var parentProto = ParseObject.prototype; if (this.hasOwnProperty('__super__') && this.__super__) { parentProto = this.prototype; } else if (classMap[adjustedClassName]) { parentProto = classMap[adjustedClassName].prototype; } var ParseObjectSubclass = function ParseObjectSubclass(attributes) { this.className = adjustedClassName; this._objCount = objectCount++; if (attributes && typeof attributes === 'object') { if (!this.set(attributes || {})) { throw new Error('Can\'t create an invalid Parse Object'); } } // Enable legacy initializers if (typeof this.initialize === 'function') { this.initialize.apply(this, arguments); } }; ParseObjectSubclass.className = adjustedClassName; ParseObjectSubclass.__super__ = parentProto; ParseObjectSubclass.prototype = _Object$create(parentProto, { constructor: { value: ParseObjectSubclass, enumerable: false, writable: true, configurable: true } }); if (protoProps) { for (var prop in protoProps) { if (prop !== 'className') { _Object$defineProperty(ParseObjectSubclass.prototype, prop, { value: protoProps[prop], enumerable: false, writable: true, configurable: true }); } } } if (classProps) { for (var prop in classProps) { if (prop !== 'className') { _Object$defineProperty(ParseObjectSubclass, prop, { value: classProps[prop], enumerable: false, writable: true, configurable: true }); } } } ParseObjectSubclass.extend = function (name, protoProps, classProps) { if (typeof name === 'string') { return ParseObject.extend.call(ParseObjectSubclass, name, protoProps, classProps); } return ParseObject.extend.call(ParseObjectSubclass, adjustedClassName, name, protoProps); }; ParseObjectSubclass.createWithoutData = ParseObject.createWithoutData; classMap[adjustedClassName] = ParseObjectSubclass; return ParseObjectSubclass; } /** * Enable single instance objects, where any local objects with the same Id * share the same attributes, and stay synchronized with each other. * This is disabled by default in server environments, since it can lead to * security issues. * @method enableSingleInstance */ }, { key: 'enableSingleInstance', value: function enableSingleInstance() { singleInstance = true; } /** * Disable single instance objects, where any local objects with the same Id * share the same attributes, and stay synchronized with each other. * When disabled, you can have two instances of the same object in memory * without them sharing attributes. * @method disableSingleInstance */ }, { key: 'disableSingleInstance', value: function disableSingleInstance() { singleInstance = false; } }]); return ParseObject; })(); exports['default'] = ParseObject; _CoreManager2['default'].setObjectController({ fetch: function fetch(target, forceFetch, options) { if (Array.isArray(target)) { if (target.length < 1) { return _ParsePromise2['default'].as([]); } var objs = []; var ids = []; var className = null; var results = []; var error = null; target.forEach(function (el, i) { if (error) { return; } if (!className) { className = el.className; } if (className !== el.className) { error = new _ParseError2['default'](_ParseError2['default'].INVALID_CLASS_NAME, 'All objects should be of the same class'); } if (!el.id) { error = new _ParseError2['default'](_ParseError2['default'].MISSING_OBJECT_ID, 'All objects must have an ID'); } if (forceFetch || _Object$keys(el._getServerData()).length === 0) { ids.push(el.id); objs.push(el); } results.push(el); }); if (error) { return _ParsePromise2['default'].error(error); } var query = new _ParseQuery2['default'](className); query.containedIn('objectId', ids); query._limit = ids.length; return query.find(options).then(function (objects) { var idMap = {}; objects.forEach(function (o) { idMap[o.id] = o; }); for (var i = 0; i < objs.length; i++) { var obj = objs[i]; if (!obj || !obj.id || !idMap[obj.id]) { if (forceFetch) { return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].OBJECT_NOT_FOUND, 'All objects must exist on the server.')); } } } if (!singleInstance) { // If single instance objects are disabled, we need to replace the for (var i = 0; i < results.length; i++) { var obj = results[i]; if (obj && obj.id && idMap[obj.id]) { var id = obj.id; obj._finishFetch(idMap[id].toJSON()); results[i] = idMap[id]; } } } return _ParsePromise2['default'].as(results); }); } else { var RESTController = _CoreManager2['default'].getRESTController(); return RESTController.request('GET', 'classes/' + target.className + '/' + target._getId(), {}, options).then(function (response, status, xhr) { if (target instanceof ParseObject) { target._clearPendingOps(); target._finishFetch(response); } return target; }); } }, destroy: function destroy(target, options) { var RESTController = _CoreManager2['default'].getRESTController(); if (Array.isArray(target)) { if (target.length < 1) { return _ParsePromise2['default'].as([]); } var batches = [[]]; target.forEach(function (obj) { if (!obj.id) { return; } batches[batches.length - 1].push(obj); if (batches[batches.length - 1].length >= 20) { batches.push([]); } }); if (batches[batches.length - 1].length === 0) { // If the last batch is empty, remove it batches.pop(); } var deleteCompleted = _ParsePromise2['default'].as(); var errors = []; batches.forEach(function (batch) { deleteCompleted = deleteCompleted.then(function () { return RESTController.request('POST', 'batch', { requests: batch.map(function (obj) { return { method: 'DELETE', path: '/1/classes/' + obj.className + '/' + obj._getId(), body: {} }; }) }, options).then(function (results) { for (var i = 0; i < results.length; i++) { if (results[i] && results[i].hasOwnProperty('error')) { var err = new _ParseError2['default'](results[i].error.code, results[i].error.error); err.object = batch[i]; errors.push(err); } } }); }); }); return deleteCompleted.then(function () { if (errors.length) { var aggregate = new _ParseError2['default'](_ParseError2['default'].AGGREGATE_ERROR); aggregate.errors = errors; return _ParsePromise2['default'].error(aggregate); } return _ParsePromise2['default'].as(target); }); } else if (target instanceof ParseObject) { return RESTController.request('DELETE', 'classes/' + target.className + '/' + target._getId(), {}, options).then(function () { return _ParsePromise2['default'].as(target); }); } return _ParsePromise2['default'].as(target); }, save: function save(target, options) { var RESTController = _CoreManager2['default'].getRESTController(); if (Array.isArray(target)) { if (target.length < 1) { return _ParsePromise2['default'].as([]); } var unsaved = target.concat(); for (var i = 0; i < target.length; i++) { if (target[i] instanceof ParseObject) { unsaved = unsaved.concat((0, _unsavedChildren2['default'])(target[i], true)); } } unsaved = (0, _unique2['default'])(unsaved); var filesSaved = _ParsePromise2['default'].as(); var pending = []; unsaved.forEach(function (el) { if (el instanceof _ParseFile2['default']) { filesSaved = filesSaved.then(function () { return el.save(); }); } else if (el instanceof ParseObject) { pending.push(el); } }); return filesSaved.then(function () { var objectError = null; return _ParsePromise2['default']._continueWhile(function () { return pending.length > 0; }, function () { var batch = []; var nextPending = []; pending.forEach(function (el) { if (batch.length < 20 && (0, _canBeSerialized2['default'])(el)) { batch.push(el); } else { nextPending.push(el); } }); pending = nextPending; if (batch.length < 1) { return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'Tried to save a batch with a cycle.')); } // Queue up tasks for each object in the batch. // When every task is ready, the API request will execute var batchReturned = new _ParsePromise2['default'](); var batchReady = []; var batchTasks = []; batch.forEach(function (obj, index) { var ready = new _ParsePromise2['default'](); batchReady.push(ready); var task = function task() { ready.resolve(); return batchReturned.then(function (responses, status) { if (responses[index].hasOwnProperty('success')) { obj._handleSaveResponse(responses[index].success, status); } else { if (!objectError && responses[index].hasOwnProperty('error')) { var serverError = responses[index].error; objectError = new _ParseError2['default'](serverError.code, serverError.error); // Cancel the rest of the save pending = []; } obj._handleSaveError(); } }); }; ObjectState.pushPendingState(obj.className, obj._getStateIdentifier()); batchTasks.push(ObjectState.enqueueTask(obj.className, obj._getStateIdentifier(), task)); }); _ParsePromise2['default'].when(batchReady).then(function () { // Kick off the batch request return RESTController.request('POST', 'batch', { requests: batch.map(function (obj) { var params = obj._getSaveParams(); params.path = '/1/' + params.path; return params; }) }, options); }).then(function (response, status, xhr) { batchReturned.resolve(response, status); }); return _ParsePromise2['default'].when(batchTasks); }).then(function () { if (objectError) { return _ParsePromise2['default'].error(objectError); } return _ParsePromise2['default'].as(target); }); }); } else if (target instanceof ParseObject) { // copying target lets Flow guarantee the pointer isn't modified elsewhere var targetCopy = target; var task = function task() { var params = targetCopy._getSaveParams(); return RESTController.request(params.method, params.path, params.body, options).then(function (response, status) { targetCopy._handleSaveResponse(response, status); }, function (error) { targetCopy._handleSaveError(); return _ParsePromise2['default'].error(error); }); }; ObjectState.pushPendingState(target.className, target._getStateIdentifier()); return ObjectState.enqueueTask(target.className, target._getStateIdentifier(), task).then(function () { return target; }, function (error) { return error; }); } return _ParsePromise2['default'].as(); } }); module.exports = exports['default']; /** * The ID of this object, unique within its class. * @property id * @type String */ },{"./CoreManager":3,"./ObjectState":6,"./ParseACL":8,"./ParseError":10,"./ParseFile":11,"./ParseOp":15,"./ParsePromise":16,"./ParseQuery":17,"./ParseRelation":18,"./canBeSerialized":28,"./decode":29,"./encode":30,"./equals":31,"./escape":32,"./parseDate":34,"./unique":35,"./unsavedChildren":36,"babel-runtime/core-js/object/create":37,"babel-runtime/core-js/object/define-property":38,"babel-runtime/core-js/object/freeze":39,"babel-runtime/core-js/object/keys":41,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/interop-require-default":47,"babel-runtime/helpers/interop-require-wildcard":48}],15:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ 'use strict'; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _get = _dereq_('babel-runtime/helpers/get')['default']; var _inherits = _dereq_('babel-runtime/helpers/inherits')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); exports.opFromJSON = opFromJSON; var _arrayContainsObject = _dereq_('./arrayContainsObject'); var _arrayContainsObject2 = _interopRequireDefault(_arrayContainsObject); var _decode = _dereq_('./decode'); var _decode2 = _interopRequireDefault(_decode); var _encode = _dereq_('./encode'); var _encode2 = _interopRequireDefault(_encode); var _ParseObject = _dereq_('./ParseObject'); var _ParseObject2 = _interopRequireDefault(_ParseObject); var _ParseRelation = _dereq_('./ParseRelation'); var _ParseRelation2 = _interopRequireDefault(_ParseRelation); var _unique = _dereq_('./unique'); var _unique2 = _interopRequireDefault(_unique); function opFromJSON(json) { if (!json || !json.__op) { return null; } switch (json.__op) { case 'Delete': return new UnsetOp(); case 'Increment': return new IncrementOp(json.amount); case 'Add': return new AddOp((0, _decode2['default'])(json.objects)); case 'AddUnique': return new AddUniqueOp((0, _decode2['default'])(json.objects)); case 'Remove': return new RemoveOp((0, _decode2['default'])(json.objects)); case 'AddRelation': var toAdd = (0, _decode2['default'])(json.objects); if (!Array.isArray(toAdd)) { return new RelationOp([], []); } return new RelationOp(toAdd, []); case 'RemoveRelation': var toRemove = (0, _decode2['default'])(json.objects); if (!Array.isArray(toRemove)) { return new RelationOp([], []); } return new RelationOp([], toRemove); case 'Batch': var toAdd = []; var toRemove = []; for (var i = 0; i < json.ops.length; i++) { if (json.ops[i].__op === 'AddRelation') { toAdd = toAdd.concat((0, _decode2['default'])(json.ops[i].objects)); } else if (json.ops[i].__op === 'RemoveRelation') { toRemove = toRemove.concat((0, _decode2['default'])(json.ops[i].objects)); } } return new RelationOp(toAdd, toRemove); } return null; } var Op = (function () { function Op() { _classCallCheck(this, Op); } _createClass(Op, [{ key: 'applyTo', // Empty parent class value: function applyTo(value) {} }, { key: 'mergeWith', value: function mergeWith(previous) {} }, { key: 'toJSON', value: function toJSON() {} }]); return Op; })(); exports.Op = Op; var SetOp = (function (_Op) { _inherits(SetOp, _Op); function SetOp(value) { _classCallCheck(this, SetOp); _get(Object.getPrototypeOf(SetOp.prototype), 'constructor', this).call(this); this._value = value; } _createClass(SetOp, [{ key: 'applyTo', value: function applyTo(value) { return this._value; } }, { key: 'mergeWith', value: function mergeWith(previous) { return new SetOp(this._value); } }, { key: 'toJSON', value: function toJSON() { return (0, _encode2['default'])(this._value, false, true); } }]); return SetOp; })(Op); exports.SetOp = SetOp; var UnsetOp = (function (_Op2) { _inherits(UnsetOp, _Op2); function UnsetOp() { _classCallCheck(this, UnsetOp); _get(Object.getPrototypeOf(UnsetOp.prototype), 'constructor', this).apply(this, arguments); } _createClass(UnsetOp, [{ key: 'applyTo', value: function applyTo(value) { return undefined; } }, { key: 'mergeWith', value: function mergeWith(previous) { return new UnsetOp(); } }, { key: 'toJSON', value: function toJSON() { return { __op: 'Delete' }; } }]); return UnsetOp; })(Op); exports.UnsetOp = UnsetOp; var IncrementOp = (function (_Op3) { _inherits(IncrementOp, _Op3); function IncrementOp(amount) { _classCallCheck(this, IncrementOp); _get(Object.getPrototypeOf(IncrementOp.prototype), 'constructor', this).call(this); if (typeof amount !== 'number') { throw new TypeError('Increment Op must be initialized with a numeric amount.'); } this._amount = amount; } _createClass(IncrementOp, [{ key: 'applyTo', value: function applyTo(value) { if (typeof value === 'undefined') { return this._amount; } if (typeof value !== 'number') { throw new TypeError('Cannot increment a non-numeric value.'); } return this._amount + value; } }, { key: 'mergeWith', value: function mergeWith(previous) { if (!previous) { return this; } if (previous instanceof SetOp) { return new SetOp(this.applyTo(previous._value)); } if (previous instanceof UnsetOp) { return new SetOp(this._amount); } if (previous instanceof IncrementOp) { return new IncrementOp(this.applyTo(previous._amount)); } throw new Error('Cannot merge Increment Op with the previous Op'); } }, { key: 'toJSON', value: function toJSON() { return { __op: 'Increment', amount: this._amount }; } }]); return IncrementOp; })(Op); exports.IncrementOp = IncrementOp; var AddOp = (function (_Op4) { _inherits(AddOp, _Op4); function AddOp(value) { _classCallCheck(this, AddOp); _get(Object.getPrototypeOf(AddOp.prototype), 'constructor', this).call(this); this._value = Array.isArray(value) ? value : [value]; } _createClass(AddOp, [{ key: 'applyTo', value: function applyTo(value) { if (value == null) { return this._value; } if (Array.isArray(value)) { return value.concat(this._value); } throw new Error('Cannot add elements to a non-array value'); } }, { key: 'mergeWith', value: function mergeWith(previous) { if (!previous) { return this; } if (previous instanceof SetOp) { return new SetOp(this.applyTo(previous._value)); } if (previous instanceof UnsetOp) { return new SetOp(this._value); } if (previous instanceof AddOp) { return new AddOp(this.applyTo(previous._value)); } throw new Error('Cannot merge Add Op with the previous Op'); } }, { key: 'toJSON', value: function toJSON() { return { __op: 'Add', objects: (0, _encode2['default'])(this._value, false, true) }; } }]); return AddOp; })(Op); exports.AddOp = AddOp; var AddUniqueOp = (function (_Op5) { _inherits(AddUniqueOp, _Op5); function AddUniqueOp(value) { _classCallCheck(this, AddUniqueOp); _get(Object.getPrototypeOf(AddUniqueOp.prototype), 'constructor', this).call(this); this._value = (0, _unique2['default'])(Array.isArray(value) ? value : [value]); } _createClass(AddUniqueOp, [{ key: 'applyTo', value: function applyTo(value) { if (value == null) { return this._value || []; } if (Array.isArray(value)) { // copying value lets Flow guarantee the pointer isn't modified elsewhere var valueCopy = value; var toAdd = []; this._value.forEach(function (v) { if (v instanceof _ParseObject2['default']) { if (!(0, _arrayContainsObject2['default'])(valueCopy, v)) { toAdd.push(v); } } else { if (valueCopy.indexOf(v) < 0) { toAdd.push(v); } } }); return value.concat(toAdd); } throw new Error('Cannot add elements to a non-array value'); } }, { key: 'mergeWith', value: function mergeWith(previous) { if (!previous) { return this; } if (previous instanceof SetOp) { return new SetOp(this.applyTo(previous._value)); } if (previous instanceof UnsetOp) { return new SetOp(this._value); } if (previous instanceof AddUniqueOp) { return new AddUniqueOp(this.applyTo(previous._value)); } throw new Error('Cannot merge AddUnique Op with the previous Op'); } }, { key: 'toJSON', value: function toJSON() { return { __op: 'AddUnique', objects: (0, _encode2['default'])(this._value, false, true) }; } }]); return AddUniqueOp; })(Op); exports.AddUniqueOp = AddUniqueOp; var RemoveOp = (function (_Op6) { _inherits(RemoveOp, _Op6); function RemoveOp(value) { _classCallCheck(this, RemoveOp); _get(Object.getPrototypeOf(RemoveOp.prototype), 'constructor', this).call(this); this._value = (0, _unique2['default'])(Array.isArray(value) ? value : [value]); } _createClass(RemoveOp, [{ key: 'applyTo', value: function applyTo(value) { if (value == null) { return []; } if (Array.isArray(value)) { var i = value.indexOf(this._value); var removed = value.concat([]); for (var i = 0; i < this._value.length; i++) { var index = removed.indexOf(this._value[i]); while (index > -1) { removed.splice(index, 1); index = removed.indexOf(this._value[i]); } if (this._value[i] instanceof _ParseObject2['default'] && this._value[i].id) { for (var j = 0; j < removed.length; j++) { if (removed[j] instanceof _ParseObject2['default'] && this._value[i].id === removed[j].id) { removed.splice(j, 1); j--; } } } } return removed; } throw new Error('Cannot remove elements from a non-array value'); } }, { key: 'mergeWith', value: function mergeWith(previous) { if (!previous) { return this; } if (previous instanceof SetOp) { return new SetOp(this.applyTo(previous._value)); } if (previous instanceof UnsetOp) { return new UnsetOp(); } if (previous instanceof RemoveOp) { var uniques = previous._value.concat([]); for (var i = 0; i < this._value.length; i++) { if (this._value[i] instanceof _ParseObject2['default']) { if (!(0, _arrayContainsObject2['default'])(uniques, this._value[i])) { uniques.push(this._value[i]); } } else { if (uniques.indexOf(this._value[i]) < 0) { uniques.push(this._value[i]); } } } return new RemoveOp(uniques); } throw new Error('Cannot merge Remove Op with the previous Op'); } }, { key: 'toJSON', value: function toJSON() { return { __op: 'Remove', objects: (0, _encode2['default'])(this._value, false, true) }; } }]); return RemoveOp; })(Op); exports.RemoveOp = RemoveOp; var RelationOp = (function (_Op7) { _inherits(RelationOp, _Op7); function RelationOp(adds, removes) { _classCallCheck(this, RelationOp); _get(Object.getPrototypeOf(RelationOp.prototype), 'constructor', this).call(this); this._targetClassName = null; if (Array.isArray(adds)) { this.relationsToAdd = (0, _unique2['default'])(adds.map(this._extractId, this)); } if (Array.isArray(removes)) { this.relationsToRemove = (0, _unique2['default'])(removes.map(this._extractId, this)); } } _createClass(RelationOp, [{ key: '_extractId', value: function _extractId(obj) { if (typeof obj === 'string') { return obj; } if (!obj.id) { throw new Error('You cannot add or remove an unsaved Parse Object from a relation'); } if (!this._targetClassName) { this._targetClassName = obj.className; } if (this._targetClassName !== obj.className) { throw new Error('Tried to create a Relation with 2 different object types: ' + this._targetClassName + ' and ' + obj.className + '.'); } return obj.id; } }, { key: 'applyTo', value: function applyTo(value, object, key) { if (!value) { var parent = new _ParseObject2['default'](object.className); if (object.id && object.id.indexOf('local') === 0) { parent._localId = object.id; } else if (object.id) { parent.id = object.id; } var relation = new _ParseRelation2['default'](parent, key); relation.targetClassName = this._targetClassName; return relation; } if (value instanceof _ParseRelation2['default']) { if (this._targetClassName) { if (value.targetClassName) { if (this._targetClassName !== value.targetClassName) { throw new Error('Related object must be a ' + value.targetClassName + ', but a ' + this._targetClassName + ' was passed in.'); } } else { value.targetClassName = this._targetClassName; } } return value; } else { throw new Error('Relation cannot be applied to a non-relation field'); } } }, { key: 'mergeWith', value: function mergeWith(previous) { if (!previous) { return this; } else if (previous instanceof UnsetOp) { throw new Error('You cannot modify a relation after deleting it.'); } else if (previous instanceof RelationOp) { if (previous._targetClassName && previous._targetClassName !== this._targetClassName) { throw new Error('Related object must be of class ' + previous._targetClassName + ', but ' + (this._targetClassName || 'null') + ' was passed in.'); } var newAdd = previous.relationsToAdd.concat([]); this.relationsToRemove.forEach(function (r) { var index = newAdd.indexOf(r); if (index > -1) { newAdd.splice(index, 1); } }); this.relationsToAdd.forEach(function (r) { var index = newAdd.indexOf(r); if (index < 0) { newAdd.push(r); } }); var newRemove = previous.relationsToRemove.concat([]); this.relationsToAdd.forEach(function (r) { var index = newRemove.indexOf(r); if (index > -1) { newRemove.splice(index, 1); } }); this.relationsToRemove.forEach(function (r) { var index = newRemove.indexOf(r); if (index < 0) { newRemove.push(r); } }); var newRelation = new RelationOp(newAdd, newRemove); newRelation._targetClassName = this._targetClassName; return newRelation; } throw new Error('Cannot merge Relation Op with the previous Op'); } }, { key: 'toJSON', value: function toJSON() { var _this = this; var idToPointer = function idToPointer(id) { return { __type: 'Pointer', className: _this._targetClassName, objectId: id }; }; var adds = null; var removes = null; var pointers = null; if (this.relationsToAdd.length > 0) { pointers = this.relationsToAdd.map(idToPointer); adds = { __op: 'AddRelation', objects: pointers }; } if (this.relationsToRemove.length > 0) { pointers = this.relationsToRemove.map(idToPointer); removes = { __op: 'RemoveRelation', objects: pointers }; } if (adds && removes) { return { __op: 'Batch', ops: [adds, removes] }; } return adds || removes || {}; } }]); return RelationOp; })(Op); exports.RelationOp = RelationOp; },{"./ParseObject":14,"./ParseRelation":18,"./arrayContainsObject":27,"./decode":29,"./encode":30,"./unique":35,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/interop-require-default":47}],16:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ // We may want to expose this value at a later time, so that Promises/A+ style // can be employed instead 'use strict'; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _isPromisesAPlusCompliant = false; /** * A Promise is returned by async methods as a hook to provide callbacks to be * called when the async task is fulfilled. * *
Typical usage would be like:
* query.find().then(function(results) { * results[0].set("foo", "bar"); * return results[0].saveAsync(); * }).then(function(result) { * console.log("Updated " + result.id); * }); ** * @class Parse.Promise * @constructor */ var ParsePromise = (function () { function ParsePromise() { _classCallCheck(this, ParsePromise); this._resolved = false; this._rejected = false; this._resolvedCallbacks = []; this._rejectedCallbacks = []; } /** * Marks this promise as fulfilled, firing any callbacks waiting on it. * @method resolve * @param {Object} result the result to pass to the callbacks. */ _createClass(ParsePromise, [{ key: 'resolve', value: function resolve() { if (this._resolved || this._rejected) { throw new Error('A promise was resolved even though it had already been ' + (this._resolved ? 'resolved' : 'rejected') + '.'); } this._resolved = true; for (var _len = arguments.length, results = Array(_len), _key = 0; _key < _len; _key++) { results[_key] = arguments[_key]; } this._result = results; for (var i = 0; i < this._resolvedCallbacks.length; i++) { this._resolvedCallbacks[i].apply(this, results); } this._resolvedCallbacks = []; this._rejectedCallbacks = []; } /** * Marks this promise as fulfilled, firing any callbacks waiting on it. * @method reject * @param {Object} error the error to pass to the callbacks. */ }, { key: 'reject', value: function reject(error) { if (this._resolved || this._rejected) { throw new Error('A promise was resolved even though it had already been ' + (this._resolved ? 'resolved' : 'rejected') + '.'); } this._rejected = true; this._error = error; for (var i = 0; i < this._rejectedCallbacks.length; i++) { this._rejectedCallbacks[i](error); } this._resolvedCallbacks = []; this._rejectedCallbacks = []; } /** * Adds callbacks to be called when this promise is fulfilled. Returns a new * Promise that will be fulfilled when the callback is complete. It allows * chaining. If the callback itself returns a Promise, then the one returned * by "then" will not be fulfilled until that one returned by the callback * is fulfilled. * @method then * @param {Function} resolvedCallback Function that is called when this * Promise is resolved. Once the callback is complete, then the Promise * returned by "then" will also be fulfilled. * @param {Function} rejectedCallback Function that is called when this * Promise is rejected with an error. Once the callback is complete, then * the promise returned by "then" with be resolved successfully. If * rejectedCallback is null, or it returns a rejected Promise, then the * Promise returned by "then" will be rejected with that error. * @return {Parse.Promise} A new Promise that will be fulfilled after this * Promise is fulfilled and either callback has completed. If the callback * returned a Promise, then this Promise will not be fulfilled until that * one is. */ }, { key: 'then', value: function then(resolvedCallback, rejectedCallback) { var _this = this; var promise = new ParsePromise(); var wrappedResolvedCallback = function wrappedResolvedCallback() { for (var _len2 = arguments.length, results = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { results[_key2] = arguments[_key2]; } if (typeof resolvedCallback === 'function') { results = [resolvedCallback.apply(this, results)]; } if (results.length === 1 && ParsePromise.is(results[0])) { results[0].then(function () { promise.resolve.apply(promise, arguments); }, function (error) { promise.reject(error); }); } else { promise.resolve.apply(promise, results); } }; var wrappedRejectedCallback = function wrappedRejectedCallback(error) { var result = []; if (typeof rejectedCallback === 'function') { result = [rejectedCallback(error)]; if (result.length === 1 && ParsePromise.is(result[0])) { result[0].then(function () { promise.resolve.apply(promise, arguments); }, function (error) { promise.reject(error); }); } else { promise.reject(result[0]); } } else { promise.reject(error); } }; var runLater = function runLater(fn) { fn.call(); }; if (this._resolved) { runLater(function () { wrappedResolvedCallback.apply(_this, _this._result); }); } else if (this._rejected) { runLater(function () { wrappedRejectedCallback(_this._error); }); } else { this._resolvedCallbacks.push(wrappedResolvedCallback); this._rejectedCallbacks.push(wrappedRejectedCallback); } return promise; } /** * Add handlers to be called when the promise * is either resolved or rejected * @method always */ }, { key: 'always', value: function always(callback) { return this.then(callback, callback); } /** * Add handlers to be called when the Promise object is resolved * @method done */ }, { key: 'done', value: function done(callback) { return this.then(callback); } /** * Add handlers to be called when the Promise object is rejected * @method fail */ }, { key: 'fail', value: function fail(callback) { return this.then(null, callback); } /** * Run the given callbacks after this promise is fulfilled. * @method _thenRunCallbacks * @param optionsOrCallback {} A Backbone-style options callback, or a * callback function. If this is an options object and contains a "model" * attributes, that will be passed to error callbacks as the first argument. * @param model {} If truthy, this will be passed as the first result of * error callbacks. This is for Backbone-compatability. * @return {Parse.Promise} A promise that will be resolved after the * callbacks are run, with the same result as this. */ }, { key: '_thenRunCallbacks', value: function _thenRunCallbacks(optionsOrCallback, model) { var options = {}; if (typeof optionsOrCallback === 'function') { options.success = function (result) { optionsOrCallback(result, null); }; options.error = function (error) { optionsOrCallback(null, error); }; } else if (typeof optionsOrCallback === 'object') { if (typeof optionsOrCallback.success === 'function') { options.success = optionsOrCallback.success; } if (typeof optionsOrCallback.error === 'function') { options.error = optionsOrCallback.error; } } return this.then(function () { for (var _len3 = arguments.length, results = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { results[_key3] = arguments[_key3]; } if (options.success) { options.success.apply(this, results); } return ParsePromise.as.apply(ParsePromise, arguments); }, function (error) { if (options.error) { if (typeof model !== 'undefined') { options.error(model, error); } else { options.error(error); } } // By explicitly returning a rejected Promise, this will work with // either jQuery or Promises/A+ semantics. return ParsePromise.error(error); }); } /** * Adds a callback function that should be called regardless of whether * this promise failed or succeeded. The callback will be given either the * array of results for its first argument, or the error as its second, * depending on whether this Promise was rejected or resolved. Returns a * new Promise, like "then" would. * @method _continueWith * @param {Function} continuation the callback. */ }, { key: '_continueWith', value: function _continueWith(continuation) { return this.then(function () { return continuation(arguments, null); }, function (error) { return continuation(null, error); }); } /** * Returns true iff the given object fulfils the Promise interface. * @method is * @param {Object} promise The object to test * @static * @return {Boolean} */ }], [{ key: 'is', value: function is(promise) { return typeof promise !== 'undefined' && typeof promise.then === 'function'; } /** * Returns a new promise that is resolved with a given value. * @method as * @param value The value to resolve the promise with * @static * @return {Parse.Promise} the new promise. */ }, { key: 'as', value: function as() { var promise = new ParsePromise(); for (var _len4 = arguments.length, values = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { values[_key4] = arguments[_key4]; } promise.resolve.apply(promise, values); return promise; } /** * Returns a new promise that is rejected with a given error. * @method error * @param error The error to reject the promise with * @static * @return {Parse.Promise} the new promise. */ }, { key: 'error', value: function error() { var promise = new ParsePromise(); for (var _len5 = arguments.length, errors = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { errors[_key5] = arguments[_key5]; } promise.reject.apply(promise, errors); return promise; } /** * Returns a new promise that is fulfilled when all of the input promises * are resolved. If any promise in the list fails, then the returned promise * will fail with the last error. If they all succeed, then the returned * promise will succeed, with the results being the results of all the input * promises. For example:
* var p1 = Parse.Promise.as(1); * var p2 = Parse.Promise.as(2); * var p3 = Parse.Promise.as(3); * * Parse.Promise.when(p1, p2, p3).then(function(r1, r2, r3) { * console.log(r1); // prints 1 * console.log(r2); // prints 2 * console.log(r3); // prints 3 * });* * The input promises can also be specified as an array:
* var promises = [p1, p2, p3]; * Parse.Promise.when(promises).then(function(r1, r2, r3) { * console.log(r1); // prints 1 * console.log(r2); // prints 2 * console.log(r3); // prints 3 * }); ** @method when * @param {Array} promises a list of promises to wait for. * @static * @return {Parse.Promise} the new promise. */ }, { key: 'when', value: function when(promises) { var objects; if (Array.isArray(promises)) { objects = promises; } else { objects = arguments; } var total = objects.length; var hadError = false; var results = []; var errors = []; results.length = objects.length; errors.length = objects.length; if (total === 0) { return ParsePromise.as.apply(this, results); } var promise = new ParsePromise(); var resolveOne = function resolveOne() { total--; if (total <= 0) { if (hadError) { promise.reject(errors); } else { promise.resolve.apply(promise, results); } } }; var chain = function chain(object, index) { if (ParsePromise.is(object)) { object.then(function (result) { results[index] = result; resolveOne(); }, function (error) { errors[index] = error; hadError = true; resolveOne(); }); } else { results[i] = object; resolveOne(); } }; for (var i = 0; i < objects.length; i++) { chain(objects[i], i); } return promise; } /** * Runs the given asyncFunction repeatedly, as long as the predicate * function returns a truthy value. Stops repeating if asyncFunction returns * a rejected promise. * @method _continueWhile * @param {Function} predicate should return false when ready to stop. * @param {Function} asyncFunction should return a Promise. * @static */ }, { key: '_continueWhile', value: function _continueWhile(predicate, asyncFunction) { if (predicate()) { return asyncFunction().then(function () { return ParsePromise._continueWhile(predicate, asyncFunction); }); } return ParsePromise.as(); } }, { key: 'isPromisesAPlusCompliant', value: function isPromisesAPlusCompliant() { return _isPromisesAPlusCompliant; } }]); return ParsePromise; })(); exports['default'] = ParsePromise; module.exports = exports['default']; },{"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44}],17:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ 'use strict'; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _CoreManager = _dereq_('./CoreManager'); var _CoreManager2 = _interopRequireDefault(_CoreManager); var _encode = _dereq_('./encode'); var _encode2 = _interopRequireDefault(_encode); var _ParseError = _dereq_('./ParseError'); var _ParseError2 = _interopRequireDefault(_ParseError); var _ParseGeoPoint = _dereq_('./ParseGeoPoint'); var _ParseGeoPoint2 = _interopRequireDefault(_ParseGeoPoint); var _ParseObject = _dereq_('./ParseObject'); var _ParseObject2 = _interopRequireDefault(_ParseObject); var _ParsePromise = _dereq_('./ParsePromise'); var _ParsePromise2 = _interopRequireDefault(_ParsePromise); /** * Converts a string into a regex that matches it. * Surrounding with \Q .. \E does this, we just need to escape any \E's in * the text separately. */ function quote(s) { return '\\Q' + s.replace('\\E', '\\E\\\\E\\Q') + '\\E'; } /** * Creates a new parse Parse.Query for the given Parse.Object subclass. * @class Parse.Query * @constructor * @param objectClass - * An instance of a subclass of Parse.Object, or a Parse className string. * *
Parse.Query defines a query that is used to fetch Parse.Objects. The
* most common use case is finding all objects that match a query through the
* find
method. For example, this sample code fetches all objects
* of class MyClass
. It calls a different function depending on
* whether the fetch succeeded or not.
*
*
* var query = new Parse.Query(MyClass); * query.find({ * success: function(results) { * // results is an array of Parse.Object. * }, * * error: function(error) { * // error is an instance of Parse.Error. * } * });* *
A Parse.Query can also be used to retrieve a single object whose id is
* known, through the get method. For example, this sample code fetches an
* object of class MyClass
and id myId
. It calls a
* different function depending on whether the fetch succeeded or not.
*
*
* var query = new Parse.Query(MyClass); * query.get(myId, { * success: function(object) { * // object is an instance of Parse.Object. * }, * * error: function(object, error) { * // error is an instance of Parse.Error. * } * });* *
A Parse.Query can also be used to count the number of objects that match
* the query without retrieving all of those objects. For example, this
* sample code counts the number of objects of the class MyClass
*
* var query = new Parse.Query(MyClass); * query.count({ * success: function(number) { * // There are number instances of MyClass. * }, * * error: function(error) { * // error is an instance of Parse.Error. * } * });*/ var ParseQuery = (function () { function ParseQuery(objectClass) { _classCallCheck(this, ParseQuery); if (typeof objectClass === 'string') { this.className = objectClass; } else if (objectClass instanceof _ParseObject2['default']) { this.className = objectClass.className; } else if (typeof objectClass === 'function') { if (typeof objectClass.className === 'string') { this.className = objectClass.className; } else { var obj = new objectClass(); this.className = obj.className; } } else { throw new TypeError('A ParseQuery must be constructed with a ParseObject or class name.'); } this._where = {}; this._include = []; this._limit = -1; // negative limit is not sent in the server request this._skip = 0; this._extraOptions = {}; } /** * Adds constraint that at least one of the passed in queries matches. * @method _orQuery * @param {Array} queries * @return {Parse.Query} Returns the query, so you can chain this call. */ _createClass(ParseQuery, [{ key: '_orQuery', value: function _orQuery(queries) { var queryJSON = queries.map(function (q) { return q.toJSON().where; }); this._where.$or = queryJSON; return this; } /** * Helper for condition queries */ }, { key: '_addCondition', value: function _addCondition(key, condition, value) { if (!this._where[key] || typeof this._where[key] === 'string') { this._where[key] = {}; } this._where[key][condition] = (0, _encode2['default'])(value, false, true); return this; } /** * Returns a JSON representation of this query. * @method toJSON * @return {Object} The JSON representation of the query. */ }, { key: 'toJSON', value: function toJSON() { var params = { where: this._where }; if (this._include.length) { params.include = this._include.join(','); } if (this._select) { params.keys = this._select.join(','); } if (this._limit >= 0) { params.limit = this._limit; } if (this._skip > 0) { params.skip = this._skip; } if (this._order) { params.order = this._order.join(','); } for (var key in this._extraOptions) { params[key] = this._extraOptions[key]; } return params; } /** * Constructs a Parse.Object whose id is already known by fetching data from * the server. Either options.success or options.error is called when the * find completes. * * @method get * @param {String} objectId The id of the object to be fetched. * @param {Object} options A Backbone-style options object. * Valid options are:
var compoundQuery = Parse.Query.or(query1, query2, query3);* * will create a compoundQuery that is an or of the query1, query2, and * query3. * @method or * @param {...Parse.Query} var_args The list of queries to OR. * @static * @return {Parse.Query} The query that is the OR of the passed in queries. */ }], [{ key: 'or', value: function or() { var className = null; for (var _len7 = arguments.length, queries = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { queries[_key7] = arguments[_key7]; } queries.forEach(function (q) { if (!className) { className = q.className; } if (className !== q.className) { throw new Error('All queries must be for the same class.'); } }); var query = new ParseQuery(className); query._orQuery(queries); return query; } }]); return ParseQuery; })(); exports['default'] = ParseQuery; _CoreManager2['default'].setQueryController({ find: function find(className, params, options) { var RESTController = _CoreManager2['default'].getRESTController(); return RESTController.request('GET', 'classes/' + className, params, options); } }); module.exports = exports['default']; },{"./CoreManager":3,"./ParseError":10,"./ParseGeoPoint":12,"./ParseObject":14,"./ParsePromise":16,"./encode":30,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/interop-require-default":47}],18:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ 'use strict'; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _ParseOp = _dereq_('./ParseOp'); var _ParseObject = _dereq_('./ParseObject'); var _ParseObject2 = _interopRequireDefault(_ParseObject); var _ParseQuery = _dereq_('./ParseQuery'); var _ParseQuery2 = _interopRequireDefault(_ParseQuery); /** * Creates a new Relation for the given parent object and key. This * constructor should rarely be used directly, but rather created by * Parse.Object.relation. * @class Parse.Relation * @constructor * @param {Parse.Object} parent The parent of this relation. * @param {String} key The key for this relation on the parent. * *
* A class that is used to access all of the children of a many-to-many * relationship. Each instance of Parse.Relation is associated with a * particular parent object and key. *
*/ var ParseRelation = (function () { function ParseRelation(parent, key) { _classCallCheck(this, ParseRelation); this.parent = parent; this.key = key; this.targetClassName = null; } /** * Makes sure that this relation has the right parent and key. */ _createClass(ParseRelation, [{ key: '_ensureParentAndKey', value: function _ensureParentAndKey(parent, key) { this.key = this.key || key; if (this.key !== key) { throw new Error('Internal Error. Relation retrieved from two different keys.'); } if (this.parent) { if (this.parent.className !== parent.className) { throw new Error('Internal Error. Relation retrieved from two different Objects.'); } if (this.parent.id) { if (this.parent.id !== parent.id) { throw new Error('Internal Error. Relation retrieved from two different Objects.'); } } else if (parent.id) { this.parent = parent; } } else { this.parent = parent; } } /** * Adds a Parse.Object or an array of Parse.Objects to the relation. * @method add * @param {} objects The item or items to add. */ }, { key: 'add', value: function add(objects) { if (!Array.isArray(objects)) { objects = [objects]; } var change = new _ParseOp.RelationOp(objects, []); this.parent.set(this.key, change); this.targetClassName = change._targetClassName; return this.parent; } /** * Removes a Parse.Object or an array of Parse.Objects from this relation. * @method remove * @param {} objects The item or items to remove. */ }, { key: 'remove', value: function remove(objects) { if (!Array.isArray(objects)) { objects = [objects]; } var change = new _ParseOp.RelationOp([], objects); this.parent.set(this.key, change); this.targetClassName = change._targetClassName; } /** * Returns a JSON version of the object suitable for saving to disk. * @method toJSON * @return {Object} */ }, { key: 'toJSON', value: function toJSON() { return { __type: 'Relation', className: this.targetClassName }; } /** * Returns a Parse.Query that is limited to objects in this * relation. * @method query * @return {Parse.Query} */ }, { key: 'query', value: function query() { var query; if (!this.targetClassName) { query = new _ParseQuery2['default'](this.parent.className); query._extraOptions.redirectClassNameForKey = this.key; } else { query = new _ParseQuery2['default'](this.targetClassName); } query._addCondition('$relatedTo', 'object', { __type: 'Pointer', className: this.parent.className, objectId: this.parent.id }); query._addCondition('$relatedTo', 'key', this.key); return query; } }]); return ParseRelation; })(); exports['default'] = ParseRelation; module.exports = exports['default']; },{"./ParseObject":14,"./ParseOp":15,"./ParseQuery":17,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/interop-require-default":47}],19:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ /** * Represents a Role on the Parse server. Roles represent groupings of * Users for the purposes of granting permissions (e.g. specifying an ACL * for an Object). Roles are specified by their sets of child users and * child roles, all of which are granted any permissions that the parent * role has. * *Roles must have a name (which cannot be changed after creation of the * role), and must specify an ACL.
* @class Parse.Role * @constructor * @param {String} name The name of the Role to create. * @param {Parse.ACL} acl The ACL for this role. Roles must have an ACL. * A Parse.Role is a local representation of a role persisted to the Parse * cloud. */ 'use strict'; var _get = _dereq_('babel-runtime/helpers/get')['default']; var _inherits = _dereq_('babel-runtime/helpers/inherits')['default']; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _ParseACL = _dereq_('./ParseACL'); var _ParseACL2 = _interopRequireDefault(_ParseACL); var _ParseError = _dereq_('./ParseError'); var _ParseError2 = _interopRequireDefault(_ParseError); var _ParseObject2 = _dereq_('./ParseObject'); var _ParseObject3 = _interopRequireDefault(_ParseObject2); var ParseRole = (function (_ParseObject) { _inherits(ParseRole, _ParseObject); function ParseRole(name, acl) { _classCallCheck(this, ParseRole); _get(Object.getPrototypeOf(ParseRole.prototype), 'constructor', this).call(this, '_Role'); if (typeof name === 'string' && acl instanceof _ParseACL2['default']) { this.setName(name); this.setACL(acl); } } /** * Gets the name of the role. You can alternatively call role.get("name") * * @method getName * @return {String} the name of the role. */ _createClass(ParseRole, [{ key: 'getName', value: function getName() { return this.get('name'); } /** * Sets the name for a role. This value must be set before the role has * been saved to the server, and cannot be set once the role has been * saved. * ** A role's name can only contain alphanumeric characters, _, -, and * spaces. *
* *This is equivalent to calling role.set("name", name)
* * @method setName * @param {String} name The name of the role. * @param {Object} options Standard options object with success and error * callbacks. */ }, { key: 'setName', value: function setName(name, options) { return this.set('name', name, options); } /** * Gets the Parse.Relation for the Parse.Users that are direct * children of this role. These users are granted any privileges that this * role has been granted (e.g. read or write access through ACLs). You can * add or remove users from the role through this relation. * *This is equivalent to calling role.relation("users")
* * @method getUsers * @return {Parse.Relation} the relation for the users belonging to this * role. */ }, { key: 'getUsers', value: function getUsers() { return this.relation('users'); } /** * Gets the Parse.Relation for the Parse.Roles that are direct * children of this role. These roles' users are granted any privileges that * this role has been granted (e.g. read or write access through ACLs). You * can add or remove child roles from this role through this relation. * *This is equivalent to calling role.relation("roles")
* * @method getRoles * @return {Parse.Relation} the relation for the roles belonging to this * role. */ }, { key: 'getRoles', value: function getRoles() { return this.relation('roles'); } }, { key: 'validate', value: function validate(attrs, options) { var isInvalid = _get(Object.getPrototypeOf(ParseRole.prototype), 'validate', this).call(this, attrs, options); if (isInvalid) { return isInvalid; } if ('name' in attrs && attrs.name !== this.getName()) { var newName = attrs.name; if (this.id && this.id !== attrs.objectId) { // Check to see if the objectId being set matches this.id // This happens during a fetch -- the id is set before calling fetch // Let the name be set in this case return new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'A role\'s name can only be set before it has been saved.'); } if (typeof newName !== 'string') { return new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'A role\'s name must be a String.'); } if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) { return new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'A role\'s name can be only contain alphanumeric characters, _, ' + '-, and spaces.'); } } return false; } }]); return ParseRole; })(_ParseObject3['default']); exports['default'] = ParseRole; _ParseObject3['default'].registerSubclass('_Role', ParseRole); module.exports = exports['default']; },{"./ParseACL":8,"./ParseError":10,"./ParseObject":14,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/interop-require-default":47}],20:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ /** * @class Parse.Session * @constructor * *A Parse.Session object is a local representation of a revocable session. * This class is a subclass of a Parse.Object, and retains the same * functionality of a Parse.Object.
*/ 'use strict'; var _get = _dereq_('babel-runtime/helpers/get')['default']; var _inherits = _dereq_('babel-runtime/helpers/inherits')['default']; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _CoreManager = _dereq_('./CoreManager'); var _CoreManager2 = _interopRequireDefault(_CoreManager); var _isRevocableSession = _dereq_('./isRevocableSession'); var _isRevocableSession2 = _interopRequireDefault(_isRevocableSession); var _ParseObject2 = _dereq_('./ParseObject'); var _ParseObject3 = _interopRequireDefault(_ParseObject2); var _ParsePromise = _dereq_('./ParsePromise'); var _ParsePromise2 = _interopRequireDefault(_ParsePromise); var _ParseUser = _dereq_('./ParseUser'); var _ParseUser2 = _interopRequireDefault(_ParseUser); var ParseSession = (function (_ParseObject) { _inherits(ParseSession, _ParseObject); function ParseSession(attributes) { _classCallCheck(this, ParseSession); _get(Object.getPrototypeOf(ParseSession.prototype), 'constructor', this).call(this, '_Session'); if (attributes && typeof attributes === 'object') { if (!this.set(attributes || {})) { throw new Error('Can\'t create an invalid Session'); } } } /** * Returns the session token string. * @method getSessionToken * @return {String} */ _createClass(ParseSession, [{ key: 'getSessionToken', value: function getSessionToken() { return this.get('sessionToken'); } }], [{ key: 'readOnlyAttributes', value: function readOnlyAttributes() { return ['createdWith', 'expiresAt', 'installationId', 'restricted', 'sessionToken', 'user']; } /** * Retrieves the Session object for the currently logged in session. * @method current * @static * @return {Parse.Promise} A promise that is resolved with the Parse.Session * object after it has been fetched. If there is no current user, the * promise will be rejected. */ }, { key: 'current', value: function current(options) { options = options || {}; var controller = _CoreManager2['default'].getSessionController(); var sessionOptions = {}; if (options.hasOwnProperty('useMasterKey')) { sessionOptions.useMasterKey = options.useMasterKey; } return _ParseUser2['default'].currentAsync().then(function (user) { if (!user) { return _ParsePromise2['default'].error('There is no current user.'); } var token = user.getSessionToken(); sessionOptions.sessionToken = user.getSessionToken(); return controller.getSession(sessionOptions); }); } /** * Determines whether the current session token is revocable. * This method is useful for migrating Express.js or Node.js web apps to * use revocable sessions. If you are migrating an app that uses the Parse * SDK in the browser only, please use Parse.User.enableRevocableSession() * instead, so that sessions can be automatically upgraded. * @method isCurrentSessionRevocable * @static * @return {Boolean} */ }, { key: 'isCurrentSessionRevocable', value: function isCurrentSessionRevocable() { var currentUser = _ParseUser2['default'].current(); if (currentUser) { return (0, _isRevocableSession2['default'])(currentUser.getSessionToken() || ''); } return false; } }]); return ParseSession; })(_ParseObject3['default']); exports['default'] = ParseSession; _ParseObject3['default'].registerSubclass('_Session', ParseSession); _CoreManager2['default'].setSessionController({ getSession: function getSession(options) { var RESTController = _CoreManager2['default'].getRESTController(); var session = new ParseSession(); return RESTController.request('GET', 'sessions/me', {}, options).then(function (sessionData) { session._finishFetch(sessionData); session._setExisted(true); return session; }); } }); module.exports = exports['default']; },{"./CoreManager":3,"./ParseObject":14,"./ParsePromise":16,"./ParseUser":21,"./isRevocableSession":33,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/interop-require-default":47}],21:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ 'use strict'; var _get = _dereq_('babel-runtime/helpers/get')['default']; var _inherits = _dereq_('babel-runtime/helpers/inherits')['default']; var _createClass = _dereq_('babel-runtime/helpers/create-class')['default']; var _classCallCheck = _dereq_('babel-runtime/helpers/class-call-check')['default']; var _Object$defineProperty = _dereq_('babel-runtime/core-js/object/define-property')['default']; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; var _interopRequireWildcard = _dereq_('babel-runtime/helpers/interop-require-wildcard')['default']; Object.defineProperty(exports, '__esModule', { value: true }); var _CoreManager = _dereq_('./CoreManager'); var _CoreManager2 = _interopRequireDefault(_CoreManager); var _isRevocableSession = _dereq_('./isRevocableSession'); var _isRevocableSession2 = _interopRequireDefault(_isRevocableSession); var _ObjectState = _dereq_('./ObjectState'); var ObjectState = _interopRequireWildcard(_ObjectState); var _ParseError = _dereq_('./ParseError'); var _ParseError2 = _interopRequireDefault(_ParseError); var _ParseObject2 = _dereq_('./ParseObject'); var _ParseObject3 = _interopRequireDefault(_ParseObject2); var _ParsePromise = _dereq_('./ParsePromise'); var _ParsePromise2 = _interopRequireDefault(_ParsePromise); var _ParseSession = _dereq_('./ParseSession'); var _ParseSession2 = _interopRequireDefault(_ParseSession); var _Storage = _dereq_('./Storage'); var _Storage2 = _interopRequireDefault(_Storage); var CURRENT_USER_KEY = 'currentUser'; var canUseCurrentUser = !_CoreManager2['default'].get('IS_NODE'); var currentUserCacheMatchesDisk = false; var currentUserCache = null; var authProviders = {}; /** * @class Parse.User * @constructor * *A Parse.User object is a local representation of a user persisted to the * Parse cloud. This class is a subclass of a Parse.Object, and retains the * same functionality of a Parse.Object, but also extends it with various * user specific methods, like authentication, signing up, and validation of * uniqueness.
*/ var ParseUser = (function (_ParseObject) { _inherits(ParseUser, _ParseObject); function ParseUser(attributes) { _classCallCheck(this, ParseUser); _get(Object.getPrototypeOf(ParseUser.prototype), 'constructor', this).call(this, '_User'); if (attributes && typeof attributes === 'object') { if (!this.set(attributes || {})) { throw new Error('Can\'t create an invalid Parse User'); } } } /** * Request a revocable session token to replace the older style of token. * @method _upgradeToRevocableSession * @param {Object} options A Backbone-style options object. * @return {Parse.Promise} A promise that is resolved when the replacement * token has been fetched. */ _createClass(ParseUser, [{ key: '_upgradeToRevocableSession', value: function _upgradeToRevocableSession(options) { options = options || {}; var upgradeOptions = {}; if (options.hasOwnProperty('useMasterKey')) { upgradeOptions.useMasterKey = options.useMasterKey; } var controller = _CoreManager2['default'].getUserController(); return controller.upgradeToRevocableSession(this, upgradeOptions)._thenRunCallbacks(options); } /** * Unlike in the Android/iOS SDKs, logInWith is unnecessary, since you can * call linkWith on the user (even if it doesn't exist yet on the server). * @method _linkWith */ }, { key: '_linkWith', value: function _linkWith(provider, options) { var _this = this; var authType; if (typeof provider === 'string') { authType = provider; provider = authProviders[provider]; } else { authType = provider.getAuthType(); } if (options && options.hasOwnProperty('authData')) { var authData = this.get('authData') || {}; authData[authType] = options.authData; var controller = _CoreManager2['default'].getUserController(); return controller.linkWith(this, authData)._thenRunCallbacks(options, this); } else { var promise = new _ParsePromise2['default'](); provider.authenticate({ success: function success(provider, result) { var opts = {}; opts.authData = result; if (options.success) { opts.success = options.success; } if (options.error) { opts.error = options.error; } _this._linkWith(provider, opts).then(function () { promise.resolve(_this); }); }, error: function error(provider, _error) { if (options.error) { options.error(_this, _error); } promise.reject(_error); } }); return promise; } } /** * Synchronizes auth data for a provider (e.g. puts the access token in the * right place to be used by the Facebook SDK). * @method _synchronizeAuthData */ }, { key: '_synchronizeAuthData', value: function _synchronizeAuthData(provider) { if (!this.isCurrent() || !provider) { return; } var authType; if (typeof provider === 'string') { authType = provider; provider = authProviders[authType]; } else { authType = provider.getAuthType(); } var authData = this.get('authData'); if (!provider || typeof authData !== 'object') { return; } var success = provider.restoreAuthentication(authData[authType]); if (!success) { this._unlinkFrom(provider); } } /** * Synchronizes authData for all providers. * @method _synchronizeAllAuthData */ }, { key: '_synchronizeAllAuthData', value: function _synchronizeAllAuthData() { var authData = this.get('authData'); if (typeof authData !== 'object') { return; } for (var key in authData) { this._synchronizeAuthData(key); } } /** * Removes null values from authData (which exist temporarily for * unlinking) * @method _cleanupAuthData */ }, { key: '_cleanupAuthData', value: function _cleanupAuthData() { if (!this.isCurrent()) { return; } var authData = this.get('authData'); if (typeof authData !== 'object') { return; } for (var key in authData) { if (!authData[key]) { delete authData[key]; } } } /** * Unlinks a user from a service. * @method _unlinkFrom */ }, { key: '_unlinkFrom', value: function _unlinkFrom(provider, options) { var _this2 = this; var authType; if (typeof provider === 'string') { authType = provider; provider = authProviders[provider]; } else { authType = provider.getAuthType(); } return this._linkWith(provider, { authData: null }).then(function () { _this2._synchronizeAuthData(provider); return _ParsePromise2['default'].as(_this2); })._thenRunCallbacks(options); } /** * Checks whether a user is linked to a service. * @method _isLinked */ }, { key: '_isLinked', value: function _isLinked(provider) { var authType; if (typeof provider === 'string') { authType = provider; } else { authType = provider.getAuthType(); } var authData = this.get('authData') || {}; return !!authData[authType]; } /** * Deauthenticates all providers. * @method _logOutWithAll */ }, { key: '_logOutWithAll', value: function _logOutWithAll() { var authData = this.get('authData'); if (typeof authData !== 'object') { return; } for (var key in authData) { this._logOutWith(key); } } /** * Deauthenticates a single provider (e.g. removing access tokens from the * Facebook SDK). * @method _logOutWith */ }, { key: '_logOutWith', value: function _logOutWith(provider) { if (!this.isCurrent()) { return; } if (typeof provider === 'string') { provider = authProviders[provider]; } if (provider && provider.deauthenticate) { provider.deauthenticate(); } } /** * Returns true ifcurrent
would return this user.
* @method isCurrent
* @return {Boolean}
*/
}, {
key: 'isCurrent',
value: function isCurrent() {
var current = ParseUser.current();
return !!current && current.id === this.id;
}
/**
* Returns get("username").
* @method getUsername
* @return {String}
*/
}, {
key: 'getUsername',
value: function getUsername() {
return this.get('username');
}
/**
* Calls set("username", username, options) and returns the result.
* @method setUsername
* @param {String} username
* @param {Object} options A Backbone-style options object.
* @return {Boolean}
*/
}, {
key: 'setUsername',
value: function setUsername(username) {
this.set('username', username);
}
/**
* Calls set("password", password, options) and returns the result.
* @method setPassword
* @param {String} password
* @param {Object} options A Backbone-style options object.
* @return {Boolean}
*/
}, {
key: 'setPassword',
value: function setPassword(password) {
this.set('password', password);
}
/**
* Returns get("email").
* @method getEmail
* @return {String}
*/
}, {
key: 'getEmail',
value: function getEmail() {
return this.get('email');
}
/**
* Calls set("email", email, options) and returns the result.
* @method setEmail
* @param {String} email
* @param {Object} options A Backbone-style options object.
* @return {Boolean}
*/
}, {
key: 'setEmail',
value: function setEmail(email) {
this.set('email', email);
}
/**
* Returns the session token for this user, if the user has been logged in,
* or if it is the result of a query with the master key. Otherwise, returns
* undefined.
* @method getSessionToken
* @return {String} the session token, or undefined
*/
}, {
key: 'getSessionToken',
value: function getSessionToken() {
return this.get('sessionToken');
}
/**
* Checks whether this user is the current user and has been authenticated.
* @method authenticated
* @return (Boolean) whether this user is the current user and is logged in.
*/
}, {
key: 'authenticated',
value: function authenticated() {
var current = ParseUser.current();
return !!this.get('sessionToken') && !!current && current.id === this.id;
}
/**
* Signs up a new user. You should call this instead of save for
* new Parse.Users. This will create a new Parse.User on the server, and
* also persist the session on disk so that you can access the user using
* current
.
*
* A username and password must be set before calling signUp.
* *Calls options.success or options.error on completion.
* * @method signUp * @param {Object} attrs Extra fields to set on the new user, or null. * @param {Object} options A Backbone-style options object. * @return {Parse.Promise} A promise that is fulfilled when the signup * finishes. */ }, { key: 'signUp', value: function signUp(attrs, options) { options = options || {}; var signupOptions = {}; if (options.hasOwnProperty('useMasterKey')) { signupOptions.useMasterKey = options.useMasterKey; } var controller = _CoreManager2['default'].getUserController(); return controller.signUp(this, attrs, signupOptions)._thenRunCallbacks(options, this); } /** * Logs in a Parse.User. On success, this saves the session to disk, * so you can retrieve the currently logged in user using *current
.
*
* A username and password must be set before calling logIn.
* *Calls options.success or options.error on completion.
* * @method logIn * @param {Object} options A Backbone-style options object. * @return {Parse.Promise} A promise that is fulfilled with the user when * the login is complete. */ }, { key: 'logIn', value: function logIn(options) { options = options || {}; var loginOptions = {}; if (options.hasOwnProperty('useMasterKey')) { loginOptions.useMasterKey = options.useMasterKey; } var controller = _CoreManager2['default'].getUserController(); return controller.logIn(this, loginOptions)._thenRunCallbacks(options, this); } }], [{ key: 'readOnlyAttributes', value: function readOnlyAttributes() { return ['sessionToken']; } /** * Adds functionality to the existing Parse.User class * @method extend * @param {Object} protoProps A set of properties to add to the prototype * @param {Object} classProps A set of static properties to add to the class * @static * @return {Class} The newly extended Parse.User class */ }, { key: 'extend', value: function extend(protoProps, classProps) { if (protoProps) { for (var prop in protoProps) { if (prop !== 'className') { _Object$defineProperty(ParseUser.prototype, prop, { value: protoProps[prop], enumerable: false, writable: true, configurable: true }); } } } if (classProps) { for (var prop in classProps) { if (prop !== 'className') { _Object$defineProperty(ParseUser, prop, { value: classProps[prop], enumerable: false, writable: true, configurable: true }); } } } return ParseUser; } /** * Retrieves the currently logged in ParseUser with a valid session, * either from memory or localStorage, if necessary. * @method current * @static * @return {Parse.Object} The currently logged in Parse.User. */ }, { key: 'current', value: function current() { if (!canUseCurrentUser) { return null; } var controller = _CoreManager2['default'].getUserController(); return controller.currentUser(); } /** * Retrieves the currently logged in ParseUser from asynchronous Storage. * @method currentAsync * @static * @return {Parse.Promise} A Promise that is resolved with the currently * logged in Parse User */ }, { key: 'currentAsync', value: function currentAsync() { if (!canUseCurrentUser) { return _ParsePromise2['default'].as(null); } var controller = _CoreManager2['default'].getUserController(); return controller.currentUserAsync(); } /** * Signs up a new user with a username (or email) and password. * This will create a new Parse.User on the server, and also persist the * session in localStorage so that you can access the user using * {@link #current}. * *Calls options.success or options.error on completion.
* * @method signUp * @param {String} username The username (or email) to sign up with. * @param {String} password The password to sign up with. * @param {Object} attrs Extra fields to set on the new user. * @param {Object} options A Backbone-style options object. * @static * @return {Parse.Promise} A promise that is fulfilled with the user when * the signup completes. */ }, { key: 'signUp', value: function signUp(username, password, attrs, options) { attrs = attrs || {}; attrs.username = username; attrs.password = password; var user = new ParseUser(attrs); return user.signUp({}, options); } /** * Logs in a user with a username (or email) and password. On success, this * saves the session to disk, so you can retrieve the currently logged in * user usingcurrent
.
*
* Calls options.success or options.error on completion.
* * @method logIn * @param {String} username The username (or email) to log in with. * @param {String} password The password to log in with. * @param {Object} options A Backbone-style options object. * @static * @return {Parse.Promise} A promise that is fulfilled with the user when * the login completes. */ }, { key: 'logIn', value: function logIn(username, password, options) { var user = new ParseUser(); user._finishFetch({ username: username, password: password }); return user.logIn(options); } /** * Logs in a user with a session token. On success, this saves the session * to disk, so you can retrieve the currently logged in user using *current
.
*
* Calls options.success or options.error on completion.
* * @method become * @param {String} sessionToken The sessionToken to log in with. * @param {Object} options A Backbone-style options object. * @static * @return {Parse.Promise} A promise that is fulfilled with the user when * the login completes. */ }, { key: 'become', value: function become(sessionToken, options) { if (!canUseCurrentUser) { throw new Error('It is not memory-safe to become a user in a server environment'); } options = options || {}; var becomeOptions = { sessionToken: sessionToken }; if (options.hasOwnProperty('useMasterKey')) { becomeOptions.useMasterKey = options.useMasterKey; } var controller = _CoreManager2['default'].getUserController(); return controller.become(becomeOptions)._thenRunCallbacks(options); } }, { key: 'logInWith', value: function logInWith(provider, options) { return ParseUser._logInWith(provider, options); } /** * Logs out the currently logged in user session. This will remove the * session from disk, log out of linked services, and future calls to *current
will return null
.
* @method logOut
* @static
* @return {Parse.Promise} A promise that is resolved when the session is
* destroyed on the server.
*/
}, {
key: 'logOut',
value: function logOut() {
if (!canUseCurrentUser) {
throw new Error('There is no current user user on a node.js server environment.');
}
var controller = _CoreManager2['default'].getUserController();
return controller.logOut();
}
/**
* Requests a password reset email to be sent to the specified email address
* associated with the user account. This email allows the user to securely
* reset their password on the Parse site.
*
* Calls options.success or options.error on completion.
* * @method requestPasswordReset * @param {String} email The email address associated with the user that * forgot their password. * @param {Object} options A Backbone-style options object. * @static */ }, { key: 'requestPasswordReset', value: function requestPasswordReset(email, options) { options = options || {}; var requestOptions = {}; if (options.hasOwnProperty('useMasterKey')) { requestOptions.useMasterKey = options.useMasterKey; } var controller = _CoreManager2['default'].getUserController(); return controller.requestPasswordReset(email, requestOptions)._thenRunCallbacks(options); } /** * Allow someone to define a custom User class without className * being rewritten to _User. The default behavior is to rewrite * User to _User for legacy reasons. This allows developers to * override that behavior. * * @method allowCustomUserClass * @param {Boolean} isAllowed Whether or not to allow custom User class * @static */ }, { key: 'allowCustomUserClass', value: function allowCustomUserClass(isAllowed) { _CoreManager2['default'].set('PERFORM_USER_REWRITE', !isAllowed); } /** * Allows a legacy application to start using revocable sessions. If the * current session token is not revocable, a request will be made for a new, * revocable session. * It is not necessary to call this method from cloud code unless you are * handling user signup or login from the server side. In a cloud code call, * this function will not attempt to upgrade the current token. * @method enableRevocableSession * @param {Object} options A Backbone-style options object. * @static * @return {Parse.Promise} A promise that is resolved when the process has * completed. If a replacement session token is requested, the promise * will be resolved after a new token has been fetched. */ }, { key: 'enableRevocableSession', value: function enableRevocableSession(options) { options = options || {}; _CoreManager2['default'].set('FORCE_REVOCABLE_SESSION', true); if (canUseCurrentUser) { var current = ParseUser.current(); if (current) { return current._upgradeToRevocableSession(options); } } return _ParsePromise2['default'].as()._thenRunCallbacks(options); } /** * Enables the use of become or the current user in a server * environment. These features are disabled by default, since they depend on * global objects that are not memory-safe for most servers. * @method enableUnsafeCurrentUser * @static */ }, { key: 'enableUnsafeCurrentUser', value: function enableUnsafeCurrentUser() { canUseCurrentUser = true; } /** * Disables the use of become or the current user in any environment. * These features are disabled on servers by default, since they depend on * global objects that are not memory-safe for most servers. * @method disableUnsafeCurrentUser * @static */ }, { key: 'disableUnsafeCurrentUser', value: function disableUnsafeCurrentUser() { canUseCurrentUser = false; } }, { key: '_registerAuthenticationProvider', value: function _registerAuthenticationProvider(provider) { authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider. var current = ParseUser.current(); if (current) { current._synchronizeAuthData(provider.getAuthType()); } } }, { key: '_logInWith', value: function _logInWith(provider, options) { var user = new ParseUser(); return user._linkWith(provider, options); } }, { key: '_clearCache', value: function _clearCache() { currentUserCache = null; currentUserCacheMatchesDisk = false; } }, { key: '_setCurrentUserCache', value: function _setCurrentUserCache(user) { currentUserCache = user; } }]); return ParseUser; })(_ParseObject3['default']); exports['default'] = ParseUser; _ParseObject3['default'].registerSubclass('_User', ParseUser); var DefaultController = { setCurrentUser: function setCurrentUser(user) { currentUserCache = user; user._cleanupAuthData(); user._synchronizeAllAuthData(); var path = _Storage2['default'].generatePath(CURRENT_USER_KEY); var json = user.toJSON(); json.className = '_User'; return _Storage2['default'].setItemAsync(path, JSON.stringify(json)).then(function () { return user; }); }, currentUser: function currentUser() { if (currentUserCache) { return currentUserCache; } if (currentUserCacheMatchesDisk) { return null; } if (_Storage2['default'].async()) { throw new Error('Cannot call currentUser() when using a platform with an async ' + 'storage system. Call currentUserAsync() instead.'); } var path = _Storage2['default'].generatePath(CURRENT_USER_KEY); var userData = _Storage2['default'].getItem(path); currentUserCacheMatchesDisk = true; if (!userData) { currentUserCache = null; return null; } userData = JSON.parse(userData); if (!userData.className) { userData.className = '_User'; } if (userData._id) { if (userData.objectId !== userData._id) { userData.objectId = userData._id; } delete userData._id; } if (userData._sessionToken) { userData.sessionToken = userData._sessionToken; delete userData._sessionToken; } var current = ParseUser.fromJSON(userData); currentUserCache = current; current._synchronizeAllAuthData(); return current; }, currentUserAsync: function currentUserAsync() { if (currentUserCache) { return _ParsePromise2['default'].as(currentUserCache); } if (currentUserCacheMatchesDisk) { return _ParsePromise2['default'].as(null); } var path = _Storage2['default'].generatePath(CURRENT_USER_KEY); return _Storage2['default'].getItemAsync(path).then(function (userData) { currentUserCacheMatchesDisk = true; if (!userData) { currentUserCache = null; return _ParsePromise2['default'].as(null); } userData = JSON.parse(userData); if (!userData.className) { userData.className = '_User'; } if (userData._id) { if (userData.objectId !== userData._id) { userData.objectId = userData._id; } delete userData._id; } if (userData._sessionToken) { userData.sessionToken = userData._sessionToken; delete userData._sessionToken; } var current = ParseUser.fromJSON(userData); currentUserCache = current; current._synchronizeAllAuthData(); return _ParsePromise2['default'].as(current); }); }, signUp: function signUp(user, attrs, options) { var username = attrs && attrs.username || user.get('username'); var password = attrs && attrs.password || user.get('password'); if (!username || !username.length) { return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'Cannot sign up user with an empty name.')); } if (!password || !password.length) { return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].OTHER_CAUSE, 'Cannot sign up user with an empty password.')); } return user.save(attrs, options).then(function () { // Clear the password field user._finishFetch({ password: undefined }); if (canUseCurrentUser) { return DefaultController.setCurrentUser(user); } return user; }); }, logIn: function logIn(user, options) { var RESTController = _CoreManager2['default'].getRESTController(); var auth = { username: user.get('username'), password: user.get('password') }; return RESTController.request('GET', 'login', auth, options).then(function (response, status) { user._migrateId(response.objectId); user._setExisted(true); ObjectState.setPendingOp(user.className, user._getId(), 'username', undefined); ObjectState.setPendingOp(user.className, user._getId(), 'password', undefined); response.password = undefined; user._finishFetch(response); if (!canUseCurrentUser) { // We can't set the current user, so just return the one we logged in return _ParsePromise2['default'].as(user); } return DefaultController.setCurrentUser(user); }); }, become: function become(options) { var user = new ParseUser(); var RESTController = _CoreManager2['default'].getRESTController(); return RESTController.request('GET', 'users/me', {}, options).then(function (response, status) { user._finishFetch(response); user._setExisted(true); return DefaultController.setCurrentUser(user); }); }, logOut: function logOut() { return DefaultController.currentUserAsync().then(function (currentUser) { var path = _Storage2['default'].generatePath(CURRENT_USER_KEY); var promise = _Storage2['default'].removeItemAsync(path); var RESTController = _CoreManager2['default'].getRESTController(); if (currentUser !== null) { var currentSession = currentUser.getSessionToken(); if (currentSession && (0, _isRevocableSession2['default'])(currentSession)) { promise.then(function () { return RESTController.request('POST', 'logout', {}, { sessionToken: currentSession }); }); } currentUser._logOutWithAll(); currentUser._finishFetch({ sessionToken: undefined }); } currentUserCacheMatchesDisk = true; currentUserCache = null; return promise; }); }, requestPasswordReset: function requestPasswordReset(email, options) { var RESTController = _CoreManager2['default'].getRESTController(); return RESTController.request('POST', 'requestPasswordReset', { email: email }, options); }, upgradeToRevocableSession: function upgradeToRevocableSession(user, options) { var token = user.getSessionToken(); if (!token) { return _ParsePromise2['default'].error(new _ParseError2['default'](_ParseError2['default'].SESSION_MISSING, 'Cannot upgrade a user with no session token')); } options.sessionToken = token; var RESTController = _CoreManager2['default'].getRESTController(); return RESTController.request('POST', 'upgradeToRevocableSession', {}, options).then(function (result) { var session = new _ParseSession2['default'](); session._finishFetch(result); user._finishFetch({ sessionToken: session.getSessionToken() }); if (user.isCurrent()) { return DefaultController.setCurrentUser(user); } return _ParsePromise2['default'].as(user); }); }, linkWith: function linkWith(user, authData) { return user.save({ authData: authData }).then(function () { if (canUseCurrentUser) { return DefaultController.setCurrentUser(user); } return user; }); } }; _CoreManager2['default'].setUserController(DefaultController); module.exports = exports['default']; },{"./CoreManager":3,"./ObjectState":6,"./ParseError":10,"./ParseObject":14,"./ParsePromise":16,"./ParseSession":20,"./Storage":24,"./isRevocableSession":33,"babel-runtime/core-js/object/define-property":38,"babel-runtime/helpers/class-call-check":43,"babel-runtime/helpers/create-class":44,"babel-runtime/helpers/get":45,"babel-runtime/helpers/inherits":46,"babel-runtime/helpers/interop-require-default":47,"babel-runtime/helpers/interop-require-wildcard":48}],22:[function(_dereq_,module,exports){ /** * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * */ 'use strict'; var _interopRequireDefault = _dereq_('babel-runtime/helpers/interop-require-default')['default']; Object.defineProperty(exports, '__esModule', { value: true }); exports.send = send; var _CoreManager = _dereq_('./CoreManager'); var _CoreManager2 = _interopRequireDefault(_CoreManager); var _ParseQuery = _dereq_('./ParseQuery'); var _ParseQuery2 = _interopRequireDefault(_ParseQuery); /** * Contains functions to deal with Push in Parse. * @class Parse.Push * @static */ /** * Sends a push notification. * @method send * @param {Object} data - The data of the push notification. Valid fields * are: *