-
-
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
feat: Support dot notation on array fields #9115
base: alpha
Are you sure you want to change the base?
Conversation
Thanks for opening this pull request! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## alpha #9115 +/- ##
==========================================
- Coverage 93.78% 93.77% -0.02%
==========================================
Files 186 186
Lines 14729 14737 +8
==========================================
+ Hits 13814 13820 +6
- Misses 915 917 +2 ☔ View full report in Codecov by Sentry. |
@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. |
src/Controllers/SchemaController.js
Outdated
// JSON Arrays are treated as Nested Objects | ||
const [x, y] = fieldName.split('.'); | ||
fieldName = x; | ||
if (!isNaN(y) && !['sentPerUTCOffset', 'failedPerUTCOffset'].includes(fieldName)) { |
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.
-
Hard-coded field names look suspicious. If certain fields require special treatment for this logic to work we may end up with the same issue as in Object attributes transformed in array Parse-SDK-JS#2198.
-
Maybe we should be stricter than
isNaN
, from Object attributes transformed in array Parse-SDK-JS#2198 I suspect there may be edge cases where this logic fails. Without using regex (too expensive) the only solution I can think of is on a per char basis; not sure about its perf though:const isArrayIndex = Array.from(y).every(c => c >= '0' && c <= '9')
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.
I added the stricter array index check.
The hard coded field names come from the _PushStatus
schema. They have array indexes but are saved as objects instead of arrays.
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.
They have array indexes but are saved as objects instead of arrays.
What does that mean? Is this the issue discussed in parse-community/Parse-SDK-JS#2198 (comment) where we don't know whether an object key 0
is an array index or a normal object key? I have rebased this PR to include the tests added in #9179. Let's see how that goes.
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.
The tests pass, that's a good sign. What would we have to change for the push status so we don't have to treat them differently here?
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.
Pretty much nothing we can do here. These are built into Parse instead of created by the user. This wouldn't break anything as the fields are type Object in the schema and are still type Object after this PR.
If you want to see how it works check out this test
https://github.com/parse-community/parse-server/blob/alpha/spec/PushWorker.spec.js#L324
Pull Request
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: #6687
Approach
https://www.mongodb.com/docs/manual/core/document/#dot-notation
Tasks