Comparing version 1.9.0 to 1.9.1
@@ -16,7 +16,7 @@ /** | ||
// Defaults | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.version.electron, | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron, | ||
REQUEST_ATTEMPT_LIMIT: 5, | ||
SERVER_URL: 'https://api.parse.com/1', | ||
LIVEQUERY_SERVER_URL: null, | ||
VERSION: 'js' + '1.9.0', | ||
VERSION: 'js' + '1.9.1', | ||
APPLICATION_ID: null, | ||
@@ -30,2 +30,10 @@ JAVASCRIPT_KEY: null, | ||
function requireMethods(name, methods, controller) { | ||
methods.forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error(name + ' must implement ' + func + '()'); | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
@@ -46,5 +54,3 @@ get: function get(key) { | ||
setAnalyticsController: function setAnalyticsController(controller) { | ||
if (typeof controller.track !== 'function') { | ||
throw new Error('AnalyticsController must implement track()'); | ||
} | ||
requireMethods('AnalyticsController', ['track'], controller); | ||
config['AnalyticsController'] = controller; | ||
@@ -58,5 +64,3 @@ }, | ||
setCloudController: function setCloudController(controller) { | ||
if (typeof controller.run !== 'function') { | ||
throw new Error('CloudController must implement run()'); | ||
} | ||
requireMethods('CloudController', ['run'], controller); | ||
config['CloudController'] = controller; | ||
@@ -70,8 +74,3 @@ }, | ||
setConfigController: function setConfigController(controller) { | ||
if (typeof controller.current !== 'function') { | ||
throw new Error('ConfigController must implement current()'); | ||
} | ||
if (typeof controller.get !== 'function') { | ||
throw new Error('ConfigController must implement get()'); | ||
} | ||
requireMethods('ConfigController', ['current', 'get'], controller); | ||
config['ConfigController'] = controller; | ||
@@ -85,8 +84,3 @@ }, | ||
setFileController: function setFileController(controller) { | ||
if (typeof controller.saveFile !== 'function') { | ||
throw new Error('FileController must implement saveFile()'); | ||
} | ||
if (typeof controller.saveBase64 !== 'function') { | ||
throw new Error('FileController must implement saveBase64()'); | ||
} | ||
requireMethods('FileController', ['saveFile', 'saveBase64'], controller); | ||
config['FileController'] = controller; | ||
@@ -100,5 +94,3 @@ }, | ||
setInstallationController: function setInstallationController(controller) { | ||
if (typeof controller.currentInstallationId !== 'function') { | ||
throw new Error('InstallationController must implement currentInstallationId()'); | ||
} | ||
requireMethods('InstallationController', ['currentInstallationId'], controller); | ||
config['InstallationController'] = controller; | ||
@@ -112,11 +104,3 @@ }, | ||
setObjectController: function setObjectController(controller) { | ||
if (typeof controller.save !== 'function') { | ||
throw new Error('ObjectController must implement save()'); | ||
} | ||
if (typeof controller.fetch !== 'function') { | ||
throw new Error('ObjectController must implement fetch()'); | ||
} | ||
if (typeof controller.destroy !== 'function') { | ||
throw new Error('ObjectController must implement destroy()'); | ||
} | ||
requireMethods('ObjectController', ['save', 'fetch', 'destroy'], controller); | ||
config['ObjectController'] = controller; | ||
@@ -130,50 +114,3 @@ }, | ||
setObjectStateController: function setObjectStateController(controller) { | ||
if (typeof controller.getState !== 'function') { | ||
throw new Error('ObjectStateController must implement getState()'); | ||
} | ||
if (typeof controller.initializeState !== 'function') { | ||
throw new Error('ObjectStateController must implement initializeState()'); | ||
} | ||
if (typeof controller.removeState !== 'function') { | ||
throw new Error('ObjectStateController must implement removeState()'); | ||
} | ||
if (typeof controller.getServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement getServerData()'); | ||
} | ||
if (typeof controller.setServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement setServerData()'); | ||
} | ||
if (typeof controller.getPendingOps !== 'function') { | ||
throw new Error('ObjectStateController must implement getPendingOps()'); | ||
} | ||
if (typeof controller.setPendingOp !== 'function') { | ||
throw new Error('ObjectStateController must implement setPendingOp()'); | ||
} | ||
if (typeof controller.pushPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement pushPendingState()'); | ||
} | ||
if (typeof controller.popPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement popPendingState()'); | ||
} | ||
if (typeof controller.mergeFirstPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement mergeFirstPendingState()'); | ||
} | ||
if (typeof controller.getObjectCache !== 'function') { | ||
throw new Error('ObjectStateController must implement getObjectCache()'); | ||
} | ||
if (typeof controller.estimateAttribute !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttribute()'); | ||
} | ||
if (typeof controller.estimateAttributes !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttributes()'); | ||
} | ||
if (typeof controller.commitServerChanges !== 'function') { | ||
throw new Error('ObjectStateController must implement commitServerChanges()'); | ||
} | ||
if (typeof controller.enqueueTask !== 'function') { | ||
throw new Error('ObjectStateController must implement enqueueTask()'); | ||
} | ||
if (typeof controller.clearAllState !== 'function') { | ||
throw new Error('ObjectStateController must implement clearAllState()'); | ||
} | ||
requireMethods('ObjectStateController', ['getState', 'initializeState', 'removeState', 'getServerData', 'setServerData', 'getPendingOps', 'setPendingOp', 'pushPendingState', 'popPendingState', 'mergeFirstPendingState', 'getObjectCache', 'estimateAttribute', 'estimateAttributes', 'commitServerChanges', 'enqueueTask', 'clearAllState'], controller); | ||
@@ -188,5 +125,3 @@ config['ObjectStateController'] = controller; | ||
setPushController: function setPushController(controller) { | ||
if (typeof controller.send !== 'function') { | ||
throw new Error('PushController must implement send()'); | ||
} | ||
requireMethods('PushController', ['send'], controller); | ||
config['PushController'] = controller; | ||
@@ -200,5 +135,3 @@ }, | ||
setQueryController: function setQueryController(controller) { | ||
if (typeof controller.find !== 'function') { | ||
throw new Error('QueryController must implement find()'); | ||
} | ||
requireMethods('QueryController', ['find'], controller); | ||
config['QueryController'] = controller; | ||
@@ -212,8 +145,3 @@ }, | ||
setRESTController: function setRESTController(controller) { | ||
if (typeof controller.request !== 'function') { | ||
throw new Error('RESTController must implement request()'); | ||
} | ||
if (typeof controller.ajax !== 'function') { | ||
throw new Error('RESTController must implement ajax()'); | ||
} | ||
requireMethods('RESTController', ['request', 'ajax'], controller); | ||
config['RESTController'] = controller; | ||
@@ -227,5 +155,3 @@ }, | ||
setSessionController: function setSessionController(controller) { | ||
if (typeof controller.getSession !== 'function') { | ||
throw new Error('A SessionController must implement getSession()'); | ||
} | ||
requireMethods('SessionController', ['getSession'], controller); | ||
config['SessionController'] = controller; | ||
@@ -240,21 +166,5 @@ }, | ||
if (controller.async) { | ||
if (typeof controller.getItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement getItemAsync()'); | ||
} | ||
if (typeof controller.setItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement setItemAsync()'); | ||
} | ||
if (typeof controller.removeItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement removeItemAsync()'); | ||
} | ||
requireMethods('An async StorageController', ['getItemAsync', 'setItemAsync', 'removeItemAsync'], controller); | ||
} else { | ||
if (typeof controller.getItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement getItem()'); | ||
} | ||
if (typeof controller.setItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement setItem()'); | ||
} | ||
if (typeof controller.removeItem !== 'function') { | ||
throw new Error('A synchonous StorageController must implement removeItem()'); | ||
} | ||
requireMethods('A synchronous StorageController', ['getItem', 'setItem', 'removeItem'], controller); | ||
} | ||
@@ -269,32 +179,3 @@ config['StorageController'] = controller; | ||
setUserController: function setUserController(controller) { | ||
if (typeof controller.setCurrentUser !== 'function') { | ||
throw new Error('A UserController must implement setCurrentUser()'); | ||
} | ||
if (typeof controller.currentUser !== 'function') { | ||
throw new Error('A UserController must implement currentUser()'); | ||
} | ||
if (typeof controller.currentUserAsync !== 'function') { | ||
throw new Error('A UserController must implement currentUserAsync()'); | ||
} | ||
if (typeof controller.signUp !== 'function') { | ||
throw new Error('A UserController must implement signUp()'); | ||
} | ||
if (typeof controller.logIn !== 'function') { | ||
throw new Error('A UserController must implement logIn()'); | ||
} | ||
if (typeof controller.become !== 'function') { | ||
throw new Error('A UserController must implement become()'); | ||
} | ||
if (typeof controller.logOut !== 'function') { | ||
throw new Error('A UserController must implement logOut()'); | ||
} | ||
if (typeof controller.requestPasswordReset !== 'function') { | ||
throw new Error('A UserController must implement requestPasswordReset()'); | ||
} | ||
if (typeof controller.upgradeToRevocableSession !== 'function') { | ||
throw new Error('A UserController must implement upgradeToRevocableSession()'); | ||
} | ||
if (typeof controller.linkWith !== 'function') { | ||
throw new Error('A UserController must implement linkWith()'); | ||
} | ||
requireMethods('UserController', ['setCurrentUser', 'currentUser', 'currentUserAsync', 'signUp', 'logIn', 'become', 'logOut', 'requestPasswordReset', 'upgradeToRevocableSession', 'linkWith'], controller); | ||
config['UserController'] = controller; | ||
@@ -308,14 +189,3 @@ }, | ||
setLiveQueryController: function setLiveQueryController(controller) { | ||
if (typeof controller.subscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement subscribe()'); | ||
} | ||
if (typeof controller.unsubscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement unsubscribe()'); | ||
} | ||
if (typeof controller.open !== 'function') { | ||
throw new Error('LiveQueryController must implement open()'); | ||
} | ||
if (typeof controller.close !== 'function') { | ||
throw new Error('LiveQueryController must implement close()'); | ||
} | ||
requireMethods('LiveQueryController', ['subscribe', 'unsubscribe', 'open', 'close'], controller); | ||
config['LiveQueryController'] = controller; | ||
@@ -329,7 +199,3 @@ }, | ||
setHooksController: function setHooksController(controller) { | ||
['create', 'get', 'update', 'remove'].forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error('A HooksController must implement ' + func + '()'); | ||
} | ||
}); | ||
requireMethods('HooksController', ['create', 'get', 'update', 'remove'], controller); | ||
config['HooksController'] = controller; | ||
@@ -336,0 +202,0 @@ }, |
@@ -116,3 +116,5 @@ /** | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
if (id) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -135,3 +137,5 @@ value = pendingOps[i][attr].applyTo(value); | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
if (id) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -138,0 +142,0 @@ data[attr] = pendingOps[i][attr].applyTo(data[attr]); |
@@ -136,3 +136,7 @@ /** | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name = userId.getName(); | ||
if (!_name) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name; | ||
} | ||
@@ -170,4 +174,11 @@ if (typeof userId !== 'string') { | ||
userId = userId.id; | ||
if (!userId) { | ||
throw new Error('Cannot get access for a ParseUser without an ID'); | ||
} | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name2 = userId.getName(); | ||
if (!_name2) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name2; | ||
} | ||
@@ -174,0 +185,0 @@ var permissions = this.permissionsById[userId]; |
@@ -90,34 +90,37 @@ /** | ||
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 commaIndex = data.base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(data.base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
if (data !== undefined) { | ||
if (Array.isArray(data)) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
base64: ParseFile.encodeBase64(data), | ||
type: specifiedType | ||
}; | ||
} else { | ||
} else if (typeof File !== 'undefined' && data instanceof File) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64, | ||
format: 'file', | ||
file: data, | ||
type: specifiedType | ||
}; | ||
} else if (data && typeof data.base64 !== 'undefined') { | ||
var _base64 = data.base64; | ||
var commaIndex = _base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(_base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
}; | ||
} else { | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64, | ||
type: specifiedType | ||
}; | ||
} | ||
} else { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
} else if (typeof data !== 'undefined') { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
@@ -254,3 +257,4 @@ } | ||
'X-Parse-Application-ID': _CoreManager2['default'].get('APPLICATION_ID'), | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY') | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY'), | ||
'Content-Type': source.type || (source.file ? source.file.type : null) | ||
}; | ||
@@ -257,0 +261,0 @@ var url = _CoreManager2['default'].get('SERVER_URL'); |
@@ -216,8 +216,8 @@ /** | ||
if (singleInstance) { | ||
var id = this.id; | ||
if (!id) { | ||
id = this._getId(); | ||
var _id = this.id; | ||
if (!_id) { | ||
_id = this._getId(); | ||
} | ||
return { | ||
id: id, | ||
id: _id, | ||
className: this.className | ||
@@ -694,3 +694,5 @@ }; | ||
} else if (k === 'objectId' || k === 'id') { | ||
this.id = changes[k]; | ||
if (typeof changes[k] === 'string') { | ||
this.id = changes[k]; | ||
} | ||
} else if (k === 'ACL' && typeof changes[k] === 'object' && !(changes[k] instanceof _ParseACL2['default'])) { | ||
@@ -884,3 +886,5 @@ newOps[k] = new _ParseOp.SetOp(new _ParseACL2['default'](changes[k])); | ||
var stateController = _CoreManager2['default'].getObjectStateController(); | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
if (stateController) { | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
} | ||
return clone; | ||
@@ -1143,5 +1147,5 @@ } | ||
if (options.hasOwnProperty('useMasterKey')) { | ||
saveOptions.useMasterKey = options.useMasterKey; | ||
saveOptions.useMasterKey = !!options.useMasterKey; | ||
} | ||
if (options.hasOwnProperty('sessionToken')) { | ||
if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') { | ||
saveOptions.sessionToken = options.sessionToken; | ||
@@ -1573,2 +1577,4 @@ } | ||
var ParseObjectSubclass = function ParseObjectSubclass(attributes, options) { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
// Enable legacy initializers | ||
@@ -1579,4 +1585,2 @@ if (typeof this.initialize === 'function') { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
if (attributes && typeof attributes === 'object') { | ||
@@ -1583,0 +1587,0 @@ if (!this.set(attributes || {}, options)) { |
@@ -466,2 +466,5 @@ /** | ||
if (!value) { | ||
if (!object || !key) { | ||
throw new Error('Cannot apply a RelationOp without either a previous value, or an object and a key'); | ||
} | ||
var parent = new _ParseObject2['default'](object.className); | ||
@@ -468,0 +471,0 @@ if (object.id && object.id.indexOf('local') === 0) { |
@@ -99,5 +99,9 @@ /** | ||
var change = new _ParseOp.RelationOp(objects, []); | ||
this.parent.set(this.key, change); | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot add to a Relation without a parent'); | ||
} | ||
parent.set(this.key, change); | ||
this.targetClassName = change._targetClassName; | ||
return this.parent; | ||
return parent; | ||
} | ||
@@ -118,2 +122,5 @@ | ||
var change = new _ParseOp.RelationOp([], objects); | ||
if (!this.parent) { | ||
throw new Error('Cannot remove from a Relation without a parent'); | ||
} | ||
this.parent.set(this.key, change); | ||
@@ -147,4 +154,8 @@ this.targetClassName = change._targetClassName; | ||
var query; | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot construct a query for a Relation without a parent'); | ||
} | ||
if (!this.targetClassName) { | ||
query = new _ParseQuery2['default'](this.parent.className); | ||
query = new _ParseQuery2['default'](parent.className); | ||
query._extraOptions.redirectClassNameForKey = this.key; | ||
@@ -156,4 +167,4 @@ } else { | ||
__type: 'Pointer', | ||
className: this.parent.className, | ||
objectId: this.parent.id | ||
className: parent.className, | ||
objectId: parent.id | ||
}); | ||
@@ -160,0 +171,0 @@ query._addCondition('$relatedTo', 'key', this.key); |
@@ -79,3 +79,7 @@ /** | ||
value: function getName() { | ||
return this.get('name'); | ||
var name = this.get('name'); | ||
if (name == null || typeof name === 'string') { | ||
return name; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ |
@@ -79,3 +79,7 @@ /** | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ }], [{ |
@@ -131,2 +131,5 @@ /** | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
throw new Error('Invalid type: authData field should be an object'); | ||
} | ||
authData[authType] = options.authData; | ||
@@ -184,3 +187,3 @@ | ||
var authData = this.get('authData'); | ||
if (!provider || typeof authData !== 'object') { | ||
if (!provider || !authData || typeof authData !== 'object') { | ||
return; | ||
@@ -270,2 +273,5 @@ } | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
return false; | ||
} | ||
return !!authData[authType]; | ||
@@ -342,3 +348,7 @@ } | ||
value: function getUsername() { | ||
return this.get('username'); | ||
var username = this.get('username'); | ||
if (username == null || typeof username === 'string') { | ||
return username; | ||
} | ||
return ''; | ||
} | ||
@@ -359,3 +369,3 @@ | ||
var authData = this.get('authData'); | ||
if (authData && authData.hasOwnProperty('anonymous')) { | ||
if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) { | ||
// We need to set anonymous to null instead of deleting it in order to remove it from Parse. | ||
@@ -388,3 +398,7 @@ authData.anonymous = null; | ||
value: function getEmail() { | ||
return this.get('email'); | ||
var email = this.get('email'); | ||
if (email == null || typeof email === 'string') { | ||
return email; | ||
} | ||
return ''; | ||
} | ||
@@ -415,3 +429,7 @@ | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (token == null || typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -418,0 +436,0 @@ |
@@ -126,3 +126,5 @@ /** | ||
headers = headers || {}; | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
if (typeof headers['Content-Type'] !== 'string') { | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
} | ||
if (_CoreManager2['default'].get('IS_NODE')) { | ||
@@ -129,0 +131,0 @@ headers['User-Agent'] = 'Parse/' + _CoreManager2['default'].get('VERSION') + ' (NodeJS ' + process.versions.node + ')'; |
@@ -35,2 +35,3 @@ /** | ||
exports.clearAllState = clearAllState; | ||
exports.duplicateState = duplicateState; | ||
@@ -148,2 +149,6 @@ var _ObjectStateMutations = require('./ObjectStateMutations'); | ||
objectState = {}; | ||
} | ||
function duplicateState(source, dest) { | ||
dest.id = source.id; | ||
} |
@@ -16,7 +16,7 @@ /** | ||
// Defaults | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.version.electron, | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron, | ||
REQUEST_ATTEMPT_LIMIT: 5, | ||
SERVER_URL: 'https://api.parse.com/1', | ||
LIVEQUERY_SERVER_URL: null, | ||
VERSION: 'js' + '1.9.0', | ||
VERSION: 'js' + '1.9.1', | ||
APPLICATION_ID: null, | ||
@@ -30,2 +30,10 @@ JAVASCRIPT_KEY: null, | ||
function requireMethods(name, methods, controller) { | ||
methods.forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error(name + ' must implement ' + func + '()'); | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
@@ -46,5 +54,3 @@ get: function get(key) { | ||
setAnalyticsController: function setAnalyticsController(controller) { | ||
if (typeof controller.track !== 'function') { | ||
throw new Error('AnalyticsController must implement track()'); | ||
} | ||
requireMethods('AnalyticsController', ['track'], controller); | ||
config['AnalyticsController'] = controller; | ||
@@ -58,5 +64,3 @@ }, | ||
setCloudController: function setCloudController(controller) { | ||
if (typeof controller.run !== 'function') { | ||
throw new Error('CloudController must implement run()'); | ||
} | ||
requireMethods('CloudController', ['run'], controller); | ||
config['CloudController'] = controller; | ||
@@ -70,8 +74,3 @@ }, | ||
setConfigController: function setConfigController(controller) { | ||
if (typeof controller.current !== 'function') { | ||
throw new Error('ConfigController must implement current()'); | ||
} | ||
if (typeof controller.get !== 'function') { | ||
throw new Error('ConfigController must implement get()'); | ||
} | ||
requireMethods('ConfigController', ['current', 'get'], controller); | ||
config['ConfigController'] = controller; | ||
@@ -85,8 +84,3 @@ }, | ||
setFileController: function setFileController(controller) { | ||
if (typeof controller.saveFile !== 'function') { | ||
throw new Error('FileController must implement saveFile()'); | ||
} | ||
if (typeof controller.saveBase64 !== 'function') { | ||
throw new Error('FileController must implement saveBase64()'); | ||
} | ||
requireMethods('FileController', ['saveFile', 'saveBase64'], controller); | ||
config['FileController'] = controller; | ||
@@ -100,5 +94,3 @@ }, | ||
setInstallationController: function setInstallationController(controller) { | ||
if (typeof controller.currentInstallationId !== 'function') { | ||
throw new Error('InstallationController must implement currentInstallationId()'); | ||
} | ||
requireMethods('InstallationController', ['currentInstallationId'], controller); | ||
config['InstallationController'] = controller; | ||
@@ -112,11 +104,3 @@ }, | ||
setObjectController: function setObjectController(controller) { | ||
if (typeof controller.save !== 'function') { | ||
throw new Error('ObjectController must implement save()'); | ||
} | ||
if (typeof controller.fetch !== 'function') { | ||
throw new Error('ObjectController must implement fetch()'); | ||
} | ||
if (typeof controller.destroy !== 'function') { | ||
throw new Error('ObjectController must implement destroy()'); | ||
} | ||
requireMethods('ObjectController', ['save', 'fetch', 'destroy'], controller); | ||
config['ObjectController'] = controller; | ||
@@ -130,50 +114,3 @@ }, | ||
setObjectStateController: function setObjectStateController(controller) { | ||
if (typeof controller.getState !== 'function') { | ||
throw new Error('ObjectStateController must implement getState()'); | ||
} | ||
if (typeof controller.initializeState !== 'function') { | ||
throw new Error('ObjectStateController must implement initializeState()'); | ||
} | ||
if (typeof controller.removeState !== 'function') { | ||
throw new Error('ObjectStateController must implement removeState()'); | ||
} | ||
if (typeof controller.getServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement getServerData()'); | ||
} | ||
if (typeof controller.setServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement setServerData()'); | ||
} | ||
if (typeof controller.getPendingOps !== 'function') { | ||
throw new Error('ObjectStateController must implement getPendingOps()'); | ||
} | ||
if (typeof controller.setPendingOp !== 'function') { | ||
throw new Error('ObjectStateController must implement setPendingOp()'); | ||
} | ||
if (typeof controller.pushPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement pushPendingState()'); | ||
} | ||
if (typeof controller.popPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement popPendingState()'); | ||
} | ||
if (typeof controller.mergeFirstPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement mergeFirstPendingState()'); | ||
} | ||
if (typeof controller.getObjectCache !== 'function') { | ||
throw new Error('ObjectStateController must implement getObjectCache()'); | ||
} | ||
if (typeof controller.estimateAttribute !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttribute()'); | ||
} | ||
if (typeof controller.estimateAttributes !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttributes()'); | ||
} | ||
if (typeof controller.commitServerChanges !== 'function') { | ||
throw new Error('ObjectStateController must implement commitServerChanges()'); | ||
} | ||
if (typeof controller.enqueueTask !== 'function') { | ||
throw new Error('ObjectStateController must implement enqueueTask()'); | ||
} | ||
if (typeof controller.clearAllState !== 'function') { | ||
throw new Error('ObjectStateController must implement clearAllState()'); | ||
} | ||
requireMethods('ObjectStateController', ['getState', 'initializeState', 'removeState', 'getServerData', 'setServerData', 'getPendingOps', 'setPendingOp', 'pushPendingState', 'popPendingState', 'mergeFirstPendingState', 'getObjectCache', 'estimateAttribute', 'estimateAttributes', 'commitServerChanges', 'enqueueTask', 'clearAllState'], controller); | ||
@@ -188,5 +125,3 @@ config['ObjectStateController'] = controller; | ||
setPushController: function setPushController(controller) { | ||
if (typeof controller.send !== 'function') { | ||
throw new Error('PushController must implement send()'); | ||
} | ||
requireMethods('PushController', ['send'], controller); | ||
config['PushController'] = controller; | ||
@@ -200,5 +135,3 @@ }, | ||
setQueryController: function setQueryController(controller) { | ||
if (typeof controller.find !== 'function') { | ||
throw new Error('QueryController must implement find()'); | ||
} | ||
requireMethods('QueryController', ['find'], controller); | ||
config['QueryController'] = controller; | ||
@@ -212,8 +145,3 @@ }, | ||
setRESTController: function setRESTController(controller) { | ||
if (typeof controller.request !== 'function') { | ||
throw new Error('RESTController must implement request()'); | ||
} | ||
if (typeof controller.ajax !== 'function') { | ||
throw new Error('RESTController must implement ajax()'); | ||
} | ||
requireMethods('RESTController', ['request', 'ajax'], controller); | ||
config['RESTController'] = controller; | ||
@@ -227,5 +155,3 @@ }, | ||
setSessionController: function setSessionController(controller) { | ||
if (typeof controller.getSession !== 'function') { | ||
throw new Error('A SessionController must implement getSession()'); | ||
} | ||
requireMethods('SessionController', ['getSession'], controller); | ||
config['SessionController'] = controller; | ||
@@ -240,21 +166,5 @@ }, | ||
if (controller.async) { | ||
if (typeof controller.getItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement getItemAsync()'); | ||
} | ||
if (typeof controller.setItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement setItemAsync()'); | ||
} | ||
if (typeof controller.removeItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement removeItemAsync()'); | ||
} | ||
requireMethods('An async StorageController', ['getItemAsync', 'setItemAsync', 'removeItemAsync'], controller); | ||
} else { | ||
if (typeof controller.getItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement getItem()'); | ||
} | ||
if (typeof controller.setItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement setItem()'); | ||
} | ||
if (typeof controller.removeItem !== 'function') { | ||
throw new Error('A synchonous StorageController must implement removeItem()'); | ||
} | ||
requireMethods('A synchronous StorageController', ['getItem', 'setItem', 'removeItem'], controller); | ||
} | ||
@@ -269,32 +179,3 @@ config['StorageController'] = controller; | ||
setUserController: function setUserController(controller) { | ||
if (typeof controller.setCurrentUser !== 'function') { | ||
throw new Error('A UserController must implement setCurrentUser()'); | ||
} | ||
if (typeof controller.currentUser !== 'function') { | ||
throw new Error('A UserController must implement currentUser()'); | ||
} | ||
if (typeof controller.currentUserAsync !== 'function') { | ||
throw new Error('A UserController must implement currentUserAsync()'); | ||
} | ||
if (typeof controller.signUp !== 'function') { | ||
throw new Error('A UserController must implement signUp()'); | ||
} | ||
if (typeof controller.logIn !== 'function') { | ||
throw new Error('A UserController must implement logIn()'); | ||
} | ||
if (typeof controller.become !== 'function') { | ||
throw new Error('A UserController must implement become()'); | ||
} | ||
if (typeof controller.logOut !== 'function') { | ||
throw new Error('A UserController must implement logOut()'); | ||
} | ||
if (typeof controller.requestPasswordReset !== 'function') { | ||
throw new Error('A UserController must implement requestPasswordReset()'); | ||
} | ||
if (typeof controller.upgradeToRevocableSession !== 'function') { | ||
throw new Error('A UserController must implement upgradeToRevocableSession()'); | ||
} | ||
if (typeof controller.linkWith !== 'function') { | ||
throw new Error('A UserController must implement linkWith()'); | ||
} | ||
requireMethods('UserController', ['setCurrentUser', 'currentUser', 'currentUserAsync', 'signUp', 'logIn', 'become', 'logOut', 'requestPasswordReset', 'upgradeToRevocableSession', 'linkWith'], controller); | ||
config['UserController'] = controller; | ||
@@ -308,14 +189,3 @@ }, | ||
setLiveQueryController: function setLiveQueryController(controller) { | ||
if (typeof controller.subscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement subscribe()'); | ||
} | ||
if (typeof controller.unsubscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement unsubscribe()'); | ||
} | ||
if (typeof controller.open !== 'function') { | ||
throw new Error('LiveQueryController must implement open()'); | ||
} | ||
if (typeof controller.close !== 'function') { | ||
throw new Error('LiveQueryController must implement close()'); | ||
} | ||
requireMethods('LiveQueryController', ['subscribe', 'unsubscribe', 'open', 'close'], controller); | ||
config['LiveQueryController'] = controller; | ||
@@ -329,7 +199,3 @@ }, | ||
setHooksController: function setHooksController(controller) { | ||
['create', 'get', 'update', 'remove'].forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error('A HooksController must implement ' + func + '()'); | ||
} | ||
}); | ||
requireMethods('HooksController', ['create', 'get', 'update', 'remove'], controller); | ||
config['HooksController'] = controller; | ||
@@ -336,0 +202,0 @@ }, |
@@ -116,3 +116,5 @@ /** | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
if (id) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -135,3 +137,5 @@ value = pendingOps[i][attr].applyTo(value); | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
if (id) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -138,0 +142,0 @@ data[attr] = pendingOps[i][attr].applyTo(data[attr]); |
@@ -136,3 +136,7 @@ /** | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name = userId.getName(); | ||
if (!_name) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name; | ||
} | ||
@@ -170,4 +174,11 @@ if (typeof userId !== 'string') { | ||
userId = userId.id; | ||
if (!userId) { | ||
throw new Error('Cannot get access for a ParseUser without an ID'); | ||
} | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name2 = userId.getName(); | ||
if (!_name2) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name2; | ||
} | ||
@@ -174,0 +185,0 @@ var permissions = this.permissionsById[userId]; |
@@ -90,34 +90,37 @@ /** | ||
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 commaIndex = data.base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(data.base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
if (data !== undefined) { | ||
if (Array.isArray(data)) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
base64: ParseFile.encodeBase64(data), | ||
type: specifiedType | ||
}; | ||
} else { | ||
} else if (typeof File !== 'undefined' && data instanceof File) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64, | ||
format: 'file', | ||
file: data, | ||
type: specifiedType | ||
}; | ||
} else if (data && typeof data.base64 !== 'undefined') { | ||
var _base64 = data.base64; | ||
var commaIndex = _base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(_base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
}; | ||
} else { | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64, | ||
type: specifiedType | ||
}; | ||
} | ||
} else { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
} else if (typeof data !== 'undefined') { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
@@ -254,3 +257,4 @@ } | ||
'X-Parse-Application-ID': _CoreManager2['default'].get('APPLICATION_ID'), | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY') | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY'), | ||
'Content-Type': source.type || (source.file ? source.file.type : null) | ||
}; | ||
@@ -257,0 +261,0 @@ var url = _CoreManager2['default'].get('SERVER_URL'); |
@@ -216,8 +216,8 @@ /** | ||
if (singleInstance) { | ||
var id = this.id; | ||
if (!id) { | ||
id = this._getId(); | ||
var _id = this.id; | ||
if (!_id) { | ||
_id = this._getId(); | ||
} | ||
return { | ||
id: id, | ||
id: _id, | ||
className: this.className | ||
@@ -694,3 +694,5 @@ }; | ||
} else if (k === 'objectId' || k === 'id') { | ||
this.id = changes[k]; | ||
if (typeof changes[k] === 'string') { | ||
this.id = changes[k]; | ||
} | ||
} else if (k === 'ACL' && typeof changes[k] === 'object' && !(changes[k] instanceof _ParseACL2['default'])) { | ||
@@ -884,3 +886,5 @@ newOps[k] = new _ParseOp.SetOp(new _ParseACL2['default'](changes[k])); | ||
var stateController = _CoreManager2['default'].getObjectStateController(); | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
if (stateController) { | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
} | ||
return clone; | ||
@@ -1143,5 +1147,5 @@ } | ||
if (options.hasOwnProperty('useMasterKey')) { | ||
saveOptions.useMasterKey = options.useMasterKey; | ||
saveOptions.useMasterKey = !!options.useMasterKey; | ||
} | ||
if (options.hasOwnProperty('sessionToken')) { | ||
if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') { | ||
saveOptions.sessionToken = options.sessionToken; | ||
@@ -1573,2 +1577,4 @@ } | ||
var ParseObjectSubclass = function ParseObjectSubclass(attributes, options) { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
// Enable legacy initializers | ||
@@ -1579,4 +1585,2 @@ if (typeof this.initialize === 'function') { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
if (attributes && typeof attributes === 'object') { | ||
@@ -1583,0 +1587,0 @@ if (!this.set(attributes || {}, options)) { |
@@ -466,2 +466,5 @@ /** | ||
if (!value) { | ||
if (!object || !key) { | ||
throw new Error('Cannot apply a RelationOp without either a previous value, or an object and a key'); | ||
} | ||
var parent = new _ParseObject2['default'](object.className); | ||
@@ -468,0 +471,0 @@ if (object.id && object.id.indexOf('local') === 0) { |
@@ -99,5 +99,9 @@ /** | ||
var change = new _ParseOp.RelationOp(objects, []); | ||
this.parent.set(this.key, change); | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot add to a Relation without a parent'); | ||
} | ||
parent.set(this.key, change); | ||
this.targetClassName = change._targetClassName; | ||
return this.parent; | ||
return parent; | ||
} | ||
@@ -118,2 +122,5 @@ | ||
var change = new _ParseOp.RelationOp([], objects); | ||
if (!this.parent) { | ||
throw new Error('Cannot remove from a Relation without a parent'); | ||
} | ||
this.parent.set(this.key, change); | ||
@@ -147,4 +154,8 @@ this.targetClassName = change._targetClassName; | ||
var query; | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot construct a query for a Relation without a parent'); | ||
} | ||
if (!this.targetClassName) { | ||
query = new _ParseQuery2['default'](this.parent.className); | ||
query = new _ParseQuery2['default'](parent.className); | ||
query._extraOptions.redirectClassNameForKey = this.key; | ||
@@ -156,4 +167,4 @@ } else { | ||
__type: 'Pointer', | ||
className: this.parent.className, | ||
objectId: this.parent.id | ||
className: parent.className, | ||
objectId: parent.id | ||
}); | ||
@@ -160,0 +171,0 @@ query._addCondition('$relatedTo', 'key', this.key); |
@@ -79,3 +79,7 @@ /** | ||
value: function getName() { | ||
return this.get('name'); | ||
var name = this.get('name'); | ||
if (name == null || typeof name === 'string') { | ||
return name; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ |
@@ -79,3 +79,7 @@ /** | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ }], [{ |
@@ -131,2 +131,5 @@ /** | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
throw new Error('Invalid type: authData field should be an object'); | ||
} | ||
authData[authType] = options.authData; | ||
@@ -184,3 +187,3 @@ | ||
var authData = this.get('authData'); | ||
if (!provider || typeof authData !== 'object') { | ||
if (!provider || !authData || typeof authData !== 'object') { | ||
return; | ||
@@ -270,2 +273,5 @@ } | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
return false; | ||
} | ||
return !!authData[authType]; | ||
@@ -342,3 +348,7 @@ } | ||
value: function getUsername() { | ||
return this.get('username'); | ||
var username = this.get('username'); | ||
if (username == null || typeof username === 'string') { | ||
return username; | ||
} | ||
return ''; | ||
} | ||
@@ -359,3 +369,3 @@ | ||
var authData = this.get('authData'); | ||
if (authData && authData.hasOwnProperty('anonymous')) { | ||
if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) { | ||
// We need to set anonymous to null instead of deleting it in order to remove it from Parse. | ||
@@ -388,3 +398,7 @@ authData.anonymous = null; | ||
value: function getEmail() { | ||
return this.get('email'); | ||
var email = this.get('email'); | ||
if (email == null || typeof email === 'string') { | ||
return email; | ||
} | ||
return ''; | ||
} | ||
@@ -415,3 +429,7 @@ | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (token == null || typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -418,0 +436,0 @@ |
@@ -128,3 +128,5 @@ /** | ||
headers = headers || {}; | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
if (typeof headers['Content-Type'] !== 'string') { | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
} | ||
if (_CoreManager2['default'].get('IS_NODE')) { | ||
@@ -131,0 +133,0 @@ headers['User-Agent'] = 'Parse/' + _CoreManager2['default'].get('VERSION') + ' (NodeJS ' + process.versions.node + ')'; |
@@ -35,2 +35,3 @@ /** | ||
exports.clearAllState = clearAllState; | ||
exports.duplicateState = duplicateState; | ||
@@ -148,2 +149,6 @@ var _ObjectStateMutations = require('./ObjectStateMutations'); | ||
objectState = {}; | ||
} | ||
function duplicateState(source, dest) { | ||
dest.id = source.id; | ||
} |
@@ -16,7 +16,7 @@ /** | ||
// Defaults | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.version.electron, | ||
IS_NODE: typeof process !== 'undefined' && !!process.versions && !!process.versions.node && !process.versions.electron, | ||
REQUEST_ATTEMPT_LIMIT: 5, | ||
SERVER_URL: 'https://api.parse.com/1', | ||
LIVEQUERY_SERVER_URL: null, | ||
VERSION: 'js' + '1.9.0', | ||
VERSION: 'js' + '1.9.1', | ||
APPLICATION_ID: null, | ||
@@ -30,2 +30,10 @@ JAVASCRIPT_KEY: null, | ||
function requireMethods(name, methods, controller) { | ||
methods.forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error(name + ' must implement ' + func + '()'); | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
@@ -46,5 +54,3 @@ get: function get(key) { | ||
setAnalyticsController: function setAnalyticsController(controller) { | ||
if (typeof controller.track !== 'function') { | ||
throw new Error('AnalyticsController must implement track()'); | ||
} | ||
requireMethods('AnalyticsController', ['track'], controller); | ||
config['AnalyticsController'] = controller; | ||
@@ -58,5 +64,3 @@ }, | ||
setCloudController: function setCloudController(controller) { | ||
if (typeof controller.run !== 'function') { | ||
throw new Error('CloudController must implement run()'); | ||
} | ||
requireMethods('CloudController', ['run'], controller); | ||
config['CloudController'] = controller; | ||
@@ -70,8 +74,3 @@ }, | ||
setConfigController: function setConfigController(controller) { | ||
if (typeof controller.current !== 'function') { | ||
throw new Error('ConfigController must implement current()'); | ||
} | ||
if (typeof controller.get !== 'function') { | ||
throw new Error('ConfigController must implement get()'); | ||
} | ||
requireMethods('ConfigController', ['current', 'get'], controller); | ||
config['ConfigController'] = controller; | ||
@@ -85,8 +84,3 @@ }, | ||
setFileController: function setFileController(controller) { | ||
if (typeof controller.saveFile !== 'function') { | ||
throw new Error('FileController must implement saveFile()'); | ||
} | ||
if (typeof controller.saveBase64 !== 'function') { | ||
throw new Error('FileController must implement saveBase64()'); | ||
} | ||
requireMethods('FileController', ['saveFile', 'saveBase64'], controller); | ||
config['FileController'] = controller; | ||
@@ -100,5 +94,3 @@ }, | ||
setInstallationController: function setInstallationController(controller) { | ||
if (typeof controller.currentInstallationId !== 'function') { | ||
throw new Error('InstallationController must implement currentInstallationId()'); | ||
} | ||
requireMethods('InstallationController', ['currentInstallationId'], controller); | ||
config['InstallationController'] = controller; | ||
@@ -112,11 +104,3 @@ }, | ||
setObjectController: function setObjectController(controller) { | ||
if (typeof controller.save !== 'function') { | ||
throw new Error('ObjectController must implement save()'); | ||
} | ||
if (typeof controller.fetch !== 'function') { | ||
throw new Error('ObjectController must implement fetch()'); | ||
} | ||
if (typeof controller.destroy !== 'function') { | ||
throw new Error('ObjectController must implement destroy()'); | ||
} | ||
requireMethods('ObjectController', ['save', 'fetch', 'destroy'], controller); | ||
config['ObjectController'] = controller; | ||
@@ -130,50 +114,3 @@ }, | ||
setObjectStateController: function setObjectStateController(controller) { | ||
if (typeof controller.getState !== 'function') { | ||
throw new Error('ObjectStateController must implement getState()'); | ||
} | ||
if (typeof controller.initializeState !== 'function') { | ||
throw new Error('ObjectStateController must implement initializeState()'); | ||
} | ||
if (typeof controller.removeState !== 'function') { | ||
throw new Error('ObjectStateController must implement removeState()'); | ||
} | ||
if (typeof controller.getServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement getServerData()'); | ||
} | ||
if (typeof controller.setServerData !== 'function') { | ||
throw new Error('ObjectStateController must implement setServerData()'); | ||
} | ||
if (typeof controller.getPendingOps !== 'function') { | ||
throw new Error('ObjectStateController must implement getPendingOps()'); | ||
} | ||
if (typeof controller.setPendingOp !== 'function') { | ||
throw new Error('ObjectStateController must implement setPendingOp()'); | ||
} | ||
if (typeof controller.pushPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement pushPendingState()'); | ||
} | ||
if (typeof controller.popPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement popPendingState()'); | ||
} | ||
if (typeof controller.mergeFirstPendingState !== 'function') { | ||
throw new Error('ObjectStateController must implement mergeFirstPendingState()'); | ||
} | ||
if (typeof controller.getObjectCache !== 'function') { | ||
throw new Error('ObjectStateController must implement getObjectCache()'); | ||
} | ||
if (typeof controller.estimateAttribute !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttribute()'); | ||
} | ||
if (typeof controller.estimateAttributes !== 'function') { | ||
throw new Error('ObjectStateController must implement estimateAttributes()'); | ||
} | ||
if (typeof controller.commitServerChanges !== 'function') { | ||
throw new Error('ObjectStateController must implement commitServerChanges()'); | ||
} | ||
if (typeof controller.enqueueTask !== 'function') { | ||
throw new Error('ObjectStateController must implement enqueueTask()'); | ||
} | ||
if (typeof controller.clearAllState !== 'function') { | ||
throw new Error('ObjectStateController must implement clearAllState()'); | ||
} | ||
requireMethods('ObjectStateController', ['getState', 'initializeState', 'removeState', 'getServerData', 'setServerData', 'getPendingOps', 'setPendingOp', 'pushPendingState', 'popPendingState', 'mergeFirstPendingState', 'getObjectCache', 'estimateAttribute', 'estimateAttributes', 'commitServerChanges', 'enqueueTask', 'clearAllState'], controller); | ||
@@ -188,5 +125,3 @@ config['ObjectStateController'] = controller; | ||
setPushController: function setPushController(controller) { | ||
if (typeof controller.send !== 'function') { | ||
throw new Error('PushController must implement send()'); | ||
} | ||
requireMethods('PushController', ['send'], controller); | ||
config['PushController'] = controller; | ||
@@ -200,5 +135,3 @@ }, | ||
setQueryController: function setQueryController(controller) { | ||
if (typeof controller.find !== 'function') { | ||
throw new Error('QueryController must implement find()'); | ||
} | ||
requireMethods('QueryController', ['find'], controller); | ||
config['QueryController'] = controller; | ||
@@ -212,8 +145,3 @@ }, | ||
setRESTController: function setRESTController(controller) { | ||
if (typeof controller.request !== 'function') { | ||
throw new Error('RESTController must implement request()'); | ||
} | ||
if (typeof controller.ajax !== 'function') { | ||
throw new Error('RESTController must implement ajax()'); | ||
} | ||
requireMethods('RESTController', ['request', 'ajax'], controller); | ||
config['RESTController'] = controller; | ||
@@ -227,5 +155,3 @@ }, | ||
setSessionController: function setSessionController(controller) { | ||
if (typeof controller.getSession !== 'function') { | ||
throw new Error('A SessionController must implement getSession()'); | ||
} | ||
requireMethods('SessionController', ['getSession'], controller); | ||
config['SessionController'] = controller; | ||
@@ -240,21 +166,5 @@ }, | ||
if (controller.async) { | ||
if (typeof controller.getItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement getItemAsync()'); | ||
} | ||
if (typeof controller.setItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement setItemAsync()'); | ||
} | ||
if (typeof controller.removeItemAsync !== 'function') { | ||
throw new Error('An async StorageController must implement removeItemAsync()'); | ||
} | ||
requireMethods('An async StorageController', ['getItemAsync', 'setItemAsync', 'removeItemAsync'], controller); | ||
} else { | ||
if (typeof controller.getItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement getItem()'); | ||
} | ||
if (typeof controller.setItem !== 'function') { | ||
throw new Error('A synchronous StorageController must implement setItem()'); | ||
} | ||
if (typeof controller.removeItem !== 'function') { | ||
throw new Error('A synchonous StorageController must implement removeItem()'); | ||
} | ||
requireMethods('A synchronous StorageController', ['getItem', 'setItem', 'removeItem'], controller); | ||
} | ||
@@ -269,32 +179,3 @@ config['StorageController'] = controller; | ||
setUserController: function setUserController(controller) { | ||
if (typeof controller.setCurrentUser !== 'function') { | ||
throw new Error('A UserController must implement setCurrentUser()'); | ||
} | ||
if (typeof controller.currentUser !== 'function') { | ||
throw new Error('A UserController must implement currentUser()'); | ||
} | ||
if (typeof controller.currentUserAsync !== 'function') { | ||
throw new Error('A UserController must implement currentUserAsync()'); | ||
} | ||
if (typeof controller.signUp !== 'function') { | ||
throw new Error('A UserController must implement signUp()'); | ||
} | ||
if (typeof controller.logIn !== 'function') { | ||
throw new Error('A UserController must implement logIn()'); | ||
} | ||
if (typeof controller.become !== 'function') { | ||
throw new Error('A UserController must implement become()'); | ||
} | ||
if (typeof controller.logOut !== 'function') { | ||
throw new Error('A UserController must implement logOut()'); | ||
} | ||
if (typeof controller.requestPasswordReset !== 'function') { | ||
throw new Error('A UserController must implement requestPasswordReset()'); | ||
} | ||
if (typeof controller.upgradeToRevocableSession !== 'function') { | ||
throw new Error('A UserController must implement upgradeToRevocableSession()'); | ||
} | ||
if (typeof controller.linkWith !== 'function') { | ||
throw new Error('A UserController must implement linkWith()'); | ||
} | ||
requireMethods('UserController', ['setCurrentUser', 'currentUser', 'currentUserAsync', 'signUp', 'logIn', 'become', 'logOut', 'requestPasswordReset', 'upgradeToRevocableSession', 'linkWith'], controller); | ||
config['UserController'] = controller; | ||
@@ -308,14 +189,3 @@ }, | ||
setLiveQueryController: function setLiveQueryController(controller) { | ||
if (typeof controller.subscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement subscribe()'); | ||
} | ||
if (typeof controller.unsubscribe !== 'function') { | ||
throw new Error('LiveQueryController must implement unsubscribe()'); | ||
} | ||
if (typeof controller.open !== 'function') { | ||
throw new Error('LiveQueryController must implement open()'); | ||
} | ||
if (typeof controller.close !== 'function') { | ||
throw new Error('LiveQueryController must implement close()'); | ||
} | ||
requireMethods('LiveQueryController', ['subscribe', 'unsubscribe', 'open', 'close'], controller); | ||
config['LiveQueryController'] = controller; | ||
@@ -329,7 +199,3 @@ }, | ||
setHooksController: function setHooksController(controller) { | ||
['create', 'get', 'update', 'remove'].forEach(function (func) { | ||
if (typeof controller[func] !== 'function') { | ||
throw new Error('A HooksController must implement ' + func + '()'); | ||
} | ||
}); | ||
requireMethods('HooksController', ['create', 'get', 'update', 'remove'], controller); | ||
config['HooksController'] = controller; | ||
@@ -336,0 +202,0 @@ }, |
@@ -116,3 +116,5 @@ /** | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
if (id) { | ||
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -135,3 +137,5 @@ value = pendingOps[i][attr].applyTo(value); | ||
if (pendingOps[i][attr] instanceof _ParseOp.RelationOp) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
if (id) { | ||
data[attr] = pendingOps[i][attr].applyTo(data[attr], { className: className, id: id }, attr); | ||
} | ||
} else { | ||
@@ -138,0 +142,0 @@ data[attr] = pendingOps[i][attr].applyTo(data[attr]); |
@@ -136,3 +136,7 @@ /** | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name = userId.getName(); | ||
if (!_name) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name; | ||
} | ||
@@ -170,4 +174,11 @@ if (typeof userId !== 'string') { | ||
userId = userId.id; | ||
if (!userId) { | ||
throw new Error('Cannot get access for a ParseUser without an ID'); | ||
} | ||
} else if (userId instanceof _ParseRole2['default']) { | ||
userId = 'role:' + userId.getName(); | ||
var _name2 = userId.getName(); | ||
if (!_name2) { | ||
throw new TypeError('Role must have a name'); | ||
} | ||
userId = 'role:' + _name2; | ||
} | ||
@@ -174,0 +185,0 @@ var permissions = this.permissionsById[userId]; |
@@ -90,34 +90,37 @@ /** | ||
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 commaIndex = data.base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(data.base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
if (data !== undefined) { | ||
if (Array.isArray(data)) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
base64: ParseFile.encodeBase64(data), | ||
type: specifiedType | ||
}; | ||
} else { | ||
} else if (typeof File !== 'undefined' && data instanceof File) { | ||
this._source = { | ||
format: 'base64', | ||
base64: data.base64, | ||
format: 'file', | ||
file: data, | ||
type: specifiedType | ||
}; | ||
} else if (data && typeof data.base64 !== 'undefined') { | ||
var _base64 = data.base64; | ||
var commaIndex = _base64.indexOf(','); | ||
if (commaIndex !== -1) { | ||
var matches = /^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/.exec(_base64.slice(0, commaIndex + 1)); | ||
// if data URI with type and charset, there will be 4 matches. | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64.slice(commaIndex + 1), | ||
type: matches[1] | ||
}; | ||
} else { | ||
this._source = { | ||
format: 'base64', | ||
base64: _base64, | ||
type: specifiedType | ||
}; | ||
} | ||
} else { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
} else if (typeof data !== 'undefined') { | ||
throw new TypeError('Cannot create a Parse.File with that data.'); | ||
} | ||
@@ -254,3 +257,4 @@ } | ||
'X-Parse-Application-ID': _CoreManager2['default'].get('APPLICATION_ID'), | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY') | ||
'X-Parse-JavaScript-Key': _CoreManager2['default'].get('JAVASCRIPT_KEY'), | ||
'Content-Type': source.type || (source.file ? source.file.type : null) | ||
}; | ||
@@ -257,0 +261,0 @@ var url = _CoreManager2['default'].get('SERVER_URL'); |
@@ -216,8 +216,8 @@ /** | ||
if (singleInstance) { | ||
var id = this.id; | ||
if (!id) { | ||
id = this._getId(); | ||
var _id = this.id; | ||
if (!_id) { | ||
_id = this._getId(); | ||
} | ||
return { | ||
id: id, | ||
id: _id, | ||
className: this.className | ||
@@ -694,3 +694,5 @@ }; | ||
} else if (k === 'objectId' || k === 'id') { | ||
this.id = changes[k]; | ||
if (typeof changes[k] === 'string') { | ||
this.id = changes[k]; | ||
} | ||
} else if (k === 'ACL' && typeof changes[k] === 'object' && !(changes[k] instanceof _ParseACL2['default'])) { | ||
@@ -884,3 +886,5 @@ newOps[k] = new _ParseOp.SetOp(new _ParseACL2['default'](changes[k])); | ||
var stateController = _CoreManager2['default'].getObjectStateController(); | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
if (stateController) { | ||
stateController.duplicateState(this._getStateIdentifier(), clone._getStateIdentifier()); | ||
} | ||
return clone; | ||
@@ -1143,5 +1147,5 @@ } | ||
if (options.hasOwnProperty('useMasterKey')) { | ||
saveOptions.useMasterKey = options.useMasterKey; | ||
saveOptions.useMasterKey = !!options.useMasterKey; | ||
} | ||
if (options.hasOwnProperty('sessionToken')) { | ||
if (options.hasOwnProperty('sessionToken') && typeof options.sessionToken === 'string') { | ||
saveOptions.sessionToken = options.sessionToken; | ||
@@ -1573,2 +1577,4 @@ } | ||
var ParseObjectSubclass = function ParseObjectSubclass(attributes, options) { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
// Enable legacy initializers | ||
@@ -1579,4 +1585,2 @@ if (typeof this.initialize === 'function') { | ||
this.className = adjustedClassName; | ||
this._objCount = objectCount++; | ||
if (attributes && typeof attributes === 'object') { | ||
@@ -1583,0 +1587,0 @@ if (!this.set(attributes || {}, options)) { |
@@ -466,2 +466,5 @@ /** | ||
if (!value) { | ||
if (!object || !key) { | ||
throw new Error('Cannot apply a RelationOp without either a previous value, or an object and a key'); | ||
} | ||
var parent = new _ParseObject2['default'](object.className); | ||
@@ -468,0 +471,0 @@ if (object.id && object.id.indexOf('local') === 0) { |
@@ -99,5 +99,9 @@ /** | ||
var change = new _ParseOp.RelationOp(objects, []); | ||
this.parent.set(this.key, change); | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot add to a Relation without a parent'); | ||
} | ||
parent.set(this.key, change); | ||
this.targetClassName = change._targetClassName; | ||
return this.parent; | ||
return parent; | ||
} | ||
@@ -118,2 +122,5 @@ | ||
var change = new _ParseOp.RelationOp([], objects); | ||
if (!this.parent) { | ||
throw new Error('Cannot remove from a Relation without a parent'); | ||
} | ||
this.parent.set(this.key, change); | ||
@@ -147,4 +154,8 @@ this.targetClassName = change._targetClassName; | ||
var query; | ||
var parent = this.parent; | ||
if (!parent) { | ||
throw new Error('Cannot construct a query for a Relation without a parent'); | ||
} | ||
if (!this.targetClassName) { | ||
query = new _ParseQuery2['default'](this.parent.className); | ||
query = new _ParseQuery2['default'](parent.className); | ||
query._extraOptions.redirectClassNameForKey = this.key; | ||
@@ -156,4 +167,4 @@ } else { | ||
__type: 'Pointer', | ||
className: this.parent.className, | ||
objectId: this.parent.id | ||
className: parent.className, | ||
objectId: parent.id | ||
}); | ||
@@ -160,0 +171,0 @@ query._addCondition('$relatedTo', 'key', this.key); |
@@ -79,3 +79,7 @@ /** | ||
value: function getName() { | ||
return this.get('name'); | ||
var name = this.get('name'); | ||
if (name == null || typeof name === 'string') { | ||
return name; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ |
@@ -79,3 +79,7 @@ /** | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -82,0 +86,0 @@ }], [{ |
@@ -131,2 +131,5 @@ /** | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
throw new Error('Invalid type: authData field should be an object'); | ||
} | ||
authData[authType] = options.authData; | ||
@@ -184,3 +187,3 @@ | ||
var authData = this.get('authData'); | ||
if (!provider || typeof authData !== 'object') { | ||
if (!provider || !authData || typeof authData !== 'object') { | ||
return; | ||
@@ -270,2 +273,5 @@ } | ||
var authData = this.get('authData') || {}; | ||
if (typeof authData !== 'object') { | ||
return false; | ||
} | ||
return !!authData[authType]; | ||
@@ -342,3 +348,7 @@ } | ||
value: function getUsername() { | ||
return this.get('username'); | ||
var username = this.get('username'); | ||
if (username == null || typeof username === 'string') { | ||
return username; | ||
} | ||
return ''; | ||
} | ||
@@ -359,3 +369,3 @@ | ||
var authData = this.get('authData'); | ||
if (authData && authData.hasOwnProperty('anonymous')) { | ||
if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) { | ||
// We need to set anonymous to null instead of deleting it in order to remove it from Parse. | ||
@@ -388,3 +398,7 @@ authData.anonymous = null; | ||
value: function getEmail() { | ||
return this.get('email'); | ||
var email = this.get('email'); | ||
if (email == null || typeof email === 'string') { | ||
return email; | ||
} | ||
return ''; | ||
} | ||
@@ -415,3 +429,7 @@ | ||
value: function getSessionToken() { | ||
return this.get('sessionToken'); | ||
var token = this.get('sessionToken'); | ||
if (token == null || typeof token === 'string') { | ||
return token; | ||
} | ||
return ''; | ||
} | ||
@@ -418,0 +436,0 @@ |
@@ -126,3 +126,5 @@ /** | ||
headers = headers || {}; | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
if (typeof headers['Content-Type'] !== 'string') { | ||
headers['Content-Type'] = 'text/plain'; // Avoid pre-flight | ||
} | ||
if (_CoreManager2['default'].get('IS_NODE')) { | ||
@@ -129,0 +131,0 @@ headers['User-Agent'] = 'Parse/' + _CoreManager2['default'].get('VERSION') + ' (NodeJS ' + process.versions.node + ')'; |
@@ -35,2 +35,3 @@ /** | ||
exports.clearAllState = clearAllState; | ||
exports.duplicateState = duplicateState; | ||
@@ -148,2 +149,6 @@ var _ObjectStateMutations = require('./ObjectStateMutations'); | ||
objectState = {}; | ||
} | ||
function duplicateState(source, dest) { | ||
dest.id = source.id; | ||
} |
{ | ||
"name": "parse", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "The Parse JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "homepage": "https://www.parse.com", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
1607531
41701