@malloydata/malloy-filter 0.0.237-dev250224215546 → 0.0.237-dev250225015031
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/SAMPLES.md +336 -114
- package/SERIALIZE_SAMPLES.md +268 -64
- package/dist/a_simple_parser.js +6 -0
- package/dist/a_simple_parser.js.map +1 -1
- package/dist/base_parser.js +6 -0
- package/dist/base_parser.js.map +1 -1
- package/dist/boolean_parser.js +28 -13
- package/dist/boolean_parser.js.map +1 -1
- package/dist/boolean_serializer.js +12 -6
- package/dist/boolean_serializer.js.map +1 -1
- package/dist/clause_types.d.ts +20 -15
- package/dist/clause_types.js +6 -0
- package/dist/clause_types.js.map +1 -1
- package/dist/date_parser.js +135 -116
- package/dist/date_parser.js.map +1 -1
- package/dist/date_serializer.js +26 -20
- package/dist/date_serializer.js.map +1 -1
- package/dist/date_types.d.ts +21 -21
- package/dist/date_types.js +6 -0
- package/dist/date_types.js.map +1 -1
- package/dist/generate_samples.js +32 -25
- package/dist/generate_samples.js.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/number_parser.js +43 -25
- package/dist/number_parser.js.map +1 -1
- package/dist/number_serializer.js +10 -4
- package/dist/number_serializer.js.map +1 -1
- package/dist/string_parser.d.ts +0 -1
- package/dist/string_parser.js +47 -79
- package/dist/string_parser.js.map +1 -1
- package/dist/string_serializer.d.ts +1 -0
- package/dist/string_serializer.js +49 -33
- package/dist/string_serializer.js.map +1 -1
- package/dist/token_types.js +6 -0
- package/dist/token_types.js.map +1 -1
- package/dist/tokenizer.js +9 -3
- package/dist/tokenizer.js.map +1 -1
- package/dist/tokenizer.spec.js +13 -7
- package/dist/tokenizer.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/a_simple_parser.ts +7 -0
- package/src/base_parser.ts +7 -0
- package/src/boolean_parser.ts +30 -18
- package/src/boolean_serializer.ts +13 -6
- package/src/clause_types.ts +36 -31
- package/src/date_parser.ts +136 -118
- package/src/date_serializer.ts +27 -20
- package/src/date_types.ts +42 -34
- package/src/generate_samples.ts +33 -25
- package/src/index.ts +7 -0
- package/src/number_parser.ts +45 -26
- package/src/number_serializer.ts +11 -4
- package/src/string_parser.ts +51 -79
- package/src/string_serializer.ts +65 -39
- package/src/token_types.ts +7 -0
- package/src/tokenizer.spec.ts +14 -7
- package/src/tokenizer.ts +10 -3
package/package.json
CHANGED
package/src/a_simple_parser.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import {BooleanParser} from './boolean_parser';
|
|
2
9
|
import {StringParser} from './string_parser';
|
|
3
10
|
import {NumberParser} from './number_parser';
|
package/src/base_parser.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import {Token} from './token_types';
|
|
2
9
|
|
|
3
10
|
export abstract class BaseParser {
|
package/src/boolean_parser.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import {SpecialToken, Tokenizer, TokenizerParams} from './tokenizer';
|
|
2
|
-
import {
|
|
3
|
-
BooleanClause,
|
|
4
|
-
BooleanParserResponse,
|
|
5
|
-
FilterError,
|
|
6
|
-
} from './clause_types';
|
|
9
|
+
import {BooleanClause, BooleanParserResponse, FilterLog} from './clause_types';
|
|
7
10
|
import {BaseParser} from './base_parser';
|
|
8
11
|
|
|
9
12
|
export class BooleanParser extends BaseParser {
|
|
@@ -14,11 +17,11 @@ export class BooleanParser extends BaseParser {
|
|
|
14
17
|
private tokenize(): void {
|
|
15
18
|
const specialSubstrings: SpecialToken[] = [{type: ',', value: ','}];
|
|
16
19
|
const specialWords: SpecialToken[] = [
|
|
17
|
-
{type: '
|
|
18
|
-
{type: '
|
|
19
|
-
{type: '
|
|
20
|
-
{type: '
|
|
21
|
-
{type: '
|
|
20
|
+
{type: 'null', value: 'null', ignoreCase: true},
|
|
21
|
+
{type: 'not_null', value: '-null', ignoreCase: true},
|
|
22
|
+
{type: 'true', value: 'true', ignoreCase: true},
|
|
23
|
+
{type: 'false', value: '=false', ignoreCase: true},
|
|
24
|
+
{type: 'false_or_null', value: 'false', ignoreCase: true},
|
|
22
25
|
];
|
|
23
26
|
const params: TokenizerParams = {
|
|
24
27
|
trimWordWhitespace: true,
|
|
@@ -36,23 +39,32 @@ export class BooleanParser extends BaseParser {
|
|
|
36
39
|
this.index = 0;
|
|
37
40
|
this.tokenize();
|
|
38
41
|
const clauses: BooleanClause[] = [];
|
|
39
|
-
const
|
|
42
|
+
const logs: FilterLog[] = [];
|
|
40
43
|
while (this.index < this.tokens.length) {
|
|
41
44
|
const token = this.getNext();
|
|
42
45
|
if (token.type === ',') {
|
|
46
|
+
if (this.index > 0 && this.tokens[this.index - 1].type === ',') {
|
|
47
|
+
logs.push({
|
|
48
|
+
severity: 'warn',
|
|
49
|
+
message: 'Empty clause',
|
|
50
|
+
startIndex: token.startIndex,
|
|
51
|
+
endIndex: token.endIndex,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
43
54
|
this.index++;
|
|
44
55
|
} else if (
|
|
45
|
-
token.type === '
|
|
46
|
-
token.type === '
|
|
47
|
-
token.type === '
|
|
48
|
-
token.type === '
|
|
49
|
-
token.type === '
|
|
56
|
+
token.type === 'null' ||
|
|
57
|
+
token.type === 'true' ||
|
|
58
|
+
token.type === 'false' ||
|
|
59
|
+
token.type === 'false_or_null' ||
|
|
60
|
+
token.type === 'not_null'
|
|
50
61
|
) {
|
|
51
62
|
const clause: BooleanClause = {operator: token.type};
|
|
52
63
|
clauses.push(clause);
|
|
53
64
|
this.index++;
|
|
54
65
|
} else {
|
|
55
|
-
|
|
66
|
+
logs.push({
|
|
67
|
+
severity: 'error',
|
|
56
68
|
message: 'Invalid token ' + token.value,
|
|
57
69
|
startIndex: token.startIndex,
|
|
58
70
|
endIndex: token.endIndex,
|
|
@@ -60,6 +72,6 @@ export class BooleanParser extends BaseParser {
|
|
|
60
72
|
this.index++;
|
|
61
73
|
}
|
|
62
74
|
}
|
|
63
|
-
return {clauses,
|
|
75
|
+
return {clauses, logs};
|
|
64
76
|
}
|
|
65
77
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
import {BooleanClause} from './clause_types';
|
|
2
9
|
|
|
3
10
|
export class BooleanSerializer {
|
|
@@ -12,12 +19,12 @@ export class BooleanSerializer {
|
|
|
12
19
|
|
|
13
20
|
private static booleanClauseToString(clause: BooleanClause): string {
|
|
14
21
|
switch (clause.operator) {
|
|
15
|
-
case '
|
|
16
|
-
return '-
|
|
17
|
-
case '
|
|
18
|
-
return '
|
|
19
|
-
case '
|
|
20
|
-
return '=
|
|
22
|
+
case 'not_null':
|
|
23
|
+
return '-null';
|
|
24
|
+
case 'false_or_null':
|
|
25
|
+
return 'false';
|
|
26
|
+
case 'false':
|
|
27
|
+
return '=false';
|
|
21
28
|
}
|
|
22
29
|
return clause.operator;
|
|
23
30
|
}
|
package/src/clause_types.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
export type NumberOperator = '<=' | '>=' | '!=' | '=' | '>' | '<';
|
|
2
9
|
|
|
3
10
|
export type NumberValue = number;
|
|
@@ -8,11 +15,11 @@ export interface NumberCondition {
|
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
export interface NumberNull {
|
|
11
|
-
operator: '
|
|
18
|
+
operator: 'null';
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
export interface NumberNotNull {
|
|
15
|
-
operator: '
|
|
22
|
+
operator: 'not_null';
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
export type NumberRangeOperator = '<=' | '>=' | '>' | '<';
|
|
@@ -35,14 +42,14 @@ export type StringConditionOperator =
|
|
|
35
42
|
| 'starts'
|
|
36
43
|
| 'ends'
|
|
37
44
|
| 'contains'
|
|
38
|
-
| '
|
|
39
|
-
| '
|
|
40
|
-
| '
|
|
41
|
-
| '~'
|
|
45
|
+
| 'not_starts'
|
|
46
|
+
| 'not_ends'
|
|
47
|
+
| 'not_contains'
|
|
42
48
|
| '='
|
|
43
|
-
| '!~'
|
|
44
49
|
| '!=';
|
|
45
50
|
|
|
51
|
+
export type StringMatchOperator = '~' | '!~';
|
|
52
|
+
|
|
46
53
|
export type StringValue = string;
|
|
47
54
|
|
|
48
55
|
export interface StringCondition {
|
|
@@ -50,68 +57,66 @@ export interface StringCondition {
|
|
|
50
57
|
values: StringValue[];
|
|
51
58
|
}
|
|
52
59
|
|
|
60
|
+
export interface StringMatch {
|
|
61
|
+
operator: StringMatchOperator;
|
|
62
|
+
escaped_values: StringValue[];
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
export interface StringNull {
|
|
54
|
-
operator: '
|
|
66
|
+
operator: 'null';
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
export interface StringNotNull {
|
|
58
|
-
operator: '
|
|
70
|
+
operator: 'not_null';
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
export interface StringEmpty {
|
|
62
|
-
operator: '
|
|
74
|
+
operator: 'empty';
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
export interface StringNotEmpty {
|
|
66
|
-
operator: '
|
|
78
|
+
operator: 'not_empty';
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
export type StringClause =
|
|
70
82
|
| StringCondition
|
|
83
|
+
| StringMatch
|
|
71
84
|
| StringNull
|
|
72
85
|
| StringNotNull
|
|
73
86
|
| StringEmpty
|
|
74
87
|
| StringNotEmpty;
|
|
75
88
|
|
|
76
89
|
export type BooleanOperator =
|
|
77
|
-
| '
|
|
78
|
-
| '
|
|
79
|
-
| '
|
|
80
|
-
| '
|
|
81
|
-
| '
|
|
90
|
+
| 'true'
|
|
91
|
+
| 'false'
|
|
92
|
+
| 'false_or_null'
|
|
93
|
+
| 'null'
|
|
94
|
+
| 'not_null';
|
|
82
95
|
|
|
83
96
|
export interface BooleanClause {
|
|
84
97
|
operator: BooleanOperator;
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
export
|
|
100
|
+
export type FilterLogSeverity = 'error' | 'warn';
|
|
101
|
+
|
|
102
|
+
export interface FilterLog {
|
|
88
103
|
message: string;
|
|
89
104
|
startIndex: number;
|
|
90
105
|
endIndex: number;
|
|
106
|
+
severity: FilterLogSeverity;
|
|
91
107
|
}
|
|
92
108
|
|
|
93
109
|
export interface BooleanParserResponse {
|
|
94
110
|
clauses: BooleanClause[];
|
|
95
|
-
|
|
111
|
+
logs: FilterLog[];
|
|
96
112
|
}
|
|
97
113
|
|
|
98
114
|
export interface NumberParserResponse {
|
|
99
115
|
clauses: NumberClause[];
|
|
100
|
-
|
|
116
|
+
logs: FilterLog[];
|
|
101
117
|
}
|
|
102
118
|
|
|
103
|
-
export type QuoteType =
|
|
104
|
-
| 'SINGLE'
|
|
105
|
-
| 'DOUBLE'
|
|
106
|
-
| 'BACKTICK'
|
|
107
|
-
| 'TRIPLESINGLE'
|
|
108
|
-
| 'TRIPLEDOUBLE'
|
|
109
|
-
| 'ESCAPEDSINGLE'
|
|
110
|
-
| 'ESCAPEDDOUBLE'
|
|
111
|
-
| 'ESCAPEDBACKTICK';
|
|
112
|
-
|
|
113
119
|
export interface StringParserResponse {
|
|
114
120
|
clauses: StringClause[];
|
|
115
|
-
|
|
116
|
-
quotes?: QuoteType[]; // List of quote types found in the string.
|
|
121
|
+
logs: FilterLog[];
|
|
117
122
|
}
|