Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse

Package Overview
Dependencies
Maintainers
6
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse - npm Package Compare versions

Comparing version 1.8.1 to 1.8.2

lib/browser/EventEmitter.js

2

lib/browser/CoreManager.js

@@ -20,3 +20,3 @@ /**

LIVEQUERY_SERVER_URL: null,
VERSION: 'js' + '1.8.1',
VERSION: 'js' + '1.8.2',
APPLICATION_ID: null,

@@ -23,0 +23,0 @@ JAVASCRIPT_KEY: null,

@@ -31,5 +31,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -157,4 +157,4 @@ var _ParsePromise = require('./ParsePromise');

var LiveQueryClient = (function (_events$EventEmitter) {
_inherits(LiveQueryClient, _events$EventEmitter);
var LiveQueryClient = (function (_EventEmitter) {
_inherits(LiveQueryClient, _EventEmitter);

@@ -390,9 +390,3 @@ function LiveQueryClient(_ref) {

value: function _getWebSocketImplementation() {
var WebSocketImplementation = undefined;
if (window.WebSocket) {
WebSocketImplementation = WebSocket;
}
return WebSocketImplementation;
return typeof WebSocket === 'function' ? WebSocket : null;
}

@@ -575,5 +569,5 @@

return LiveQueryClient;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = LiveQueryClient;
module.exports = exports['default'];

@@ -27,5 +27,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -116,4 +116,4 @@ var _CoreManager = require('./CoreManager');

var Subscription = (function (_events$EventEmitter) {
_inherits(Subscription, _events$EventEmitter);
var Subscription = (function (_EventEmitter) {
_inherits(Subscription, _EventEmitter);

@@ -136,5 +136,10 @@ function Subscription(id, query, sessionToken) {

value: function unsubscribe() {
var liveQueryClient = _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
liveQueryClient.unsubscribe(this);
this.emit('close');
var _this2 = this;
var _this = this;
_CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) {
liveQueryClient.unsubscribe(_this);
_this.emit('close');
_this2.resolve();
});
}

@@ -144,5 +149,5 @@ }]);

return Subscription;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = Subscription;
module.exports = exports['default'];

@@ -9,5 +9,5 @@ 'use strict';

var _events = require('events');
var _EventEmitter = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter2 = _interopRequireDefault(_EventEmitter);

@@ -22,2 +22,6 @@ var _LiveQueryClient = require('./LiveQueryClient');

var _ParsePromise = require('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
/**

@@ -52,3 +56,3 @@ *

*/
var LiveQuery = new _events2['default'].EventEmitter();
var LiveQuery = new _EventEmitter2['default']();

