github RecoLabs/gnata v0.6.2

3 hours ago

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.

npm

  • Package version 0.6.2.

Don't miss a new gnata release

NewReleases is sending notifications on new releases.