@jetstreamapp/soql-parser-js 7.1.1 → 7.2.0
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/CHANGELOG.md +19 -0
- package/README.md +51 -27
- package/dist/cjs/index.js +5 -0
- package/dist/cli/index.js +5 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/lwc/soqlParserJs.js +28 -0
- package/package.json +13 -7
- package/dist/lwc/index.js +0 -2975
package/dist/lwc/index.js
DELETED
|
@@ -1,2975 +0,0 @@
|
|
|
1
|
-
// src/parser/lexer.ts
|
|
2
|
-
var TokenKind = /* @__PURE__ */ ((TokenKind2) => {
|
|
3
|
-
TokenKind2[TokenKind2["AND"] = 0] = "AND";
|
|
4
|
-
TokenKind2[TokenKind2["AS"] = 1] = "AS";
|
|
5
|
-
TokenKind2[TokenKind2["ASC"] = 2] = "ASC";
|
|
6
|
-
TokenKind2[TokenKind2["DESC"] = 3] = "DESC";
|
|
7
|
-
TokenKind2[TokenKind2["CUBE"] = 4] = "CUBE";
|
|
8
|
-
TokenKind2[TokenKind2["ELSE"] = 5] = "ELSE";
|
|
9
|
-
TokenKind2[TokenKind2["EXCLUDES"] = 6] = "EXCLUDES";
|
|
10
|
-
TokenKind2[TokenKind2["FALSE"] = 7] = "FALSE";
|
|
11
|
-
TokenKind2[TokenKind2["FIRST"] = 8] = "FIRST";
|
|
12
|
-
TokenKind2[TokenKind2["FROM"] = 9] = "FROM";
|
|
13
|
-
TokenKind2[TokenKind2["GROUP_BY"] = 10] = "GROUP_BY";
|
|
14
|
-
TokenKind2[TokenKind2["HAVING"] = 11] = "HAVING";
|
|
15
|
-
TokenKind2[TokenKind2["IN"] = 12] = "IN";
|
|
16
|
-
TokenKind2[TokenKind2["INCLUDES"] = 13] = "INCLUDES";
|
|
17
|
-
TokenKind2[TokenKind2["LAST"] = 14] = "LAST";
|
|
18
|
-
TokenKind2[TokenKind2["LIKE"] = 15] = "LIKE";
|
|
19
|
-
TokenKind2[TokenKind2["LIMIT"] = 16] = "LIMIT";
|
|
20
|
-
TokenKind2[TokenKind2["NOT"] = 17] = "NOT";
|
|
21
|
-
TokenKind2[TokenKind2["NULL"] = 18] = "NULL";
|
|
22
|
-
TokenKind2[TokenKind2["NULLS"] = 19] = "NULLS";
|
|
23
|
-
TokenKind2[TokenKind2["OR"] = 20] = "OR";
|
|
24
|
-
TokenKind2[TokenKind2["ORDER_BY"] = 21] = "ORDER_BY";
|
|
25
|
-
TokenKind2[TokenKind2["ROLLUP"] = 22] = "ROLLUP";
|
|
26
|
-
TokenKind2[TokenKind2["SELECT"] = 23] = "SELECT";
|
|
27
|
-
TokenKind2[TokenKind2["TRUE"] = 24] = "TRUE";
|
|
28
|
-
TokenKind2[TokenKind2["USING"] = 25] = "USING";
|
|
29
|
-
TokenKind2[TokenKind2["WHERE"] = 26] = "WHERE";
|
|
30
|
-
TokenKind2[TokenKind2["WITH"] = 27] = "WITH";
|
|
31
|
-
TokenKind2[TokenKind2["FOR"] = 28] = "FOR";
|
|
32
|
-
TokenKind2[TokenKind2["UPDATE"] = 29] = "UPDATE";
|
|
33
|
-
TokenKind2[TokenKind2["ABOVE"] = 30] = "ABOVE";
|
|
34
|
-
TokenKind2[TokenKind2["ABOVE_OR_BELOW"] = 31] = "ABOVE_OR_BELOW";
|
|
35
|
-
TokenKind2[TokenKind2["APEX_NEW"] = 32] = "APEX_NEW";
|
|
36
|
-
TokenKind2[TokenKind2["AT"] = 33] = "AT";
|
|
37
|
-
TokenKind2[TokenKind2["BELOW"] = 34] = "BELOW";
|
|
38
|
-
TokenKind2[TokenKind2["DATA_CATEGORY"] = 35] = "DATA_CATEGORY";
|
|
39
|
-
TokenKind2[TokenKind2["END"] = 36] = "END";
|
|
40
|
-
TokenKind2[TokenKind2["OFFSET"] = 37] = "OFFSET";
|
|
41
|
-
TokenKind2[TokenKind2["REFERENCE"] = 38] = "REFERENCE";
|
|
42
|
-
TokenKind2[TokenKind2["SCOPE"] = 39] = "SCOPE";
|
|
43
|
-
TokenKind2[TokenKind2["TRACKING"] = 40] = "TRACKING";
|
|
44
|
-
TokenKind2[TokenKind2["THEN"] = 41] = "THEN";
|
|
45
|
-
TokenKind2[TokenKind2["TYPEOF"] = 42] = "TYPEOF";
|
|
46
|
-
TokenKind2[TokenKind2["VIEW"] = 43] = "VIEW";
|
|
47
|
-
TokenKind2[TokenKind2["VIEWSTAT"] = 44] = "VIEWSTAT";
|
|
48
|
-
TokenKind2[TokenKind2["WHEN"] = 45] = "WHEN";
|
|
49
|
-
TokenKind2[TokenKind2["SECURITY_ENFORCED"] = 46] = "SECURITY_ENFORCED";
|
|
50
|
-
TokenKind2[TokenKind2["SYSTEM_MODE"] = 47] = "SYSTEM_MODE";
|
|
51
|
-
TokenKind2[TokenKind2["USER_MODE"] = 48] = "USER_MODE";
|
|
52
|
-
TokenKind2[TokenKind2["CALENDAR_MONTH"] = 49] = "CALENDAR_MONTH";
|
|
53
|
-
TokenKind2[TokenKind2["CALENDAR_QUARTER"] = 50] = "CALENDAR_QUARTER";
|
|
54
|
-
TokenKind2[TokenKind2["CALENDAR_YEAR"] = 51] = "CALENDAR_YEAR";
|
|
55
|
-
TokenKind2[TokenKind2["DAY_IN_MONTH"] = 52] = "DAY_IN_MONTH";
|
|
56
|
-
TokenKind2[TokenKind2["DAY_IN_WEEK"] = 53] = "DAY_IN_WEEK";
|
|
57
|
-
TokenKind2[TokenKind2["DAY_IN_YEAR"] = 54] = "DAY_IN_YEAR";
|
|
58
|
-
TokenKind2[TokenKind2["DAY_ONLY"] = 55] = "DAY_ONLY";
|
|
59
|
-
TokenKind2[TokenKind2["FISCAL_MONTH"] = 56] = "FISCAL_MONTH";
|
|
60
|
-
TokenKind2[TokenKind2["FISCAL_QUARTER"] = 57] = "FISCAL_QUARTER";
|
|
61
|
-
TokenKind2[TokenKind2["FISCAL_YEAR"] = 58] = "FISCAL_YEAR";
|
|
62
|
-
TokenKind2[TokenKind2["HOUR_IN_DAY"] = 59] = "HOUR_IN_DAY";
|
|
63
|
-
TokenKind2[TokenKind2["WEEK_IN_MONTH"] = 60] = "WEEK_IN_MONTH";
|
|
64
|
-
TokenKind2[TokenKind2["WEEK_IN_YEAR"] = 61] = "WEEK_IN_YEAR";
|
|
65
|
-
TokenKind2[TokenKind2["AVG"] = 62] = "AVG";
|
|
66
|
-
TokenKind2[TokenKind2["COUNT"] = 63] = "COUNT";
|
|
67
|
-
TokenKind2[TokenKind2["COUNT_DISTINCT"] = 64] = "COUNT_DISTINCT";
|
|
68
|
-
TokenKind2[TokenKind2["MIN"] = 65] = "MIN";
|
|
69
|
-
TokenKind2[TokenKind2["MAX"] = 66] = "MAX";
|
|
70
|
-
TokenKind2[TokenKind2["SUM"] = 67] = "SUM";
|
|
71
|
-
TokenKind2[TokenKind2["DISTANCE"] = 68] = "DISTANCE";
|
|
72
|
-
TokenKind2[TokenKind2["GEOLOCATION"] = 69] = "GEOLOCATION";
|
|
73
|
-
TokenKind2[TokenKind2["FIELDS"] = 70] = "FIELDS";
|
|
74
|
-
TokenKind2[TokenKind2["FORMAT"] = 71] = "FORMAT";
|
|
75
|
-
TokenKind2[TokenKind2["TOLABEL"] = 72] = "TOLABEL";
|
|
76
|
-
TokenKind2[TokenKind2["CONVERT_TIMEZONE"] = 73] = "CONVERT_TIMEZONE";
|
|
77
|
-
TokenKind2[TokenKind2["CONVERT_CURRENCY"] = 74] = "CONVERT_CURRENCY";
|
|
78
|
-
TokenKind2[TokenKind2["GROUPING"] = 75] = "GROUPING";
|
|
79
|
-
TokenKind2[TokenKind2["ALL"] = 76] = "ALL";
|
|
80
|
-
TokenKind2[TokenKind2["CUSTOM"] = 77] = "CUSTOM";
|
|
81
|
-
TokenKind2[TokenKind2["STANDARD"] = 78] = "STANDARD";
|
|
82
|
-
TokenKind2[TokenKind2["YESTERDAY"] = 79] = "YESTERDAY";
|
|
83
|
-
TokenKind2[TokenKind2["TODAY"] = 80] = "TODAY";
|
|
84
|
-
TokenKind2[TokenKind2["TOMORROW"] = 81] = "TOMORROW";
|
|
85
|
-
TokenKind2[TokenKind2["LAST_WEEK"] = 82] = "LAST_WEEK";
|
|
86
|
-
TokenKind2[TokenKind2["THIS_WEEK"] = 83] = "THIS_WEEK";
|
|
87
|
-
TokenKind2[TokenKind2["NEXT_WEEK"] = 84] = "NEXT_WEEK";
|
|
88
|
-
TokenKind2[TokenKind2["LAST_MONTH"] = 85] = "LAST_MONTH";
|
|
89
|
-
TokenKind2[TokenKind2["THIS_MONTH"] = 86] = "THIS_MONTH";
|
|
90
|
-
TokenKind2[TokenKind2["NEXT_MONTH"] = 87] = "NEXT_MONTH";
|
|
91
|
-
TokenKind2[TokenKind2["LAST_90_DAYS"] = 88] = "LAST_90_DAYS";
|
|
92
|
-
TokenKind2[TokenKind2["NEXT_90_DAYS"] = 89] = "NEXT_90_DAYS";
|
|
93
|
-
TokenKind2[TokenKind2["THIS_QUARTER"] = 90] = "THIS_QUARTER";
|
|
94
|
-
TokenKind2[TokenKind2["LAST_QUARTER"] = 91] = "LAST_QUARTER";
|
|
95
|
-
TokenKind2[TokenKind2["NEXT_QUARTER"] = 92] = "NEXT_QUARTER";
|
|
96
|
-
TokenKind2[TokenKind2["THIS_YEAR"] = 93] = "THIS_YEAR";
|
|
97
|
-
TokenKind2[TokenKind2["LAST_YEAR"] = 94] = "LAST_YEAR";
|
|
98
|
-
TokenKind2[TokenKind2["NEXT_YEAR"] = 95] = "NEXT_YEAR";
|
|
99
|
-
TokenKind2[TokenKind2["THIS_FISCAL_QUARTER"] = 96] = "THIS_FISCAL_QUARTER";
|
|
100
|
-
TokenKind2[TokenKind2["LAST_FISCAL_QUARTER"] = 97] = "LAST_FISCAL_QUARTER";
|
|
101
|
-
TokenKind2[TokenKind2["NEXT_FISCAL_QUARTER"] = 98] = "NEXT_FISCAL_QUARTER";
|
|
102
|
-
TokenKind2[TokenKind2["THIS_FISCAL_YEAR"] = 99] = "THIS_FISCAL_YEAR";
|
|
103
|
-
TokenKind2[TokenKind2["LAST_FISCAL_YEAR"] = 100] = "LAST_FISCAL_YEAR";
|
|
104
|
-
TokenKind2[TokenKind2["NEXT_FISCAL_YEAR"] = 101] = "NEXT_FISCAL_YEAR";
|
|
105
|
-
TokenKind2[TokenKind2["NEXT_N_DAYS"] = 102] = "NEXT_N_DAYS";
|
|
106
|
-
TokenKind2[TokenKind2["LAST_N_DAYS"] = 103] = "LAST_N_DAYS";
|
|
107
|
-
TokenKind2[TokenKind2["N_DAYS_AGO"] = 104] = "N_DAYS_AGO";
|
|
108
|
-
TokenKind2[TokenKind2["NEXT_N_WEEKS"] = 105] = "NEXT_N_WEEKS";
|
|
109
|
-
TokenKind2[TokenKind2["LAST_N_WEEKS"] = 106] = "LAST_N_WEEKS";
|
|
110
|
-
TokenKind2[TokenKind2["N_WEEKS_AGO"] = 107] = "N_WEEKS_AGO";
|
|
111
|
-
TokenKind2[TokenKind2["NEXT_N_MONTHS"] = 108] = "NEXT_N_MONTHS";
|
|
112
|
-
TokenKind2[TokenKind2["LAST_N_MONTHS"] = 109] = "LAST_N_MONTHS";
|
|
113
|
-
TokenKind2[TokenKind2["N_MONTHS_AGO"] = 110] = "N_MONTHS_AGO";
|
|
114
|
-
TokenKind2[TokenKind2["NEXT_N_QUARTERS"] = 111] = "NEXT_N_QUARTERS";
|
|
115
|
-
TokenKind2[TokenKind2["LAST_N_QUARTERS"] = 112] = "LAST_N_QUARTERS";
|
|
116
|
-
TokenKind2[TokenKind2["N_QUARTERS_AGO"] = 113] = "N_QUARTERS_AGO";
|
|
117
|
-
TokenKind2[TokenKind2["NEXT_N_YEARS"] = 114] = "NEXT_N_YEARS";
|
|
118
|
-
TokenKind2[TokenKind2["LAST_N_YEARS"] = 115] = "LAST_N_YEARS";
|
|
119
|
-
TokenKind2[TokenKind2["N_YEARS_AGO"] = 116] = "N_YEARS_AGO";
|
|
120
|
-
TokenKind2[TokenKind2["NEXT_N_FISCAL_QUARTERS"] = 117] = "NEXT_N_FISCAL_QUARTERS";
|
|
121
|
-
TokenKind2[TokenKind2["LAST_N_FISCAL_QUARTERS"] = 118] = "LAST_N_FISCAL_QUARTERS";
|
|
122
|
-
TokenKind2[TokenKind2["N_FISCAL_QUARTERS_AGO"] = 119] = "N_FISCAL_QUARTERS_AGO";
|
|
123
|
-
TokenKind2[TokenKind2["NEXT_N_FISCAL_YEARS"] = 120] = "NEXT_N_FISCAL_YEARS";
|
|
124
|
-
TokenKind2[TokenKind2["LAST_N_FISCAL_YEARS"] = 121] = "LAST_N_FISCAL_YEARS";
|
|
125
|
-
TokenKind2[TokenKind2["N_FISCAL_YEARS_AGO"] = 122] = "N_FISCAL_YEARS_AGO";
|
|
126
|
-
TokenKind2[TokenKind2["DELEGATED"] = 123] = "DELEGATED";
|
|
127
|
-
TokenKind2[TokenKind2["EVERYTHING"] = 124] = "EVERYTHING";
|
|
128
|
-
TokenKind2[TokenKind2["MINE_AND_MY_GROUPS"] = 125] = "MINE_AND_MY_GROUPS";
|
|
129
|
-
TokenKind2[TokenKind2["MINE"] = 126] = "MINE";
|
|
130
|
-
TokenKind2[TokenKind2["MY_TERRITORY"] = 127] = "MY_TERRITORY";
|
|
131
|
-
TokenKind2[TokenKind2["MY_TEAM_TERRITORY"] = 128] = "MY_TEAM_TERRITORY";
|
|
132
|
-
TokenKind2[TokenKind2["TEAM"] = 129] = "TEAM";
|
|
133
|
-
TokenKind2[TokenKind2["ALL_PRIVATE"] = 130] = "ALL_PRIVATE";
|
|
134
|
-
TokenKind2[TokenKind2["MRU"] = 131] = "MRU";
|
|
135
|
-
TokenKind2[TokenKind2["EQUAL"] = 132] = "EQUAL";
|
|
136
|
-
TokenKind2[TokenKind2["NOT_EQUAL"] = 133] = "NOT_EQUAL";
|
|
137
|
-
TokenKind2[TokenKind2["LESS_THAN"] = 134] = "LESS_THAN";
|
|
138
|
-
TokenKind2[TokenKind2["LESS_THAN_OR_EQUAL"] = 135] = "LESS_THAN_OR_EQUAL";
|
|
139
|
-
TokenKind2[TokenKind2["GREATER_THAN"] = 136] = "GREATER_THAN";
|
|
140
|
-
TokenKind2[TokenKind2["GREATER_THAN_OR_EQUAL"] = 137] = "GREATER_THAN_OR_EQUAL";
|
|
141
|
-
TokenKind2[TokenKind2["L_PAREN"] = 138] = "L_PAREN";
|
|
142
|
-
TokenKind2[TokenKind2["R_PAREN"] = 139] = "R_PAREN";
|
|
143
|
-
TokenKind2[TokenKind2["L_SQUARE_BRACKET"] = 140] = "L_SQUARE_BRACKET";
|
|
144
|
-
TokenKind2[TokenKind2["R_SQUARE_BRACKET"] = 141] = "R_SQUARE_BRACKET";
|
|
145
|
-
TokenKind2[TokenKind2["DOT"] = 142] = "DOT";
|
|
146
|
-
TokenKind2[TokenKind2["COMMA"] = 143] = "COMMA";
|
|
147
|
-
TokenKind2[TokenKind2["COLON"] = 144] = "COLON";
|
|
148
|
-
TokenKind2[TokenKind2["SEMICOLON"] = 145] = "SEMICOLON";
|
|
149
|
-
TokenKind2[TokenKind2["ASTERISK"] = 146] = "ASTERISK";
|
|
150
|
-
TokenKind2[TokenKind2["PLUS"] = 147] = "PLUS";
|
|
151
|
-
TokenKind2[TokenKind2["MINUS"] = 148] = "MINUS";
|
|
152
|
-
TokenKind2[TokenKind2["DATETIME"] = 149] = "DATETIME";
|
|
153
|
-
TokenKind2[TokenKind2["DATE_TOKEN"] = 150] = "DATE_TOKEN";
|
|
154
|
-
TokenKind2[TokenKind2["CURRENCY_PREFIXED_DECIMAL"] = 151] = "CURRENCY_PREFIXED_DECIMAL";
|
|
155
|
-
TokenKind2[TokenKind2["CURRENCY_PREFIXED_INTEGER"] = 152] = "CURRENCY_PREFIXED_INTEGER";
|
|
156
|
-
TokenKind2[TokenKind2["SIGNED_DECIMAL"] = 153] = "SIGNED_DECIMAL";
|
|
157
|
-
TokenKind2[TokenKind2["UNSIGNED_DECIMAL"] = 154] = "UNSIGNED_DECIMAL";
|
|
158
|
-
TokenKind2[TokenKind2["SIGNED_INTEGER"] = 155] = "SIGNED_INTEGER";
|
|
159
|
-
TokenKind2[TokenKind2["UNSIGNED_INTEGER"] = 156] = "UNSIGNED_INTEGER";
|
|
160
|
-
TokenKind2[TokenKind2["STRING_LITERAL"] = 157] = "STRING_LITERAL";
|
|
161
|
-
TokenKind2[TokenKind2["GEOLOCATION_UNIT"] = 158] = "GEOLOCATION_UNIT";
|
|
162
|
-
TokenKind2[TokenKind2["IDENTIFIER"] = 159] = "IDENTIFIER";
|
|
163
|
-
TokenKind2[TokenKind2["EOF"] = 160] = "EOF";
|
|
164
|
-
return TokenKind2;
|
|
165
|
-
})(TokenKind || {});
|
|
166
|
-
function isDateFunction(kind) {
|
|
167
|
-
return kind >= 49 /* CALENDAR_MONTH */ && kind <= 61 /* WEEK_IN_YEAR */;
|
|
168
|
-
}
|
|
169
|
-
function isAggregateFunction(kind) {
|
|
170
|
-
return kind >= 62 /* AVG */ && kind <= 67 /* SUM */;
|
|
171
|
-
}
|
|
172
|
-
function isLocationFunction(kind) {
|
|
173
|
-
return kind >= 68 /* DISTANCE */ && kind <= 69 /* GEOLOCATION */;
|
|
174
|
-
}
|
|
175
|
-
function isFieldsFunction(kind) {
|
|
176
|
-
return kind === 70 /* FIELDS */;
|
|
177
|
-
}
|
|
178
|
-
function isOtherFunction(kind) {
|
|
179
|
-
return kind >= 71 /* FORMAT */ && kind <= 75 /* GROUPING */;
|
|
180
|
-
}
|
|
181
|
-
function isFieldsFunctionParam(kind) {
|
|
182
|
-
return kind >= 76 /* ALL */ && kind <= 78 /* STANDARD */;
|
|
183
|
-
}
|
|
184
|
-
function isDateLiteral(kind) {
|
|
185
|
-
return kind >= 79 /* YESTERDAY */ && kind <= 101 /* NEXT_FISCAL_YEAR */;
|
|
186
|
-
}
|
|
187
|
-
function isDateNLiteral(kind) {
|
|
188
|
-
return kind >= 102 /* NEXT_N_DAYS */ && kind <= 122 /* N_FISCAL_YEARS_AGO */;
|
|
189
|
-
}
|
|
190
|
-
function isUsingScopeEnumeration(kind) {
|
|
191
|
-
return kind >= 123 /* DELEGATED */ && kind <= 131 /* MRU */;
|
|
192
|
-
}
|
|
193
|
-
function isIdentifierLike(kind) {
|
|
194
|
-
if (kind === 159 /* IDENTIFIER */) return true;
|
|
195
|
-
if (kind >= 30 /* ABOVE */ && kind <= 48 /* USER_MODE */) return true;
|
|
196
|
-
if (kind >= 49 /* CALENDAR_MONTH */ && kind <= 61 /* WEEK_IN_YEAR */) return true;
|
|
197
|
-
if (kind >= 62 /* AVG */ && kind <= 67 /* SUM */) return true;
|
|
198
|
-
if (kind >= 68 /* DISTANCE */ && kind <= 69 /* GEOLOCATION */) return true;
|
|
199
|
-
if (kind === 70 /* FIELDS */) return true;
|
|
200
|
-
if (kind >= 71 /* FORMAT */ && kind <= 75 /* GROUPING */) return true;
|
|
201
|
-
if (kind >= 76 /* ALL */ && kind <= 78 /* STANDARD */) return true;
|
|
202
|
-
if (kind >= 79 /* YESTERDAY */ && kind <= 101 /* NEXT_FISCAL_YEAR */) return true;
|
|
203
|
-
if (kind >= 102 /* NEXT_N_DAYS */ && kind <= 122 /* N_FISCAL_YEARS_AGO */) return true;
|
|
204
|
-
if (kind >= 123 /* DELEGATED */ && kind <= 131 /* MRU */) return true;
|
|
205
|
-
if (kind === 158 /* GEOLOCATION_UNIT */) return true;
|
|
206
|
-
if (kind === 152 /* CURRENCY_PREFIXED_INTEGER */) return true;
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
function isNumberLiteral(kind) {
|
|
210
|
-
return kind === 153 /* SIGNED_DECIMAL */ || kind === 154 /* UNSIGNED_DECIMAL */ || kind === 155 /* SIGNED_INTEGER */ || kind === 156 /* UNSIGNED_INTEGER */;
|
|
211
|
-
}
|
|
212
|
-
function isRelationalOperator(kind) {
|
|
213
|
-
return kind >= 132 /* EQUAL */ && kind <= 137 /* GREATER_THAN_OR_EQUAL */;
|
|
214
|
-
}
|
|
215
|
-
var keywordMap = /* @__PURE__ */ new Map([
|
|
216
|
-
// Reserved keywords
|
|
217
|
-
["AND", 0 /* AND */],
|
|
218
|
-
["AS", 1 /* AS */],
|
|
219
|
-
["ASC", 2 /* ASC */],
|
|
220
|
-
["DESC", 3 /* DESC */],
|
|
221
|
-
["CUBE", 4 /* CUBE */],
|
|
222
|
-
["ELSE", 5 /* ELSE */],
|
|
223
|
-
["EXCLUDES", 6 /* EXCLUDES */],
|
|
224
|
-
["FALSE", 7 /* FALSE */],
|
|
225
|
-
["FIRST", 8 /* FIRST */],
|
|
226
|
-
["FROM", 9 /* FROM */],
|
|
227
|
-
["HAVING", 11 /* HAVING */],
|
|
228
|
-
["IN", 12 /* IN */],
|
|
229
|
-
["INCLUDES", 13 /* INCLUDES */],
|
|
230
|
-
["LAST", 14 /* LAST */],
|
|
231
|
-
["LIKE", 15 /* LIKE */],
|
|
232
|
-
["LIMIT", 16 /* LIMIT */],
|
|
233
|
-
["NOT", 17 /* NOT */],
|
|
234
|
-
["NULL", 18 /* NULL */],
|
|
235
|
-
["NULLS", 19 /* NULLS */],
|
|
236
|
-
["OR", 20 /* OR */],
|
|
237
|
-
["ROLLUP", 22 /* ROLLUP */],
|
|
238
|
-
["SELECT", 23 /* SELECT */],
|
|
239
|
-
["TRUE", 24 /* TRUE */],
|
|
240
|
-
["USING", 25 /* USING */],
|
|
241
|
-
["WHERE", 26 /* WHERE */],
|
|
242
|
-
["WITH", 27 /* WITH */],
|
|
243
|
-
["FOR", 28 /* FOR */],
|
|
244
|
-
["UPDATE", 29 /* UPDATE */],
|
|
245
|
-
// Non-reserved keywords
|
|
246
|
-
["ABOVE_OR_BELOW", 31 /* ABOVE_OR_BELOW */],
|
|
247
|
-
["ABOVE", 30 /* ABOVE */],
|
|
248
|
-
["NEW", 32 /* APEX_NEW */],
|
|
249
|
-
["AT", 33 /* AT */],
|
|
250
|
-
["BELOW", 34 /* BELOW */],
|
|
251
|
-
["END", 36 /* END */],
|
|
252
|
-
["OFFSET", 37 /* OFFSET */],
|
|
253
|
-
["REFERENCE", 38 /* REFERENCE */],
|
|
254
|
-
["SCOPE", 39 /* SCOPE */],
|
|
255
|
-
["TRACKING", 40 /* TRACKING */],
|
|
256
|
-
["THEN", 41 /* THEN */],
|
|
257
|
-
["TYPEOF", 42 /* TYPEOF */],
|
|
258
|
-
["VIEW", 43 /* VIEW */],
|
|
259
|
-
["VIEWSTAT", 44 /* VIEWSTAT */],
|
|
260
|
-
["WHEN", 45 /* WHEN */],
|
|
261
|
-
["SECURITY_ENFORCED", 46 /* SECURITY_ENFORCED */],
|
|
262
|
-
["SYSTEM_MODE", 47 /* SYSTEM_MODE */],
|
|
263
|
-
["USER_MODE", 48 /* USER_MODE */],
|
|
264
|
-
// Date functions
|
|
265
|
-
["CALENDAR_MONTH", 49 /* CALENDAR_MONTH */],
|
|
266
|
-
["CALENDAR_QUARTER", 50 /* CALENDAR_QUARTER */],
|
|
267
|
-
["CALENDAR_YEAR", 51 /* CALENDAR_YEAR */],
|
|
268
|
-
["DAY_IN_MONTH", 52 /* DAY_IN_MONTH */],
|
|
269
|
-
["DAY_IN_WEEK", 53 /* DAY_IN_WEEK */],
|
|
270
|
-
["DAY_IN_YEAR", 54 /* DAY_IN_YEAR */],
|
|
271
|
-
["DAY_ONLY", 55 /* DAY_ONLY */],
|
|
272
|
-
["FISCAL_MONTH", 56 /* FISCAL_MONTH */],
|
|
273
|
-
["FISCAL_QUARTER", 57 /* FISCAL_QUARTER */],
|
|
274
|
-
["FISCAL_YEAR", 58 /* FISCAL_YEAR */],
|
|
275
|
-
["HOUR_IN_DAY", 59 /* HOUR_IN_DAY */],
|
|
276
|
-
["WEEK_IN_MONTH", 60 /* WEEK_IN_MONTH */],
|
|
277
|
-
["WEEK_IN_YEAR", 61 /* WEEK_IN_YEAR */],
|
|
278
|
-
// Aggregate functions
|
|
279
|
-
["AVG", 62 /* AVG */],
|
|
280
|
-
["COUNT_DISTINCT", 64 /* COUNT_DISTINCT */],
|
|
281
|
-
["COUNT", 63 /* COUNT */],
|
|
282
|
-
["MIN", 65 /* MIN */],
|
|
283
|
-
["MAX", 66 /* MAX */],
|
|
284
|
-
["SUM", 67 /* SUM */],
|
|
285
|
-
// Location functions
|
|
286
|
-
["DISTANCE", 68 /* DISTANCE */],
|
|
287
|
-
["GEOLOCATION", 69 /* GEOLOCATION */],
|
|
288
|
-
// Fields function
|
|
289
|
-
["FIELDS", 70 /* FIELDS */],
|
|
290
|
-
// Other functions
|
|
291
|
-
["FORMAT", 71 /* FORMAT */],
|
|
292
|
-
["TOLABEL", 72 /* TOLABEL */],
|
|
293
|
-
["CONVERTTIMEZONE", 73 /* CONVERT_TIMEZONE */],
|
|
294
|
-
["CONVERTCURRENCY", 74 /* CONVERT_CURRENCY */],
|
|
295
|
-
["GROUPING", 75 /* GROUPING */],
|
|
296
|
-
// Fields function params
|
|
297
|
-
["ALL", 76 /* ALL */],
|
|
298
|
-
["CUSTOM", 77 /* CUSTOM */],
|
|
299
|
-
["STANDARD", 78 /* STANDARD */],
|
|
300
|
-
// Date literals
|
|
301
|
-
["YESTERDAY", 79 /* YESTERDAY */],
|
|
302
|
-
["TODAY", 80 /* TODAY */],
|
|
303
|
-
["TOMORROW", 81 /* TOMORROW */],
|
|
304
|
-
["LAST_WEEK", 82 /* LAST_WEEK */],
|
|
305
|
-
["THIS_WEEK", 83 /* THIS_WEEK */],
|
|
306
|
-
["NEXT_WEEK", 84 /* NEXT_WEEK */],
|
|
307
|
-
["LAST_MONTH", 85 /* LAST_MONTH */],
|
|
308
|
-
["THIS_MONTH", 86 /* THIS_MONTH */],
|
|
309
|
-
["NEXT_MONTH", 87 /* NEXT_MONTH */],
|
|
310
|
-
["LAST_90_DAYS", 88 /* LAST_90_DAYS */],
|
|
311
|
-
["NEXT_90_DAYS", 89 /* NEXT_90_DAYS */],
|
|
312
|
-
["THIS_QUARTER", 90 /* THIS_QUARTER */],
|
|
313
|
-
["LAST_QUARTER", 91 /* LAST_QUARTER */],
|
|
314
|
-
["NEXT_QUARTER", 92 /* NEXT_QUARTER */],
|
|
315
|
-
["THIS_YEAR", 93 /* THIS_YEAR */],
|
|
316
|
-
["LAST_YEAR", 94 /* LAST_YEAR */],
|
|
317
|
-
["NEXT_YEAR", 95 /* NEXT_YEAR */],
|
|
318
|
-
["THIS_FISCAL_QUARTER", 96 /* THIS_FISCAL_QUARTER */],
|
|
319
|
-
["LAST_FISCAL_QUARTER", 97 /* LAST_FISCAL_QUARTER */],
|
|
320
|
-
["NEXT_FISCAL_QUARTER", 98 /* NEXT_FISCAL_QUARTER */],
|
|
321
|
-
["THIS_FISCAL_YEAR", 99 /* THIS_FISCAL_YEAR */],
|
|
322
|
-
["LAST_FISCAL_YEAR", 100 /* LAST_FISCAL_YEAR */],
|
|
323
|
-
["NEXT_FISCAL_YEAR", 101 /* NEXT_FISCAL_YEAR */],
|
|
324
|
-
// Date N literals
|
|
325
|
-
["NEXT_N_DAYS", 102 /* NEXT_N_DAYS */],
|
|
326
|
-
["LAST_N_DAYS", 103 /* LAST_N_DAYS */],
|
|
327
|
-
["N_DAYS_AGO", 104 /* N_DAYS_AGO */],
|
|
328
|
-
["NEXT_N_WEEKS", 105 /* NEXT_N_WEEKS */],
|
|
329
|
-
["LAST_N_WEEKS", 106 /* LAST_N_WEEKS */],
|
|
330
|
-
["N_WEEKS_AGO", 107 /* N_WEEKS_AGO */],
|
|
331
|
-
["NEXT_N_MONTHS", 108 /* NEXT_N_MONTHS */],
|
|
332
|
-
["LAST_N_MONTHS", 109 /* LAST_N_MONTHS */],
|
|
333
|
-
["N_MONTHS_AGO", 110 /* N_MONTHS_AGO */],
|
|
334
|
-
["NEXT_N_QUARTERS", 111 /* NEXT_N_QUARTERS */],
|
|
335
|
-
["LAST_N_QUARTERS", 112 /* LAST_N_QUARTERS */],
|
|
336
|
-
["N_QUARTERS_AGO", 113 /* N_QUARTERS_AGO */],
|
|
337
|
-
["NEXT_N_YEARS", 114 /* NEXT_N_YEARS */],
|
|
338
|
-
["LAST_N_YEARS", 115 /* LAST_N_YEARS */],
|
|
339
|
-
["N_YEARS_AGO", 116 /* N_YEARS_AGO */],
|
|
340
|
-
["NEXT_N_FISCAL_QUARTERS", 117 /* NEXT_N_FISCAL_QUARTERS */],
|
|
341
|
-
["LAST_N_FISCAL_QUARTERS", 118 /* LAST_N_FISCAL_QUARTERS */],
|
|
342
|
-
["N_FISCAL_QUARTERS_AGO", 119 /* N_FISCAL_QUARTERS_AGO */],
|
|
343
|
-
["NEXT_N_FISCAL_YEARS", 120 /* NEXT_N_FISCAL_YEARS */],
|
|
344
|
-
["LAST_N_FISCAL_YEARS", 121 /* LAST_N_FISCAL_YEARS */],
|
|
345
|
-
["N_FISCAL_YEARS_AGO", 122 /* N_FISCAL_YEARS_AGO */],
|
|
346
|
-
// Using scope enumerations
|
|
347
|
-
["DELEGATED", 123 /* DELEGATED */],
|
|
348
|
-
["EVERYTHING", 124 /* EVERYTHING */],
|
|
349
|
-
["MINEANDMYGROUPS", 125 /* MINE_AND_MY_GROUPS */],
|
|
350
|
-
["MINE", 126 /* MINE */],
|
|
351
|
-
["MY_TERRITORY", 127 /* MY_TERRITORY */],
|
|
352
|
-
["MY_TEAM_TERRITORY", 128 /* MY_TEAM_TERRITORY */],
|
|
353
|
-
["TEAM", 129 /* TEAM */],
|
|
354
|
-
["ALLPRIVATE", 130 /* ALL_PRIVATE */],
|
|
355
|
-
["MRU", 131 /* MRU */]
|
|
356
|
-
]);
|
|
357
|
-
var _tokenTypeNames = [];
|
|
358
|
-
(function initTokenTypeNames() {
|
|
359
|
-
for (const key of Object.keys(TokenKind)) {
|
|
360
|
-
const val = TokenKind[key];
|
|
361
|
-
if (typeof val === "number") {
|
|
362
|
-
_tokenTypeNames[val] = key;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
_tokenTypeNames[72 /* TOLABEL */] = "toLabel";
|
|
366
|
-
_tokenTypeNames[73 /* CONVERT_TIMEZONE */] = "convertTimezone";
|
|
367
|
-
_tokenTypeNames[74 /* CONVERT_CURRENCY */] = "convertCurrency";
|
|
368
|
-
_tokenTypeNames[157 /* STRING_LITERAL */] = "StringIdentifier";
|
|
369
|
-
_tokenTypeNames[150 /* DATE_TOKEN */] = "DATE";
|
|
370
|
-
_tokenTypeNames[32 /* APEX_NEW */] = "new";
|
|
371
|
-
_tokenTypeNames[125 /* MINE_AND_MY_GROUPS */] = "MineAndMyGroups";
|
|
372
|
-
_tokenTypeNames[127 /* MY_TERRITORY */] = "MyTerritory";
|
|
373
|
-
_tokenTypeNames[128 /* MY_TEAM_TERRITORY */] = "MyTeamTerritory";
|
|
374
|
-
_tokenTypeNames[130 /* ALL_PRIVATE */] = "AllPrivate";
|
|
375
|
-
_tokenTypeNames[123 /* DELEGATED */] = "Delegated";
|
|
376
|
-
_tokenTypeNames[124 /* EVERYTHING */] = "Everything";
|
|
377
|
-
_tokenTypeNames[126 /* MINE */] = "Mine";
|
|
378
|
-
_tokenTypeNames[129 /* TEAM */] = "Team";
|
|
379
|
-
_tokenTypeNames[131 /* MRU */] = "Mru";
|
|
380
|
-
_tokenTypeNames[159 /* IDENTIFIER */] = "Identifier";
|
|
381
|
-
_tokenTypeNames[132 /* EQUAL */] = "EQUAL";
|
|
382
|
-
_tokenTypeNames[156 /* UNSIGNED_INTEGER */] = "UNSIGNED_INTEGER";
|
|
383
|
-
_tokenTypeNames[155 /* SIGNED_INTEGER */] = "SIGNED_INTEGER";
|
|
384
|
-
_tokenTypeNames[154 /* UNSIGNED_DECIMAL */] = "UNSIGNED_DECIMAL";
|
|
385
|
-
_tokenTypeNames[153 /* SIGNED_DECIMAL */] = "SIGNED_DECIMAL";
|
|
386
|
-
_tokenTypeNames[151 /* CURRENCY_PREFIXED_DECIMAL */] = "CURRENCY_PREFIXED_DECIMAL";
|
|
387
|
-
_tokenTypeNames[152 /* CURRENCY_PREFIXED_INTEGER */] = "CURRENCY_PREFIXED_INTEGER";
|
|
388
|
-
})();
|
|
389
|
-
function tokenTypeName(kind) {
|
|
390
|
-
return _tokenTypeNames[kind] || TokenKind[kind];
|
|
391
|
-
}
|
|
392
|
-
function isAlpha(ch) {
|
|
393
|
-
return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122;
|
|
394
|
-
}
|
|
395
|
-
function isDigit(ch) {
|
|
396
|
-
return ch >= 48 && ch <= 57;
|
|
397
|
-
}
|
|
398
|
-
function isAlphaNumOrUnderscore(ch) {
|
|
399
|
-
return isAlpha(ch) || isDigit(ch) || ch === 95;
|
|
400
|
-
}
|
|
401
|
-
function isWhitespace(ch) {
|
|
402
|
-
return ch === 32 || ch === 9 || ch === 10 || ch === 13 || ch === 12;
|
|
403
|
-
}
|
|
404
|
-
function tokenize(input) {
|
|
405
|
-
const tokens = [];
|
|
406
|
-
const len = input.length;
|
|
407
|
-
let pos = 0;
|
|
408
|
-
while (pos < len) {
|
|
409
|
-
const ch = input.charCodeAt(pos);
|
|
410
|
-
if (isWhitespace(ch)) {
|
|
411
|
-
pos++;
|
|
412
|
-
while (pos < len && isWhitespace(input.charCodeAt(pos))) {
|
|
413
|
-
pos++;
|
|
414
|
-
}
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
if (ch === 39) {
|
|
418
|
-
const start = pos;
|
|
419
|
-
pos++;
|
|
420
|
-
while (pos < len) {
|
|
421
|
-
const c = input.charCodeAt(pos);
|
|
422
|
-
if (c === 92) {
|
|
423
|
-
pos += 2;
|
|
424
|
-
continue;
|
|
425
|
-
}
|
|
426
|
-
if (c === 39) {
|
|
427
|
-
pos++;
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
pos++;
|
|
431
|
-
}
|
|
432
|
-
const text = input.substring(start, pos);
|
|
433
|
-
const inner = text.substring(1, text.length - 1);
|
|
434
|
-
const innerUpper = inner.toUpperCase();
|
|
435
|
-
if (innerUpper === "MI" || innerUpper === "KM") {
|
|
436
|
-
tokens.push({ kind: 158 /* GEOLOCATION_UNIT */, text, start });
|
|
437
|
-
} else {
|
|
438
|
-
tokens.push({ kind: 157 /* STRING_LITERAL */, text, start });
|
|
439
|
-
}
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
if (isDigit(ch)) {
|
|
443
|
-
if (pos + 9 < len && input.charCodeAt(pos + 4) === 45 && input.charCodeAt(pos + 7) === 45) {
|
|
444
|
-
let isDatePattern = true;
|
|
445
|
-
for (const off of [0, 1, 2, 3, 5, 6, 8, 9]) {
|
|
446
|
-
if (!isDigit(input.charCodeAt(pos + off))) {
|
|
447
|
-
isDatePattern = false;
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (isDatePattern) {
|
|
452
|
-
if (pos + 10 < len && (input.charCodeAt(pos + 10) === 84 || input.charCodeAt(pos + 10) === 116)) {
|
|
453
|
-
const start2 = pos;
|
|
454
|
-
pos += 11;
|
|
455
|
-
while (pos < len) {
|
|
456
|
-
const tc = input.charCodeAt(pos);
|
|
457
|
-
if (isDigit(tc) || tc === 58) {
|
|
458
|
-
pos++;
|
|
459
|
-
} else {
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (pos < len && input.charCodeAt(pos) === 46) {
|
|
464
|
-
pos++;
|
|
465
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
466
|
-
pos++;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
if (pos < len) {
|
|
470
|
-
const tzCh = input.charCodeAt(pos);
|
|
471
|
-
if (tzCh === 90 || tzCh === 122) {
|
|
472
|
-
pos++;
|
|
473
|
-
} else if (tzCh === 46) {
|
|
474
|
-
pos++;
|
|
475
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
476
|
-
pos++;
|
|
477
|
-
}
|
|
478
|
-
if (pos < len && (input.charCodeAt(pos) === 90 || input.charCodeAt(pos) === 122)) {
|
|
479
|
-
pos++;
|
|
480
|
-
}
|
|
481
|
-
} else if (tzCh === 43 || tzCh === 45) {
|
|
482
|
-
pos++;
|
|
483
|
-
while (pos < len) {
|
|
484
|
-
const dc = input.charCodeAt(pos);
|
|
485
|
-
if (isDigit(dc) || dc === 58) {
|
|
486
|
-
pos++;
|
|
487
|
-
} else {
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
tokens.push({ kind: 149 /* DATETIME */, text: input.substring(start2, pos), start: start2 });
|
|
494
|
-
continue;
|
|
495
|
-
} else {
|
|
496
|
-
const start2 = pos;
|
|
497
|
-
pos += 10;
|
|
498
|
-
tokens.push({ kind: 150 /* DATE_TOKEN */, text: input.substring(start2, pos), start: start2 });
|
|
499
|
-
continue;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
const start = pos;
|
|
504
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
505
|
-
pos++;
|
|
506
|
-
}
|
|
507
|
-
if (pos < len && input.charCodeAt(pos) === 46) {
|
|
508
|
-
if (pos + 1 < len && isDigit(input.charCodeAt(pos + 1))) {
|
|
509
|
-
pos++;
|
|
510
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
511
|
-
pos++;
|
|
512
|
-
}
|
|
513
|
-
tokens.push({ kind: 154 /* UNSIGNED_DECIMAL */, text: input.substring(start, pos), start });
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
tokens.push({ kind: 156 /* UNSIGNED_INTEGER */, text: input.substring(start, pos), start });
|
|
518
|
-
continue;
|
|
519
|
-
}
|
|
520
|
-
if (ch === 33) {
|
|
521
|
-
if (pos + 1 < len && input.charCodeAt(pos + 1) === 61) {
|
|
522
|
-
tokens.push({ kind: 133 /* NOT_EQUAL */, text: "!=", start: pos });
|
|
523
|
-
pos += 2;
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
throw new Error(`Unexpected character '!' at position ${pos}`);
|
|
527
|
-
}
|
|
528
|
-
if (ch === 60) {
|
|
529
|
-
if (pos + 1 < len) {
|
|
530
|
-
const next = input.charCodeAt(pos + 1);
|
|
531
|
-
if (next === 61) {
|
|
532
|
-
tokens.push({ kind: 135 /* LESS_THAN_OR_EQUAL */, text: "<=", start: pos });
|
|
533
|
-
pos += 2;
|
|
534
|
-
continue;
|
|
535
|
-
}
|
|
536
|
-
if (next === 62) {
|
|
537
|
-
tokens.push({ kind: 133 /* NOT_EQUAL */, text: "<>", start: pos });
|
|
538
|
-
pos += 2;
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
tokens.push({ kind: 134 /* LESS_THAN */, text: "<", start: pos });
|
|
543
|
-
pos++;
|
|
544
|
-
continue;
|
|
545
|
-
}
|
|
546
|
-
if (ch === 62) {
|
|
547
|
-
if (pos + 1 < len && input.charCodeAt(pos + 1) === 61) {
|
|
548
|
-
tokens.push({ kind: 137 /* GREATER_THAN_OR_EQUAL */, text: ">=", start: pos });
|
|
549
|
-
pos += 2;
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
tokens.push({ kind: 136 /* GREATER_THAN */, text: ">", start: pos });
|
|
553
|
-
pos++;
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
if (ch === 61) {
|
|
557
|
-
tokens.push({ kind: 132 /* EQUAL */, text: "=", start: pos });
|
|
558
|
-
pos++;
|
|
559
|
-
continue;
|
|
560
|
-
}
|
|
561
|
-
if (ch === 40) {
|
|
562
|
-
tokens.push({ kind: 138 /* L_PAREN */, text: "(", start: pos });
|
|
563
|
-
pos++;
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
if (ch === 41) {
|
|
567
|
-
tokens.push({ kind: 139 /* R_PAREN */, text: ")", start: pos });
|
|
568
|
-
pos++;
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
if (ch === 91) {
|
|
572
|
-
tokens.push({ kind: 140 /* L_SQUARE_BRACKET */, text: "[", start: pos });
|
|
573
|
-
pos++;
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
if (ch === 93) {
|
|
577
|
-
tokens.push({ kind: 141 /* R_SQUARE_BRACKET */, text: "]", start: pos });
|
|
578
|
-
pos++;
|
|
579
|
-
continue;
|
|
580
|
-
}
|
|
581
|
-
if (ch === 44) {
|
|
582
|
-
tokens.push({ kind: 143 /* COMMA */, text: ",", start: pos });
|
|
583
|
-
pos++;
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
if (ch === 58) {
|
|
587
|
-
tokens.push({ kind: 144 /* COLON */, text: ":", start: pos });
|
|
588
|
-
pos++;
|
|
589
|
-
continue;
|
|
590
|
-
}
|
|
591
|
-
if (ch === 59) {
|
|
592
|
-
tokens.push({ kind: 145 /* SEMICOLON */, text: ";", start: pos });
|
|
593
|
-
pos++;
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
if (ch === 42) {
|
|
597
|
-
tokens.push({ kind: 146 /* ASTERISK */, text: "*", start: pos });
|
|
598
|
-
pos++;
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
if (ch === 43 || ch === 45) {
|
|
602
|
-
if (pos + 1 < len) {
|
|
603
|
-
const nextCh = input.charCodeAt(pos + 1);
|
|
604
|
-
if (isDigit(nextCh)) {
|
|
605
|
-
const start = pos;
|
|
606
|
-
pos++;
|
|
607
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
608
|
-
pos++;
|
|
609
|
-
}
|
|
610
|
-
if (pos < len && input.charCodeAt(pos) === 46) {
|
|
611
|
-
if (pos + 1 < len && isDigit(input.charCodeAt(pos + 1))) {
|
|
612
|
-
pos++;
|
|
613
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
614
|
-
pos++;
|
|
615
|
-
}
|
|
616
|
-
tokens.push({ kind: 153 /* SIGNED_DECIMAL */, text: input.substring(start, pos), start });
|
|
617
|
-
continue;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
tokens.push({ kind: 155 /* SIGNED_INTEGER */, text: input.substring(start, pos), start });
|
|
621
|
-
continue;
|
|
622
|
-
}
|
|
623
|
-
if (nextCh === 46 && pos + 2 < len && isDigit(input.charCodeAt(pos + 2))) {
|
|
624
|
-
const start = pos;
|
|
625
|
-
pos += 2;
|
|
626
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
627
|
-
pos++;
|
|
628
|
-
}
|
|
629
|
-
tokens.push({ kind: 153 /* SIGNED_DECIMAL */, text: input.substring(start, pos), start });
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
tokens.push({ kind: ch === 43 ? 147 /* PLUS */ : 148 /* MINUS */, text: input[pos], start: pos });
|
|
634
|
-
pos++;
|
|
635
|
-
continue;
|
|
636
|
-
}
|
|
637
|
-
if (ch === 46) {
|
|
638
|
-
if (pos + 1 < len && isDigit(input.charCodeAt(pos + 1))) {
|
|
639
|
-
const start = pos;
|
|
640
|
-
pos++;
|
|
641
|
-
while (pos < len && isDigit(input.charCodeAt(pos))) {
|
|
642
|
-
pos++;
|
|
643
|
-
}
|
|
644
|
-
tokens.push({ kind: 154 /* UNSIGNED_DECIMAL */, text: input.substring(start, pos), start });
|
|
645
|
-
continue;
|
|
646
|
-
}
|
|
647
|
-
tokens.push({ kind: 142 /* DOT */, text: ".", start: pos });
|
|
648
|
-
pos++;
|
|
649
|
-
continue;
|
|
650
|
-
}
|
|
651
|
-
if (isAlpha(ch)) {
|
|
652
|
-
const start = pos;
|
|
653
|
-
pos++;
|
|
654
|
-
while (pos < len) {
|
|
655
|
-
const c = input.charCodeAt(pos);
|
|
656
|
-
if (isAlphaNumOrUnderscore(c) || c === 46) {
|
|
657
|
-
pos++;
|
|
658
|
-
} else {
|
|
659
|
-
break;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
let text = input.substring(start, pos);
|
|
663
|
-
if (text.includes("..")) {
|
|
664
|
-
throw new Error(`Invalid identifier with consecutive dots at position ${start}: "${text}"`);
|
|
665
|
-
}
|
|
666
|
-
const upper = text.toUpperCase();
|
|
667
|
-
if (upper === "ORDER" && !text.includes(".")) {
|
|
668
|
-
const byResult = peekMultiWordSuffix(input, pos, "BY");
|
|
669
|
-
if (byResult !== -1) {
|
|
670
|
-
const fullText = input.substring(start, byResult);
|
|
671
|
-
tokens.push({ kind: 21 /* ORDER_BY */, text: fullText, start });
|
|
672
|
-
pos = byResult;
|
|
673
|
-
continue;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if (upper === "GROUP" && !text.includes(".")) {
|
|
677
|
-
const byResult = peekMultiWordSuffix(input, pos, "BY");
|
|
678
|
-
if (byResult !== -1) {
|
|
679
|
-
const fullText = input.substring(start, byResult);
|
|
680
|
-
tokens.push({ kind: 10 /* GROUP_BY */, text: fullText, start });
|
|
681
|
-
pos = byResult;
|
|
682
|
-
continue;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (upper === "DATA" && !text.includes(".")) {
|
|
686
|
-
const catResult = peekMultiWordSuffix(input, pos, "CATEGORY");
|
|
687
|
-
if (catResult !== -1) {
|
|
688
|
-
const fullText = input.substring(start, catResult);
|
|
689
|
-
tokens.push({ kind: 35 /* DATA_CATEGORY */, text: fullText, start });
|
|
690
|
-
pos = catResult;
|
|
691
|
-
continue;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (text.length >= 4) {
|
|
695
|
-
const first3 = text.substring(0, 3);
|
|
696
|
-
if (isAllAlpha(first3)) {
|
|
697
|
-
const rest = text.substring(3);
|
|
698
|
-
if (isCurrencyNumberSuffix(rest)) {
|
|
699
|
-
if (rest.includes(".")) {
|
|
700
|
-
tokens.push({ kind: 151 /* CURRENCY_PREFIXED_DECIMAL */, text, start });
|
|
701
|
-
} else {
|
|
702
|
-
tokens.push({ kind: 152 /* CURRENCY_PREFIXED_INTEGER */, text, start });
|
|
703
|
-
}
|
|
704
|
-
continue;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
if (text.length === 3 && isAllAlpha(text)) {
|
|
709
|
-
const savedPos = pos;
|
|
710
|
-
let currPos = pos;
|
|
711
|
-
let hasMinus = false;
|
|
712
|
-
if (currPos < len && input.charCodeAt(currPos) === 45) {
|
|
713
|
-
hasMinus = true;
|
|
714
|
-
currPos++;
|
|
715
|
-
}
|
|
716
|
-
if (hasMinus && currPos < len && isDigit(input.charCodeAt(currPos))) {
|
|
717
|
-
while (currPos < len && isDigit(input.charCodeAt(currPos))) {
|
|
718
|
-
currPos++;
|
|
719
|
-
}
|
|
720
|
-
if (currPos < len && input.charCodeAt(currPos) === 46 && currPos + 1 < len && isDigit(input.charCodeAt(currPos + 1))) {
|
|
721
|
-
currPos++;
|
|
722
|
-
while (currPos < len && isDigit(input.charCodeAt(currPos))) {
|
|
723
|
-
currPos++;
|
|
724
|
-
}
|
|
725
|
-
const fullText = input.substring(start, currPos);
|
|
726
|
-
tokens.push({ kind: 151 /* CURRENCY_PREFIXED_DECIMAL */, text: fullText, start });
|
|
727
|
-
pos = currPos;
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
if (currPos >= len || !isAlphaNumOrUnderscore(input.charCodeAt(currPos)) && input.charCodeAt(currPos) !== 46) {
|
|
731
|
-
const fullText = input.substring(start, currPos);
|
|
732
|
-
tokens.push({ kind: 152 /* CURRENCY_PREFIXED_INTEGER */, text: fullText, start });
|
|
733
|
-
pos = currPos;
|
|
734
|
-
continue;
|
|
735
|
-
}
|
|
736
|
-
pos = savedPos;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
if (text.includes(".")) {
|
|
740
|
-
tokens.push({ kind: 159 /* IDENTIFIER */, text, start });
|
|
741
|
-
continue;
|
|
742
|
-
}
|
|
743
|
-
const kwKind = keywordMap.get(upper);
|
|
744
|
-
if (kwKind !== void 0) {
|
|
745
|
-
tokens.push({ kind: kwKind, text, start });
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
tokens.push({ kind: 159 /* IDENTIFIER */, text, start });
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
throw new Error(`Unexpected character '${input[pos]}' (code ${ch}) at position ${pos}`);
|
|
752
|
-
}
|
|
753
|
-
tokens.push({ kind: 160 /* EOF */, text: "", start: pos });
|
|
754
|
-
return tokens;
|
|
755
|
-
}
|
|
756
|
-
function peekMultiWordSuffix(input, pos, suffix) {
|
|
757
|
-
const len = input.length;
|
|
758
|
-
let p = pos;
|
|
759
|
-
if (p >= len || !isWhitespace(input.charCodeAt(p))) {
|
|
760
|
-
return -1;
|
|
761
|
-
}
|
|
762
|
-
while (p < len && isWhitespace(input.charCodeAt(p))) {
|
|
763
|
-
p++;
|
|
764
|
-
}
|
|
765
|
-
const suffixLen = suffix.length;
|
|
766
|
-
if (p + suffixLen > len) {
|
|
767
|
-
return -1;
|
|
768
|
-
}
|
|
769
|
-
for (let i = 0; i < suffixLen; i++) {
|
|
770
|
-
const c = input.charCodeAt(p + i);
|
|
771
|
-
const s = suffix.charCodeAt(i);
|
|
772
|
-
const upper = c >= 97 && c <= 122 ? c - 32 : c;
|
|
773
|
-
if (upper !== s) {
|
|
774
|
-
return -1;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
const afterSuffix = p + suffixLen;
|
|
778
|
-
if (afterSuffix < len) {
|
|
779
|
-
const nextCh = input.charCodeAt(afterSuffix);
|
|
780
|
-
if (isAlphaNumOrUnderscore(nextCh) || nextCh === 46) {
|
|
781
|
-
return -1;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
return afterSuffix;
|
|
785
|
-
}
|
|
786
|
-
function isAllAlpha(s) {
|
|
787
|
-
for (let i = 0; i < s.length; i++) {
|
|
788
|
-
if (!isAlpha(s.charCodeAt(i))) return false;
|
|
789
|
-
}
|
|
790
|
-
return true;
|
|
791
|
-
}
|
|
792
|
-
function isCurrencyNumberSuffix(s) {
|
|
793
|
-
if (s.length === 0) return false;
|
|
794
|
-
let i = 0;
|
|
795
|
-
if (s.charCodeAt(i) === 45) {
|
|
796
|
-
i++;
|
|
797
|
-
}
|
|
798
|
-
if (i >= s.length || !isDigit(s.charCodeAt(i))) return false;
|
|
799
|
-
while (i < s.length && isDigit(s.charCodeAt(i))) {
|
|
800
|
-
i++;
|
|
801
|
-
}
|
|
802
|
-
if (i < s.length) {
|
|
803
|
-
if (s.charCodeAt(i) === 46) {
|
|
804
|
-
i++;
|
|
805
|
-
if (i >= s.length || !isDigit(s.charCodeAt(i))) return false;
|
|
806
|
-
while (i < s.length && isDigit(s.charCodeAt(i))) {
|
|
807
|
-
i++;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return i === s.length;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// src/parser/parser.ts
|
|
815
|
-
var CLAUSE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
816
|
-
23 /* SELECT */,
|
|
817
|
-
9 /* FROM */,
|
|
818
|
-
26 /* WHERE */,
|
|
819
|
-
21 /* ORDER_BY */,
|
|
820
|
-
10 /* GROUP_BY */,
|
|
821
|
-
11 /* HAVING */,
|
|
822
|
-
16 /* LIMIT */,
|
|
823
|
-
27 /* WITH */,
|
|
824
|
-
28 /* FOR */,
|
|
825
|
-
29 /* UPDATE */,
|
|
826
|
-
25 /* USING */,
|
|
827
|
-
19 /* NULLS */,
|
|
828
|
-
2 /* ASC */,
|
|
829
|
-
3 /* DESC */,
|
|
830
|
-
0 /* AND */,
|
|
831
|
-
20 /* OR */,
|
|
832
|
-
17 /* NOT */,
|
|
833
|
-
45 /* WHEN */,
|
|
834
|
-
41 /* THEN */,
|
|
835
|
-
5 /* ELSE */,
|
|
836
|
-
36 /* END */,
|
|
837
|
-
42 /* TYPEOF */,
|
|
838
|
-
143 /* COMMA */,
|
|
839
|
-
139 /* R_PAREN */,
|
|
840
|
-
160 /* EOF */
|
|
841
|
-
]);
|
|
842
|
-
var SoqlParser = class _SoqlParser {
|
|
843
|
-
constructor(tokens, config) {
|
|
844
|
-
this.pos = 0;
|
|
845
|
-
this.tokens = tokens;
|
|
846
|
-
this.config = config;
|
|
847
|
-
}
|
|
848
|
-
getPos() {
|
|
849
|
-
return this.pos;
|
|
850
|
-
}
|
|
851
|
-
// ---- Navigation helpers ----
|
|
852
|
-
peek() {
|
|
853
|
-
return this.tokens[this.pos];
|
|
854
|
-
}
|
|
855
|
-
peekAt(offset) {
|
|
856
|
-
const idx = this.pos + offset;
|
|
857
|
-
if (idx >= this.tokens.length) {
|
|
858
|
-
return this.tokens[this.tokens.length - 1];
|
|
859
|
-
}
|
|
860
|
-
return this.tokens[idx];
|
|
861
|
-
}
|
|
862
|
-
advance() {
|
|
863
|
-
const t = this.tokens[this.pos];
|
|
864
|
-
if (t.kind !== 160 /* EOF */) {
|
|
865
|
-
this.pos++;
|
|
866
|
-
}
|
|
867
|
-
return t;
|
|
868
|
-
}
|
|
869
|
-
expect(kind) {
|
|
870
|
-
const t = this.peek();
|
|
871
|
-
if (t.kind !== kind) {
|
|
872
|
-
throw this.error(`Expected ${TokenKind[kind]} but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
873
|
-
}
|
|
874
|
-
return this.advance();
|
|
875
|
-
}
|
|
876
|
-
match(kind) {
|
|
877
|
-
if (this.peek().kind === kind) {
|
|
878
|
-
this.advance();
|
|
879
|
-
return true;
|
|
880
|
-
}
|
|
881
|
-
return false;
|
|
882
|
-
}
|
|
883
|
-
check(kind) {
|
|
884
|
-
return this.peek().kind === kind;
|
|
885
|
-
}
|
|
886
|
-
isAtEnd() {
|
|
887
|
-
return this.peek().kind === 160 /* EOF */;
|
|
888
|
-
}
|
|
889
|
-
error(message) {
|
|
890
|
-
if (this.config.logErrors) {
|
|
891
|
-
console.log(message);
|
|
892
|
-
}
|
|
893
|
-
return new Error(message);
|
|
894
|
-
}
|
|
895
|
-
static {
|
|
896
|
-
this.CLAUSE_BOUNDARY_KINDS = /* @__PURE__ */ new Set([
|
|
897
|
-
26 /* WHERE */,
|
|
898
|
-
21 /* ORDER_BY */,
|
|
899
|
-
10 /* GROUP_BY */,
|
|
900
|
-
11 /* HAVING */,
|
|
901
|
-
16 /* LIMIT */,
|
|
902
|
-
37 /* OFFSET */,
|
|
903
|
-
27 /* WITH */,
|
|
904
|
-
28 /* FOR */,
|
|
905
|
-
29 /* UPDATE */,
|
|
906
|
-
25 /* USING */,
|
|
907
|
-
160 /* EOF */
|
|
908
|
-
]);
|
|
909
|
-
}
|
|
910
|
-
isAtClauseBoundary() {
|
|
911
|
-
const k = this.peek().kind;
|
|
912
|
-
return _SoqlParser.CLAUSE_BOUNDARY_KINDS.has(k) || k === 139 /* R_PAREN */;
|
|
913
|
-
}
|
|
914
|
-
synchronize() {
|
|
915
|
-
while (!this.isAtEnd()) {
|
|
916
|
-
if (this.isAtClauseBoundary()) return;
|
|
917
|
-
this.advance();
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
// ---- Identifier consumption ----
|
|
921
|
-
// Consumes an identifier token. In SOQL many keywords can appear as identifiers.
|
|
922
|
-
// The lexer produces specific TokenKind for keywords; we accept anything that isIdentifierLike.
|
|
923
|
-
consumeIdentifier() {
|
|
924
|
-
const t = this.peek();
|
|
925
|
-
if (isIdentifierLike(t.kind)) {
|
|
926
|
-
return this.advance();
|
|
927
|
-
}
|
|
928
|
-
throw this.error(`Expected identifier but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
929
|
-
}
|
|
930
|
-
// Check if the current token can be treated as an identifier
|
|
931
|
-
checkIdentifier() {
|
|
932
|
-
return isIdentifierLike(this.peek().kind);
|
|
933
|
-
}
|
|
934
|
-
// ---- Check if next token is a function name followed by ( ----
|
|
935
|
-
isFunctionCall() {
|
|
936
|
-
const t = this.peek();
|
|
937
|
-
const next = this.peekAt(1);
|
|
938
|
-
return (isDateFunction(t.kind) || isAggregateFunction(t.kind) || isLocationFunction(t.kind) || isFieldsFunction(t.kind) || isOtherFunction(t.kind)) && next.kind === 138 /* L_PAREN */;
|
|
939
|
-
}
|
|
940
|
-
// ---- Check if current token could be an alias ----
|
|
941
|
-
// An alias is an identifier-like token that is NOT a clause keyword,
|
|
942
|
-
// and NOT OFFSET followed by an unsigned integer.
|
|
943
|
-
canBeAlias() {
|
|
944
|
-
const t = this.peek();
|
|
945
|
-
if (!isIdentifierLike(t.kind)) return false;
|
|
946
|
-
if (CLAUSE_KEYWORDS.has(t.kind)) return false;
|
|
947
|
-
if (t.kind === 37 /* OFFSET */ && this.peekAt(1).kind === 156 /* UNSIGNED_INTEGER */) return false;
|
|
948
|
-
return true;
|
|
949
|
-
}
|
|
950
|
-
// ---- Literal type detection ----
|
|
951
|
-
getLiteralType(kind) {
|
|
952
|
-
const name = tokenTypeName(kind);
|
|
953
|
-
if (name === "UNSIGNED_INTEGER" || name === "SIGNED_INTEGER") return "INTEGER";
|
|
954
|
-
if (name === "UNSIGNED_DECIMAL" || name === "SIGNED_DECIMAL") return "DECIMAL";
|
|
955
|
-
if (name === "CURRENCY_PREFIXED_DECIMAL") return "DECIMAL_WITH_CURRENCY_PREFIX";
|
|
956
|
-
if (name === "CURRENCY_PREFIXED_INTEGER") return "INTEGER_WITH_CURRENCY_PREFIX";
|
|
957
|
-
if (name === "DATETIME") return "DATETIME";
|
|
958
|
-
if (name === "DATE") return "DATE";
|
|
959
|
-
if (name === "NULL") return "NULL";
|
|
960
|
-
if (name === "StringIdentifier") return "STRING";
|
|
961
|
-
if (name === "Identifier") return "STRING";
|
|
962
|
-
if (name === "TRUE" || name === "FALSE") return "BOOLEAN";
|
|
963
|
-
if (isDateLiteral(kind)) return "DATE_LITERAL";
|
|
964
|
-
if (isDateNLiteral(kind)) return "DATE_N_LITERAL";
|
|
965
|
-
return "STRING";
|
|
966
|
-
}
|
|
967
|
-
// ====================================================================
|
|
968
|
-
// Entry Points
|
|
969
|
-
// ====================================================================
|
|
970
|
-
parseSelectStatement(isSubquery2 = false) {
|
|
971
|
-
const fields = this.parseSelectClause();
|
|
972
|
-
const fromResult = this.parseFromClause();
|
|
973
|
-
let query;
|
|
974
|
-
if (isSubquery2) {
|
|
975
|
-
query = {
|
|
976
|
-
fields,
|
|
977
|
-
relationshipName: fromResult.sObject
|
|
978
|
-
};
|
|
979
|
-
if (fromResult.sObjectPrefix) {
|
|
980
|
-
query.sObjectPrefix = fromResult.sObjectPrefix;
|
|
981
|
-
}
|
|
982
|
-
} else {
|
|
983
|
-
query = {
|
|
984
|
-
fields,
|
|
985
|
-
sObject: fromResult.sObject
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
if (fromResult.alias) {
|
|
989
|
-
query.sObjectAlias = fromResult.alias;
|
|
990
|
-
}
|
|
991
|
-
this.applySObjectAlias(query);
|
|
992
|
-
const clauses = this.parseClauseStatements();
|
|
993
|
-
Object.assign(query, clauses);
|
|
994
|
-
return query;
|
|
995
|
-
}
|
|
996
|
-
parseSelectStatementPartial() {
|
|
997
|
-
let fields;
|
|
998
|
-
let fromResult;
|
|
999
|
-
if (this.check(23 /* SELECT */)) {
|
|
1000
|
-
fields = this.parseSelectClause();
|
|
1001
|
-
}
|
|
1002
|
-
if (this.check(9 /* FROM */)) {
|
|
1003
|
-
fromResult = this.parseFromClause();
|
|
1004
|
-
}
|
|
1005
|
-
const query = {};
|
|
1006
|
-
if (fields) {
|
|
1007
|
-
query.fields = fields;
|
|
1008
|
-
}
|
|
1009
|
-
if (fromResult) {
|
|
1010
|
-
query.sObject = fromResult.sObject;
|
|
1011
|
-
if (fromResult.alias) {
|
|
1012
|
-
query.sObjectAlias = fromResult.alias;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
if (query.fields) {
|
|
1016
|
-
this.applySObjectAlias(query);
|
|
1017
|
-
}
|
|
1018
|
-
const clauses = this.parseClauseStatements();
|
|
1019
|
-
Object.assign(query, clauses);
|
|
1020
|
-
return query;
|
|
1021
|
-
}
|
|
1022
|
-
applySObjectAlias(query) {
|
|
1023
|
-
if (!query.sObjectAlias || !Array.isArray(query.fields)) return;
|
|
1024
|
-
const alias = query.sObjectAlias;
|
|
1025
|
-
query.fields.forEach((field) => {
|
|
1026
|
-
if (field.relationships && field.relationships[0] === alias) {
|
|
1027
|
-
field.relationships = field.relationships.slice(1);
|
|
1028
|
-
field.objectPrefix = alias;
|
|
1029
|
-
if (field.relationships.length === 0) {
|
|
1030
|
-
delete field.relationships;
|
|
1031
|
-
field.type = "Field";
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
// ====================================================================
|
|
1037
|
-
// SELECT Clause
|
|
1038
|
-
// ====================================================================
|
|
1039
|
-
parseSelectClause() {
|
|
1040
|
-
this.expect(23 /* SELECT */);
|
|
1041
|
-
const fields = [];
|
|
1042
|
-
fields.push(this.parseSelectField());
|
|
1043
|
-
while (this.match(143 /* COMMA */)) {
|
|
1044
|
-
fields.push(this.parseSelectField());
|
|
1045
|
-
}
|
|
1046
|
-
return fields;
|
|
1047
|
-
}
|
|
1048
|
-
parseSelectField() {
|
|
1049
|
-
const t = this.peek();
|
|
1050
|
-
const next = this.peekAt(1);
|
|
1051
|
-
if (t.kind === 138 /* L_PAREN */ && next.kind === 23 /* SELECT */) {
|
|
1052
|
-
return this.parseSelectClauseSubqueryIdentifier();
|
|
1053
|
-
}
|
|
1054
|
-
if (t.kind === 42 /* TYPEOF */) {
|
|
1055
|
-
return this.parseSelectClauseTypeOf();
|
|
1056
|
-
}
|
|
1057
|
-
if (this.isFunctionCall()) {
|
|
1058
|
-
return this.parseSelectClauseFunctionIdentifier();
|
|
1059
|
-
}
|
|
1060
|
-
return this.parseSelectClauseIdentifier();
|
|
1061
|
-
}
|
|
1062
|
-
parseSelectClauseFunctionIdentifier() {
|
|
1063
|
-
const fn = this.parseAnyFunction(true);
|
|
1064
|
-
if (this.canBeAlias()) {
|
|
1065
|
-
fn.alias = this.consumeIdentifier().text;
|
|
1066
|
-
}
|
|
1067
|
-
return fn;
|
|
1068
|
-
}
|
|
1069
|
-
parseSelectClauseSubqueryIdentifier() {
|
|
1070
|
-
this.expect(138 /* L_PAREN */);
|
|
1071
|
-
const subquery = this.parseSelectStatement(true);
|
|
1072
|
-
this.expect(139 /* R_PAREN */);
|
|
1073
|
-
return {
|
|
1074
|
-
type: "FieldSubquery",
|
|
1075
|
-
subquery
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
parseSelectClauseTypeOf() {
|
|
1079
|
-
this.expect(42 /* TYPEOF */);
|
|
1080
|
-
const field = this.consumeIdentifier().text;
|
|
1081
|
-
const conditions = [];
|
|
1082
|
-
while (this.check(45 /* WHEN */)) {
|
|
1083
|
-
this.advance();
|
|
1084
|
-
const objectType = this.consumeIdentifier().text;
|
|
1085
|
-
this.expect(41 /* THEN */);
|
|
1086
|
-
const fieldList = [];
|
|
1087
|
-
fieldList.push(this.consumeIdentifier().text);
|
|
1088
|
-
while (this.match(143 /* COMMA */)) {
|
|
1089
|
-
fieldList.push(this.consumeIdentifier().text);
|
|
1090
|
-
}
|
|
1091
|
-
conditions.push({ type: "WHEN", objectType, fieldList });
|
|
1092
|
-
}
|
|
1093
|
-
if (this.check(5 /* ELSE */)) {
|
|
1094
|
-
this.advance();
|
|
1095
|
-
const fieldList = [];
|
|
1096
|
-
fieldList.push(this.consumeIdentifier().text);
|
|
1097
|
-
while (this.match(143 /* COMMA */)) {
|
|
1098
|
-
fieldList.push(this.consumeIdentifier().text);
|
|
1099
|
-
}
|
|
1100
|
-
conditions.push({ type: "ELSE", fieldList });
|
|
1101
|
-
}
|
|
1102
|
-
this.expect(36 /* END */);
|
|
1103
|
-
return {
|
|
1104
|
-
type: "FieldTypeof",
|
|
1105
|
-
field,
|
|
1106
|
-
conditions
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
parseSelectClauseIdentifier() {
|
|
1110
|
-
const idToken = this.consumeIdentifier();
|
|
1111
|
-
const fullText = idToken.text;
|
|
1112
|
-
let output;
|
|
1113
|
-
if (!fullText.includes(".")) {
|
|
1114
|
-
output = {
|
|
1115
|
-
type: "Field",
|
|
1116
|
-
field: fullText
|
|
1117
|
-
};
|
|
1118
|
-
} else {
|
|
1119
|
-
const parts = fullText.split(".");
|
|
1120
|
-
output = {
|
|
1121
|
-
type: "FieldRelationship",
|
|
1122
|
-
field: parts[parts.length - 1],
|
|
1123
|
-
relationships: parts.slice(0, parts.length - 1),
|
|
1124
|
-
rawValue: fullText
|
|
1125
|
-
};
|
|
1126
|
-
}
|
|
1127
|
-
if (this.canBeAlias()) {
|
|
1128
|
-
output.alias = this.consumeIdentifier().text;
|
|
1129
|
-
}
|
|
1130
|
-
return output;
|
|
1131
|
-
}
|
|
1132
|
-
// ====================================================================
|
|
1133
|
-
// FROM Clause
|
|
1134
|
-
// ====================================================================
|
|
1135
|
-
parseFromClause() {
|
|
1136
|
-
this.expect(9 /* FROM */);
|
|
1137
|
-
const idToken = this.consumeIdentifier();
|
|
1138
|
-
const fullText = idToken.text;
|
|
1139
|
-
let result;
|
|
1140
|
-
if (fullText.includes(".")) {
|
|
1141
|
-
const parts = fullText.split(".");
|
|
1142
|
-
result = {
|
|
1143
|
-
sObjectPrefix: parts.slice(0, parts.length - 1),
|
|
1144
|
-
sObject: parts[parts.length - 1]
|
|
1145
|
-
};
|
|
1146
|
-
} else {
|
|
1147
|
-
result = { sObject: fullText };
|
|
1148
|
-
}
|
|
1149
|
-
if (this.canBeAlias()) {
|
|
1150
|
-
result.alias = this.consumeIdentifier().text;
|
|
1151
|
-
}
|
|
1152
|
-
return result;
|
|
1153
|
-
}
|
|
1154
|
-
// ====================================================================
|
|
1155
|
-
// Clause Statements (everything after FROM)
|
|
1156
|
-
// ====================================================================
|
|
1157
|
-
parseClauseStatements() {
|
|
1158
|
-
const query = {};
|
|
1159
|
-
const tryParse = (fn, cleanup) => {
|
|
1160
|
-
if (this.config.ignoreParseErrors) {
|
|
1161
|
-
try {
|
|
1162
|
-
fn();
|
|
1163
|
-
if (!this.isAtClauseBoundary()) {
|
|
1164
|
-
if (cleanup) cleanup();
|
|
1165
|
-
this.synchronize();
|
|
1166
|
-
}
|
|
1167
|
-
} catch (e) {
|
|
1168
|
-
if (this.config.logErrors) {
|
|
1169
|
-
console.log(e);
|
|
1170
|
-
}
|
|
1171
|
-
if (cleanup) cleanup();
|
|
1172
|
-
this.synchronize();
|
|
1173
|
-
}
|
|
1174
|
-
} else {
|
|
1175
|
-
fn();
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
if (this.check(25 /* USING */)) {
|
|
1179
|
-
tryParse(() => {
|
|
1180
|
-
query.usingScope = this.parseUsingScope();
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
if (this.check(26 /* WHERE */)) {
|
|
1184
|
-
tryParse(
|
|
1185
|
-
() => {
|
|
1186
|
-
query.where = this.parseWhereClause();
|
|
1187
|
-
},
|
|
1188
|
-
() => {
|
|
1189
|
-
delete query.where;
|
|
1190
|
-
}
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
while (this.check(27 /* WITH */)) {
|
|
1194
|
-
tryParse(() => {
|
|
1195
|
-
const withResult = this.parseWithClause();
|
|
1196
|
-
if (withResult.withSecurityEnforced) {
|
|
1197
|
-
query.withSecurityEnforced = true;
|
|
1198
|
-
}
|
|
1199
|
-
if (withResult.withAccessLevel) {
|
|
1200
|
-
query.withAccessLevel = withResult.withAccessLevel;
|
|
1201
|
-
}
|
|
1202
|
-
if (withResult.withDataCategory) {
|
|
1203
|
-
query.withDataCategory = withResult.withDataCategory;
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
if (this.check(10 /* GROUP_BY */)) {
|
|
1208
|
-
tryParse(() => {
|
|
1209
|
-
query.groupBy = this.parseGroupByClause();
|
|
1210
|
-
});
|
|
1211
|
-
if (this.check(11 /* HAVING */)) {
|
|
1212
|
-
tryParse(() => {
|
|
1213
|
-
query.having = this.parseHavingClause();
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
if (this.check(21 /* ORDER_BY */)) {
|
|
1218
|
-
tryParse(() => {
|
|
1219
|
-
query.orderBy = this.parseOrderByClause();
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
if (this.check(16 /* LIMIT */)) {
|
|
1223
|
-
tryParse(() => {
|
|
1224
|
-
this.advance();
|
|
1225
|
-
query.limit = Number(this.expect(156 /* UNSIGNED_INTEGER */).text);
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
if (this.check(37 /* OFFSET */)) {
|
|
1229
|
-
tryParse(() => {
|
|
1230
|
-
this.advance();
|
|
1231
|
-
query.offset = Number(this.expect(156 /* UNSIGNED_INTEGER */).text);
|
|
1232
|
-
});
|
|
1233
|
-
}
|
|
1234
|
-
if (this.check(28 /* FOR */)) {
|
|
1235
|
-
tryParse(() => {
|
|
1236
|
-
this.advance();
|
|
1237
|
-
const t = this.peek();
|
|
1238
|
-
if (t.kind === 43 /* VIEW */ || t.kind === 38 /* REFERENCE */ || t.kind === 29 /* UPDATE */) {
|
|
1239
|
-
query.for = tokenTypeName(this.advance().kind);
|
|
1240
|
-
} else {
|
|
1241
|
-
throw this.error(`Expected VIEW, REFERENCE, or UPDATE after FOR at position ${t.start}`);
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
if (this.check(29 /* UPDATE */)) {
|
|
1246
|
-
tryParse(() => {
|
|
1247
|
-
this.advance();
|
|
1248
|
-
const t = this.peek();
|
|
1249
|
-
if (t.kind === 40 /* TRACKING */ || t.kind === 44 /* VIEWSTAT */) {
|
|
1250
|
-
query.update = tokenTypeName(this.advance().kind);
|
|
1251
|
-
} else {
|
|
1252
|
-
throw this.error(`Expected TRACKING or VIEWSTAT after UPDATE at position ${t.start}`);
|
|
1253
|
-
}
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
return query;
|
|
1257
|
-
}
|
|
1258
|
-
// ====================================================================
|
|
1259
|
-
// USING SCOPE
|
|
1260
|
-
// ====================================================================
|
|
1261
|
-
parseUsingScope() {
|
|
1262
|
-
this.expect(25 /* USING */);
|
|
1263
|
-
this.expect(39 /* SCOPE */);
|
|
1264
|
-
const t = this.peek();
|
|
1265
|
-
if (isUsingScopeEnumeration(t.kind)) {
|
|
1266
|
-
return this.advance().text;
|
|
1267
|
-
}
|
|
1268
|
-
if (isIdentifierLike(t.kind)) {
|
|
1269
|
-
return this.advance().text;
|
|
1270
|
-
}
|
|
1271
|
-
throw this.error(`Expected scope enumeration value at position ${t.start}`);
|
|
1272
|
-
}
|
|
1273
|
-
// ====================================================================
|
|
1274
|
-
// WHERE Clause
|
|
1275
|
-
// ====================================================================
|
|
1276
|
-
parseWhereClause() {
|
|
1277
|
-
this.expect(26 /* WHERE */);
|
|
1278
|
-
return this.parseConditionExpressions(true, true);
|
|
1279
|
-
}
|
|
1280
|
-
parseConditionExpressions(allowAggregateFn, allowLocationFn) {
|
|
1281
|
-
let expressionTree;
|
|
1282
|
-
let prevExpression;
|
|
1283
|
-
const parenCount = { left: 0, right: 0 };
|
|
1284
|
-
while (true) {
|
|
1285
|
-
let logicalOp;
|
|
1286
|
-
if (expressionTree) {
|
|
1287
|
-
if (this.check(0 /* AND */)) {
|
|
1288
|
-
logicalOp = "AND";
|
|
1289
|
-
this.advance();
|
|
1290
|
-
} else if (this.check(20 /* OR */)) {
|
|
1291
|
-
logicalOp = "OR";
|
|
1292
|
-
this.advance();
|
|
1293
|
-
} else {
|
|
1294
|
-
break;
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
let baseExpression = {};
|
|
1298
|
-
let currExpression = baseExpression;
|
|
1299
|
-
let parentForRight = null;
|
|
1300
|
-
while (this.hasNegationPrefix()) {
|
|
1301
|
-
let openParenCount = 0;
|
|
1302
|
-
while (this.check(138 /* L_PAREN */) && this.isNegationAhead()) {
|
|
1303
|
-
this.advance();
|
|
1304
|
-
openParenCount++;
|
|
1305
|
-
parenCount.left++;
|
|
1306
|
-
}
|
|
1307
|
-
if (this.check(17 /* NOT */)) {
|
|
1308
|
-
this.advance();
|
|
1309
|
-
const negation = {
|
|
1310
|
-
left: openParenCount > 0 ? { openParen: openParenCount } : null,
|
|
1311
|
-
operator: "NOT",
|
|
1312
|
-
right: { left: {} }
|
|
1313
|
-
};
|
|
1314
|
-
if (!parentForRight) {
|
|
1315
|
-
baseExpression = negation;
|
|
1316
|
-
} else {
|
|
1317
|
-
parentForRight.right = negation;
|
|
1318
|
-
}
|
|
1319
|
-
parentForRight = negation;
|
|
1320
|
-
currExpression = negation.right;
|
|
1321
|
-
} else {
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
currExpression.left = this.parseExpression(allowAggregateFn, allowLocationFn, parenCount);
|
|
1326
|
-
if (!expressionTree) {
|
|
1327
|
-
expressionTree = baseExpression;
|
|
1328
|
-
prevExpression = baseExpression;
|
|
1329
|
-
} else {
|
|
1330
|
-
if (logicalOp) {
|
|
1331
|
-
prevExpression.operator = logicalOp;
|
|
1332
|
-
prevExpression.right = baseExpression;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
let temp = baseExpression;
|
|
1336
|
-
while (temp.right && temp.right.left !== void 0) {
|
|
1337
|
-
const r = temp.right;
|
|
1338
|
-
if (r.right && r.right.left !== void 0) {
|
|
1339
|
-
temp = r;
|
|
1340
|
-
} else {
|
|
1341
|
-
temp = r;
|
|
1342
|
-
break;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
prevExpression = temp;
|
|
1346
|
-
if (this.isAtEnd()) break;
|
|
1347
|
-
const nextKind = this.peek().kind;
|
|
1348
|
-
if (nextKind !== 0 /* AND */ && nextKind !== 20 /* OR */) break;
|
|
1349
|
-
}
|
|
1350
|
-
if (parenCount.left !== parenCount.right) {
|
|
1351
|
-
throw this.error(`Mismatched parentheses in WHERE/HAVING clause: ${parenCount.left} open vs ${parenCount.right} close`);
|
|
1352
|
-
}
|
|
1353
|
-
return expressionTree;
|
|
1354
|
-
}
|
|
1355
|
-
// Check if there's a negation pattern ahead (possible parens then NOT then expression)
|
|
1356
|
-
hasNegationPrefix() {
|
|
1357
|
-
let offset = 0;
|
|
1358
|
-
while (this.peekAt(offset).kind === 138 /* L_PAREN */) {
|
|
1359
|
-
offset++;
|
|
1360
|
-
}
|
|
1361
|
-
return this.peekAt(offset).kind === 17 /* NOT */;
|
|
1362
|
-
}
|
|
1363
|
-
// Check if after some L_PARENs there is a NOT keyword
|
|
1364
|
-
isNegationAhead() {
|
|
1365
|
-
let offset = 1;
|
|
1366
|
-
while (this.peekAt(offset).kind === 138 /* L_PAREN */) {
|
|
1367
|
-
offset++;
|
|
1368
|
-
}
|
|
1369
|
-
return this.peekAt(offset).kind === 17 /* NOT */;
|
|
1370
|
-
}
|
|
1371
|
-
// ====================================================================
|
|
1372
|
-
// Expression (WHERE/HAVING condition)
|
|
1373
|
-
// ====================================================================
|
|
1374
|
-
parseExpression(allowAggregateFn, allowLocationFn, parenCount) {
|
|
1375
|
-
let openParenCount = 0;
|
|
1376
|
-
while (this.check(138 /* L_PAREN */) && !this.isSubqueryStart() && !this.isArrayExpressionStart()) {
|
|
1377
|
-
this.advance();
|
|
1378
|
-
openParenCount++;
|
|
1379
|
-
if (parenCount) parenCount.left++;
|
|
1380
|
-
}
|
|
1381
|
-
let lhs;
|
|
1382
|
-
let isLhsFn = false;
|
|
1383
|
-
if (allowAggregateFn && isAggregateFunction(this.peek().kind) && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1384
|
-
lhs = this.parseAggregateFunction(false);
|
|
1385
|
-
isLhsFn = true;
|
|
1386
|
-
} else if (allowLocationFn && isLocationFunction(this.peek().kind) && this.peek().kind === 68 /* DISTANCE */ && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1387
|
-
lhs = this.parseLocationFunction(false);
|
|
1388
|
-
isLhsFn = true;
|
|
1389
|
-
} else if (isDateFunction(this.peek().kind) && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1390
|
-
lhs = this.parseDateFunction(false);
|
|
1391
|
-
isLhsFn = true;
|
|
1392
|
-
} else if (isOtherFunction(this.peek().kind) && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1393
|
-
lhs = this.parseOtherFunction(false);
|
|
1394
|
-
isLhsFn = true;
|
|
1395
|
-
} else {
|
|
1396
|
-
lhs = this.consumeIdentifier().text;
|
|
1397
|
-
}
|
|
1398
|
-
const operatorResult = this.parseOperator();
|
|
1399
|
-
const operator = operatorResult.operator;
|
|
1400
|
-
const isSetOperator = operatorResult.isSet;
|
|
1401
|
-
let value;
|
|
1402
|
-
let literalType;
|
|
1403
|
-
let dateLiteralVariable;
|
|
1404
|
-
if (isSetOperator) {
|
|
1405
|
-
if (this.check(138 /* L_PAREN */) && this.peekAt(1).kind === 23 /* SELECT */) {
|
|
1406
|
-
this.expect(138 /* L_PAREN */);
|
|
1407
|
-
value = this.parseSelectStatement(false);
|
|
1408
|
-
this.expect(139 /* R_PAREN */);
|
|
1409
|
-
literalType = "SUBQUERY";
|
|
1410
|
-
} else if (this.config.allowApexBindVariables && this.check(144 /* COLON */)) {
|
|
1411
|
-
const apexResult = this.parseApexBindVariable();
|
|
1412
|
-
value = apexResult.value;
|
|
1413
|
-
literalType = "APEX_BIND_VARIABLE";
|
|
1414
|
-
} else {
|
|
1415
|
-
const arrayResult = this.parseArrayExpression();
|
|
1416
|
-
value = arrayResult.values;
|
|
1417
|
-
literalType = arrayResult.literalType;
|
|
1418
|
-
dateLiteralVariable = arrayResult.dateLiteralVariable;
|
|
1419
|
-
}
|
|
1420
|
-
} else {
|
|
1421
|
-
const atomicResult = this.parseAtomicValue();
|
|
1422
|
-
value = atomicResult.value;
|
|
1423
|
-
literalType = atomicResult.literalType;
|
|
1424
|
-
dateLiteralVariable = atomicResult.dateLiteralVariable;
|
|
1425
|
-
}
|
|
1426
|
-
let closeParenCount = 0;
|
|
1427
|
-
while (this.check(139 /* R_PAREN */) && (!parenCount || parenCount.left > parenCount.right)) {
|
|
1428
|
-
this.advance();
|
|
1429
|
-
closeParenCount++;
|
|
1430
|
-
if (parenCount) parenCount.right++;
|
|
1431
|
-
}
|
|
1432
|
-
const condition = {};
|
|
1433
|
-
if (isLhsFn) {
|
|
1434
|
-
condition.fn = lhs;
|
|
1435
|
-
} else {
|
|
1436
|
-
condition.field = lhs;
|
|
1437
|
-
}
|
|
1438
|
-
condition.operator = operator;
|
|
1439
|
-
if (literalType === "SUBQUERY") {
|
|
1440
|
-
condition.valueQuery = value;
|
|
1441
|
-
} else {
|
|
1442
|
-
condition.value = value;
|
|
1443
|
-
}
|
|
1444
|
-
condition.literalType = literalType;
|
|
1445
|
-
if (dateLiteralVariable !== void 0) {
|
|
1446
|
-
condition.dateLiteralVariable = dateLiteralVariable;
|
|
1447
|
-
}
|
|
1448
|
-
if (openParenCount > 0) {
|
|
1449
|
-
condition.openParen = openParenCount;
|
|
1450
|
-
}
|
|
1451
|
-
if (closeParenCount > 0) {
|
|
1452
|
-
condition.closeParen = closeParenCount;
|
|
1453
|
-
}
|
|
1454
|
-
return condition;
|
|
1455
|
-
}
|
|
1456
|
-
isSubqueryStart() {
|
|
1457
|
-
return this.check(138 /* L_PAREN */) && this.peekAt(1).kind === 23 /* SELECT */;
|
|
1458
|
-
}
|
|
1459
|
-
isArrayExpressionStart() {
|
|
1460
|
-
return false;
|
|
1461
|
-
}
|
|
1462
|
-
// ====================================================================
|
|
1463
|
-
// Operators
|
|
1464
|
-
// ====================================================================
|
|
1465
|
-
parseOperator() {
|
|
1466
|
-
const t = this.peek();
|
|
1467
|
-
if (isRelationalOperator(t.kind)) {
|
|
1468
|
-
return { operator: this.advance().text, isSet: false };
|
|
1469
|
-
}
|
|
1470
|
-
if (t.kind === 15 /* LIKE */) {
|
|
1471
|
-
this.advance();
|
|
1472
|
-
return { operator: "LIKE", isSet: false };
|
|
1473
|
-
}
|
|
1474
|
-
if (t.kind === 12 /* IN */) {
|
|
1475
|
-
this.advance();
|
|
1476
|
-
return { operator: "IN", isSet: true };
|
|
1477
|
-
}
|
|
1478
|
-
if (t.kind === 17 /* NOT */ && this.peekAt(1).kind === 12 /* IN */) {
|
|
1479
|
-
this.advance();
|
|
1480
|
-
this.advance();
|
|
1481
|
-
return { operator: "NOT IN", isSet: true };
|
|
1482
|
-
}
|
|
1483
|
-
if (t.kind === 13 /* INCLUDES */) {
|
|
1484
|
-
this.advance();
|
|
1485
|
-
return { operator: "INCLUDES", isSet: true };
|
|
1486
|
-
}
|
|
1487
|
-
if (t.kind === 6 /* EXCLUDES */) {
|
|
1488
|
-
this.advance();
|
|
1489
|
-
return { operator: "EXCLUDES", isSet: true };
|
|
1490
|
-
}
|
|
1491
|
-
throw this.error(`Expected operator but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
1492
|
-
}
|
|
1493
|
-
// ====================================================================
|
|
1494
|
-
// Atomic Values
|
|
1495
|
-
// ====================================================================
|
|
1496
|
-
parseAtomicValue() {
|
|
1497
|
-
const t = this.peek();
|
|
1498
|
-
if (this.config.allowApexBindVariables && t.kind === 144 /* COLON */) {
|
|
1499
|
-
const result = this.parseApexBindVariable();
|
|
1500
|
-
return { value: result.value, literalType: "APEX_BIND_VARIABLE" };
|
|
1501
|
-
}
|
|
1502
|
-
if (t.kind === 157 /* STRING_LITERAL */) {
|
|
1503
|
-
return { value: this.advance().text, literalType: "STRING" };
|
|
1504
|
-
}
|
|
1505
|
-
if (t.kind === 158 /* GEOLOCATION_UNIT */) {
|
|
1506
|
-
return { value: this.advance().text, literalType: "STRING" };
|
|
1507
|
-
}
|
|
1508
|
-
if (t.kind === 156 /* UNSIGNED_INTEGER */) {
|
|
1509
|
-
return { value: this.advance().text, literalType: "INTEGER" };
|
|
1510
|
-
}
|
|
1511
|
-
if (t.kind === 155 /* SIGNED_INTEGER */) {
|
|
1512
|
-
return { value: this.advance().text, literalType: "INTEGER" };
|
|
1513
|
-
}
|
|
1514
|
-
if (t.kind === 154 /* UNSIGNED_DECIMAL */) {
|
|
1515
|
-
return { value: this.advance().text, literalType: "DECIMAL" };
|
|
1516
|
-
}
|
|
1517
|
-
if (t.kind === 153 /* SIGNED_DECIMAL */) {
|
|
1518
|
-
return { value: this.advance().text, literalType: "DECIMAL" };
|
|
1519
|
-
}
|
|
1520
|
-
if (t.kind === 151 /* CURRENCY_PREFIXED_DECIMAL */) {
|
|
1521
|
-
return { value: this.advance().text, literalType: "DECIMAL_WITH_CURRENCY_PREFIX" };
|
|
1522
|
-
}
|
|
1523
|
-
if (t.kind === 152 /* CURRENCY_PREFIXED_INTEGER */) {
|
|
1524
|
-
return { value: this.advance().text, literalType: "INTEGER_WITH_CURRENCY_PREFIX" };
|
|
1525
|
-
}
|
|
1526
|
-
if (t.kind === 149 /* DATETIME */) {
|
|
1527
|
-
return { value: this.advance().text, literalType: "DATETIME" };
|
|
1528
|
-
}
|
|
1529
|
-
if (t.kind === 150 /* DATE_TOKEN */) {
|
|
1530
|
-
return { value: this.advance().text, literalType: "DATE" };
|
|
1531
|
-
}
|
|
1532
|
-
if (t.kind === 18 /* NULL */) {
|
|
1533
|
-
this.advance();
|
|
1534
|
-
return { value: "NULL", literalType: "NULL" };
|
|
1535
|
-
}
|
|
1536
|
-
if (t.kind === 24 /* TRUE */ || t.kind === 7 /* FALSE */) {
|
|
1537
|
-
return { value: tokenTypeName(this.advance().kind), literalType: "BOOLEAN" };
|
|
1538
|
-
}
|
|
1539
|
-
if (isDateLiteral(t.kind)) {
|
|
1540
|
-
return { value: this.advance().text, literalType: "DATE_LITERAL" };
|
|
1541
|
-
}
|
|
1542
|
-
if (isDateNLiteral(t.kind)) {
|
|
1543
|
-
const dateNToken = this.advance();
|
|
1544
|
-
this.expect(144 /* COLON */);
|
|
1545
|
-
const numToken = this.peek();
|
|
1546
|
-
let variable;
|
|
1547
|
-
if (numToken.kind === 156 /* UNSIGNED_INTEGER */ || numToken.kind === 155 /* SIGNED_INTEGER */) {
|
|
1548
|
-
variable = Number(this.advance().text);
|
|
1549
|
-
} else {
|
|
1550
|
-
throw this.error(`Expected integer after date N literal colon at position ${numToken.start}`);
|
|
1551
|
-
}
|
|
1552
|
-
const value = `${dateNToken.text}:${variable}`;
|
|
1553
|
-
return { value, literalType: "DATE_N_LITERAL", dateLiteralVariable: variable };
|
|
1554
|
-
}
|
|
1555
|
-
throw this.error(`Expected value but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
1556
|
-
}
|
|
1557
|
-
// ====================================================================
|
|
1558
|
-
// Array Expression
|
|
1559
|
-
// ====================================================================
|
|
1560
|
-
parseArrayExpression() {
|
|
1561
|
-
this.expect(138 /* L_PAREN */);
|
|
1562
|
-
const items = [];
|
|
1563
|
-
items.push(this.parseArrayItem());
|
|
1564
|
-
while (this.match(143 /* COMMA */)) {
|
|
1565
|
-
items.push(this.parseArrayItem());
|
|
1566
|
-
}
|
|
1567
|
-
this.expect(139 /* R_PAREN */);
|
|
1568
|
-
const values = items.map((i) => i.value);
|
|
1569
|
-
const types = items.map((i) => i.type);
|
|
1570
|
-
const dateLiteralTemp = items.map((i) => i.variable !== void 0 ? i.variable : null);
|
|
1571
|
-
const hasDateLiterals = dateLiteralTemp.some((item) => item !== null);
|
|
1572
|
-
let literalType;
|
|
1573
|
-
if (new Set(types).size === 1) {
|
|
1574
|
-
literalType = this.getLiteralType(this.tokenKindFromTypeName(types[0]));
|
|
1575
|
-
} else {
|
|
1576
|
-
literalType = types.map((t) => this.getLiteralType(this.tokenKindFromTypeName(t)));
|
|
1577
|
-
}
|
|
1578
|
-
const result = { values, literalType };
|
|
1579
|
-
if (hasDateLiterals) {
|
|
1580
|
-
result.dateLiteralVariable = dateLiteralTemp;
|
|
1581
|
-
}
|
|
1582
|
-
return result;
|
|
1583
|
-
}
|
|
1584
|
-
tokenKindFromTypeName(name) {
|
|
1585
|
-
for (let i = 0; i <= 160 /* EOF */; i++) {
|
|
1586
|
-
if (tokenTypeName(i) === name) return i;
|
|
1587
|
-
}
|
|
1588
|
-
return 159 /* IDENTIFIER */;
|
|
1589
|
-
}
|
|
1590
|
-
parseArrayItem() {
|
|
1591
|
-
const t = this.peek();
|
|
1592
|
-
if (t.kind === 157 /* STRING_LITERAL */) {
|
|
1593
|
-
return { value: this.advance().text, type: tokenTypeName(157 /* STRING_LITERAL */) };
|
|
1594
|
-
}
|
|
1595
|
-
if (t.kind === 158 /* GEOLOCATION_UNIT */) {
|
|
1596
|
-
return { value: this.advance().text, type: tokenTypeName(158 /* GEOLOCATION_UNIT */) };
|
|
1597
|
-
}
|
|
1598
|
-
if (t.kind === 151 /* CURRENCY_PREFIXED_DECIMAL */) {
|
|
1599
|
-
return { value: this.advance().text, type: tokenTypeName(151 /* CURRENCY_PREFIXED_DECIMAL */) };
|
|
1600
|
-
}
|
|
1601
|
-
if (t.kind === 152 /* CURRENCY_PREFIXED_INTEGER */) {
|
|
1602
|
-
return { value: this.advance().text, type: tokenTypeName(152 /* CURRENCY_PREFIXED_INTEGER */) };
|
|
1603
|
-
}
|
|
1604
|
-
if (isNumberLiteral(t.kind)) {
|
|
1605
|
-
const token = this.advance();
|
|
1606
|
-
return { value: token.text, type: tokenTypeName(token.kind) };
|
|
1607
|
-
}
|
|
1608
|
-
if (t.kind === 149 /* DATETIME */) {
|
|
1609
|
-
return { value: this.advance().text, type: tokenTypeName(149 /* DATETIME */) };
|
|
1610
|
-
}
|
|
1611
|
-
if (t.kind === 150 /* DATE_TOKEN */) {
|
|
1612
|
-
return { value: this.advance().text, type: tokenTypeName(150 /* DATE_TOKEN */) };
|
|
1613
|
-
}
|
|
1614
|
-
if (t.kind === 18 /* NULL */) {
|
|
1615
|
-
this.advance();
|
|
1616
|
-
return { value: "NULL", type: "NULL" };
|
|
1617
|
-
}
|
|
1618
|
-
if (t.kind === 24 /* TRUE */) {
|
|
1619
|
-
return { value: this.advance().text, type: "TRUE" };
|
|
1620
|
-
}
|
|
1621
|
-
if (t.kind === 7 /* FALSE */) {
|
|
1622
|
-
return { value: this.advance().text, type: "FALSE" };
|
|
1623
|
-
}
|
|
1624
|
-
if (isDateLiteral(t.kind)) {
|
|
1625
|
-
return { value: this.advance().text, type: tokenTypeName(t.kind) };
|
|
1626
|
-
}
|
|
1627
|
-
if (isDateNLiteral(t.kind)) {
|
|
1628
|
-
const dateNToken = this.advance();
|
|
1629
|
-
this.expect(144 /* COLON */);
|
|
1630
|
-
const numToken = this.peek();
|
|
1631
|
-
let variable;
|
|
1632
|
-
if (numToken.kind === 156 /* UNSIGNED_INTEGER */ || numToken.kind === 155 /* SIGNED_INTEGER */) {
|
|
1633
|
-
variable = Number(this.advance().text);
|
|
1634
|
-
} else {
|
|
1635
|
-
throw this.error(`Expected integer after date N literal colon at position ${numToken.start}`);
|
|
1636
|
-
}
|
|
1637
|
-
return {
|
|
1638
|
-
value: `${dateNToken.text}:${variable}`,
|
|
1639
|
-
type: tokenTypeName(dateNToken.kind),
|
|
1640
|
-
variable
|
|
1641
|
-
};
|
|
1642
|
-
}
|
|
1643
|
-
throw this.error(`Expected array value but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
1644
|
-
}
|
|
1645
|
-
// ====================================================================
|
|
1646
|
-
// Apex Bind Variables
|
|
1647
|
-
// ====================================================================
|
|
1648
|
-
parseApexBindVariable() {
|
|
1649
|
-
this.expect(144 /* COLON */);
|
|
1650
|
-
const parts = [];
|
|
1651
|
-
if (this.check(32 /* APEX_NEW */)) {
|
|
1652
|
-
parts.push(this.parseApexBindNewInstantiation());
|
|
1653
|
-
} else if (this.checkIdentifier()) {
|
|
1654
|
-
if (this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1655
|
-
parts.push(this.parseApexBindFunctionCall());
|
|
1656
|
-
} else {
|
|
1657
|
-
parts.push(this.parseApexBindIdentifier());
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
while (this.check(142 /* DOT */)) {
|
|
1661
|
-
this.advance();
|
|
1662
|
-
if (this.checkIdentifier() && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1663
|
-
parts.push(this.parseApexBindFunctionCall());
|
|
1664
|
-
} else if (this.checkIdentifier()) {
|
|
1665
|
-
parts.push(this.parseApexBindIdentifier());
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
return { value: parts.join(".") };
|
|
1669
|
-
}
|
|
1670
|
-
parseApexBindIdentifier() {
|
|
1671
|
-
let output = this.consumeIdentifier().text;
|
|
1672
|
-
if (this.check(140 /* L_SQUARE_BRACKET */)) {
|
|
1673
|
-
output += this.parseApexBindArrayAccessor();
|
|
1674
|
-
}
|
|
1675
|
-
return output;
|
|
1676
|
-
}
|
|
1677
|
-
parseApexBindNewInstantiation() {
|
|
1678
|
-
this.expect(32 /* APEX_NEW */);
|
|
1679
|
-
const fnName = this.consumeIdentifier().text;
|
|
1680
|
-
let output = `new ${fnName}`;
|
|
1681
|
-
if (this.check(134 /* LESS_THAN */)) {
|
|
1682
|
-
this.advance();
|
|
1683
|
-
const params = [];
|
|
1684
|
-
params.push(this.consumeIdentifier().text);
|
|
1685
|
-
while (this.match(143 /* COMMA */)) {
|
|
1686
|
-
params.push(this.consumeIdentifier().text);
|
|
1687
|
-
}
|
|
1688
|
-
this.expect(136 /* GREATER_THAN */);
|
|
1689
|
-
output += `<${params.join(", ")}>`;
|
|
1690
|
-
}
|
|
1691
|
-
output += this.parseApexBindFunctionParams();
|
|
1692
|
-
if (this.check(140 /* L_SQUARE_BRACKET */)) {
|
|
1693
|
-
output += this.parseApexBindArrayAccessor();
|
|
1694
|
-
}
|
|
1695
|
-
return output;
|
|
1696
|
-
}
|
|
1697
|
-
parseApexBindFunctionCall() {
|
|
1698
|
-
const fnName = this.consumeIdentifier().text;
|
|
1699
|
-
let output = fnName + this.parseApexBindFunctionParams();
|
|
1700
|
-
if (this.check(140 /* L_SQUARE_BRACKET */)) {
|
|
1701
|
-
output += this.parseApexBindArrayAccessor();
|
|
1702
|
-
}
|
|
1703
|
-
return output;
|
|
1704
|
-
}
|
|
1705
|
-
parseApexBindFunctionParams() {
|
|
1706
|
-
this.expect(138 /* L_PAREN */);
|
|
1707
|
-
const params = [];
|
|
1708
|
-
if (!this.check(139 /* R_PAREN */)) {
|
|
1709
|
-
params.push(this.consumeIdentifier().text);
|
|
1710
|
-
while (this.match(143 /* COMMA */)) {
|
|
1711
|
-
params.push(this.consumeIdentifier().text);
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
this.expect(139 /* R_PAREN */);
|
|
1715
|
-
return `(${params.join(", ")})`;
|
|
1716
|
-
}
|
|
1717
|
-
parseApexBindArrayAccessor() {
|
|
1718
|
-
this.expect(140 /* L_SQUARE_BRACKET */);
|
|
1719
|
-
const t = this.peek();
|
|
1720
|
-
let val;
|
|
1721
|
-
if (t.kind === 156 /* UNSIGNED_INTEGER */) {
|
|
1722
|
-
val = this.advance().text;
|
|
1723
|
-
} else if (isIdentifierLike(t.kind)) {
|
|
1724
|
-
val = this.advance().text;
|
|
1725
|
-
} else {
|
|
1726
|
-
throw this.error(`Expected integer or identifier in array accessor at position ${t.start}`);
|
|
1727
|
-
}
|
|
1728
|
-
this.expect(141 /* R_SQUARE_BRACKET */);
|
|
1729
|
-
return `[${val}]`;
|
|
1730
|
-
}
|
|
1731
|
-
// ====================================================================
|
|
1732
|
-
// Functions
|
|
1733
|
-
// ====================================================================
|
|
1734
|
-
// Parse any function type, used in SELECT clause function identifier context
|
|
1735
|
-
parseAnyFunction(includeType) {
|
|
1736
|
-
const t = this.peek();
|
|
1737
|
-
if (isDateFunction(t.kind)) return this.parseDateFunction(includeType);
|
|
1738
|
-
if (isAggregateFunction(t.kind)) return this.parseAggregateFunction(includeType);
|
|
1739
|
-
if (t.kind === 68 /* DISTANCE */) return this.parseLocationFunction(includeType);
|
|
1740
|
-
if (isFieldsFunction(t.kind)) return this.parseFieldsFunction(includeType);
|
|
1741
|
-
if (isOtherFunction(t.kind)) return this.parseOtherFunction(includeType);
|
|
1742
|
-
throw this.error(`Expected function name but found ${TokenKind[t.kind]} at position ${t.start}`);
|
|
1743
|
-
}
|
|
1744
|
-
parseDateFunction(includeType) {
|
|
1745
|
-
const fnToken = this.advance();
|
|
1746
|
-
const fnName = tokenTypeName(fnToken.kind);
|
|
1747
|
-
const params = this.parseFunctionExpression(false, includeType);
|
|
1748
|
-
const output = {};
|
|
1749
|
-
if (includeType) {
|
|
1750
|
-
output.type = "FieldFunctionExpression";
|
|
1751
|
-
}
|
|
1752
|
-
output.functionName = fnName;
|
|
1753
|
-
output.parameters = params;
|
|
1754
|
-
if (includeType) {
|
|
1755
|
-
output.isAggregateFn = true;
|
|
1756
|
-
}
|
|
1757
|
-
output.rawValue = `${fnToken.text}(${params.map((p) => typeof p === "string" ? p : p.rawValue).join(", ")})`;
|
|
1758
|
-
return output;
|
|
1759
|
-
}
|
|
1760
|
-
parseAggregateFunction(includeType) {
|
|
1761
|
-
const fnToken = this.advance();
|
|
1762
|
-
const fnName = tokenTypeName(fnToken.kind);
|
|
1763
|
-
const params = this.parseFunctionExpression(true, includeType);
|
|
1764
|
-
const output = {};
|
|
1765
|
-
if (includeType) {
|
|
1766
|
-
output.type = "FieldFunctionExpression";
|
|
1767
|
-
}
|
|
1768
|
-
output.functionName = fnName;
|
|
1769
|
-
output.parameters = params;
|
|
1770
|
-
if (includeType) {
|
|
1771
|
-
output.isAggregateFn = true;
|
|
1772
|
-
}
|
|
1773
|
-
output.rawValue = `${fnToken.text}(${params.map((p) => typeof p === "string" ? p : p.rawValue).join(", ")})`;
|
|
1774
|
-
return output;
|
|
1775
|
-
}
|
|
1776
|
-
parseFieldsFunction(includeType) {
|
|
1777
|
-
this.advance();
|
|
1778
|
-
this.expect(138 /* L_PAREN */);
|
|
1779
|
-
const t = this.peek();
|
|
1780
|
-
let paramText;
|
|
1781
|
-
if (isFieldsFunctionParam(t.kind)) {
|
|
1782
|
-
paramText = this.advance().text;
|
|
1783
|
-
} else if (isIdentifierLike(t.kind)) {
|
|
1784
|
-
paramText = this.advance().text;
|
|
1785
|
-
} else {
|
|
1786
|
-
throw this.error(`Expected FIELDS function parameter at position ${t.start}`);
|
|
1787
|
-
}
|
|
1788
|
-
this.expect(139 /* R_PAREN */);
|
|
1789
|
-
const output = {};
|
|
1790
|
-
if (includeType) {
|
|
1791
|
-
output.type = "FieldFunctionExpression";
|
|
1792
|
-
}
|
|
1793
|
-
output.functionName = "FIELDS";
|
|
1794
|
-
output.parameters = [paramText];
|
|
1795
|
-
output.rawValue = `FIELDS(${paramText})`;
|
|
1796
|
-
return output;
|
|
1797
|
-
}
|
|
1798
|
-
parseOtherFunction(includeType) {
|
|
1799
|
-
const fnToken = this.advance();
|
|
1800
|
-
const fnName = tokenTypeName(fnToken.kind);
|
|
1801
|
-
const params = this.parseFunctionExpression(false, includeType);
|
|
1802
|
-
const output = {};
|
|
1803
|
-
if (includeType) {
|
|
1804
|
-
output.type = "FieldFunctionExpression";
|
|
1805
|
-
}
|
|
1806
|
-
output.functionName = fnName;
|
|
1807
|
-
output.parameters = params;
|
|
1808
|
-
output.rawValue = `${fnToken.text}(${params.map((p) => typeof p === "string" ? p : p.rawValue).join(", ")})`;
|
|
1809
|
-
return output;
|
|
1810
|
-
}
|
|
1811
|
-
parseLocationFunction(includeType) {
|
|
1812
|
-
this.advance();
|
|
1813
|
-
this.expect(138 /* L_PAREN */);
|
|
1814
|
-
const location1 = this.consumeIdentifier().text;
|
|
1815
|
-
this.expect(143 /* COMMA */);
|
|
1816
|
-
let location2;
|
|
1817
|
-
if (this.check(69 /* GEOLOCATION */) && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1818
|
-
location2 = this.parseGeolocationFunction(includeType);
|
|
1819
|
-
} else {
|
|
1820
|
-
location2 = this.consumeIdentifier().text;
|
|
1821
|
-
}
|
|
1822
|
-
this.expect(143 /* COMMA */);
|
|
1823
|
-
const unit = this.expect(158 /* GEOLOCATION_UNIT */).text;
|
|
1824
|
-
this.expect(139 /* R_PAREN */);
|
|
1825
|
-
const output = {};
|
|
1826
|
-
if (includeType) {
|
|
1827
|
-
output.type = "FieldFunctionExpression";
|
|
1828
|
-
}
|
|
1829
|
-
output.functionName = "DISTANCE";
|
|
1830
|
-
output.parameters = [location1, location2, unit];
|
|
1831
|
-
if (includeType) {
|
|
1832
|
-
output.isAggregateFn = true;
|
|
1833
|
-
}
|
|
1834
|
-
const loc2Str = typeof location2 === "string" ? location2 : location2.rawValue;
|
|
1835
|
-
output.rawValue = `DISTANCE(${location1}, ${loc2Str}, ${unit})`;
|
|
1836
|
-
return output;
|
|
1837
|
-
}
|
|
1838
|
-
parseGeolocationFunction(includeType) {
|
|
1839
|
-
this.advance();
|
|
1840
|
-
this.expect(138 /* L_PAREN */);
|
|
1841
|
-
const lat = this.parseNumberValue();
|
|
1842
|
-
this.expect(143 /* COMMA */);
|
|
1843
|
-
const lon = this.parseNumberValue();
|
|
1844
|
-
this.expect(139 /* R_PAREN */);
|
|
1845
|
-
const output = {};
|
|
1846
|
-
if (includeType) {
|
|
1847
|
-
output.type = "FieldFunctionExpression";
|
|
1848
|
-
}
|
|
1849
|
-
output.functionName = "GEOLOCATION";
|
|
1850
|
-
output.parameters = [lat, lon];
|
|
1851
|
-
output.rawValue = `GEOLOCATION(${lat}, ${lon})`;
|
|
1852
|
-
return output;
|
|
1853
|
-
}
|
|
1854
|
-
parseNumberValue() {
|
|
1855
|
-
const t = this.peek();
|
|
1856
|
-
if (t.kind === 156 /* UNSIGNED_INTEGER */ || t.kind === 155 /* SIGNED_INTEGER */ || t.kind === 154 /* UNSIGNED_DECIMAL */ || t.kind === 153 /* SIGNED_DECIMAL */) {
|
|
1857
|
-
return this.advance().text;
|
|
1858
|
-
}
|
|
1859
|
-
throw this.error(`Expected number but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
1860
|
-
}
|
|
1861
|
-
parseFunctionExpression(skipAggregate, includeType = true) {
|
|
1862
|
-
this.expect(138 /* L_PAREN */);
|
|
1863
|
-
const params = [];
|
|
1864
|
-
if (!this.check(139 /* R_PAREN */)) {
|
|
1865
|
-
params.push(this.parseFunctionParam(skipAggregate, includeType));
|
|
1866
|
-
while (this.match(143 /* COMMA */)) {
|
|
1867
|
-
params.push(this.parseFunctionParam(skipAggregate, includeType));
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
this.expect(139 /* R_PAREN */);
|
|
1871
|
-
return params;
|
|
1872
|
-
}
|
|
1873
|
-
parseFunctionParam(skipAggregate, includeType) {
|
|
1874
|
-
const t = this.peek();
|
|
1875
|
-
const next = this.peekAt(1);
|
|
1876
|
-
if (!skipAggregate && isAggregateFunction(t.kind) && next.kind === 138 /* L_PAREN */) {
|
|
1877
|
-
return this.parseAggregateFunction(includeType);
|
|
1878
|
-
}
|
|
1879
|
-
if (isOtherFunction(t.kind) && next.kind === 138 /* L_PAREN */) {
|
|
1880
|
-
return this.parseOtherFunction(includeType);
|
|
1881
|
-
}
|
|
1882
|
-
if (t.kind === 157 /* STRING_LITERAL */) {
|
|
1883
|
-
return this.advance().text;
|
|
1884
|
-
}
|
|
1885
|
-
if (isNumberLiteral(t.kind)) {
|
|
1886
|
-
return this.advance().text;
|
|
1887
|
-
}
|
|
1888
|
-
if (isIdentifierLike(t.kind)) {
|
|
1889
|
-
return this.advance().text;
|
|
1890
|
-
}
|
|
1891
|
-
throw this.error(`Expected function parameter but found ${TokenKind[t.kind]} ("${t.text}") at position ${t.start}`);
|
|
1892
|
-
}
|
|
1893
|
-
// ====================================================================
|
|
1894
|
-
// GROUP BY Clause
|
|
1895
|
-
// ====================================================================
|
|
1896
|
-
parseGroupByClause() {
|
|
1897
|
-
this.expect(10 /* GROUP_BY */);
|
|
1898
|
-
const groups = [];
|
|
1899
|
-
groups.push(this.parseGroupByItem());
|
|
1900
|
-
while (this.match(143 /* COMMA */)) {
|
|
1901
|
-
groups.push(this.parseGroupByItem());
|
|
1902
|
-
}
|
|
1903
|
-
return groups;
|
|
1904
|
-
}
|
|
1905
|
-
parseGroupByItem() {
|
|
1906
|
-
const t = this.peek();
|
|
1907
|
-
if (t.kind === 4 /* CUBE */ && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1908
|
-
return { fn: this.parseCubeOrRollupFunction("CUBE") };
|
|
1909
|
-
}
|
|
1910
|
-
if (t.kind === 22 /* ROLLUP */ && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1911
|
-
return { fn: this.parseCubeOrRollupFunction("ROLLUP") };
|
|
1912
|
-
}
|
|
1913
|
-
if (isDateFunction(t.kind) && this.peekAt(1).kind === 138 /* L_PAREN */) {
|
|
1914
|
-
return { fn: this.parseDateFunction(false) };
|
|
1915
|
-
}
|
|
1916
|
-
return { field: this.consumeIdentifier().text };
|
|
1917
|
-
}
|
|
1918
|
-
parseCubeOrRollupFunction(name) {
|
|
1919
|
-
const fnToken = this.advance();
|
|
1920
|
-
const params = this.parseFunctionExpression(false);
|
|
1921
|
-
return {
|
|
1922
|
-
functionName: name,
|
|
1923
|
-
parameters: params,
|
|
1924
|
-
rawValue: `${name}(${params.join(", ")})`
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
// ====================================================================
|
|
1928
|
-
// HAVING Clause
|
|
1929
|
-
// ====================================================================
|
|
1930
|
-
parseHavingClause() {
|
|
1931
|
-
this.expect(11 /* HAVING */);
|
|
1932
|
-
return this.parseConditionExpressions(true, false);
|
|
1933
|
-
}
|
|
1934
|
-
// ====================================================================
|
|
1935
|
-
// ORDER BY Clause
|
|
1936
|
-
// ====================================================================
|
|
1937
|
-
parseOrderByClause() {
|
|
1938
|
-
this.expect(21 /* ORDER_BY */);
|
|
1939
|
-
const items = [];
|
|
1940
|
-
items.push(this.parseOrderByItem());
|
|
1941
|
-
while (this.match(143 /* COMMA */)) {
|
|
1942
|
-
items.push(this.parseOrderByItem());
|
|
1943
|
-
}
|
|
1944
|
-
return items;
|
|
1945
|
-
}
|
|
1946
|
-
parseOrderByItem() {
|
|
1947
|
-
const t = this.peek();
|
|
1948
|
-
const next = this.peekAt(1);
|
|
1949
|
-
let clause;
|
|
1950
|
-
if (t.kind === 75 /* GROUPING */ && next.kind === 138 /* L_PAREN */) {
|
|
1951
|
-
const fnToken = this.advance();
|
|
1952
|
-
const params = this.parseFunctionExpression(false);
|
|
1953
|
-
clause = {
|
|
1954
|
-
fn: {
|
|
1955
|
-
functionName: tokenTypeName(fnToken.kind),
|
|
1956
|
-
parameters: params,
|
|
1957
|
-
rawValue: `${fnToken.text}(${params.join(", ")})`
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
} else if (isAggregateFunction(t.kind) && next.kind === 138 /* L_PAREN */) {
|
|
1961
|
-
clause = { fn: this.parseAggregateFunction(false) };
|
|
1962
|
-
} else if (isDateFunction(t.kind) && next.kind === 138 /* L_PAREN */) {
|
|
1963
|
-
clause = { fn: this.parseDateFunction(false) };
|
|
1964
|
-
} else if (t.kind === 68 /* DISTANCE */ && next.kind === 138 /* L_PAREN */) {
|
|
1965
|
-
clause = { fn: this.parseLocationFunction(false) };
|
|
1966
|
-
} else {
|
|
1967
|
-
clause = { field: this.consumeIdentifier().text };
|
|
1968
|
-
}
|
|
1969
|
-
if (this.check(2 /* ASC */)) {
|
|
1970
|
-
clause.order = tokenTypeName(this.advance().kind);
|
|
1971
|
-
} else if (this.check(3 /* DESC */)) {
|
|
1972
|
-
clause.order = tokenTypeName(this.advance().kind);
|
|
1973
|
-
}
|
|
1974
|
-
if (this.check(19 /* NULLS */)) {
|
|
1975
|
-
this.advance();
|
|
1976
|
-
if (this.check(8 /* FIRST */)) {
|
|
1977
|
-
clause.nulls = tokenTypeName(this.advance().kind);
|
|
1978
|
-
} else if (this.check(14 /* LAST */)) {
|
|
1979
|
-
clause.nulls = tokenTypeName(this.advance().kind);
|
|
1980
|
-
} else {
|
|
1981
|
-
throw this.error(`Expected FIRST or LAST after NULLS at position ${this.peek().start}`);
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
return clause;
|
|
1985
|
-
}
|
|
1986
|
-
// ====================================================================
|
|
1987
|
-
// WITH Clause
|
|
1988
|
-
// ====================================================================
|
|
1989
|
-
parseWithClause() {
|
|
1990
|
-
this.expect(27 /* WITH */);
|
|
1991
|
-
const t = this.peek();
|
|
1992
|
-
if (t.kind === 46 /* SECURITY_ENFORCED */) {
|
|
1993
|
-
this.advance();
|
|
1994
|
-
return { withSecurityEnforced: true };
|
|
1995
|
-
}
|
|
1996
|
-
if (t.kind === 48 /* USER_MODE */) {
|
|
1997
|
-
this.advance();
|
|
1998
|
-
return { withAccessLevel: "USER_MODE" };
|
|
1999
|
-
}
|
|
2000
|
-
if (t.kind === 47 /* SYSTEM_MODE */) {
|
|
2001
|
-
this.advance();
|
|
2002
|
-
return { withAccessLevel: "SYSTEM_MODE" };
|
|
2003
|
-
}
|
|
2004
|
-
if (t.kind === 35 /* DATA_CATEGORY */) {
|
|
2005
|
-
return { withDataCategory: this.parseWithDataCategory() };
|
|
2006
|
-
}
|
|
2007
|
-
throw this.error(`Expected SECURITY_ENFORCED, USER_MODE, SYSTEM_MODE, or DATA CATEGORY after WITH at position ${t.start}`);
|
|
2008
|
-
}
|
|
2009
|
-
parseWithDataCategory() {
|
|
2010
|
-
this.expect(35 /* DATA_CATEGORY */);
|
|
2011
|
-
const conditions = [];
|
|
2012
|
-
conditions.push(this.parseDataCategoryCondition());
|
|
2013
|
-
while (this.check(0 /* AND */)) {
|
|
2014
|
-
this.advance();
|
|
2015
|
-
conditions.push(this.parseDataCategoryCondition());
|
|
2016
|
-
}
|
|
2017
|
-
return { conditions };
|
|
2018
|
-
}
|
|
2019
|
-
parseDataCategoryCondition() {
|
|
2020
|
-
const groupName = this.consumeIdentifier().text;
|
|
2021
|
-
const t = this.peek();
|
|
2022
|
-
let selector;
|
|
2023
|
-
if (t.kind === 33 /* AT */ || t.kind === 30 /* ABOVE */ || t.kind === 34 /* BELOW */ || t.kind === 31 /* ABOVE_OR_BELOW */) {
|
|
2024
|
-
selector = this.advance().text;
|
|
2025
|
-
} else {
|
|
2026
|
-
throw this.error(`Expected data category selector (AT, ABOVE, BELOW, ABOVE_OR_BELOW) at position ${t.start}`);
|
|
2027
|
-
}
|
|
2028
|
-
const hasParen = this.match(138 /* L_PAREN */);
|
|
2029
|
-
const parameters = [];
|
|
2030
|
-
parameters.push(this.consumeIdentifier().text);
|
|
2031
|
-
while (this.match(143 /* COMMA */)) {
|
|
2032
|
-
parameters.push(this.consumeIdentifier().text);
|
|
2033
|
-
}
|
|
2034
|
-
if (hasParen) {
|
|
2035
|
-
this.expect(139 /* R_PAREN */);
|
|
2036
|
-
}
|
|
2037
|
-
return { groupName, selector, parameters };
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
function parseQuery(soql, options) {
|
|
2041
|
-
const config = options || {};
|
|
2042
|
-
const tokens = tokenize(soql);
|
|
2043
|
-
const parser = new SoqlParser(tokens, config);
|
|
2044
|
-
let query;
|
|
2045
|
-
if (config.allowPartialQuery) {
|
|
2046
|
-
query = parser.parseSelectStatementPartial();
|
|
2047
|
-
} else {
|
|
2048
|
-
query = parser.parseSelectStatement(false);
|
|
2049
|
-
}
|
|
2050
|
-
if (!parser.isAtEnd() && !config.ignoreParseErrors) {
|
|
2051
|
-
const remaining = tokens[parser.getPos()];
|
|
2052
|
-
throw new Error(`Unexpected token "${remaining.text}" at position ${remaining.start}. Expected end of query.`);
|
|
2053
|
-
}
|
|
2054
|
-
return query;
|
|
2055
|
-
}
|
|
2056
|
-
function isQueryValid(soql, options) {
|
|
2057
|
-
try {
|
|
2058
|
-
parseQuery(soql, options);
|
|
2059
|
-
return true;
|
|
2060
|
-
} catch (e) {
|
|
2061
|
-
return false;
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
// src/utils.ts
|
|
2066
|
-
function isString(val) {
|
|
2067
|
-
return typeof val === "string";
|
|
2068
|
-
}
|
|
2069
|
-
function isStringArray(val) {
|
|
2070
|
-
if (!val) {
|
|
2071
|
-
return false;
|
|
2072
|
-
}
|
|
2073
|
-
return val.every((item) => isString(item));
|
|
2074
|
-
}
|
|
2075
|
-
function isNumber(val) {
|
|
2076
|
-
return Number.isFinite(val);
|
|
2077
|
-
}
|
|
2078
|
-
function isNil(val) {
|
|
2079
|
-
return val === null || val === void 0;
|
|
2080
|
-
}
|
|
2081
|
-
function get(val, suffix, prefix) {
|
|
2082
|
-
return isNil(val) ? "" : `${prefix || ""}${val}${suffix || ""}`;
|
|
2083
|
-
}
|
|
2084
|
-
function getAsArrayStr(val, alwaysParens = false) {
|
|
2085
|
-
if (Array.isArray(val)) {
|
|
2086
|
-
if (val.length > 0) {
|
|
2087
|
-
return `(${val.join(", ")})`;
|
|
2088
|
-
} else {
|
|
2089
|
-
return alwaysParens ? "()" : "";
|
|
2090
|
-
}
|
|
2091
|
-
} else {
|
|
2092
|
-
return alwaysParens ? `(${val || ""})` : val || "";
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
function generateParens(count, character, joinCharacter = "") {
|
|
2096
|
-
return isNumber(count) && count > 0 ? new Array(count).fill(character).join(joinCharacter) : "";
|
|
2097
|
-
}
|
|
2098
|
-
function getParams(functionFieldExp) {
|
|
2099
|
-
if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
|
|
2100
|
-
return [];
|
|
2101
|
-
}
|
|
2102
|
-
if (isStringArray(functionFieldExp.parameters)) {
|
|
2103
|
-
return functionFieldExp.parameters;
|
|
2104
|
-
}
|
|
2105
|
-
if (isString(functionFieldExp.parameters[0])) {
|
|
2106
|
-
return [functionFieldExp.parameters[0]];
|
|
2107
|
-
}
|
|
2108
|
-
return getParams(functionFieldExp.parameters[0]);
|
|
2109
|
-
}
|
|
2110
|
-
function isNestedParamAggregateFunction(functionFieldExp) {
|
|
2111
|
-
if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
|
|
2112
|
-
return false;
|
|
2113
|
-
}
|
|
2114
|
-
const parameter = functionFieldExp.parameters[0];
|
|
2115
|
-
if (isString(parameter)) {
|
|
2116
|
-
return false;
|
|
2117
|
-
}
|
|
2118
|
-
return !!parameter.isAggregateFn;
|
|
2119
|
-
}
|
|
2120
|
-
function hasAlias(value) {
|
|
2121
|
-
return value && !isNil(value.alias);
|
|
2122
|
-
}
|
|
2123
|
-
function isComposeField(input) {
|
|
2124
|
-
return isString(input.field) && !Array.isArray(input.relationships) && !Array.isArray(input.conditions);
|
|
2125
|
-
}
|
|
2126
|
-
function isComposeFieldFunction(input) {
|
|
2127
|
-
return !isNil(input.functionName || input.fn);
|
|
2128
|
-
}
|
|
2129
|
-
function isComposeFieldRelationship(input) {
|
|
2130
|
-
return isString(input.field) && Array.isArray(input.relationships);
|
|
2131
|
-
}
|
|
2132
|
-
function isComposeFieldSubquery(input) {
|
|
2133
|
-
return !isNil(input.subquery);
|
|
2134
|
-
}
|
|
2135
|
-
function isComposeFieldTypeof(input) {
|
|
2136
|
-
return isString(input.field) && Array.isArray(input.conditions);
|
|
2137
|
-
}
|
|
2138
|
-
function isSubquery(query) {
|
|
2139
|
-
return isString(query.relationshipName);
|
|
2140
|
-
}
|
|
2141
|
-
function isFieldSubquery(value) {
|
|
2142
|
-
return !!value && !!value.type && value.type === "FieldSubquery";
|
|
2143
|
-
}
|
|
2144
|
-
function isWhereClauseWithRightCondition(value) {
|
|
2145
|
-
return !!value && !!value.operator && !!value.right;
|
|
2146
|
-
}
|
|
2147
|
-
function isHavingClauseWithRightCondition(value) {
|
|
2148
|
-
return !!value && !!value.operator && !!value.right;
|
|
2149
|
-
}
|
|
2150
|
-
function isWhereOrHavingClauseWithRightCondition(value) {
|
|
2151
|
-
return !!value && !!value.operator && !!value.right;
|
|
2152
|
-
}
|
|
2153
|
-
function isValueCondition(value) {
|
|
2154
|
-
return value && isString(value.field) && isString(value.operator) && !isNil(value.value);
|
|
2155
|
-
}
|
|
2156
|
-
function isValueWithDateLiteralCondition(value) {
|
|
2157
|
-
return value && isString(value.field) && isString(value.operator) && !isNil(value.value) && (value.literalType === "DATE_LITERAL" || Array.isArray(value.literalType) && value.literalType[0] === "DATE_LITERAL");
|
|
2158
|
-
}
|
|
2159
|
-
function isValueWithDateNLiteralCondition(value) {
|
|
2160
|
-
return value && isString(value.field) && isString(value.operator) && !isNil(value.value) && !isNil(value.dateLiteralVariable);
|
|
2161
|
-
}
|
|
2162
|
-
function isValueFunctionCondition(value) {
|
|
2163
|
-
return value && !isNil(value.fn) && isString(value.operator) && !isNil(value.value);
|
|
2164
|
-
}
|
|
2165
|
-
function isNegationCondition(value) {
|
|
2166
|
-
return value && isNumber(value.openParen) && isNil(value.operator) && isNil(value.field) && isNil(value.fn) && isNil(value.closeParen);
|
|
2167
|
-
}
|
|
2168
|
-
function isValueQueryCondition(value) {
|
|
2169
|
-
return value && isString(value.field) && isString(value.operator) && !isNil(value.valueQuery) && isNil(value.value);
|
|
2170
|
-
}
|
|
2171
|
-
function isOrderByField(value) {
|
|
2172
|
-
return value && !isNil(value.field);
|
|
2173
|
-
}
|
|
2174
|
-
function isOrderByFn(value) {
|
|
2175
|
-
return value && !isNil(value.fn);
|
|
2176
|
-
}
|
|
2177
|
-
function isGroupByField(value) {
|
|
2178
|
-
return value && !isNil(value.field);
|
|
2179
|
-
}
|
|
2180
|
-
function isGroupByFn(value) {
|
|
2181
|
-
return value && !isNil(value.fn);
|
|
2182
|
-
}
|
|
2183
|
-
function isArrayOperator(operator) {
|
|
2184
|
-
return ["IN", "NOT IN", "INCLUDES", "EXCLUDES"].includes(operator);
|
|
2185
|
-
}
|
|
2186
|
-
function getWhereValue(value, literalType, operator) {
|
|
2187
|
-
if (isNil(literalType)) {
|
|
2188
|
-
return value;
|
|
2189
|
-
}
|
|
2190
|
-
if (operator && literalType !== "APEX_BIND_VARIABLE" && isArrayOperator(operator) && !Array.isArray(value)) {
|
|
2191
|
-
value = [value];
|
|
2192
|
-
literalType = Array.isArray(literalType) ? literalType : [literalType];
|
|
2193
|
-
}
|
|
2194
|
-
if (Array.isArray(literalType) && Array.isArray(value)) {
|
|
2195
|
-
return value.map((val, i) => {
|
|
2196
|
-
return whereValueHelper(val, literalType?.[i]);
|
|
2197
|
-
});
|
|
2198
|
-
} else {
|
|
2199
|
-
if (Array.isArray(literalType)) {
|
|
2200
|
-
literalType = literalType[0];
|
|
2201
|
-
}
|
|
2202
|
-
switch (literalType) {
|
|
2203
|
-
case "STRING": {
|
|
2204
|
-
if (Array.isArray(value)) {
|
|
2205
|
-
return value.filter(Boolean).map((val) => isString(val) && val.startsWith("'") ? val : `'${val ?? ""}'`);
|
|
2206
|
-
} else {
|
|
2207
|
-
value = String(value ?? "");
|
|
2208
|
-
return isString(value) && value.startsWith("'") ? value : `'${value ?? ""}'`;
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
case "APEX_BIND_VARIABLE": {
|
|
2212
|
-
return `:${value}`;
|
|
2213
|
-
}
|
|
2214
|
-
default: {
|
|
2215
|
-
return value;
|
|
2216
|
-
}
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
function whereValueHelper(value, literalType) {
|
|
2221
|
-
switch (literalType) {
|
|
2222
|
-
case "STRING": {
|
|
2223
|
-
return isString(value) && value.startsWith("'") ? value : `'${value ?? ""}'`;
|
|
2224
|
-
}
|
|
2225
|
-
case "NULL": {
|
|
2226
|
-
return "null";
|
|
2227
|
-
}
|
|
2228
|
-
default: {
|
|
2229
|
-
return value;
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
|
|
2234
|
-
// src/api/public-utils.ts
|
|
2235
|
-
function getComposedField(input) {
|
|
2236
|
-
return getField(input);
|
|
2237
|
-
}
|
|
2238
|
-
function getField(input) {
|
|
2239
|
-
if (typeof input === "string") {
|
|
2240
|
-
return {
|
|
2241
|
-
type: "Field",
|
|
2242
|
-
field: input
|
|
2243
|
-
};
|
|
2244
|
-
} else if (isComposeFieldFunction(input)) {
|
|
2245
|
-
let parameters = [];
|
|
2246
|
-
if (input.parameters) {
|
|
2247
|
-
parameters = Array.isArray(input.parameters) ? input.parameters : [input.parameters];
|
|
2248
|
-
}
|
|
2249
|
-
return {
|
|
2250
|
-
type: "FieldFunctionExpression",
|
|
2251
|
-
functionName: input.functionName || input.fn,
|
|
2252
|
-
parameters,
|
|
2253
|
-
alias: input.alias
|
|
2254
|
-
};
|
|
2255
|
-
} else if (isComposeFieldRelationship(input)) {
|
|
2256
|
-
return {
|
|
2257
|
-
type: "FieldRelationship",
|
|
2258
|
-
field: input.field,
|
|
2259
|
-
relationships: input.relationships,
|
|
2260
|
-
objectPrefix: input.objectPrefix
|
|
2261
|
-
};
|
|
2262
|
-
} else if (isComposeFieldSubquery(input)) {
|
|
2263
|
-
return {
|
|
2264
|
-
type: "FieldSubquery",
|
|
2265
|
-
subquery: input.subquery
|
|
2266
|
-
};
|
|
2267
|
-
} else if (isComposeFieldTypeof(input)) {
|
|
2268
|
-
return {
|
|
2269
|
-
type: "FieldTypeof",
|
|
2270
|
-
field: input.field,
|
|
2271
|
-
conditions: input.conditions
|
|
2272
|
-
};
|
|
2273
|
-
} else if (isComposeField(input)) {
|
|
2274
|
-
return {
|
|
2275
|
-
type: "Field",
|
|
2276
|
-
field: input.field,
|
|
2277
|
-
objectPrefix: input.objectPrefix
|
|
2278
|
-
};
|
|
2279
|
-
} else {
|
|
2280
|
-
throw new TypeError("The input object provided did not match any valid field types");
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
function getFlattenedFields(query, isAggregateResult) {
|
|
2284
|
-
if (!query) {
|
|
2285
|
-
return [];
|
|
2286
|
-
}
|
|
2287
|
-
query = isFieldSubquery(query) ? query.subquery : query;
|
|
2288
|
-
const fields = query.fields;
|
|
2289
|
-
if (!fields) {
|
|
2290
|
-
return [];
|
|
2291
|
-
}
|
|
2292
|
-
let groupByFields = {};
|
|
2293
|
-
if (!!query.groupBy) {
|
|
2294
|
-
groupByFields = (Array.isArray(query.groupBy) ? query.groupBy : [query.groupBy]).reduce(
|
|
2295
|
-
(output, clause) => {
|
|
2296
|
-
if (isGroupByField(clause)) {
|
|
2297
|
-
output[clause.field.toLocaleLowerCase()] = clause.field;
|
|
2298
|
-
}
|
|
2299
|
-
return output;
|
|
2300
|
-
},
|
|
2301
|
-
{}
|
|
2302
|
-
);
|
|
2303
|
-
}
|
|
2304
|
-
let currUnAliasedAggExp = -1;
|
|
2305
|
-
let sObject = (isSubquery(query) ? query.relationshipName : query.sObject || "").toLowerCase();
|
|
2306
|
-
let sObjectAlias = (query.sObjectAlias || "").toLowerCase();
|
|
2307
|
-
const parsedFields = fields.flatMap((field) => {
|
|
2308
|
-
switch (field.type) {
|
|
2309
|
-
case "Field": {
|
|
2310
|
-
return field.alias || field.field;
|
|
2311
|
-
}
|
|
2312
|
-
case "FieldFunctionExpression": {
|
|
2313
|
-
let params = getParams(field);
|
|
2314
|
-
params = params.map((param) => {
|
|
2315
|
-
if (param.includes(".")) {
|
|
2316
|
-
let tempParams = param.split(".");
|
|
2317
|
-
const firstParam = tempParams[0].toLowerCase();
|
|
2318
|
-
if (firstParam === sObjectAlias || firstParam === sObject) {
|
|
2319
|
-
tempParams = tempParams.slice(1);
|
|
2320
|
-
}
|
|
2321
|
-
return tempParams.join(".");
|
|
2322
|
-
}
|
|
2323
|
-
return param;
|
|
2324
|
-
});
|
|
2325
|
-
if (field.alias && (field.isAggregateFn || isAggregateResult)) {
|
|
2326
|
-
return field.alias;
|
|
2327
|
-
}
|
|
2328
|
-
if (field.alias) {
|
|
2329
|
-
const firstParam = params[0];
|
|
2330
|
-
if (firstParam.includes(".")) {
|
|
2331
|
-
params = firstParam.split(".").slice(0, -1);
|
|
2332
|
-
params.push(field.alias);
|
|
2333
|
-
return params.join(".");
|
|
2334
|
-
}
|
|
2335
|
-
return field.alias;
|
|
2336
|
-
}
|
|
2337
|
-
if (field.isAggregateFn || isNestedParamAggregateFunction(field) || isAggregateResult) {
|
|
2338
|
-
currUnAliasedAggExp++;
|
|
2339
|
-
return `expr${currUnAliasedAggExp}`;
|
|
2340
|
-
}
|
|
2341
|
-
if (params.length > 0) {
|
|
2342
|
-
return params.join(".");
|
|
2343
|
-
}
|
|
2344
|
-
return field.functionName;
|
|
2345
|
-
}
|
|
2346
|
-
case "FieldRelationship": {
|
|
2347
|
-
const firstRelationship = field.relationships[0].toLowerCase();
|
|
2348
|
-
if (hasAlias(field)) {
|
|
2349
|
-
return field.alias;
|
|
2350
|
-
}
|
|
2351
|
-
if (field.rawValue && groupByFields[field.rawValue.toLocaleLowerCase()]) {
|
|
2352
|
-
return field.field;
|
|
2353
|
-
}
|
|
2354
|
-
if (firstRelationship === sObjectAlias || firstRelationship === sObject) {
|
|
2355
|
-
return field.relationships.concat([field.field]).slice(1).join(".");
|
|
2356
|
-
}
|
|
2357
|
-
return field.relationships.concat([field.field]).join(".");
|
|
2358
|
-
}
|
|
2359
|
-
case "FieldSubquery": {
|
|
2360
|
-
return field.subquery.relationshipName;
|
|
2361
|
-
}
|
|
2362
|
-
case "FieldTypeof": {
|
|
2363
|
-
const priorFields = /* @__PURE__ */ new Set();
|
|
2364
|
-
const fields2 = [];
|
|
2365
|
-
field.conditions.forEach((condition) => {
|
|
2366
|
-
condition.fieldList.forEach((currField) => {
|
|
2367
|
-
if (!priorFields.has(currField)) {
|
|
2368
|
-
priorFields.add(currField);
|
|
2369
|
-
fields2.push(`${field.field}.${currField}`);
|
|
2370
|
-
}
|
|
2371
|
-
});
|
|
2372
|
-
});
|
|
2373
|
-
return fields2;
|
|
2374
|
-
}
|
|
2375
|
-
default:
|
|
2376
|
-
break;
|
|
2377
|
-
}
|
|
2378
|
-
}).filter((field) => isString(field));
|
|
2379
|
-
return parsedFields;
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
// src/formatter/formatter.ts
|
|
2383
|
-
var Formatter = class {
|
|
2384
|
-
constructor(enabled, options) {
|
|
2385
|
-
this.currIndent = 1;
|
|
2386
|
-
this.enabled = enabled;
|
|
2387
|
-
this.options = {
|
|
2388
|
-
numIndent: options.numIndent ?? 1,
|
|
2389
|
-
fieldMaxLineLength: options.fieldMaxLineLength ?? 60,
|
|
2390
|
-
fieldSubqueryParensOnOwnLine: options.fieldSubqueryParensOnOwnLine ?? true,
|
|
2391
|
-
whereClauseOperatorsIndented: true,
|
|
2392
|
-
newLineAfterKeywords: options.newLineAfterKeywords ?? false,
|
|
2393
|
-
logging: options.logging ?? false
|
|
2394
|
-
};
|
|
2395
|
-
if (this.options.newLineAfterKeywords) {
|
|
2396
|
-
this.options.fieldSubqueryParensOnOwnLine = true;
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
log(data) {
|
|
2400
|
-
if (this.options.logging) {
|
|
2401
|
-
console.log(data);
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
getIndent(additionalIndent = 0) {
|
|
2405
|
-
return this.repeatChar((this.currIndent + additionalIndent) * (this.options.numIndent || 1), " ");
|
|
2406
|
-
}
|
|
2407
|
-
repeatChar(numTimes, char) {
|
|
2408
|
-
return new Array(numTimes).fill(char).join("");
|
|
2409
|
-
}
|
|
2410
|
-
setSubquery(isSubquery2) {
|
|
2411
|
-
this.currIndent = isSubquery2 ? this.currIndent += 1 : this.currIndent -= 1;
|
|
2412
|
-
}
|
|
2413
|
-
stepCurrIndex(num) {
|
|
2414
|
-
this.currIndent += num;
|
|
2415
|
-
}
|
|
2416
|
-
/**
|
|
2417
|
-
* Format fields
|
|
2418
|
-
* @param fieldData
|
|
2419
|
-
*/
|
|
2420
|
-
formatFields(fieldData) {
|
|
2421
|
-
function trimPrevSuffix(currIdx) {
|
|
2422
|
-
if (fieldData.fields[currIdx - 1]) {
|
|
2423
|
-
fieldData.fields[currIdx - 1].suffix = fieldData.fields[currIdx - 1].suffix.trim();
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
fieldData.fields.forEach((field, i) => {
|
|
2427
|
-
field.suffix = fieldData.fields.length - 1 === i ? "" : ", ";
|
|
2428
|
-
});
|
|
2429
|
-
if (this.enabled) {
|
|
2430
|
-
let lineLen = 0;
|
|
2431
|
-
let newLineAndIndentNext = false;
|
|
2432
|
-
fieldData.fields.forEach((field, i) => {
|
|
2433
|
-
if (field.isSubquery) {
|
|
2434
|
-
trimPrevSuffix(i);
|
|
2435
|
-
field.prefix = `
|
|
2436
|
-
${this.getIndent()}`;
|
|
2437
|
-
field.suffix = fieldData.fields.length - 1 === i ? "" : ", ";
|
|
2438
|
-
lineLen = 0;
|
|
2439
|
-
newLineAndIndentNext = true;
|
|
2440
|
-
} else if (Array.isArray(field.typeOfClause)) {
|
|
2441
|
-
trimPrevSuffix(i);
|
|
2442
|
-
field.prefix = `
|
|
2443
|
-
${this.getIndent()}`;
|
|
2444
|
-
newLineAndIndentNext = true;
|
|
2445
|
-
} else if (isNumber(this.options.fieldMaxLineLength)) {
|
|
2446
|
-
lineLen += field.text.length + field.suffix.length;
|
|
2447
|
-
if (lineLen > this.options.fieldMaxLineLength || newLineAndIndentNext) {
|
|
2448
|
-
trimPrevSuffix(i);
|
|
2449
|
-
if (!this.options.newLineAfterKeywords || i > 0) {
|
|
2450
|
-
field.prefix += `
|
|
2451
|
-
${this.getIndent()}`;
|
|
2452
|
-
}
|
|
2453
|
-
lineLen = 0;
|
|
2454
|
-
newLineAndIndentNext = false;
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
this.log(field);
|
|
2458
|
-
});
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
formatTyeOfField(text, typeOfClause) {
|
|
2462
|
-
if (this.enabled && this.options.newLineAfterKeywords) {
|
|
2463
|
-
return typeOfClause.map((part, i) => {
|
|
2464
|
-
if (i === 0) {
|
|
2465
|
-
return part;
|
|
2466
|
-
} else if (i === typeOfClause.length - 1) {
|
|
2467
|
-
return `${this.getIndent()}${part}`;
|
|
2468
|
-
} else {
|
|
2469
|
-
return `${this.getIndent()} ${part}`;
|
|
2470
|
-
}
|
|
2471
|
-
}).join("\n");
|
|
2472
|
-
}
|
|
2473
|
-
return text;
|
|
2474
|
-
}
|
|
2475
|
-
formatTypeofFieldCondition(condition) {
|
|
2476
|
-
let output = "";
|
|
2477
|
-
const fields = condition.fieldList.join(", ");
|
|
2478
|
-
if (this.enabled && this.options.newLineAfterKeywords) {
|
|
2479
|
-
const indent = this.getIndent();
|
|
2480
|
-
output = `${condition.type}`;
|
|
2481
|
-
if (condition.objectType) {
|
|
2482
|
-
output += `
|
|
2483
|
-
${indent} ${condition.objectType}
|
|
2484
|
-
${indent} THEN
|
|
2485
|
-
${indent} ${fields}`;
|
|
2486
|
-
} else {
|
|
2487
|
-
output += `
|
|
2488
|
-
${indent} ${fields}`;
|
|
2489
|
-
}
|
|
2490
|
-
} else {
|
|
2491
|
-
output = condition.type;
|
|
2492
|
-
if (condition.objectType) {
|
|
2493
|
-
output += ` ${condition.objectType} THEN ${fields}`;
|
|
2494
|
-
} else {
|
|
2495
|
-
output += ` ${fields}`;
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
return output;
|
|
2499
|
-
}
|
|
2500
|
-
/**
|
|
2501
|
-
* Formats subquery with additional indents
|
|
2502
|
-
*/
|
|
2503
|
-
formatSubquery(queryStr, numTabs = 2, incrementTabsWhereClauseOpIndent = false) {
|
|
2504
|
-
if (incrementTabsWhereClauseOpIndent) {
|
|
2505
|
-
numTabs++;
|
|
2506
|
-
}
|
|
2507
|
-
let leftParen = "(";
|
|
2508
|
-
let rightParen = ")";
|
|
2509
|
-
if (this.enabled) {
|
|
2510
|
-
if (this.options.fieldSubqueryParensOnOwnLine || this.options.newLineAfterKeywords) {
|
|
2511
|
-
queryStr = queryStr.replace(/\n/g, `
|
|
2512
|
-
${this.repeatChar(numTabs, " ")}`);
|
|
2513
|
-
leftParen = `(
|
|
2514
|
-
${this.repeatChar(numTabs, " ")}`;
|
|
2515
|
-
rightParen = `
|
|
2516
|
-
${this.repeatChar(numTabs - 1, " ")})`;
|
|
2517
|
-
} else {
|
|
2518
|
-
queryStr = queryStr.replace(/\n/g, "\n ");
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
return `${leftParen}${queryStr}${rightParen}`;
|
|
2522
|
-
}
|
|
2523
|
-
/**
|
|
2524
|
-
* Formats all clauses that do not have a more specialized format function
|
|
2525
|
-
* If formatting is enabled, then this will put a new line before the clause
|
|
2526
|
-
* @param clause
|
|
2527
|
-
* @returns clause
|
|
2528
|
-
*/
|
|
2529
|
-
formatClause(clause) {
|
|
2530
|
-
if (this.enabled) {
|
|
2531
|
-
return this.options.newLineAfterKeywords ? `
|
|
2532
|
-
${clause}
|
|
2533
|
-
${this.getIndent()}` : `
|
|
2534
|
-
${clause}`;
|
|
2535
|
-
}
|
|
2536
|
-
return ` ${clause}`;
|
|
2537
|
-
}
|
|
2538
|
-
/**
|
|
2539
|
-
* If newLineAfterKeywords is true, then no preceding space will be added
|
|
2540
|
-
* This is called after clauses
|
|
2541
|
-
* @param text
|
|
2542
|
-
* @returns text
|
|
2543
|
-
*/
|
|
2544
|
-
formatText(text) {
|
|
2545
|
-
return this.enabled && (this.options.newLineAfterKeywords || text.startsWith("\n")) ? text : ` ${text}`;
|
|
2546
|
-
}
|
|
2547
|
-
formatWithIndent(text) {
|
|
2548
|
-
return this.enabled ? `${this.getIndent()}${text}` : text;
|
|
2549
|
-
}
|
|
2550
|
-
formatOrderByArray(groupBy) {
|
|
2551
|
-
if (this.enabled) {
|
|
2552
|
-
let currLen = 0;
|
|
2553
|
-
let output = "";
|
|
2554
|
-
groupBy.forEach((token, i) => {
|
|
2555
|
-
const nextToken = groupBy[i + 1];
|
|
2556
|
-
currLen += token.length;
|
|
2557
|
-
if (nextToken && (currLen + nextToken.length > (this.options.fieldMaxLineLength || 0) || this.options.newLineAfterKeywords)) {
|
|
2558
|
-
output += `${token},
|
|
2559
|
-
`;
|
|
2560
|
-
currLen = 0;
|
|
2561
|
-
} else {
|
|
2562
|
-
output += `${token}${nextToken ? ", " : ""}`;
|
|
2563
|
-
}
|
|
2564
|
-
});
|
|
2565
|
-
return output;
|
|
2566
|
-
} else {
|
|
2567
|
-
return groupBy.join(", ");
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
/**
|
|
2571
|
-
* Formats parens
|
|
2572
|
-
* @param count
|
|
2573
|
-
* @param character
|
|
2574
|
-
* @param [leadingParenInline] Make the leading paren inline (last for "(" and first for ")") used for negation condition
|
|
2575
|
-
* @returns
|
|
2576
|
-
*/
|
|
2577
|
-
formatParens(count, character, leadingParenInline = false) {
|
|
2578
|
-
let output = "";
|
|
2579
|
-
if (isNumber(count) && count > 0) {
|
|
2580
|
-
if (this.enabled) {
|
|
2581
|
-
if (character === "(") {
|
|
2582
|
-
for (let i = 0; i < count; i++) {
|
|
2583
|
-
if (leadingParenInline && i === count - 1) {
|
|
2584
|
-
output += "(";
|
|
2585
|
-
} else {
|
|
2586
|
-
if (i === 0) {
|
|
2587
|
-
output += "(\n";
|
|
2588
|
-
} else {
|
|
2589
|
-
this.currIndent++;
|
|
2590
|
-
output += `${this.getIndent()}(
|
|
2591
|
-
`;
|
|
2592
|
-
}
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
if (!leadingParenInline || count > 1) {
|
|
2596
|
-
this.currIndent++;
|
|
2597
|
-
}
|
|
2598
|
-
} else {
|
|
2599
|
-
for (let i = count - 1; i >= 0; i--) {
|
|
2600
|
-
if (leadingParenInline && i === count - 1) {
|
|
2601
|
-
output += ")";
|
|
2602
|
-
} else {
|
|
2603
|
-
this.currIndent--;
|
|
2604
|
-
output += `
|
|
2605
|
-
${this.getIndent()})`;
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
} else {
|
|
2610
|
-
output += generateParens(count, character);
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
return output;
|
|
2614
|
-
}
|
|
2615
|
-
formatWhereClauseOperators(operator, whereClause, additionalIndent = 0) {
|
|
2616
|
-
const skipNewLineAndIndent = operator === "NOT";
|
|
2617
|
-
if (this.enabled && !skipNewLineAndIndent) {
|
|
2618
|
-
return `
|
|
2619
|
-
${this.getIndent(additionalIndent)}${operator} ${whereClause}`;
|
|
2620
|
-
} else {
|
|
2621
|
-
return `${skipNewLineAndIndent ? "" : " "}${operator} ${whereClause}`;
|
|
2622
|
-
}
|
|
2623
|
-
}
|
|
2624
|
-
formatAddNewLine(alt = " ", skipNewLineAndIndent) {
|
|
2625
|
-
return this.enabled && !skipNewLineAndIndent ? `
|
|
2626
|
-
` : alt;
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
|
|
2630
|
-
// src/composer/composer.ts
|
|
2631
|
-
function formatQuery(soql, formatOptions, parseOptions) {
|
|
2632
|
-
return composeQuery(parseQuery(soql, parseOptions), { format: true, formatOptions });
|
|
2633
|
-
}
|
|
2634
|
-
function composeQuery(soql, config = {}) {
|
|
2635
|
-
if (!soql) {
|
|
2636
|
-
return "";
|
|
2637
|
-
}
|
|
2638
|
-
config = config || {};
|
|
2639
|
-
config.format = config.format ? true : false;
|
|
2640
|
-
if (config.logging) {
|
|
2641
|
-
console.time("composer");
|
|
2642
|
-
console.log("Composing Query:", soql);
|
|
2643
|
-
console.log("Format output:", config.format);
|
|
2644
|
-
}
|
|
2645
|
-
const query = new Compose(soql, config).query;
|
|
2646
|
-
if (config.logging) {
|
|
2647
|
-
console.timeEnd("composer");
|
|
2648
|
-
}
|
|
2649
|
-
return query;
|
|
2650
|
-
}
|
|
2651
|
-
var Compose = class {
|
|
2652
|
-
constructor(soql, config = {}) {
|
|
2653
|
-
this.soql = soql;
|
|
2654
|
-
this.logging = false;
|
|
2655
|
-
this.format = false;
|
|
2656
|
-
config = { autoCompose: true, ...config };
|
|
2657
|
-
const { logging, format } = config;
|
|
2658
|
-
this.logging = !!logging;
|
|
2659
|
-
this.format = !!format;
|
|
2660
|
-
this.query = "";
|
|
2661
|
-
this.formatter = new Formatter(this.format, {
|
|
2662
|
-
logging: this.logging,
|
|
2663
|
-
...config.formatOptions
|
|
2664
|
-
});
|
|
2665
|
-
if (config.autoCompose) {
|
|
2666
|
-
this.start();
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
/**
|
|
2670
|
-
* Starts compose
|
|
2671
|
-
*/
|
|
2672
|
-
start() {
|
|
2673
|
-
this.query = this.parseQuery(this.soql);
|
|
2674
|
-
}
|
|
2675
|
-
/**
|
|
2676
|
-
* If logging is enabled, print the query to the console
|
|
2677
|
-
* @param soql
|
|
2678
|
-
*/
|
|
2679
|
-
log(soql) {
|
|
2680
|
-
if (this.logging) {
|
|
2681
|
-
console.log("Current SOQL:", soql);
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
/**
|
|
2685
|
-
* Parses FunctionExp object
|
|
2686
|
-
* Prefers functionName if populated, otherwise will fallback to rawValue
|
|
2687
|
-
* @param fn
|
|
2688
|
-
* @returns fn
|
|
2689
|
-
*/
|
|
2690
|
-
parseFn(fn) {
|
|
2691
|
-
let output;
|
|
2692
|
-
if (fn.rawValue) {
|
|
2693
|
-
output = fn.rawValue;
|
|
2694
|
-
} else {
|
|
2695
|
-
output = fn.functionName;
|
|
2696
|
-
output += `(${(fn.parameters || []).map((param) => isString(param) ? param : this.parseFn(param)).join(", ")})`;
|
|
2697
|
-
}
|
|
2698
|
-
if (fn.alias) {
|
|
2699
|
-
output += ` ${fn.alias}`;
|
|
2700
|
-
}
|
|
2701
|
-
return output;
|
|
2702
|
-
}
|
|
2703
|
-
/**
|
|
2704
|
-
* Parses query
|
|
2705
|
-
* Base entry point for the query
|
|
2706
|
-
* this may be called multiple times recursively for subqueries and WHERE queries
|
|
2707
|
-
* @param query
|
|
2708
|
-
* @returns query
|
|
2709
|
-
*/
|
|
2710
|
-
parseQuery(query) {
|
|
2711
|
-
const fieldData = {
|
|
2712
|
-
fields: this.parseFields(query.fields || []).map((field) => ({
|
|
2713
|
-
text: field.text,
|
|
2714
|
-
typeOfClause: field.typeOfClause,
|
|
2715
|
-
isSubquery: field.text.startsWith("("),
|
|
2716
|
-
prefix: "",
|
|
2717
|
-
suffix: ""
|
|
2718
|
-
})),
|
|
2719
|
-
isSubquery: isSubquery(query),
|
|
2720
|
-
lineBreaks: []
|
|
2721
|
-
};
|
|
2722
|
-
let output = "";
|
|
2723
|
-
if (query.fields) {
|
|
2724
|
-
output += this.formatter.formatClause("SELECT").trimStart();
|
|
2725
|
-
}
|
|
2726
|
-
this.formatter.formatFields(fieldData);
|
|
2727
|
-
let fieldsOutput = "";
|
|
2728
|
-
fieldData.fields.forEach((field) => {
|
|
2729
|
-
if (Array.isArray(field.typeOfClause)) {
|
|
2730
|
-
fieldsOutput += `${field.prefix}${this.formatter.formatTyeOfField(field.text, field.typeOfClause)}${field.suffix}`;
|
|
2731
|
-
} else {
|
|
2732
|
-
fieldsOutput += `${field.prefix}${field.text}${field.suffix}`;
|
|
2733
|
-
}
|
|
2734
|
-
});
|
|
2735
|
-
output += this.formatter.formatText(fieldsOutput);
|
|
2736
|
-
if (!!(isSubquery(query) ? query.relationshipName : query.sObject)) {
|
|
2737
|
-
output += this.formatter.formatClause("FROM");
|
|
2738
|
-
}
|
|
2739
|
-
if (isSubquery(query)) {
|
|
2740
|
-
const sObjectPrefix = query.sObjectPrefix || [];
|
|
2741
|
-
sObjectPrefix.push(query.relationshipName);
|
|
2742
|
-
output += this.formatter.formatText(`${sObjectPrefix.join(".")}${get(query.sObjectAlias, "", " ")}`);
|
|
2743
|
-
} else if (query.sObject) {
|
|
2744
|
-
output += this.formatter.formatText(`${query.sObject}${get(query.sObjectAlias, "", " ")}`);
|
|
2745
|
-
}
|
|
2746
|
-
this.log(output);
|
|
2747
|
-
if (query.usingScope) {
|
|
2748
|
-
output += this.formatter.formatClause("USING SCOPE");
|
|
2749
|
-
output += this.formatter.formatText(query.usingScope);
|
|
2750
|
-
this.log(output);
|
|
2751
|
-
}
|
|
2752
|
-
if (query.where) {
|
|
2753
|
-
output += this.formatter.formatClause("WHERE");
|
|
2754
|
-
output += this.formatter.formatText(this.parseWhereOrHavingClause(query.where));
|
|
2755
|
-
this.log(output);
|
|
2756
|
-
}
|
|
2757
|
-
if (query.groupBy) {
|
|
2758
|
-
output += this.formatter.formatClause("GROUP BY");
|
|
2759
|
-
output += this.formatter.formatText(this.parseGroupByClause(query.groupBy));
|
|
2760
|
-
this.log(output);
|
|
2761
|
-
if (query.having) {
|
|
2762
|
-
output += this.formatter.formatClause("HAVING");
|
|
2763
|
-
output += this.formatter.formatText(this.parseWhereOrHavingClause(query.having));
|
|
2764
|
-
this.log(output);
|
|
2765
|
-
}
|
|
2766
|
-
}
|
|
2767
|
-
if (query.orderBy && (!Array.isArray(query.orderBy) || query.orderBy.length > 0)) {
|
|
2768
|
-
output += this.formatter.formatClause("ORDER BY");
|
|
2769
|
-
output += this.formatter.formatText(this.parseOrderBy(query.orderBy));
|
|
2770
|
-
this.log(output);
|
|
2771
|
-
}
|
|
2772
|
-
if (isNumber(query.limit)) {
|
|
2773
|
-
output += this.formatter.formatClause("LIMIT");
|
|
2774
|
-
output += this.formatter.formatText(`${query.limit}`);
|
|
2775
|
-
this.log(output);
|
|
2776
|
-
}
|
|
2777
|
-
if (isNumber(query.offset)) {
|
|
2778
|
-
output += this.formatter.formatClause("OFFSET");
|
|
2779
|
-
output += this.formatter.formatText(`${query.offset}`);
|
|
2780
|
-
this.log(output);
|
|
2781
|
-
}
|
|
2782
|
-
if (query.withDataCategory) {
|
|
2783
|
-
output += this.formatter.formatClause("WITH DATA CATEGORY");
|
|
2784
|
-
output += this.formatter.formatText(this.parseWithDataCategory(query.withDataCategory));
|
|
2785
|
-
this.log(output);
|
|
2786
|
-
}
|
|
2787
|
-
if (query.withSecurityEnforced) {
|
|
2788
|
-
output += this.formatter.formatClause("WITH SECURITY_ENFORCED");
|
|
2789
|
-
this.log(output);
|
|
2790
|
-
}
|
|
2791
|
-
if (query.withAccessLevel) {
|
|
2792
|
-
output += this.formatter.formatClause(`WITH ${query.withAccessLevel}`);
|
|
2793
|
-
this.log(output);
|
|
2794
|
-
}
|
|
2795
|
-
if (query.for) {
|
|
2796
|
-
output += this.formatter.formatClause("FOR");
|
|
2797
|
-
output += this.formatter.formatText(query.for);
|
|
2798
|
-
this.log(output);
|
|
2799
|
-
}
|
|
2800
|
-
if (query.update) {
|
|
2801
|
-
output += this.formatter.formatClause("UPDATE");
|
|
2802
|
-
output += this.formatter.formatText(query.update);
|
|
2803
|
-
this.log(output);
|
|
2804
|
-
}
|
|
2805
|
-
return output.trim();
|
|
2806
|
-
}
|
|
2807
|
-
/**
|
|
2808
|
-
* Parses fields
|
|
2809
|
-
* e.x.: SELECT amount, FORMAT(amount) Amt, (SELECT Id, Name FROM Contacts)
|
|
2810
|
-
* @param fields
|
|
2811
|
-
* @returns fields
|
|
2812
|
-
*/
|
|
2813
|
-
parseFields(fields) {
|
|
2814
|
-
return fields.map((field) => {
|
|
2815
|
-
let text = "";
|
|
2816
|
-
let typeOfClause;
|
|
2817
|
-
const objPrefix = field.objectPrefix ? `${field.objectPrefix}.` : "";
|
|
2818
|
-
switch (field.type) {
|
|
2819
|
-
case "Field": {
|
|
2820
|
-
text = `${objPrefix}${field.field}${field.alias ? ` ${field.alias}` : ""}`;
|
|
2821
|
-
break;
|
|
2822
|
-
}
|
|
2823
|
-
case "FieldFunctionExpression": {
|
|
2824
|
-
let params = "";
|
|
2825
|
-
if (field.parameters) {
|
|
2826
|
-
params = field.parameters.map((param) => isString(param) ? param : this.parseFields([param]).map((param2) => param2.text)).join(", ");
|
|
2827
|
-
}
|
|
2828
|
-
text = `${field.functionName}(${params})${field.alias ? ` ${field.alias}` : ""}`;
|
|
2829
|
-
break;
|
|
2830
|
-
}
|
|
2831
|
-
case "FieldRelationship": {
|
|
2832
|
-
text = `${objPrefix}${field.relationships.join(".")}.${field.field}${hasAlias(field) ? ` ${field.alias}` : ""}`;
|
|
2833
|
-
break;
|
|
2834
|
-
}
|
|
2835
|
-
case "FieldSubquery": {
|
|
2836
|
-
text = this.formatter.formatSubquery(this.parseQuery(field.subquery));
|
|
2837
|
-
break;
|
|
2838
|
-
}
|
|
2839
|
-
case "FieldTypeof": {
|
|
2840
|
-
typeOfClause = this.parseTypeOfField(field);
|
|
2841
|
-
text = typeOfClause.join(" ");
|
|
2842
|
-
break;
|
|
2843
|
-
}
|
|
2844
|
-
default:
|
|
2845
|
-
break;
|
|
2846
|
-
}
|
|
2847
|
-
return { text, typeOfClause };
|
|
2848
|
-
});
|
|
2849
|
-
}
|
|
2850
|
-
/**
|
|
2851
|
-
* Parses type of Field
|
|
2852
|
-
* e.x.: TYPEOF What WHEN Account THEN Phone, NumberOfEmployees WHEN Opportunity THEN Amount, CloseDate ELSE Name
|
|
2853
|
-
* @param typeOfField
|
|
2854
|
-
* @returns type of field
|
|
2855
|
-
*/
|
|
2856
|
-
parseTypeOfField(typeOfField) {
|
|
2857
|
-
const output = [`TYPEOF ${typeOfField.field}`].concat(
|
|
2858
|
-
typeOfField.conditions.map((condition) => this.formatter.formatTypeofFieldCondition(condition))
|
|
2859
|
-
);
|
|
2860
|
-
output.push(`END`);
|
|
2861
|
-
return output;
|
|
2862
|
-
}
|
|
2863
|
-
/**
|
|
2864
|
-
* Parses where clause
|
|
2865
|
-
* e.x.: WHERE LoginTime > 2010-09-20T22:16:30.000Z AND LoginTime < 2010-09-21T22:16:30.000Z
|
|
2866
|
-
* WHERE Id IN (SELECT AccountId FROM Contact WHERE LastName LIKE 'apple%') AND Id IN (SELECT AccountId FROM Opportunity WHERE isClosed = false)
|
|
2867
|
-
* @param where
|
|
2868
|
-
* @param priorIsNegationOperator - do not set this when calling manually. Recursive call will set this to ensure proper formatting.
|
|
2869
|
-
* @returns where clause
|
|
2870
|
-
*/
|
|
2871
|
-
parseWhereOrHavingClause(whereOrHaving, tabOffset = 0, priorConditionIsNegation = false) {
|
|
2872
|
-
let output = "";
|
|
2873
|
-
const left = whereOrHaving.left;
|
|
2874
|
-
let trimPrecedingOutput = false;
|
|
2875
|
-
if (left) {
|
|
2876
|
-
output += this.formatter.formatParens(left.openParen, "(", isNegationCondition(left));
|
|
2877
|
-
if (!isNegationCondition(left)) {
|
|
2878
|
-
tabOffset = tabOffset + (left.openParen || 0) - (left.closeParen || 0);
|
|
2879
|
-
if (priorConditionIsNegation) {
|
|
2880
|
-
tabOffset++;
|
|
2881
|
-
}
|
|
2882
|
-
let expression = "";
|
|
2883
|
-
expression += isValueFunctionCondition(left) ? this.parseFn(left.fn) : left.field;
|
|
2884
|
-
expression += ` ${left.operator} `;
|
|
2885
|
-
if (isValueQueryCondition(left)) {
|
|
2886
|
-
expression += this.formatter.formatSubquery(this.parseQuery(left.valueQuery), 1, true);
|
|
2887
|
-
} else {
|
|
2888
|
-
expression += getAsArrayStr(getWhereValue(left.value, left.literalType, left.operator));
|
|
2889
|
-
}
|
|
2890
|
-
output += this.formatter.formatWithIndent(expression);
|
|
2891
|
-
output += this.formatter.formatParens(left.closeParen, ")", priorConditionIsNegation);
|
|
2892
|
-
}
|
|
2893
|
-
}
|
|
2894
|
-
if (isWhereOrHavingClauseWithRightCondition(whereOrHaving)) {
|
|
2895
|
-
const operator = get(whereOrHaving.operator);
|
|
2896
|
-
trimPrecedingOutput = operator === "NOT";
|
|
2897
|
-
const formattedData = this.formatter.formatWhereClauseOperators(
|
|
2898
|
-
operator,
|
|
2899
|
-
this.parseWhereOrHavingClause(whereOrHaving.right, tabOffset, isNegationCondition(left)),
|
|
2900
|
-
tabOffset
|
|
2901
|
-
);
|
|
2902
|
-
return `${trimPrecedingOutput ? output.trimRight() : output}${formattedData}`.trim();
|
|
2903
|
-
} else {
|
|
2904
|
-
return output.trim();
|
|
2905
|
-
}
|
|
2906
|
-
}
|
|
2907
|
-
/**
|
|
2908
|
-
* Parses group by clause
|
|
2909
|
-
* e.x.: GROUP BY CampaignId
|
|
2910
|
-
* @param groupBy
|
|
2911
|
-
* @returns group by clause
|
|
2912
|
-
*/
|
|
2913
|
-
parseGroupByClause(groupBy) {
|
|
2914
|
-
return (Array.isArray(groupBy) ? groupBy : [groupBy]).map((clause) => isGroupByField(clause) ? clause.field : this.parseFn(clause.fn)).join(", ");
|
|
2915
|
-
}
|
|
2916
|
-
/**
|
|
2917
|
-
* Parses order by
|
|
2918
|
-
* e.x.: ORDER BY BillingPostalCode ASC NULLS LAST
|
|
2919
|
-
* @param orderBy
|
|
2920
|
-
* @returns order by
|
|
2921
|
-
*/
|
|
2922
|
-
parseOrderBy(orderBy) {
|
|
2923
|
-
if (Array.isArray(orderBy)) {
|
|
2924
|
-
return this.formatter.formatOrderByArray(orderBy.map((ob) => this.parseOrderBy(ob)));
|
|
2925
|
-
} else {
|
|
2926
|
-
let output = "";
|
|
2927
|
-
if (isOrderByField(orderBy)) {
|
|
2928
|
-
output = `${get(orderBy.field, " ")}`;
|
|
2929
|
-
} else {
|
|
2930
|
-
output += `${this.parseFn(orderBy.fn)} `;
|
|
2931
|
-
}
|
|
2932
|
-
output += `${get(orderBy.order, " ")}${get(orderBy.nulls, "", "NULLS ")}`;
|
|
2933
|
-
return output.trim();
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
/**
|
|
2937
|
-
* Parses with data category
|
|
2938
|
-
* e.x.: WITH DATA CATEGORY Geography__c AT (usa__c, uk__c)
|
|
2939
|
-
* @param withDataCategory
|
|
2940
|
-
* @returns with data category
|
|
2941
|
-
*/
|
|
2942
|
-
parseWithDataCategory(withDataCategory) {
|
|
2943
|
-
return withDataCategory.conditions.map((condition) => {
|
|
2944
|
-
const params = condition.parameters.length > 1 ? `(${condition.parameters.join(", ")})` : `${condition.parameters.join(", ")}`;
|
|
2945
|
-
return `${condition.groupName} ${condition.selector} ${params}`;
|
|
2946
|
-
}).join(" AND ");
|
|
2947
|
-
}
|
|
2948
|
-
};
|
|
2949
|
-
export {
|
|
2950
|
-
Compose,
|
|
2951
|
-
composeQuery,
|
|
2952
|
-
formatQuery,
|
|
2953
|
-
getComposedField,
|
|
2954
|
-
getField,
|
|
2955
|
-
getFlattenedFields,
|
|
2956
|
-
hasAlias,
|
|
2957
|
-
isFieldSubquery,
|
|
2958
|
-
isGroupByField,
|
|
2959
|
-
isGroupByFn,
|
|
2960
|
-
isHavingClauseWithRightCondition,
|
|
2961
|
-
isNegationCondition,
|
|
2962
|
-
isOrderByField,
|
|
2963
|
-
isOrderByFn,
|
|
2964
|
-
isQueryValid,
|
|
2965
|
-
isString,
|
|
2966
|
-
isSubquery,
|
|
2967
|
-
isValueCondition,
|
|
2968
|
-
isValueFunctionCondition,
|
|
2969
|
-
isValueQueryCondition,
|
|
2970
|
-
isValueWithDateLiteralCondition,
|
|
2971
|
-
isValueWithDateNLiteralCondition,
|
|
2972
|
-
isWhereClauseWithRightCondition,
|
|
2973
|
-
isWhereOrHavingClauseWithRightCondition,
|
|
2974
|
-
parseQuery
|
|
2975
|
-
};
|