@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.
Files changed (58) hide show
  1. package/SAMPLES.md +336 -114
  2. package/SERIALIZE_SAMPLES.md +268 -64
  3. package/dist/a_simple_parser.js +6 -0
  4. package/dist/a_simple_parser.js.map +1 -1
  5. package/dist/base_parser.js +6 -0
  6. package/dist/base_parser.js.map +1 -1
  7. package/dist/boolean_parser.js +28 -13
  8. package/dist/boolean_parser.js.map +1 -1
  9. package/dist/boolean_serializer.js +12 -6
  10. package/dist/boolean_serializer.js.map +1 -1
  11. package/dist/clause_types.d.ts +20 -15
  12. package/dist/clause_types.js +6 -0
  13. package/dist/clause_types.js.map +1 -1
  14. package/dist/date_parser.js +135 -116
  15. package/dist/date_parser.js.map +1 -1
  16. package/dist/date_serializer.js +26 -20
  17. package/dist/date_serializer.js.map +1 -1
  18. package/dist/date_types.d.ts +21 -21
  19. package/dist/date_types.js +6 -0
  20. package/dist/date_types.js.map +1 -1
  21. package/dist/generate_samples.js +32 -25
  22. package/dist/generate_samples.js.map +1 -1
  23. package/dist/index.js +6 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/number_parser.js +43 -25
  26. package/dist/number_parser.js.map +1 -1
  27. package/dist/number_serializer.js +10 -4
  28. package/dist/number_serializer.js.map +1 -1
  29. package/dist/string_parser.d.ts +0 -1
  30. package/dist/string_parser.js +47 -79
  31. package/dist/string_parser.js.map +1 -1
  32. package/dist/string_serializer.d.ts +1 -0
  33. package/dist/string_serializer.js +49 -33
  34. package/dist/string_serializer.js.map +1 -1
  35. package/dist/token_types.js +6 -0
  36. package/dist/token_types.js.map +1 -1
  37. package/dist/tokenizer.js +9 -3
  38. package/dist/tokenizer.js.map +1 -1
  39. package/dist/tokenizer.spec.js +13 -7
  40. package/dist/tokenizer.spec.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/a_simple_parser.ts +7 -0
  43. package/src/base_parser.ts +7 -0
  44. package/src/boolean_parser.ts +30 -18
  45. package/src/boolean_serializer.ts +13 -6
  46. package/src/clause_types.ts +36 -31
  47. package/src/date_parser.ts +136 -118
  48. package/src/date_serializer.ts +27 -20
  49. package/src/date_types.ts +42 -34
  50. package/src/generate_samples.ts +33 -25
  51. package/src/index.ts +7 -0
  52. package/src/number_parser.ts +45 -26
  53. package/src/number_serializer.ts +11 -4
  54. package/src/string_parser.ts +51 -79
  55. package/src/string_serializer.ts +65 -39
  56. package/src/token_types.ts +7 -0
  57. package/src/tokenizer.spec.ts +14 -7
  58. package/src/tokenizer.ts +10 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy-filter",
3
- "version": "0.0.237-dev250224215546",
3
+ "version": "0.0.237-dev250225015031",
4
4
  "license": "MIT",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
@@ -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';
@@ -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 {
@@ -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: 'NULL', value: 'null', ignoreCase: true},
18
- {type: 'NOTNULL', value: '-null', ignoreCase: true},
19
- {type: 'TRUE', value: 'true', ignoreCase: true},
20
- {type: 'FALSE', value: '=false', ignoreCase: true},
21
- {type: 'FALSEORNULL', value: 'false', ignoreCase: true},
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 errors: FilterError[] = [];
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 === 'NULL' ||
46
- token.type === 'TRUE' ||
47
- token.type === 'FALSE' ||
48
- token.type === 'FALSEORNULL' ||
49
- token.type === 'NOTNULL'
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
- errors.push({
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, errors};
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 'NOTNULL':
16
- return '-NULL';
17
- case 'FALSEORNULL':
18
- return 'FALSE';
19
- case 'FALSE':
20
- return '=FALSE';
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
  }
@@ -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: 'NULL';
18
+ operator: 'null';
12
19
  }
13
20
 
14
21
  export interface NumberNotNull {
15
- operator: 'NOTNULL';
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
- | 'notStarts'
39
- | 'notEnds'
40
- | 'notContains'
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: 'NULL';
66
+ operator: 'null';
55
67
  }
56
68
 
57
69
  export interface StringNotNull {
58
- operator: 'NOTNULL';
70
+ operator: 'not_null';
59
71
  }
60
72
 
61
73
  export interface StringEmpty {
62
- operator: 'EMPTY';
74
+ operator: 'empty';
63
75
  }
64
76
 
65
77
  export interface StringNotEmpty {
66
- operator: 'NOTEMPTY';
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
- | 'TRUE'
78
- | 'FALSE'
79
- | 'FALSEORNULL'
80
- | 'NULL'
81
- | 'NOTNULL';
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 interface FilterError {
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
- errors: FilterError[];
111
+ logs: FilterLog[];
96
112
  }
97
113
 
98
114
  export interface NumberParserResponse {
99
115
  clauses: NumberClause[];
100
- errors: FilterError[];
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
- errors: FilterError[];
116
- quotes?: QuoteType[]; // List of quote types found in the string.
121
+ logs: FilterLog[];
117
122
  }