@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,175 @@
|
|
|
1
|
+
export declare type LogicalOperatorAnd = 'AND';
|
|
2
|
+
export declare type LogicalOperatorOr = 'OR';
|
|
3
|
+
export declare type LogicalOperatorNot = 'NOT';
|
|
4
|
+
export declare type LogicalOperator = LogicalOperatorAnd | LogicalOperatorOr | LogicalOperatorNot;
|
|
5
|
+
export declare type Operator = '=' | '!=' | '<=' | '>=' | '>' | '<' | 'LIKE' | 'IN' | 'NOT IN' | 'INCLUDES' | 'EXCLUDES';
|
|
6
|
+
export declare type FieldTypeOfConditionType = 'WHEN' | 'ELSE';
|
|
7
|
+
export declare type GroupSelector = 'ABOVE' | 'AT' | 'BELOW' | 'ABOVE_OR_BELOW';
|
|
8
|
+
export declare type ForClause = 'VIEW' | 'UPDATE' | 'REFERENCE';
|
|
9
|
+
export declare type UpdateClause = 'TRACKING' | 'VIEWSTAT';
|
|
10
|
+
export declare type LiteralType = 'STRING' | 'INTEGER' | 'DECIMAL' | 'INTEGER_WITH_CURRENCY_PREFIX' | 'DECIMAL_WITH_CURRENCY_PREFIX' | 'BOOLEAN' | 'NULL' | 'DATETIME' | 'DATE' | 'DATE_LITERAL' | 'DATE_N_LITERAL' | 'APEX_BIND_VARIABLE' | 'SUBQUERY';
|
|
11
|
+
export declare type FieldType = Field | FieldWithAlias | FieldFunctionExpression | FieldRelationship | FieldRelationshipWithAlias | FieldSubquery | FieldTypeOf;
|
|
12
|
+
export declare type OrderByCriterion = 'ASC' | 'DESC';
|
|
13
|
+
export declare type NullsOrder = 'FIRST' | 'LAST';
|
|
14
|
+
export declare type GroupByType = 'CUBE' | 'ROLLUP';
|
|
15
|
+
export declare type AccessLevel = 'USER_MODE' | 'SYSTEM_MODE';
|
|
16
|
+
export declare type DateLiteral = 'YESTERDAY' | 'TODAY' | 'TOMORROW' | 'LAST_WEEK' | 'THIS_WEEK' | 'NEXT_WEEK' | 'LAST_MONTH' | 'THIS_MONTH' | 'NEXT_MONTH' | 'LAST_90_DAYS' | 'NEXT_90_DAYS' | 'THIS_QUARTER' | 'LAST_QUARTER' | 'NEXT_QUARTER' | 'THIS_YEAR' | 'LAST_YEAR' | 'NEXT_YEAR' | 'THIS_FISCAL_QUARTER' | 'LAST_FISCAL_QUARTER' | 'NEXT_FISCAL_QUARTER' | 'THIS_FISCAL_YEAR' | 'LAST_FISCAL_YEAR' | 'NEXT_FISCAL_YEAR';
|
|
17
|
+
export declare type DateNLiteral = 'YESTERDAY' | 'NEXT_N_DAYS' | 'LAST_N_DAYS' | 'N_DAYS_AGO' | 'NEXT_N_WEEKS' | 'LAST_N_WEEKS' | 'N_WEEKS_AGO' | 'NEXT_N_MONTHS' | 'LAST_N_MONTHS' | 'N_MONTHS_AGO' | 'NEXT_N_QUARTERS' | 'LAST_N_QUARTERS' | 'N_QUARTERS_AGO' | 'NEXT_N_YEARS' | 'LAST_N_YEARS' | 'N_YEARS_AGO' | 'NEXT_N_FISCAL_QUARTERS' | 'LAST_N_FISCAL_QUARTERS' | 'N_FISCAL_QUARTERS_AGO' | 'NEXT_N_FISCAL_YEARS' | 'LAST_N_FISCAL_YEARS' | 'N_FISCAL_YEARS_AGO';
|
|
18
|
+
export interface Field {
|
|
19
|
+
type: 'Field';
|
|
20
|
+
field: string;
|
|
21
|
+
alias?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface FieldWithAlias extends Field {
|
|
24
|
+
objectPrefix: string;
|
|
25
|
+
rawValue: string;
|
|
26
|
+
}
|
|
27
|
+
export interface FieldFunctionExpression {
|
|
28
|
+
type: 'FieldFunctionExpression';
|
|
29
|
+
functionName: string;
|
|
30
|
+
parameters: (string | FieldFunctionExpression)[];
|
|
31
|
+
alias?: string;
|
|
32
|
+
isAggregateFn?: boolean;
|
|
33
|
+
rawValue?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface FieldRelationship {
|
|
36
|
+
type: 'FieldRelationship';
|
|
37
|
+
field: string;
|
|
38
|
+
relationships: string[];
|
|
39
|
+
rawValue?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface FieldRelationshipWithAlias extends FieldRelationship {
|
|
42
|
+
objectPrefix: string;
|
|
43
|
+
alias: string;
|
|
44
|
+
}
|
|
45
|
+
export interface FieldSubquery {
|
|
46
|
+
type: 'FieldSubquery';
|
|
47
|
+
subquery: Subquery;
|
|
48
|
+
}
|
|
49
|
+
export interface FieldTypeOf {
|
|
50
|
+
type: 'FieldTypeof';
|
|
51
|
+
field: string;
|
|
52
|
+
conditions: FieldTypeOfCondition[];
|
|
53
|
+
}
|
|
54
|
+
export interface FieldTypeOfCondition {
|
|
55
|
+
type: FieldTypeOfConditionType;
|
|
56
|
+
objectType?: string;
|
|
57
|
+
fieldList: string[];
|
|
58
|
+
}
|
|
59
|
+
export interface QueryBase {
|
|
60
|
+
fields?: FieldType[];
|
|
61
|
+
sObjectAlias?: string;
|
|
62
|
+
usingScope?: string;
|
|
63
|
+
where?: WhereClause;
|
|
64
|
+
limit?: number;
|
|
65
|
+
offset?: number;
|
|
66
|
+
groupBy?: GroupByClause | GroupByClause[];
|
|
67
|
+
having?: HavingClause;
|
|
68
|
+
orderBy?: OrderByClause | OrderByClause[];
|
|
69
|
+
withDataCategory?: WithDataCategoryClause;
|
|
70
|
+
withSecurityEnforced?: boolean;
|
|
71
|
+
withAccessLevel?: AccessLevel;
|
|
72
|
+
for?: ForClause;
|
|
73
|
+
update?: UpdateClause;
|
|
74
|
+
}
|
|
75
|
+
export interface Query extends QueryBase {
|
|
76
|
+
sObject?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface Subquery extends QueryBase {
|
|
79
|
+
relationshipName: string;
|
|
80
|
+
sObjectPrefix?: string[];
|
|
81
|
+
}
|
|
82
|
+
export declare type WhereClause = WhereClauseWithoutOperator | WhereClauseWithoutNegationOperator | WhereClauseWithRightCondition;
|
|
83
|
+
export interface WhereClauseWithoutOperator {
|
|
84
|
+
left: ConditionWithValueQuery;
|
|
85
|
+
}
|
|
86
|
+
export interface WhereClauseWithRightCondition extends WhereClauseWithoutOperator {
|
|
87
|
+
operator: LogicalOperator;
|
|
88
|
+
right: WhereClause;
|
|
89
|
+
}
|
|
90
|
+
export interface WhereClauseWithoutNegationOperator {
|
|
91
|
+
left: NegationCondition | null;
|
|
92
|
+
operator: LogicalOperatorNot;
|
|
93
|
+
right: WhereClause;
|
|
94
|
+
}
|
|
95
|
+
export declare type Condition = ValueCondition | ValueWithDateLiteralCondition | ValueWithDateNLiteralCondition | ValueFunctionCondition | NegationCondition;
|
|
96
|
+
export declare type ConditionWithValueQuery = Condition | ValueQueryCondition;
|
|
97
|
+
export interface OptionalParentheses {
|
|
98
|
+
openParen?: number;
|
|
99
|
+
closeParen?: number;
|
|
100
|
+
}
|
|
101
|
+
export interface ValueCondition extends OptionalParentheses {
|
|
102
|
+
field: string;
|
|
103
|
+
operator: Operator;
|
|
104
|
+
value: string | string[];
|
|
105
|
+
literalType?: LiteralType | LiteralType[];
|
|
106
|
+
}
|
|
107
|
+
export interface ValueWithDateLiteralCondition extends OptionalParentheses {
|
|
108
|
+
field: string;
|
|
109
|
+
operator: Operator;
|
|
110
|
+
value: DateLiteral | DateLiteral[];
|
|
111
|
+
literalType?: 'DATE_LITERAL' | 'DATE_LITERAL'[];
|
|
112
|
+
}
|
|
113
|
+
export interface ValueWithDateNLiteralCondition extends OptionalParentheses {
|
|
114
|
+
field: string;
|
|
115
|
+
operator: Operator;
|
|
116
|
+
value: string | string[];
|
|
117
|
+
literalType?: 'DATE_N_LITERAL' | 'DATE_N_LITERAL'[];
|
|
118
|
+
dateLiteralVariable: number | number[];
|
|
119
|
+
}
|
|
120
|
+
export interface ValueQueryCondition extends OptionalParentheses {
|
|
121
|
+
field: string;
|
|
122
|
+
operator: Operator;
|
|
123
|
+
valueQuery: Query;
|
|
124
|
+
literalType?: 'SUBQUERY';
|
|
125
|
+
}
|
|
126
|
+
export interface ValueFunctionCondition extends OptionalParentheses {
|
|
127
|
+
fn: FunctionExp;
|
|
128
|
+
operator: Operator;
|
|
129
|
+
value: string | string[];
|
|
130
|
+
literalType?: LiteralType | LiteralType[];
|
|
131
|
+
}
|
|
132
|
+
export interface NegationCondition {
|
|
133
|
+
openParen: number;
|
|
134
|
+
}
|
|
135
|
+
export declare type OrderByClause = OrderByFieldClause | OrderByFnClause;
|
|
136
|
+
export interface OrderByOptionalFieldsClause {
|
|
137
|
+
order?: OrderByCriterion;
|
|
138
|
+
nulls?: NullsOrder;
|
|
139
|
+
}
|
|
140
|
+
export interface OrderByFieldClause extends OrderByOptionalFieldsClause {
|
|
141
|
+
field: string;
|
|
142
|
+
}
|
|
143
|
+
export interface OrderByFnClause extends OrderByOptionalFieldsClause {
|
|
144
|
+
fn: FunctionExp;
|
|
145
|
+
}
|
|
146
|
+
export declare type GroupByClause = GroupByFieldClause | GroupByFnClause;
|
|
147
|
+
export interface GroupByFieldClause {
|
|
148
|
+
field: string;
|
|
149
|
+
}
|
|
150
|
+
export interface GroupByFnClause {
|
|
151
|
+
fn: FunctionExp;
|
|
152
|
+
}
|
|
153
|
+
export declare type HavingClause = HavingClauseWithoutOperator | HavingClauseWithRightCondition;
|
|
154
|
+
export interface HavingClauseWithoutOperator {
|
|
155
|
+
left: Condition;
|
|
156
|
+
}
|
|
157
|
+
export interface HavingClauseWithRightCondition extends HavingClauseWithoutOperator {
|
|
158
|
+
operator: LogicalOperator;
|
|
159
|
+
right: HavingClause;
|
|
160
|
+
}
|
|
161
|
+
export interface FunctionExp {
|
|
162
|
+
rawValue?: string;
|
|
163
|
+
functionName?: string;
|
|
164
|
+
alias?: string;
|
|
165
|
+
parameters?: (string | FunctionExp)[];
|
|
166
|
+
isAggregateFn?: boolean;
|
|
167
|
+
}
|
|
168
|
+
export interface WithDataCategoryClause {
|
|
169
|
+
conditions: WithDataCategoryCondition[];
|
|
170
|
+
}
|
|
171
|
+
export interface WithDataCategoryCondition {
|
|
172
|
+
groupName: string;
|
|
173
|
+
selector: GroupSelector;
|
|
174
|
+
parameters: string[];
|
|
175
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { hasAlias, isFieldSubquery, isGroupByField, isGroupByFn, isHavingClauseWithRightCondition, isNegationCondition, isOrderByField, isOrderByFn, isString, isSubquery, isValueCondition, isValueFunctionCondition, isValueQueryCondition, isValueWithDateLiteralCondition, isValueWithDateNLiteralCondition, isWhereClauseWithRightCondition, isWhereOrHavingClauseWithRightCondition } from '../utils';
|
|
2
|
+
import * as SoqlModels from './api-models';
|
|
3
|
+
export { hasAlias, isFieldSubquery, isGroupByField, isGroupByFn, isHavingClauseWithRightCondition, isNegationCondition, isOrderByField, isOrderByFn, isString, isSubquery, isValueCondition, isValueFunctionCondition, isValueQueryCondition, isValueWithDateLiteralCondition, isValueWithDateNLiteralCondition, isWhereClauseWithRightCondition, isWhereOrHavingClauseWithRightCondition, };
|
|
4
|
+
export declare type ComposeFieldInput = ComposeField | ComposeFieldFunction | ComposeFieldRelationship | ComposeFieldSubquery | ComposeFieldTypeof;
|
|
5
|
+
export interface ComposeField {
|
|
6
|
+
field: string;
|
|
7
|
+
objectPrefix?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ComposeFieldFunction {
|
|
10
|
+
fn?: string;
|
|
11
|
+
functionName: string;
|
|
12
|
+
parameters?: string | SoqlModels.FieldFunctionExpression | (string | SoqlModels.FieldFunctionExpression)[];
|
|
13
|
+
alias?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ComposeFieldRelationship {
|
|
16
|
+
field: string;
|
|
17
|
+
relationships: string[];
|
|
18
|
+
objectPrefix?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ComposeFieldSubquery {
|
|
21
|
+
subquery?: SoqlModels.Subquery;
|
|
22
|
+
}
|
|
23
|
+
export interface ComposeFieldTypeof {
|
|
24
|
+
field: string;
|
|
25
|
+
conditions: SoqlModels.FieldTypeOfCondition[];
|
|
26
|
+
}
|
|
27
|
+
export declare function getComposedField(input: string | ComposeFieldInput): SoqlModels.FieldType;
|
|
28
|
+
export declare function getField(input: string | ComposeFieldInput): SoqlModels.FieldType;
|
|
29
|
+
export declare function getFlattenedFields(query: SoqlModels.Query | SoqlModels.Subquery | SoqlModels.FieldSubquery, isAggregateResult?: boolean): string[];
|
|
@@ -0,0 +1,175 @@
|
|
|
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FieldType, GroupByClause, HavingClause, OrderByClause, Query, WhereClause, WithDataCategoryClause, FieldTypeOf, Subquery } from '../api/api-models';
|
|
2
|
+
import { Formatter, FormatOptions } from '../formatter/formatter';
|
|
3
|
+
import { ParseQueryConfig } from '../parser/parser';
|
|
4
|
+
export interface SoqlComposeConfig {
|
|
5
|
+
logging: boolean;
|
|
6
|
+
format: boolean;
|
|
7
|
+
formatOptions?: FormatOptions;
|
|
8
|
+
autoCompose: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function formatQuery(soql: string, formatOptions?: FormatOptions, parseOptions?: ParseQueryConfig): string;
|
|
11
|
+
export declare function composeQuery(soql: Query, config?: Partial<SoqlComposeConfig>): string;
|
|
12
|
+
export declare class Compose {
|
|
13
|
+
private soql;
|
|
14
|
+
logging: boolean;
|
|
15
|
+
format: boolean;
|
|
16
|
+
query: string;
|
|
17
|
+
formatter: Formatter;
|
|
18
|
+
constructor(soql: Query, config?: Partial<SoqlComposeConfig>);
|
|
19
|
+
start(): void;
|
|
20
|
+
private log;
|
|
21
|
+
private parseFn;
|
|
22
|
+
parseQuery(query: Query | Subquery): string;
|
|
23
|
+
parseFields(fields: FieldType[]): {
|
|
24
|
+
text: string;
|
|
25
|
+
typeOfClause?: string[];
|
|
26
|
+
}[];
|
|
27
|
+
parseTypeOfField(typeOfField: FieldTypeOf): string[];
|
|
28
|
+
parseWhereOrHavingClause(whereOrHaving: WhereClause | HavingClause, tabOffset?: number, priorConditionIsNegation?: boolean): string;
|
|
29
|
+
parseGroupByClause(groupBy: GroupByClause | GroupByClause[]): string;
|
|
30
|
+
parseOrderBy(orderBy: OrderByClause | OrderByClause[]): string;
|
|
31
|
+
parseWithDataCategory(withDataCategory: WithDataCategoryClause): string;
|
|
32
|
+
}
|