diff --git a/spec/ParseLiveQueryServer.spec.js b/spec/ParseLiveQueryServer.spec.js index 6c1b831a5da..4b810a81e1b 100644 --- a/spec/ParseLiveQueryServer.spec.js +++ b/spec/ParseLiveQueryServer.spec.js @@ -232,7 +232,7 @@ describe('ParseLiveQueryServer', function () { classNames: ['Yolo'], }, }) - .then(parseServer => { + .then((parseServer) => { saveSpy = spyOn(parseServer.config.liveQueryController, 'onAfterSave'); deleteSpy = spyOn( parseServer.config.liveQueryController, @@ -247,7 +247,7 @@ describe('ParseLiveQueryServer', function () { const obj = new Parse.Object('Yolo'); return obj.save(); }) - .then(obj => { + .then((obj) => { return obj.destroy(); }) .then(() => { @@ -307,52 +307,6 @@ describe('ParseLiveQueryServer', function () { expect(client.pushConnect).toHaveBeenCalled(); }); - it('basic beforeConnect rejection', async () => { - Parse.Cloud.beforeConnect(function () { - throw new Error('You shall not pass!'); - }); - const parseLiveQueryServer = new ParseLiveQueryServer({}); - const parseWebSocket = { - clientId: -1, - }; - await parseLiveQueryServer._handleConnect(parseWebSocket, { - sessionToken: 'token', - }); - expect(parseLiveQueryServer.clients.size).toBe(0); - const Client = require('../lib/LiveQuery/Client').Client; - expect(Client.pushError).toHaveBeenCalled(); - }); - - it('basic beforeSubscribe rejection', async () => { - Parse.Cloud.beforeSubscribe('test', function () { - throw new Error('You shall not pass!'); - }); - const parseLiveQueryServer = new ParseLiveQueryServer({}); - const parseWebSocket = { - clientId: -1, - }; - await parseLiveQueryServer._handleConnect(parseWebSocket, { - sessionToken: 'token', - }); - const query = { - className: 'test', - where: { - key: 'value', - }, - fields: ['test'], - }; - const requestId = 2; - const request = { - query: query, - requestId: requestId, - sessionToken: 'sessionToken', - }; - await parseLiveQueryServer._handleSubscribe(parseWebSocket, request); - expect(parseLiveQueryServer.clients.size).toBe(1); - const Client = require('../lib/LiveQuery/Client').Client; - expect(Client.pushError).toHaveBeenCalled(); - }); - it('can handle subscribe command without clientId', async () => { const parseLiveQueryServer = new ParseLiveQueryServer({}); const incompleteParseConn = {}; @@ -775,7 +729,7 @@ describe('ParseLiveQueryServer', function () { expect(client.pushDelete).not.toHaveBeenCalled(); }); - it('can handle object delete command which matches some subscriptions', async done => { + it('can handle object delete command which matches some subscriptions', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make deletedParseObject const parseObject = new Parse.Object(testClassName); @@ -819,7 +773,7 @@ describe('ParseLiveQueryServer', function () { parseLiveQueryServer._onAfterSave(message); }); - it('can handle object save command which does not match any subscription', async done => { + it('can handle object save command which does not match any subscription', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make mock request message const message = generateMockMessage(); @@ -850,7 +804,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle object enter command which matches some subscriptions', async done => { + it('can handle object enter command which matches some subscriptions', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make mock request message const message = generateMockMessage(true); @@ -887,7 +841,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle object update command which matches some subscriptions', async done => { + it('can handle object update command which matches some subscriptions', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make mock request message const message = generateMockMessage(true); @@ -920,7 +874,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle object leave command which matches some subscriptions', async done => { + it('can handle object leave command which matches some subscriptions', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make mock request message const message = generateMockMessage(true); @@ -957,7 +911,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle update command with original object', async done => { + it('can handle update command with original object', async (done) => { jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client'); const Client = require('../lib/LiveQuery/Client').Client; const parseLiveQueryServer = new ParseLiveQueryServer({}); @@ -1007,7 +961,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle object create command which matches some subscriptions', async done => { + it('can handle object create command which matches some subscriptions', async (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); // Make mock request message const message = generateMockMessage(); @@ -1040,7 +994,7 @@ describe('ParseLiveQueryServer', function () { }, jasmine.ASYNC_TEST_WAIT_TIME); }); - it('can handle create command with fields', async done => { + it('can handle create command with fields', async (done) => { jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client'); const Client = require('../lib/LiveQuery/Client').Client; const parseLiveQueryServer = new ParseLiveQueryServer({}); @@ -1546,7 +1500,7 @@ describe('ParseLiveQueryServer', function () { }); describe('class level permissions', () => { - it('matches CLP when find is closed', done => { + it('matches CLP when find is closed', (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); const acl = new Parse.ACL(); acl.setReadAccess(testUserId, true); @@ -1571,13 +1525,13 @@ describe('ParseLiveQueryServer', function () { requestId, 'find' ) - .then(isMatched => { + .then((isMatched) => { expect(isMatched).toBe(false); done(); }); }); - it('matches CLP when find is open', done => { + it('matches CLP when find is open', (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); const acl = new Parse.ACL(); acl.setReadAccess(testUserId, true); @@ -1602,13 +1556,13 @@ describe('ParseLiveQueryServer', function () { requestId, 'find' ) - .then(isMatched => { + .then((isMatched) => { expect(isMatched).toBe(true); done(); }); }); - it('matches CLP when find is restricted to userIds', done => { + it('matches CLP when find is restricted to userIds', (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); const acl = new Parse.ACL(); acl.setReadAccess(testUserId, true); @@ -1633,13 +1587,13 @@ describe('ParseLiveQueryServer', function () { requestId, 'find' ) - .then(isMatched => { + .then((isMatched) => { expect(isMatched).toBe(true); done(); }); }); - it('matches CLP when find is restricted to userIds', done => { + it('matches CLP when find is restricted to userIds', (done) => { const parseLiveQueryServer = new ParseLiveQueryServer({}); const acl = new Parse.ACL(); acl.setReadAccess(testUserId, true); @@ -1664,7 +1618,7 @@ describe('ParseLiveQueryServer', function () { requestId, 'find' ) - .then(isMatched => { + .then((isMatched) => { expect(isMatched).toBe(false); done(); }); @@ -2001,7 +1955,7 @@ describe('LiveQueryController', () => { classNames: ['Yolo'], }, }) - .then(parseServer => { + .then((parseServer) => { saveSpy = spyOn( parseServer.config.liveQueryController, 'onAfterSave' @@ -2019,7 +1973,7 @@ describe('LiveQueryController', () => { const obj = new Parse.Object('Yolo'); return obj.save(); }) - .then(obj => { + .then((obj) => { return obj.destroy(); }) .then(() => { @@ -2099,3 +2053,49 @@ describe('LiveQueryController', () => { }); }); }); + +it('basic beforeConnect rejection', async () => { + Parse.Cloud.beforeConnect(function () { + throw new Error('You shall not pass!'); + }); + const parseLiveQueryServer = new ParseLiveQueryServer({}); + const parseWebSocket = { + clientId: -1, + }; + await parseLiveQueryServer._handleConnect(parseWebSocket, { + sessionToken: 'token', + }); + expect(parseLiveQueryServer.clients.size).toBe(0); + const Client = require('../lib/LiveQuery/Client').Client; + expect(Client.pushError).toHaveBeenCalled(); +}); + +it('basic beforeSubscribe rejection', async () => { + Parse.Cloud.beforeSubscribe('test', function () { + throw new Error('You shall not pass!'); + }); + const parseLiveQueryServer = new ParseLiveQueryServer({}); + const parseWebSocket = { + clientId: -1, + }; + await parseLiveQueryServer._handleConnect(parseWebSocket, { + sessionToken: 'token', + }); + const query = { + className: 'test', + where: { + key: 'value', + }, + fields: ['test'], + }; + const requestId = 2; + const request = { + query: query, + requestId: requestId, + sessionToken: 'sessionToken', + }; + await parseLiveQueryServer._handleSubscribe(parseWebSocket, request); + expect(parseLiveQueryServer.clients.size).toBe(0); + const Client = require('../lib/LiveQuery/Client').Client; + expect(Client.pushError).toHaveBeenCalled(); +}); diff --git a/src/cloud-code/Parse.Cloud.js b/src/cloud-code/Parse.Cloud.js index c3f0536c2b7..3cd4ea2178a 100644 --- a/src/cloud-code/Parse.Cloud.js +++ b/src/cloud-code/Parse.Cloud.js @@ -453,21 +453,6 @@ ParseCloud.afterDeleteFile = function (handler) { ); }; -/** - * Registers a before live query server connect function. - * - * **Available in Cloud Code only.** - * - * ``` - * Parse.Cloud.beforeConnect(async (request) => { - * // code here - * }) - *``` - * - * @method beforeConnect - * @name Parse.Cloud.beforeConnect - * @param {Function} func The function to before connection is made. This function can be async and should take just one parameter, {@link Parse.Cloud.ConnectTriggerRequest}. - */ ParseCloud.beforeConnect = function (handler) { triggers.addConnectTrigger( triggers.Types.beforeConnect, @@ -476,27 +461,6 @@ ParseCloud.beforeConnect = function (handler) { ); }; -/** - * Registers a before live query subscription function. - * - * **Available in Cloud Code only.** - * - * If you want to use beforeSubscribe for a predefined class in the Parse JavaScript SDK (e.g. {@link Parse.User}), you should pass the class itself and not the String for arg1. - * ``` - * Parse.Cloud.beforeSubscribe('MyCustomClass', (request) => { - * // code here - * }) - * - * Parse.Cloud.beforeSubscribe(Parse.User, (request) => { - * // code here - * }) - *``` - * - * @method beforeSubscribe - * @name Parse.Cloud.beforeSubscribe - * @param {(String|Parse.Object)} arg1 The Parse.Object subclass to register the before subscription function for. This can instead be a String that is the className of the subclass. - * @param {Function} func The function to run before a subscription. This function can be async and should take one parameter, a {@link Parse.Cloud.TriggerRequest}. - */ ParseCloud.beforeSubscribe = function (parseClass, handler) { var className = getClassName(parseClass); triggers.addTrigger( diff --git a/src/triggers.js b/src/triggers.js index 48464c2ff45..278ed8afd21 100644 --- a/src/triggers.js +++ b/src/triggers.js @@ -155,7 +155,7 @@ export function removeTrigger(type, className, applicationId) { } export function _unregisterAll() { - Object.keys(_triggerStore).forEach(appId => delete _triggerStore[appId]); + Object.keys(_triggerStore).forEach((appId) => delete _triggerStore[appId]); } export function getTrigger(className, triggerType, applicationId) { @@ -188,7 +188,7 @@ export function getFunctionNames(applicationId) { {}; const functionNames = []; const extractFunctionNames = (namespace, store) => { - Object.keys(store).forEach(name => { + Object.keys(store).forEach((name) => { const value = store[name]; if (namespace) { name = `${namespace}.${name}`; @@ -315,7 +315,7 @@ export function getResponseObject(request, resolve, reject) { if (!response) { response = request.objects; } - response = response.map(object => { + response = response.map((object) => { return object.toJSON(); }); return resolve(response); @@ -426,10 +426,10 @@ export function maybeRunAfterFindTrigger( const request = getRequestObject(triggerType, auth, null, null, config); const { success, error } = getResponseObject( request, - object => { + (object) => { resolve(object); }, - error => { + (error) => { reject(error); } ); @@ -440,7 +440,7 @@ export function maybeRunAfterFindTrigger( JSON.stringify(objects), auth ); - request.objects = objects.map(object => { + request.objects = objects.map((object) => { //setting the class name to transform into parse object object.className = className; return Parse.Object.fromJSON(object); @@ -449,7 +449,7 @@ export function maybeRunAfterFindTrigger( .then(() => { const response = trigger(request); if (response && typeof response.then === 'function') { - return response.then(results => { + return response.then((results) => { if (!results) { throw new Parse.Error( Parse.Error.SCRIPT_FAILED, @@ -462,7 +462,7 @@ export function maybeRunAfterFindTrigger( return response; }) .then(success, error); - }).then(results => { + }).then((results) => { logTriggerAfterHook(triggerType, className, JSON.stringify(results), auth); return results; }); @@ -509,7 +509,7 @@ export function maybeRunQueryTrigger( return trigger(requestObject); }) .then( - result => { + (result) => { let queryResult = parseQuery; if (result && result instanceof Parse.Query) { queryResult = result; @@ -569,7 +569,7 @@ export function maybeRunQueryTrigger( restOptions, }; }, - err => { + (err) => { if (typeof err === 'string') { throw new Parse.Error(1, err); } else { @@ -612,7 +612,7 @@ export function maybeRunTrigger( ); var { success, error } = getResponseObject( request, - object => { + (object) => { logTriggerSuccessBeforeHook( triggerType, parseObject.className, @@ -630,7 +630,7 @@ export function maybeRunTrigger( } resolve(object); }, - error => { + (error) => { logTriggerErrorBeforeHook( triggerType, parseObject.className, @@ -665,7 +665,7 @@ export function maybeRunTrigger( // beforeSave is expected to return null (nothing) if (triggerType === Types.beforeSave) { if (promise && typeof promise.then === 'function') { - return promise.then(response => { + return promise.then((response) => { // response.object may come from express routing before hook if (response && response.object) { return response; @@ -703,7 +703,7 @@ export function runLiveQueryEventHandlers( ) { return; } - _triggerStore[applicationId].LiveQuery.forEach(handler => handler(data)); + _triggerStore[applicationId].LiveQuery.forEach((handler) => handler(data)); } export function getRequestFileObject(triggerType, auth, fileObject, config) {