@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,42 @@
|
|
|
1
|
+
import { IToken } from 'chevrotain';
|
|
2
|
+
import { FieldFunctionExpression, FieldRelationshipWithAlias, FieldSubquery, FieldWithAlias, GroupByFieldClause, GroupByFnClause, HavingClauseWithRightCondition, LiteralType, NegationCondition, Operator, OrderByFieldClause, OrderByFnClause, Query, Subquery, ValueCondition, ValueFunctionCondition, ValueQueryCondition, ValueWithDateLiteralCondition, ValueWithDateNLiteralCondition, WhereClauseWithRightCondition } from './api/api-models';
|
|
3
|
+
import { ComposeField, ComposeFieldFunction, ComposeFieldRelationship, ComposeFieldSubquery, ComposeFieldTypeof } from './api/public-utils';
|
|
4
|
+
export declare function isToken(val: any): val is IToken[] | IToken;
|
|
5
|
+
export declare function isSubqueryFromFlag(val: any, isSubquery: boolean): val is Subquery;
|
|
6
|
+
export declare function isString(val: any): val is string;
|
|
7
|
+
export declare function isStringArray(val: any[]): val is string[];
|
|
8
|
+
export declare function isNumber(val: any): val is number;
|
|
9
|
+
export declare function isBoolean(val: any): val is boolean;
|
|
10
|
+
export declare function isObject(val: any): val is any;
|
|
11
|
+
export declare function isNil(val: any): val is null | undefined;
|
|
12
|
+
export declare function get(val: string | null | undefined, suffix?: string, prefix?: string): string;
|
|
13
|
+
export declare function getIfTrue(val: boolean | null | undefined, returnStr: string): string;
|
|
14
|
+
export declare function getLastItem<T>(arr: T[]): T;
|
|
15
|
+
export declare function getAsArrayStr(val: string | string[], alwaysParens?: boolean): string;
|
|
16
|
+
export declare function pad(val: string, len: number, left?: number): string;
|
|
17
|
+
export declare function generateParens(count: number, character: '(' | ')', joinCharacter?: string): string;
|
|
18
|
+
export declare function getParams(functionFieldExp: FieldFunctionExpression): string[];
|
|
19
|
+
export declare function isNestedParamAggregateFunction(functionFieldExp: FieldFunctionExpression): boolean;
|
|
20
|
+
export declare function hasAlias(value: any): value is FieldWithAlias | FieldRelationshipWithAlias;
|
|
21
|
+
export declare function isComposeField(input: any): input is ComposeField;
|
|
22
|
+
export declare function isComposeFieldFunction(input: any): input is ComposeFieldFunction;
|
|
23
|
+
export declare function isComposeFieldRelationship(input: any): input is ComposeFieldRelationship;
|
|
24
|
+
export declare function isComposeFieldSubquery(input: any): input is ComposeFieldSubquery;
|
|
25
|
+
export declare function isComposeFieldTypeof(input: any): input is ComposeFieldTypeof;
|
|
26
|
+
export declare function isSubquery(query: Query | Subquery): query is Subquery;
|
|
27
|
+
export declare function isFieldSubquery(value: any): value is FieldSubquery;
|
|
28
|
+
export declare function isWhereClauseWithRightCondition(value: any): value is WhereClauseWithRightCondition;
|
|
29
|
+
export declare function isHavingClauseWithRightCondition(value: any): value is HavingClauseWithRightCondition;
|
|
30
|
+
export declare function isWhereOrHavingClauseWithRightCondition(value: any): value is WhereClauseWithRightCondition | HavingClauseWithRightCondition;
|
|
31
|
+
export declare function isValueCondition(value: any): value is ValueCondition;
|
|
32
|
+
export declare function isValueWithDateLiteralCondition(value: any): value is ValueWithDateLiteralCondition;
|
|
33
|
+
export declare function isValueWithDateNLiteralCondition(value: any): value is ValueWithDateNLiteralCondition;
|
|
34
|
+
export declare function isValueFunctionCondition(value: any): value is ValueFunctionCondition;
|
|
35
|
+
export declare function isNegationCondition(value: any): value is NegationCondition;
|
|
36
|
+
export declare function isValueQueryCondition(value: any): value is ValueQueryCondition;
|
|
37
|
+
export declare function isOrderByField(value: any): value is OrderByFieldClause;
|
|
38
|
+
export declare function isOrderByFn(value: any): value is OrderByFnClause;
|
|
39
|
+
export declare function isGroupByField(value: any): value is GroupByFieldClause;
|
|
40
|
+
export declare function isGroupByFn(value: any): value is GroupByFnClause;
|
|
41
|
+
export declare function isArrayOperator(operator: Operator): boolean;
|
|
42
|
+
export declare function getWhereValue(value: any | any[], literalType?: LiteralType | LiteralType[], operator?: Operator): any;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWhereValue = exports.isArrayOperator = exports.isGroupByFn = exports.isGroupByField = exports.isOrderByFn = exports.isOrderByField = exports.isValueQueryCondition = exports.isNegationCondition = exports.isValueFunctionCondition = exports.isValueWithDateNLiteralCondition = exports.isValueWithDateLiteralCondition = exports.isValueCondition = exports.isWhereOrHavingClauseWithRightCondition = exports.isHavingClauseWithRightCondition = exports.isWhereClauseWithRightCondition = exports.isFieldSubquery = exports.isSubquery = exports.isComposeFieldTypeof = exports.isComposeFieldSubquery = exports.isComposeFieldRelationship = exports.isComposeFieldFunction = exports.isComposeField = exports.hasAlias = exports.isNestedParamAggregateFunction = exports.getParams = exports.generateParens = exports.pad = exports.getAsArrayStr = exports.getLastItem = exports.getIfTrue = exports.get = exports.isNil = exports.isObject = exports.isBoolean = exports.isNumber = exports.isStringArray = exports.isString = exports.isSubqueryFromFlag = exports.isToken = void 0;
|
|
4
|
+
function isToken(val) {
|
|
5
|
+
val = Array.isArray(val) ? val[0] : val;
|
|
6
|
+
return val.image && true;
|
|
7
|
+
}
|
|
8
|
+
exports.isToken = isToken;
|
|
9
|
+
function isSubqueryFromFlag(val, isSubquery) {
|
|
10
|
+
return isSubquery;
|
|
11
|
+
}
|
|
12
|
+
exports.isSubqueryFromFlag = isSubqueryFromFlag;
|
|
13
|
+
function isString(val) {
|
|
14
|
+
return typeof val === 'string';
|
|
15
|
+
}
|
|
16
|
+
exports.isString = isString;
|
|
17
|
+
function isStringArray(val) {
|
|
18
|
+
if (!val) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return val.every(function (item) { return isString(item); });
|
|
22
|
+
}
|
|
23
|
+
exports.isStringArray = isStringArray;
|
|
24
|
+
function isNumber(val) {
|
|
25
|
+
return Number.isFinite(val);
|
|
26
|
+
}
|
|
27
|
+
exports.isNumber = isNumber;
|
|
28
|
+
function isBoolean(val) {
|
|
29
|
+
return typeof val === typeof true;
|
|
30
|
+
}
|
|
31
|
+
exports.isBoolean = isBoolean;
|
|
32
|
+
function isObject(val) {
|
|
33
|
+
return val instanceof Object;
|
|
34
|
+
}
|
|
35
|
+
exports.isObject = isObject;
|
|
36
|
+
function isNil(val) {
|
|
37
|
+
return val === null || val === undefined;
|
|
38
|
+
}
|
|
39
|
+
exports.isNil = isNil;
|
|
40
|
+
function get(val, suffix, prefix) {
|
|
41
|
+
return isNil(val) ? '' : "".concat(prefix || '').concat(val).concat(suffix || '');
|
|
42
|
+
}
|
|
43
|
+
exports.get = get;
|
|
44
|
+
function getIfTrue(val, returnStr) {
|
|
45
|
+
return isBoolean(val) && val ? returnStr : '';
|
|
46
|
+
}
|
|
47
|
+
exports.getIfTrue = getIfTrue;
|
|
48
|
+
function getLastItem(arr) {
|
|
49
|
+
return arr[arr.length - 1];
|
|
50
|
+
}
|
|
51
|
+
exports.getLastItem = getLastItem;
|
|
52
|
+
function getAsArrayStr(val, alwaysParens) {
|
|
53
|
+
if (alwaysParens === void 0) { alwaysParens = false; }
|
|
54
|
+
if (Array.isArray(val)) {
|
|
55
|
+
if (val.length > 0) {
|
|
56
|
+
return "(".concat(val.join(', '), ")");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return alwaysParens ? '()' : '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return alwaysParens ? "(".concat(val || '', ")") : val || '';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.getAsArrayStr = getAsArrayStr;
|
|
67
|
+
function pad(val, len, left) {
|
|
68
|
+
if (left === void 0) { left = 0; }
|
|
69
|
+
var leftPad = left > 0 ? new Array(left).fill(' ').join('') : '';
|
|
70
|
+
if (val.length > len) {
|
|
71
|
+
return "".concat(leftPad).concat(val);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return "".concat(leftPad).concat(val).concat(new Array(len - val.length).fill(' ').join(''));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.pad = pad;
|
|
78
|
+
function generateParens(count, character, joinCharacter) {
|
|
79
|
+
if (joinCharacter === void 0) { joinCharacter = ''; }
|
|
80
|
+
return isNumber(count) && count > 0 ? new Array(count).fill(character).join(joinCharacter) : '';
|
|
81
|
+
}
|
|
82
|
+
exports.generateParens = generateParens;
|
|
83
|
+
function getParams(functionFieldExp) {
|
|
84
|
+
if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
if (isStringArray(functionFieldExp.parameters)) {
|
|
88
|
+
return functionFieldExp.parameters;
|
|
89
|
+
}
|
|
90
|
+
if (isString(functionFieldExp.parameters[0])) {
|
|
91
|
+
return [functionFieldExp.parameters[0]];
|
|
92
|
+
}
|
|
93
|
+
return getParams(functionFieldExp.parameters[0]);
|
|
94
|
+
}
|
|
95
|
+
exports.getParams = getParams;
|
|
96
|
+
function isNestedParamAggregateFunction(functionFieldExp) {
|
|
97
|
+
if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
var parameter = functionFieldExp.parameters[0];
|
|
101
|
+
if (isString(parameter)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return !!parameter.isAggregateFn;
|
|
105
|
+
}
|
|
106
|
+
exports.isNestedParamAggregateFunction = isNestedParamAggregateFunction;
|
|
107
|
+
function hasAlias(value) {
|
|
108
|
+
return value && !isNil(value.alias);
|
|
109
|
+
}
|
|
110
|
+
exports.hasAlias = hasAlias;
|
|
111
|
+
function isComposeField(input) {
|
|
112
|
+
return isString(input.field) && !Array.isArray(input.relationships) && !Array.isArray(input.conditions);
|
|
113
|
+
}
|
|
114
|
+
exports.isComposeField = isComposeField;
|
|
115
|
+
function isComposeFieldFunction(input) {
|
|
116
|
+
return !isNil(input.functionName || input.fn);
|
|
117
|
+
}
|
|
118
|
+
exports.isComposeFieldFunction = isComposeFieldFunction;
|
|
119
|
+
function isComposeFieldRelationship(input) {
|
|
120
|
+
return isString(input.field) && Array.isArray(input.relationships);
|
|
121
|
+
}
|
|
122
|
+
exports.isComposeFieldRelationship = isComposeFieldRelationship;
|
|
123
|
+
function isComposeFieldSubquery(input) {
|
|
124
|
+
return !isNil(input.subquery);
|
|
125
|
+
}
|
|
126
|
+
exports.isComposeFieldSubquery = isComposeFieldSubquery;
|
|
127
|
+
function isComposeFieldTypeof(input) {
|
|
128
|
+
return isString(input.field) && Array.isArray(input.conditions);
|
|
129
|
+
}
|
|
130
|
+
exports.isComposeFieldTypeof = isComposeFieldTypeof;
|
|
131
|
+
function isSubquery(query) {
|
|
132
|
+
return isString(query.relationshipName);
|
|
133
|
+
}
|
|
134
|
+
exports.isSubquery = isSubquery;
|
|
135
|
+
function isFieldSubquery(value) {
|
|
136
|
+
return !!value && !!value.type && value.type === 'FieldSubquery';
|
|
137
|
+
}
|
|
138
|
+
exports.isFieldSubquery = isFieldSubquery;
|
|
139
|
+
function isWhereClauseWithRightCondition(value) {
|
|
140
|
+
return !!value && !!value.operator && !!value.right;
|
|
141
|
+
}
|
|
142
|
+
exports.isWhereClauseWithRightCondition = isWhereClauseWithRightCondition;
|
|
143
|
+
function isHavingClauseWithRightCondition(value) {
|
|
144
|
+
return !!value && !!value.operator && !!value.right;
|
|
145
|
+
}
|
|
146
|
+
exports.isHavingClauseWithRightCondition = isHavingClauseWithRightCondition;
|
|
147
|
+
function isWhereOrHavingClauseWithRightCondition(value) {
|
|
148
|
+
return !!value && !!value.operator && !!value.right;
|
|
149
|
+
}
|
|
150
|
+
exports.isWhereOrHavingClauseWithRightCondition = isWhereOrHavingClauseWithRightCondition;
|
|
151
|
+
function isValueCondition(value) {
|
|
152
|
+
return value && isString(value.field) && isString(value.operator) && !isNil(value.value);
|
|
153
|
+
}
|
|
154
|
+
exports.isValueCondition = isValueCondition;
|
|
155
|
+
function isValueWithDateLiteralCondition(value) {
|
|
156
|
+
return (value &&
|
|
157
|
+
isString(value.field) &&
|
|
158
|
+
isString(value.operator) &&
|
|
159
|
+
!isNil(value.value) &&
|
|
160
|
+
(value.literalType === 'DATE_LITERAL' || (Array.isArray(value.literalType) && value.literalType[0] === 'DATE_LITERAL')));
|
|
161
|
+
}
|
|
162
|
+
exports.isValueWithDateLiteralCondition = isValueWithDateLiteralCondition;
|
|
163
|
+
function isValueWithDateNLiteralCondition(value) {
|
|
164
|
+
return value && isString(value.field) && isString(value.operator) && !isNil(value.value) && !isNil(value.dateLiteralVariable);
|
|
165
|
+
}
|
|
166
|
+
exports.isValueWithDateNLiteralCondition = isValueWithDateNLiteralCondition;
|
|
167
|
+
function isValueFunctionCondition(value) {
|
|
168
|
+
return value && !isNil(value.fn) && isString(value.operator) && !isNil(value.value);
|
|
169
|
+
}
|
|
170
|
+
exports.isValueFunctionCondition = isValueFunctionCondition;
|
|
171
|
+
function isNegationCondition(value) {
|
|
172
|
+
return value && isNumber(value.openParen) && isNil(value.operator) && isNil(value.field) && isNil(value.fn) && isNil(value.closeParen);
|
|
173
|
+
}
|
|
174
|
+
exports.isNegationCondition = isNegationCondition;
|
|
175
|
+
function isValueQueryCondition(value) {
|
|
176
|
+
return value && isString(value.field) && isString(value.operator) && !isNil(value.valueQuery) && isNil(value.value);
|
|
177
|
+
}
|
|
178
|
+
exports.isValueQueryCondition = isValueQueryCondition;
|
|
179
|
+
function isOrderByField(value) {
|
|
180
|
+
return value && !isNil(value.field);
|
|
181
|
+
}
|
|
182
|
+
exports.isOrderByField = isOrderByField;
|
|
183
|
+
function isOrderByFn(value) {
|
|
184
|
+
return value && !isNil(value.fn);
|
|
185
|
+
}
|
|
186
|
+
exports.isOrderByFn = isOrderByFn;
|
|
187
|
+
function isGroupByField(value) {
|
|
188
|
+
return value && !isNil(value.field);
|
|
189
|
+
}
|
|
190
|
+
exports.isGroupByField = isGroupByField;
|
|
191
|
+
function isGroupByFn(value) {
|
|
192
|
+
return value && !isNil(value.fn);
|
|
193
|
+
}
|
|
194
|
+
exports.isGroupByFn = isGroupByFn;
|
|
195
|
+
function isArrayOperator(operator) {
|
|
196
|
+
return ['IN', 'NOT IN', 'INCLUDES', 'EXCLUDES'].includes(operator);
|
|
197
|
+
}
|
|
198
|
+
exports.isArrayOperator = isArrayOperator;
|
|
199
|
+
function getWhereValue(value, literalType, operator) {
|
|
200
|
+
if (isNil(literalType)) {
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
if (operator && literalType !== 'APEX_BIND_VARIABLE' && isArrayOperator(operator) && !Array.isArray(value)) {
|
|
204
|
+
value = [value];
|
|
205
|
+
literalType = Array.isArray(literalType) ? literalType : [literalType];
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(literalType) && Array.isArray(value)) {
|
|
208
|
+
return value.map(function (val, i) {
|
|
209
|
+
return whereValueHelper(val, literalType === null || literalType === void 0 ? void 0 : literalType[i]);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
if (Array.isArray(literalType)) {
|
|
214
|
+
literalType = literalType[0];
|
|
215
|
+
}
|
|
216
|
+
switch (literalType) {
|
|
217
|
+
case 'STRING': {
|
|
218
|
+
if (Array.isArray(value)) {
|
|
219
|
+
return value.filter(Boolean).map(function (val) { return (isString(val) && val.startsWith("'") ? val : "'".concat(val !== null && val !== void 0 ? val : '', "'")); });
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
value = String(value !== null && value !== void 0 ? value : '');
|
|
223
|
+
return isString(value) && value.startsWith("'") ? value : "'".concat(value !== null && value !== void 0 ? value : '', "'");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
case 'APEX_BIND_VARIABLE': {
|
|
227
|
+
return ":".concat(value);
|
|
228
|
+
}
|
|
229
|
+
default: {
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.getWhereValue = getWhereValue;
|
|
236
|
+
function whereValueHelper(value, literalType) {
|
|
237
|
+
switch (literalType) {
|
|
238
|
+
case 'STRING': {
|
|
239
|
+
return isString(value) && value.startsWith("'") ? value : "'".concat(value !== null && value !== void 0 ? value : '', "'");
|
|
240
|
+
}
|
|
241
|
+
default: {
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const src_1 = require("../src");
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const program = new commander_1.Command();
|
|
6
|
+
program
|
|
7
|
+
.command('parse <soql>')
|
|
8
|
+
.option('-a, --allow-apex', 'allow apex bind variables')
|
|
9
|
+
.option('-p, --allow-partial', 'allow partial queries')
|
|
10
|
+
.option('-i, --ignore-errors', 'ignore parse errors, return as much of query as possible')
|
|
11
|
+
.action((query, options) => {
|
|
12
|
+
console.log(JSON.stringify((0, src_1.parseQuery)(query, {
|
|
13
|
+
allowApexBindVariables: options.allowApex,
|
|
14
|
+
allowPartialQuery: options.allowPartial,
|
|
15
|
+
ignoreParseErrors: options.ignoreErrors,
|
|
16
|
+
})));
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command('compose <query>')
|
|
20
|
+
.option('-f, --format', 'format output')
|
|
21
|
+
.option('-i --indent <chars>', 'number of tab characters to indent', 1)
|
|
22
|
+
.option('-m --line-length <chars>', 'max number of characters per lins', 60)
|
|
23
|
+
.option('-s --subquery-parens-new-line', 'subquery parens on own line')
|
|
24
|
+
.option('-k --keywords-new-line', 'new line after keywords')
|
|
25
|
+
.option('-j, --json', 'output as JSON')
|
|
26
|
+
.action((query, options) => {
|
|
27
|
+
const formatOptions = {};
|
|
28
|
+
if (options.indent) {
|
|
29
|
+
formatOptions.numIndent = options.indent;
|
|
30
|
+
}
|
|
31
|
+
if (options.lineLength) {
|
|
32
|
+
formatOptions.fieldMaxLineLength = options.lineLength;
|
|
33
|
+
}
|
|
34
|
+
if (options.subqueryParensNewLine) {
|
|
35
|
+
formatOptions.fieldSubqueryParensOnOwnLine = options.subqueryParensNewLine;
|
|
36
|
+
}
|
|
37
|
+
if (options.keywordsNewLine) {
|
|
38
|
+
formatOptions.newLineAfterKeywords = options.keywordsNewLine;
|
|
39
|
+
}
|
|
40
|
+
let output = (0, src_1.composeQuery)(JSON.parse(query), { format: options.format, formatOptions });
|
|
41
|
+
if (options.json) {
|
|
42
|
+
console.log(JSON.stringify({ query: output }));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
console.log(output);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
program
|
|
49
|
+
.command('format <soql>')
|
|
50
|
+
.option('-a, --allow-apex', 'allow apex bind variables')
|
|
51
|
+
.option('-p, --allow-partial', 'allow partial queries')
|
|
52
|
+
.option('-i --indent <chars>', 'number of tab characters to indent', 1)
|
|
53
|
+
.option('-m --line-length <chars>', 'max number of characters per lins', 60)
|
|
54
|
+
.option('-s --subquery-parens-new-line', 'subquery parens on own line')
|
|
55
|
+
.option('-k --keywords-new-line', 'new line after keywords')
|
|
56
|
+
.option('-j, --json', 'output as JSON')
|
|
57
|
+
.action((query, options) => {
|
|
58
|
+
const parseQueryConfig = {};
|
|
59
|
+
const formatOptions = {};
|
|
60
|
+
if (options.allowApex) {
|
|
61
|
+
parseQueryConfig.allowApexBindVariables = true;
|
|
62
|
+
}
|
|
63
|
+
if (options.allowPartial) {
|
|
64
|
+
parseQueryConfig.allowPartialQuery = true;
|
|
65
|
+
}
|
|
66
|
+
if (options.indent) {
|
|
67
|
+
formatOptions.numIndent = options.indent;
|
|
68
|
+
}
|
|
69
|
+
if (options.lineLength) {
|
|
70
|
+
formatOptions.fieldMaxLineLength = options.lineLength;
|
|
71
|
+
}
|
|
72
|
+
if (options.subqueryParensNewLine) {
|
|
73
|
+
formatOptions.fieldSubqueryParensOnOwnLine = options.subqueryParensNewLine;
|
|
74
|
+
}
|
|
75
|
+
if (options.keywordsNewLine) {
|
|
76
|
+
formatOptions.newLineAfterKeywords = options.keywordsNewLine;
|
|
77
|
+
}
|
|
78
|
+
const output = (0, src_1.formatQuery)(query, formatOptions, parseQueryConfig);
|
|
79
|
+
if (options.json) {
|
|
80
|
+
console.log(JSON.stringify({ query: output }));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(output);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
program
|
|
87
|
+
.command('valid <soql>')
|
|
88
|
+
.option('-a, --allow-apex', 'allow apex bind variables')
|
|
89
|
+
.option('-p, --allow-partial', 'allow partial queries')
|
|
90
|
+
.option('-j, --json', 'output as JSON')
|
|
91
|
+
.action((query, options) => {
|
|
92
|
+
const parseQueryConfig = {};
|
|
93
|
+
if (options.allowApex) {
|
|
94
|
+
parseQueryConfig.allowApexBindVariables = true;
|
|
95
|
+
}
|
|
96
|
+
if (options.allowPartial) {
|
|
97
|
+
parseQueryConfig.allowPartialQuery = true;
|
|
98
|
+
}
|
|
99
|
+
const isValid = (0, src_1.isQueryValid)(query, parseQueryConfig);
|
|
100
|
+
if (options.json) {
|
|
101
|
+
console.log(JSON.stringify({ isValid }));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (isValid) {
|
|
105
|
+
console.log('true');
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.error('false');
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { getParams, hasAlias, isComposeField, isComposeFieldFunction, isComposeFieldRelationship, isComposeFieldSubquery, isComposeFieldTypeof, isFieldSubquery, isGroupByField, isGroupByFn, isHavingClauseWithRightCondition, isNegationCondition, isNestedParamAggregateFunction, isOrderByField, isOrderByFn, isString, isSubquery, isValueCondition, isValueFunctionCondition, isValueQueryCondition, isValueWithDateLiteralCondition, isValueWithDateNLiteralCondition, isWhereClauseWithRightCondition, isWhereOrHavingClauseWithRightCondition, } from '../utils';
|
|
2
|
+
export { hasAlias, isFieldSubquery, isGroupByField, isGroupByFn, isHavingClauseWithRightCondition, isNegationCondition, isOrderByField, isOrderByFn, isString, isSubquery, isValueCondition, isValueFunctionCondition, isValueQueryCondition, isValueWithDateLiteralCondition, isValueWithDateNLiteralCondition, isWhereClauseWithRightCondition, isWhereOrHavingClauseWithRightCondition, };
|
|
3
|
+
export function getComposedField(input) {
|
|
4
|
+
return getField(input);
|
|
5
|
+
}
|
|
6
|
+
export function getField(input) {
|
|
7
|
+
if (typeof input === 'string') {
|
|
8
|
+
return {
|
|
9
|
+
type: 'Field',
|
|
10
|
+
field: input,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
else if (isComposeFieldFunction(input)) {
|
|
14
|
+
let parameters = [];
|
|
15
|
+
if (input.parameters) {
|
|
16
|
+
parameters = (Array.isArray(input.parameters) ? input.parameters : [input.parameters]);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: 'FieldFunctionExpression',
|
|
20
|
+
functionName: (input.functionName || input.fn),
|
|
21
|
+
parameters,
|
|
22
|
+
alias: input.alias,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if (isComposeFieldRelationship(input)) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'FieldRelationship',
|
|
28
|
+
field: input.field,
|
|
29
|
+
relationships: input.relationships,
|
|
30
|
+
objectPrefix: input.objectPrefix,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (isComposeFieldSubquery(input)) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'FieldSubquery',
|
|
36
|
+
subquery: input.subquery,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else if (isComposeFieldTypeof(input)) {
|
|
40
|
+
return {
|
|
41
|
+
type: 'FieldTypeof',
|
|
42
|
+
field: input.field,
|
|
43
|
+
conditions: input.conditions,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (isComposeField(input)) {
|
|
47
|
+
return {
|
|
48
|
+
type: 'Field',
|
|
49
|
+
field: input.field,
|
|
50
|
+
objectPrefix: input.objectPrefix,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw new TypeError('The input object provided did not match any valid field types');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function getFlattenedFields(query, isAggregateResult) {
|
|
58
|
+
if (!query) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
query = isFieldSubquery(query) ? query.subquery : query;
|
|
62
|
+
const fields = query.fields;
|
|
63
|
+
if (!fields) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
let groupByFields = {};
|
|
67
|
+
if (!!query.groupBy) {
|
|
68
|
+
groupByFields = (Array.isArray(query.groupBy) ? query.groupBy : [query.groupBy]).reduce((output, clause) => {
|
|
69
|
+
if (isGroupByField(clause)) {
|
|
70
|
+
output[clause.field.toLocaleLowerCase()] = clause.field;
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
}, {});
|
|
74
|
+
}
|
|
75
|
+
let currUnAliasedAggExp = -1;
|
|
76
|
+
let sObject = (isSubquery(query) ? query.relationshipName : query.sObject || '').toLowerCase();
|
|
77
|
+
let sObjectAlias = (query.sObjectAlias || '').toLowerCase();
|
|
78
|
+
const parsedFields = fields
|
|
79
|
+
.flatMap(field => {
|
|
80
|
+
switch (field.type) {
|
|
81
|
+
case 'Field': {
|
|
82
|
+
return field.alias || field.field;
|
|
83
|
+
}
|
|
84
|
+
case 'FieldFunctionExpression': {
|
|
85
|
+
let params = getParams(field);
|
|
86
|
+
params = params.map(param => {
|
|
87
|
+
if (param.includes('.')) {
|
|
88
|
+
let tempParams = param.split('.');
|
|
89
|
+
const firstParam = tempParams[0].toLowerCase();
|
|
90
|
+
if (firstParam === sObjectAlias || firstParam === sObject) {
|
|
91
|
+
tempParams = tempParams.slice(1);
|
|
92
|
+
}
|
|
93
|
+
return tempParams.join('.');
|
|
94
|
+
}
|
|
95
|
+
return param;
|
|
96
|
+
});
|
|
97
|
+
if (field.alias && (field.isAggregateFn || isAggregateResult)) {
|
|
98
|
+
return field.alias;
|
|
99
|
+
}
|
|
100
|
+
if (field.alias) {
|
|
101
|
+
const firstParam = params[0];
|
|
102
|
+
if (firstParam.includes('.')) {
|
|
103
|
+
params = firstParam.split('.').slice(0, -1);
|
|
104
|
+
params.push(field.alias);
|
|
105
|
+
return params.join('.');
|
|
106
|
+
}
|
|
107
|
+
return field.alias;
|
|
108
|
+
}
|
|
109
|
+
if (field.isAggregateFn || isNestedParamAggregateFunction(field) || isAggregateResult) {
|
|
110
|
+
currUnAliasedAggExp++;
|
|
111
|
+
return `expr${currUnAliasedAggExp}`;
|
|
112
|
+
}
|
|
113
|
+
if (params.length > 0) {
|
|
114
|
+
return params.join('.');
|
|
115
|
+
}
|
|
116
|
+
return field.functionName;
|
|
117
|
+
}
|
|
118
|
+
case 'FieldRelationship': {
|
|
119
|
+
const firstRelationship = field.relationships[0].toLowerCase();
|
|
120
|
+
if (hasAlias(field)) {
|
|
121
|
+
return field.alias;
|
|
122
|
+
}
|
|
123
|
+
if (field.rawValue && groupByFields[field.rawValue.toLocaleLowerCase()]) {
|
|
124
|
+
return field.field;
|
|
125
|
+
}
|
|
126
|
+
if (firstRelationship === sObjectAlias || firstRelationship === sObject) {
|
|
127
|
+
return field.relationships.concat([field.field]).slice(1).join('.');
|
|
128
|
+
}
|
|
129
|
+
return field.relationships.concat([field.field]).join('.');
|
|
130
|
+
}
|
|
131
|
+
case 'FieldSubquery': {
|
|
132
|
+
return field.subquery.relationshipName;
|
|
133
|
+
}
|
|
134
|
+
case 'FieldTypeof': {
|
|
135
|
+
const priorFields = new Set();
|
|
136
|
+
const fields = [];
|
|
137
|
+
field.conditions.forEach(condition => {
|
|
138
|
+
condition.fieldList.forEach(currField => {
|
|
139
|
+
if (!priorFields.has(currField)) {
|
|
140
|
+
priorFields.add(currField);
|
|
141
|
+
fields.push(`${field.field}.${currField}`);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return fields;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
.filter(field => isString(field));
|
|
152
|
+
return parsedFields;
|
|
153
|
+
}
|