@jetstreamapp/soql-parser-js 6.1.0 → 6.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.
Files changed (46) hide show
  1. package/README.md +2 -3
  2. package/dist/cjs/index.js +143 -2
  3. package/dist/cli/index.js +148 -113
  4. package/dist/esm/index.js +143 -4
  5. package/dist/{cjs/src → types}/index.d.ts +1 -1
  6. package/package.json +12 -20
  7. package/dist/cjs/index.js.LICENSE.txt +0 -1
  8. package/dist/cjs/main.licenses.txt +0 -898
  9. package/dist/cjs/src/api/api-models.js +0 -2
  10. package/dist/cjs/src/api/public-utils.js +0 -175
  11. package/dist/cjs/src/composer/composer.js +0 -295
  12. package/dist/cjs/src/formatter/formatter.js +0 -236
  13. package/dist/cjs/src/index.js +0 -23
  14. package/dist/cjs/src/models.js +0 -2
  15. package/dist/cjs/src/parser/lexer.js +0 -954
  16. package/dist/cjs/src/parser/parser.js +0 -697
  17. package/dist/cjs/src/parser/visitor.js +0 -856
  18. package/dist/cjs/src/utils.js +0 -245
  19. package/dist/esm/api/api-models.js +0 -1
  20. package/dist/esm/api/public-utils.js +0 -153
  21. package/dist/esm/composer/composer.js +0 -273
  22. package/dist/esm/formatter/formatter.js +0 -223
  23. package/dist/esm/models.js +0 -1
  24. package/dist/esm/parser/lexer.js +0 -947
  25. package/dist/esm/parser/parser.js +0 -667
  26. package/dist/esm/parser/visitor.js +0 -823
  27. package/dist/esm/utils.js +0 -200
  28. package/dist/src/api/api-models.js +0 -2
  29. package/dist/src/api/public-utils.js +0 -203
  30. package/dist/src/composer/composer.js +0 -358
  31. package/dist/src/formatter/formatter.js +0 -263
  32. package/dist/src/index.js +0 -28
  33. package/dist/src/models.js +0 -2
  34. package/dist/src/parser/lexer.js +0 -997
  35. package/dist/src/parser/parser.js +0 -711
  36. package/dist/src/parser/visitor.js +0 -862
  37. package/dist/src/utils.js +0 -251
  38. /package/dist/{cjs/src → types}/api/api-models.d.ts +0 -0
  39. /package/dist/{cjs/src → types}/api/public-utils.d.ts +0 -0
  40. /package/dist/{cjs/src → types}/composer/composer.d.ts +0 -0
  41. /package/dist/{cjs/src → types}/formatter/formatter.d.ts +0 -0
  42. /package/dist/{cjs/src → types}/models.d.ts +0 -0
  43. /package/dist/{cjs/src → types}/parser/lexer.d.ts +0 -0
  44. /package/dist/{cjs/src → types}/parser/parser.d.ts +0 -0
  45. /package/dist/{cjs/src → types}/parser/visitor.d.ts +0 -0
  46. /package/dist/{cjs/src → types}/utils.d.ts +0 -0
