parse-server
parse-server copied to clipboard
feat: Support dot notation on array fields
Pull Request
- Report security issues confidentially.
- Any contribution is under this license.
- Link this pull request to an issue.
Issue
Currently all dot notations are treated as operations on Object type field. This results in a error: Cannot read property '0' of undefined when used on Array type fields.
Closes: https://github.com/parse-community/parse-server/issues/6687
Approach
Check types for Array vs Fields based on dot notation format.
https://www.mongodb.com/docs/manual/core/document/#dot-notation
Tasks
- [x] Add tests
- [x] Add changes to documentation (guides, repository pages, code comments)
- [x] Add security check
- [x] Add new Parse Error codes to Parse JS SDK
Thanks for opening this pull request!
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 94.14%. Comparing base (
892052c) to head (fffc003).
Additional details and impacted files
@@ Coverage Diff @@
## alpha #9115 +/- ##
==========================================
- Coverage 94.15% 94.14% -0.01%
==========================================
Files 186 186
Lines 14738 14750 +12
==========================================
+ Hits 13877 13887 +10
- Misses 861 863 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@mtrezza This is an extremely complicated feature. I tried running this with the SDK internal fix against the server test suite and got Array dot notation working but it somehow broke the server. I’ll let you know when this is ready for review.
@mtrezza This is ready for review.
Looks good to me, also the tests seem to cover it well; and with the additional test from https://github.com/parse-community/parse-server/issues/9179 I think we are on the safe side. Good to merge? I would then make a Parse Server stable release and deprecate Parse Server 7.1.0 due to the JS SDK bug.
We are good to merge after the tests pass.
Tests pass; but I see you made more commits; should I go ahead and merge?
This is good to merge. I'll improve Postgres support in another PR (e.g increment, add, remove, delete). This PR has query support for PG so its a good start.
🎉 This change has been released in version 7.1.0-alpha.16
🎉 This change has been released in version 7.2.0-beta.1
🎉 This change has been released in version 7.2.0
Just FYI,
Array operations like increment, add, remove currently doesn't work with dot notation because PG doesn't support multidimensional arrays and for one dimensional arrays you don't need dot notation. A lot of COALESE for missing indexes and custom .sql script would be needed but it is doable probably.
I created a branch incase anybody isn interested. Currently for arrays you can fetch, update and save but it won't be atomic.
https://github.com/parse-community/parse-server/compare/alpha...dplewis:parse-server:dot-notation-ops?expand=1