Nonflavored Prescription Medicine
    Wondering what’s next for npm?Check out our public roadmap! »

    @wedgekit/mql

    1.3.2 • Public • Published

    MQL (Metadata Query Language)

    Encoding

    The encode method accepts a pseudo abstract syntax tree that is represented as follows using disjunctive normal form:

        [ // conditions combined with ||
            conditionA,
            conditionB,
            [ // conditions combined with &&
        	    conditionC,
        	    [ // conditions combined with ||
        		    conditionD,
        		    [ // conditions combined with &&
        			    ... and so on, alternating || and && by layer
        		    ]
        	    ]
            ],
            conditionE
        ]
    

    ...where a given condition is represented as and object with a field, operator, and list of values:

        {
            field: some field,
            operator: an operator from the metadata spec,
            value: [list of reqired values needed for chosen operator]
        }
    

    The field and values cannot contain parentheses or gate symbols, so the following symbols are reserved: (, ), ||, and &&.

    Refer to the metadata spec for required values.

    NOTE - SET_VALUE expressions are not currently supported by the encoder.

    For example, the following condition:

        [
            {
                field: 'exampleA',
                operator: 'EQUALS',
                value: ['A']
            },
            [
                {
                    field: 'exampleB',
                    operator: 'TRUTHY',
                    value: []
                },
        	    [
                    {
                        field: 'exampleC',
                        operator: 'STARTS_WITH',
                        value: ['example']
                    },
                    {
                        field: 'exampleC',
                        operator: 'ENDS_WITH',
                        value: ['C']
                    }
        	    ]
            ],
            {
                field: 'exampleD',
                operator: 'BETWEEN',
                value: [1, 5]
            }
        ]
    

    is encoded as "exampleA EQUALS A || (exampleB TRUTHY && (exampleC STARTS_WITH example || exampleC ENDS_WITH C)) || exampleD BETWEEN 1 5".

    Parsing

    The parse method accepts MQL query string written and returns a pseudo abstract syntax tree. It does the inverse of the example above.

    The MQL query string MUST abide by the following (where A-G represent different conditions such as "fiedName EQUALS fieldValue"):

    • all conditions or expressions are combined with logic gates
    • the query is has has alternating logic gates at each level of depth
    • the query cannot have different logic gates at the same level of depth
    • each condition's operator must be followed by the required amount of values as can be found in the metadata spec
    • the query must have a valid parentheses structure

    The MQL query does NOT need to be simplified. Redundant parentheses are allowed and will be cleaned up before parsing.

    Keywords

    none

    Install

    npm i @wedgekit/mql

    DownloadsWeekly Downloads

    33

    Version

    1.3.2

    License

    MIT

    Unpacked Size

    73.6 kB

    Total Files

    37

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar