@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
@@ -1,223 +0,0 @@
1
- import { isNumber, generateParens } from '../utils';
2
- export class Formatter {
3
- enabled;
4
- options;
5
- currIndent = 1;
6
- constructor(enabled, options) {
7
- this.enabled = enabled;
8
- this.options = {
9
- numIndent: options.numIndent ?? 1,
10
- fieldMaxLineLength: options.fieldMaxLineLength ?? 60,
11
- fieldSubqueryParensOnOwnLine: options.fieldSubqueryParensOnOwnLine ?? true,
12
- whereClauseOperatorsIndented: true,
13
- newLineAfterKeywords: options.newLineAfterKeywords ?? false,
14
- logging: options.logging ?? false,
15
- };
16
- if (this.options.newLineAfterKeywords) {
17
- this.options.fieldSubqueryParensOnOwnLine = true;
18
- }
19
- }
20
- log(data) {
21
- if (this.options.logging) {
22
- console.log(data);
23
- }
24
- }
25
- getIndent(additionalIndent = 0) {
26
- return this.repeatChar((this.currIndent + additionalIndent) * (this.options.numIndent || 1), '\t');
27
- }
28
- repeatChar(numTimes, char) {
29
- return new Array(numTimes).fill(char).join('');
30
- }
31
- setSubquery(isSubquery) {
32
- this.currIndent = isSubquery ? (this.currIndent += 1) : (this.currIndent -= 1);
33
- }
34
- stepCurrIndex(num) {
35
- this.currIndent += num;
36
- }
37
- formatFields(fieldData) {
38
- function trimPrevSuffix(currIdx) {
39
- if (fieldData.fields[currIdx - 1]) {
40
- fieldData.fields[currIdx - 1].suffix = fieldData.fields[currIdx - 1].suffix.trim();
41
- }
42
- }
43
- fieldData.fields.forEach((field, i) => {
44
- field.suffix = fieldData.fields.length - 1 === i ? '' : ', ';
45
- });
46
- if (this.enabled) {
47
- let lineLen = 0;
48
- let newLineAndIndentNext = false;
49
- fieldData.fields.forEach((field, i) => {
50
- if (field.isSubquery) {
51
- trimPrevSuffix(i);
52
- field.prefix = `\n${this.getIndent()}`;
53
- field.suffix = fieldData.fields.length - 1 === i ? '' : ', ';
54
- lineLen = 0;
55
- newLineAndIndentNext = true;
56
- }
57
- else if (Array.isArray(field.typeOfClause)) {
58
- trimPrevSuffix(i);
59
- field.prefix = `\n${this.getIndent()}`;
60
- newLineAndIndentNext = true;
61
- }
62
- else if (isNumber(this.options.fieldMaxLineLength)) {
63
- lineLen += field.text.length + field.suffix.length;
64
- if (lineLen > this.options.fieldMaxLineLength || newLineAndIndentNext) {
65
- trimPrevSuffix(i);
66
- if (!this.options.newLineAfterKeywords || i > 0) {
67
- field.prefix += `\n${this.getIndent()}`;
68
- }
69
- lineLen = 0;
70
- newLineAndIndentNext = false;
71
- }
72
- }
73
- this.log(field);
74
- });
75
- }
76
- }
77
- formatTyeOfField(text, typeOfClause) {
78
- if (this.enabled && this.options.newLineAfterKeywords) {
79
- return typeOfClause
80
- .map((part, i) => {
81
- if (i === 0) {
82
- return part;
83
- }
84
- else if (i === typeOfClause.length - 1) {
85
- return `${this.getIndent()}${part}`;
86
- }
87
- else {
88
- return `${this.getIndent()}\t${part}`;
89
- }
90
- })
91
- .join('\n');
92
- }
93
- return text;
94
- }
95
- formatTypeofFieldCondition(condition) {
96
- let output = '';
97
- const fields = condition.fieldList.join(', ');
98
- if (this.enabled && this.options.newLineAfterKeywords) {
99
- const indent = this.getIndent();
100
- output = `${condition.type}`;
101
- if (condition.objectType) {
102
- output += `\n${indent}\t\t${condition.objectType}\n${indent}\tTHEN\n${indent}\t\t${fields}`;
103
- }
104
- else {
105
- output += `\n${indent}\t\t${fields}`;
106
- }
107
- }
108
- else {
109
- output = condition.type;
110
- if (condition.objectType) {
111
- output += ` ${condition.objectType} THEN ${fields}`;
112
- }
113
- else {
114
- output += ` ${fields}`;
115
- }
116
- }
117
- return output;
118
- }
119
- formatSubquery(queryStr, numTabs = 2, incrementTabsWhereClauseOpIndent = false) {
120
- if (incrementTabsWhereClauseOpIndent) {
121
- numTabs++;
122
- }
123
- let leftParen = '(';
124
- let rightParen = ')';
125
- if (this.enabled) {
126
- if (this.options.fieldSubqueryParensOnOwnLine || this.options.newLineAfterKeywords) {
127
- queryStr = queryStr.replace(/\n/g, `\n${this.repeatChar(numTabs, '\t')}`);
128
- leftParen = `(\n${this.repeatChar(numTabs, '\t')}`;
129
- rightParen = `\n${this.repeatChar(numTabs - 1, '\t')})`;
130
- }
131
- else {
132
- queryStr = queryStr.replace(/\n/g, '\n\t');
133
- }
134
- }
135
- return `${leftParen}${queryStr}${rightParen}`;
136
- }
137
- formatClause(clause) {
138
- if (this.enabled) {
139
- return this.options.newLineAfterKeywords ? `\n${clause}\n\t` : `\n${clause}`;
140
- }
141
- return ` ${clause}`;
142
- }
143
- formatText(text) {
144
- return this.enabled && (this.options.newLineAfterKeywords || text.startsWith('\n')) ? text : ` ${text}`;
145
- }
146
- formatWithIndent(text) {
147
- return this.enabled ? `${this.getIndent()}${text}` : text;
148
- }
149
- formatOrderByArray(groupBy) {
150
- if (this.enabled) {
151
- let currLen = 0;
152
- let output = '';
153
- groupBy.forEach((token, i) => {
154
- const nextToken = groupBy[i + 1];
155
- currLen += token.length;
156
- if (nextToken && (currLen + nextToken.length > (this.options.fieldMaxLineLength || 0) || this.options.newLineAfterKeywords)) {
157
- output += `${token},\n\t`;
158
- currLen = 0;
159
- }
160
- else {
161
- output += `${token}${nextToken ? ', ' : ''}`;
162
- }
163
- });
164
- return output;
165
- }
166
- else {
167
- return groupBy.join(', ');
168
- }
169
- }
170
- formatParens(count, character, leadingParenInline = false) {
171
- let output = '';
172
- if (isNumber(count) && count > 0) {
173
- if (this.enabled) {
174
- if (character === '(') {
175
- for (let i = 0; i < count; i++) {
176
- if (leadingParenInline && i === count - 1) {
177
- output += '(';
178
- }
179
- else {
180
- if (i === 0) {
181
- output += '(\n';
182
- }
183
- else {
184
- this.currIndent++;
185
- output += `${this.getIndent()}(\n`;
186
- }
187
- }
188
- }
189
- if (!leadingParenInline || count > 1) {
190
- this.currIndent++;
191
- }
192
- }
193
- else {
194
- for (let i = count - 1; i >= 0; i--) {
195
- if (leadingParenInline && i === count - 1) {
196
- output += ')';
197
- }
198
- else {
199
- this.currIndent--;
200
- output += `\n${this.getIndent()})`;
201
- }
202
- }
203
- }
204
- }
205
- else {
206
- output += generateParens(count, character);
207
- }
208
- }
209
- return output;
210
- }
211
- formatWhereClauseOperators(operator, whereClause, additionalIndent = 0) {
212
- const skipNewLineAndIndent = operator === 'NOT';
213
- if (this.enabled && !skipNewLineAndIndent) {
214
- return `\n${this.getIndent(additionalIndent)}${operator} ${whereClause}`;
215
- }
216
- else {
217
- return `${skipNewLineAndIndent ? '' : ' '}${operator} ${whereClause}`;
218
- }
219
- }
220
- formatAddNewLine(alt = ' ', skipNewLineAndIndent) {
221
- return this.enabled && !skipNewLineAndIndent ? `\n` : alt;
222
- }
223
- }
package/dist/esm/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { parseQuery, isQueryValid } from './parser/visitor';
2
- export * from './api/api-models';
3
- export * from './api/public-utils';
4
- export * from './composer/composer';
@@ -1 +0,0 @@
1
- export {};