@malloydata/malloy-filter 0.0.237-dev250222025222 → 0.0.237-dev250222205057

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 (69) hide show
  1. package/dist/a_simple_parser.js +12 -9
  2. package/dist/a_simple_parser.js.map +1 -1
  3. package/dist/base_parser.d.ts +0 -2
  4. package/dist/base_parser.js.map +1 -1
  5. package/dist/boolean_parser.d.ts +2 -2
  6. package/dist/boolean_parser.js +3 -1
  7. package/dist/boolean_parser.js.map +1 -1
  8. package/dist/boolean_serializer.d.ts +4 -4
  9. package/dist/boolean_serializer.js +12 -4
  10. package/dist/boolean_serializer.js.map +1 -1
  11. package/dist/clause_types.d.ts +40 -47
  12. package/dist/date_parser.d.ts +13 -11
  13. package/dist/date_parser.js +192 -131
  14. package/dist/date_parser.js.map +1 -1
  15. package/dist/date_serializer.d.ts +6 -5
  16. package/dist/date_serializer.js +65 -77
  17. package/dist/date_serializer.js.map +1 -1
  18. package/dist/date_types.d.ts +75 -0
  19. package/dist/{filter_types.js → date_types.js} +1 -1
  20. package/dist/date_types.js.map +1 -0
  21. package/dist/generate_samples.js +162 -87
  22. package/dist/generate_samples.js.map +1 -1
  23. package/dist/number_parser.d.ts +2 -5
  24. package/dist/number_parser.js +10 -51
  25. package/dist/number_parser.js.map +1 -1
  26. package/dist/number_serializer.d.ts +4 -4
  27. package/dist/number_serializer.js +17 -14
  28. package/dist/number_serializer.js.map +1 -1
  29. package/dist/string_parser.d.ts +2 -2
  30. package/dist/string_parser.js +21 -21
  31. package/dist/string_parser.js.map +1 -1
  32. package/dist/string_serializer.d.ts +6 -5
  33. package/dist/string_serializer.js +38 -24
  34. package/dist/string_serializer.js.map +1 -1
  35. package/package.json +1 -2
  36. package/src/DEVELOPING.md +2 -5
  37. package/src/a_simple_parser.ts +12 -9
  38. package/src/base_parser.ts +0 -3
  39. package/src/boolean_parser.ts +10 -5
  40. package/src/boolean_serializer.ts +14 -7
  41. package/src/clause_types.ts +65 -108
  42. package/src/date_parser.ts +229 -192
  43. package/src/date_serializer.ts +59 -87
  44. package/src/date_types.ts +159 -0
  45. package/src/generate_samples.ts +178 -109
  46. package/src/number_parser.ts +14 -63
  47. package/src/number_serializer.ts +19 -20
  48. package/src/string_parser.ts +40 -27
  49. package/src/string_serializer.ts +58 -32
  50. package/tsconfig.json +1 -6
  51. package/dist/a_simple_serializer.d.ts +0 -1
  52. package/dist/a_simple_serializer.js +0 -31
  53. package/dist/a_simple_serializer.js.map +0 -1
  54. package/dist/base_serializer.d.ts +0 -6
  55. package/dist/base_serializer.js +0 -11
  56. package/dist/base_serializer.js.map +0 -1
  57. package/dist/filter_parser.d.ts +0 -12
  58. package/dist/filter_parser.js +0 -66
  59. package/dist/filter_parser.js.map +0 -1
  60. package/dist/filter_serializer.d.ts +0 -13
  61. package/dist/filter_serializer.js +0 -43
  62. package/dist/filter_serializer.js.map +0 -1
  63. package/dist/filter_types.d.ts +0 -10
  64. package/dist/filter_types.js.map +0 -1
  65. package/src/a_simple_serializer.ts +0 -40
  66. package/src/base_serializer.ts +0 -9
  67. package/src/filter_parser.ts +0 -68
  68. package/src/filter_serializer.ts +0 -49
  69. package/src/filter_types.ts +0 -12
