JSON Model-to-Model Projection (JM2MP) Documentation

JSON Model-to-Model Projection (JM2MP) Documentation

Module

jm2mp/adapters/native_paths

This module implements the EBNF parser for native paths and navigation/location functions.

This modules encapsules native syntaxes for JM2MP. It is invoked exclusively for the native query language QueryAdapter; there are no other sites of invocation (neither evaluator nor generic validator).

A native path with text string syntax has following form:

root ( "." identifier | "[" array-index "]" | "[" named-property "]" )*

where root must be one of the following:

  • $: represents the source document's root value (root).
  • @: represents the current context (ctx).
  • %AliasName: represents a lexical alias bound using a let template command (alias).

native syntax also allows $path to be an array literal which items will represent accessors (strings for named-properties of objects and natural numbers for indexed-items in arrays); that allows navigation/location without additional parsing.

In practice, native_paths are really similar to JSONPointer (external) syntax, which QueryAdapter is developed in JSONPointer (module).

Source

Members

staticconstant

EXECUTION_ENVIRONMENT_FROMobject

It lists the starting points of a path from the execution environment.

Type

  • object

Source

Methods

static

navigate(value, accessors) → {*}

It applies the sequence of accessors to an initial JSON value, navigating/location inside of such value.

It follows the null absorption rule: if in any step the resulting value is null or the accessor is not applicable (not named property found, index out of range, dot navigation over scalar value, ...), then the final resultant value will be null.

Parameters

  • value *

    The initial JSON value.

  • accessors Array.<(string|number)>

    The list of accessors to be orderly applied.

Returns

  • *

    El valor tras la navegación, o null si la navegación falla. The resultant JSON value found after the navigation/locate.

Throws

Whenever ... is not supported.

Type
EvaluationError

Source

static

parsePath(input) → {ParsedPath}

Parameters

  • input string

    The input path to parse.

Default Value

  • It parses 'input' string as a native path.

Returns

  • ParsedPath

    The abstract syntax tree (AST) of 'input' path.

Throws

Whenever 'input' string were not a valid path.

Type
module:jm2mp/errors.ParseError

Source

inner

isDigit(ch) → {boolean}

True whenever 'ch' is an ASCII digit.

Parameters

  • ch string

    The character to test.

Returns

  • boolean

    Is 'ch' in [0-9] ?

Source

inner

isIdentifierContinue(ch) → {boolean}

True whenever 'ch' can continue an identifier (ASCII letter, digit or underline characters).

Parameters

  • ch string

    The character to test.

Returns

  • boolean

    Is 'ch' in isIdentifierStart and isDigit ?

Source

inner

isIdentifierStart(ch) → {boolean}

True whenever 'ch' can starts an identifier (ASCII letter or underline characters).

Parameters

  • ch string

    The character to test.

Returns

  • boolean

    Is 'ch' in [A-Za-z_] ?

Source

inner

readIdentifier(input, start) → {string|null}

It reads an identifier from 'input' with starting delimiter character 'start'. An identifier starts by [A-Za-z_] (see isIdentifierStart) and continues by [A-Za-z_0-9] (see isIdentifierContinue). It returns the identifier found, or null otherwise.

Parameters

  • input string

    The input string containing the full path.

  • start number

    The initial position to read the expected identifier.

Returns

  • string null

    The identifier found, or null if no one valid is in such position.

Source

inner

readNonNegativeInteger(input, start) → {Object}

It reads a natural number (non-negative integer) from 'start' position in 'input', and returns its numeric value.

Parameters

  • input string

    The input string containing the full path.

  • start number

    The initial position to read the expected natural number.

Returns

  • Object

    Tuple with both: numeric value and number of characters consumed by the parser.

Source

inner

readQuotedString(input, start) → {Object}

It reads an string quoted only as JSON supports (&quote; is allowed but not &apos;) from 'input' path, starting at 'start' position character. It also supports escaping characters like JSON: \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX.

Parameters

  • input string

    The input string containing the full path.

  • start integer

    The initial position to read the quoted string, considering that input[start] must be a &quote;.

Returns

  • Object

    Tuple with both: unquoted string value and the number of characters consumed by the parser reading the value (and both &quote;s).

Source

Type Definitions

ParsedPath

It represents a parsed path (from string-based syntax).

Type

  • object

Properties

  • kind "root" | "ctx" | "alias"

    The base kind of the parsed path.

  • aliasName string | null

    The name of the alias only if kind is 'alias'; otherwise, it is null.

  • accessors Array.<(string|number)>

    The accessors after the base (it is always an array, empty or not).

Source