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
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Changes
API
Expression.ReferencedPaths() (#57): returns the input fields an expression reads, for any expression, as raw field names from the root of the input, plus complete. RequiredPaths covers fast-path expressions only. complete == true means evaluating the expression against its input pruned to those paths gives the same result. It is false when the expression may read input it doesn't name, for example the whole input, an unknown variable, a lambda parameter or $eval. This is a static analysis, not a security boundary.
expr, _:=gnata.Compile(`a[b = 1].c = "x" and $exists(d)`)
paths, complete:=expr.ReferencedPaths() // [[a c] [a b] [d]], true
Expression.ReferencedPathsIn(env): the same, for evaluation with a CustomEnvironment, whose custom functions (including ones that replace a builtin) are treated as reading their context.
Semantics
Predicates, sort terms, groups and transforms resolve against the step they apply to; focus bindings, %, $/$$, := bindings, closures and tail calls follow JSONata's evaluation rules.
A call reads its context when the builtin's signature may inject it for the arguments' static types, checked with the same matcher Inject and Validate use.
Paths are kept as a trie with size caps, so the cost stays linear and close to Compile, including on adversarial expressions.
Tests
Every complete TestReferencedPaths case, and every complete expression in the jsonata-js suite (1,124 of 1,808), is evaluated again on its input pruned to its paths and must give the same result. The context-injection check is verified against every registered builtin.