@@ -1,7 +1,13 @@
1
1
  import {SpecialToken, Tokenizer, TokenizerParams} from './tokenizer';
2
- import {StringCondition, StringOperator, QuoteType} from './clause_types';
2
+ import {
3
+ StringClause,
4
+ StringCondition,
5
+ StringConditionOperator,
6
+ QuoteType,
7
+ FilterError,
8
+ StringParserResponse,
9
+ } from './clause_types';
3
10
  import {BaseParser} from './base_parser';
4
- import {FilterParserResponse, FilterError} from './filter_types';
5
11
 
6
12
  export class StringParser extends BaseParser {
7
13
  private static readonly percentRegex: RegExp = /(?<!\\)%/;
@@ -35,26 +41,22 @@ export class StringParser extends BaseParser {
35
41
  this.tokens = Tokenizer.convertSpecialWords(this.tokens, specialWords);
36
42
  }
37
43
 
38
- public parse(): FilterParserResponse {
44
+ public parse(): StringParserResponse {
39
45
  this.index = 0;
40
46
  this.tokenize();
41
- const clauses: StringCondition[] = [];
47
+ const clauses: StringClause[] = [];
42
48
  const errors: FilterError[] = [];
43
49
  while (this.index < this.tokens.length) {
44
50
  const token = this.getNext();
45
51
  if (token.type === ',') {
46
52
  this.index++;
47
- } else if (token.type === 'NULL') {
48
- clauses.push({operator: '=', values: [null]});
49
- this.index++;
50
- } else if (token.type === 'EMPTY') {
51
- clauses.push({operator: 'EMPTY', values: [null]});
52
- this.index++;
53
- } else if (token.type === 'NOTNULL') {
54
- clauses.push({operator: '!=', values: [null]});
55
- this.index++;
56
- } else if (token.type === 'NOTEMPTY') {
57
- clauses.push({operator: 'NOTEMPTY', values: [null]});
53
+ } else if (
54
+ token.type === 'NULL' ||
55
+ token.type === 'NOTNULL' ||
56
+ token.type === 'EMPTY' ||
57
+ token.type === 'NOTEMPTY'
58
+ ) {
59
+ clauses.push({operator: token.type});
58
60
  this.index++;
59
61
  } else if (this.checkSimpleWord(clauses)) {
60
62
  this.index++;
@@ -67,7 +69,15 @@ export class StringParser extends BaseParser {
67
69
  this.index++;
68
70
  }
69
71
  }
70
- return {clauses: StringParser.groupClauses(clauses), errors};
72
+ const response: StringParserResponse = {
73
+ clauses: StringParser.groupClauses(clauses),
74
+ errors,
75
+ };
76
+ const quotes: QuoteType[] = StringParser.findQuotes(this.inputString);
77
+ if (quotes.length > 0) {
78
+ response.quotes = quotes;
79
+ }
80
+ return response;
71
81
  }
72
82
 
73
83
  private static findQuotes(str: string): QuoteType[] {
@@ -119,18 +129,23 @@ export class StringParser extends BaseParser {
119
129
  return Array.from(quotes);
120
130
  }
121
131
 
122
- private static groupClauses(clauses: StringCondition[]): StringCondition[] {
132
+ private static groupClauses(clauses: StringClause[]): StringClause[] {
123
133
  if (clauses.length < 2) {
124
134
  return clauses;
125
135
  }
126
- let previous: StringCondition = clauses[0];
127
- const outputs: StringCondition[] = [previous];
136
+ let previous: StringClause = clauses[0];
137
+ const outputs: StringClause[] = [previous];
128
138
  for (let i = 1; i < clauses.length; i++) {
129
- if (previous.operator === clauses[i].operator) {
130
- previous.values.push(...clauses[i].values);
139
+ const current = clauses[i];
140
+ if (
141
+ previous.operator === current.operator &&
142
+ 'values' in previous &&
143
+ 'values' in current
144
+ ) {
145
+ previous.values.push(...current.values);
131
146
  } else {
132
- previous = clauses[i];
133
- outputs.push(previous);
147
+ previous = current;
148
+ outputs.push(current);
134
149
  }
135
150
  }
136
151
  return outputs;
@@ -147,7 +162,7 @@ export class StringParser extends BaseParser {
147
162
  return word.replace(StringParser.singleBackslashRegex, _match => '');
148
163
  }
149
164
 
150
- private checkSimpleWord(clauses: StringCondition[]): boolean {
165
+ private checkSimpleWord(clauses: StringClause[]): boolean {
151
166
  const token = this.getNext();
152
167
  if (token.type !== 'word') {
153
168
  return false;
@@ -161,7 +176,7 @@ export class StringParser extends BaseParser {
161
176
  const isUnderscore = StringParser.underscoreRegex.test(word);
162
177
  const isPercentMiddle = StringParser.percentInMiddle(word);
163
178
 
164
- let operator: StringOperator = negatedMatch ? '!=' : '=';
179
+ let operator: StringConditionOperator = negatedMatch ? '!=' : '=';
165
180
  if (isUnderscore || isPercentMiddle || (isPercentBoth && word.length < 3)) {
166
181
  operator = negatedMatch ? '!~' : '~';
167
182
  } else if (isPercentBoth && word.length > 2) {
@@ -185,8 +200,6 @@ export class StringParser extends BaseParser {
185
200
  }
186
201
 
187
202
  const clause: StringCondition = {operator: operator, values: [word]};
188
- //const quotes: QuoteType[] = StringParser.findQuotes(word);
189
- //if (quotes.length > 0) { clause.quotes = quotes; }
190
203
  clauses.push(clause);
191
204
  return true;
192
205
  }
@@ -1,9 +1,12 @@
1
- import {StringCondition, StringOperator, Clause} from './clause_types';
2
- import {BaseSerializer} from './base_serializer';
1
+ import {
2
+ StringClause,
3
+ StringCondition,
4
+ StringConditionOperator,
5
+ } from './clause_types';
3
6
 
4
- export class StringSerializer extends BaseSerializer {
5
- constructor(clauses: Clause[]) {
6
- super(clauses);
7
+ export class StringSerializer {
8
+ constructor(private clauses: StringClause[]) {
9
+ this.clauses = clauses;
7
10
  }
8
11
 
9
12
  public serialize(): string {
@@ -11,9 +14,8 @@ export class StringSerializer extends BaseSerializer {
11
14
  return result.trim().replace(/,$/, '');
12
15
  }
13
16
 
14
- private static isNegated(operator: StringOperator): boolean {
17
+ private static isNegated(operator: StringConditionOperator): boolean {
15
18
  return (
16
- operator === 'NOTEMPTY' ||
17
19
  operator === '!~' ||
18
20
  operator === '!=' ||
19
21
  operator === 'notStarts' ||
@@ -30,22 +32,14 @@ export class StringSerializer extends BaseSerializer {
30
32
  return input.replace(/[_%]/g, match => `\\${match}`);
31
33
  }
32
34
 
33
- // export type StringOperator = 'EMPTY' | 'NOTEMPTY' | 'starts' | 'ends' | 'contains' | 'notStarts' |
34
- // 'notEnds' | 'notContains' | '~' | '=' | '!~' | '!=';
35
- private static stringConditionToString(
36
- operator: StringOperator,
37
- value: string | null
35
+ // export type StringOperator =
36
+ // | 'starts' | 'ends' | 'contains' | 'notStarts' | 'notEnds' | 'notContains'
37
+ // | '~' | '=' | '!~' | '!=';
38
+ private static StringConditionWordToString(
39
+ operator: StringConditionOperator,
40
+ value: string
38
41
  ): string {
39
- if (operator === 'EMPTY') {
40
- return 'EMPTY';
41
- } else if (operator === 'NOTEMPTY') {
42
- return '-EMPTY';
43
- }
44
-
45
42
  const negated: boolean = StringSerializer.isNegated(operator);
46
- if (value === null) {
47
- return negated ? '-NULL' : 'NULL';
48
- }
49
43
  if (value === 'NULL' || value === '-NULL') {
50
44
  return (negated ? '-' : '') + '\\' + value;
51
45
  }
@@ -68,18 +62,50 @@ export class StringSerializer extends BaseSerializer {
68
62
  return (negated ? '-' : '') + value;
69
63
  }
70
64
 
71
- private static clauseToString(clauses: Clause[]): string {
65
+ private static StringClauseToString(
66
+ operator:
67
+ | StringConditionOperator
68
+ | 'EMPTY'
69
+ | 'NOTEMPTY'
70
+ | 'NULL'
71
+ | 'NOTNULL',
72
+ clause: StringClause
73
+ ): string {
74
+ if (operator === 'EMPTY') {
75
+ return 'EMPTY';
76
+ } else if (operator === 'NOTEMPTY') {
77
+ return '-EMPTY';
78
+ } else if (operator === 'NULL') {
79
+ return 'NULL';
80
+ } else if (operator === 'NOTNULL') {
81
+ return '-NULL';
82
+ }
83
+ if (!('values' in clause) || clause.values.length === 0) {
84
+ return '';
85
+ }
86
+ let result = '';
87
+ const condition: StringCondition = clause;
88
+ for (const value of condition.values) {
89
+ const word = StringSerializer.StringConditionWordToString(
90
+ condition.operator,
91
+ value
92
+ );
93
+ if (word) {
94
+ result += word + ', ';
95
+ }
96
+ }
97
+ return result;
98
+ }
99
+
100
+ private static clauseToString(clauses: StringClause[]): string {
72
101
  let result = '';
73
- for (const genericClause of clauses) {
74
- const clause: StringCondition = genericClause as StringCondition;
75
- for (const value of clause.values) {
76
- const word = StringSerializer.stringConditionToString(
77
- clause.operator,
78
- value
79
- );
80
- if (word) {
81
- result += word + ', ';
82
- }
102
+ for (const clause of clauses) {
103
+ const words = StringSerializer.StringClauseToString(
104
+ clause.operator,
105
+ clause
106
+ );
107
+ if (words) {
108
+ result += words + ', ';
83
109
  }
84
110
  }
85
111
  return result;
package/tsconfig.json CHANGED
@@ -5,10 +5,5 @@
5
5
  "outDir": "dist",
6
6
  "composite": true,
7
7
  "noImplicitReturns": true,
8
- },
9
- "references": [
10
- {
11
- "path": "../malloy"
12
- }
13
- ]
8
+ }
14
9
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const filter_serializer_1 = require("./filter_serializer");
4
- /* eslint-disable no-console */
5
- function aSimpleSerializer() {
6
- const strings = [{ operator: '=', values: ['CAT', 'DOG'] }];
7
- let response = new filter_serializer_1.FilterSerializer(strings, 'string').serialize();
8
- console.log(...strings, '\n', response.result, '\n');
9
- const numbers = [
10
- {
11
- operator: 'range',
12
- startOperator: '>=',
13
- startValue: -5.5,
14
- endOperator: '<',
15
- endValue: 10,
16
- },
17
- ];
18
- response = new filter_serializer_1.FilterSerializer(numbers, 'number').serialize();
19
- console.log(...numbers, '\n', response.result, '\n');
20
- const booleans = [{ operator: 'NULL' }, { operator: 'TRUE' }];
21
- response = new filter_serializer_1.FilterSerializer(booleans, 'boolean').serialize();
22
- console.log(...booleans, '\n', response.result, '\n');
23
- const dates = [
24
- { operator: 'YESTERDAY' },
25
- { operator: 'NEXT', unit: 'TUESDAY' },
26
- ];
27
- response = new filter_serializer_1.FilterSerializer(dates, 'date').serialize();
28
- console.log(...dates, '\n', response.result, '\n');
29
- }
30
- aSimpleSerializer();
31
- //# sourceMappingURL=a_simple_serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"a_simple_serializer.js","sourceRoot":"","sources":["../src/a_simple_serializer.ts"],"names":[],"mappings":";;AAAA,2DAAqD;AAQrD,+BAA+B;AAC/B,SAAS,iBAAiB;IACxB,MAAM,OAAO,GAAsB,CAAC,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAC,CAAC,CAAC;IAC7E,IAAI,QAAQ,GAAG,IAAI,oCAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAErD,MAAM,OAAO,GAAmB;QAC9B;YACE,QAAQ,EAAE,OAAO;YACjB,aAAa,EAAE,IAAI;YACnB,UAAU,EAAE,CAAC,GAAG;YAChB,WAAW,EAAE,GAAG;YAChB,QAAQ,EAAE,EAAE;SACb;KACF,CAAC;IACF,QAAQ,GAAG,IAAI,oCAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC;IAC/D,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAErD,MAAM,QAAQ,GAAoB,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;IAE3E,QAAQ,GAAG,IAAI,oCAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtD,MAAM,KAAK,GAAiB;QAC1B,EAAC,QAAQ,EAAE,WAAW,EAAC;QACvB,EAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAC;KACpC,CAAC;IACF,QAAQ,GAAG,IAAI,oCAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,iBAAiB,EAAE,CAAC"}
@@ -1,6 +0,0 @@
1
- import { Clause } from './clause_types';
2
- export declare abstract class BaseSerializer {
3
- protected clauses: Clause[];
4
- constructor(clauses: Clause[]);
5
- abstract serialize(): string;
6
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseSerializer = void 0;
4
- class BaseSerializer {
5
- constructor(clauses) {
6
- this.clauses = clauses;
7
- this.clauses = clauses;
8
- }
9
- }
10
- exports.BaseSerializer = BaseSerializer;
11
- //# sourceMappingURL=base_serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base_serializer.js","sourceRoot":"","sources":["../src/base_serializer.ts"],"names":[],"mappings":";;;AAEA,MAAsB,cAAc;IAClC,YAAsB,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CAGF;AAND,wCAMC"}
@@ -1,12 +0,0 @@
1
- import { FilterParserResponse } from './filter_types';
2
- import { Token } from './token_types';
3
- export type FilterType = 'boolean' | 'number' | 'string' | 'date';
4
- export declare class FilterParser {
5
- private input;
6
- private type;
7
- constructor(input: string, type: FilterType);
8
- private initParser;
9
- getTokens(): Token[];
10
- private makeErrorMessage;
11
- parse(): FilterParserResponse;
12
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FilterParser = void 0;
4
- const boolean_parser_1 = require("./boolean_parser");
5
- const string_parser_1 = require("./string_parser");
6
- const number_parser_1 = require("./number_parser");
7
- const date_parser_1 = require("./date_parser");
8
- class FilterParser {
9
- constructor(input, type) {
10
- this.input = input;
11
- this.type = type;
12
- this.input = input;
13
- this.type = type;
14
- }
15
- initParser() {
16
- switch (this.type) {
17
- case 'boolean':
18
- return new boolean_parser_1.BooleanParser(this.input);
19
- case 'number':
20
- return new number_parser_1.NumberParser(this.input);
21
- case 'string':
22
- return new string_parser_1.StringParser(this.input);
23
- case 'date':
24
- return new date_parser_1.DateParser(this.input);
25
- }
26
- }
27
- /* eslint-disable no-console */
28
- getTokens() {
29
- let tokens = [];
30
- try {
31
- const parser = this.initParser();
32
- tokens = parser.getTokens();
33
- }
34
- catch (ex) {
35
- if (ex instanceof Error)
36
- console.error('Error: ', ex.message, '\n');
37
- else {
38
- console.error('Unknown error: ', ex, '\n');
39
- }
40
- }
41
- return tokens;
42
- }
43
- /* eslint-enable no-console */
44
- makeErrorMessage(message) {
45
- return { message, startIndex: 0, endIndex: this.input.length };
46
- }
47
- parse() {
48
- try {
49
- const parser = this.initParser();
50
- return parser.parse();
51
- }
52
- catch (ex) {
53
- if (ex instanceof Error) {
54
- return { clauses: [], errors: [this.makeErrorMessage(ex.message)] };
55
- }
56
- else {
57
- return {
58
- clauses: [],
59
- errors: [this.makeErrorMessage('Unknown error ' + ex)],
60
- };
61
- }
62
- }
63
- }
64
- }
65
- exports.FilterParser = FilterParser;
66
- //# sourceMappingURL=filter_parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter_parser.js","sourceRoot":"","sources":["../src/filter_parser.ts"],"names":[],"mappings":";;;AAEA,qDAA+C;AAC/C,mDAA6C;AAC7C,mDAA6C;AAC7C,+CAAyC;AAKzC,MAAa,YAAY;IACvB,YACU,KAAa,EACb,IAAgB;QADhB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAY;QAExB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEO,UAAU;QAChB,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,SAAS;gBACZ,OAAO,IAAI,8BAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvC,KAAK,QAAQ;gBACX,OAAO,IAAI,4BAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,KAAK,QAAQ;gBACX,OAAO,IAAI,4BAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,KAAK,MAAM;gBACT,OAAO,IAAI,wBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrC;IACH,CAAC;IAED,+BAA+B;IACxB,SAAS;QACd,IAAI,MAAM,GAAY,EAAE,CAAC;QACzB,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACjC,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;SAC7B;QAAC,OAAO,EAAmB,EAAE;YAC5B,IAAI,EAAE,YAAY,KAAK;gBAAE,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;iBAC/D;gBACH,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;aAC5C;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,8BAA8B;IAEtB,gBAAgB,CAAC,OAAe;QACtC,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAC,CAAC;IAC/D,CAAC;IAEM,KAAK;QACV,IAAI;YACF,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;SACvB;QAAC,OAAO,EAAmB,EAAE;YAC5B,IAAI,EAAE,YAAY,KAAK,EAAE;gBACvB,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,CAAC;aACnE;iBAAM;gBACL,OAAO;oBACL,OAAO,EAAE,EAAE;oBACX,MAAM,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;iBACvD,CAAC;aACH;SACF;IACH,CAAC;CACF;AAzDD,oCAyDC"}
@@ -1,13 +0,0 @@
1
- import { Clause } from './clause_types';
2
- export type FilterType = 'boolean' | 'number' | 'string' | 'date';
3
- export interface FilterSerializerResponse {
4
- result: string;
5
- error?: string;
6
- }
7
- export declare class FilterSerializer {
8
- private input;
9
- private type;
10
- constructor(input: Clause[], type: FilterType);
11
- private initSerializer;
12
- serialize(): FilterSerializerResponse;
13
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FilterSerializer = void 0;
4
- const boolean_serializer_1 = require("./boolean_serializer");
5
- const string_serializer_1 = require("./string_serializer");
6
- const number_serializer_1 = require("./number_serializer");
7
- const date_serializer_1 = require("./date_serializer");
8
- class FilterSerializer {
9
- constructor(input, type) {
10
- this.input = input;
11
- this.type = type;
12
- this.input = input;
13
- this.type = type;
14
- }
15
- initSerializer() {
16
- switch (this.type) {
17
- case 'boolean':
18
- return new boolean_serializer_1.BooleanSerializer(this.input);
19
- case 'number':
20
- return new number_serializer_1.NumberSerializer(this.input);
21
- case 'string':
22
- return new string_serializer_1.StringSerializer(this.input);
23
- case 'date':
24
- return new date_serializer_1.DateSerializer(this.input);
25
- }
26
- }
27
- serialize() {
28
- try {
29
- const serializer = this.initSerializer();
30
- return { result: serializer.serialize() };
31
- }
32
- catch (ex) {
33
- if (ex instanceof Error) {
34
- return { result: '', error: ex.message };
35
- }
36
- else {
37
- return { result: '', error: 'Unknown error ' + ex };
38
- }
39
- }
40
- }
41
- }
42
- exports.FilterSerializer = FilterSerializer;
43
- //# sourceMappingURL=filter_serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter_serializer.js","sourceRoot":"","sources":["../src/filter_serializer.ts"],"names":[],"mappings":";;;AACA,6DAAuD;AACvD,2DAAqD;AACrD,2DAAqD;AACrD,uDAAiD;AAUjD,MAAa,gBAAgB;IAC3B,YACU,KAAe,EACf,IAAgB;QADhB,UAAK,GAAL,KAAK,CAAU;QACf,SAAI,GAAJ,IAAI,CAAY;QAExB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEO,cAAc;QACpB,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,SAAS;gBACZ,OAAO,IAAI,sCAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3C,KAAK,QAAQ;gBACX,OAAO,IAAI,oCAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,KAAK,QAAQ;gBACX,OAAO,IAAI,oCAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,KAAK,MAAM;gBACT,OAAO,IAAI,gCAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACzC;IACH,CAAC;IAEM,SAAS;QACd,IAAI;YACF,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YACzC,OAAO,EAAC,MAAM,EAAE,UAAU,CAAC,SAAS,EAAE,EAAC,CAAC;SACzC;QAAC,OAAO,EAAmB,EAAE;YAC5B,IAAI,EAAE,YAAY,KAAK,EAAE;gBACvB,OAAO,EAAC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,EAAC,CAAC;aACxC;iBAAM;gBACL,OAAO,EAAC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG,EAAE,EAAC,CAAC;aACnD;SACF;IACH,CAAC;CACF;AAlCD,4CAkCC"}
@@ -1,10 +0,0 @@
1
- import { Clause } from './clause_types';
2
- export interface FilterError {
3
- message: string;
4
- startIndex: number;
5
- endIndex: number;
6
- }
7
- export interface FilterParserResponse {
8
- clauses: Clause[];
9
- errors: FilterError[];
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter_types.js","sourceRoot":"","sources":["../src/filter_types.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import {FilterSerializer} from './filter_serializer';
2
- import {
3
- NumberClause,
4
- StringCondition,
5
- BooleanClause,
6
- DateClause,
7
- } from './clause_types';
8
-
9
- /* eslint-disable no-console */
10
- function aSimpleSerializer() {
11
- const strings: StringCondition[] = [{operator: '=', values: ['CAT', 'DOG']}];
12
- let response = new FilterSerializer(strings, 'string').serialize();
13
- console.log(...strings, '\n', response.result, '\n');
14
-
15
- const numbers: NumberClause[] = [
16
- {
17
- operator: 'range',
18
- startOperator: '>=',
19
- startValue: -5.5,
20
- endOperator: '<',
21
- endValue: 10,
22
- },
23
- ];
24
- response = new FilterSerializer(numbers, 'number').serialize();
25
- console.log(...numbers, '\n', response.result, '\n');
26
-
27
- const booleans: BooleanClause[] = [{operator: 'NULL'}, {operator: 'TRUE'}];
28
-
29
- response = new FilterSerializer(booleans, 'boolean').serialize();
30
- console.log(...booleans, '\n', response.result, '\n');
31
-
32
- const dates: DateClause[] = [
33
- {operator: 'YESTERDAY'},
34
- {operator: 'NEXT', unit: 'TUESDAY'},
35
- ];
36
- response = new FilterSerializer(dates, 'date').serialize();
37
- console.log(...dates, '\n', response.result, '\n');
38
- }
39
-
40
- aSimpleSerializer();
@@ -1,9 +0,0 @@
1
- import {Clause} from './clause_types';
2
-
3
- export abstract class BaseSerializer {
4
- constructor(protected clauses: Clause[]) {
5
- this.clauses = clauses;
6
- }
7
-
8
- public abstract serialize(): string;
9
- }
@@ -1,68 +0,0 @@
1
- import {FilterError, FilterParserResponse} from './filter_types';
2
- import {Token} from './token_types';
3
- import {BooleanParser} from './boolean_parser';
4
- import {StringParser} from './string_parser';
5
- import {NumberParser} from './number_parser';
6
- import {DateParser} from './date_parser';
7
- import {BaseParser} from './base_parser';
8
-
9
- export type FilterType = 'boolean' | 'number' | 'string' | 'date';
10
-
11
- export class FilterParser {
12
- constructor(
13
- private input: string,
14
- private type: FilterType
15
- ) {
16
- this.input = input;
17
- this.type = type;
18
- }
19
-
20
- private initParser(): BaseParser {
21
- switch (this.type) {
22
- case 'boolean':
23
- return new BooleanParser(this.input);
24
- case 'number':
25
- return new NumberParser(this.input);
26
- case 'string':
27
- return new StringParser(this.input);
28
- case 'date':
29
- return new DateParser(this.input);
30
- }
31
- }
32
-
33
- /* eslint-disable no-console */
34
- public getTokens(): Token[] {
35
- let tokens: Token[] = [];
36
- try {
37
- const parser = this.initParser();
38
- tokens = parser.getTokens();
39
- } catch (ex: Error | unknown) {
40
- if (ex instanceof Error) console.error('Error: ', ex.message, '\n');
41
- else {
42
- console.error('Unknown error: ', ex, '\n');
43
- }
44
- }
45
- return tokens;
46
- }
47
- /* eslint-enable no-console */
48
-
49
- private makeErrorMessage(message: string): FilterError {
50
- return {message, startIndex: 0, endIndex: this.input.length};
51
- }
52
-
53
- public parse(): FilterParserResponse {
54
- try {
55
- const parser = this.initParser();
56
- return parser.parse();
57
- } catch (ex: Error | unknown) {
58
- if (ex instanceof Error) {
59
- return {clauses: [], errors: [this.makeErrorMessage(ex.message)]};
60
- } else {
61
- return {
62
- clauses: [],
63
- errors: [this.makeErrorMessage('Unknown error ' + ex)],
64
- };
65
- }
66
- }
67
- }
68
- }
@@ -1,49 +0,0 @@
1
- import {Clause} from './clause_types';
2
- import {BooleanSerializer} from './boolean_serializer';
3
- import {StringSerializer} from './string_serializer';
4
- import {NumberSerializer} from './number_serializer';
5
- import {DateSerializer} from './date_serializer';
6
- import {BaseSerializer} from './base_serializer';
7
-
8
- export type FilterType = 'boolean' | 'number' | 'string' | 'date';
9
-
10
- export interface FilterSerializerResponse {
11
- result: string;
12
- error?: string;
13
- }
14
-
15
- export class FilterSerializer {
16
- constructor(
17
- private input: Clause[],
18
- private type: FilterType
19
- ) {
20
- this.input = input;
21
- this.type = type;
22
- }
23
-
24
- private initSerializer(): BaseSerializer {
25
- switch (this.type) {
26
- case 'boolean':
27
- return new BooleanSerializer(this.input);
28
- case 'number':
29
- return new NumberSerializer(this.input);
30
- case 'string':
31
- return new StringSerializer(this.input);
32
- case 'date':
33
- return new DateSerializer(this.input);
34
- }
35
- }
36
-
37
- public serialize(): FilterSerializerResponse {
38
- try {
39
- const serializer = this.initSerializer();
40
- return {result: serializer.serialize()};
41
- } catch (ex: Error | unknown) {
42
- if (ex instanceof Error) {
43
- return {result: '', error: ex.message};
44
- } else {
45
- return {result: '', error: 'Unknown error ' + ex};
46
- }
47
- }
48
- }
49
- }
@@ -1,12 +0,0 @@
1
- import {Clause} from './clause_types';
2
-
3
- export interface FilterError {
4
- message: string;
5
- startIndex: number;
6
- endIndex: number;
7
- }
8
-
9
- export interface FilterParserResponse {
10
- clauses: Clause[];
11
- errors: FilterError[];
12
- }