@@ -1,697 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.parse = exports.SoqlParser = void 0;
19
- var chevrotain_1 = require("chevrotain");
20
- var lexer = require("./lexer");
21
- var LexingError = (function (_super) {
22
- __extends(LexingError, _super);
23
- function LexingError(lexingError) {
24
- var _this = _super.call(this, "".concat(lexingError.message, " (").concat(lexingError.line, ":").concat(lexingError.column, ")")) || this;
25
- _this.name = 'LexingError';
26
- return _this;
27
- }
28
- return LexingError;
29
- }(Error));
30
- var ParsingError = (function (_super) {
31
- __extends(ParsingError, _super);
32
- function ParsingError(parsingError) {
33
- var _this = _super.call(this, parsingError.message) || this;
34
- _this.name = parsingError.name;
35
- return _this;
36
- }
37
- return ParsingError;
38
- }(Error));
39
- var SoqlParser = (function (_super) {
40
- __extends(SoqlParser, _super);
41
- function SoqlParser(_a) {
42
- var _b = _a === void 0 ? { ignoreParseErrors: false } : _a, ignoreParseErrors = _b.ignoreParseErrors;
43
- var _this = _super.call(this, lexer.allTokens, {
44
- skipValidations: false,
45
- recoveryEnabled: !!ignoreParseErrors,
46
- }) || this;
47
- _this.$_dateFunctionOr = undefined;
48
- _this.$_aggregateFunction = undefined;
49
- _this.$_otherFunction = undefined;
50
- _this.$_atomicExpression = undefined;
51
- _this.$_apexBindVariableExpression = undefined;
52
- _this.$_arrayExpression = undefined;
53
- _this.$_relationalOperator = undefined;
54
- _this.$_selectClause = undefined;
55
- _this.$_selectClauseFunctionIdentifier = undefined;
56
- _this.$_withDataCategoryArr = undefined;
57
- _this.allowApexBindVariables = false;
58
- _this.ignoreParseErrors = false;
59
- _this.selectStatement = _this.RULE('selectStatement', function () {
60
- _this.SUBRULE(_this.selectClause);
61
- _this.SUBRULE(_this.fromClause);
62
- _this.SUBRULE(_this.clauseStatements);
63
- });
64
- _this.selectStatementPartial = _this.RULE('selectStatementPartial', function () {
65
- _this.OPTION(function () {
66
- _this.SUBRULE(_this.selectClause);
67
- });
68
- _this.OPTION1(function () {
69
- _this.SUBRULE(_this.fromClause);
70
- });
71
- _this.SUBRULE(_this.clauseStatements);
72
- });
73
- _this.clauseStatements = _this.RULE('clauseStatements', function () {
74
- _this.OPTION(function () {
75
- _this.SUBRULE(_this.usingScopeClause);
76
- });
77
- _this.OPTION1(function () {
78
- _this.SUBRULE(_this.whereClause);
79
- });
80
- _this.OPTION2(function () {
81
- _this.MANY({
82
- DEF: function () {
83
- _this.SUBRULE(_this.withClause);
84
- },
85
- });
86
- });
87
- _this.OPTION3(function () {
88
- _this.SUBRULE(_this.groupByClause);
89
- _this.OPTION4(function () {
90
- _this.SUBRULE(_this.havingClause);
91
- });
92
- });
93
- _this.OPTION5(function () {
94
- _this.SUBRULE(_this.orderByClause);
95
- });
96
- _this.OPTION6(function () {
97
- _this.SUBRULE(_this.limitClause);
98
- });
99
- _this.OPTION7(function () {
100
- _this.SUBRULE(_this.offsetClause);
101
- });
102
- _this.OPTION8(function () {
103
- _this.SUBRULE(_this.forViewOrReference);
104
- });
105
- _this.OPTION9(function () {
106
- _this.SUBRULE(_this.updateTrackingViewstat);
107
- });
108
- });
109
- _this.selectClause = _this.RULE('selectClause', function () {
110
- _this.CONSUME(lexer.Select);
111
- _this.AT_LEAST_ONE_SEP({
112
- SEP: lexer.Comma,
113
- DEF: function () {
114
- _this.OR(_this.$_selectClause ||
115
- (_this.$_selectClause = [
116
- { ALT: function () { return _this.SUBRULE(_this.selectClauseFunctionIdentifier, { LABEL: 'field' }); } },
117
- { ALT: function () { return _this.SUBRULE(_this.selectClauseSubqueryIdentifier, { LABEL: 'field' }); } },
118
- { ALT: function () { return _this.SUBRULE(_this.selectClauseTypeOf, { LABEL: 'field' }); } },
119
- { ALT: function () { return _this.SUBRULE(_this.selectClauseIdentifier, { LABEL: 'field' }); } },
120
- ]));
121
- },
122
- });
123
- }, { resyncEnabled: false });
124
- _this.selectClauseFunctionIdentifier = _this.RULE('selectClauseFunctionIdentifier', function () {
125
- _this.OR(_this.$_selectClauseFunctionIdentifier ||
126
- (_this.$_selectClauseFunctionIdentifier = [
127
- { ALT: function () { return _this.SUBRULE(_this.dateFunction, { LABEL: 'fn' }); } },
128
- { ALT: function () { return _this.SUBRULE(_this.aggregateFunction, { LABEL: 'fn' }); } },
129
- { ALT: function () { return _this.SUBRULE(_this.locationFunction, { LABEL: 'fn' }); } },
130
- { ALT: function () { return _this.SUBRULE(_this.fieldsFunction, { LABEL: 'fn' }); } },
131
- { ALT: function () { return _this.SUBRULE(_this.otherFunction, { LABEL: 'fn' }); } },
132
- ]));
133
- _this.OPTION(function () { return _this.CONSUME(lexer.Identifier, { LABEL: 'alias' }); });
134
- }, { resyncEnabled: false });
135
- _this.selectClauseSubqueryIdentifier = _this.RULE('selectClauseSubqueryIdentifier', function () {
136
- _this.CONSUME(lexer.LParen);
137
- _this.SUBRULE(_this.selectStatement);
138
- _this.CONSUME(lexer.RParen);
139
- }, { resyncEnabled: false });
140
- _this.selectClauseTypeOf = _this.RULE('selectClauseTypeOf', function () {
141
- _this.CONSUME(lexer.Typeof);
142
- _this.CONSUME(lexer.Identifier, { LABEL: 'typeOfField' });
143
- _this.AT_LEAST_ONE({
144
- DEF: function () {
145
- _this.SUBRULE(_this.selectClauseTypeOfThen);
146
- },
147
- });
148
- _this.OPTION(function () {
149
- _this.SUBRULE(_this.selectClauseTypeOfElse);
150
- });
151
- _this.CONSUME(lexer.End);
152
- }, { resyncEnabled: false });
153
- _this.selectClauseIdentifier = _this.RULE('selectClauseIdentifier', function () {
154
- _this.CONSUME(lexer.Identifier, { LABEL: 'field' });
155
- _this.OPTION(function () { return _this.CONSUME1(lexer.Identifier, { LABEL: 'alias' }); });
156
- }, { resyncEnabled: false });
157
- _this.selectClauseTypeOfThen = _this.RULE('selectClauseTypeOfThen', function () {
158
- _this.CONSUME(lexer.When);
159
- _this.CONSUME(lexer.Identifier, { LABEL: 'typeOfField' });
160
- _this.CONSUME(lexer.Then);
161
- _this.AT_LEAST_ONE_SEP({
162
- SEP: lexer.Comma,
163
- DEF: function () {
164
- _this.CONSUME1(lexer.Identifier, { LABEL: 'field' });
165
- },
166
- });
167
- }, { resyncEnabled: false });
168
- _this.selectClauseTypeOfElse = _this.RULE('selectClauseTypeOfElse', function () {
169
- _this.CONSUME(lexer.Else);
170
- _this.AT_LEAST_ONE_SEP({
171
- SEP: lexer.Comma,
172
- DEF: function () {
173
- _this.CONSUME(lexer.Identifier, { LABEL: 'field' });
174
- },
175
- });
176
- }, { resyncEnabled: false });
177
- _this.fromClause = _this.RULE('fromClause', function () {
178
- _this.CONSUME(lexer.From);
179
- _this.CONSUME(lexer.Identifier);
180
- _this.OPTION({
181
- GATE: function () { return !(_this.LA(1).tokenType === lexer.Offset && _this.LA(2).tokenType === lexer.UnsignedInteger); },
182
- DEF: function () { return _this.CONSUME1(lexer.Identifier, { LABEL: 'alias' }); },
183
- });
184
- }, { resyncEnabled: false });
185
- _this.usingScopeClause = _this.RULE('usingScopeClause', function () {
186
- _this.CONSUME(lexer.Using);
187
- _this.CONSUME(lexer.Scope);
188
- _this.CONSUME(lexer.UsingScopeEnumeration);
189
- });
190
- _this.whereClause = _this.RULE('whereClause', function () {
191
- _this.CONSUME(lexer.Where);
192
- var parenCount = _this.getParenCount();
193
- _this.AT_LEAST_ONE({
194
- DEF: function () {
195
- _this.SUBRULE(_this.conditionExpression, { ARGS: [parenCount, true, true] });
196
- },
197
- });
198
- _this.$_checkBalancedParens(parenCount);
199
- });
200
- _this.whereClauseSubqueryIdentifier = _this.RULE('whereClauseSubqueryIdentifier', function () {
201
- _this.CONSUME(lexer.LParen);
202
- _this.SUBRULE(_this.selectStatement);
203
- _this.CONSUME(lexer.RParen);
204
- });
205
- _this.conditionExpression = _this.RULE('conditionExpression', function (parenCount, allowAggregateFn, allowLocationFn) {
206
- parenCount = _this.getParenCount(parenCount);
207
- _this.OPTION(function () {
208
- _this.OR([
209
- { ALT: function () { return _this.CONSUME(lexer.And, { LABEL: 'logicalOperator' }); } },
210
- { ALT: function () { return _this.CONSUME(lexer.Or, { LABEL: 'logicalOperator' }); } },
211
- ]);
212
- });
213
- _this.MANY({
214
- MAX_LOOKAHEAD: 10,
215
- DEF: function () { return _this.SUBRULE(_this.expressionPartWithNegation, { ARGS: [parenCount], LABEL: 'expressionNegation' }); },
216
- });
217
- _this.OR1({
218
- MAX_LOOKAHEAD: 10,
219
- DEF: [{ ALT: function () { return _this.SUBRULE(_this.expression, { ARGS: [parenCount, false, allowAggregateFn, allowLocationFn] }); } }],
220
- });
221
- });
222
- _this.withClause = _this.RULE('withClause', function () {
223
- _this.CONSUME(lexer.With);
224
- _this.OR([
225
- { ALT: function () { return _this.CONSUME(lexer.SecurityEnforced, { LABEL: 'withSecurityEnforced' }); } },
226
- { ALT: function () { return _this.CONSUME(lexer.UserMode, { LABEL: 'withAccessLevel' }); } },
227
- { ALT: function () { return _this.CONSUME(lexer.SystemMode, { LABEL: 'withAccessLevel' }); } },
228
- { ALT: function () { return _this.SUBRULE(_this.withDataCategory); } },
229
- ]);
230
- });
231
- _this.withDataCategory = _this.RULE('withDataCategory', function () {
232
- _this.CONSUME(lexer.DataCategory);
233
- _this.AT_LEAST_ONE_SEP({
234
- SEP: lexer.And,
235
- DEF: function () {
236
- _this.SUBRULE(_this.withDataCategoryArr);
237
- },
238
- });
239
- });
240
- _this.withDataCategoryArr = _this.RULE('withDataCategoryArr', function () {
241
- _this.CONSUME(lexer.Identifier, { LABEL: 'dataCategoryGroupName' });
242
- _this.OR(_this.$_withDataCategoryArr ||
243
- (_this.$_withDataCategoryArr = [
244
- { ALT: function () { return _this.CONSUME(lexer.At, { LABEL: 'filteringSelector' }); } },
245
- { ALT: function () { return _this.CONSUME(lexer.Above, { LABEL: 'filteringSelector' }); } },
246
- { ALT: function () { return _this.CONSUME(lexer.Below, { LABEL: 'filteringSelector' }); } },
247
- { ALT: function () { return _this.CONSUME(lexer.AboveOrBelow, { LABEL: 'filteringSelector' }); } },
248
- ]));
249
- _this.OPTION(function () {
250
- _this.CONSUME1(lexer.LParen);
251
- });
252
- _this.AT_LEAST_ONE_SEP1({
253
- SEP: lexer.Comma,
254
- DEF: function () {
255
- _this.CONSUME1(lexer.Identifier, { LABEL: 'dataCategoryName' });
256
- },
257
- });
258
- _this.OPTION1(function () {
259
- _this.CONSUME2(lexer.RParen);
260
- });
261
- });
262
- _this.groupByClause = _this.RULE('groupByClause', function () {
263
- _this.CONSUME(lexer.GroupBy);
264
- _this.AT_LEAST_ONE_SEP({
265
- SEP: lexer.Comma,
266
- DEF: function () {
267
- _this.OR([
268
- { ALT: function () { return _this.SUBRULE(_this.cubeFunction, { LABEL: 'groupBy' }); } },
269
- { ALT: function () { return _this.SUBRULE(_this.rollupFunction, { LABEL: 'groupBy' }); } },
270
- { ALT: function () { return _this.SUBRULE(_this.dateFunction, { LABEL: 'groupBy' }); } },
271
- { ALT: function () { return _this.CONSUME(lexer.Identifier, { LABEL: 'groupBy' }); } },
272
- ]);
273
- },
274
- });
275
- });
276
- _this.havingClause = _this.RULE('havingClause', function () {
277
- _this.CONSUME(lexer.Having);
278
- var parenCount = _this.getParenCount();
279
- _this.AT_LEAST_ONE({
280
- DEF: function () {
281
- _this.SUBRULE(_this.conditionExpression, { ARGS: [parenCount, true, false] });
282
- },
283
- });
284
- _this.$_checkBalancedParens(parenCount);
285
- });
286
- _this.orderByClause = _this.RULE('orderByClause', function () {
287
- _this.CONSUME(lexer.OrderBy);
288
- _this.AT_LEAST_ONE_SEP({
289
- SEP: lexer.Comma,
290
- DEF: function () {
291
- _this.OR([
292
- { ALT: function () { return _this.SUBRULE(_this.orderByGroupingFunctionExpression, { LABEL: 'orderByExpressionOrFn' }); } },
293
- { ALT: function () { return _this.SUBRULE(_this.orderBySpecialFunctionExpression, { LABEL: 'orderByExpressionOrFn' }); } },
294
- { ALT: function () { return _this.SUBRULE(_this.orderByExpression, { LABEL: 'orderByExpressionOrFn' }); } },
295
- ]);
296
- },
297
- });
298
- });
299
- _this.orderByExpression = _this.RULE('orderByExpression', function () {
300
- _this.CONSUME(lexer.Identifier);
301
- _this.OPTION(function () {
302
- _this.OR([{ ALT: function () { return _this.CONSUME(lexer.Asc, { LABEL: 'order' }); } }, { ALT: function () { return _this.CONSUME(lexer.Desc, { LABEL: 'order' }); } }]);
303
- });
304
- _this.OPTION1(function () {
305
- _this.CONSUME(lexer.Nulls);
306
- _this.OR1([{ ALT: function () { return _this.CONSUME(lexer.First, { LABEL: 'nulls' }); } }, { ALT: function () { return _this.CONSUME(lexer.Last, { LABEL: 'nulls' }); } }]);
307
- });
308
- });
309
- _this.orderByGroupingFunctionExpression = _this.RULE('orderByGroupingFunctionExpression', function () {
310
- _this.CONSUME(lexer.Grouping, { LABEL: 'fn' });
311
- _this.SUBRULE(_this.functionExpression);
312
- });
313
- _this.orderBySpecialFunctionExpression = _this.RULE('orderBySpecialFunctionExpression', function () {
314
- _this.OR([
315
- { ALT: function () { return _this.SUBRULE(_this.aggregateFunction); } },
316
- { ALT: function () { return _this.SUBRULE(_this.dateFunction); } },
317
- { ALT: function () { return _this.SUBRULE(_this.locationFunction); } },
318
- ]);
319
- _this.OPTION(function () {
320
- _this.OR1([{ ALT: function () { return _this.CONSUME(lexer.Asc, { LABEL: 'order' }); } }, { ALT: function () { return _this.CONSUME(lexer.Desc, { LABEL: 'order' }); } }]);
321
- });
322
- _this.OPTION1(function () {
323
- _this.CONSUME(lexer.Nulls);
324
- _this.OR2([{ ALT: function () { return _this.CONSUME(lexer.First, { LABEL: 'nulls' }); } }, { ALT: function () { return _this.CONSUME(lexer.Last, { LABEL: 'nulls' }); } }]);
325
- });
326
- });
327
- _this.limitClause = _this.RULE('limitClause', function () {
328
- _this.CONSUME(lexer.Limit);
329
- _this.CONSUME(lexer.UnsignedInteger, { LABEL: 'value' });
330
- });
331
- _this.offsetClause = _this.RULE('offsetClause', function () {
332
- _this.CONSUME(lexer.Offset);
333
- _this.CONSUME(lexer.UnsignedInteger, { LABEL: 'value' });
334
- });
335
- _this.dateFunction = _this.RULE('dateFunction', function () {
336
- _this.OR(_this.$_dateFunctionOr ||
337
- (_this.$_dateFunctionOr = [
338
- { ALT: function () { return _this.CONSUME(lexer.CalendarMonth, { LABEL: 'fn' }); } },
339
- { ALT: function () { return _this.CONSUME(lexer.CalendarQuarter, { LABEL: 'fn' }); } },
340
- { ALT: function () { return _this.CONSUME(lexer.CalendarYear, { LABEL: 'fn' }); } },
341
- { ALT: function () { return _this.CONSUME(lexer.DayInMonth, { LABEL: 'fn' }); } },
342
- { ALT: function () { return _this.CONSUME(lexer.DayInWeek, { LABEL: 'fn' }); } },
343
- { ALT: function () { return _this.CONSUME(lexer.DayInYear, { LABEL: 'fn' }); } },
344
- { ALT: function () { return _this.CONSUME(lexer.DayOnly, { LABEL: 'fn' }); } },
345
- { ALT: function () { return _this.CONSUME(lexer.FiscalMonth, { LABEL: 'fn' }); } },
346
- { ALT: function () { return _this.CONSUME(lexer.FiscalQuarter, { LABEL: 'fn' }); } },
347
- { ALT: function () { return _this.CONSUME(lexer.FiscalYear, { LABEL: 'fn' }); } },
348
- { ALT: function () { return _this.CONSUME(lexer.HourInDay, { LABEL: 'fn' }); } },
349
- { ALT: function () { return _this.CONSUME(lexer.WeekInMonth, { LABEL: 'fn' }); } },
350
- { ALT: function () { return _this.CONSUME(lexer.WeekInYear, { LABEL: 'fn' }); } },
351
- ]));
352
- _this.SUBRULE(_this.functionExpression);
353
- });
354
- _this.aggregateFunction = _this.RULE('aggregateFunction', function () {
355
- _this.OR(_this.$_aggregateFunction ||
356
- (_this.$_aggregateFunction = [
357
- { ALT: function () { return _this.CONSUME(lexer.Avg, { LABEL: 'fn' }); } },
358
- { ALT: function () { return _this.CONSUME(lexer.Count, { LABEL: 'fn' }); } },
359
- { ALT: function () { return _this.CONSUME(lexer.CountDistinct, { LABEL: 'fn' }); } },
360
- { ALT: function () { return _this.CONSUME(lexer.Min, { LABEL: 'fn' }); } },
361
- { ALT: function () { return _this.CONSUME(lexer.Max, { LABEL: 'fn' }); } },
362
- { ALT: function () { return _this.CONSUME(lexer.Sum, { LABEL: 'fn' }); } },
363
- ]));
364
- _this.SUBRULE(_this.functionExpression, { ARGS: [true] });
365
- });
366
- _this.fieldsFunction = _this.RULE('fieldsFunction', function () {
367
- _this.CONSUME(lexer.Fields, { LABEL: 'fn' });
368
- _this.CONSUME(lexer.LParen);
369
- _this.CONSUME(lexer.FieldsFunctionParamIdentifier, { LABEL: 'params' });
370
- _this.CONSUME(lexer.RParen);
371
- });
372
- _this.otherFunction = _this.RULE('otherFunction', function () {
373
- _this.OR(_this.$_otherFunction ||
374
- (_this.$_otherFunction = [
375
- { ALT: function () { return _this.CONSUME(lexer.Format, { LABEL: 'fn' }); } },
376
- { ALT: function () { return _this.CONSUME(lexer.Tolabel, { LABEL: 'fn' }); } },
377
- { ALT: function () { return _this.CONSUME(lexer.ConvertTimeZone, { LABEL: 'fn' }); } },
378
- { ALT: function () { return _this.CONSUME(lexer.ConvertCurrency, { LABEL: 'fn' }); } },
379
- { ALT: function () { return _this.CONSUME(lexer.Grouping, { LABEL: 'fn' }); } },
380
- ]));
381
- _this.SUBRULE(_this.functionExpression);
382
- });
383
- _this.cubeFunction = _this.RULE('cubeFunction', function () {
384
- _this.CONSUME(lexer.Cube, { LABEL: 'fn' });
385
- _this.SUBRULE(_this.functionExpression);
386
- });
387
- _this.rollupFunction = _this.RULE('rollupFunction', function () {
388
- _this.CONSUME(lexer.Rollup, { LABEL: 'fn' });
389
- _this.SUBRULE(_this.functionExpression);
390
- });
391
- _this.functionExpression = _this.RULE('functionExpression', function (skipAggregate) {
392
- _this.CONSUME(lexer.LParen);
393
- _this.MANY_SEP({
394
- SEP: lexer.Comma,
395
- DEF: function () {
396
- _this.OR([
397
- { GATE: function () { return !skipAggregate; }, ALT: function () { return _this.SUBRULE(_this.aggregateFunction, { LABEL: 'params' }); } },
398
- { ALT: function () { return _this.SUBRULE(_this.otherFunction, { LABEL: 'params' }); } },
399
- { ALT: function () { return _this.CONSUME(lexer.StringIdentifier, { LABEL: 'params' }); } },
400
- { ALT: function () { return _this.CONSUME(lexer.NumberIdentifier, { LABEL: 'params' }); } },
401
- { ALT: function () { return _this.CONSUME(lexer.Identifier, { LABEL: 'params' }); } },
402
- ]);
403
- },
404
- });
405
- _this.CONSUME(lexer.RParen);
406
- });
407
- _this.locationFunction = _this.RULE('locationFunction', function () {
408
- _this.CONSUME(lexer.Distance);
409
- _this.CONSUME(lexer.LParen);
410
- _this.CONSUME(lexer.Identifier, { LABEL: 'location1' });
411
- _this.CONSUME(lexer.Comma);
412
- _this.OR([
413
- { ALT: function () { return _this.SUBRULE(_this.geolocationFunction, { LABEL: 'location2' }); } },
414
- { ALT: function () { return _this.CONSUME1(lexer.Identifier, { LABEL: 'location2' }); } },
415
- ]);
416
- _this.CONSUME1(lexer.Comma);
417
- _this.CONSUME(lexer.GeolocationUnit, { LABEL: 'unit' });
418
- _this.CONSUME(lexer.RParen);
419
- });
420
- _this.geolocationFunction = _this.RULE('geolocationFunction', function () {
421
- _this.CONSUME(lexer.Geolocation);
422
- _this.CONSUME(lexer.LParen);
423
- _this.CONSUME(lexer.NumberIdentifier, { LABEL: 'latitude' });
424
- _this.CONSUME(lexer.Comma);
425
- _this.CONSUME1(lexer.NumberIdentifier, { LABEL: 'longitude' });
426
- _this.CONSUME(lexer.RParen);
427
- });
428
- _this.expressionPartWithNegation = _this.RULE('expressionPartWithNegation', function (parenCount) {
429
- var leftParenCount = 0;
430
- _this.MANY(function () {
431
- _this.CONSUME(lexer.LParen);
432
- leftParenCount++;
433
- });
434
- _this.CONSUME(lexer.Not, { LABEL: 'expressionNegation' });
435
- if (parenCount && leftParenCount) {
436
- parenCount.left += leftParenCount;
437
- }
438
- });
439
- _this.expression = _this.RULE('expression', function (parenCount, allowSubquery, allowAggregateFn, allowLocationFn) {
440
- _this.OPTION1(function () {
441
- _this.MANY1(function () {
442
- _this.CONSUME(lexer.LParen);
443
- if (parenCount) {
444
- parenCount.left++;
445
- }
446
- });
447
- });
448
- _this.OR1([
449
- { GATE: function () { return !!allowAggregateFn; }, ALT: function () { return _this.SUBRULE(_this.aggregateFunction, { LABEL: 'lhs' }); } },
450
- { GATE: function () { return !!allowLocationFn; }, ALT: function () { return _this.SUBRULE(_this.locationFunction, { LABEL: 'lhs' }); } },
451
- { ALT: function () { return _this.SUBRULE(_this.dateFunction, { LABEL: 'lhs' }); } },
452
- { ALT: function () { return _this.SUBRULE(_this.otherFunction, { LABEL: 'lhs' }); } },
453
- { ALT: function () { return _this.CONSUME(lexer.Identifier, { LABEL: 'lhs' }); } },
454
- ]);
455
- _this.OR2([
456
- { ALT: function () { return _this.SUBRULE(_this.expressionWithRelationalOperator, { LABEL: 'operator' }); } },
457
- { ALT: function () { return _this.SUBRULE(_this.expressionWithSetOperator, { LABEL: 'operator', ARGS: [allowSubquery] }); } },
458
- ]);
459
- _this.OPTION3(function () {
460
- _this.MANY2({
461
- GATE: function () { return (parenCount ? parenCount.left > parenCount.right : true); },
462
- DEF: function () {
463
- _this.CONSUME(lexer.RParen);
464
- if (parenCount) {
465
- parenCount.right++;
466
- }
467
- },
468
- });
469
- });
470
- });
471
- _this.expressionWithRelationalOperator = _this.RULE('expressionWithRelationalOperator', function () {
472
- _this.SUBRULE(_this.relationalOperator);
473
- _this.SUBRULE(_this.atomicExpression, { LABEL: 'rhs' });
474
- });
475
- _this.expressionWithSetOperator = _this.RULE('expressionWithSetOperator', function (allowSubquery) {
476
- _this.SUBRULE(_this.setOperator);
477
- _this.SUBRULE2(_this.atomicExpression, { LABEL: 'rhs', ARGS: [true, allowSubquery] });
478
- });
479
- _this.atomicExpression = _this.RULE('atomicExpression', function (isArray, allowSubquery) {
480
- _this.OR(_this.$_atomicExpression ||
481
- (_this.$_atomicExpression = [
482
- { GATE: function () { return _this.allowApexBindVariables; }, ALT: function () { return _this.SUBRULE(_this.apexBindVariableExpression); } },
483
- { GATE: function () { return isArray; }, ALT: function () { return _this.SUBRULE(_this.arrayExpression); } },
484
- { GATE: function () { return isArray && allowSubquery; }, ALT: function () { return _this.SUBRULE(_this.whereClauseSubqueryIdentifier); } },
485
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.DateIdentifier); } },
486
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.CurrencyPrefixedDecimal, { LABEL: 'CurrencyPrefixedDecimal' }); } },
487
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.CurrencyPrefixedInteger, { LABEL: 'CurrencyPrefixedInteger' }); } },
488
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.NumberIdentifier); } },
489
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.Null); } },
490
- { GATE: function () { return !isArray; }, ALT: function () { return _this.SUBRULE(_this.booleanValue); } },
491
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.DateLiteral); } },
492
- { GATE: function () { return !isArray; }, ALT: function () { return _this.SUBRULE(_this.dateNLiteral); } },
493
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.GeolocationUnit, { LABEL: 'StringIdentifier' }); } },
494
- { GATE: function () { return !isArray; }, ALT: function () { return _this.CONSUME(lexer.StringIdentifier); } },
495
- ]));
496
- });
497
- _this.apexBindVariableExpression = _this.RULE('apexBindVariableExpression', function () {
498
- _this.CONSUME(lexer.Colon);
499
- _this.OPTION(function () {
500
- _this.SUBRULE(_this.apexBindVariableNewInstantiation, { LABEL: 'apex' });
501
- _this.OPTION1(function () {
502
- _this.CONSUME(lexer.Decimal);
503
- });
504
- });
505
- _this.MANY_SEP({
506
- SEP: lexer.Decimal,
507
- DEF: function () {
508
- _this.OR(_this.$_apexBindVariableExpression ||
509
- (_this.$_apexBindVariableExpression = [
510
- { ALT: function () { return _this.SUBRULE(_this.apexBindVariableFunctionCall, { LABEL: 'apex' }); } },
511
- { ALT: function () { return _this.SUBRULE(_this.apexBindVariableIdentifier, { LABEL: 'apex' }); } },
512
- ]));
513
- },
514
- });
515
- });
516
- _this.apexBindVariableIdentifier = _this.RULE('apexBindVariableIdentifier', function () {
517
- _this.CONSUME(lexer.Identifier);
518
- _this.OPTION(function () { return _this.SUBRULE(_this.apexBindVariableFunctionArrayAccessor); });
519
- });
520
- _this.apexBindVariableNewInstantiation = _this.RULE('apexBindVariableNewInstantiation', function () {
521
- _this.CONSUME(lexer.ApexNew, { LABEL: 'new' });
522
- _this.CONSUME(lexer.Identifier, { LABEL: 'function' });
523
- _this.OPTION(function () {
524
- _this.SUBRULE(_this.apexBindVariableGeneric);
525
- });
526
- _this.SUBRULE(_this.apexBindVariableFunctionParams);
527
- _this.OPTION1(function () { return _this.SUBRULE(_this.apexBindVariableFunctionArrayAccessor); });
528
- });
529
- _this.apexBindVariableFunctionCall = _this.RULE('apexBindVariableFunctionCall', function () {
530
- _this.CONSUME(lexer.Identifier, { LABEL: 'function' });
531
- _this.SUBRULE(_this.apexBindVariableFunctionParams);
532
- _this.OPTION(function () { return _this.SUBRULE(_this.apexBindVariableFunctionArrayAccessor); });
533
- });
534
- _this.apexBindVariableGeneric = _this.RULE('apexBindVariableGeneric', function () {
535
- _this.CONSUME(lexer.LessThan);
536
- _this.AT_LEAST_ONE_SEP({
537
- SEP: lexer.Comma,
538
- DEF: function () {
539
- _this.CONSUME(lexer.Identifier, { LABEL: 'parameter' });
540
- },
541
- });
542
- _this.CONSUME(lexer.GreaterThan);
543
- });
544
- _this.apexBindVariableFunctionParams = _this.RULE('apexBindVariableFunctionParams', function () {
545
- _this.CONSUME(lexer.LParen);
546
- _this.MANY_SEP({
547
- SEP: lexer.Comma,
548
- DEF: function () {
549
- _this.CONSUME(lexer.Identifier, { LABEL: 'parameter' });
550
- },
551
- });
552
- _this.CONSUME(lexer.RParen);
553
- });
554
- _this.apexBindVariableFunctionArrayAccessor = _this.RULE('apexBindVariableFunctionArrayAccessor', function () {
555
- _this.CONSUME(lexer.LSquareBracket);
556
- _this.OR([
557
- { ALT: function () { return _this.CONSUME(lexer.UnsignedInteger, { LABEL: 'value' }); } },
558
- { ALT: function () { return _this.CONSUME(lexer.Identifier, { LABEL: 'value' }); } },
559
- ]);
560
- _this.CONSUME(lexer.RSquareBracket);
561
- });
562
- _this.arrayExpression = _this.RULE('arrayExpression', function () {
563
- _this.CONSUME(lexer.LParen);
564
- _this.AT_LEAST_ONE_SEP({
565
- SEP: lexer.Comma,
566
- DEF: function () {
567
- _this.OR(_this.$_arrayExpression ||
568
- (_this.$_arrayExpression = [
569
- { ALT: function () { return _this.CONSUME(lexer.CurrencyPrefixedDecimal, { LABEL: 'value' }); } },
570
- { ALT: function () { return _this.CONSUME(lexer.CurrencyPrefixedInteger, { LABEL: 'value' }); } },
571
- { ALT: function () { return _this.CONSUME(lexer.NumberIdentifier, { LABEL: 'value' }); } },
572
- { ALT: function () { return _this.CONSUME(lexer.DateIdentifier, { LABEL: 'value' }); } },
573
- { ALT: function () { return _this.CONSUME(lexer.Null, { LABEL: 'value' }); } },
574
- { ALT: function () { return _this.CONSUME(lexer.True, { LABEL: 'value' }); } },
575
- { ALT: function () { return _this.CONSUME(lexer.False, { LABEL: 'value' }); } },
576
- { ALT: function () { return _this.CONSUME(lexer.DateLiteral, { LABEL: 'value' }); } },
577
- { ALT: function () { return _this.SUBRULE(_this.dateNLiteral, { LABEL: 'value' }); } },
578
- { ALT: function () { return _this.CONSUME(lexer.GeolocationUnit, { LABEL: 'value' }); } },
579
- { ALT: function () { return _this.CONSUME(lexer.StringIdentifier, { LABEL: 'value' }); } },
580
- ]));
581
- },
582
- });
583
- _this.CONSUME(lexer.RParen);
584
- });
585
- _this.relationalOperator = _this.RULE('relationalOperator', function () {
586
- _this.OR(_this.$_relationalOperator ||
587
- (_this.$_relationalOperator = [
588
- { ALT: function () { return _this.CONSUME(lexer.Equal, { LABEL: 'operator' }); } },
589
- { ALT: function () { return _this.CONSUME(lexer.NotEqual, { LABEL: 'operator' }); } },
590
- { ALT: function () { return _this.CONSUME(lexer.GreaterThan, { LABEL: 'operator' }); } },
591
- { ALT: function () { return _this.CONSUME(lexer.GreaterThanOrEqual, { LABEL: 'operator' }); } },
592
- { ALT: function () { return _this.CONSUME(lexer.LessThan, { LABEL: 'operator' }); } },
593
- { ALT: function () { return _this.CONSUME(lexer.LessThanOrEqual, { LABEL: 'operator' }); } },
594
- { ALT: function () { return _this.CONSUME(lexer.Like, { LABEL: 'operator' }); } },
595
- ]));
596
- });
597
- _this.setOperator = _this.RULE('setOperator', function () {
598
- _this.OR([
599
- { ALT: function () { return _this.CONSUME(lexer.In, { LABEL: 'operator' }); } },
600
- { ALT: function () { return _this.SUBRULE(_this.notInOperator, { LABEL: 'notIn' }); } },
601
- { ALT: function () { return _this.CONSUME(lexer.Includes, { LABEL: 'operator' }); } },
602
- { ALT: function () { return _this.CONSUME(lexer.Excludes, { LABEL: 'operator' }); } },
603
- ]);
604
- });
605
- _this.notInOperator = _this.RULE('notInOperator', function () {
606
- _this.CONSUME(lexer.Not, { LABEL: 'operator' });
607
- _this.CONSUME(lexer.In, { LABEL: 'operator' });
608
- });
609
- _this.booleanValue = _this.RULE('booleanValue', function () {
610
- _this.OR([
611
- { ALT: function () { return _this.CONSUME(lexer.True, { LABEL: 'boolean' }); } },
612
- { ALT: function () { return _this.CONSUME(lexer.False, { LABEL: 'boolean' }); } },
613
- ]);
614
- });
615
- _this.dateNLiteral = _this.RULE('dateNLiteral', function () {
616
- _this.CONSUME(lexer.DateNLiteral, { LABEL: 'dateNLiteral' });
617
- _this.CONSUME(lexer.Colon);
618
- _this.OR1([
619
- { ALT: function () { return _this.CONSUME(lexer.UnsignedInteger, { LABEL: 'variable' }); } },
620
- { ALT: function () { return _this.CONSUME(lexer.SignedInteger, { LABEL: 'variable' }); } },
621
- ]);
622
- });
623
- _this.forViewOrReference = _this.RULE('forViewOrReference', function () {
624
- _this.CONSUME(lexer.For);
625
- _this.OR([
626
- { ALT: function () { return _this.CONSUME(lexer.View, { LABEL: 'value' }); } },
627
- { ALT: function () { return _this.CONSUME(lexer.Reference, { LABEL: 'value' }); } },
628
- { ALT: function () { return _this.CONSUME(lexer.Update, { LABEL: 'value' }); } },
629
- ]);
630
- });
631
- _this.updateTrackingViewstat = _this.RULE('updateTrackingViewstat', function () {
632
- _this.CONSUME(lexer.Update);
633
- _this.OR([
634
- { ALT: function () { return _this.CONSUME(lexer.Tracking, { LABEL: 'value' }); } },
635
- { ALT: function () { return _this.CONSUME(lexer.Viewstat, { LABEL: 'value' }); } },
636
- ]);
637
- });
638
- _this.ignoreParseErrors = !!ignoreParseErrors;
639
- _this.performSelfAnalysis();
640
- return _this;
641
- }
642
- SoqlParser.prototype.$_checkBalancedParens = function (parenCount) {
643
- if (!this.RECORDING_PHASE && parenCount) {
644
- var parenMatch = parenCount.left - parenCount.right;
645
- if (parenMatch !== 0) {
646
- this.CONSUME(lexer.RParenMismatch, { ERR_MSG: "Expecting a token type of --> RParen <-- but found --> '' <--" });
647
- }
648
- }
649
- };
650
- SoqlParser.prototype.getParenCount = function (parenCount) {
651
- return parenCount || { right: 0, left: 0 };
652
- };
653
- return SoqlParser;
654
- }(chevrotain_1.CstParser));
655
- exports.SoqlParser = SoqlParser;
656
- var parser = new SoqlParser();
657
- function parse(soql, options) {
658
- var _a = options || {
659
- allowApexBindVariables: false,
660
- logErrors: false,
661
- ignoreParseErrors: false,
662
- }, allowApexBindVariables = _a.allowApexBindVariables, logErrors = _a.logErrors, ignoreParseErrors = _a.ignoreParseErrors, allowPartialQuery = _a.allowPartialQuery;
663
- var lexResult = lexer.lex(soql);
664
- if (lexResult.errors.length > 0) {
665
- if (logErrors) {
666
- console.log('Lexing Errors:');
667
- console.log(lexResult.errors);
668
- }
669
- throw new LexingError(lexResult.errors[0]);
670
- }
671
- if (parser.ignoreParseErrors !== ignoreParseErrors) {
672
- parser = new SoqlParser({ ignoreParseErrors: ignoreParseErrors });
673
- }
674
- parser.input = lexResult.tokens;
675
- parser.allowApexBindVariables = allowApexBindVariables || false;
676
- var cst;
677
- if (allowPartialQuery) {
678
- cst = parser.selectStatementPartial();
679
- }
680
- else {
681
- cst = parser.selectStatement();
682
- }
683
- if (parser.errors.length > 0) {
684
- if (logErrors) {
685
- console.log('Parsing Errors:');
686
- console.log(parser.errors);
687
- }
688
- if (!ignoreParseErrors) {
689
- throw new ParsingError(parser.errors[0]);
690
- }
691
- }
692
- return {
693
- cst: cst,
694
- parseErrors: parser.errors.map(function (err) { return new ParsingError(err); }),
695
- };
696
- }
697
- exports.parse = parse;