Create beforeConnect and beforeSubscribe Cloud Triggers#6649
Create beforeConnect and beforeSubscribe Cloud Triggers#6649dblythy wants to merge 45 commits intoparse-community:masterfrom dblythy:master
Conversation
|
Thanks for the PR. Can you please check the tests out? They are not passing. |
|
Will do! |
Dblythy patch 1
Update ParseLiveQueryServer.spec.js
Update triggers.js
Codecov Report
@@ Coverage Diff @@
## master #6649 +/- ##
=======================================
Coverage 93.59% 93.59%
=======================================
Files 169 169
Lines 12059 12059
=======================================
Hits 11287 11287
Misses 772 772 Continue to review full report at Codecov.
|
|
Sorry @davimacedo - not on my computer so had to edit through GitHub desktop which made it a bit difficult (and the commits a bit of a mess). I had to edit the LiveQuery spec so that it would await the result of the new beforeConnect / beforeSubscribe methods - is that okay? |
| }); | ||
|
|
||
| it('can handle connect command', function() { | ||
| it('can handle connect command', async () => { |
There was a problem hiding this comment.
Adding await here is fine. Can you add additional tests for this feature? You might have to await in other places.
|
@dplewis thank you! |
|
@dblythy Couldn't these trigger run in the background? (replace async with old fashion then / catch) Edit: beforeConnect in your example in the OP you assume its and async function returning |
|
@dplewis I can work on replacing the async with then / catch. The only reason I used async is because my JavaScript is not great, especially with promises 😝. I will reopen another PR at a later date with tests as well. Thank you for your time and advice! |
|
This is a great feature and a lot of progress was made. A lot of other data could be passed in too besides user and query. I look forward to your PR. If you don’t have time. Let me know and I can add this feature. |
My first PR so feel free to make suggestions of course.
Creates two new cloud code triggers which affect LiveQuery: beforeConnect and beforeSubscribe.
beforeConnect allows validation prior to a LiveQuery opening connection. This is not class specific.
beforeSubscribe handles the .subscribe methods from LiveQuery. Can be used to validate users, or to mutate the request.query, enforcing fields, equalTo, or whatever required.
I also created
userForSessionTokenon triggers.js, so that the sessionToken from LQ is only looked up if the trigger exists.In relation to #6642.