@malloydata/malloy-filter 0.0.245 → 0.0.246-dev250320220920
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boolean_filter_expression.d.ts +3 -3
- package/dist/clause_utils.d.ts +23 -23
- package/dist/clause_utils.js +8 -8
- package/dist/clause_utils.js.map +1 -1
- package/dist/filter_interface.d.ts +120 -0
- package/dist/{filter_clause.js → filter_interface.js} +22 -18
- package/dist/filter_interface.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/ftemporal_parser.js +3 -1
- package/dist/lib/ftemporal_parser.js.map +1 -1
- package/dist/nearley_parse.d.ts +2 -2
- package/dist/nearley_parse.js +19 -12
- package/dist/nearley_parse.js.map +1 -1
- package/dist/number_filter_expression.d.ts +3 -3
- package/dist/number_filter_expression.js +2 -2
- package/dist/number_filter_expression.js.map +1 -1
- package/dist/string_filter_expression.d.ts +3 -3
- package/dist/string_filter_expression.js +2 -2
- package/dist/string_filter_expression.js.map +1 -1
- package/dist/temporal_filter_expression.d.ts +3 -3
- package/dist/temporal_filter_expression.js +2 -2
- package/dist/temporal_filter_expression.js.map +1 -1
- package/package.json +2 -1
- package/src/boolean_filter_expression.ts +4 -4
- package/src/clause_utils.ts +21 -21
- package/src/{filter_clause.ts → filter_interface.ts} +78 -72
- package/src/index.ts +2 -2
- package/src/lib/ftemporal_parser.ts +4 -1
- package/src/nearley_parse.ts +21 -14
- package/src/number_filter_expression.ts +5 -5
- package/src/string_filter_expression.ts +5 -5
- package/src/temporal_filter_expression.ts +7 -7
- package/dist/filter_clause.d.ts +0 -133
- package/dist/filter_clause.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nearley_parse.js","sourceRoot":"","sources":["../src/nearley_parse.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,
|
|
1
|
+
{"version":3,"file":"nearley_parse.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,UAAU,IAAI,qBAAqB,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE;gBACH;oBACE,OAAO,EAAE,UAAU;oBACnB,UAAU,EAAE,GAAG,GAAG,CAAC;oBACnB,QAAQ,EAAE,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;oBAC3B,QAAQ,EAAE,OAAO;iBAClB;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAzCD,gCAyCC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FilterParserResponse,
|
|
1
|
+
import type { FilterParserResponse, NumberFilter } from './filter_interface';
|
|
2
2
|
export declare const NumberFilterExpression: {
|
|
3
|
-
parse(src: string): FilterParserResponse<
|
|
4
|
-
unparse(nc:
|
|
3
|
+
parse(src: string): FilterParserResponse<NumberFilter>;
|
|
4
|
+
unparse(nc: NumberFilter | null): string;
|
|
5
5
|
};
|
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.NumberFilterExpression = void 0;
|
|
36
|
-
const
|
|
36
|
+
const filter_interface_1 = require("./filter_interface");
|
|
37
37
|
const nearley = __importStar(require("nearley"));
|
|
38
38
|
const fexpr_number_parser_1 = __importDefault(require("./lib/fexpr_number_parser"));
|
|
39
39
|
const nearley_parse_1 = require("./nearley_parse");
|
|
@@ -41,7 +41,7 @@ exports.NumberFilterExpression = {
|
|
|
41
41
|
parse(src) {
|
|
42
42
|
const fnumber_parser = new nearley.Parser(nearley.Grammar.fromCompiled(fexpr_number_parser_1.default));
|
|
43
43
|
const parse_result = (0, nearley_parse_1.run_parser)(src, fnumber_parser);
|
|
44
|
-
if (parse_result.parsed && (0,
|
|
44
|
+
if (parse_result.parsed && (0, filter_interface_1.isNumberFilter)(parse_result.parsed)) {
|
|
45
45
|
return { parsed: parse_result.parsed, log: [] };
|
|
46
46
|
}
|
|
47
47
|
return { parsed: null, log: parse_result.log };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number_filter_expression.js","sourceRoot":"","sources":["../src/number_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,
|
|
1
|
+
{"version":3,"file":"number_filter_expression.js","sourceRoot":"","sources":["../src/number_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,yDAAkD;AAClD,iDAAmC;AACnC,oFAAwD;AACxD,mDAA2C;AAE9B,QAAA,sBAAsB,GAAG;IACpC,KAAK,CAAC,GAAW;QACf,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,MAAM,CACvC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,6BAAe,CAAC,CAC9C,CAAC;QACF,MAAM,YAAY,GAAG,IAAA,0BAAU,EAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACrD,IAAI,YAAY,CAAC,MAAM,IAAI,IAAA,iCAAc,EAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/D,OAAO,EAAC,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,EAAC,CAAC;QAChD,CAAC;QACD,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAC,CAAC;IAC/C,CAAC;IACD,OAAO,CAAC,EAAuB;QAC7B,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;YACpB,KAAK,GAAG;gBACN,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;Y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C;YACtC,CAAC;YACD,KAAK,KAAK,CAAC;YACX,KAAK,IAAI;gBACP,OAAO,EAAE,CAAC,OAAO;qBACd,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,8BAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;qBAC3C,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC;YAC9B,KAAK,IAAI,CAAC,CAAC,CAAC;gBACV,MAAM,IAAI,GAAG,GAAG,GAAG,8BAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;gBACjE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;IAChD,CAAC;CACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FilterParserResponse,
|
|
1
|
+
import type { FilterParserResponse, StringFilter } from './filter_interface';
|
|
2
2
|
export declare const StringFilterExpression: {
|
|
3
|
-
parse(src: string): FilterParserResponse<
|
|
4
|
-
unparse(sc:
|
|
3
|
+
parse(src: string): FilterParserResponse<StringFilter>;
|
|
4
|
+
unparse(sc: StringFilter | null): string;
|
|
5
5
|
};
|
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.StringFilterExpression = void 0;
|
|
36
|
-
const
|
|
36
|
+
const filter_interface_1 = require("./filter_interface");
|
|
37
37
|
const nearley = __importStar(require("nearley"));
|
|
38
38
|
const fexpr_string_parser_1 = __importDefault(require("./lib/fexpr_string_parser"));
|
|
39
39
|
const clause_utils_1 = require("./clause_utils");
|
|
@@ -47,7 +47,7 @@ exports.StringFilterExpression = {
|
|
|
47
47
|
parse(src) {
|
|
48
48
|
const fstring_parser = new nearley.Parser(nearley.Grammar.fromCompiled(fexpr_string_parser_1.default));
|
|
49
49
|
const parse_result = (0, nearley_parse_1.run_parser)(src, fstring_parser);
|
|
50
|
-
if (parse_result.parsed && (0,
|
|
50
|
+
if (parse_result.parsed && (0, filter_interface_1.isStringFilter)(parse_result.parsed)) {
|
|
51
51
|
return { parsed: parse_result.parsed, log: [] };
|
|
52
52
|
}
|
|
53
53
|
return { parsed: null, log: parse_result.log };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string_filter_expression.js","sourceRoot":"","sources":["../src/string_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,
|
|
1
|
+
{"version":3,"file":"string_filter_expression.js","sourceRoot":"","sources":["../src/string_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,yDAAkD;AAClD,iDAAmC;AACnC,oFAAwD;AACxD,iDAAsC;AACtC,mDAA2C;AAE3C,yEAAyE;AACzE,wEAAwE;AACxE,uEAAuE;AACvE,uEAAuE;AACvE,iBAAiB;AACJ,QAAA,sBAAsB,GAAG;IACpC,KAAK,CAAC,GAAW;QACf,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,MAAM,CACvC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,6BAAe,CAAC,CAC9C,CAAC;QACF,MAAM,YAAY,GAAG,IAAA,0BAAU,EAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACrD,IAAI,YAAY,CAAC,MAAM,IAAI,IAAA,iCAAc,EAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/D,OAAO,EAAC,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,EAAC,CAAC;QAChD,CAAC;QACD,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,GAAG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,EAAE,CAAC,EAAE,CAAC,8BAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;qBAC7C,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,KAAK,IAAI,CAAC,CAAC,CAAC;gBACV,MAAM,IAAI,GAAG,GAAG,GAAG,8BAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;gBACjE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACpC,CAAC;YACD,KAAK,MAAM;gBACT,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YACnC,KAAK,OAAO;gBACV,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QACvC,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FilterParserResponse,
|
|
1
|
+
import type { FilterParserResponse, TemporalFilter } from './filter_interface';
|
|
2
2
|
export declare const TemporalFilterExpression: {
|
|
3
|
-
parse(src: string): FilterParserResponse<
|
|
4
|
-
unparse(tc:
|
|
3
|
+
parse(src: string): FilterParserResponse<TemporalFilter>;
|
|
4
|
+
unparse(tc: TemporalFilter | null): string;
|
|
5
5
|
};
|
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.TemporalFilterExpression = void 0;
|
|
36
|
-
const
|
|
36
|
+
const filter_interface_1 = require("./filter_interface");
|
|
37
37
|
const ftemporal_parser_1 = __importDefault(require("./lib/ftemporal_parser"));
|
|
38
38
|
const nearley = __importStar(require("nearley"));
|
|
39
39
|
const nearley_parse_1 = require("./nearley_parse");
|
|
@@ -41,7 +41,7 @@ exports.TemporalFilterExpression = {
|
|
|
41
41
|
parse(src) {
|
|
42
42
|
const ftemporal_parser = new nearley.Parser(nearley.Grammar.fromCompiled(ftemporal_parser_1.default));
|
|
43
43
|
const parse_result = (0, nearley_parse_1.run_parser)(src, ftemporal_parser);
|
|
44
|
-
if (parse_result.parsed && (0,
|
|
44
|
+
if (parse_result.parsed && (0, filter_interface_1.isTemporalFilter)(parse_result.parsed)) {
|
|
45
45
|
return { parsed: parse_result.parsed, log: [] };
|
|
46
46
|
}
|
|
47
47
|
return { parsed: null, log: parse_result.log };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal_filter_expression.js","sourceRoot":"","sources":["../src/temporal_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,
|
|
1
|
+
{"version":3,"file":"temporal_filter_expression.js","sourceRoot":"","sources":["../src/temporal_filter_expression.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,yDAAoD;AACpD,8EAAuD;AACvD,iDAAmC;AACnC,mDAA2C;AAE9B,QAAA,wBAAwB,GAAG;IACtC,KAAK,CAAC,GAAW;QACf,MAAM,gBAAgB,GAAG,IAAI,OAAO,CAAC,MAAM,CACzC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,0BAAiB,CAAC,CAChD,CAAC;QACF,MAAM,YAAY,GAAG,IAAA,0BAAU,EAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;QACvD,IAAI,YAAY,CAAC,MAAM,IAAI,IAAA,mCAAgB,EAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YACjE,OAAO,EAAC,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,EAAC,CAAC;QAChD,CAAC;QACD,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAC,CAAC;IAC/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,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5D,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAClC,KAAK,KAAK;YACR,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5B,KAAK,UAAU;YACb,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;IACnC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy-filter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.246-dev250320220920",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Parsers for the Malloy filtering sub-languages",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"author": "",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"jest-diff": "^29.6.2",
|
|
26
|
+
"luxon": "^3.5.0",
|
|
26
27
|
"moo": "^0.5.2",
|
|
27
28
|
"nearley": "^2.20.1"
|
|
28
29
|
},
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {BooleanFilter, FilterParserResponse} from './filter_interface';
|
|
9
9
|
|
|
10
10
|
export const BooleanFilterExpression = {
|
|
11
|
-
parse(srcText: string): FilterParserResponse<
|
|
12
|
-
const ret: FilterParserResponse<
|
|
11
|
+
parse(srcText: string): FilterParserResponse<BooleanFilter> {
|
|
12
|
+
const ret: FilterParserResponse<BooleanFilter> = {parsed: null, log: []};
|
|
13
13
|
let src = srcText.toLowerCase().trim().replace(/\s\s+/, ' ');
|
|
14
14
|
let negate = false;
|
|
15
15
|
if (src.startsWith('not ')) {
|
|
@@ -44,7 +44,7 @@ export const BooleanFilterExpression = {
|
|
|
44
44
|
}
|
|
45
45
|
return ret;
|
|
46
46
|
},
|
|
47
|
-
unparse(bc:
|
|
47
|
+
unparse(bc: BooleanFilter | null): string {
|
|
48
48
|
if (bc === null) {
|
|
49
49
|
return '';
|
|
50
50
|
}
|
package/src/clause_utils.ts
CHANGED
|
@@ -8,26 +8,26 @@
|
|
|
8
8
|
import type {
|
|
9
9
|
ChainOp,
|
|
10
10
|
NumberRange,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
ClauseBase,
|
|
11
|
+
StringFilter,
|
|
12
|
+
NumberFilter,
|
|
14
13
|
TemporalUnit,
|
|
15
14
|
TemporalLiteral,
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
TemporalFilter,
|
|
16
|
+
FilterExpression,
|
|
17
|
+
} from './filter_interface';
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
isNumberFilter,
|
|
20
|
+
isStringFilter,
|
|
21
21
|
isStringCondition,
|
|
22
|
-
|
|
23
|
-
} from './
|
|
22
|
+
isTemporalFilter,
|
|
23
|
+
} from './filter_interface';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* If there is a minus token, add "not:true" to the clause
|
|
27
27
|
*/
|
|
28
28
|
export function maybeNot(data: (Object | undefined)[]) {
|
|
29
29
|
const [isMinus, op] = data;
|
|
30
|
-
if (isMinus && op &&
|
|
30
|
+
if (isMinus && op && isStringFilter(op)) {
|
|
31
31
|
return {...op, not: true};
|
|
32
32
|
}
|
|
33
33
|
return op;
|
|
@@ -98,7 +98,7 @@ function describeString(s: string) {
|
|
|
98
98
|
* Generate the correct match clause operator based on the contents
|
|
99
99
|
* of the match string.
|
|
100
100
|
*/
|
|
101
|
-
export function matchOp(matchSrc: string):
|
|
101
|
+
export function matchOp(matchSrc: string): StringFilter {
|
|
102
102
|
let matchTxt = matchSrc.trimStart();
|
|
103
103
|
const {hasLike, percentEnd, percentStart, endSpace} =
|
|
104
104
|
describeString(matchTxt);
|
|
@@ -143,7 +143,7 @@ export function matchOp(matchSrc: string): StringClause {
|
|
|
143
143
|
return {operator: '=', values: [unescape(matchTxt)]};
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
function sameAs<T extends
|
|
146
|
+
function sameAs<T extends FilterExpression>(a: T, b: FilterExpression): b is T {
|
|
147
147
|
return (
|
|
148
148
|
a.operator === b.operator && (a['not'] ?? false) === (b['not'] ?? false)
|
|
149
149
|
);
|
|
@@ -153,8 +153,8 @@ export function conjoin(
|
|
|
153
153
|
left: Object,
|
|
154
154
|
op: string,
|
|
155
155
|
right: Object
|
|
156
|
-
):
|
|
157
|
-
if (
|
|
156
|
+
): StringFilter | null {
|
|
157
|
+
if (isStringFilter(left) && isStringFilter(right)) {
|
|
158
158
|
if (op === ',') {
|
|
159
159
|
if (left.operator === '~' && sameAs(left, right)) {
|
|
160
160
|
return {
|
|
@@ -182,10 +182,10 @@ export function joinNumbers(
|
|
|
182
182
|
left: Object,
|
|
183
183
|
op: string,
|
|
184
184
|
right: Object
|
|
185
|
-
):
|
|
186
|
-
if (
|
|
185
|
+
): NumberFilter | null {
|
|
186
|
+
if (isNumberFilter(left) && isNumberFilter(right)) {
|
|
187
187
|
if (op === 'or' && left.operator === '=' && sameAs(left, right)) {
|
|
188
|
-
const ret:
|
|
188
|
+
const ret: NumberFilter = {
|
|
189
189
|
operator: '=',
|
|
190
190
|
values: [...left.values, ...right.values],
|
|
191
191
|
};
|
|
@@ -224,7 +224,7 @@ export function mkValues(n: string, nList: string[]) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
export function numNot(op: Object, notToken: unknown) {
|
|
227
|
-
if (
|
|
227
|
+
if (isNumberFilter(op) && notToken) {
|
|
228
228
|
if (op.operator === '=') return {operator: '!=', values: op.values};
|
|
229
229
|
if (op.operator === '!=') return {operator: '=', values: op.values};
|
|
230
230
|
return {...op, not: true};
|
|
@@ -233,7 +233,7 @@ export function numNot(op: Object, notToken: unknown) {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
export function temporalNot(op: Object, notToken: unknown) {
|
|
236
|
-
if (
|
|
236
|
+
if (isTemporalFilter(op) && notToken) {
|
|
237
237
|
return {...op, not: true};
|
|
238
238
|
}
|
|
239
239
|
return op;
|
|
@@ -243,8 +243,8 @@ export function joinTemporal(
|
|
|
243
243
|
left: Object,
|
|
244
244
|
op: string,
|
|
245
245
|
right: Object
|
|
246
|
-
):
|
|
247
|
-
if (
|
|
246
|
+
): TemporalFilter | null {
|
|
247
|
+
if (isTemporalFilter(left) && isTemporalFilter(right)) {
|
|
248
248
|
// if (
|
|
249
249
|
// (op === ',' || op === 'or') &&
|
|
250
250
|
// left.operator === '=' &&
|
|
@@ -5,87 +5,60 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
operator:
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isClauseBase(o: Object): o is ClauseBase {
|
|
13
|
-
return 'operator' in o;
|
|
8
|
+
interface FilterOperator<T extends string> {
|
|
9
|
+
operator: T;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
12
|
interface Negateable {
|
|
17
13
|
not?: boolean;
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
export interface Null extends
|
|
21
|
-
operator: 'null';
|
|
22
|
-
}
|
|
16
|
+
export interface Null extends FilterOperator<'null'>, Negateable {}
|
|
23
17
|
|
|
24
18
|
export type ChainOp = 'and' | 'or' | ',';
|
|
25
19
|
export function isChainOp(s: string): s is ChainOp {
|
|
26
20
|
return ['and', 'or', ','].includes(s);
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
interface ClauseChain<T> extends
|
|
30
|
-
operator: ChainOp;
|
|
23
|
+
interface ClauseChain<T> extends FilterOperator<ChainOp> {
|
|
31
24
|
members: T[];
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
type BooleanChainOp = 'and' | 'or';
|
|
35
|
-
export interface BooleanChain<T> extends
|
|
36
|
-
operator: BooleanChainOp;
|
|
28
|
+
export interface BooleanChain<T> extends FilterOperator<BooleanChainOp> {
|
|
37
29
|
members: T[];
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
interface ClauseGroup<T> extends
|
|
41
|
-
operator: '()';
|
|
32
|
+
interface ClauseGroup<T> extends FilterOperator<'()'>, Negateable {
|
|
42
33
|
expr: T;
|
|
43
34
|
}
|
|
44
35
|
|
|
45
36
|
export type StringConditionOperator = 'starts' | 'ends' | 'contains' | '=';
|
|
46
|
-
export function isStringCondition(sc:
|
|
37
|
+
export function isStringCondition(sc: StringFilter): sc is StringCondition {
|
|
47
38
|
return ['starts', 'ends', 'contains', '='].includes(sc.operator);
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
export interface StringCondition
|
|
51
|
-
|
|
41
|
+
export interface StringCondition
|
|
42
|
+
extends FilterOperator<StringConditionOperator>,
|
|
43
|
+
Negateable {
|
|
52
44
|
values: string[];
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
export interface StringMatch extends
|
|
56
|
-
operator: '~';
|
|
47
|
+
export interface StringMatch extends FilterOperator<'~'>, Negateable {
|
|
57
48
|
escaped_values: string[];
|
|
58
49
|
}
|
|
59
50
|
|
|
60
|
-
export interface StringEmpty extends
|
|
61
|
-
operator: 'empty';
|
|
62
|
-
}
|
|
51
|
+
export interface StringEmpty extends FilterOperator<'empty'>, Negateable {}
|
|
63
52
|
|
|
64
|
-
export type
|
|
53
|
+
export type StringFilter =
|
|
65
54
|
| StringCondition
|
|
66
55
|
| StringMatch
|
|
67
56
|
| Null
|
|
68
57
|
| StringEmpty
|
|
69
|
-
| ClauseChain<
|
|
70
|
-
| ClauseGroup<
|
|
71
|
-
|
|
72
|
-
export type BooleanOperator = 'true' | 'false' | 'false_or_null';
|
|
73
|
-
|
|
74
|
-
export interface BooleanCondition extends Negateable {
|
|
75
|
-
operator: BooleanOperator;
|
|
76
|
-
}
|
|
58
|
+
| ClauseChain<StringFilter>
|
|
59
|
+
| ClauseGroup<StringFilter>;
|
|
77
60
|
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
export function isBooleanClause(bc: Object): bc is BooleanClause {
|
|
81
|
-
return (
|
|
82
|
-
'operator' in bc &&
|
|
83
|
-
typeof bc.operator === 'string' &&
|
|
84
|
-
['null', 'true', 'false', 'false_or_null'].includes(bc.operator)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function isStringClause(sc: Object): sc is StringClause {
|
|
61
|
+
export function isStringFilter(sc: Object): sc is StringFilter {
|
|
89
62
|
return (
|
|
90
63
|
'operator' in sc &&
|
|
91
64
|
typeof sc.operator === 'string' &&
|
|
@@ -105,31 +78,47 @@ export function isStringClause(sc: Object): sc is StringClause {
|
|
|
105
78
|
);
|
|
106
79
|
}
|
|
107
80
|
|
|
81
|
+
export type BooleanOperator = 'true' | 'false' | 'false_or_null';
|
|
82
|
+
|
|
83
|
+
export interface BooleanCondition extends Negateable {
|
|
84
|
+
operator: BooleanOperator;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type BooleanFilter = BooleanCondition | Null;
|
|
88
|
+
|
|
89
|
+
export function isBooleanFilter(bc: Object): bc is BooleanFilter {
|
|
90
|
+
return (
|
|
91
|
+
'operator' in bc &&
|
|
92
|
+
typeof bc.operator === 'string' &&
|
|
93
|
+
['null', 'true', 'false', 'false_or_null'].includes(bc.operator)
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
108
97
|
export type NumberOperator = '<=' | '>=' | '!=' | '=' | '>' | '<';
|
|
109
98
|
|
|
110
|
-
export interface NumberCondition
|
|
111
|
-
|
|
99
|
+
export interface NumberCondition
|
|
100
|
+
extends FilterOperator<NumberOperator>,
|
|
101
|
+
Negateable {
|
|
112
102
|
values: string[];
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
export type NumberRangeOperator = '<=' | '>=' | '>' | '<';
|
|
116
106
|
|
|
117
|
-
export interface NumberRange extends
|
|
118
|
-
operator: 'range';
|
|
107
|
+
export interface NumberRange extends FilterOperator<'range'>, Negateable {
|
|
119
108
|
startOperator: NumberRangeOperator;
|
|
120
109
|
startValue: string;
|
|
121
110
|
endOperator: NumberRangeOperator;
|
|
122
111
|
endValue: string;
|
|
123
112
|
}
|
|
124
113
|
|
|
125
|
-
export type
|
|
114
|
+
export type NumberFilter =
|
|
126
115
|
| NumberCondition
|
|
127
116
|
| NumberRange
|
|
128
117
|
| Null
|
|
129
|
-
| ClauseGroup<
|
|
130
|
-
| BooleanChain<
|
|
118
|
+
| ClauseGroup<NumberFilter>
|
|
119
|
+
| BooleanChain<NumberFilter>;
|
|
131
120
|
|
|
132
|
-
export function
|
|
121
|
+
export function isNumberFilter(sc: Object): sc is NumberFilter {
|
|
133
122
|
return (
|
|
134
123
|
'operator' in sc &&
|
|
135
124
|
typeof sc.operator === 'string' &&
|
|
@@ -212,43 +201,40 @@ export type Moment =
|
|
|
212
201
|
| WhichdayMoment
|
|
213
202
|
| WeekdayMoment;
|
|
214
203
|
|
|
215
|
-
export interface Before extends Negateable {
|
|
216
|
-
operator: 'before';
|
|
204
|
+
export interface Before extends FilterOperator<'before'>, Negateable {
|
|
217
205
|
before: Moment;
|
|
218
206
|
}
|
|
219
207
|
|
|
220
|
-
export interface After extends Negateable {
|
|
221
|
-
operator: 'after';
|
|
208
|
+
export interface After extends FilterOperator<'after'>, Negateable {
|
|
222
209
|
after: Moment;
|
|
223
210
|
}
|
|
224
211
|
|
|
225
|
-
export interface To extends Negateable {
|
|
226
|
-
operator: 'to';
|
|
212
|
+
export interface To extends FilterOperator<'to'>, Negateable {
|
|
227
213
|
fromMoment: Moment;
|
|
228
214
|
toMoment: Moment;
|
|
229
215
|
}
|
|
230
216
|
|
|
231
|
-
export interface For extends Negateable, Duration {
|
|
232
|
-
operator: 'for';
|
|
217
|
+
export interface For extends FilterOperator<'for'>, Negateable, Duration {
|
|
233
218
|
begin: Moment;
|
|
234
219
|
}
|
|
235
220
|
|
|
236
221
|
// N units starting in the past, including this one
|
|
237
|
-
export interface in_last
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
export interface in_last
|
|
223
|
+
extends FilterOperator<'in_last'>,
|
|
224
|
+
Negateable,
|
|
225
|
+
Duration {}
|
|
240
226
|
|
|
241
227
|
// Nunits starting in the past, not including this one
|
|
242
|
-
export interface JustUnits
|
|
243
|
-
|
|
244
|
-
|
|
228
|
+
export interface JustUnits
|
|
229
|
+
extends FilterOperator<'last' | 'next'>,
|
|
230
|
+
Negateable,
|
|
231
|
+
Duration {}
|
|
245
232
|
|
|
246
|
-
export interface InMoment extends Negateable {
|
|
247
|
-
operator: 'in';
|
|
233
|
+
export interface InMoment extends FilterOperator<'in'>, Negateable {
|
|
248
234
|
in: Moment;
|
|
249
235
|
}
|
|
250
236
|
|
|
251
|
-
export type
|
|
237
|
+
export type TemporalFilter =
|
|
252
238
|
| Null
|
|
253
239
|
| Before
|
|
254
240
|
| After
|
|
@@ -257,10 +243,10 @@ export type TemporalClause =
|
|
|
257
243
|
| JustUnits
|
|
258
244
|
| in_last
|
|
259
245
|
| InMoment
|
|
260
|
-
| BooleanChain<
|
|
261
|
-
| ClauseGroup<
|
|
246
|
+
| BooleanChain<TemporalFilter>
|
|
247
|
+
| ClauseGroup<TemporalFilter>;
|
|
262
248
|
|
|
263
|
-
export function
|
|
249
|
+
export function isTemporalFilter(sc: Object): sc is TemporalFilter {
|
|
264
250
|
return (
|
|
265
251
|
'operator' in sc &&
|
|
266
252
|
typeof sc.operator === 'string' &&
|
|
@@ -283,6 +269,16 @@ export function isTemporalClause(sc: Object): sc is TemporalClause {
|
|
|
283
269
|
);
|
|
284
270
|
}
|
|
285
271
|
|
|
272
|
+
export type FilterExpression =
|
|
273
|
+
| BooleanFilter
|
|
274
|
+
| NumberFilter
|
|
275
|
+
| StringFilter
|
|
276
|
+
| TemporalFilter;
|
|
277
|
+
|
|
278
|
+
export function isFilterExpression(obj: Object): obj is FilterExpression {
|
|
279
|
+
return 'operator' in obj;
|
|
280
|
+
}
|
|
281
|
+
|
|
286
282
|
export type FilterLogSeverity = 'error' | 'warn';
|
|
287
283
|
|
|
288
284
|
export interface FilterLog {
|
|
@@ -292,7 +288,17 @@ export interface FilterLog {
|
|
|
292
288
|
severity: FilterLogSeverity;
|
|
293
289
|
}
|
|
294
290
|
|
|
295
|
-
export interface FilterParserResponse<T extends
|
|
291
|
+
export interface FilterParserResponse<T extends FilterExpression> {
|
|
296
292
|
parsed: T | null;
|
|
297
293
|
log: FilterLog[];
|
|
298
294
|
}
|
|
295
|
+
|
|
296
|
+
export type FilterableType =
|
|
297
|
+
| 'string'
|
|
298
|
+
| 'number'
|
|
299
|
+
| 'boolean'
|
|
300
|
+
| 'timestamp'
|
|
301
|
+
| 'date';
|
|
302
|
+
export function isFilterable(s: string): s is FilterableType {
|
|
303
|
+
return ['string', 'number', 'boolean', 'timestamp', 'date'].includes(s);
|
|
304
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export * from './filter_interface';
|
|
8
9
|
export {BooleanFilterExpression} from './boolean_filter_expression';
|
|
9
|
-
export {TemporalFilterExpression} from './temporal_filter_expression';
|
|
10
10
|
export {NumberFilterExpression} from './number_filter_expression';
|
|
11
11
|
export {StringFilterExpression} from './string_filter_expression';
|
|
12
|
-
export
|
|
12
|
+
export {TemporalFilterExpression} from './temporal_filter_expression';
|
|
@@ -38,6 +38,7 @@ declare var AGO: any;
|
|
|
38
38
|
declare var FROM: any;
|
|
39
39
|
declare var literal: any;
|
|
40
40
|
declare var lit_day: any;
|
|
41
|
+
declare var lit_min: any;
|
|
41
42
|
declare var lit_hour: any;
|
|
42
43
|
declare var lit_month: any;
|
|
43
44
|
declare var lit_quarter: any;
|
|
@@ -111,9 +112,10 @@ const temporal_lexer = moo.compile({
|
|
|
111
112
|
literal: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*))/,
|
|
112
113
|
lit_week: /\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,
|
|
113
114
|
lit_quarter: /\d\d\d\d-[qQ][1234]/,
|
|
115
|
+
lit_min: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,
|
|
114
116
|
lit_hour: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d/,
|
|
115
117
|
lit_day: /\d\d\d\d-\d\d-\d\d/,
|
|
116
|
-
lit_month: /\d\d\d\d-\d\d
|
|
118
|
+
lit_month: /\d\d\d\d-\d\d/,
|
|
117
119
|
lit_year: /\d\d\d\d/,
|
|
118
120
|
n: /\d+/,
|
|
119
121
|
});
|
|
@@ -210,6 +212,7 @@ const grammar: Grammar = {
|
|
|
210
212
|
{"name": "moment", "symbols": ["timeLiteral"], "postprocess": d => d[0]},
|
|
211
213
|
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("literal") ? {type: "literal"} : literal)], "postprocess": ([l]) => timeLiteral(l.text)},
|
|
212
214
|
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("lit_day") ? {type: "lit_day"} : lit_day)], "postprocess": ([l]) => timeLiteral(l.text, 'day')},
|
|
215
|
+
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("lit_min") ? {type: "lit_min"} : lit_min)], "postprocess": ([l]) => timeLiteral(l.text, 'minute')},
|
|
213
216
|
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("lit_hour") ? {type: "lit_hour"} : lit_hour)], "postprocess": ([l]) => timeLiteral(l.text, 'hour')},
|
|
214
217
|
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("lit_month") ? {type: "lit_month"} : lit_month)], "postprocess": ([l]) => timeLiteral(l.text, 'month')},
|
|
215
218
|
{"name": "timeLiteral", "symbols": [(temporal_lexer.has("lit_quarter") ? {type: "lit_quarter"} : lit_quarter)], "postprocess": ([l]) => timeLiteral(l.text, 'quarter')},
|