You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After some discussion in the PR about how to handle in and parens, I think we should implement a breaking change to make array ([ ]) usage more consistent and easier to reason about.
Current
Currently an array wraps each items within it in their own parens. (code)
}elseif(Array.isArray(filters)){constbuiltFilters=filters.map(f=>buildFilter(f,propPrefix)).filter(f=>f!==undefined);if(builtFilters.length){return`${builtFilters.map(f=>`(${f})`).join(` and `)}`}
which produces:
buildFilter({filter: [{SomeProp: 1},{AnotherProp: 2},"startswith(Name, 'R')"]});=>"?$filter=(SomeProp eq 1) and (AnotherProp eq 2) and (startswith(Name, 'R'))";
Proposal
The proposal is to change the code to:
}elseif(Array.isArray(filters)){constbuiltFilters=filters.map(f=>buildFilter(f,propPrefix)).filter(f=>f!==undefined);if(builtFilters.length){return`(${builtFilters.join(` and `)})`}
which would produce:
buildFilter({filter: [{SomeProp: 1},{AnotherProp: 2},"startswith(Name, 'R')"]});=>"?$filter=(SomeProp eq 1 and AnotherProp eq 2 and startswith(Name, 'R'))";
You also do not need the individual objects for the first two (not a change, just a simplification of the example).
buildFilter({filter: [{SomeProp: 1,AnotherProp: 2},"startswith(Name, 'R')"]});=>"?$filter=(SomeProp eq 1 and AnotherProp eq 2 and startswith(Name, 'R'))";
If you wanted to reproduce the original results (albeit with an extra wrapping parens around it all), you would wrap each item in an array:
buildFilter({filter: [[{SomeProp: 1}],[{AnotherProp: 2}],["startswith(Name, 'R')"]]});=>"?$filter=((SomeProp eq 1) and (AnotherProp eq 2) and (startswith(Name, 'R')))";
In summary, the [ ] would literally translate as ( ) in the query. If this change is made, I would release it as a new major version since it could be breaking for some users.
The text was updated successfully, but these errors were encountered:
After some discussion in the PR about how to handle
in
and parens, I think we should implement a breaking change to make array ([ ]
) usage more consistent and easier to reason about.Current
Currently an array wraps each items within it in their own parens. (code)
which produces:
Proposal
The proposal is to change the code to:
which would produce:
You also do not need the individual objects for the first two (not a change, just a simplification of the example).
If you wanted to reproduce the original results (albeit with an extra wrapping parens around it all), you would wrap each item in an array:
In summary, the
[ ]
would literally translate as( )
in the query. If this change is made, I would release it as a new major version since it could be breaking for some users.The text was updated successfully, but these errors were encountered: