@jetstreamapp/soql-parser-js 6.0.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/AUTHORS.md +1 -0
- package/CHANGELOG.md +959 -0
- package/LICENSE.txt +12 -0
- package/README.md +949 -0
- package/bin/soql-parser-js +3 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.LICENSE.txt +1 -0
- package/dist/cjs/main.licenses.txt +898 -0
- package/dist/cjs/src/api/api-models.d.ts +175 -0
- package/dist/cjs/src/api/api-models.js +2 -0
- package/dist/cjs/src/api/public-utils.d.ts +29 -0
- package/dist/cjs/src/api/public-utils.js +175 -0
- package/dist/cjs/src/composer/composer.d.ts +32 -0
- package/dist/cjs/src/composer/composer.js +295 -0
- package/dist/cjs/src/formatter/formatter.d.ts +42 -0
- package/dist/cjs/src/formatter/formatter.js +236 -0
- package/dist/cjs/src/index.d.ts +5 -0
- package/dist/cjs/src/index.js +23 -0
- package/dist/cjs/src/models.d.ts +266 -0
- package/dist/cjs/src/models.js +2 -0
- package/dist/cjs/src/parser/lexer.d.ts +186 -0
- package/dist/cjs/src/parser/lexer.js +954 -0
- package/dist/cjs/src/parser/parser.d.ts +89 -0
- package/dist/cjs/src/parser/parser.js +697 -0
- package/dist/cjs/src/parser/visitor.d.ts +4 -0
- package/dist/cjs/src/parser/visitor.js +856 -0
- package/dist/cjs/src/utils.d.ts +42 -0
- package/dist/cjs/src/utils.js +245 -0
- package/dist/cli/index.js +113 -0
- package/dist/esm/api/api-models.js +1 -0
- package/dist/esm/api/public-utils.js +153 -0
- package/dist/esm/composer/composer.js +273 -0
- package/dist/esm/formatter/formatter.js +223 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/parser/lexer.js +947 -0
- package/dist/esm/parser/parser.js +667 -0
- package/dist/esm/parser/visitor.js +823 -0
- package/dist/esm/utils.js +200 -0
- package/dist/src/api/api-models.js +2 -0
- package/dist/src/api/public-utils.js +203 -0
- package/dist/src/composer/composer.js +358 -0
- package/dist/src/formatter/formatter.js +263 -0
- package/dist/src/index.js +28 -0
- package/dist/src/models.js +2 -0
- package/dist/src/parser/lexer.js +997 -0
- package/dist/src/parser/parser.js +711 -0
- package/dist/src/parser/visitor.js +862 -0
- package/dist/src/utils.js +251 -0
- package/package.json +78 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Compose = exports.composeQuery = exports.formatQuery = void 0;
|
|
15
|
+
var utils = require("../utils");
|
|
16
|
+
var formatter_1 = require("../formatter/formatter");
|
|
17
|
+
var visitor_1 = require("../parser/visitor");
|
|
18
|
+
function formatQuery(soql, formatOptions, parseOptions) {
|
|
19
|
+
return composeQuery((0, visitor_1.parseQuery)(soql, parseOptions), { format: true, formatOptions: formatOptions });
|
|
20
|
+
}
|
|
21
|
+
exports.formatQuery = formatQuery;
|
|
22
|
+
function composeQuery(soql, config) {
|
|
23
|
+
if (config === void 0) { config = {}; }
|
|
24
|
+
if (!soql) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
config = config || {};
|
|
28
|
+
config.format = config.format ? true : false;
|
|
29
|
+
if (config.logging) {
|
|
30
|
+
console.time('composer');
|
|
31
|
+
console.log('Composing Query:', soql);
|
|
32
|
+
console.log('Format output:', config.format);
|
|
33
|
+
}
|
|
34
|
+
var query = new Compose(soql, config).query;
|
|
35
|
+
if (config.logging) {
|
|
36
|
+
console.timeEnd('composer');
|
|
37
|
+
}
|
|
38
|
+
return query;
|
|
39
|
+
}
|
|
40
|
+
exports.composeQuery = composeQuery;
|
|
41
|
+
var Compose = (function () {
|
|
42
|
+
function Compose(soql, config) {
|
|
43
|
+
if (config === void 0) { config = {}; }
|
|
44
|
+
this.soql = soql;
|
|
45
|
+
this.logging = false;
|
|
46
|
+
this.format = false;
|
|
47
|
+
config = __assign({ autoCompose: true }, config);
|
|
48
|
+
var logging = config.logging, format = config.format;
|
|
49
|
+
this.logging = !!logging;
|
|
50
|
+
this.format = !!format;
|
|
51
|
+
this.query = '';
|
|
52
|
+
this.formatter = new formatter_1.Formatter(this.format, __assign({ logging: this.logging }, config.formatOptions));
|
|
53
|
+
if (config.autoCompose) {
|
|
54
|
+
this.start();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
Compose.prototype.start = function () {
|
|
58
|
+
this.query = this.parseQuery(this.soql);
|
|
59
|
+
};
|
|
60
|
+
Compose.prototype.log = function (soql) {
|
|
61
|
+
if (this.logging) {
|
|
62
|
+
console.log('Current SOQL:', soql);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
Compose.prototype.parseFn = function (fn) {
|
|
66
|
+
var _this = this;
|
|
67
|
+
var output;
|
|
68
|
+
if (fn.rawValue) {
|
|
69
|
+
output = fn.rawValue;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
output = fn.functionName;
|
|
73
|
+
output += "(".concat((fn.parameters || []).map(function (param) { return (utils.isString(param) ? param : _this.parseFn(param)); }).join(', '), ")");
|
|
74
|
+
}
|
|
75
|
+
if (fn.alias) {
|
|
76
|
+
output += " ".concat(fn.alias);
|
|
77
|
+
}
|
|
78
|
+
return output;
|
|
79
|
+
};
|
|
80
|
+
Compose.prototype.parseQuery = function (query) {
|
|
81
|
+
var _this = this;
|
|
82
|
+
var fieldData = {
|
|
83
|
+
fields: this.parseFields(query.fields || []).map(function (field) { return ({
|
|
84
|
+
text: field.text,
|
|
85
|
+
typeOfClause: field.typeOfClause,
|
|
86
|
+
isSubquery: field.text.startsWith('('),
|
|
87
|
+
prefix: '',
|
|
88
|
+
suffix: '',
|
|
89
|
+
}); }),
|
|
90
|
+
isSubquery: utils.isSubquery(query),
|
|
91
|
+
lineBreaks: [],
|
|
92
|
+
};
|
|
93
|
+
var output = '';
|
|
94
|
+
if (query.fields) {
|
|
95
|
+
output += this.formatter.formatClause('SELECT').trimStart();
|
|
96
|
+
}
|
|
97
|
+
this.formatter.formatFields(fieldData);
|
|
98
|
+
var fieldsOutput = '';
|
|
99
|
+
fieldData.fields.forEach(function (field) {
|
|
100
|
+
if (Array.isArray(field.typeOfClause)) {
|
|
101
|
+
fieldsOutput += "".concat(field.prefix).concat(_this.formatter.formatTyeOfField(field.text, field.typeOfClause)).concat(field.suffix);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
fieldsOutput += "".concat(field.prefix).concat(field.text).concat(field.suffix);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
output += this.formatter.formatText(fieldsOutput);
|
|
108
|
+
if (!!(utils.isSubquery(query) ? query.relationshipName : query.sObject)) {
|
|
109
|
+
output += this.formatter.formatClause('FROM');
|
|
110
|
+
}
|
|
111
|
+
if (utils.isSubquery(query)) {
|
|
112
|
+
var sObjectPrefix = query.sObjectPrefix || [];
|
|
113
|
+
sObjectPrefix.push(query.relationshipName);
|
|
114
|
+
output += this.formatter.formatText("".concat(sObjectPrefix.join('.')).concat(utils.get(query.sObjectAlias, '', ' ')));
|
|
115
|
+
}
|
|
116
|
+
else if (query.sObject) {
|
|
117
|
+
output += this.formatter.formatText("".concat(query.sObject).concat(utils.get(query.sObjectAlias, '', ' ')));
|
|
118
|
+
}
|
|
119
|
+
this.log(output);
|
|
120
|
+
if (query.usingScope) {
|
|
121
|
+
output += this.formatter.formatClause('USING SCOPE');
|
|
122
|
+
output += this.formatter.formatText(query.usingScope);
|
|
123
|
+
this.log(output);
|
|
124
|
+
}
|
|
125
|
+
if (query.where) {
|
|
126
|
+
output += this.formatter.formatClause('WHERE');
|
|
127
|
+
output += this.formatter.formatText(this.parseWhereOrHavingClause(query.where));
|
|
128
|
+
this.log(output);
|
|
129
|
+
}
|
|
130
|
+
if (query.groupBy) {
|
|
131
|
+
output += this.formatter.formatClause('GROUP BY');
|
|
132
|
+
output += this.formatter.formatText(this.parseGroupByClause(query.groupBy));
|
|
133
|
+
this.log(output);
|
|
134
|
+
if (query.having) {
|
|
135
|
+
output += this.formatter.formatClause('HAVING');
|
|
136
|
+
output += this.formatter.formatText(this.parseWhereOrHavingClause(query.having));
|
|
137
|
+
this.log(output);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (query.orderBy && (!Array.isArray(query.orderBy) || query.orderBy.length > 0)) {
|
|
141
|
+
output += this.formatter.formatClause('ORDER BY');
|
|
142
|
+
output += this.formatter.formatText(this.parseOrderBy(query.orderBy));
|
|
143
|
+
this.log(output);
|
|
144
|
+
}
|
|
145
|
+
if (utils.isNumber(query.limit)) {
|
|
146
|
+
output += this.formatter.formatClause('LIMIT');
|
|
147
|
+
output += this.formatter.formatText("".concat(query.limit));
|
|
148
|
+
this.log(output);
|
|
149
|
+
}
|
|
150
|
+
if (utils.isNumber(query.offset)) {
|
|
151
|
+
output += this.formatter.formatClause('OFFSET');
|
|
152
|
+
output += this.formatter.formatText("".concat(query.offset));
|
|
153
|
+
this.log(output);
|
|
154
|
+
}
|
|
155
|
+
if (query.withDataCategory) {
|
|
156
|
+
output += this.formatter.formatClause('WITH DATA CATEGORY');
|
|
157
|
+
output += this.formatter.formatText(this.parseWithDataCategory(query.withDataCategory));
|
|
158
|
+
this.log(output);
|
|
159
|
+
}
|
|
160
|
+
if (query.withSecurityEnforced) {
|
|
161
|
+
output += this.formatter.formatClause('WITH SECURITY_ENFORCED');
|
|
162
|
+
this.log(output);
|
|
163
|
+
}
|
|
164
|
+
if (query.withAccessLevel) {
|
|
165
|
+
output += this.formatter.formatClause("WITH ".concat(query.withAccessLevel));
|
|
166
|
+
this.log(output);
|
|
167
|
+
}
|
|
168
|
+
if (query.for) {
|
|
169
|
+
output += this.formatter.formatClause('FOR');
|
|
170
|
+
output += this.formatter.formatText(query.for);
|
|
171
|
+
this.log(output);
|
|
172
|
+
}
|
|
173
|
+
if (query.update) {
|
|
174
|
+
output += this.formatter.formatClause('UPDATE');
|
|
175
|
+
output += this.formatter.formatText(query.update);
|
|
176
|
+
this.log(output);
|
|
177
|
+
}
|
|
178
|
+
return output.trim();
|
|
179
|
+
};
|
|
180
|
+
Compose.prototype.parseFields = function (fields) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
return fields.map(function (field) {
|
|
183
|
+
var text = '';
|
|
184
|
+
var typeOfClause;
|
|
185
|
+
var objPrefix = field.objectPrefix ? "".concat(field.objectPrefix, ".") : '';
|
|
186
|
+
switch (field.type) {
|
|
187
|
+
case 'Field': {
|
|
188
|
+
text = "".concat(objPrefix).concat(field.field).concat(field.alias ? " ".concat(field.alias) : '');
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 'FieldFunctionExpression': {
|
|
192
|
+
var params = '';
|
|
193
|
+
if (field.parameters) {
|
|
194
|
+
params = field.parameters
|
|
195
|
+
.map(function (param) { return (utils.isString(param) ? param : _this.parseFields([param]).map(function (param) { return param.text; })); })
|
|
196
|
+
.join(', ');
|
|
197
|
+
}
|
|
198
|
+
text = "".concat(field.functionName, "(").concat(params, ")").concat(field.alias ? " ".concat(field.alias) : '');
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'FieldRelationship': {
|
|
202
|
+
text = "".concat(objPrefix).concat(field.relationships.join('.'), ".").concat(field.field).concat(utils.hasAlias(field) ? " ".concat(field.alias) : '');
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'FieldSubquery': {
|
|
206
|
+
text = _this.formatter.formatSubquery(_this.parseQuery(field.subquery));
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'FieldTypeof': {
|
|
210
|
+
typeOfClause = _this.parseTypeOfField(field);
|
|
211
|
+
text = typeOfClause.join(' ');
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
return { text: text, typeOfClause: typeOfClause };
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
Compose.prototype.parseTypeOfField = function (typeOfField) {
|
|
221
|
+
var _this = this;
|
|
222
|
+
var output = ["TYPEOF ".concat(typeOfField.field)].concat(typeOfField.conditions.map(function (condition) { return _this.formatter.formatTypeofFieldCondition(condition); }));
|
|
223
|
+
output.push("END");
|
|
224
|
+
return output;
|
|
225
|
+
};
|
|
226
|
+
Compose.prototype.parseWhereOrHavingClause = function (whereOrHaving, tabOffset, priorConditionIsNegation) {
|
|
227
|
+
if (tabOffset === void 0) { tabOffset = 0; }
|
|
228
|
+
if (priorConditionIsNegation === void 0) { priorConditionIsNegation = false; }
|
|
229
|
+
var output = '';
|
|
230
|
+
var left = whereOrHaving.left;
|
|
231
|
+
var trimPrecedingOutput = false;
|
|
232
|
+
if (left) {
|
|
233
|
+
output += this.formatter.formatParens(left.openParen, '(', utils.isNegationCondition(left));
|
|
234
|
+
if (!utils.isNegationCondition(left)) {
|
|
235
|
+
tabOffset = tabOffset + (left.openParen || 0) - (left.closeParen || 0);
|
|
236
|
+
if (priorConditionIsNegation) {
|
|
237
|
+
tabOffset++;
|
|
238
|
+
}
|
|
239
|
+
var expression = '';
|
|
240
|
+
expression += utils.isValueFunctionCondition(left) ? this.parseFn(left.fn) : left.field;
|
|
241
|
+
expression += " ".concat(left.operator, " ");
|
|
242
|
+
if (utils.isValueQueryCondition(left)) {
|
|
243
|
+
expression += this.formatter.formatSubquery(this.parseQuery(left.valueQuery), 1, true);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
expression += utils.getAsArrayStr(utils.getWhereValue(left.value, left.literalType, left.operator));
|
|
247
|
+
}
|
|
248
|
+
output += this.formatter.formatWithIndent(expression);
|
|
249
|
+
output += this.formatter.formatParens(left.closeParen, ')', priorConditionIsNegation);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (utils.isWhereOrHavingClauseWithRightCondition(whereOrHaving)) {
|
|
253
|
+
var operator = utils.get(whereOrHaving.operator);
|
|
254
|
+
trimPrecedingOutput = operator === 'NOT';
|
|
255
|
+
var formattedData = this.formatter.formatWhereClauseOperators(operator, this.parseWhereOrHavingClause(whereOrHaving.right, tabOffset, utils.isNegationCondition(left)), tabOffset);
|
|
256
|
+
return "".concat(trimPrecedingOutput ? output.trimRight() : output).concat(formattedData).trim();
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return output.trim();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
Compose.prototype.parseGroupByClause = function (groupBy) {
|
|
263
|
+
var _this = this;
|
|
264
|
+
return (Array.isArray(groupBy) ? groupBy : [groupBy])
|
|
265
|
+
.map(function (clause) { return (utils.isGroupByField(clause) ? clause.field : _this.parseFn(clause.fn)); })
|
|
266
|
+
.join(', ');
|
|
267
|
+
};
|
|
268
|
+
Compose.prototype.parseOrderBy = function (orderBy) {
|
|
269
|
+
var _this = this;
|
|
270
|
+
if (Array.isArray(orderBy)) {
|
|
271
|
+
return this.formatter.formatOrderByArray(orderBy.map(function (ob) { return _this.parseOrderBy(ob); }));
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
var output = '';
|
|
275
|
+
if (utils.isOrderByField(orderBy)) {
|
|
276
|
+
output = "".concat(utils.get(orderBy.field, ' '));
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
output += "".concat(this.parseFn(orderBy.fn), " ");
|
|
280
|
+
}
|
|
281
|
+
output += "".concat(utils.get(orderBy.order, ' ')).concat(utils.get(orderBy.nulls, '', 'NULLS '));
|
|
282
|
+
return output.trim();
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
Compose.prototype.parseWithDataCategory = function (withDataCategory) {
|
|
286
|
+
return withDataCategory.conditions
|
|
287
|
+
.map(function (condition) {
|
|
288
|
+
var params = condition.parameters.length > 1 ? "(".concat(condition.parameters.join(', '), ")") : "".concat(condition.parameters.join(', '));
|
|
289
|
+
return "".concat(condition.groupName, " ").concat(condition.selector, " ").concat(params);
|
|
290
|
+
})
|
|
291
|
+
.join(' AND ');
|
|
292
|
+
};
|
|
293
|
+
return Compose;
|
|
294
|
+
}());
|
|
295
|
+
exports.Compose = Compose;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FieldTypeOfCondition } from '../api/api-models';
|
|
2
|
+
export interface FieldData {
|
|
3
|
+
fields: {
|
|
4
|
+
text: string;
|
|
5
|
+
typeOfClause?: string[];
|
|
6
|
+
isSubquery: boolean;
|
|
7
|
+
prefix: string;
|
|
8
|
+
suffix: string;
|
|
9
|
+
}[];
|
|
10
|
+
isSubquery: boolean;
|
|
11
|
+
lineBreaks: number[];
|
|
12
|
+
}
|
|
13
|
+
export interface FormatOptions {
|
|
14
|
+
numIndent?: number;
|
|
15
|
+
fieldMaxLineLength?: number;
|
|
16
|
+
fieldSubqueryParensOnOwnLine?: boolean;
|
|
17
|
+
whereClauseOperatorsIndented?: boolean;
|
|
18
|
+
newLineAfterKeywords?: boolean;
|
|
19
|
+
logging?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class Formatter {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
private options;
|
|
24
|
+
private currIndent;
|
|
25
|
+
constructor(enabled: boolean, options: FormatOptions);
|
|
26
|
+
private log;
|
|
27
|
+
private getIndent;
|
|
28
|
+
private repeatChar;
|
|
29
|
+
setSubquery(isSubquery: boolean): void;
|
|
30
|
+
stepCurrIndex(num: number): void;
|
|
31
|
+
formatFields(fieldData: FieldData): void;
|
|
32
|
+
formatTyeOfField(text: string, typeOfClause: string[]): string;
|
|
33
|
+
formatTypeofFieldCondition(condition: FieldTypeOfCondition): string;
|
|
34
|
+
formatSubquery(queryStr: string, numTabs?: number, incrementTabsWhereClauseOpIndent?: boolean): string;
|
|
35
|
+
formatClause(clause: string): string;
|
|
36
|
+
formatText(text: string): string;
|
|
37
|
+
formatWithIndent(text: string): string;
|
|
38
|
+
formatOrderByArray(groupBy: string[]): string;
|
|
39
|
+
formatParens(count: number | undefined, character: '(' | ')', leadingParenInline?: boolean): string;
|
|
40
|
+
formatWhereClauseOperators(operator: string, whereClause: string, additionalIndent?: number): string;
|
|
41
|
+
formatAddNewLine(alt?: string, skipNewLineAndIndent?: boolean): string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Formatter = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
var Formatter = (function () {
|
|
6
|
+
function Formatter(enabled, options) {
|
|
7
|
+
var _a, _b, _c, _d, _e;
|
|
8
|
+
this.currIndent = 1;
|
|
9
|
+
this.enabled = enabled;
|
|
10
|
+
this.options = {
|
|
11
|
+
numIndent: (_a = options.numIndent) !== null && _a !== void 0 ? _a : 1,
|
|
12
|
+
fieldMaxLineLength: (_b = options.fieldMaxLineLength) !== null && _b !== void 0 ? _b : 60,
|
|
13
|
+
fieldSubqueryParensOnOwnLine: (_c = options.fieldSubqueryParensOnOwnLine) !== null && _c !== void 0 ? _c : true,
|
|
14
|
+
whereClauseOperatorsIndented: true,
|
|
15
|
+
newLineAfterKeywords: (_d = options.newLineAfterKeywords) !== null && _d !== void 0 ? _d : false,
|
|
16
|
+
logging: (_e = options.logging) !== null && _e !== void 0 ? _e : false,
|
|
17
|
+
};
|
|
18
|
+
if (this.options.newLineAfterKeywords) {
|
|
19
|
+
this.options.fieldSubqueryParensOnOwnLine = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
Formatter.prototype.log = function (data) {
|
|
23
|
+
if (this.options.logging) {
|
|
24
|
+
console.log(data);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
Formatter.prototype.getIndent = function (additionalIndent) {
|
|
28
|
+
if (additionalIndent === void 0) { additionalIndent = 0; }
|
|
29
|
+
return this.repeatChar((this.currIndent + additionalIndent) * (this.options.numIndent || 1), '\t');
|
|
30
|
+
};
|
|
31
|
+
Formatter.prototype.repeatChar = function (numTimes, char) {
|
|
32
|
+
return new Array(numTimes).fill(char).join('');
|
|
33
|
+
};
|
|
34
|
+
Formatter.prototype.setSubquery = function (isSubquery) {
|
|
35
|
+
this.currIndent = isSubquery ? (this.currIndent += 1) : (this.currIndent -= 1);
|
|
36
|
+
};
|
|
37
|
+
Formatter.prototype.stepCurrIndex = function (num) {
|
|
38
|
+
this.currIndent += num;
|
|
39
|
+
};
|
|
40
|
+
Formatter.prototype.formatFields = function (fieldData) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
function trimPrevSuffix(currIdx) {
|
|
43
|
+
if (fieldData.fields[currIdx - 1]) {
|
|
44
|
+
fieldData.fields[currIdx - 1].suffix = fieldData.fields[currIdx - 1].suffix.trim();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
fieldData.fields.forEach(function (field, i) {
|
|
48
|
+
field.suffix = fieldData.fields.length - 1 === i ? '' : ', ';
|
|
49
|
+
});
|
|
50
|
+
if (this.enabled) {
|
|
51
|
+
var lineLen_1 = 0;
|
|
52
|
+
var newLineAndIndentNext_1 = false;
|
|
53
|
+
fieldData.fields.forEach(function (field, i) {
|
|
54
|
+
if (field.isSubquery) {
|
|
55
|
+
trimPrevSuffix(i);
|
|
56
|
+
field.prefix = "\n".concat(_this.getIndent());
|
|
57
|
+
field.suffix = fieldData.fields.length - 1 === i ? '' : ', ';
|
|
58
|
+
lineLen_1 = 0;
|
|
59
|
+
newLineAndIndentNext_1 = true;
|
|
60
|
+
}
|
|
61
|
+
else if (Array.isArray(field.typeOfClause)) {
|
|
62
|
+
trimPrevSuffix(i);
|
|
63
|
+
field.prefix = "\n".concat(_this.getIndent());
|
|
64
|
+
newLineAndIndentNext_1 = true;
|
|
65
|
+
}
|
|
66
|
+
else if ((0, utils_1.isNumber)(_this.options.fieldMaxLineLength)) {
|
|
67
|
+
lineLen_1 += field.text.length + field.suffix.length;
|
|
68
|
+
if (lineLen_1 > _this.options.fieldMaxLineLength || newLineAndIndentNext_1) {
|
|
69
|
+
trimPrevSuffix(i);
|
|
70
|
+
if (!_this.options.newLineAfterKeywords || i > 0) {
|
|
71
|
+
field.prefix += "\n".concat(_this.getIndent());
|
|
72
|
+
}
|
|
73
|
+
lineLen_1 = 0;
|
|
74
|
+
newLineAndIndentNext_1 = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_this.log(field);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
Formatter.prototype.formatTyeOfField = function (text, typeOfClause) {
|
|
82
|
+
var _this = this;
|
|
83
|
+
if (this.enabled && this.options.newLineAfterKeywords) {
|
|
84
|
+
return typeOfClause
|
|
85
|
+
.map(function (part, i) {
|
|
86
|
+
if (i === 0) {
|
|
87
|
+
return part;
|
|
88
|
+
}
|
|
89
|
+
else if (i === typeOfClause.length - 1) {
|
|
90
|
+
return "".concat(_this.getIndent()).concat(part);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return "".concat(_this.getIndent(), "\t").concat(part);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.join('\n');
|
|
97
|
+
}
|
|
98
|
+
return text;
|
|
99
|
+
};
|
|
100
|
+
Formatter.prototype.formatTypeofFieldCondition = function (condition) {
|
|
101
|
+
var output = '';
|
|
102
|
+
var fields = condition.fieldList.join(', ');
|
|
103
|
+
if (this.enabled && this.options.newLineAfterKeywords) {
|
|
104
|
+
var indent = this.getIndent();
|
|
105
|
+
output = "".concat(condition.type);
|
|
106
|
+
if (condition.objectType) {
|
|
107
|
+
output += "\n".concat(indent, "\t\t").concat(condition.objectType, "\n").concat(indent, "\tTHEN\n").concat(indent, "\t\t").concat(fields);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
output += "\n".concat(indent, "\t\t").concat(fields);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
output = condition.type;
|
|
115
|
+
if (condition.objectType) {
|
|
116
|
+
output += " ".concat(condition.objectType, " THEN ").concat(fields);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
output += " ".concat(fields);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return output;
|
|
123
|
+
};
|
|
124
|
+
Formatter.prototype.formatSubquery = function (queryStr, numTabs, incrementTabsWhereClauseOpIndent) {
|
|
125
|
+
if (numTabs === void 0) { numTabs = 2; }
|
|
126
|
+
if (incrementTabsWhereClauseOpIndent === void 0) { incrementTabsWhereClauseOpIndent = false; }
|
|
127
|
+
if (incrementTabsWhereClauseOpIndent) {
|
|
128
|
+
numTabs++;
|
|
129
|
+
}
|
|
130
|
+
var leftParen = '(';
|
|
131
|
+
var rightParen = ')';
|
|
132
|
+
if (this.enabled) {
|
|
133
|
+
if (this.options.fieldSubqueryParensOnOwnLine || this.options.newLineAfterKeywords) {
|
|
134
|
+
queryStr = queryStr.replace(/\n/g, "\n".concat(this.repeatChar(numTabs, '\t')));
|
|
135
|
+
leftParen = "(\n".concat(this.repeatChar(numTabs, '\t'));
|
|
136
|
+
rightParen = "\n".concat(this.repeatChar(numTabs - 1, '\t'), ")");
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
queryStr = queryStr.replace(/\n/g, '\n\t');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return "".concat(leftParen).concat(queryStr).concat(rightParen);
|
|
143
|
+
};
|
|
144
|
+
Formatter.prototype.formatClause = function (clause) {
|
|
145
|
+
if (this.enabled) {
|
|
146
|
+
return this.options.newLineAfterKeywords ? "\n".concat(clause, "\n\t") : "\n".concat(clause);
|
|
147
|
+
}
|
|
148
|
+
return " ".concat(clause);
|
|
149
|
+
};
|
|
150
|
+
Formatter.prototype.formatText = function (text) {
|
|
151
|
+
return this.enabled && (this.options.newLineAfterKeywords || text.startsWith('\n')) ? text : " ".concat(text);
|
|
152
|
+
};
|
|
153
|
+
Formatter.prototype.formatWithIndent = function (text) {
|
|
154
|
+
return this.enabled ? "".concat(this.getIndent()).concat(text) : text;
|
|
155
|
+
};
|
|
156
|
+
Formatter.prototype.formatOrderByArray = function (groupBy) {
|
|
157
|
+
var _this = this;
|
|
158
|
+
if (this.enabled) {
|
|
159
|
+
var currLen_1 = 0;
|
|
160
|
+
var output_1 = '';
|
|
161
|
+
groupBy.forEach(function (token, i) {
|
|
162
|
+
var nextToken = groupBy[i + 1];
|
|
163
|
+
currLen_1 += token.length;
|
|
164
|
+
if (nextToken && (currLen_1 + nextToken.length > (_this.options.fieldMaxLineLength || 0) || _this.options.newLineAfterKeywords)) {
|
|
165
|
+
output_1 += "".concat(token, ",\n\t");
|
|
166
|
+
currLen_1 = 0;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
output_1 += "".concat(token).concat(nextToken ? ', ' : '');
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return output_1;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return groupBy.join(', ');
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
Formatter.prototype.formatParens = function (count, character, leadingParenInline) {
|
|
179
|
+
if (leadingParenInline === void 0) { leadingParenInline = false; }
|
|
180
|
+
var output = '';
|
|
181
|
+
if ((0, utils_1.isNumber)(count) && count > 0) {
|
|
182
|
+
if (this.enabled) {
|
|
183
|
+
if (character === '(') {
|
|
184
|
+
for (var i = 0; i < count; i++) {
|
|
185
|
+
if (leadingParenInline && i === count - 1) {
|
|
186
|
+
output += '(';
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
if (i === 0) {
|
|
190
|
+
output += '(\n';
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
this.currIndent++;
|
|
194
|
+
output += "".concat(this.getIndent(), "(\n");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (!leadingParenInline || count > 1) {
|
|
199
|
+
this.currIndent++;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
for (var i = count - 1; i >= 0; i--) {
|
|
204
|
+
if (leadingParenInline && i === count - 1) {
|
|
205
|
+
output += ')';
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
this.currIndent--;
|
|
209
|
+
output += "\n".concat(this.getIndent(), ")");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
output += (0, utils_1.generateParens)(count, character);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return output;
|
|
219
|
+
};
|
|
220
|
+
Formatter.prototype.formatWhereClauseOperators = function (operator, whereClause, additionalIndent) {
|
|
221
|
+
if (additionalIndent === void 0) { additionalIndent = 0; }
|
|
222
|
+
var skipNewLineAndIndent = operator === 'NOT';
|
|
223
|
+
if (this.enabled && !skipNewLineAndIndent) {
|
|
224
|
+
return "\n".concat(this.getIndent(additionalIndent)).concat(operator, " ").concat(whereClause);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
return "".concat(skipNewLineAndIndent ? '' : ' ').concat(operator, " ").concat(whereClause);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
Formatter.prototype.formatAddNewLine = function (alt, skipNewLineAndIndent) {
|
|
231
|
+
if (alt === void 0) { alt = ' '; }
|
|
232
|
+
return this.enabled && !skipNewLineAndIndent ? "\n" : alt;
|
|
233
|
+
};
|
|
234
|
+
return Formatter;
|
|
235
|
+
}());
|
|
236
|
+
exports.Formatter = Formatter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isQueryValid = exports.parseQuery = void 0;
|
|
18
|
+
var visitor_1 = require("./parser/visitor");
|
|
19
|
+
Object.defineProperty(exports, "parseQuery", { enumerable: true, get: function () { return visitor_1.parseQuery; } });
|
|
20
|
+
Object.defineProperty(exports, "isQueryValid", { enumerable: true, get: function () { return visitor_1.isQueryValid; } });
|
|
21
|
+
__exportStar(require("./api/api-models"), exports);
|
|
22
|
+
__exportStar(require("./api/public-utils"), exports);
|
|
23
|
+
__exportStar(require("./composer/composer"), exports);
|