Skip to content
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

feat: Support dot notation on array fields #2120

Merged
merged 4 commits into from
May 17, 2024

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented May 3, 2024

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: #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

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

Copy link

Thanks for opening this pull request!

Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dplewis dplewis requested a review from a team May 3, 2024 08:07
@mortenmo
Copy link
Contributor

mortenmo commented May 3, 2024

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?

@dplewis
Copy link
Member Author

dplewis commented May 3, 2024

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 parse-community/parse-server#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

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this PR ready for merge?

@mtrezza mtrezza changed the title feat: Support Dot Notation on Array fields feat: Support dot notation on array fields May 17, 2024
@dplewis
Copy link
Member Author

dplewis commented May 17, 2024

@mtrezza This is ready to merge.

@mtrezza mtrezza merged commit 25ec684 into parse-community:alpha May 17, 2024
10 of 11 checks passed
parseplatformorg pushed a commit that referenced this pull request May 17, 2024
# [5.2.0-alpha.1](5.1.1-alpha.1...5.2.0-alpha.1) (2024-05-17)

### Features

* Support dot notation on array fields ([#2120](#2120)) ([25ec684](25ec684))
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label May 17, 2024
@dplewis dplewis deleted the dot-notation-array branch May 23, 2024 20:15
parseplatformorg pushed a commit that referenced this pull request Jun 24, 2024
# [5.2.0-beta.1](5.1.0...5.2.0-beta.1) (2024-06-24)

### Bug Fixes

* `LiveQueryClient.resubscribe` with Parse Server 7 causes many open connections ([#2184](#2184)) ([71b4d17](71b4d17))
* `Parse.Installation` not working when installation is deleted on server ([#2126](#2126)) ([22360b4](22360b4))
* Duplicate pending operations on nested fields ([#2162](#2162)) ([df6df7c](df6df7c))

### Features

* Support dot notation on array fields ([#2120](#2120)) ([25ec684](25ec684))
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 24, 2024
parseplatformorg pushed a commit that referenced this pull request Jun 29, 2024
# [5.2.0](5.1.0...5.2.0) (2024-06-29)

### Bug Fixes

* `LiveQueryClient.resubscribe` with Parse Server 7 causes many open connections ([#2184](#2184)) ([71b4d17](71b4d17))
* `Parse.Installation` not working when installation is deleted on server ([#2126](#2126)) ([22360b4](22360b4))
* Dot notation on JSON arrays doesn't work on `PushStatus` offset fields ([#2194](#2194)) ([e0eb6f0](e0eb6f0))
* Duplicate pending operations on nested fields ([#2162](#2162)) ([df6df7c](df6df7c))

### Features

* Support dot notation on array fields ([#2120](#2120)) ([25ec684](25ec684))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants