This module implements the structural and semantic validation of solved modules, the second stage in the processing of the projection language JM2MP.
The validation process is asynchronous because the signature of
QueryAdapter's
ValidateFunction
is async.
It traverses every named template of every projection module to validate:
- That each template command and operator is recognized and have the required clauses.
- That there must be no unrecognized clauses in template commands and operators.
- That all references to aliases are within lexical scope.
- That the reference to a named templates in every
$refclause of acalltemplate command actually points to an existing (declared) named template. - That every object literal key does not begin with an unescaped
$character. - That every
gettemplate command have its own$syntaxclause (after normalization stage), and that all syntaxes correspond to a registered query adapter. But it delegates the specific validation of$pathclauses to such adapter.
Source
Members
KNOWN_OPSSet.<string>
All the recognized template commands and operators.
It must be stay in sync with the evaluator's JM2MP_PROJECTIONS and OP_ARGS.
Type
-
Set.<string>
Source
OP_ARGSmodule:jm2mp/validator~OP_ARGS_TABLE
It describes the required and optional clauses' names for every
template command and operator defined in JM2MP.
The always required $op clause is not included, because the
names of every template command and operator themselves are the
keys of this constant object.
It must be stay in sync with the evaluator's JM2MP_PROJECTIONS and KNOWN_OPS.
Type
Source
Methods
isOperation(obj) → {boolean}
It checks whether an object is a template command or an operator,
that is: if it contains the key $op.
Parameters
-
obj
*The object to test.
Returns
-
booleantruewheneverobjis a template command or operator; otherwise,false.
Source
isValidName(name) → {boolean}
It checks whether a text string can be used as a name (for named templates or aliases), that is:
- It is non-empty.
- It does not starts by: '$', '@' or '%'.
Parameters
-
name
stringThe
stringto check.
Returns
-
booleantruewhenevernamecan be a valid name; otherwise,false.
Source
validateModule(module, registry) → {Promise.<void>}
It validates a previously resolved projection module along with all its named templates (and recursively, their template commands and operators).
The validation process is asynchronous because the signature of
QueryAdapter's
ValidateFunction
is async.
Parameters
-
module
objectThe previously resolved projection module.
-
registry
module:jm2mp/adapters/registry.AdapterRegistryThe AdapterRegistry used to validate all expressions from any declared query language syntax.
Returns
-
Promise.<void>This function should be
awaited.
Throws
-
- Whenever the name of any named template is not valid.
- If no root template is found in the projection module.
- Type
-
ValidationError
Source
validateCall(op, ctx)
If validates deeply and recursively a call template command
due to its special semantics.
It validates several operational aspects: valid reference name,
existing referenced named template, and recursively over the
$at projection.
It is important to note that the validation about the existence of the referenced named template is made only at this point. If validation is ommited, then invoking a non-existent named template will raise an EvaluationError at runtime.
Parameters
-
op
*The
lettemplate command to validate. -
ctx
ObjectThe execution environment used to validate.
Throws
-
Whenever an error is detected during the validation process. Its
messagewill contain the kind of error found and the execution environmentpathwhere it was found. - Type
-
ValidationError
Source
validateGet(op, ctx)
If validates deeply and recursively a get template command
due to its special semantics.
It validates several operational aspects: registered $syntax,
validates $path using the right
QueryAdapter,
scope of aliases when using the native string-variant syntax,
and recursive valiation over the $from projection.
Parameters
-
op
*The
lettemplate command to validate. -
ctx
ObjectThe execution environment used to validate.
Throws
-
Whenever an error is detected during the validation process. Its
messagewill contain the kind of error found and the execution environmentpathwhere it was found. - Type
-
ValidationError
Source
validateLet(op, ctx)
If validates deeply and recursively a let template command
due to its special semantics.
It validates several operational aspects: valid aliases names, parallel binding evaluation at outer scope, and $in evaluation at inner (extended) scope (including new aliases).
Parameters
-
op
*The
lettemplate command to validate. -
ctx
ObjectThe execution environment used to validate.
Throws
-
Whenever an error is detected during the validation process. Its
messagewill contain the kind of error found and the execution environmentpathwhere it was found. - Type
-
ValidationError
Source
validateLiteralObject(obj, ctx)
It validates recursively a projection that is a literal object but neither a template command nor operator:
- It validates that all its keys (property names) must not start by unescaped '$' character; they must use '$' instead.
- It validates recursively the value of all its properties as projections.
Parameters
-
obj
*The projection (which is a literal object), to validate.
-
ctx
objectThe execution context used for validation.
Throws
-
Whenever an unescaped invalid key is found.
- Type
-
ValidationError
Source
validateOperation(op, ctx)
If validates recursively a projection considering it specifically as a template command or operator.
It validates several operational aspects: known name, required and optional arguments, and not additional unknown arguments.
It deeply validates template commands with special semantics:
let, call, and get.
Structural data types (arrays and objects) are traversed recursively in a generic manner.
Parameters
-
op
*The template command or operator to validate.
-
ctx
ObjectThe execution context used for validation.
Throws
-
Whenever an error is detected during the validation process. Its
messagewill contain the kind of error found and the execution environmentpathwhere it was found. - Type
-
ValidationError
Source
validateProjection(proj, ctx)
It validates recursively a projection.
Parameters
-
proj
*The projection (that can be any valid JSON value), to validate.
-
ctx
objectThe execution context used for validation.
Throws
-
Whenever the type of
projis not supported by JSON (what should never happen). - Type
-
ValidationError
Source
Type Definitions
OP_ARGS_OPERATOR
It describes the required and optional clauses' names for a single
template command or operator defined in JM2MP.
Type
-
Object
Properties
-
required
Array.<string>The list of required clauses' names for such template command or operator.
-
optional
Array.<string>The list of optional clauses' names for such template command or operator.
Source
OP_ARGS_TABLE
It describes the required and optional clauses' names for every
template command and operator defined in JM2MP.
Type
-
Object
Properties
-
get
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
gettemplate command. -
if
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
iftemplate command. -
foldArr
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
foldArrtemplate command. -
foldObj
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
foldObjtemplate command. -
cons
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
constemplate command. -
insert
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
inserttemplate command. -
let
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
lettemplate command. -
call
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
calltemplate command. -
eq
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
eqtemplate command. -
lt
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
ltoperator. -
gt
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
gtoperator. -
lte
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
lteoperator. -
gte
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
gteoperator. -
neq
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
neqoperator. -
not
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
notoperator. -
and
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
andoperator. -
or
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
oroperator. -
add
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
addoperator. -
sub
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
suboperator. -
mul
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
muloperator. -
div
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
divoperator. -
mod
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
modoperator. -
neg
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
negoperator. -
abs
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
absoperator. -
concat
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
concatoperator. -
length
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
lengthoperator. -
substring
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
substringoperator. -
upper
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
upperoperator. -
lower
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
loweroperator. -
typeof
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
typeofoperator. -
coalesce
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
coalesceoperator. -
has
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
hastemplate command. -
sort
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
sorttemplate command. -
lookup
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
lookuptemplate command. -
merge
module:jm2mp/validator~OP_ARGS_OPERATORBoth required and optional clauses for the
mergetemplate command.