@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.
- package/README.md +2 -3
- package/dist/cjs/index.js +143 -2
- package/dist/cli/index.js +148 -113
- package/dist/esm/index.js +143 -4
- package/dist/{cjs/src → types}/index.d.ts +1 -1
- package/package.json +12 -20
- package/dist/cjs/index.js.LICENSE.txt +0 -1
- package/dist/cjs/main.licenses.txt +0 -898
- package/dist/cjs/src/api/api-models.js +0 -2
- package/dist/cjs/src/api/public-utils.js +0 -175
- package/dist/cjs/src/composer/composer.js +0 -295
- package/dist/cjs/src/formatter/formatter.js +0 -236
- package/dist/cjs/src/index.js +0 -23
- package/dist/cjs/src/models.js +0 -2
- package/dist/cjs/src/parser/lexer.js +0 -954
- package/dist/cjs/src/parser/parser.js +0 -697
- package/dist/cjs/src/parser/visitor.js +0 -856
- package/dist/cjs/src/utils.js +0 -245
- package/dist/esm/api/api-models.js +0 -1
- package/dist/esm/api/public-utils.js +0 -153
- package/dist/esm/composer/composer.js +0 -273
- package/dist/esm/formatter/formatter.js +0 -223
- package/dist/esm/models.js +0 -1
- package/dist/esm/parser/lexer.js +0 -947
- package/dist/esm/parser/parser.js +0 -667
- package/dist/esm/parser/visitor.js +0 -823
- package/dist/esm/utils.js +0 -200
- package/dist/src/api/api-models.js +0 -2
- package/dist/src/api/public-utils.js +0 -203
- package/dist/src/composer/composer.js +0 -358
- package/dist/src/formatter/formatter.js +0 -263
- package/dist/src/index.js +0 -28
- package/dist/src/models.js +0 -2
- package/dist/src/parser/lexer.js +0 -997
- package/dist/src/parser/parser.js +0 -711
- package/dist/src/parser/visitor.js +0 -862
- package/dist/src/utils.js +0 -251
- /package/dist/{cjs/src → types}/api/api-models.d.ts +0 -0
- /package/dist/{cjs/src → types}/api/public-utils.d.ts +0 -0
- /package/dist/{cjs/src → types}/composer/composer.d.ts +0 -0
- /package/dist/{cjs/src → types}/formatter/formatter.d.ts +0 -0
- /package/dist/{cjs/src → types}/models.d.ts +0 -0
- /package/dist/{cjs/src → types}/parser/lexer.d.ts +0 -0
- /package/dist/{cjs/src → types}/parser/parser.d.ts +0 -0
- /package/dist/{cjs/src → types}/parser/visitor.d.ts +0 -0
- /package/dist/{cjs/src → types}/utils.d.ts +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFlattenedFields = exports.getField = exports.getComposedField = exports.isWhereOrHavingClauseWithRightCondition = exports.isWhereClauseWithRightCondition = exports.isValueWithDateNLiteralCondition = exports.isValueWithDateLiteralCondition = exports.isValueQueryCondition = exports.isValueFunctionCondition = exports.isValueCondition = exports.isSubquery = exports.isString = exports.isOrderByFn = exports.isOrderByField = exports.isNegationCondition = exports.isHavingClauseWithRightCondition = exports.isGroupByFn = exports.isGroupByField = exports.isFieldSubquery = exports.hasAlias = void 0;
|
|
4
|
-
var utils_1 = require("../utils");
|
|
5
|
-
Object.defineProperty(exports, "hasAlias", { enumerable: true, get: function () { return utils_1.hasAlias; } });
|
|
6
|
-
Object.defineProperty(exports, "isFieldSubquery", { enumerable: true, get: function () { return utils_1.isFieldSubquery; } });
|
|
7
|
-
Object.defineProperty(exports, "isGroupByField", { enumerable: true, get: function () { return utils_1.isGroupByField; } });
|
|
8
|
-
Object.defineProperty(exports, "isGroupByFn", { enumerable: true, get: function () { return utils_1.isGroupByFn; } });
|
|
9
|
-
Object.defineProperty(exports, "isHavingClauseWithRightCondition", { enumerable: true, get: function () { return utils_1.isHavingClauseWithRightCondition; } });
|
|
10
|
-
Object.defineProperty(exports, "isNegationCondition", { enumerable: true, get: function () { return utils_1.isNegationCondition; } });
|
|
11
|
-
Object.defineProperty(exports, "isOrderByField", { enumerable: true, get: function () { return utils_1.isOrderByField; } });
|
|
12
|
-
Object.defineProperty(exports, "isOrderByFn", { enumerable: true, get: function () { return utils_1.isOrderByFn; } });
|
|
13
|
-
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return utils_1.isString; } });
|
|
14
|
-
Object.defineProperty(exports, "isSubquery", { enumerable: true, get: function () { return utils_1.isSubquery; } });
|
|
15
|
-
Object.defineProperty(exports, "isValueCondition", { enumerable: true, get: function () { return utils_1.isValueCondition; } });
|
|
16
|
-
Object.defineProperty(exports, "isValueFunctionCondition", { enumerable: true, get: function () { return utils_1.isValueFunctionCondition; } });
|
|
17
|
-
Object.defineProperty(exports, "isValueQueryCondition", { enumerable: true, get: function () { return utils_1.isValueQueryCondition; } });
|
|
18
|
-
Object.defineProperty(exports, "isValueWithDateLiteralCondition", { enumerable: true, get: function () { return utils_1.isValueWithDateLiteralCondition; } });
|
|
19
|
-
Object.defineProperty(exports, "isValueWithDateNLiteralCondition", { enumerable: true, get: function () { return utils_1.isValueWithDateNLiteralCondition; } });
|
|
20
|
-
Object.defineProperty(exports, "isWhereClauseWithRightCondition", { enumerable: true, get: function () { return utils_1.isWhereClauseWithRightCondition; } });
|
|
21
|
-
Object.defineProperty(exports, "isWhereOrHavingClauseWithRightCondition", { enumerable: true, get: function () { return utils_1.isWhereOrHavingClauseWithRightCondition; } });
|
|
22
|
-
function getComposedField(input) {
|
|
23
|
-
return getField(input);
|
|
24
|
-
}
|
|
25
|
-
exports.getComposedField = getComposedField;
|
|
26
|
-
function getField(input) {
|
|
27
|
-
if (typeof input === 'string') {
|
|
28
|
-
return {
|
|
29
|
-
type: 'Field',
|
|
30
|
-
field: input,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
else if ((0, utils_1.isComposeFieldFunction)(input)) {
|
|
34
|
-
var parameters = [];
|
|
35
|
-
if (input.parameters) {
|
|
36
|
-
parameters = (Array.isArray(input.parameters) ? input.parameters : [input.parameters]);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
type: 'FieldFunctionExpression',
|
|
40
|
-
functionName: (input.functionName || input.fn),
|
|
41
|
-
parameters: parameters,
|
|
42
|
-
alias: input.alias,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
else if ((0, utils_1.isComposeFieldRelationship)(input)) {
|
|
46
|
-
return {
|
|
47
|
-
type: 'FieldRelationship',
|
|
48
|
-
field: input.field,
|
|
49
|
-
relationships: input.relationships,
|
|
50
|
-
objectPrefix: input.objectPrefix,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
else if ((0, utils_1.isComposeFieldSubquery)(input)) {
|
|
54
|
-
return {
|
|
55
|
-
type: 'FieldSubquery',
|
|
56
|
-
subquery: input.subquery,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
else if ((0, utils_1.isComposeFieldTypeof)(input)) {
|
|
60
|
-
return {
|
|
61
|
-
type: 'FieldTypeof',
|
|
62
|
-
field: input.field,
|
|
63
|
-
conditions: input.conditions,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
else if ((0, utils_1.isComposeField)(input)) {
|
|
67
|
-
return {
|
|
68
|
-
type: 'Field',
|
|
69
|
-
field: input.field,
|
|
70
|
-
objectPrefix: input.objectPrefix,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new TypeError('The input object provided did not match any valid field types');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.getField = getField;
|
|
78
|
-
function getFlattenedFields(query, isAggregateResult) {
|
|
79
|
-
if (!query) {
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
query = (0, utils_1.isFieldSubquery)(query) ? query.subquery : query;
|
|
83
|
-
var fields = query.fields;
|
|
84
|
-
if (!fields) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
var groupByFields = {};
|
|
88
|
-
if (!!query.groupBy) {
|
|
89
|
-
groupByFields = (Array.isArray(query.groupBy) ? query.groupBy : [query.groupBy]).reduce(function (output, clause) {
|
|
90
|
-
if ((0, utils_1.isGroupByField)(clause)) {
|
|
91
|
-
output[clause.field.toLocaleLowerCase()] = clause.field;
|
|
92
|
-
}
|
|
93
|
-
return output;
|
|
94
|
-
}, {});
|
|
95
|
-
}
|
|
96
|
-
var currUnAliasedAggExp = -1;
|
|
97
|
-
var sObject = ((0, utils_1.isSubquery)(query) ? query.relationshipName : query.sObject || '').toLowerCase();
|
|
98
|
-
var sObjectAlias = (query.sObjectAlias || '').toLowerCase();
|
|
99
|
-
var parsedFields = fields
|
|
100
|
-
.flatMap(function (field) {
|
|
101
|
-
switch (field.type) {
|
|
102
|
-
case 'Field': {
|
|
103
|
-
return field.alias || field.field;
|
|
104
|
-
}
|
|
105
|
-
case 'FieldFunctionExpression': {
|
|
106
|
-
var params = (0, utils_1.getParams)(field);
|
|
107
|
-
params = params.map(function (param) {
|
|
108
|
-
if (param.includes('.')) {
|
|
109
|
-
var tempParams = param.split('.');
|
|
110
|
-
var firstParam = tempParams[0].toLowerCase();
|
|
111
|
-
if (firstParam === sObjectAlias || firstParam === sObject) {
|
|
112
|
-
tempParams = tempParams.slice(1);
|
|
113
|
-
}
|
|
114
|
-
return tempParams.join('.');
|
|
115
|
-
}
|
|
116
|
-
return param;
|
|
117
|
-
});
|
|
118
|
-
if (field.alias && (field.isAggregateFn || isAggregateResult)) {
|
|
119
|
-
return field.alias;
|
|
120
|
-
}
|
|
121
|
-
if (field.alias) {
|
|
122
|
-
var firstParam = params[0];
|
|
123
|
-
if (firstParam.includes('.')) {
|
|
124
|
-
params = firstParam.split('.').slice(0, -1);
|
|
125
|
-
params.push(field.alias);
|
|
126
|
-
return params.join('.');
|
|
127
|
-
}
|
|
128
|
-
return field.alias;
|
|
129
|
-
}
|
|
130
|
-
if (field.isAggregateFn || (0, utils_1.isNestedParamAggregateFunction)(field) || isAggregateResult) {
|
|
131
|
-
currUnAliasedAggExp++;
|
|
132
|
-
return "expr".concat(currUnAliasedAggExp);
|
|
133
|
-
}
|
|
134
|
-
if (params.length > 0) {
|
|
135
|
-
return params.join('.');
|
|
136
|
-
}
|
|
137
|
-
return field.functionName;
|
|
138
|
-
}
|
|
139
|
-
case 'FieldRelationship': {
|
|
140
|
-
var firstRelationship = field.relationships[0].toLowerCase();
|
|
141
|
-
if ((0, utils_1.hasAlias)(field)) {
|
|
142
|
-
return field.alias;
|
|
143
|
-
}
|
|
144
|
-
if (field.rawValue && groupByFields[field.rawValue.toLocaleLowerCase()]) {
|
|
145
|
-
return field.field;
|
|
146
|
-
}
|
|
147
|
-
if (firstRelationship === sObjectAlias || firstRelationship === sObject) {
|
|
148
|
-
return field.relationships.concat([field.field]).slice(1).join('.');
|
|
149
|
-
}
|
|
150
|
-
return field.relationships.concat([field.field]).join('.');
|
|
151
|
-
}
|
|
152
|
-
case 'FieldSubquery': {
|
|
153
|
-
return field.subquery.relationshipName;
|
|
154
|
-
}
|
|
155
|
-
case 'FieldTypeof': {
|
|
156
|
-
var priorFields_1 = new Set();
|
|
157
|
-
var fields_1 = [];
|
|
158
|
-
field.conditions.forEach(function (condition) {
|
|
159
|
-
condition.fieldList.forEach(function (currField) {
|
|
160
|
-
if (!priorFields_1.has(currField)) {
|
|
161
|
-
priorFields_1.add(currField);
|
|
162
|
-
fields_1.push("".concat(field.field, ".").concat(currField));
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
return fields_1;
|
|
167
|
-
}
|
|
168
|
-
default:
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
})
|
|
172
|
-
.filter(function (field) { return (0, utils_1.isString)(field); });
|
|
173
|
-
return parsedFields;
|
|
174
|
-
}
|
|
175
|
-
exports.getFlattenedFields = getFlattenedFields;
|
|
@@ -1,295 +0,0 @@
|
|
|
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;
|