masterrecord 0.0.23 → 0.0.24

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.
@@ -1,173 +1,173 @@
1
-
2
-
3
- class Tokenization{
4
- constructor(){
5
- this.tokenList = [];
6
- this.fieldStrings = [];
7
- this.rules = [
8
- ["arrowHead", /^=>/],
9
- ["skip", /^skip/],
10
- ["take", /^take/],
11
- ["last", /^last/],
12
- ["orderByDescending", /^orderByDescending/],
13
- ["orderBy", /^orderBy/],
14
- ["groupBy", /^groupBy/],
15
- ["union", /^union/],
16
- ["find", /^find/],
17
- ["except", /^except/],
18
- ["any", /^any/],
19
- ["select", /^select/],
20
- ["distinct", /^distinct/],
21
- ["count", /^count/],
22
- ["average", /^average/],
23
- ["sum", /^sum/],
24
- ["max", /^max/],
25
- ["min", /^min/],
26
- ["join", /^join/],
27
- ["groupJoin", /^groupJoin/],
28
- ["toArray", /^toArray/],
29
- ["toDictionary", /^toDictionary/],
30
- ["toList", /^toList/],
31
- ["single", /^single/],
32
- ["where", /^where/],
33
- ["openBraces", /^\{/],
34
- ["closeBraces", /^\}/],
35
- ["openParenthesis", /^\(/],
36
- ["closeParenthesis", /^\)/],
37
- ["comma", /^,/],
38
- ["colon", /^:/],
39
- ["dot", /^\./],
40
- ["singleQuotes", /^\'/],
41
- ["doubleQuotes", /^\"/],
42
- ["greaterThen", /^>/],
43
- ["lessThen" , /^</],
44
- ["greaterThenEqualTo", /^>=/],
45
- ["lessThenEqualTo", /^<=/],
46
- ["doubleEquals" , /^==/],
47
- ["tripleEquals" , /^===/],
48
- ["notEqualsSingle", /^!=/],
49
- ["notEqualsDouble", /^!==/],
50
- ["not", /!/],
51
- ["in", /^contains/],
52
- ["like", /^like/],
53
- ["number", /^\d+/],
54
- ["or" , /^\|\|/],
55
- ["and", /^\&\&/], // will use between
56
- ["dateTimeValue", /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$"/], //Javascript ISO 8601
57
- // ["propertyName", /^.+:$/],
58
- //["stringLiteral", /([^\s"']+)|"([^"]*)/],
59
- ["conversionType", /^\?/]
60
- //["fields", ""], // just desfult to string array and when you another rule kicks off create the string
61
- ]
62
- }
63
-
64
- checkIfField(remainingText,expre){
65
- if(/^[a-zA-Z]+$/g.test(remainingText)){
66
- var next = expre.charAt(1);
67
- return !/^[a-zA-Z]+$/g.test(next);
68
- }
69
- }
70
-
71
- addRule(type, regex){
72
- this.rules.push([type, regex]);
73
- }
74
-
75
- findMatch(expression, secondText){
76
- for(var tokenRule in this.rules)
77
- {
78
- var match = this.match(expression, this.rules[tokenRule], secondText);
79
- if(match.isMatch !== false){
80
- return match;
81
- }
82
- }
83
-
84
- return {
85
- isMatch : false
86
- }
87
- }
88
-
89
- match(inputString, rule, secondText){
90
-
91
- // check if expression fits into one of the rules
92
- var match = inputString.match(rule[1]);
93
- if(match !== null){
94
- if(match[0].length === inputString.length){
95
- var val = true;
96
- switch(rule[0]){
97
- case "doubleEquals":
98
- if(secondText === "="){
99
- val = false;
100
- }
101
- // code block
102
- break;
103
- case "notEqualsSingle":
104
- if(secondText === "="){
105
- val = false;
106
- }
107
- // code block
108
- break;
109
- case "not":
110
- if(secondText === "="){
111
- val = false;
112
- }
113
- // code block
114
- break;
115
- }
116
- if(val === true){
117
- return {
118
- value : match,
119
- tokenType : rule[0],
120
- isMatch : true
121
- }
122
- }
123
- else{
124
- return {
125
- isMatch : false
126
- }
127
- }
128
- }
129
- else{
130
- return {
131
- isMatch : false
132
- }
133
- }
134
- }
135
- else{
136
- return {
137
- isMatch : false
138
- }
139
- }
140
-
141
- }
142
-
143
- Tokenize(expression){
144
- expression = expression.replace(/\s/g, '');
145
- while(expression !== "")
146
- {
147
- var remainingText = expression.charAt(0);
148
- var secondText = expression.substring(1, 2);
149
- var joinedFields = this.fieldStrings.join("") + remainingText;
150
- var match = this.findMatch(joinedFields, secondText);
151
- if (match.isMatch === true)
152
- {
153
- this.tokenList.push([match.tokenType, match.value[0]]);
154
- this.fieldStrings = [];
155
- }
156
- else{
157
-
158
- if(this.checkIfField(joinedFields, expression)){
159
- this.tokenList.push(["field", joinedFields]);
160
- this.fieldStrings = [];
161
- }
162
- else{
163
- this.fieldStrings.push(remainingText);
164
- }
165
- }
166
- expression = expression.substring(1);
167
- }
168
- return this.tokenList;
169
- }
170
-
171
- }
172
-
1
+
2
+
3
+ class Tokenization{
4
+ constructor(){
5
+ this.tokenList = [];
6
+ this.fieldStrings = [];
7
+ this.rules = [
8
+ ["arrowHead", /^=>/],
9
+ ["skip", /^skip/],
10
+ ["take", /^take/],
11
+ ["last", /^last/],
12
+ ["orderByDescending", /^orderByDescending/],
13
+ ["orderBy", /^orderBy/],
14
+ ["groupBy", /^groupBy/],
15
+ ["union", /^union/],
16
+ ["find", /^find/],
17
+ ["except", /^except/],
18
+ ["any", /^any/],
19
+ ["select", /^select/],
20
+ ["distinct", /^distinct/],
21
+ ["count", /^count/],
22
+ ["average", /^average/],
23
+ ["sum", /^sum/],
24
+ ["max", /^max/],
25
+ ["min", /^min/],
26
+ ["join", /^join/],
27
+ ["groupJoin", /^groupJoin/],
28
+ ["toArray", /^toArray/],
29
+ ["toDictionary", /^toDictionary/],
30
+ ["toList", /^toList/],
31
+ ["single", /^single/],
32
+ ["where", /^where/],
33
+ ["openBraces", /^\{/],
34
+ ["closeBraces", /^\}/],
35
+ ["openParenthesis", /^\(/],
36
+ ["closeParenthesis", /^\)/],
37
+ ["comma", /^,/],
38
+ ["colon", /^:/],
39
+ ["dot", /^\./],
40
+ ["singleQuotes", /^\'/],
41
+ ["doubleQuotes", /^\"/],
42
+ ["greaterThen", /^>/],
43
+ ["lessThen" , /^</],
44
+ ["greaterThenEqualTo", /^>=/],
45
+ ["lessThenEqualTo", /^<=/],
46
+ ["doubleEquals" , /^==/],
47
+ ["tripleEquals" , /^===/],
48
+ ["notEqualsSingle", /^!=/],
49
+ ["notEqualsDouble", /^!==/],
50
+ ["not", /!/],
51
+ ["in", /^contains/],
52
+ ["like", /^like/],
53
+ ["number", /^\d+/],
54
+ ["or" , /^\|\|/],
55
+ ["and", /^\&\&/], // will use between
56
+ ["dateTimeValue", /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$"/], //Javascript ISO 8601
57
+ // ["propertyName", /^.+:$/],
58
+ //["stringLiteral", /([^\s"']+)|"([^"]*)/],
59
+ ["conversionType", /^\?/]
60
+ //["fields", ""], // just desfult to string array and when you another rule kicks off create the string
61
+ ]
62
+ }
63
+
64
+ checkIfField(remainingText,expre){
65
+ if(/^[a-zA-Z]+$/g.test(remainingText)){
66
+ var next = expre.charAt(1);
67
+ return !/^[a-zA-Z]+$/g.test(next);
68
+ }
69
+ }
70
+
71
+ addRule(type, regex){
72
+ this.rules.push([type, regex]);
73
+ }
74
+
75
+ findMatch(expression, secondText){
76
+ for(var tokenRule in this.rules)
77
+ {
78
+ var match = this.match(expression, this.rules[tokenRule], secondText);
79
+ if(match.isMatch !== false){
80
+ return match;
81
+ }
82
+ }
83
+
84
+ return {
85
+ isMatch : false
86
+ }
87
+ }
88
+
89
+ match(inputString, rule, secondText){
90
+
91
+ // check if expression fits into one of the rules
92
+ var match = inputString.match(rule[1]);
93
+ if(match !== null){
94
+ if(match[0].length === inputString.length){
95
+ var val = true;
96
+ switch(rule[0]){
97
+ case "doubleEquals":
98
+ if(secondText === "="){
99
+ val = false;
100
+ }
101
+ // code block
102
+ break;
103
+ case "notEqualsSingle":
104
+ if(secondText === "="){
105
+ val = false;
106
+ }
107
+ // code block
108
+ break;
109
+ case "not":
110
+ if(secondText === "="){
111
+ val = false;
112
+ }
113
+ // code block
114
+ break;
115
+ }
116
+ if(val === true){
117
+ return {
118
+ value : match,
119
+ tokenType : rule[0],
120
+ isMatch : true
121
+ }
122
+ }
123
+ else{
124
+ return {
125
+ isMatch : false
126
+ }
127
+ }
128
+ }
129
+ else{
130
+ return {
131
+ isMatch : false
132
+ }
133
+ }
134
+ }
135
+ else{
136
+ return {
137
+ isMatch : false
138
+ }
139
+ }
140
+
141
+ }
142
+
143
+ Tokenize(expression){
144
+ expression = expression.replace(/\s/g, '');
145
+ while(expression !== "")
146
+ {
147
+ var remainingText = expression.charAt(0);
148
+ var secondText = expression.substring(1, 2);
149
+ var joinedFields = this.fieldStrings.join("") + remainingText;
150
+ var match = this.findMatch(joinedFields, secondText);
151
+ if (match.isMatch === true)
152
+ {
153
+ this.tokenList.push([match.tokenType, match.value[0]]);
154
+ this.fieldStrings = [];
155
+ }
156
+ else{
157
+
158
+ if(this.checkIfField(joinedFields, expression)){
159
+ this.tokenList.push(["field", joinedFields]);
160
+ this.fieldStrings = [];
161
+ }
162
+ else{
163
+ this.fieldStrings.push(remainingText);
164
+ }
165
+ }
166
+ expression = expression.substring(1);
167
+ }
168
+ return this.tokenList;
169
+ }
170
+
171
+ }
172
+
173
173
  module.exports = Tokenization;