1.2.0 • Published 4 years ago

@quenk/facets-dsl v1.2.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

facets-dsl

Provides a parser and related APIs for converting a string sequence of filter conditions (query string) into usable search filters.

Installation

npm install --save-dev @quenk/facets-dsl

Usage

This module only provides the APIs for parsing a string into an AST.

To actually generate a query, use one of the modules for the supported platforms below: 1. facets-mongodb 2. facets-mysql

or implement your own using them as a guide.

Syntax

Query String

A valid query string consists of a sequence of one or more "filters" seperated by the following operators:

  1. "," (space) - indicates the filters are chained via a logical "AND".
  2. "," - Same as above.
  3. "or" - indicates the filters are chained via a logical "OR".
  4. "|" - Same as above.

In short, a sequence of more than one filter is either chained together via a logical "AND" or "OR".

Example:

let qs1 = 'name:"jon"';
let qs2 = 'name:"jon" or name:"jon\'s" age:>=12';
let qs3 = '(name:"jon" or name:"jon\'s") and age:>=12';

Filters can be grouped together via parenthesis "(" ")" to ensure precedence is kept during parsing.

Filters

A filter consists of a field name part, colon, optional operator and a value part:

<field> <colon> <operator>? <value>

The field name is any valid ECMAScript identifier. The operator is one of >,<,>=<=,=,!=. If no operator is specified then the special operator default is assumed which means it is up to the compiler to decide which operator to apply.

This is usually set in the policy.

The value part can either be a string surronded by double quotes, an identifier which is treated as a string, a valid ECMAScript number literal, one of the boolean values true or false, an "array" of values or a "dictionary" (object literal) of key value pairs.

A compile target may not support all the value types.

License

Apache 2.0 (SEE LICENSE) file. (c) 2020 Quenk Technologies Limited.

1.2.0

4 years ago

1.1.0

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago