Draft
Conversation
This counter is incremented whenever a VDU returns a value other than `1`, whereas `ok` and `true` are also treated as acceptable success values. This fixes the counter to only increment on actual failure responses.
…o $elemMatch and $allMatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds atop #5858 to add a
$dataoperator to Mango, which is particularly useful for VDUs as it allows comparisons between different fields in the input, and thus allows some authorisation logic to be implemented in Mango instead of JS.The syntax of the operator is
{ "$data": Path }wherePathhas the same syntax as the compound field accessor, i.e. it consists of one or more property names separated by.. Thus this expression:{ "a": { "$gt": "b.c" } }Means the doc's
aproperty must be greater than itsb.cproperty. This would accept{ a: 2, b: { c: 1 } }and reject{ a: 2, b: { c: 3 } }. It would also reject docs where the referent of the$dataoperator is missing, e.g.{ a: 2, b: {} }.The
Pathvalue has one additional bit of syntax which is that it can be prefixed with one or more.characters to indicate relative paths. For example:{ "a": { "$gt": { "$data": ".b" } } }means theafield must be greater than thebfield that is next to theafield. A path of..bwould denote thebfield in the parent object relative to theafield, and so on.The
$dataoperator may only be used with operators that expect a literal value as input, and it cannot be used with combinators like$and,$or,$not,$allMatch,$elemMatch, and so on. This is because such uses would allow an input doc to inject its own selectors and use them to bypass the intended logic.This is implemented as follows:
{ "$data": Path }expressions are pre-parsed so thatPathis broken into its constituent pieces. i.e.<<"a.b">>becomes[<<"a">>, <<"b">>]. Relative paths produce a special token at the front to say how many levels to navigate back up the doc before following the path, e.g.<<"..a.b">>parses to[{[{<<"parent">, 2}]}, <<"a">>, <<"b">>]. This structure is chosen so that the "parent" token is a valid ejson value.$datais used incorrectly, i.e. it is used with an operator that it is not allowed, it is rejected at normalization so it cannot be used to evaluate any docs.mango_doc:get_fieldare added that record the stack of objects traversed while accessing the requested field, and retrieve an item from a given depth in the stack. The#ctxrecord gains astackproperty which tracks the stack of objects there were traversed to reach the current point.{ Op: { $data: Path } }have the data reference evaluated first, to turn them into{ Op: Value }before continuing. For consistency with existing semantics,{ Field: { $data: Path } }is considered to mean{ Field: { $eq: { $data: Path } } }.If this is accepted, we should add
userCtxandsecurityObj(names TBC) to the structure passed to VDU expressions so that they can implement auth logic. The tests added here use the$dataoperator to create a rule where updates to a doc cannot remove any of the existing items from thetagsfield.Testing recommendations
Some unit tests for normalisation and evaluation are included but I think they could be more thorough, I'd welcome suggestions for edge cases I've overlooked.
Related Issues or Pull Requests
match_failures/2function #5858Checklist
rel/overlay/etc/default.inisrc/docsfolder