This module implements the
QueryAdapter
interface to use the JSONata query language
as part of JM2MP projection documents.
This module only supports JSONata 2.x versions. Older version 1.x uses another incompatible API, as well as possibly future versions (3.x).
By design, JSONata 2.x is async only, as well as QueryAdapter.evaluate interface contract.
By compliance with JM2MP, the
QueryAdapter
created by createJsonataAdapter
maintains the expected behaviour:
undefined-->null.- Type errors --> EvaluationError with
cause. nullinput -->nulloutput without calling JSONata external library.- Invalid expression during validation --> ValidationError.
- Invalid expression during runtime --> EvaluationError.
Timeout mechanism: this adapter supports an optional timeout
parameter (expressed in milliseconds). If the evaluation of an
expression takes too long, it will be rejected and a
EvaluationError exception
will be raised, referencing such timeout. But the actual evaluation
will continue to run in the background until it naturally completes,
although its result will be discarded.
This timeout mechanism is acceptable for well written expressions but maybe insufficient for potentially malicious queries.
The jsonata library is dynamically loaded when constructing its corresponding QueryAdapter. If not previously installed, an AdapterError exception will be raised from createJsonataAdapter with a clear message about it.
Source
Methods
createJsonataAdapter(optionsopt) → {Promise.<module:jm2mp/adapters/registry.QueryAdapter>}
It creates a new QueryAdapter dynamically loading JSONata version 2.x.
Parameters
-
options
object<optional>
Properties
-
timeout
number<optional>
Timeout (expressed in milliseconds) for evaluating each query. If its value is greater than zero, any evaluation that exceeds this timeout will raise an EvaluationError exception. If it is not defined, is zero or is less than zero, no timeout will be applied.
-
timeout
Returns
-
Promise.<module:jm2mp/adapters/registry.QueryAdapter>