parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

feat: Add a new `beforeLiveQueryEvent` trigger

Open codeKonami opened this issue 1 year ago • 8 comments
trafficstars

Pull Request

Issue

Closes: https://github.com/parse-community/parse-server/issues/9431

Approach

I added a beforeLiveQueryEvent trigger which allows the user to modify the updated object before it is passed to the LiveQuery server (via PubSub). It is a cloned version of the object so it won't modify the one passed to the afterSave trigger.

I've added an option which I'm not really convinced. You can set the context of the request to req.context.preventLiveQuery === true to prevent the publish to be made by the Parse Server and so limiting some network and CPU consumption depending on some business logic.

Tasks

  • [x] Add tests
  • [ ] Add changes to documentation (guides, repository pages, code comments)
  • [ ] Add security check
  • [ ] Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • New Features

    • Introduced support for registering "before live query event" triggers, allowing custom logic to run before live query events are published.
    • Added the ability to prevent specific live query events from being sent by setting a context flag in the trigger.
  • Bug Fixes

    • Improved context handling for triggers to ensure consistent behavior during live query events.
  • Tests

    • Added comprehensive tests to verify the behavior and effects of the new "before live query event" triggers.

codeKonami avatar Nov 19 '24 20:11 codeKonami