map.apps Bundle APIs 4.20.0
    Preparing search index...

    Interpreter and test engine for ComplexQueryExpressions.

    import ComplexQuery from "store-api/ComplexQuery";

    const query = {
    $and : [{
    a : {
    $eqw: "test*"
    },
    $or : [{ x : { $lt : 1 }},
    { x : { $gt : 2 }}]
    }]
    }
    const options = {};

    const cq = ComplexQuery.parse(query, options);

    const astRootNode = cq.ast.root();

    // the ast root node is an object structure like this:
    const expectedRootNode = {
    o : "$and",
    c : [{
    o : "$eqw",
    n : "a",
    v : "test*"
    },
    {
    o : "$or",
    c : [{
    o : $lt,
    n : "x",
    v : 1
    },{
    o : $gt,
    n : "x",
    v : 2
    }]
    }]
    }
    Index

    Properties

    Parser: typeof Parser = Parser

    Internally used Parser. Exported to allow new operations. To add a new operator use:

    ComplexQuery.Parser.prototype.operators[<name>] = <operator definition>
    
    ast: AST

    Normalized syntax tree of the query.

    Methods

    • Function to find matching ASTNodes in the AST.

      Parameters

      • query: ComplexQueryExpression

        query to parse

      • queryOptions: undefined | ComplexQueryOptions

        query options

      • operatorName: string

        name of operator to find

      • OptionalpropertyName: string

        name of property referenced by the operator

      Returns ASTNode[]

      array of matching ASTNodes or an empty array if nothing is found.

    • Function to test if a given query is a complex query.

      Parameters

      Returns boolean

      true if the expression is a complex query, otherwise false.

    • Function to test if an operator is used within a given query.

      Parameters

      • query: ComplexQueryExpression

        a complex query expression

      • queryOptions: undefined | ComplexQueryOptions

        query options

      • operatorName: string

        name of operator to find

      • OptionalpropertyName: string

        name of property referenced by the operator

      Returns boolean

      true if the operator is detected in the query.

    • Function to encode the AST or a part of it with a custom encoder.

      Type Parameters

      • T

      Parameters

      • encoder: Encoder<T>

        function which allows the conversion of the AST into another type.

      • OptionalwalkerOrAst: Walker | AST

        a Walker or AST instance. If not provided the parsed AST is used.

      Returns any

      output of the encoder.

    • Function to test if an item fulfills the conditions of the parsed query.

      Parameters

      • item: any

      Returns boolean