Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

feat: Support Dot Notation on Array fields

Open dplewis opened this issue 1 year ago • 4 comments

Pull Request

Issue

Using Dot notation on array fields messes up the internal state of objects. Most notably internally they are handled like objects instead of arrays. This would prevent other array operations like add, remove from working. Also this may cause errors on the Server.

{ items: { '0': { count: 20 }, '1': { count: 5 } } }

instead of

{ items: [{ count: 20 }, { count: 5 }] }

Closes: https://github.com/parse-community/Parse-SDK-JS/pull/1343

Approach

Update ObjectStateMutation estimateAttributes and commitServerChanges. estimateAttributes is called whenever obj.attributes is accessed. commitServerChanges is called on obj.save and obj.fetch

TODO

  • [ ] Run against Parse Server test suite

Tasks

  • [x] Add tests
  • [x] Add changes to documentation (guides, repository pages, code comments)

dplewis avatar May 03 '24 08:05 dplewis

Thanks for opening this pull request!

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (b50790a) to head (5c1e04b). Report is 45 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##             alpha     #2120    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           61        64     +3     
  Lines         6186      6364   +178     
  Branches      1499      1514    +15     
==========================================
+ Hits          6186      6364   +178     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 03 '24 08:05 codecov[bot]

so the syntax is set('arr.1.name', 'Bob');? I'd be curious if the server creates the right mongo update to support this, might be worth a integration test.

Unrelated, I noticed in one of my PRs that ObjectStateMutations.js has a function estimateAttribute that doesn't seem to support dot-notation at all, while the plural estimateAttributes does (which you updated here). I couldn't find any usage of the first one, is it just dead code?

mortenmo avatar May 03 '24 15:05 mortenmo

so the syntax is set('arr.1.name', 'Bob');? I'd be curious if the server creates the right mongo update to support this, might be worth a integration test.

I'm curious as well but https://github.com/parse-community/parse-server/pull/9115 will need to be merged first. I think it should work based on the tests I wrote.

estimateAttribute that doesn't seem to support dot-notation at all

I think this might be dead code, good catch

dplewis avatar May 03 '24 15:05 dplewis

@mtrezza This is ready to merge.

dplewis avatar May 17 '24 14:05 dplewis

🎉 This change has been released in version 5.2.0-alpha.1

parseplatformorg avatar May 17 '24 18:05 parseplatformorg

🎉 This change has been released in version 5.2.0-beta.1

parseplatformorg avatar Jun 24 '24 20:06 parseplatformorg

🎉 This change has been released in version 5.2.0

parseplatformorg avatar Jun 29 '24 14:06 parseplatformorg