-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create beforeConnect and beforeSubscribe Cloud Triggers #6649
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits
@@ -285,15 +285,15 @@ describe('ParseLiveQueryServer', function() { | |||
.catch(done.fail); | |||
}); | |||
|
|||
it('can handle connect command', function() { | |||
it('can handle connect command', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
userForSessionToken
on triggers.js, so that the sessionToken from LQ is only looked up if the trigger exists.In relation to #6642.