JSON Model-to-Model Projection (JM2MP) Documentation

JSON Model-to-Model Projection (JM2MP) Documentation

Module

jm2mp/validator

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 $ref clause of a call template command actually points to an existing (declared) named template.
  • That every object literal key does not begin with an unescaped $ character.
  • That every get template command have its own $syntax clause (after normalization stage), and that all syntaxes correspond to a registered query adapter. But it delegates the specific validation of $path clauses to such adapter.

Source

Members

Methods

static

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

  • boolean

    true whenever obj is a template command or operator; otherwise, false.

Source

static

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 string

    The string to check.

Returns

  • boolean

    true whenever name can be a valid name; otherwise, false.

Source

static

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

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

asyncinner

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 let template command to validate.

  • ctx Object

    The execution environment used to validate.

Throws

Whenever an error is detected during the validation process. Its message will contain the kind of error found and the execution environment path where it was found.

Type
ValidationError

Source

asyncinner

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 let template command to validate.

  • ctx Object

    The execution environment used to validate.

Throws

Whenever an error is detected during the validation process. Its message will contain the kind of error found and the execution environment path where it was found.

Type
ValidationError

Source

asyncinner

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 let template command to validate.

  • ctx Object

    The execution environment used to validate.

Throws

Whenever an error is detected during the validation process. Its message will contain the kind of error found and the execution environment path where it was found.

Type
ValidationError

Source

asyncinner

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 object

    The execution context used for validation.

Throws

Whenever an unescaped invalid key is found.

Type
ValidationError

Source

asyncinner

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 Object

    The execution context used for validation.

Throws

Whenever an error is detected during the validation process. Its message will contain the kind of error found and the execution environment path where it was found.

Type
ValidationError

Source

asyncinner

validateProjection(proj, ctx)

It validates recursively a projection.

Parameters

  • proj *

    The projection (that can be any valid JSON value), to validate.

  • ctx object

    The execution context used for validation.

Throws

Whenever the type of proj is 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

Source