@jetstreamapp/soql-parser-js 6.1.0 → 6.2.1

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 (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -3
  3. package/dist/cjs/index.js +143 -2
  4. package/dist/cli/index.js +148 -113
  5. package/dist/esm/index.mjs +143 -0
  6. package/dist/{cjs/src → types}/index.d.ts +1 -1
  7. package/package.json +23 -25
  8. package/dist/cjs/index.js.LICENSE.txt +0 -1
  9. package/dist/cjs/main.licenses.txt +0 -898
  10. package/dist/cjs/src/api/api-models.js +0 -2
  11. package/dist/cjs/src/api/public-utils.js +0 -175
  12. package/dist/cjs/src/composer/composer.js +0 -295
  13. package/dist/cjs/src/formatter/formatter.js +0 -236
  14. package/dist/cjs/src/index.js +0 -23
  15. package/dist/cjs/src/models.js +0 -2
  16. package/dist/cjs/src/parser/lexer.js +0 -954
  17. package/dist/cjs/src/parser/parser.js +0 -697
  18. package/dist/cjs/src/parser/visitor.js +0 -856
  19. package/dist/cjs/src/utils.js +0 -245
  20. package/dist/esm/api/api-models.js +0 -1
  21. package/dist/esm/api/public-utils.js +0 -153
  22. package/dist/esm/composer/composer.js +0 -273
  23. package/dist/esm/formatter/formatter.js +0 -223
  24. package/dist/esm/index.js +0 -4
  25. package/dist/esm/models.js +0 -1
  26. package/dist/esm/parser/lexer.js +0 -947
  27. package/dist/esm/parser/parser.js +0 -667
  28. package/dist/esm/parser/visitor.js +0 -823
  29. package/dist/esm/utils.js +0 -200
  30. package/dist/src/api/api-models.js +0 -2
  31. package/dist/src/api/public-utils.js +0 -203
  32. package/dist/src/composer/composer.js +0 -358
  33. package/dist/src/formatter/formatter.js +0 -263
  34. package/dist/src/index.js +0 -28
  35. package/dist/src/models.js +0 -2
  36. package/dist/src/parser/lexer.js +0 -997
  37. package/dist/src/parser/parser.js +0 -711
  38. package/dist/src/parser/visitor.js +0 -862
  39. package/dist/src/utils.js +0 -251
  40. /package/dist/{cjs/src → types}/api/api-models.d.ts +0 -0
  41. /package/dist/{cjs/src → types}/api/public-utils.d.ts +0 -0
  42. /package/dist/{cjs/src → types}/composer/composer.d.ts +0 -0
  43. /package/dist/{cjs/src → types}/formatter/formatter.d.ts +0 -0
  44. /package/dist/{cjs/src → types}/models.d.ts +0 -0
  45. /package/dist/{cjs/src → types}/parser/lexer.d.ts +0 -0
  46. /package/dist/{cjs/src → types}/parser/parser.d.ts +0 -0
  47. /package/dist/{cjs/src → types}/parser/visitor.d.ts +0 -0
  48. /package/dist/{cjs/src → types}/utils.d.ts +0 -0
package/dist/esm/utils.js DELETED
@@ -1,200 +0,0 @@
1
- export function isToken(val) {
2
- val = Array.isArray(val) ? val[0] : val;
3
- return val.image && true;
4
- }
5
- export function isSubqueryFromFlag(val, isSubquery) {
6
- return isSubquery;
7
- }
8
- export function isString(val) {
9
- return typeof val === 'string';
10
- }
11
- export function isStringArray(val) {
12
- if (!val) {
13
- return false;
14
- }
15
- return val.every(item => isString(item));
16
- }
17
- export function isNumber(val) {
18
- return Number.isFinite(val);
19
- }
20
- export function isBoolean(val) {
21
- return typeof val === typeof true;
22
- }
23
- export function isObject(val) {
24
- return val instanceof Object;
25
- }
26
- export function isNil(val) {
27
- return val === null || val === undefined;
28
- }
29
- export function get(val, suffix, prefix) {
30
- return isNil(val) ? '' : `${prefix || ''}${val}${suffix || ''}`;
31
- }
32
- export function getIfTrue(val, returnStr) {
33
- return isBoolean(val) && val ? returnStr : '';
34
- }
35
- export function getLastItem(arr) {
36
- return arr[arr.length - 1];
37
- }
38
- export function getAsArrayStr(val, alwaysParens = false) {
39
- if (Array.isArray(val)) {
40
- if (val.length > 0) {
41
- return `(${val.join(', ')})`;
42
- }
43
- else {
44
- return alwaysParens ? '()' : '';
45
- }
46
- }
47
- else {
48
- return alwaysParens ? `(${val || ''})` : val || '';
49
- }
50
- }
51
- export function pad(val, len, left = 0) {
52
- let leftPad = left > 0 ? new Array(left).fill(' ').join('') : '';
53
- if (val.length > len) {
54
- return `${leftPad}${val}`;
55
- }
56
- else {
57
- return `${leftPad}${val}${new Array(len - val.length).fill(' ').join('')}`;
58
- }
59
- }
60
- export function generateParens(count, character, joinCharacter = '') {
61
- return isNumber(count) && count > 0 ? new Array(count).fill(character).join(joinCharacter) : '';
62
- }
63
- export function getParams(functionFieldExp) {
64
- if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
65
- return [];
66
- }
67
- if (isStringArray(functionFieldExp.parameters)) {
68
- return functionFieldExp.parameters;
69
- }
70
- if (isString(functionFieldExp.parameters[0])) {
71
- return [functionFieldExp.parameters[0]];
72
- }
73
- return getParams(functionFieldExp.parameters[0]);
74
- }
75
- export function isNestedParamAggregateFunction(functionFieldExp) {
76
- if (!functionFieldExp.parameters || functionFieldExp.parameters.length === 0) {
77
- return false;
78
- }
79
- const parameter = functionFieldExp.parameters[0];
80
- if (isString(parameter)) {
81
- return false;
82
- }
83
- return !!parameter.isAggregateFn;
84
- }
85
- export function hasAlias(value) {
86
- return value && !isNil(value.alias);
87
- }
88
- export function isComposeField(input) {
89
- return isString(input.field) && !Array.isArray(input.relationships) && !Array.isArray(input.conditions);
90
- }
91
- export function isComposeFieldFunction(input) {
92
- return !isNil(input.functionName || input.fn);
93
- }
94
- export function isComposeFieldRelationship(input) {
95
- return isString(input.field) && Array.isArray(input.relationships);
96
- }
97
- export function isComposeFieldSubquery(input) {
98
- return !isNil(input.subquery);
99
- }
100
- export function isComposeFieldTypeof(input) {
101
- return isString(input.field) && Array.isArray(input.conditions);
102
- }
103
- export function isSubquery(query) {
104
- return isString(query.relationshipName);
105
- }
106
- export function isFieldSubquery(value) {
107
- return !!value && !!value.type && value.type === 'FieldSubquery';
108
- }
109
- export function isWhereClauseWithRightCondition(value) {
110
- return !!value && !!value.operator && !!value.right;
111
- }
112
- export function isHavingClauseWithRightCondition(value) {
113
- return !!value && !!value.operator && !!value.right;
114
- }
115
- export function isWhereOrHavingClauseWithRightCondition(value) {
116
- return !!value && !!value.operator && !!value.right;
117
- }
118
- export function isValueCondition(value) {
119
- return value && isString(value.field) && isString(value.operator) && !isNil(value.value);
120
- }
121
- export function isValueWithDateLiteralCondition(value) {
122
- return (value &&
123
- isString(value.field) &&
124
- isString(value.operator) &&
125
- !isNil(value.value) &&
126
- (value.literalType === 'DATE_LITERAL' || (Array.isArray(value.literalType) && value.literalType[0] === 'DATE_LITERAL')));
127
- }
128
- export function isValueWithDateNLiteralCondition(value) {
129
- return value && isString(value.field) && isString(value.operator) && !isNil(value.value) && !isNil(value.dateLiteralVariable);
130
- }
131
- export function isValueFunctionCondition(value) {
132
- return value && !isNil(value.fn) && isString(value.operator) && !isNil(value.value);
133
- }
134
- export function isNegationCondition(value) {
135
- return value && isNumber(value.openParen) && isNil(value.operator) && isNil(value.field) && isNil(value.fn) && isNil(value.closeParen);
136
- }
137
- export function isValueQueryCondition(value) {
138
- return value && isString(value.field) && isString(value.operator) && !isNil(value.valueQuery) && isNil(value.value);
139
- }
140
- export function isOrderByField(value) {
141
- return value && !isNil(value.field);
142
- }
143
- export function isOrderByFn(value) {
144
- return value && !isNil(value.fn);
145
- }
146
- export function isGroupByField(value) {
147
- return value && !isNil(value.field);
148
- }
149
- export function isGroupByFn(value) {
150
- return value && !isNil(value.fn);
151
- }
152
- export function isArrayOperator(operator) {
153
- return ['IN', 'NOT IN', 'INCLUDES', 'EXCLUDES'].includes(operator);
154
- }
155
- export function getWhereValue(value, literalType, operator) {
156
- if (isNil(literalType)) {
157
- return value;
158
- }
159
- if (operator && literalType !== 'APEX_BIND_VARIABLE' && isArrayOperator(operator) && !Array.isArray(value)) {
160
- value = [value];
161
- literalType = Array.isArray(literalType) ? literalType : [literalType];
162
- }
163
- if (Array.isArray(literalType) && Array.isArray(value)) {
164
- return value.map((val, i) => {
165
- return whereValueHelper(val, literalType?.[i]);
166
- });
167
- }
168
- else {
169
- if (Array.isArray(literalType)) {
170
- literalType = literalType[0];
171
- }
172
- switch (literalType) {
173
- case 'STRING': {
174
- if (Array.isArray(value)) {
175
- return value.filter(Boolean).map(val => (isString(val) && val.startsWith("'") ? val : `'${val ?? ''}'`));
176
- }
177
- else {
178
- value = String(value ?? '');
179
- return isString(value) && value.startsWith("'") ? value : `'${value ?? ''}'`;
180
- }
181
- }
182
- case 'APEX_BIND_VARIABLE': {
183
- return `:${value}`;
184
- }
185
- default: {
186
- return value;
187
- }
188
- }
189
- }
190
- }
191
- function whereValueHelper(value, literalType) {
192
- switch (literalType) {
193
- case 'STRING': {
194
- return isString(value) && value.startsWith("'") ? value : `'${value ?? ''}'`;
195
- }
196
- default: {
197
- return value;
198
- }
199
- }
200
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,203 +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
- const 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
- /**
23
- * @deprecated - use `getField()` instead
24
- * Pass any a basic string or populate required properties on the ComposeField object
25
- * and a constructed field will be returned
26
- * @param input string | ComposeFieldInput
27
- * @returns FieldType
28
- */
29
- function getComposedField(input) {
30
- return getField(input);
31
- }
32
- exports.getComposedField = getComposedField;
33
- /**
34
- * Pass any a basic string or populate required properties on the ComposeField object
35
- * and a constructed field will be returned
36
- * @param input string | ComposeFieldInput
37
- * @returns FieldType
38
- */
39
- function getField(input) {
40
- if (typeof input === 'string') {
41
- return {
42
- type: 'Field',
43
- field: input,
44
- };
45
- }
46
- else if ((0, utils_1.isComposeFieldFunction)(input)) {
47
- let parameters = [];
48
- if (input.parameters) {
49
- parameters = (Array.isArray(input.parameters) ? input.parameters : [input.parameters]);
50
- }
51
- return {
52
- type: 'FieldFunctionExpression',
53
- functionName: (input.functionName || input.fn),
54
- parameters,
55
- alias: input.alias,
56
- };
57
- }
58
- else if ((0, utils_1.isComposeFieldRelationship)(input)) {
59
- return {
60
- type: 'FieldRelationship',
61
- field: input.field,
62
- relationships: input.relationships,
63
- objectPrefix: input.objectPrefix,
64
- };
65
- }
66
- else if ((0, utils_1.isComposeFieldSubquery)(input)) {
67
- return {
68
- type: 'FieldSubquery',
69
- subquery: input.subquery,
70
- };
71
- }
72
- else if ((0, utils_1.isComposeFieldTypeof)(input)) {
73
- return {
74
- type: 'FieldTypeof',
75
- field: input.field,
76
- conditions: input.conditions,
77
- };
78
- }
79
- else if ((0, utils_1.isComposeField)(input)) {
80
- return {
81
- type: 'Field',
82
- field: input.field,
83
- objectPrefix: input.objectPrefix,
84
- };
85
- }
86
- else {
87
- throw new TypeError('The input object provided did not match any valid field types');
88
- }
89
- }
90
- exports.getField = getField;
91
- /**
92
- * Gets flattened fields - this will turn a Query into a list of fields that can be used to parse results from a returned dataset from SFDC
93
- * Subqueries only include the child SObject relationship name
94
- * @param query
95
- * @param [isAggregateResult] pass in true to force expr0...1 for all non-aliased functions even if field is not explicitly an aggregate expression
96
- * @returns flattened fields
97
- */
98
- function getFlattenedFields(query, isAggregateResult) {
99
- if (!query) {
100
- return [];
101
- }
102
- query = (0, utils_1.isFieldSubquery)(query) ? query.subquery : query;
103
- const fields = query.fields;
104
- if (!fields) {
105
- return [];
106
- }
107
- // if a relationship field is used in a group by, then Salesforce removes the relationship portion of the field in the returned records
108
- let groupByFields = {};
109
- if (!!query.groupBy) {
110
- groupByFields = (Array.isArray(query.groupBy) ? query.groupBy : [query.groupBy]).reduce((output, clause) => {
111
- if ((0, utils_1.isGroupByField)(clause)) {
112
- output[clause.field.toLocaleLowerCase()] = clause.field;
113
- }
114
- return output;
115
- }, {});
116
- }
117
- let currUnAliasedAggExp = -1;
118
- let sObject = ((0, utils_1.isSubquery)(query) ? query.relationshipName : query.sObject || '').toLowerCase();
119
- let sObjectAlias = (query.sObjectAlias || '').toLowerCase();
120
- const parsedFields = fields
121
- .flatMap(field => {
122
- switch (field.type) {
123
- case 'Field': {
124
- return field.alias || field.field;
125
- }
126
- case 'FieldFunctionExpression': {
127
- let params = (0, utils_1.getParams)(field);
128
- // If the parameter has dot notation and the first entry is the object name/alias, remove it
129
- params = params.map(param => {
130
- if (param.includes('.')) {
131
- let tempParams = param.split('.');
132
- const firstParam = tempParams[0].toLowerCase();
133
- if (firstParam === sObjectAlias || firstParam === sObject) {
134
- tempParams = tempParams.slice(1);
135
- }
136
- return tempParams.join('.');
137
- }
138
- return param;
139
- });
140
- if (field.alias && (field.isAggregateFn || isAggregateResult)) {
141
- return field.alias;
142
- }
143
- if (field.alias) {
144
- const firstParam = params[0];
145
- // Include the full path and replace the field with the alias
146
- if (firstParam.includes('.')) {
147
- params = firstParam.split('.').slice(0, -1);
148
- params.push(field.alias);
149
- return params.join('.');
150
- }
151
- return field.alias;
152
- }
153
- // Non-aliased aggregate fields use computed name expr0, expr1, etc..
154
- if (field.isAggregateFn || (0, utils_1.isNestedParamAggregateFunction)(field) || isAggregateResult) {
155
- currUnAliasedAggExp++;
156
- return `expr${currUnAliasedAggExp}`;
157
- }
158
- if (params.length > 0) {
159
- return params.join('.');
160
- }
161
- return field.functionName;
162
- }
163
- case 'FieldRelationship': {
164
- const firstRelationship = field.relationships[0].toLowerCase();
165
- if ((0, utils_1.hasAlias)(field)) {
166
- return field.alias;
167
- }
168
- // If relationship field is used in groupby, then return field instead of full path
169
- if (field.rawValue && groupByFields[field.rawValue.toLocaleLowerCase()]) {
170
- return field.field;
171
- }
172
- // If first object is the same object queried, remove the object
173
- if (firstRelationship === sObjectAlias || firstRelationship === sObject) {
174
- return field.relationships.concat([field.field]).slice(1).join('.');
175
- }
176
- return field.relationships.concat([field.field]).join('.');
177
- }
178
- case 'FieldSubquery': {
179
- return field.subquery.relationshipName;
180
- }
181
- case 'FieldTypeof': {
182
- // keep track of fields to avoid adding duplicates
183
- const priorFields = new Set();
184
- const fields = [];
185
- // Add all unique fields across all conditions
186
- field.conditions.forEach(condition => {
187
- condition.fieldList.forEach(currField => {
188
- if (!priorFields.has(currField)) {
189
- priorFields.add(currField);
190
- fields.push(`${field.field}.${currField}`);
191
- }
192
- });
193
- });
194
- return fields;
195
- }
196
- default:
197
- break;
198
- }
199
- })
200
- .filter(field => (0, utils_1.isString)(field));
201
- return parsedFields;
202
- }
203
- exports.getFlattenedFields = getFlattenedFields;