@@ -86,12 +90,14 @@ /**

var getSessionToken = function getSessionToken() {
var currentUser = _CoreManager2['default'].getUserController().currentUser();
var sessionToken = undefined;
if (currentUser) {
sessionToken = currentUser.getSessionToken();
}
return sessionToken;
var promiseUser = _CoreManager2['default'].getUserController().currentUserAsync();
return promiseUser.then(function (currentUser) {
return _ParsePromise2['default'].as(currentUser ? currentUser.sessionToken : undefined);
}).then(function (sessionToken) {
return _ParsePromise2['default'].as(sessionToken);
});
};
var getLiveQueryClient = function getLiveQueryClient() {
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (defaultLiveQueryClient) {
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
};

@@ -107,61 +113,105 @@

if (defaultLiveQueryClient) {
return defaultLiveQueryClient;
return _ParsePromise2['default'].as(defaultLiveQueryClient);
}
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
var sessionTokenPromise = getSessionToken();
return sessionTokenPromise.then(function (sessionToken) {
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: getSessionToken()
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: sessionToken
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
}).on('open', function () {
LiveQuery.emit('open');
}).on('close', function () {
LiveQuery.emit('close');
});
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
});
defaultLiveQueryClient.on('open', function () {
LiveQuery.emit('open');
});
defaultLiveQueryClient.on('close', function () {
LiveQuery.emit('close');
});
return defaultLiveQueryClient;
},
open: function open() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.open();
var _this = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this.resolve(liveQueryClient.open());
});
},
close: function close() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.close();
var _this2 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this2.resolve(liveQueryClient.close());
});
},
subscribe: function subscribe(query) {
var liveQueryClient = getLiveQueryClient();
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
return liveQueryClient.subscribe(query, getSessionToken());
var _this3 = this;
var subscriptionWrap = new _EventEmitter2['default']();
getLiveQueryClient().then(function (liveQueryClient) {
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
var promiseSessionToken = getSessionToken();
// new event emitter
return promiseSessionToken.then(function (sessionToken) {
var subscription = liveQueryClient.subscribe(query, sessionToken);
// enter, leave create, etc
subscriptionWrap.id = subscription.id;
subscriptionWrap.query = subscription.query;
subscriptionWrap.sessionToken = subscription.sessionToken;
subscriptionWrap.unsubscribe = subscription.unsubscribe;
subscription.on('open', function () {
subscriptionWrap.emit('open');
}).on('create', function (object) {
subscriptionWrap.emit('create', object);
}).on('update', function (object) {
subscriptionWrap.emit('update', object);
}).on('enter', function (object) {
subscriptionWrap.emit('enter', object);
}).on('leave', function (object) {
subscriptionWrap.emit('leave', object);
}).on('delete', function (object) {
subscriptionWrap.emit('delete', object);
});
_this3.resolve();
});
});
return subscriptionWrap;
},
unsubscribe: function unsubscribe(subscription) {
var liveQueryClient = getLiveQueryClient();
return liveQueryClient.unsubscribe(subscription);
var _this4 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this4.resolve(liveQueryClient.unsubscribe(subscription));
});
}
});
module.exports = exports['default'];

@@ -1462,3 +1462,10 @@ /**

}
var preserved = null;
if (typeof o._preserveFieldsOnFetch === 'function') {
preserved = o._preserveFieldsOnFetch();
}
o._clearServerData();
if (preserved) {
o._finishFetch(preserved);
}
}

@@ -1465,0 +1472,0 @@ o._finishFetch(otherAttributes);

@@ -308,2 +308,14 @@ /**

/**
* Class instance method used to maintain specific keys when a fetch occurs.
* Used to ensure that the session token is not lost.
*/
}, {
key: '_preserveFieldsOnFetch',
value: function _preserveFieldsOnFetch() {
return {
sessionToken: this.get('sessionToken')
};
}
/**
* Returns true if <code>current</code> would return this user.

@@ -310,0 +322,0 @@ * @method isCurrent

@@ -88,3 +88,5 @@ /**

obj.forEach(function (el) {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
if (typeof el === 'object') {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
}
});

@@ -91,0 +93,0 @@ }

@@ -20,3 +20,3 @@ /**

LIVEQUERY_SERVER_URL: null,
VERSION: 'js' + '1.8.1',
VERSION: 'js' + '1.8.2',
APPLICATION_ID: null,

@@ -23,0 +23,0 @@ JAVASCRIPT_KEY: null,

@@ -31,5 +31,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -157,4 +157,4 @@ var _ParsePromise = require('./ParsePromise');

var LiveQueryClient = (function (_events$EventEmitter) {
_inherits(LiveQueryClient, _events$EventEmitter);
var LiveQueryClient = (function (_EventEmitter) {
_inherits(LiveQueryClient, _EventEmitter);

@@ -390,7 +390,3 @@ function LiveQueryClient(_ref) {

value: function _getWebSocketImplementation() {
var WebSocketImplementation = undefined;
WebSocketImplementation = require('ws');
return WebSocketImplementation;
return require('ws');
}

@@ -573,5 +569,5 @@

return LiveQueryClient;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = LiveQueryClient;
module.exports = exports['default'];

@@ -27,5 +27,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -116,4 +116,4 @@ var _CoreManager = require('./CoreManager');

var Subscription = (function (_events$EventEmitter) {
_inherits(Subscription, _events$EventEmitter);
var Subscription = (function (_EventEmitter) {
_inherits(Subscription, _EventEmitter);

@@ -136,5 +136,10 @@ function Subscription(id, query, sessionToken) {

value: function unsubscribe() {
var liveQueryClient = _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
liveQueryClient.unsubscribe(this);
this.emit('close');
var _this2 = this;
var _this = this;
_CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) {
liveQueryClient.unsubscribe(_this);
_this.emit('close');
_this2.resolve();
});
}

@@ -144,5 +149,5 @@ }]);

return Subscription;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = Subscription;
module.exports = exports['default'];

@@ -9,5 +9,5 @@ 'use strict';

var _events = require('events');
var _EventEmitter = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter2 = _interopRequireDefault(_EventEmitter);

@@ -22,2 +22,6 @@ var _LiveQueryClient = require('./LiveQueryClient');

var _ParsePromise = require('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
/**

@@ -52,3 +56,3 @@ *

*/
var LiveQuery = new _events2['default'].EventEmitter();
var LiveQuery = new _EventEmitter2['default']();

@@ -86,12 +90,14 @@ /**

var getSessionToken = function getSessionToken() {
var currentUser = _CoreManager2['default'].getUserController().currentUser();
var sessionToken = undefined;
if (currentUser) {
sessionToken = currentUser.getSessionToken();
}
return sessionToken;
var promiseUser = _CoreManager2['default'].getUserController().currentUserAsync();
return promiseUser.then(function (currentUser) {
return _ParsePromise2['default'].as(currentUser ? currentUser.sessionToken : undefined);
}).then(function (sessionToken) {
return _ParsePromise2['default'].as(sessionToken);
});
};
var getLiveQueryClient = function getLiveQueryClient() {
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (defaultLiveQueryClient) {
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
};

@@ -107,61 +113,105 @@

if (defaultLiveQueryClient) {
return defaultLiveQueryClient;
return _ParsePromise2['default'].as(defaultLiveQueryClient);
}
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
var sessionTokenPromise = getSessionToken();
return sessionTokenPromise.then(function (sessionToken) {
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: getSessionToken()
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: sessionToken
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
}).on('open', function () {
LiveQuery.emit('open');
}).on('close', function () {
LiveQuery.emit('close');
});
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
});
defaultLiveQueryClient.on('open', function () {
LiveQuery.emit('open');
});
defaultLiveQueryClient.on('close', function () {
LiveQuery.emit('close');
});
return defaultLiveQueryClient;
},
open: function open() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.open();
var _this = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this.resolve(liveQueryClient.open());
});
},
close: function close() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.close();
var _this2 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this2.resolve(liveQueryClient.close());
});
},
subscribe: function subscribe(query) {
var liveQueryClient = getLiveQueryClient();
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
return liveQueryClient.subscribe(query, getSessionToken());
var _this3 = this;
var subscriptionWrap = new _EventEmitter2['default']();
getLiveQueryClient().then(function (liveQueryClient) {
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
var promiseSessionToken = getSessionToken();
// new event emitter
return promiseSessionToken.then(function (sessionToken) {
var subscription = liveQueryClient.subscribe(query, sessionToken);
// enter, leave create, etc
subscriptionWrap.id = subscription.id;
subscriptionWrap.query = subscription.query;
subscriptionWrap.sessionToken = subscription.sessionToken;
subscriptionWrap.unsubscribe = subscription.unsubscribe;
subscription.on('open', function () {
subscriptionWrap.emit('open');
}).on('create', function (object) {
subscriptionWrap.emit('create', object);
}).on('update', function (object) {
subscriptionWrap.emit('update', object);
}).on('enter', function (object) {
subscriptionWrap.emit('enter', object);
}).on('leave', function (object) {
subscriptionWrap.emit('leave', object);
}).on('delete', function (object) {
subscriptionWrap.emit('delete', object);
});
_this3.resolve();
});
});
return subscriptionWrap;
},
unsubscribe: function unsubscribe(subscription) {
var liveQueryClient = getLiveQueryClient();
return liveQueryClient.unsubscribe(subscription);
var _this4 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this4.resolve(liveQueryClient.unsubscribe(subscription));
});
}
});
module.exports = exports['default'];

@@ -1462,3 +1462,10 @@ /**

}
var preserved = null;
if (typeof o._preserveFieldsOnFetch === 'function') {
preserved = o._preserveFieldsOnFetch();
}
o._clearServerData();
if (preserved) {
o._finishFetch(preserved);
}
}

@@ -1465,0 +1472,0 @@ o._finishFetch(otherAttributes);

@@ -308,2 +308,14 @@ /**

/**
* Class instance method used to maintain specific keys when a fetch occurs.
* Used to ensure that the session token is not lost.
*/
}, {
key: '_preserveFieldsOnFetch',
value: function _preserveFieldsOnFetch() {
return {
sessionToken: this.get('sessionToken')
};
}
/**
* Returns true if <code>current</code> would return this user.

@@ -310,0 +322,0 @@ * @method isCurrent

@@ -88,3 +88,5 @@ /**

obj.forEach(function (el) {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
if (typeof el === 'object') {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
}
});

@@ -91,0 +93,0 @@ }

@@ -20,3 +20,3 @@ /**

LIVEQUERY_SERVER_URL: null,
VERSION: 'js' + '1.8.1',
VERSION: 'js' + '1.8.2',
APPLICATION_ID: null,

@@ -23,0 +23,0 @@ JAVASCRIPT_KEY: null,

@@ -31,5 +31,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -157,4 +157,4 @@ var _ParsePromise = require('./ParsePromise');

var LiveQueryClient = (function (_events$EventEmitter) {
_inherits(LiveQueryClient, _events$EventEmitter);
var LiveQueryClient = (function (_EventEmitter) {
_inherits(LiveQueryClient, _EventEmitter);

@@ -390,5 +390,3 @@ function LiveQueryClient(_ref) {

value: function _getWebSocketImplementation() {
var WebSocketImplementation = undefined;
return WebSocketImplementation;
return WebSocket;
}

@@ -571,5 +569,5 @@

return LiveQueryClient;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = LiveQueryClient;
module.exports = exports['default'];

@@ -27,5 +27,5 @@ /**

var _events = require('events');
var _EventEmitter2 = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter3 = _interopRequireDefault(_EventEmitter2);

@@ -116,4 +116,4 @@ var _CoreManager = require('./CoreManager');

var Subscription = (function (_events$EventEmitter) {
_inherits(Subscription, _events$EventEmitter);
var Subscription = (function (_EventEmitter) {
_inherits(Subscription, _EventEmitter);

@@ -136,5 +136,10 @@ function Subscription(id, query, sessionToken) {

value: function unsubscribe() {
var liveQueryClient = _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
liveQueryClient.unsubscribe(this);
this.emit('close');
var _this2 = this;
var _this = this;
_CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) {
liveQueryClient.unsubscribe(_this);
_this.emit('close');
_this2.resolve();
});
}

@@ -144,5 +149,5 @@ }]);

return Subscription;
})(_events2['default'].EventEmitter);
})(_EventEmitter3['default']);
exports['default'] = Subscription;
module.exports = exports['default'];

@@ -9,5 +9,5 @@ 'use strict';

var _events = require('events');
var _EventEmitter = require('./EventEmitter');
var _events2 = _interopRequireDefault(_events);
var _EventEmitter2 = _interopRequireDefault(_EventEmitter);

@@ -22,2 +22,6 @@ var _LiveQueryClient = require('./LiveQueryClient');

var _ParsePromise = require('./ParsePromise');
var _ParsePromise2 = _interopRequireDefault(_ParsePromise);
/**

@@ -52,3 +56,3 @@ *

*/
var LiveQuery = new _events2['default'].EventEmitter();
var LiveQuery = new _EventEmitter2['default']();

@@ -86,12 +90,14 @@ /**

var getSessionToken = function getSessionToken() {
var currentUser = _CoreManager2['default'].getUserController().currentUser();
var sessionToken = undefined;
if (currentUser) {
sessionToken = currentUser.getSessionToken();
}
return sessionToken;
var promiseUser = _CoreManager2['default'].getUserController().currentUserAsync();
return promiseUser.then(function (currentUser) {
return _ParsePromise2['default'].as(currentUser ? currentUser.sessionToken : undefined);
}).then(function (sessionToken) {
return _ParsePromise2['default'].as(sessionToken);
});
};
var getLiveQueryClient = function getLiveQueryClient() {
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient();
return _CoreManager2['default'].getLiveQueryController().getDefaultLiveQueryClient().then(function (defaultLiveQueryClient) {
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
};

@@ -107,61 +113,105 @@

if (defaultLiveQueryClient) {
return defaultLiveQueryClient;
return _ParsePromise2['default'].as(defaultLiveQueryClient);
}
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
var sessionTokenPromise = getSessionToken();
return sessionTokenPromise.then(function (sessionToken) {
var liveQueryServerURL = _CoreManager2['default'].get('LIVEQUERY_SERVER_URL');
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
if (liveQueryServerURL && liveQueryServerURL.indexOf('ws') !== 0) {
throw new Error('You need to set a proper Parse LiveQuery server url before using LiveQueryClient');
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
// If we can not find Parse.liveQueryServerURL, we try to extract it from Parse.serverURL
if (!liveQueryServerURL) {
var host = _CoreManager2['default'].get('SERVER_URL').replace(/^https?:\/\//, '');
liveQueryServerURL = 'ws://' + host;
_CoreManager2['default'].set('LIVEQUERY_SERVER_URL', liveQueryServerURL);
}
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: getSessionToken()
var applicationId = _CoreManager2['default'].get('APPLICATION_ID');
var javascriptKey = _CoreManager2['default'].get('JAVASCRIPT_KEY');
var masterKey = _CoreManager2['default'].get('MASTER_KEY');
// Get currentUser sessionToken if possible
defaultLiveQueryClient = new _LiveQueryClient2['default']({
applicationId: applicationId,
serverURL: liveQueryServerURL,
javascriptKey: javascriptKey,
masterKey: masterKey,
sessionToken: sessionToken
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
}).on('open', function () {
LiveQuery.emit('open');
}).on('close', function () {
LiveQuery.emit('close');
});
return _ParsePromise2['default'].as(defaultLiveQueryClient);
});
// Register a default onError callback to make sure we do not crash on error
defaultLiveQueryClient.on('error', function (error) {
LiveQuery.emit('error', error);
});
defaultLiveQueryClient.on('open', function () {
LiveQuery.emit('open');
});
defaultLiveQueryClient.on('close', function () {
LiveQuery.emit('close');
});
return defaultLiveQueryClient;
},
open: function open() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.open();
var _this = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this.resolve(liveQueryClient.open());
});
},
close: function close() {
var liveQueryClient = getLiveQueryClient();
liveQueryClient.close();
var _this2 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this2.resolve(liveQueryClient.close());
});
},
subscribe: function subscribe(query) {
var liveQueryClient = getLiveQueryClient();
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
return liveQueryClient.subscribe(query, getSessionToken());
var _this3 = this;
var subscriptionWrap = new _EventEmitter2['default']();
getLiveQueryClient().then(function (liveQueryClient) {
if (liveQueryClient.shouldOpen()) {
liveQueryClient.open();
}
var promiseSessionToken = getSessionToken();
// new event emitter
return promiseSessionToken.then(function (sessionToken) {
var subscription = liveQueryClient.subscribe(query, sessionToken);
// enter, leave create, etc
subscriptionWrap.id = subscription.id;
subscriptionWrap.query = subscription.query;
subscriptionWrap.sessionToken = subscription.sessionToken;
subscriptionWrap.unsubscribe = subscription.unsubscribe;
subscription.on('open', function () {
subscriptionWrap.emit('open');
}).on('create', function (object) {
subscriptionWrap.emit('create', object);
}).on('update', function (object) {
subscriptionWrap.emit('update', object);
}).on('enter', function (object) {
subscriptionWrap.emit('enter', object);
}).on('leave', function (object) {
subscriptionWrap.emit('leave', object);
}).on('delete', function (object) {
subscriptionWrap.emit('delete', object);
});
_this3.resolve();
});
});
return subscriptionWrap;
},
unsubscribe: function unsubscribe(subscription) {
var liveQueryClient = getLiveQueryClient();
return liveQueryClient.unsubscribe(subscription);
var _this4 = this;
getLiveQueryClient().then(function (liveQueryClient) {
_this4.resolve(liveQueryClient.unsubscribe(subscription));
});
}
});
module.exports = exports['default'];

@@ -1462,3 +1462,10 @@ /**

}
var preserved = null;
if (typeof o._preserveFieldsOnFetch === 'function') {
preserved = o._preserveFieldsOnFetch();
}
o._clearServerData();
if (preserved) {
o._finishFetch(preserved);
}
}

@@ -1465,0 +1472,0 @@ o._finishFetch(otherAttributes);

@@ -308,2 +308,14 @@ /**

/**
* Class instance method used to maintain specific keys when a fetch occurs.
* Used to ensure that the session token is not lost.
*/
}, {
key: '_preserveFieldsOnFetch',
value: function _preserveFieldsOnFetch() {
return {
sessionToken: this.get('sessionToken')
};
}
/**
* Returns true if <code>current</code> would return this user.

@@ -310,0 +322,0 @@ * @method isCurrent

@@ -88,3 +88,5 @@ /**

obj.forEach(function (el) {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
if (typeof el === 'object') {
traverse(el, encountered, shouldThrow, allowDeepUnsaved);
}
});

@@ -91,0 +93,0 @@ }

{
"name": "parse",
"version": "1.8.1",
"version": "1.8.2",
"description": "The Parse JavaScript SDK",

@@ -32,3 +32,2 @@ "homepage": "https://www.parse.com",

"babel-runtime": "^5.8.20",
"events": "^1.1.0",
"ws": "^1.0.1",

@@ -35,0 +34,0 @@ "xmlhttprequest": "^1.7.0"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc