@jetstreamapp/soql-parser-js 7.3.0 → 7.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.4.1
4
+
5
+ Aug 6, 2026
6
+
7
+ No changes to the published library — this release updates devDependencies and overhauls the release pipeline.
8
+
9
+ ### Dependencies
10
+
11
+ - Updated devDependencies to latest versions (prettier, release-it, tsx, vitest) and docs site dependencies (Docusaurus 3.10.2, React 19.2.8, TypeScript 6)
12
+
13
+ ## 7.4.0
14
+
15
+ Jul 16, 2026
16
+
17
+ ### Features
18
+
19
+ - **Added comment utilities: `stripComments`, `hasComments`, and `getComments`** — These operate on the raw query string without parsing it, so they work on any input (including invalid SOQL) and never throw. `stripComments` removes comments without otherwise modifying the query — no reformatting, no whitespace or keyword normalization — making it safe for proxying user-authored queries to the Salesforce API, which does not accept comments. When the query contains no comments, the original string is returned as-is, so it can be called unconditionally. A single space is inserted where removing a comment would otherwise merge adjacent tokens (`SELECT Id/*c*/FROM Account` → `SELECT Id FROM Account`). Comment markers inside string literals are treated as literal text, and an unterminated `/*` is stripped through the end of the input rather than throwing. `hasComments` returns whether a query contains any comments, and `getComments` returns each comment's type (`line` | `block`), text, and position.
20
+
3
21
  ## 7.3.0
4
22
 
5
23
  Jul 16, 2026
package/README.md CHANGED
@@ -74,6 +74,9 @@ Many of hte utility functions are provided to easily determine the shape of spec
74
74
  | hasAlias | Returns `true` if the field passed in has the `alias` property. | input: `string \| ComposeFieldInput` |
75
75
  | getField | Convenience method to construct fields in the correct format when using `composeQuery()`. Look in the data models section below for the structure of `ComposeFieldInput`. | input: `string \| ComposeFieldInput` |
76
76
  | getFlattenedFields | Flatten a Salesforce record based on the parsed SOQL Query. this is useful if you have relationships in your query and want to show the results in a table, using `.` dot notation for the relationship field headings. | soql: `Query \| Subquery \| FieldSubquery`<br> config?: `SoqlComposeConfig` |
77
+ | hasComments | Returns `true` if the query string contains at least one comment. Operates on the raw string without parsing it, so it works on any input and never throws. | soql: `string` |
78
+ | getComments | Returns all comments in the query string (type, text, and position), in order of appearance. Operates on the raw string without parsing it, so it works on any input and never throws. | soql: `string` |
79
+ | stripComments | Removes comments from a query string without otherwise modifying it. Returns the original string as-is if there are no comments. See [Comments in queries](#comments-in-queries). | soql: `string` |
77
80
  | isSubquery | Returns `true` if the data passed in is a subquery. | query: `Query \| Subquery` |
78
81
  | isFieldSubquery | Returns `true` if the data passed in is a FieldSubquery. | value: `any` |
79
82
  | isWhereClauseWithRightCondition | Returns `true` if the value passed in is a `WhereClause` with an `operator` and `right` property | value: `WhereClause` |
@@ -208,6 +211,30 @@ const soql = `
208
211
  composeQuery(parseQuery(soql)); // SELECT Id, Name FROM Account
209
212
  ```
210
213
 
214
+ If you want to remove comments from a query **without otherwise modifying it** (no reformatting, no whitespace or keyword normalization), use `stripComments`. It operates on the raw string without parsing it, so it works even on invalid SOQL and never throws — an unterminated `/*` is stripped through the end of the input rather than throwing like `parseQuery` does. When the query contains no comments the original string is returned unchanged, so it is safe to call on every query before sending it to the Salesforce API. A single space is inserted where removing a comment would otherwise merge adjacent tokens.
215
+
216
+ `hasComments` and `getComments` follow the same rules and can be used to detect or inspect comments without modifying the query.
217
+
218
+ ```typescript
219
+ import { stripComments, hasComments, getComments } from '@jetstreamapp/soql-parser-js';
220
+
221
+ stripComments(`SELECT Id, Name // the fields we need
222
+ FROM Account`);
223
+ // 'SELECT Id, Name \nFROM Account'
224
+
225
+ stripComments('SELECT Id/* comment */FROM Account'); // 'SELECT Id FROM Account'
226
+
227
+ const soql = "SELECT Id FROM Account WHERE Url = 'https://example.com'";
228
+ stripComments(soql) === soql; // true - no comments, original string returned as-is
229
+ hasComments(soql); // false
230
+
231
+ getComments('SELECT Id /* fields */ FROM Account // trailing');
232
+ // [
233
+ // { type: 'block', text: '/* fields */', start: 10, end: 22 },
234
+ // { type: 'line', text: '// trailing', start: 36, end: 47 },
235
+ // ]
236
+ ```
237
+
211
238
  ### Parsing a partial query
212
239
 
213
240
  Added support for `allowPartialQuery` in version `4.4.0`
@@ -537,10 +564,10 @@ WHERE Name LIKE 'a%'
537
564
 
538
565
  The library can be used as a Lightning Web Component in your Salesforce org. The build produces two artifacts to support different workflows:
539
566
 
540
- | Artifact | What it is | Best for |
541
- | ------------------------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------- |
542
- | `dist/lwc/soqlParserJs.js` | Standalone bundled JS file (no metadata) | SFDX projects — drop into your existing `lwc/soqlParserJs/` folder |
543
- | `dist/lwc-packaged/` (and the release zip) | Full Salesforce metadata package: `package.xml` + `lwc/soqlParserJs/{js,js-meta.xml}` | Direct deployment to an org via `sf project deploy start` — no SFDX project required |
567
+ | Artifact | What it is | Best for |
568
+ | ------------------------------------------ | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
569
+ | `dist/lwc/soqlParserJs.js` | Standalone bundled JS file (no metadata) | SFDX projects — drop into your existing `lwc/soqlParserJs/` folder |
570
+ | `dist/lwc-packaged/` (and the release zip) | Full Salesforce metadata package: `package.xml` + `lwc/soqlParserJs/{js,js-meta.xml}` | Direct deployment to an org via `sf project deploy start` — no SFDX project required |
544
571
 
545
572
  The Salesforce API version used for the metadata package is configured via the `salesforceApiVersion` field in [package.json](package.json) and is applied to both `package.xml` and `soqlParserJs.js-meta.xml` at build time.
546
573
 
@@ -615,6 +642,8 @@ export default class MyComponent extends LightningElement {
615
642
  }
616
643
  ```
617
644
 
645
+ <!-- LWC event bindings must be unquoted (onclick={handleClick}); prettier would add quotes -->
646
+ <!-- prettier-ignore -->
618
647
  ```html
619
648
  <template>
620
649
  <button class="slds-button slds-button_neutral" onclick={handleClick}>Click Me</button>
package/dist/cjs/index.js CHANGED
@@ -1,28 +1,28 @@
1
1
  /*!
2
- * @jetstreamapp/soql-parser-js v7.3.0
2
+ * @jetstreamapp/soql-parser-js v7.4.1
3
3
  * https://github.com/jetstreamapp/soql-parser-js
4
4
  * @license MIT
5
5
  */
6
- "use strict";var B=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var Fe=(i,e)=>{for(var s in e)B(i,s,{get:e[s],enumerable:!0})},me=(i,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Oe(e))!ge.call(i,n)&&n!==s&&B(i,n,{get:()=>e[n],enumerable:!(t=Le(e,n))||t.enumerable});return i};var ye=i=>me(B({},"__esModule",{value:!0}),i);var Be={};Fe(Be,{Compose:()=>W,composeQuery:()=>Ie,formatQuery:()=>We,getComposedField:()=>we,getField:()=>Se,getFlattenedFields:()=>$e,hasAlias:()=>b,isFieldSubquery:()=>J,isGroupByField:()=>U,isGroupByFn:()=>Ce,isHavingClauseWithRightCondition:()=>Ae,isNegationCondition:()=>y,isOrderByField:()=>w,isOrderByFn:()=>Te,isQueryValid:()=>ne,isString:()=>d,isSubquery:()=>g,isValueCondition:()=>de,isValueFunctionCondition:()=>v,isValueQueryCondition:()=>Y,isValueWithDateLiteralCondition:()=>Ne,isValueWithDateNLiteralCondition:()=>Re,isWhereClauseWithRightCondition:()=>fe,isWhereOrHavingClauseWithRightCondition:()=>P,parseQuery:()=>D});module.exports=ye(Be);var T=(r=>(r[r.AND=0]="AND",r[r.AS=1]="AS",r[r.ASC=2]="ASC",r[r.DESC=3]="DESC",r[r.CUBE=4]="CUBE",r[r.ELSE=5]="ELSE",r[r.EXCLUDES=6]="EXCLUDES",r[r.FALSE=7]="FALSE",r[r.FIRST=8]="FIRST",r[r.FROM=9]="FROM",r[r.GROUP_BY=10]="GROUP_BY",r[r.HAVING=11]="HAVING",r[r.IN=12]="IN",r[r.INCLUDES=13]="INCLUDES",r[r.LAST=14]="LAST",r[r.LIKE=15]="LIKE",r[r.LIMIT=16]="LIMIT",r[r.NOT=17]="NOT",r[r.NULL=18]="NULL",r[r.NULLS=19]="NULLS",r[r.OR=20]="OR",r[r.ORDER_BY=21]="ORDER_BY",r[r.ROLLUP=22]="ROLLUP",r[r.SELECT=23]="SELECT",r[r.TRUE=24]="TRUE",r[r.USING=25]="USING",r[r.WHERE=26]="WHERE",r[r.WITH=27]="WITH",r[r.FOR=28]="FOR",r[r.UPDATE=29]="UPDATE",r[r.ABOVE=30]="ABOVE",r[r.ABOVE_OR_BELOW=31]="ABOVE_OR_BELOW",r[r.APEX_NEW=32]="APEX_NEW",r[r.AT=33]="AT",r[r.BELOW=34]="BELOW",r[r.DATA_CATEGORY=35]="DATA_CATEGORY",r[r.END=36]="END",r[r.OFFSET=37]="OFFSET",r[r.REFERENCE=38]="REFERENCE",r[r.SCOPE=39]="SCOPE",r[r.TRACKING=40]="TRACKING",r[r.THEN=41]="THEN",r[r.TYPEOF=42]="TYPEOF",r[r.VIEW=43]="VIEW",r[r.VIEWSTAT=44]="VIEWSTAT",r[r.WHEN=45]="WHEN",r[r.SECURITY_ENFORCED=46]="SECURITY_ENFORCED",r[r.SYSTEM_MODE=47]="SYSTEM_MODE",r[r.USER_MODE=48]="USER_MODE",r[r.CALENDAR_MONTH=49]="CALENDAR_MONTH",r[r.CALENDAR_QUARTER=50]="CALENDAR_QUARTER",r[r.CALENDAR_YEAR=51]="CALENDAR_YEAR",r[r.DAY_IN_MONTH=52]="DAY_IN_MONTH",r[r.DAY_IN_WEEK=53]="DAY_IN_WEEK",r[r.DAY_IN_YEAR=54]="DAY_IN_YEAR",r[r.DAY_ONLY=55]="DAY_ONLY",r[r.FISCAL_MONTH=56]="FISCAL_MONTH",r[r.FISCAL_QUARTER=57]="FISCAL_QUARTER",r[r.FISCAL_YEAR=58]="FISCAL_YEAR",r[r.HOUR_IN_DAY=59]="HOUR_IN_DAY",r[r.WEEK_IN_MONTH=60]="WEEK_IN_MONTH",r[r.WEEK_IN_YEAR=61]="WEEK_IN_YEAR",r[r.AVG=62]="AVG",r[r.COUNT=63]="COUNT",r[r.COUNT_DISTINCT=64]="COUNT_DISTINCT",r[r.MIN=65]="MIN",r[r.MAX=66]="MAX",r[r.SUM=67]="SUM",r[r.DISTANCE=68]="DISTANCE",r[r.GEOLOCATION=69]="GEOLOCATION",r[r.FIELDS=70]="FIELDS",r[r.FORMAT=71]="FORMAT",r[r.TOLABEL=72]="TOLABEL",r[r.CONVERT_TIMEZONE=73]="CONVERT_TIMEZONE",r[r.CONVERT_CURRENCY=74]="CONVERT_CURRENCY",r[r.GROUPING=75]="GROUPING",r[r.ALL=76]="ALL",r[r.CUSTOM=77]="CUSTOM",r[r.STANDARD=78]="STANDARD",r[r.YESTERDAY=79]="YESTERDAY",r[r.TODAY=80]="TODAY",r[r.TOMORROW=81]="TOMORROW",r[r.LAST_WEEK=82]="LAST_WEEK",r[r.THIS_WEEK=83]="THIS_WEEK",r[r.NEXT_WEEK=84]="NEXT_WEEK",r[r.LAST_MONTH=85]="LAST_MONTH",r[r.THIS_MONTH=86]="THIS_MONTH",r[r.NEXT_MONTH=87]="NEXT_MONTH",r[r.LAST_90_DAYS=88]="LAST_90_DAYS",r[r.NEXT_90_DAYS=89]="NEXT_90_DAYS",r[r.THIS_QUARTER=90]="THIS_QUARTER",r[r.LAST_QUARTER=91]="LAST_QUARTER",r[r.NEXT_QUARTER=92]="NEXT_QUARTER",r[r.THIS_YEAR=93]="THIS_YEAR",r[r.LAST_YEAR=94]="LAST_YEAR",r[r.NEXT_YEAR=95]="NEXT_YEAR",r[r.THIS_FISCAL_QUARTER=96]="THIS_FISCAL_QUARTER",r[r.LAST_FISCAL_QUARTER=97]="LAST_FISCAL_QUARTER",r[r.NEXT_FISCAL_QUARTER=98]="NEXT_FISCAL_QUARTER",r[r.THIS_FISCAL_YEAR=99]="THIS_FISCAL_YEAR",r[r.LAST_FISCAL_YEAR=100]="LAST_FISCAL_YEAR",r[r.NEXT_FISCAL_YEAR=101]="NEXT_FISCAL_YEAR",r[r.NEXT_N_DAYS=102]="NEXT_N_DAYS",r[r.LAST_N_DAYS=103]="LAST_N_DAYS",r[r.N_DAYS_AGO=104]="N_DAYS_AGO",r[r.NEXT_N_WEEKS=105]="NEXT_N_WEEKS",r[r.LAST_N_WEEKS=106]="LAST_N_WEEKS",r[r.N_WEEKS_AGO=107]="N_WEEKS_AGO",r[r.NEXT_N_MONTHS=108]="NEXT_N_MONTHS",r[r.LAST_N_MONTHS=109]="LAST_N_MONTHS",r[r.N_MONTHS_AGO=110]="N_MONTHS_AGO",r[r.NEXT_N_QUARTERS=111]="NEXT_N_QUARTERS",r[r.LAST_N_QUARTERS=112]="LAST_N_QUARTERS",r[r.N_QUARTERS_AGO=113]="N_QUARTERS_AGO",r[r.NEXT_N_YEARS=114]="NEXT_N_YEARS",r[r.LAST_N_YEARS=115]="LAST_N_YEARS",r[r.N_YEARS_AGO=116]="N_YEARS_AGO",r[r.NEXT_N_FISCAL_QUARTERS=117]="NEXT_N_FISCAL_QUARTERS",r[r.LAST_N_FISCAL_QUARTERS=118]="LAST_N_FISCAL_QUARTERS",r[r.N_FISCAL_QUARTERS_AGO=119]="N_FISCAL_QUARTERS_AGO",r[r.NEXT_N_FISCAL_YEARS=120]="NEXT_N_FISCAL_YEARS",r[r.LAST_N_FISCAL_YEARS=121]="LAST_N_FISCAL_YEARS",r[r.N_FISCAL_YEARS_AGO=122]="N_FISCAL_YEARS_AGO",r[r.DELEGATED=123]="DELEGATED",r[r.EVERYTHING=124]="EVERYTHING",r[r.MINE_AND_MY_GROUPS=125]="MINE_AND_MY_GROUPS",r[r.MINE=126]="MINE",r[r.MY_TERRITORY=127]="MY_TERRITORY",r[r.MY_TEAM_TERRITORY=128]="MY_TEAM_TERRITORY",r[r.TEAM=129]="TEAM",r[r.ALL_PRIVATE=130]="ALL_PRIVATE",r[r.MRU=131]="MRU",r[r.EQUAL=132]="EQUAL",r[r.NOT_EQUAL=133]="NOT_EQUAL",r[r.LESS_THAN=134]="LESS_THAN",r[r.LESS_THAN_OR_EQUAL=135]="LESS_THAN_OR_EQUAL",r[r.GREATER_THAN=136]="GREATER_THAN",r[r.GREATER_THAN_OR_EQUAL=137]="GREATER_THAN_OR_EQUAL",r[r.L_PAREN=138]="L_PAREN",r[r.R_PAREN=139]="R_PAREN",r[r.L_SQUARE_BRACKET=140]="L_SQUARE_BRACKET",r[r.R_SQUARE_BRACKET=141]="R_SQUARE_BRACKET",r[r.DOT=142]="DOT",r[r.COMMA=143]="COMMA",r[r.COLON=144]="COLON",r[r.SEMICOLON=145]="SEMICOLON",r[r.ASTERISK=146]="ASTERISK",r[r.PLUS=147]="PLUS",r[r.MINUS=148]="MINUS",r[r.DATETIME=149]="DATETIME",r[r.DATE_TOKEN=150]="DATE_TOKEN",r[r.CURRENCY_PREFIXED_DECIMAL=151]="CURRENCY_PREFIXED_DECIMAL",r[r.CURRENCY_PREFIXED_INTEGER=152]="CURRENCY_PREFIXED_INTEGER",r[r.SIGNED_DECIMAL=153]="SIGNED_DECIMAL",r[r.UNSIGNED_DECIMAL=154]="UNSIGNED_DECIMAL",r[r.SIGNED_INTEGER=155]="SIGNED_INTEGER",r[r.UNSIGNED_INTEGER=156]="UNSIGNED_INTEGER",r[r.STRING_LITERAL=157]="STRING_LITERAL",r[r.GEOLOCATION_UNIT=158]="GEOLOCATION_UNIT",r[r.IDENTIFIER=159]="IDENTIFIER",r[r.EOF=160]="EOF",r))(T||{});function F(i){return i>=49&&i<=61}function m(i){return i>=62&&i<=67}function Q(i){return i>=68&&i<=69}function X(i){return i===70}function x(i){return i>=71&&i<=75}function te(i){return i>=76&&i<=78}function G(i){return i>=79&&i<=101}function M(i){return i>=102&&i<=122}function ie(i){return i>=123&&i<=131}function I(i){return i===159||i>=30&&i<=48||i>=49&&i<=61||i>=62&&i<=67||i>=68&&i<=69||i===70||i>=71&&i<=75||i>=76&&i<=78||i>=79&&i<=101||i>=102&&i<=122||i>=123&&i<=131||i===158||i===152}function j(i){return i===153||i===154||i===155||i===156}function re(i){return i>=132&&i<=137}var xe=new Map([["AND",0],["AS",1],["ASC",2],["DESC",3],["CUBE",4],["ELSE",5],["EXCLUDES",6],["FALSE",7],["FIRST",8],["FROM",9],["HAVING",11],["IN",12],["INCLUDES",13],["LAST",14],["LIKE",15],["LIMIT",16],["NOT",17],["NULL",18],["NULLS",19],["OR",20],["ROLLUP",22],["SELECT",23],["TRUE",24],["USING",25],["WHERE",26],["WITH",27],["FOR",28],["UPDATE",29],["ABOVE_OR_BELOW",31],["ABOVE",30],["NEW",32],["AT",33],["BELOW",34],["END",36],["OFFSET",37],["REFERENCE",38],["SCOPE",39],["TRACKING",40],["THEN",41],["TYPEOF",42],["VIEW",43],["VIEWSTAT",44],["WHEN",45],["SECURITY_ENFORCED",46],["SYSTEM_MODE",47],["USER_MODE",48],["CALENDAR_MONTH",49],["CALENDAR_QUARTER",50],["CALENDAR_YEAR",51],["DAY_IN_MONTH",52],["DAY_IN_WEEK",53],["DAY_IN_YEAR",54],["DAY_ONLY",55],["FISCAL_MONTH",56],["FISCAL_QUARTER",57],["FISCAL_YEAR",58],["HOUR_IN_DAY",59],["WEEK_IN_MONTH",60],["WEEK_IN_YEAR",61],["AVG",62],["COUNT_DISTINCT",64],["COUNT",63],["MIN",65],["MAX",66],["SUM",67],["DISTANCE",68],["GEOLOCATION",69],["FIELDS",70],["FORMAT",71],["TOLABEL",72],["CONVERTTIMEZONE",73],["CONVERTCURRENCY",74],["GROUPING",75],["ALL",76],["CUSTOM",77],["STANDARD",78],["YESTERDAY",79],["TODAY",80],["TOMORROW",81],["LAST_WEEK",82],["THIS_WEEK",83],["NEXT_WEEK",84],["LAST_MONTH",85],["THIS_MONTH",86],["NEXT_MONTH",87],["LAST_90_DAYS",88],["NEXT_90_DAYS",89],["THIS_QUARTER",90],["LAST_QUARTER",91],["NEXT_QUARTER",92],["THIS_YEAR",93],["LAST_YEAR",94],["NEXT_YEAR",95],["THIS_FISCAL_QUARTER",96],["LAST_FISCAL_QUARTER",97],["NEXT_FISCAL_QUARTER",98],["THIS_FISCAL_YEAR",99],["LAST_FISCAL_YEAR",100],["NEXT_FISCAL_YEAR",101],["NEXT_N_DAYS",102],["LAST_N_DAYS",103],["N_DAYS_AGO",104],["NEXT_N_WEEKS",105],["LAST_N_WEEKS",106],["N_WEEKS_AGO",107],["NEXT_N_MONTHS",108],["LAST_N_MONTHS",109],["N_MONTHS_AGO",110],["NEXT_N_QUARTERS",111],["LAST_N_QUARTERS",112],["N_QUARTERS_AGO",113],["NEXT_N_YEARS",114],["LAST_N_YEARS",115],["N_YEARS_AGO",116],["NEXT_N_FISCAL_QUARTERS",117],["LAST_N_FISCAL_QUARTERS",118],["N_FISCAL_QUARTERS_AGO",119],["NEXT_N_FISCAL_YEARS",120],["LAST_N_FISCAL_YEARS",121],["N_FISCAL_YEARS_AGO",122],["DELEGATED",123],["EVERYTHING",124],["MINEANDMYGROUPS",125],["MINE",126],["MY_TERRITORY",127],["MY_TEAM_TERRITORY",128],["TEAM",129],["ALLPRIVATE",130],["MRU",131]]),p=[];(function(){for(let e of Object.keys(T)){let s=T[e];typeof s=="number"&&(p[s]=e)}p[72]="toLabel",p[73]="convertTimezone",p[74]="convertCurrency",p[157]="StringIdentifier",p[150]="DATE",p[32]="new",p[125]="MineAndMyGroups",p[127]="MyTerritory",p[128]="MyTeamTerritory",p[130]="AllPrivate",p[123]="Delegated",p[124]="Everything",p[126]="Mine",p[129]="Team",p[131]="Mru",p[159]="Identifier",p[132]="EQUAL",p[156]="UNSIGNED_INTEGER",p[155]="SIGNED_INTEGER",p[154]="UNSIGNED_DECIMAL",p[153]="SIGNED_DECIMAL",p[151]="CURRENCY_PREFIXED_DECIMAL",p[152]="CURRENCY_PREFIXED_INTEGER"})();function A(i){return p[i]||T[i]}function q(i){return i>=65&&i<=90||i>=97&&i<=122}function c(i){return i>=48&&i<=57}function V(i){return q(i)||c(i)||i===95}function k(i){return i===32||i===9||i===10||i===13||i===12}function se(i){let e=[],s=i.length,t=0;for(;t<s;){let n=i.charCodeAt(t);if(k(n)){for(t++;t<s&&k(i.charCodeAt(t));)t++;continue}if(n===47){let a=t+1<s?i.charCodeAt(t+1):0;if(a===47){for(t+=2;t<s;){let o=i.charCodeAt(t);if(o===10||o===13)break;t++}continue}if(a===42){let o=t;t+=2;let E=!1;for(;t<s;){if(i.charCodeAt(t)===42&&t+1<s&&i.charCodeAt(t+1)===47){t+=2,E=!0;break}t++}if(!E)throw new Error(`Unterminated comment at position ${o}`);continue}}if(n===39){let a=t;for(t++;t<s;){let h=i.charCodeAt(t);if(h===92){t+=2;continue}if(h===39){t++;break}t++}let o=i.substring(a,t),l=o.substring(1,o.length-1).toUpperCase();l==="MI"||l==="KM"?e.push({kind:158,text:o,start:a}):e.push({kind:157,text:o,start:a});continue}if(c(n)){if(t+9<s&&i.charCodeAt(t+4)===45&&i.charCodeAt(t+7)===45){let o=!0;for(let E of[0,1,2,3,5,6,8,9])if(!c(i.charCodeAt(t+E))){o=!1;break}if(o)if(t+10<s&&(i.charCodeAt(t+10)===84||i.charCodeAt(t+10)===116)){let E=t;for(t+=11;t<s;){let l=i.charCodeAt(t);if(c(l)||l===58)t++;else break}if(t<s&&i.charCodeAt(t)===46)for(t++;t<s&&c(i.charCodeAt(t));)t++;if(t<s){let l=i.charCodeAt(t);if(l===90||l===122)t++;else if(l===46){for(t++;t<s&&c(i.charCodeAt(t));)t++;t<s&&(i.charCodeAt(t)===90||i.charCodeAt(t)===122)&&t++}else if(l===43||l===45)for(t++;t<s;){let h=i.charCodeAt(t);if(c(h)||h===58)t++;else break}}e.push({kind:149,text:i.substring(E,t),start:E});continue}else{let E=t;t+=10,e.push({kind:150,text:i.substring(E,t),start:E});continue}}let a=t;for(;t<s&&c(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&c(i.charCodeAt(t+1))){for(t++;t<s&&c(i.charCodeAt(t));)t++;e.push({kind:154,text:i.substring(a,t),start:a});continue}e.push({kind:156,text:i.substring(a,t),start:a});continue}if(n===33){if(t+1<s&&i.charCodeAt(t+1)===61){e.push({kind:133,text:"!=",start:t}),t+=2;continue}throw new Error(`Unexpected character '!' at position ${t}`)}if(n===60){if(t+1<s){let a=i.charCodeAt(t+1);if(a===61){e.push({kind:135,text:"<=",start:t}),t+=2;continue}if(a===62){e.push({kind:133,text:"<>",start:t}),t+=2;continue}}e.push({kind:134,text:"<",start:t}),t++;continue}if(n===62){if(t+1<s&&i.charCodeAt(t+1)===61){e.push({kind:137,text:">=",start:t}),t+=2;continue}e.push({kind:136,text:">",start:t}),t++;continue}if(n===61){e.push({kind:132,text:"=",start:t}),t++;continue}if(n===40){e.push({kind:138,text:"(",start:t}),t++;continue}if(n===41){e.push({kind:139,text:")",start:t}),t++;continue}if(n===91){e.push({kind:140,text:"[",start:t}),t++;continue}if(n===93){e.push({kind:141,text:"]",start:t}),t++;continue}if(n===44){e.push({kind:143,text:",",start:t}),t++;continue}if(n===58){e.push({kind:144,text:":",start:t}),t++;continue}if(n===59){e.push({kind:145,text:";",start:t}),t++;continue}if(n===42){e.push({kind:146,text:"*",start:t}),t++;continue}if(n===43||n===45){if(t+1<s){let a=i.charCodeAt(t+1);if(c(a)){let o=t;for(t++;t<s&&c(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&c(i.charCodeAt(t+1))){for(t++;t<s&&c(i.charCodeAt(t));)t++;e.push({kind:153,text:i.substring(o,t),start:o});continue}e.push({kind:155,text:i.substring(o,t),start:o});continue}if(a===46&&t+2<s&&c(i.charCodeAt(t+2))){let o=t;for(t+=2;t<s&&c(i.charCodeAt(t));)t++;e.push({kind:153,text:i.substring(o,t),start:o});continue}}e.push({kind:n===43?147:148,text:i[t],start:t}),t++;continue}if(n===46){if(t+1<s&&c(i.charCodeAt(t+1))){let a=t;for(t++;t<s&&c(i.charCodeAt(t));)t++;e.push({kind:154,text:i.substring(a,t),start:a});continue}e.push({kind:142,text:".",start:t}),t++;continue}if(q(n)){let a=t;for(t++;t<s;){let h=i.charCodeAt(t);if(V(h)||h===46)t++;else break}let o=i.substring(a,t);if(o.includes(".."))throw new Error(`Invalid identifier with consecutive dots at position ${a}: "${o}"`);let E=o.toUpperCase();if(E==="ORDER"&&!o.includes(".")){let h=H(i,t,"BY");if(h!==-1){let u=i.substring(a,h);e.push({kind:21,text:u,start:a}),t=h;continue}}if(E==="GROUP"&&!o.includes(".")){let h=H(i,t,"BY");if(h!==-1){let u=i.substring(a,h);e.push({kind:10,text:u,start:a}),t=h;continue}}if(E==="DATA"&&!o.includes(".")){let h=H(i,t,"CATEGORY");if(h!==-1){let u=i.substring(a,h);e.push({kind:35,text:u,start:a}),t=h;continue}}if(o.length>=4){let h=o.substring(0,3);if(ee(h)){let u=o.substring(3);if(De(u)){u.includes(".")?e.push({kind:151,text:o,start:a}):e.push({kind:152,text:o,start:a});continue}}}if(o.length===3&&ee(o)){let h=t,u=t,R=!1;if(u<s&&i.charCodeAt(u)===45&&(R=!0,u++),R&&u<s&&c(i.charCodeAt(u))){for(;u<s&&c(i.charCodeAt(u));)u++;if(u<s&&i.charCodeAt(u)===46&&u+1<s&&c(i.charCodeAt(u+1))){for(u++;u<s&&c(i.charCodeAt(u));)u++;let f=i.substring(a,u);e.push({kind:151,text:f,start:a}),t=u;continue}if(u>=s||!V(i.charCodeAt(u))&&i.charCodeAt(u)!==46){let f=i.substring(a,u);e.push({kind:152,text:f,start:a}),t=u;continue}t=h}}if(o.includes(".")){e.push({kind:159,text:o,start:a});continue}let l=xe.get(E);if(l!==void 0){e.push({kind:l,text:o,start:a});continue}e.push({kind:159,text:o,start:a});continue}throw new Error(`Unexpected character '${i[t]}' (code ${n}) at position ${t}`)}return e.push({kind:160,text:"",start:t}),e}function H(i,e,s){let t=i.length,n=e;if(n>=t||!k(i.charCodeAt(n)))return-1;for(;n<t&&k(i.charCodeAt(n));)n++;let a=s.length;if(n+a>t)return-1;for(let E=0;E<a;E++){let l=i.charCodeAt(n+E),h=s.charCodeAt(E);if((l>=97&&l<=122?l-32:l)!==h)return-1}let o=n+a;if(o<t){let E=i.charCodeAt(o);if(V(E)||E===46)return-1}return o}function ee(i){for(let e=0;e<i.length;e++)if(!q(i.charCodeAt(e)))return!1;return!0}function De(i){if(i.length===0)return!1;let e=0;if(i.charCodeAt(e)===45&&e++,e>=i.length||!c(i.charCodeAt(e)))return!1;for(;e<i.length&&c(i.charCodeAt(e));)e++;if(e<i.length&&i.charCodeAt(e)===46){if(e++,e>=i.length||!c(i.charCodeAt(e)))return!1;for(;e<i.length&&c(i.charCodeAt(e));)e++}return e===i.length}var be=new Set([23,9,26,21,10,11,16,27,28,29,25,19,2,3,0,20,17,45,41,5,36,42,143,139,160]),K=class i{constructor(e,s){this.pos=0;this.tokens=e,this.config=s}getPos(){return this.pos}peek(){return this.tokens[this.pos]}peekAt(e){let s=this.pos+e;return s>=this.tokens.length?this.tokens[this.tokens.length-1]:this.tokens[s]}advance(){let e=this.tokens[this.pos];return e.kind!==160&&this.pos++,e}expect(e){let s=this.peek();if(s.kind!==e)throw this.error(`Expected ${T[e]} but found ${T[s.kind]} ("${s.text}") at position ${s.start}`);return this.advance()}match(e){return this.peek().kind===e?(this.advance(),!0):!1}check(e){return this.peek().kind===e}isAtEnd(){return this.peek().kind===160}error(e){return this.config.logErrors&&console.log(e),new Error(e)}static{this.CLAUSE_BOUNDARY_KINDS=new Set([26,21,10,11,16,37,27,28,29,25,160])}isAtClauseBoundary(){let e=this.peek().kind;return i.CLAUSE_BOUNDARY_KINDS.has(e)||e===139}synchronize(){for(;!this.isAtEnd();){if(this.isAtClauseBoundary())return;this.advance()}}consumeIdentifier(){let e=this.peek();if(I(e.kind))return this.advance();throw this.error(`Expected identifier but found ${T[e.kind]} ("${e.text}") at position ${e.start}`)}checkIdentifier(){return I(this.peek().kind)}isFunctionCall(){let e=this.peek(),s=this.peekAt(1);return(F(e.kind)||m(e.kind)||Q(e.kind)||X(e.kind)||x(e.kind))&&s.kind===138}canBeAlias(){let e=this.peek();return!(!I(e.kind)||be.has(e.kind)||e.kind===37&&this.peekAt(1).kind===156)}getLiteralType(e){let s=A(e);return s==="UNSIGNED_INTEGER"||s==="SIGNED_INTEGER"?"INTEGER":s==="UNSIGNED_DECIMAL"||s==="SIGNED_DECIMAL"?"DECIMAL":s==="CURRENCY_PREFIXED_DECIMAL"?"DECIMAL_WITH_CURRENCY_PREFIX":s==="CURRENCY_PREFIXED_INTEGER"?"INTEGER_WITH_CURRENCY_PREFIX":s==="DATETIME"?"DATETIME":s==="DATE"?"DATE":s==="NULL"?"NULL":s==="StringIdentifier"||s==="Identifier"?"STRING":s==="TRUE"||s==="FALSE"?"BOOLEAN":G(e)?"DATE_LITERAL":M(e)?"DATE_N_LITERAL":"STRING"}parseSelectStatement(e=!1){let s=this.parseSelectClause(),t=this.parseFromClause(),n;e?(n={fields:s,relationshipName:t.sObject},t.sObjectPrefix&&(n.sObjectPrefix=t.sObjectPrefix)):n={fields:s,sObject:t.sObject},t.alias&&(n.sObjectAlias=t.alias),this.applySObjectAlias(n);let a=this.parseClauseStatements();return Object.assign(n,a),n}parseSelectStatementPartial(){let e,s;this.check(23)&&(e=this.parseSelectClause()),this.check(9)&&(s=this.parseFromClause());let t={};e&&(t.fields=e),s&&(t.sObject=s.sObject,s.alias&&(t.sObjectAlias=s.alias)),t.fields&&this.applySObjectAlias(t);let n=this.parseClauseStatements();return Object.assign(t,n),t}applySObjectAlias(e){if(!e.sObjectAlias||!Array.isArray(e.fields))return;let s=e.sObjectAlias;e.fields.forEach(t=>{t.relationships&&t.relationships[0]===s&&(t.relationships=t.relationships.slice(1),t.objectPrefix=s,t.relationships.length===0&&(delete t.relationships,t.type="Field"))})}parseSelectClause(){this.expect(23);let e=[];for(e.push(this.parseSelectField());this.match(143);)e.push(this.parseSelectField());return e}parseSelectField(){let e=this.peek(),s=this.peekAt(1);return e.kind===138&&s.kind===23?this.parseSelectClauseSubqueryIdentifier():e.kind===42?this.parseSelectClauseTypeOf():this.isFunctionCall()?this.parseSelectClauseFunctionIdentifier():this.parseSelectClauseIdentifier()}parseSelectClauseFunctionIdentifier(){let e=this.parseAnyFunction(!0);return this.canBeAlias()&&(e.alias=this.consumeIdentifier().text),e}parseSelectClauseSubqueryIdentifier(){this.expect(138);let e=this.parseSelectStatement(!0);return this.expect(139),{type:"FieldSubquery",subquery:e}}parseSelectClauseTypeOf(){this.expect(42);let e=this.consumeIdentifier().text,s=[];for(;this.check(45);){this.advance();let t=this.consumeIdentifier().text;this.expect(41);let n=[];for(n.push(this.consumeIdentifier().text);this.match(143);)n.push(this.consumeIdentifier().text);s.push({type:"WHEN",objectType:t,fieldList:n})}if(this.check(5)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);s.push({type:"ELSE",fieldList:t})}return this.expect(36),{type:"FieldTypeof",field:e,conditions:s}}parseSelectClauseIdentifier(){let s=this.consumeIdentifier().text,t;if(!s.includes("."))t={type:"Field",field:s};else{let n=s.split(".");t={type:"FieldRelationship",field:n[n.length-1],relationships:n.slice(0,n.length-1),rawValue:s}}return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseFromClause(){this.expect(9);let s=this.consumeIdentifier().text,t;if(s.includes(".")){let n=s.split(".");t={sObjectPrefix:n.slice(0,n.length-1),sObject:n[n.length-1]}}else t={sObject:s};return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseClauseStatements(){let e={},s=(t,n)=>{if(this.config.ignoreParseErrors)try{t(),this.isAtClauseBoundary()||(n&&n(),this.synchronize())}catch(a){this.config.logErrors&&console.log(a),n&&n(),this.synchronize()}else t()};for(this.check(25)&&s(()=>{e.usingScope=this.parseUsingScope()}),this.check(26)&&s(()=>{e.where=this.parseWhereClause()},()=>{delete e.where});this.check(27);)s(()=>{let t=this.parseWithClause();t.withSecurityEnforced&&(e.withSecurityEnforced=!0),t.withAccessLevel&&(e.withAccessLevel=t.withAccessLevel),t.withDataCategory&&(e.withDataCategory=t.withDataCategory)});return this.check(10)&&(s(()=>{e.groupBy=this.parseGroupByClause()}),this.check(11)&&s(()=>{e.having=this.parseHavingClause()})),this.check(21)&&s(()=>{e.orderBy=this.parseOrderByClause()}),this.check(16)&&s(()=>{this.advance(),e.limit=Number(this.expect(156).text)}),this.check(37)&&s(()=>{this.advance(),e.offset=Number(this.expect(156).text)}),this.check(28)&&s(()=>{this.advance();let t=this.peek();if(t.kind===43||t.kind===38||t.kind===29)e.for=A(this.advance().kind);else throw this.error(`Expected VIEW, REFERENCE, or UPDATE after FOR at position ${t.start}`)}),this.check(29)&&s(()=>{this.advance();let t=this.peek();if(t.kind===40||t.kind===44)e.update=A(this.advance().kind);else throw this.error(`Expected TRACKING or VIEWSTAT after UPDATE at position ${t.start}`)}),e}parseUsingScope(){this.expect(25),this.expect(39);let e=this.peek();if(ie(e.kind))return this.advance().text;if(I(e.kind))return this.advance().text;throw this.error(`Expected scope enumeration value at position ${e.start}`)}parseWhereClause(){return this.expect(26),this.parseConditionExpressions(!0,!0)}parseConditionExpressions(e,s){let t,n,a={left:0,right:0};for(;;){let o;if(t)if(this.check(0))o="AND",this.advance();else if(this.check(20))o="OR",this.advance();else break;let E={},l=E,h=null;for(;this.hasNegationPrefix();){let f=0;for(;this.check(138)&&this.isNegationAhead();)this.advance(),f++,a.left++;if(this.check(17)){this.advance();let _={left:f>0?{openParen:f}:null,operator:"NOT",right:{left:{}}};h?h.right=_:E=_,h=_,l=_.right}else break}l.left=this.parseExpression(e,s,a),t?o&&(n.operator=o,n.right=E):(t=E,n=E);let u=E;for(;u.right&&u.right.left!==void 0;){let f=u.right;if(f.right&&f.right.left!==void 0)u=f;else{u=f;break}}if(n=u,this.isAtEnd())break;let R=this.peek().kind;if(R!==0&&R!==20)break}if(a.left!==a.right)throw this.error(`Mismatched parentheses in WHERE/HAVING clause: ${a.left} open vs ${a.right} close`);return t}hasNegationPrefix(){let e=0;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}isNegationAhead(){let e=1;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}parseExpression(e,s,t){let n=0;for(;this.check(138)&&!this.isSubqueryStart()&&!this.isArrayExpressionStart();)this.advance(),n++,t&&t.left++;let a,o=!1;e&&m(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseAggregateFunction(!1),o=!0):s&&Q(this.peek().kind)&&this.peek().kind===68&&this.peekAt(1).kind===138?(a=this.parseLocationFunction(!1),o=!0):F(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseDateFunction(!1),o=!0):x(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseOtherFunction(!1),o=!0):a=this.consumeIdentifier().text;let E=this.parseOperator(),l=E.operator,h=E.isSet,u,R,f;if(h)if(this.check(138)&&this.peekAt(1).kind===23)this.expect(138),u=this.parseSelectStatement(!1),this.expect(139),R="SUBQUERY";else if(this.config.allowApexBindVariables&&this.check(144))u=this.parseApexBindVariable().value,R="APEX_BIND_VARIABLE";else{let S=this.parseArrayExpression();u=S.values,R=S.literalType,f=S.dateLiteralVariable}else{let S=this.parseAtomicValue();u=S.value,R=S.literalType,f=S.dateLiteralVariable}let _=0;for(;this.check(139)&&(!t||t.left>t.right);)this.advance(),_++,t&&t.right++;let C={};return o?C.fn=a:C.field=a,C.operator=l,R==="SUBQUERY"?C.valueQuery=u:C.value=u,C.literalType=R,f!==void 0&&(C.dateLiteralVariable=f),n>0&&(C.openParen=n),_>0&&(C.closeParen=_),C}isSubqueryStart(){return this.check(138)&&this.peekAt(1).kind===23}isArrayExpressionStart(){return!1}parseOperator(){let e=this.peek();if(re(e.kind))return{operator:this.advance().text,isSet:!1};if(e.kind===15)return this.advance(),{operator:"LIKE",isSet:!1};if(e.kind===12)return this.advance(),{operator:"IN",isSet:!0};if(e.kind===17&&this.peekAt(1).kind===12)return this.advance(),this.advance(),{operator:"NOT IN",isSet:!0};if(e.kind===13)return this.advance(),{operator:"INCLUDES",isSet:!0};if(e.kind===6)return this.advance(),{operator:"EXCLUDES",isSet:!0};throw this.error(`Expected operator but found ${T[e.kind]} ("${e.text}") at position ${e.start}`)}parseAtomicValue(){let e=this.peek();if(this.config.allowApexBindVariables&&e.kind===144)return{value:this.parseApexBindVariable().value,literalType:"APEX_BIND_VARIABLE"};if(e.kind===157)return{value:this.advance().text,literalType:"STRING"};if(e.kind===158)return{value:this.advance().text,literalType:"STRING"};if(e.kind===156)return{value:this.advance().text,literalType:"INTEGER"};if(e.kind===155)return{value:this.advance().text,literalType:"INTEGER"};if(e.kind===154)return{value:this.advance().text,literalType:"DECIMAL"};if(e.kind===153)return{value:this.advance().text,literalType:"DECIMAL"};if(e.kind===151)return{value:this.advance().text,literalType:"DECIMAL_WITH_CURRENCY_PREFIX"};if(e.kind===152)return{value:this.advance().text,literalType:"INTEGER_WITH_CURRENCY_PREFIX"};if(e.kind===149)return{value:this.advance().text,literalType:"DATETIME"};if(e.kind===150)return{value:this.advance().text,literalType:"DATE"};if(e.kind===18)return this.advance(),{value:"NULL",literalType:"NULL"};if(e.kind===24||e.kind===7)return{value:A(this.advance().kind),literalType:"BOOLEAN"};if(G(e.kind))return{value:this.advance().text,literalType:"DATE_LITERAL"};if(M(e.kind)){let s=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${s.text}:${n}`,literalType:"DATE_N_LITERAL",dateLiteralVariable:n}}throw this.error(`Expected value but found ${T[e.kind]} ("${e.text}") at position ${e.start}`)}parseArrayExpression(){this.expect(138);let e=[];for(e.push(this.parseArrayItem());this.match(143);)e.push(this.parseArrayItem());this.expect(139);let s=e.map(l=>l.value),t=e.map(l=>l.type),n=e.map(l=>l.variable!==void 0?l.variable:null),a=n.some(l=>l!==null),o;new Set(t).size===1?o=this.getLiteralType(this.tokenKindFromTypeName(t[0])):o=t.map(l=>this.getLiteralType(this.tokenKindFromTypeName(l)));let E={values:s,literalType:o};return a&&(E.dateLiteralVariable=n),E}tokenKindFromTypeName(e){for(let s=0;s<=160;s++)if(A(s)===e)return s;return 159}parseArrayItem(){let e=this.peek();if(e.kind===157)return{value:this.advance().text,type:A(157)};if(e.kind===158)return{value:this.advance().text,type:A(158)};if(e.kind===151)return{value:this.advance().text,type:A(151)};if(e.kind===152)return{value:this.advance().text,type:A(152)};if(j(e.kind)){let s=this.advance();return{value:s.text,type:A(s.kind)}}if(e.kind===149)return{value:this.advance().text,type:A(149)};if(e.kind===150)return{value:this.advance().text,type:A(150)};if(e.kind===18)return this.advance(),{value:"NULL",type:"NULL"};if(e.kind===24)return{value:this.advance().text,type:"TRUE"};if(e.kind===7)return{value:this.advance().text,type:"FALSE"};if(G(e.kind))return{value:this.advance().text,type:A(e.kind)};if(M(e.kind)){let s=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${s.text}:${n}`,type:A(s.kind),variable:n}}throw this.error(`Expected array value but found ${T[e.kind]} ("${e.text}") at position ${e.start}`)}parseApexBindVariable(){this.expect(144);let e=[];for(this.check(32)?e.push(this.parseApexBindNewInstantiation()):this.checkIdentifier()&&(this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):e.push(this.parseApexBindIdentifier()));this.check(142);)this.advance(),this.checkIdentifier()&&this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):this.checkIdentifier()&&e.push(this.parseApexBindIdentifier());return{value:e.join(".")}}parseApexBindIdentifier(){let e=this.consumeIdentifier().text;return this.check(140)&&(e+=this.parseApexBindArrayAccessor()),e}parseApexBindNewInstantiation(){this.expect(32);let s=`new ${this.consumeIdentifier().text}`;if(this.check(134)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);this.expect(136),s+=`<${t.join(", ")}>`}return s+=this.parseApexBindFunctionParams(),this.check(140)&&(s+=this.parseApexBindArrayAccessor()),s}parseApexBindFunctionCall(){let s=this.consumeIdentifier().text+this.parseApexBindFunctionParams();return this.check(140)&&(s+=this.parseApexBindArrayAccessor()),s}parseApexBindFunctionParams(){this.expect(138);let e=[];if(!this.check(139))for(e.push(this.consumeIdentifier().text);this.match(143);)e.push(this.consumeIdentifier().text);return this.expect(139),`(${e.join(", ")})`}parseApexBindArrayAccessor(){this.expect(140);let e=this.peek(),s;if(e.kind===156)s=this.advance().text;else if(I(e.kind))s=this.advance().text;else throw this.error(`Expected integer or identifier in array accessor at position ${e.start}`);return this.expect(141),`[${s}]`}parseAnyFunction(e){let s=this.peek();if(F(s.kind))return this.parseDateFunction(e);if(m(s.kind))return this.parseAggregateFunction(e);if(s.kind===68)return this.parseLocationFunction(e);if(X(s.kind))return this.parseFieldsFunction(e);if(x(s.kind))return this.parseOtherFunction(e);throw this.error(`Expected function name but found ${T[s.kind]} at position ${s.start}`)}parseDateFunction(e){let s=this.advance(),t=A(s.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${s.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseAggregateFunction(e){let s=this.advance(),t=A(s.kind),n=this.parseFunctionExpression(!0,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${s.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseFieldsFunction(e){this.advance(),this.expect(138);let s=this.peek(),t;if(te(s.kind))t=this.advance().text;else if(I(s.kind))t=this.advance().text;else throw this.error(`Expected FIELDS function parameter at position ${s.start}`);this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="FIELDS",n.parameters=[t],n.rawValue=`FIELDS(${t})`,n}parseOtherFunction(e){let s=this.advance(),t=A(s.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,a.rawValue=`${s.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseLocationFunction(e){this.advance(),this.expect(138);let s=this.consumeIdentifier().text;this.expect(143);let t;this.check(69)&&this.peekAt(1).kind===138?t=this.parseGeolocationFunction(e):t=this.consumeIdentifier().text,this.expect(143);let n=this.expect(158).text;this.expect(139);let a={};e&&(a.type="FieldFunctionExpression"),a.functionName="DISTANCE",a.parameters=[s,t,n],e&&(a.isAggregateFn=!0);let o=typeof t=="string"?t:t.rawValue;return a.rawValue=`DISTANCE(${s}, ${o}, ${n})`,a}parseGeolocationFunction(e){this.advance(),this.expect(138);let s=this.parseNumberValue();this.expect(143);let t=this.parseNumberValue();this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="GEOLOCATION",n.parameters=[s,t],n.rawValue=`GEOLOCATION(${s}, ${t})`,n}parseNumberValue(){let e=this.peek();if(e.kind===156||e.kind===155||e.kind===154||e.kind===153)return this.advance().text;throw this.error(`Expected number but found ${T[e.kind]} ("${e.text}") at position ${e.start}`)}parseFunctionExpression(e,s=!0){this.expect(138);let t=[];if(!this.check(139))for(t.push(this.parseFunctionParam(e,s));this.match(143);)t.push(this.parseFunctionParam(e,s));return this.expect(139),t}parseFunctionParam(e,s){let t=this.peek(),n=this.peekAt(1);if(!e&&m(t.kind)&&n.kind===138)return this.parseAggregateFunction(s);if(x(t.kind)&&n.kind===138)return this.parseOtherFunction(s);if(t.kind===157)return this.advance().text;if(j(t.kind))return this.advance().text;if(I(t.kind))return this.advance().text;throw this.error(`Expected function parameter but found ${T[t.kind]} ("${t.text}") at position ${t.start}`)}parseGroupByClause(){this.expect(10);let e=[];for(e.push(this.parseGroupByItem());this.match(143);)e.push(this.parseGroupByItem());return e}parseGroupByItem(){let e=this.peek();return e.kind===4&&this.peekAt(1).kind===138?{fn:this.parseCubeOrRollupFunction("CUBE")}:e.kind===22&&this.peekAt(1).kind===138?{fn:this.parseCubeOrRollupFunction("ROLLUP")}:F(e.kind)&&this.peekAt(1).kind===138?{fn:this.parseDateFunction(!1)}:{field:this.consumeIdentifier().text}}parseCubeOrRollupFunction(e){let s=this.advance(),t=this.parseFunctionExpression(!1);return{functionName:e,parameters:t,rawValue:`${e}(${t.join(", ")})`}}parseHavingClause(){return this.expect(11),this.parseConditionExpressions(!0,!1)}parseOrderByClause(){this.expect(21);let e=[];for(e.push(this.parseOrderByItem());this.match(143);)e.push(this.parseOrderByItem());return e}parseOrderByItem(){let e=this.peek(),s=this.peekAt(1),t;if(e.kind===75&&s.kind===138){let n=this.advance(),a=this.parseFunctionExpression(!1);t={fn:{functionName:A(n.kind),parameters:a,rawValue:`${n.text}(${a.join(", ")})`}}}else m(e.kind)&&s.kind===138?t={fn:this.parseAggregateFunction(!1)}:F(e.kind)&&s.kind===138?t={fn:this.parseDateFunction(!1)}:e.kind===68&&s.kind===138?t={fn:this.parseLocationFunction(!1)}:t={field:this.consumeIdentifier().text};if(this.check(2)?t.order=A(this.advance().kind):this.check(3)&&(t.order=A(this.advance().kind)),this.check(19))if(this.advance(),this.check(8))t.nulls=A(this.advance().kind);else if(this.check(14))t.nulls=A(this.advance().kind);else throw this.error(`Expected FIRST or LAST after NULLS at position ${this.peek().start}`);return t}parseWithClause(){this.expect(27);let e=this.peek();if(e.kind===46)return this.advance(),{withSecurityEnforced:!0};if(e.kind===48)return this.advance(),{withAccessLevel:"USER_MODE"};if(e.kind===47)return this.advance(),{withAccessLevel:"SYSTEM_MODE"};if(e.kind===35)return{withDataCategory:this.parseWithDataCategory()};throw this.error(`Expected SECURITY_ENFORCED, USER_MODE, SYSTEM_MODE, or DATA CATEGORY after WITH at position ${e.start}`)}parseWithDataCategory(){this.expect(35);let e=[];for(e.push(this.parseDataCategoryCondition());this.check(0);)this.advance(),e.push(this.parseDataCategoryCondition());return{conditions:e}}parseDataCategoryCondition(){let e=this.consumeIdentifier().text,s=this.peek(),t;if(s.kind===33||s.kind===30||s.kind===34||s.kind===31)t=this.advance().text;else throw this.error(`Expected data category selector (AT, ABOVE, BELOW, ABOVE_OR_BELOW) at position ${s.start}`);let n=this.match(138),a=[];for(a.push(this.consumeIdentifier().text);this.match(143);)a.push(this.consumeIdentifier().text);return n&&this.expect(139),{groupName:e,selector:t,parameters:a}}};function D(i,e){let s=e||{},t=se(i),n=new K(t,s),a;if(s.allowPartialQuery?a=n.parseSelectStatementPartial():a=n.parseSelectStatement(!1),!n.isAtEnd()&&!s.ignoreParseErrors){let o=t[n.getPos()];throw new Error(`Unexpected token "${o.text}" at position ${o.start}. Expected end of query.`)}return a}function ne(i,e){try{return D(i,e),!0}catch{return!1}}function d(i){return typeof i=="string"}function Ue(i){return i?i.every(e=>d(e)):!1}function L(i){return Number.isFinite(i)}function N(i){return i==null}function O(i,e,s){return N(i)?"":`${s||""}${i}${e||""}`}function ae(i,e=!1){return Array.isArray(i)?i.length>0?`(${i.join(", ")})`:e?"()":"":e?`(${i||""})`:i||""}function oe(i,e,s=""){return L(i)&&i>0?new Array(i).fill(e).join(s):""}function Z(i){return!i.parameters||i.parameters.length===0?[]:Ue(i.parameters)?i.parameters:d(i.parameters[0])?[i.parameters[0]]:Z(i.parameters[0])}function le(i){if(!i.parameters||i.parameters.length===0)return!1;let e=i.parameters[0];return d(e)?!1:!!e.isAggregateFn}function b(i){return i&&!N(i.alias)}function ue(i){return d(i.field)&&!Array.isArray(i.relationships)&&!Array.isArray(i.conditions)}function Ee(i){return!N(i.functionName||i.fn)}function he(i){return d(i.field)&&Array.isArray(i.relationships)}function ce(i){return!N(i.subquery)}function pe(i){return d(i.field)&&Array.isArray(i.conditions)}function g(i){return d(i.relationshipName)}function J(i){return!!i&&!!i.type&&i.type==="FieldSubquery"}function fe(i){return!!i&&!!i.operator&&!!i.right}function Ae(i){return!!i&&!!i.operator&&!!i.right}function P(i){return!!i&&!!i.operator&&!!i.right}function de(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)}function Ne(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)&&(i.literalType==="DATE_LITERAL"||Array.isArray(i.literalType)&&i.literalType[0]==="DATE_LITERAL")}function Re(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)&&!N(i.dateLiteralVariable)}function v(i){return i&&!N(i.fn)&&d(i.operator)&&!N(i.value)}function y(i){return i&&L(i.openParen)&&N(i.operator)&&N(i.field)&&N(i.fn)&&N(i.closeParen)}function Y(i){return i&&d(i.field)&&d(i.operator)&&!N(i.valueQuery)&&N(i.value)}function w(i){return i&&!N(i.field)}function Te(i){return i&&!N(i.fn)}function U(i){return i&&!N(i.field)}function Ce(i){return i&&!N(i.fn)}function ke(i){return["IN","NOT IN","INCLUDES","EXCLUDES"].includes(i)}function _e(i,e,s){if(N(e))return i;if(s&&e!=="APEX_BIND_VARIABLE"&&ke(s)&&!Array.isArray(i)&&(i=[i],e=Array.isArray(e)?e:[e]),Array.isArray(e)&&Array.isArray(i))return i.map((t,n)=>Ge(t,e?.[n]));switch(Array.isArray(e)&&(e=e[0]),e){case"STRING":return Array.isArray(i)?i.filter(Boolean).map(t=>z(t)):z(i);case"APEX_BIND_VARIABLE":return`:${i}`;default:return i}}function Ge(i,e){switch(e){case"STRING":return z(i);case"NULL":return"null";default:return i}}function z(i){if(d(i)&&i.startsWith("'")&&i.endsWith("'")&&i.length>=2)return i;let e=String(i??"");return`'${ve(e)}'`}var Me=/[nNrRtTbBfF"'\\_%]/,Pe=/^[0-9a-fA-F]{4}$/;function ve(i){let e="";for(let s=0;s<i.length;s++){let t=i[s];if(t==="\\"){let n=i[s+1];n!==void 0&&Me.test(n)?(e+=t+n,s++):n==="u"&&Pe.test(i.substr(s+2,4))?(e+=i.substr(s,6),s+=5):e+="\\\\"}else t==="'"?e+="\\'":e+=t}return e}function we(i){return Se(i)}function Se(i){if(typeof i=="string")return{type:"Field",field:i};if(Ee(i)){let e=[];return i.parameters&&(e=Array.isArray(i.parameters)?i.parameters:[i.parameters]),{type:"FieldFunctionExpression",functionName:i.functionName||i.fn,parameters:e,alias:i.alias}}else{if(he(i))return{type:"FieldRelationship",field:i.field,relationships:i.relationships,objectPrefix:i.objectPrefix};if(ce(i))return{type:"FieldSubquery",subquery:i.subquery};if(pe(i))return{type:"FieldTypeof",field:i.field,conditions:i.conditions};if(ue(i))return{type:"Field",field:i.field,objectPrefix:i.objectPrefix};throw new TypeError("The input object provided did not match any valid field types")}}function $e(i,e){if(!i)return[];i=J(i)?i.subquery:i;let s=i.fields;if(!s)return[];let t={};i.groupBy&&(t=(Array.isArray(i.groupBy)?i.groupBy:[i.groupBy]).reduce((l,h)=>(U(h)&&(l[h.field.toLocaleLowerCase()]=h.field),l),{}));let n=-1,a=(g(i)?i.relationshipName:i.sObject||"").toLowerCase(),o=(i.sObjectAlias||"").toLowerCase();return s.flatMap(l=>{switch(l.type){case"Field":return l.alias||l.field;case"FieldFunctionExpression":{let h=Z(l);if(h=h.map(u=>{if(u.includes(".")){let R=u.split("."),f=R[0].toLowerCase();return(f===o||f===a)&&(R=R.slice(1)),R.join(".")}return u}),l.alias&&(l.isAggregateFn||e))return l.alias;if(l.alias){let u=h[0];return u.includes(".")?(h=u.split(".").slice(0,-1),h.push(l.alias),h.join(".")):l.alias}return l.isAggregateFn||le(l)||e?(n++,`expr${n}`):h.length>0?h.join("."):l.functionName}case"FieldRelationship":{let h=l.relationships[0].toLowerCase();return b(l)?l.alias:l.rawValue&&t[l.rawValue.toLocaleLowerCase()]?l.field:h===o||h===a?l.relationships.concat([l.field]).slice(1).join("."):l.relationships.concat([l.field]).join(".")}case"FieldSubquery":return l.subquery.relationshipName;case"FieldTypeof":{let h=new Set,u=[];return l.conditions.forEach(R=>{R.fieldList.forEach(f=>{h.has(f)||(h.add(f),u.push(`${l.field}.${f}`))})}),u}default:break}}).filter(l=>d(l))}var $=class{constructor(e,s){this.currIndent=1;this.enabled=e,this.options={numIndent:s.numIndent??1,fieldMaxLineLength:s.fieldMaxLineLength??60,fieldSubqueryParensOnOwnLine:s.fieldSubqueryParensOnOwnLine??!0,whereClauseOperatorsIndented:!0,newLineAfterKeywords:s.newLineAfterKeywords??!1,logging:s.logging??!1},this.options.newLineAfterKeywords&&(this.options.fieldSubqueryParensOnOwnLine=!0)}log(e){this.options.logging&&console.log(e)}getIndent(e=0){return this.repeatChar((this.currIndent+e)*(this.options.numIndent||1)," ")}repeatChar(e,s){return new Array(e).fill(s).join("")}setSubquery(e){this.currIndent=e?this.currIndent+=1:this.currIndent-=1}stepCurrIndex(e){this.currIndent+=e}formatFields(e){function s(t){e.fields[t-1]&&(e.fields[t-1].suffix=e.fields[t-1].suffix.trim())}if(e.fields.forEach((t,n)=>{t.suffix=e.fields.length-1===n?"":", "}),this.enabled){let t=0,n=!1;e.fields.forEach((a,o)=>{a.isSubquery?(s(o),a.prefix=`
7
- ${this.getIndent()}`,a.suffix=e.fields.length-1===o?"":", ",t=0,n=!0):Array.isArray(a.typeOfClause)?(s(o),a.prefix=`
8
- ${this.getIndent()}`,n=!0):L(this.options.fieldMaxLineLength)&&(t+=a.text.length+a.suffix.length,(t>this.options.fieldMaxLineLength||n)&&(s(o),(!this.options.newLineAfterKeywords||o>0)&&(a.prefix+=`
9
- ${this.getIndent()}`),t=0,n=!1)),this.log(a)})}}formatTyeOfField(e,s){return this.enabled&&this.options.newLineAfterKeywords?s.map((t,n)=>n===0?t:n===s.length-1?`${this.getIndent()}${t}`:`${this.getIndent()} ${t}`).join(`
10
- `):e}formatTypeofFieldCondition(e){let s="",t=e.fieldList.join(", ");if(this.enabled&&this.options.newLineAfterKeywords){let n=this.getIndent();s=`${e.type}`,e.objectType?s+=`
6
+ "use strict";var B=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var De=Object.prototype.hasOwnProperty;var be=(i,e)=>{for(var r in e)B(i,r,{get:e[r],enumerable:!0})},Ue=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of xe(e))!De.call(i,n)&&n!==r&&B(i,n,{get:()=>e[n],enumerable:!(t=ye(e,n))||t.enumerable});return i};var ke=i=>Ue(B({},"__esModule",{value:!0}),i);var je={};be(je,{Compose:()=>W,composeQuery:()=>Fe,formatQuery:()=>Xe,getComments:()=>le,getComposedField:()=>Ve,getField:()=>me,getFlattenedFields:()=>Qe,hasAlias:()=>b,hasComments:()=>ue,isFieldSubquery:()=>ee,isGroupByField:()=>U,isGroupByFn:()=>Oe,isHavingClauseWithRightCondition:()=>Te,isNegationCondition:()=>y,isOrderByField:()=>w,isOrderByFn:()=>Le,isQueryValid:()=>ae,isString:()=>d,isSubquery:()=>g,isValueCondition:()=>_e,isValueFunctionCondition:()=>v,isValueQueryCondition:()=>Y,isValueWithDateLiteralCondition:()=>Se,isValueWithDateNLiteralCondition:()=>Ie,isWhereClauseWithRightCondition:()=>Ce,isWhereOrHavingClauseWithRightCondition:()=>P,parseQuery:()=>D,stripComments:()=>Ee});module.exports=ke(je);var C=(s=>(s[s.AND=0]="AND",s[s.AS=1]="AS",s[s.ASC=2]="ASC",s[s.DESC=3]="DESC",s[s.CUBE=4]="CUBE",s[s.ELSE=5]="ELSE",s[s.EXCLUDES=6]="EXCLUDES",s[s.FALSE=7]="FALSE",s[s.FIRST=8]="FIRST",s[s.FROM=9]="FROM",s[s.GROUP_BY=10]="GROUP_BY",s[s.HAVING=11]="HAVING",s[s.IN=12]="IN",s[s.INCLUDES=13]="INCLUDES",s[s.LAST=14]="LAST",s[s.LIKE=15]="LIKE",s[s.LIMIT=16]="LIMIT",s[s.NOT=17]="NOT",s[s.NULL=18]="NULL",s[s.NULLS=19]="NULLS",s[s.OR=20]="OR",s[s.ORDER_BY=21]="ORDER_BY",s[s.ROLLUP=22]="ROLLUP",s[s.SELECT=23]="SELECT",s[s.TRUE=24]="TRUE",s[s.USING=25]="USING",s[s.WHERE=26]="WHERE",s[s.WITH=27]="WITH",s[s.FOR=28]="FOR",s[s.UPDATE=29]="UPDATE",s[s.ABOVE=30]="ABOVE",s[s.ABOVE_OR_BELOW=31]="ABOVE_OR_BELOW",s[s.APEX_NEW=32]="APEX_NEW",s[s.AT=33]="AT",s[s.BELOW=34]="BELOW",s[s.DATA_CATEGORY=35]="DATA_CATEGORY",s[s.END=36]="END",s[s.OFFSET=37]="OFFSET",s[s.REFERENCE=38]="REFERENCE",s[s.SCOPE=39]="SCOPE",s[s.TRACKING=40]="TRACKING",s[s.THEN=41]="THEN",s[s.TYPEOF=42]="TYPEOF",s[s.VIEW=43]="VIEW",s[s.VIEWSTAT=44]="VIEWSTAT",s[s.WHEN=45]="WHEN",s[s.SECURITY_ENFORCED=46]="SECURITY_ENFORCED",s[s.SYSTEM_MODE=47]="SYSTEM_MODE",s[s.USER_MODE=48]="USER_MODE",s[s.CALENDAR_MONTH=49]="CALENDAR_MONTH",s[s.CALENDAR_QUARTER=50]="CALENDAR_QUARTER",s[s.CALENDAR_YEAR=51]="CALENDAR_YEAR",s[s.DAY_IN_MONTH=52]="DAY_IN_MONTH",s[s.DAY_IN_WEEK=53]="DAY_IN_WEEK",s[s.DAY_IN_YEAR=54]="DAY_IN_YEAR",s[s.DAY_ONLY=55]="DAY_ONLY",s[s.FISCAL_MONTH=56]="FISCAL_MONTH",s[s.FISCAL_QUARTER=57]="FISCAL_QUARTER",s[s.FISCAL_YEAR=58]="FISCAL_YEAR",s[s.HOUR_IN_DAY=59]="HOUR_IN_DAY",s[s.WEEK_IN_MONTH=60]="WEEK_IN_MONTH",s[s.WEEK_IN_YEAR=61]="WEEK_IN_YEAR",s[s.AVG=62]="AVG",s[s.COUNT=63]="COUNT",s[s.COUNT_DISTINCT=64]="COUNT_DISTINCT",s[s.MIN=65]="MIN",s[s.MAX=66]="MAX",s[s.SUM=67]="SUM",s[s.DISTANCE=68]="DISTANCE",s[s.GEOLOCATION=69]="GEOLOCATION",s[s.FIELDS=70]="FIELDS",s[s.FORMAT=71]="FORMAT",s[s.TOLABEL=72]="TOLABEL",s[s.CONVERT_TIMEZONE=73]="CONVERT_TIMEZONE",s[s.CONVERT_CURRENCY=74]="CONVERT_CURRENCY",s[s.GROUPING=75]="GROUPING",s[s.ALL=76]="ALL",s[s.CUSTOM=77]="CUSTOM",s[s.STANDARD=78]="STANDARD",s[s.YESTERDAY=79]="YESTERDAY",s[s.TODAY=80]="TODAY",s[s.TOMORROW=81]="TOMORROW",s[s.LAST_WEEK=82]="LAST_WEEK",s[s.THIS_WEEK=83]="THIS_WEEK",s[s.NEXT_WEEK=84]="NEXT_WEEK",s[s.LAST_MONTH=85]="LAST_MONTH",s[s.THIS_MONTH=86]="THIS_MONTH",s[s.NEXT_MONTH=87]="NEXT_MONTH",s[s.LAST_90_DAYS=88]="LAST_90_DAYS",s[s.NEXT_90_DAYS=89]="NEXT_90_DAYS",s[s.THIS_QUARTER=90]="THIS_QUARTER",s[s.LAST_QUARTER=91]="LAST_QUARTER",s[s.NEXT_QUARTER=92]="NEXT_QUARTER",s[s.THIS_YEAR=93]="THIS_YEAR",s[s.LAST_YEAR=94]="LAST_YEAR",s[s.NEXT_YEAR=95]="NEXT_YEAR",s[s.THIS_FISCAL_QUARTER=96]="THIS_FISCAL_QUARTER",s[s.LAST_FISCAL_QUARTER=97]="LAST_FISCAL_QUARTER",s[s.NEXT_FISCAL_QUARTER=98]="NEXT_FISCAL_QUARTER",s[s.THIS_FISCAL_YEAR=99]="THIS_FISCAL_YEAR",s[s.LAST_FISCAL_YEAR=100]="LAST_FISCAL_YEAR",s[s.NEXT_FISCAL_YEAR=101]="NEXT_FISCAL_YEAR",s[s.NEXT_N_DAYS=102]="NEXT_N_DAYS",s[s.LAST_N_DAYS=103]="LAST_N_DAYS",s[s.N_DAYS_AGO=104]="N_DAYS_AGO",s[s.NEXT_N_WEEKS=105]="NEXT_N_WEEKS",s[s.LAST_N_WEEKS=106]="LAST_N_WEEKS",s[s.N_WEEKS_AGO=107]="N_WEEKS_AGO",s[s.NEXT_N_MONTHS=108]="NEXT_N_MONTHS",s[s.LAST_N_MONTHS=109]="LAST_N_MONTHS",s[s.N_MONTHS_AGO=110]="N_MONTHS_AGO",s[s.NEXT_N_QUARTERS=111]="NEXT_N_QUARTERS",s[s.LAST_N_QUARTERS=112]="LAST_N_QUARTERS",s[s.N_QUARTERS_AGO=113]="N_QUARTERS_AGO",s[s.NEXT_N_YEARS=114]="NEXT_N_YEARS",s[s.LAST_N_YEARS=115]="LAST_N_YEARS",s[s.N_YEARS_AGO=116]="N_YEARS_AGO",s[s.NEXT_N_FISCAL_QUARTERS=117]="NEXT_N_FISCAL_QUARTERS",s[s.LAST_N_FISCAL_QUARTERS=118]="LAST_N_FISCAL_QUARTERS",s[s.N_FISCAL_QUARTERS_AGO=119]="N_FISCAL_QUARTERS_AGO",s[s.NEXT_N_FISCAL_YEARS=120]="NEXT_N_FISCAL_YEARS",s[s.LAST_N_FISCAL_YEARS=121]="LAST_N_FISCAL_YEARS",s[s.N_FISCAL_YEARS_AGO=122]="N_FISCAL_YEARS_AGO",s[s.DELEGATED=123]="DELEGATED",s[s.EVERYTHING=124]="EVERYTHING",s[s.MINE_AND_MY_GROUPS=125]="MINE_AND_MY_GROUPS",s[s.MINE=126]="MINE",s[s.MY_TERRITORY=127]="MY_TERRITORY",s[s.MY_TEAM_TERRITORY=128]="MY_TEAM_TERRITORY",s[s.TEAM=129]="TEAM",s[s.ALL_PRIVATE=130]="ALL_PRIVATE",s[s.MRU=131]="MRU",s[s.EQUAL=132]="EQUAL",s[s.NOT_EQUAL=133]="NOT_EQUAL",s[s.LESS_THAN=134]="LESS_THAN",s[s.LESS_THAN_OR_EQUAL=135]="LESS_THAN_OR_EQUAL",s[s.GREATER_THAN=136]="GREATER_THAN",s[s.GREATER_THAN_OR_EQUAL=137]="GREATER_THAN_OR_EQUAL",s[s.L_PAREN=138]="L_PAREN",s[s.R_PAREN=139]="R_PAREN",s[s.L_SQUARE_BRACKET=140]="L_SQUARE_BRACKET",s[s.R_SQUARE_BRACKET=141]="R_SQUARE_BRACKET",s[s.DOT=142]="DOT",s[s.COMMA=143]="COMMA",s[s.COLON=144]="COLON",s[s.SEMICOLON=145]="SEMICOLON",s[s.ASTERISK=146]="ASTERISK",s[s.PLUS=147]="PLUS",s[s.MINUS=148]="MINUS",s[s.DATETIME=149]="DATETIME",s[s.DATE_TOKEN=150]="DATE_TOKEN",s[s.CURRENCY_PREFIXED_DECIMAL=151]="CURRENCY_PREFIXED_DECIMAL",s[s.CURRENCY_PREFIXED_INTEGER=152]="CURRENCY_PREFIXED_INTEGER",s[s.SIGNED_DECIMAL=153]="SIGNED_DECIMAL",s[s.UNSIGNED_DECIMAL=154]="UNSIGNED_DECIMAL",s[s.SIGNED_INTEGER=155]="SIGNED_INTEGER",s[s.UNSIGNED_INTEGER=156]="UNSIGNED_INTEGER",s[s.STRING_LITERAL=157]="STRING_LITERAL",s[s.GEOLOCATION_UNIT=158]="GEOLOCATION_UNIT",s[s.IDENTIFIER=159]="IDENTIFIER",s[s.EOF=160]="EOF",s))(C||{});function m(i){return i>=49&&i<=61}function F(i){return i>=62&&i<=67}function Q(i){return i>=68&&i<=69}function X(i){return i===70}function x(i){return i>=71&&i<=75}function ie(i){return i>=76&&i<=78}function G(i){return i>=79&&i<=101}function M(i){return i>=102&&i<=122}function re(i){return i>=123&&i<=131}function I(i){return i===159||i>=30&&i<=48||i>=49&&i<=61||i>=62&&i<=67||i>=68&&i<=69||i===70||i>=71&&i<=75||i>=76&&i<=78||i>=79&&i<=101||i>=102&&i<=122||i>=123&&i<=131||i===158||i===152}function j(i){return i===153||i===154||i===155||i===156}function se(i){return i>=132&&i<=137}var Ge=new Map([["AND",0],["AS",1],["ASC",2],["DESC",3],["CUBE",4],["ELSE",5],["EXCLUDES",6],["FALSE",7],["FIRST",8],["FROM",9],["HAVING",11],["IN",12],["INCLUDES",13],["LAST",14],["LIKE",15],["LIMIT",16],["NOT",17],["NULL",18],["NULLS",19],["OR",20],["ROLLUP",22],["SELECT",23],["TRUE",24],["USING",25],["WHERE",26],["WITH",27],["FOR",28],["UPDATE",29],["ABOVE_OR_BELOW",31],["ABOVE",30],["NEW",32],["AT",33],["BELOW",34],["END",36],["OFFSET",37],["REFERENCE",38],["SCOPE",39],["TRACKING",40],["THEN",41],["TYPEOF",42],["VIEW",43],["VIEWSTAT",44],["WHEN",45],["SECURITY_ENFORCED",46],["SYSTEM_MODE",47],["USER_MODE",48],["CALENDAR_MONTH",49],["CALENDAR_QUARTER",50],["CALENDAR_YEAR",51],["DAY_IN_MONTH",52],["DAY_IN_WEEK",53],["DAY_IN_YEAR",54],["DAY_ONLY",55],["FISCAL_MONTH",56],["FISCAL_QUARTER",57],["FISCAL_YEAR",58],["HOUR_IN_DAY",59],["WEEK_IN_MONTH",60],["WEEK_IN_YEAR",61],["AVG",62],["COUNT_DISTINCT",64],["COUNT",63],["MIN",65],["MAX",66],["SUM",67],["DISTANCE",68],["GEOLOCATION",69],["FIELDS",70],["FORMAT",71],["TOLABEL",72],["CONVERTTIMEZONE",73],["CONVERTCURRENCY",74],["GROUPING",75],["ALL",76],["CUSTOM",77],["STANDARD",78],["YESTERDAY",79],["TODAY",80],["TOMORROW",81],["LAST_WEEK",82],["THIS_WEEK",83],["NEXT_WEEK",84],["LAST_MONTH",85],["THIS_MONTH",86],["NEXT_MONTH",87],["LAST_90_DAYS",88],["NEXT_90_DAYS",89],["THIS_QUARTER",90],["LAST_QUARTER",91],["NEXT_QUARTER",92],["THIS_YEAR",93],["LAST_YEAR",94],["NEXT_YEAR",95],["THIS_FISCAL_QUARTER",96],["LAST_FISCAL_QUARTER",97],["NEXT_FISCAL_QUARTER",98],["THIS_FISCAL_YEAR",99],["LAST_FISCAL_YEAR",100],["NEXT_FISCAL_YEAR",101],["NEXT_N_DAYS",102],["LAST_N_DAYS",103],["N_DAYS_AGO",104],["NEXT_N_WEEKS",105],["LAST_N_WEEKS",106],["N_WEEKS_AGO",107],["NEXT_N_MONTHS",108],["LAST_N_MONTHS",109],["N_MONTHS_AGO",110],["NEXT_N_QUARTERS",111],["LAST_N_QUARTERS",112],["N_QUARTERS_AGO",113],["NEXT_N_YEARS",114],["LAST_N_YEARS",115],["N_YEARS_AGO",116],["NEXT_N_FISCAL_QUARTERS",117],["LAST_N_FISCAL_QUARTERS",118],["N_FISCAL_QUARTERS_AGO",119],["NEXT_N_FISCAL_YEARS",120],["LAST_N_FISCAL_YEARS",121],["N_FISCAL_YEARS_AGO",122],["DELEGATED",123],["EVERYTHING",124],["MINEANDMYGROUPS",125],["MINE",126],["MY_TERRITORY",127],["MY_TEAM_TERRITORY",128],["TEAM",129],["ALLPRIVATE",130],["MRU",131]]),p=[];(function(){for(let e of Object.keys(C)){let r=C[e];typeof r=="number"&&(p[r]=e)}p[72]="toLabel",p[73]="convertTimezone",p[74]="convertCurrency",p[157]="StringIdentifier",p[150]="DATE",p[32]="new",p[125]="MineAndMyGroups",p[127]="MyTerritory",p[128]="MyTeamTerritory",p[130]="AllPrivate",p[123]="Delegated",p[124]="Everything",p[126]="Mine",p[129]="Team",p[131]="Mru",p[159]="Identifier",p[132]="EQUAL",p[156]="UNSIGNED_INTEGER",p[155]="SIGNED_INTEGER",p[154]="UNSIGNED_DECIMAL",p[153]="SIGNED_DECIMAL",p[151]="CURRENCY_PREFIXED_DECIMAL",p[152]="CURRENCY_PREFIXED_INTEGER"})();function A(i){return p[i]||C[i]}function q(i){return i>=65&&i<=90||i>=97&&i<=122}function c(i){return i>=48&&i<=57}function V(i){return q(i)||c(i)||i===95}function k(i){return i===32||i===9||i===10||i===13||i===12}function ne(i){let e=[],r=i.length,t=0;for(;t<r;){let n=i.charCodeAt(t);if(k(n)){for(t++;t<r&&k(i.charCodeAt(t));)t++;continue}if(n===47){let a=t+1<r?i.charCodeAt(t+1):0;if(a===47){for(t+=2;t<r;){let o=i.charCodeAt(t);if(o===10||o===13)break;t++}continue}if(a===42){let o=t;t+=2;let u=!1;for(;t<r;){if(i.charCodeAt(t)===42&&t+1<r&&i.charCodeAt(t+1)===47){t+=2,u=!0;break}t++}if(!u)throw new Error(`Unterminated comment at position ${o}`);continue}}if(n===39){let a=t;for(t++;t<r;){let h=i.charCodeAt(t);if(h===92){t+=2;continue}if(h===39){t++;break}t++}let o=i.substring(a,t),l=o.substring(1,o.length-1).toUpperCase();l==="MI"||l==="KM"?e.push({kind:158,text:o,start:a}):e.push({kind:157,text:o,start:a});continue}if(c(n)){if(t+9<r&&i.charCodeAt(t+4)===45&&i.charCodeAt(t+7)===45){let o=!0;for(let u of[0,1,2,3,5,6,8,9])if(!c(i.charCodeAt(t+u))){o=!1;break}if(o)if(t+10<r&&(i.charCodeAt(t+10)===84||i.charCodeAt(t+10)===116)){let u=t;for(t+=11;t<r;){let l=i.charCodeAt(t);if(c(l)||l===58)t++;else break}if(t<r&&i.charCodeAt(t)===46)for(t++;t<r&&c(i.charCodeAt(t));)t++;if(t<r){let l=i.charCodeAt(t);if(l===90||l===122)t++;else if(l===46){for(t++;t<r&&c(i.charCodeAt(t));)t++;t<r&&(i.charCodeAt(t)===90||i.charCodeAt(t)===122)&&t++}else if(l===43||l===45)for(t++;t<r;){let h=i.charCodeAt(t);if(c(h)||h===58)t++;else break}}e.push({kind:149,text:i.substring(u,t),start:u});continue}else{let u=t;t+=10,e.push({kind:150,text:i.substring(u,t),start:u});continue}}let a=t;for(;t<r&&c(i.charCodeAt(t));)t++;if(t<r&&i.charCodeAt(t)===46&&t+1<r&&c(i.charCodeAt(t+1))){for(t++;t<r&&c(i.charCodeAt(t));)t++;e.push({kind:154,text:i.substring(a,t),start:a});continue}e.push({kind:156,text:i.substring(a,t),start:a});continue}if(n===33){if(t+1<r&&i.charCodeAt(t+1)===61){e.push({kind:133,text:"!=",start:t}),t+=2;continue}throw new Error(`Unexpected character '!' at position ${t}`)}if(n===60){if(t+1<r){let a=i.charCodeAt(t+1);if(a===61){e.push({kind:135,text:"<=",start:t}),t+=2;continue}if(a===62){e.push({kind:133,text:"<>",start:t}),t+=2;continue}}e.push({kind:134,text:"<",start:t}),t++;continue}if(n===62){if(t+1<r&&i.charCodeAt(t+1)===61){e.push({kind:137,text:">=",start:t}),t+=2;continue}e.push({kind:136,text:">",start:t}),t++;continue}if(n===61){e.push({kind:132,text:"=",start:t}),t++;continue}if(n===40){e.push({kind:138,text:"(",start:t}),t++;continue}if(n===41){e.push({kind:139,text:")",start:t}),t++;continue}if(n===91){e.push({kind:140,text:"[",start:t}),t++;continue}if(n===93){e.push({kind:141,text:"]",start:t}),t++;continue}if(n===44){e.push({kind:143,text:",",start:t}),t++;continue}if(n===58){e.push({kind:144,text:":",start:t}),t++;continue}if(n===59){e.push({kind:145,text:";",start:t}),t++;continue}if(n===42){e.push({kind:146,text:"*",start:t}),t++;continue}if(n===43||n===45){if(t+1<r){let a=i.charCodeAt(t+1);if(c(a)){let o=t;for(t++;t<r&&c(i.charCodeAt(t));)t++;if(t<r&&i.charCodeAt(t)===46&&t+1<r&&c(i.charCodeAt(t+1))){for(t++;t<r&&c(i.charCodeAt(t));)t++;e.push({kind:153,text:i.substring(o,t),start:o});continue}e.push({kind:155,text:i.substring(o,t),start:o});continue}if(a===46&&t+2<r&&c(i.charCodeAt(t+2))){let o=t;for(t+=2;t<r&&c(i.charCodeAt(t));)t++;e.push({kind:153,text:i.substring(o,t),start:o});continue}}e.push({kind:n===43?147:148,text:i[t],start:t}),t++;continue}if(n===46){if(t+1<r&&c(i.charCodeAt(t+1))){let a=t;for(t++;t<r&&c(i.charCodeAt(t));)t++;e.push({kind:154,text:i.substring(a,t),start:a});continue}e.push({kind:142,text:".",start:t}),t++;continue}if(q(n)){let a=t;for(t++;t<r;){let h=i.charCodeAt(t);if(V(h)||h===46)t++;else break}let o=i.substring(a,t);if(o.includes(".."))throw new Error(`Invalid identifier with consecutive dots at position ${a}: "${o}"`);let u=o.toUpperCase();if(u==="ORDER"&&!o.includes(".")){let h=H(i,t,"BY");if(h!==-1){let E=i.substring(a,h);e.push({kind:21,text:E,start:a}),t=h;continue}}if(u==="GROUP"&&!o.includes(".")){let h=H(i,t,"BY");if(h!==-1){let E=i.substring(a,h);e.push({kind:10,text:E,start:a}),t=h;continue}}if(u==="DATA"&&!o.includes(".")){let h=H(i,t,"CATEGORY");if(h!==-1){let E=i.substring(a,h);e.push({kind:35,text:E,start:a}),t=h;continue}}if(o.length>=4){let h=o.substring(0,3);if(te(h)){let E=o.substring(3);if(Me(E)){E.includes(".")?e.push({kind:151,text:o,start:a}):e.push({kind:152,text:o,start:a});continue}}}if(o.length===3&&te(o)){let h=t,E=t,R=!1;if(E<r&&i.charCodeAt(E)===45&&(R=!0,E++),R&&E<r&&c(i.charCodeAt(E))){for(;E<r&&c(i.charCodeAt(E));)E++;if(E<r&&i.charCodeAt(E)===46&&E+1<r&&c(i.charCodeAt(E+1))){for(E++;E<r&&c(i.charCodeAt(E));)E++;let f=i.substring(a,E);e.push({kind:151,text:f,start:a}),t=E;continue}if(E>=r||!V(i.charCodeAt(E))&&i.charCodeAt(E)!==46){let f=i.substring(a,E);e.push({kind:152,text:f,start:a}),t=E;continue}t=h}}if(o.includes(".")){e.push({kind:159,text:o,start:a});continue}let l=Ge.get(u);if(l!==void 0){e.push({kind:l,text:o,start:a});continue}e.push({kind:159,text:o,start:a});continue}throw new Error(`Unexpected character '${i[t]}' (code ${n}) at position ${t}`)}return e.push({kind:160,text:"",start:t}),e}function H(i,e,r){let t=i.length,n=e;if(n>=t||!k(i.charCodeAt(n)))return-1;for(;n<t&&k(i.charCodeAt(n));)n++;let a=r.length;if(n+a>t)return-1;for(let u=0;u<a;u++){let l=i.charCodeAt(n+u),h=r.charCodeAt(u);if((l>=97&&l<=122?l-32:l)!==h)return-1}let o=n+a;if(o<t){let u=i.charCodeAt(o);if(V(u)||u===46)return-1}return o}function te(i){for(let e=0;e<i.length;e++)if(!q(i.charCodeAt(e)))return!1;return!0}function Me(i){if(i.length===0)return!1;let e=0;if(i.charCodeAt(e)===45&&e++,e>=i.length||!c(i.charCodeAt(e)))return!1;for(;e<i.length&&c(i.charCodeAt(e));)e++;if(e<i.length&&i.charCodeAt(e)===46){if(e++,e>=i.length||!c(i.charCodeAt(e)))return!1;for(;e<i.length&&c(i.charCodeAt(e));)e++}return e===i.length}var Pe=new Set([23,9,26,21,10,11,16,27,28,29,25,19,2,3,0,20,17,45,41,5,36,42,143,139,160]),K=class i{constructor(e,r){this.pos=0;this.tokens=e,this.config=r}getPos(){return this.pos}peek(){return this.tokens[this.pos]}peekAt(e){let r=this.pos+e;return r>=this.tokens.length?this.tokens[this.tokens.length-1]:this.tokens[r]}advance(){let e=this.tokens[this.pos];return e.kind!==160&&this.pos++,e}expect(e){let r=this.peek();if(r.kind!==e)throw this.error(`Expected ${C[e]} but found ${C[r.kind]} ("${r.text}") at position ${r.start}`);return this.advance()}match(e){return this.peek().kind===e?(this.advance(),!0):!1}check(e){return this.peek().kind===e}isAtEnd(){return this.peek().kind===160}error(e){return this.config.logErrors&&console.log(e),new Error(e)}static{this.CLAUSE_BOUNDARY_KINDS=new Set([26,21,10,11,16,37,27,28,29,25,160])}isAtClauseBoundary(){let e=this.peek().kind;return i.CLAUSE_BOUNDARY_KINDS.has(e)||e===139}synchronize(){for(;!this.isAtEnd();){if(this.isAtClauseBoundary())return;this.advance()}}consumeIdentifier(){let e=this.peek();if(I(e.kind))return this.advance();throw this.error(`Expected identifier but found ${C[e.kind]} ("${e.text}") at position ${e.start}`)}checkIdentifier(){return I(this.peek().kind)}isFunctionCall(){let e=this.peek(),r=this.peekAt(1);return(m(e.kind)||F(e.kind)||Q(e.kind)||X(e.kind)||x(e.kind))&&r.kind===138}canBeAlias(){let e=this.peek();return!(!I(e.kind)||Pe.has(e.kind)||e.kind===37&&this.peekAt(1).kind===156)}getLiteralType(e){let r=A(e);return r==="UNSIGNED_INTEGER"||r==="SIGNED_INTEGER"?"INTEGER":r==="UNSIGNED_DECIMAL"||r==="SIGNED_DECIMAL"?"DECIMAL":r==="CURRENCY_PREFIXED_DECIMAL"?"DECIMAL_WITH_CURRENCY_PREFIX":r==="CURRENCY_PREFIXED_INTEGER"?"INTEGER_WITH_CURRENCY_PREFIX":r==="DATETIME"?"DATETIME":r==="DATE"?"DATE":r==="NULL"?"NULL":r==="StringIdentifier"||r==="Identifier"?"STRING":r==="TRUE"||r==="FALSE"?"BOOLEAN":G(e)?"DATE_LITERAL":M(e)?"DATE_N_LITERAL":"STRING"}parseSelectStatement(e=!1){let r=this.parseSelectClause(),t=this.parseFromClause(),n;e?(n={fields:r,relationshipName:t.sObject},t.sObjectPrefix&&(n.sObjectPrefix=t.sObjectPrefix)):n={fields:r,sObject:t.sObject},t.alias&&(n.sObjectAlias=t.alias),this.applySObjectAlias(n);let a=this.parseClauseStatements();return Object.assign(n,a),n}parseSelectStatementPartial(){let e,r;this.check(23)&&(e=this.parseSelectClause()),this.check(9)&&(r=this.parseFromClause());let t={};e&&(t.fields=e),r&&(t.sObject=r.sObject,r.alias&&(t.sObjectAlias=r.alias)),t.fields&&this.applySObjectAlias(t);let n=this.parseClauseStatements();return Object.assign(t,n),t}applySObjectAlias(e){if(!e.sObjectAlias||!Array.isArray(e.fields))return;let r=e.sObjectAlias;e.fields.forEach(t=>{t.relationships&&t.relationships[0]===r&&(t.relationships=t.relationships.slice(1),t.objectPrefix=r,t.relationships.length===0&&(delete t.relationships,t.type="Field"))})}parseSelectClause(){this.expect(23);let e=[];for(e.push(this.parseSelectField());this.match(143);)e.push(this.parseSelectField());return e}parseSelectField(){let e=this.peek(),r=this.peekAt(1);return e.kind===138&&r.kind===23?this.parseSelectClauseSubqueryIdentifier():e.kind===42?this.parseSelectClauseTypeOf():this.isFunctionCall()?this.parseSelectClauseFunctionIdentifier():this.parseSelectClauseIdentifier()}parseSelectClauseFunctionIdentifier(){let e=this.parseAnyFunction(!0);return this.canBeAlias()&&(e.alias=this.consumeIdentifier().text),e}parseSelectClauseSubqueryIdentifier(){this.expect(138);let e=this.parseSelectStatement(!0);return this.expect(139),{type:"FieldSubquery",subquery:e}}parseSelectClauseTypeOf(){this.expect(42);let e=this.consumeIdentifier().text,r=[];for(;this.check(45);){this.advance();let t=this.consumeIdentifier().text;this.expect(41);let n=[];for(n.push(this.consumeIdentifier().text);this.match(143);)n.push(this.consumeIdentifier().text);r.push({type:"WHEN",objectType:t,fieldList:n})}if(this.check(5)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);r.push({type:"ELSE",fieldList:t})}return this.expect(36),{type:"FieldTypeof",field:e,conditions:r}}parseSelectClauseIdentifier(){let r=this.consumeIdentifier().text,t;if(!r.includes("."))t={type:"Field",field:r};else{let n=r.split(".");t={type:"FieldRelationship",field:n[n.length-1],relationships:n.slice(0,n.length-1),rawValue:r}}return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseFromClause(){this.expect(9);let r=this.consumeIdentifier().text,t;if(r.includes(".")){let n=r.split(".");t={sObjectPrefix:n.slice(0,n.length-1),sObject:n[n.length-1]}}else t={sObject:r};return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseClauseStatements(){let e={},r=(t,n)=>{if(this.config.ignoreParseErrors)try{t(),this.isAtClauseBoundary()||(n&&n(),this.synchronize())}catch(a){this.config.logErrors&&console.log(a),n&&n(),this.synchronize()}else t()};for(this.check(25)&&r(()=>{e.usingScope=this.parseUsingScope()}),this.check(26)&&r(()=>{e.where=this.parseWhereClause()},()=>{delete e.where});this.check(27);)r(()=>{let t=this.parseWithClause();t.withSecurityEnforced&&(e.withSecurityEnforced=!0),t.withAccessLevel&&(e.withAccessLevel=t.withAccessLevel),t.withDataCategory&&(e.withDataCategory=t.withDataCategory)});return this.check(10)&&(r(()=>{e.groupBy=this.parseGroupByClause()}),this.check(11)&&r(()=>{e.having=this.parseHavingClause()})),this.check(21)&&r(()=>{e.orderBy=this.parseOrderByClause()}),this.check(16)&&r(()=>{this.advance(),e.limit=Number(this.expect(156).text)}),this.check(37)&&r(()=>{this.advance(),e.offset=Number(this.expect(156).text)}),this.check(28)&&r(()=>{this.advance();let t=this.peek();if(t.kind===43||t.kind===38||t.kind===29)e.for=A(this.advance().kind);else throw this.error(`Expected VIEW, REFERENCE, or UPDATE after FOR at position ${t.start}`)}),this.check(29)&&r(()=>{this.advance();let t=this.peek();if(t.kind===40||t.kind===44)e.update=A(this.advance().kind);else throw this.error(`Expected TRACKING or VIEWSTAT after UPDATE at position ${t.start}`)}),e}parseUsingScope(){this.expect(25),this.expect(39);let e=this.peek();if(re(e.kind))return this.advance().text;if(I(e.kind))return this.advance().text;throw this.error(`Expected scope enumeration value at position ${e.start}`)}parseWhereClause(){return this.expect(26),this.parseConditionExpressions(!0,!0)}parseConditionExpressions(e,r){let t,n,a={left:0,right:0};for(;;){let o;if(t)if(this.check(0))o="AND",this.advance();else if(this.check(20))o="OR",this.advance();else break;let u={},l=u,h=null;for(;this.hasNegationPrefix();){let f=0;for(;this.check(138)&&this.isNegationAhead();)this.advance(),f++,a.left++;if(this.check(17)){this.advance();let _={left:f>0?{openParen:f}:null,operator:"NOT",right:{left:{}}};h?h.right=_:u=_,h=_,l=_.right}else break}l.left=this.parseExpression(e,r,a),t?o&&(n.operator=o,n.right=u):(t=u,n=u);let E=u;for(;E.right&&E.right.left!==void 0;){let f=E.right;if(f.right&&f.right.left!==void 0)E=f;else{E=f;break}}if(n=E,this.isAtEnd())break;let R=this.peek().kind;if(R!==0&&R!==20)break}if(a.left!==a.right)throw this.error(`Mismatched parentheses in WHERE/HAVING clause: ${a.left} open vs ${a.right} close`);return t}hasNegationPrefix(){let e=0;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}isNegationAhead(){let e=1;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}parseExpression(e,r,t){let n=0;for(;this.check(138)&&!this.isSubqueryStart()&&!this.isArrayExpressionStart();)this.advance(),n++,t&&t.left++;let a,o=!1;e&&F(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseAggregateFunction(!1),o=!0):r&&Q(this.peek().kind)&&this.peek().kind===68&&this.peekAt(1).kind===138?(a=this.parseLocationFunction(!1),o=!0):m(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseDateFunction(!1),o=!0):x(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseOtherFunction(!1),o=!0):a=this.consumeIdentifier().text;let u=this.parseOperator(),l=u.operator,h=u.isSet,E,R,f;if(h)if(this.check(138)&&this.peekAt(1).kind===23)this.expect(138),E=this.parseSelectStatement(!1),this.expect(139),R="SUBQUERY";else if(this.config.allowApexBindVariables&&this.check(144))E=this.parseApexBindVariable().value,R="APEX_BIND_VARIABLE";else{let S=this.parseArrayExpression();E=S.values,R=S.literalType,f=S.dateLiteralVariable}else{let S=this.parseAtomicValue();E=S.value,R=S.literalType,f=S.dateLiteralVariable}let _=0;for(;this.check(139)&&(!t||t.left>t.right);)this.advance(),_++,t&&t.right++;let T={};return o?T.fn=a:T.field=a,T.operator=l,R==="SUBQUERY"?T.valueQuery=E:T.value=E,T.literalType=R,f!==void 0&&(T.dateLiteralVariable=f),n>0&&(T.openParen=n),_>0&&(T.closeParen=_),T}isSubqueryStart(){return this.check(138)&&this.peekAt(1).kind===23}isArrayExpressionStart(){return!1}parseOperator(){let e=this.peek();if(se(e.kind))return{operator:this.advance().text,isSet:!1};if(e.kind===15)return this.advance(),{operator:"LIKE",isSet:!1};if(e.kind===12)return this.advance(),{operator:"IN",isSet:!0};if(e.kind===17&&this.peekAt(1).kind===12)return this.advance(),this.advance(),{operator:"NOT IN",isSet:!0};if(e.kind===13)return this.advance(),{operator:"INCLUDES",isSet:!0};if(e.kind===6)return this.advance(),{operator:"EXCLUDES",isSet:!0};throw this.error(`Expected operator but found ${C[e.kind]} ("${e.text}") at position ${e.start}`)}parseAtomicValue(){let e=this.peek();if(this.config.allowApexBindVariables&&e.kind===144)return{value:this.parseApexBindVariable().value,literalType:"APEX_BIND_VARIABLE"};if(e.kind===157)return{value:this.advance().text,literalType:"STRING"};if(e.kind===158)return{value:this.advance().text,literalType:"STRING"};if(e.kind===156)return{value:this.advance().text,literalType:"INTEGER"};if(e.kind===155)return{value:this.advance().text,literalType:"INTEGER"};if(e.kind===154)return{value:this.advance().text,literalType:"DECIMAL"};if(e.kind===153)return{value:this.advance().text,literalType:"DECIMAL"};if(e.kind===151)return{value:this.advance().text,literalType:"DECIMAL_WITH_CURRENCY_PREFIX"};if(e.kind===152)return{value:this.advance().text,literalType:"INTEGER_WITH_CURRENCY_PREFIX"};if(e.kind===149)return{value:this.advance().text,literalType:"DATETIME"};if(e.kind===150)return{value:this.advance().text,literalType:"DATE"};if(e.kind===18)return this.advance(),{value:"NULL",literalType:"NULL"};if(e.kind===24||e.kind===7)return{value:A(this.advance().kind),literalType:"BOOLEAN"};if(G(e.kind))return{value:this.advance().text,literalType:"DATE_LITERAL"};if(M(e.kind)){let r=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${r.text}:${n}`,literalType:"DATE_N_LITERAL",dateLiteralVariable:n}}throw this.error(`Expected value but found ${C[e.kind]} ("${e.text}") at position ${e.start}`)}parseArrayExpression(){this.expect(138);let e=[];for(e.push(this.parseArrayItem());this.match(143);)e.push(this.parseArrayItem());this.expect(139);let r=e.map(l=>l.value),t=e.map(l=>l.type),n=e.map(l=>l.variable!==void 0?l.variable:null),a=n.some(l=>l!==null),o;new Set(t).size===1?o=this.getLiteralType(this.tokenKindFromTypeName(t[0])):o=t.map(l=>this.getLiteralType(this.tokenKindFromTypeName(l)));let u={values:r,literalType:o};return a&&(u.dateLiteralVariable=n),u}tokenKindFromTypeName(e){for(let r=0;r<=160;r++)if(A(r)===e)return r;return 159}parseArrayItem(){let e=this.peek();if(e.kind===157)return{value:this.advance().text,type:A(157)};if(e.kind===158)return{value:this.advance().text,type:A(158)};if(e.kind===151)return{value:this.advance().text,type:A(151)};if(e.kind===152)return{value:this.advance().text,type:A(152)};if(j(e.kind)){let r=this.advance();return{value:r.text,type:A(r.kind)}}if(e.kind===149)return{value:this.advance().text,type:A(149)};if(e.kind===150)return{value:this.advance().text,type:A(150)};if(e.kind===18)return this.advance(),{value:"NULL",type:"NULL"};if(e.kind===24)return{value:this.advance().text,type:"TRUE"};if(e.kind===7)return{value:this.advance().text,type:"FALSE"};if(G(e.kind))return{value:this.advance().text,type:A(e.kind)};if(M(e.kind)){let r=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${r.text}:${n}`,type:A(r.kind),variable:n}}throw this.error(`Expected array value but found ${C[e.kind]} ("${e.text}") at position ${e.start}`)}parseApexBindVariable(){this.expect(144);let e=[];for(this.check(32)?e.push(this.parseApexBindNewInstantiation()):this.checkIdentifier()&&(this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):e.push(this.parseApexBindIdentifier()));this.check(142);)this.advance(),this.checkIdentifier()&&this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):this.checkIdentifier()&&e.push(this.parseApexBindIdentifier());return{value:e.join(".")}}parseApexBindIdentifier(){let e=this.consumeIdentifier().text;return this.check(140)&&(e+=this.parseApexBindArrayAccessor()),e}parseApexBindNewInstantiation(){this.expect(32);let r=`new ${this.consumeIdentifier().text}`;if(this.check(134)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);this.expect(136),r+=`<${t.join(", ")}>`}return r+=this.parseApexBindFunctionParams(),this.check(140)&&(r+=this.parseApexBindArrayAccessor()),r}parseApexBindFunctionCall(){let r=this.consumeIdentifier().text+this.parseApexBindFunctionParams();return this.check(140)&&(r+=this.parseApexBindArrayAccessor()),r}parseApexBindFunctionParams(){this.expect(138);let e=[];if(!this.check(139))for(e.push(this.consumeIdentifier().text);this.match(143);)e.push(this.consumeIdentifier().text);return this.expect(139),`(${e.join(", ")})`}parseApexBindArrayAccessor(){this.expect(140);let e=this.peek(),r;if(e.kind===156)r=this.advance().text;else if(I(e.kind))r=this.advance().text;else throw this.error(`Expected integer or identifier in array accessor at position ${e.start}`);return this.expect(141),`[${r}]`}parseAnyFunction(e){let r=this.peek();if(m(r.kind))return this.parseDateFunction(e);if(F(r.kind))return this.parseAggregateFunction(e);if(r.kind===68)return this.parseLocationFunction(e);if(X(r.kind))return this.parseFieldsFunction(e);if(x(r.kind))return this.parseOtherFunction(e);throw this.error(`Expected function name but found ${C[r.kind]} at position ${r.start}`)}parseDateFunction(e){let r=this.advance(),t=A(r.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseAggregateFunction(e){let r=this.advance(),t=A(r.kind),n=this.parseFunctionExpression(!0,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseFieldsFunction(e){this.advance(),this.expect(138);let r=this.peek(),t;if(ie(r.kind))t=this.advance().text;else if(I(r.kind))t=this.advance().text;else throw this.error(`Expected FIELDS function parameter at position ${r.start}`);this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="FIELDS",n.parameters=[t],n.rawValue=`FIELDS(${t})`,n}parseOtherFunction(e){let r=this.advance(),t=A(r.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseLocationFunction(e){this.advance(),this.expect(138);let r=this.consumeIdentifier().text;this.expect(143);let t;this.check(69)&&this.peekAt(1).kind===138?t=this.parseGeolocationFunction(e):t=this.consumeIdentifier().text,this.expect(143);let n=this.expect(158).text;this.expect(139);let a={};e&&(a.type="FieldFunctionExpression"),a.functionName="DISTANCE",a.parameters=[r,t,n],e&&(a.isAggregateFn=!0);let o=typeof t=="string"?t:t.rawValue;return a.rawValue=`DISTANCE(${r}, ${o}, ${n})`,a}parseGeolocationFunction(e){this.advance(),this.expect(138);let r=this.parseNumberValue();this.expect(143);let t=this.parseNumberValue();this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="GEOLOCATION",n.parameters=[r,t],n.rawValue=`GEOLOCATION(${r}, ${t})`,n}parseNumberValue(){let e=this.peek();if(e.kind===156||e.kind===155||e.kind===154||e.kind===153)return this.advance().text;throw this.error(`Expected number but found ${C[e.kind]} ("${e.text}") at position ${e.start}`)}parseFunctionExpression(e,r=!0){this.expect(138);let t=[];if(!this.check(139))for(t.push(this.parseFunctionParam(e,r));this.match(143);)t.push(this.parseFunctionParam(e,r));return this.expect(139),t}parseFunctionParam(e,r){let t=this.peek(),n=this.peekAt(1);if(!e&&F(t.kind)&&n.kind===138)return this.parseAggregateFunction(r);if(x(t.kind)&&n.kind===138)return this.parseOtherFunction(r);if(t.kind===157)return this.advance().text;if(j(t.kind))return this.advance().text;if(I(t.kind))return this.advance().text;throw this.error(`Expected function parameter but found ${C[t.kind]} ("${t.text}") at position ${t.start}`)}parseGroupByClause(){this.expect(10);let e=[];for(e.push(this.parseGroupByItem());this.match(143);)e.push(this.parseGroupByItem());return e}parseGroupByItem(){let e=this.peek();return e.kind===4&&this.peekAt(1).kind===138?{fn:this.parseCubeOrRollupFunction("CUBE")}:e.kind===22&&this.peekAt(1).kind===138?{fn:this.parseCubeOrRollupFunction("ROLLUP")}:m(e.kind)&&this.peekAt(1).kind===138?{fn:this.parseDateFunction(!1)}:{field:this.consumeIdentifier().text}}parseCubeOrRollupFunction(e){let r=this.advance(),t=this.parseFunctionExpression(!1);return{functionName:e,parameters:t,rawValue:`${e}(${t.join(", ")})`}}parseHavingClause(){return this.expect(11),this.parseConditionExpressions(!0,!1)}parseOrderByClause(){this.expect(21);let e=[];for(e.push(this.parseOrderByItem());this.match(143);)e.push(this.parseOrderByItem());return e}parseOrderByItem(){let e=this.peek(),r=this.peekAt(1),t;if(e.kind===75&&r.kind===138){let n=this.advance(),a=this.parseFunctionExpression(!1);t={fn:{functionName:A(n.kind),parameters:a,rawValue:`${n.text}(${a.join(", ")})`}}}else F(e.kind)&&r.kind===138?t={fn:this.parseAggregateFunction(!1)}:m(e.kind)&&r.kind===138?t={fn:this.parseDateFunction(!1)}:e.kind===68&&r.kind===138?t={fn:this.parseLocationFunction(!1)}:t={field:this.consumeIdentifier().text};if(this.check(2)?t.order=A(this.advance().kind):this.check(3)&&(t.order=A(this.advance().kind)),this.check(19))if(this.advance(),this.check(8))t.nulls=A(this.advance().kind);else if(this.check(14))t.nulls=A(this.advance().kind);else throw this.error(`Expected FIRST or LAST after NULLS at position ${this.peek().start}`);return t}parseWithClause(){this.expect(27);let e=this.peek();if(e.kind===46)return this.advance(),{withSecurityEnforced:!0};if(e.kind===48)return this.advance(),{withAccessLevel:"USER_MODE"};if(e.kind===47)return this.advance(),{withAccessLevel:"SYSTEM_MODE"};if(e.kind===35)return{withDataCategory:this.parseWithDataCategory()};throw this.error(`Expected SECURITY_ENFORCED, USER_MODE, SYSTEM_MODE, or DATA CATEGORY after WITH at position ${e.start}`)}parseWithDataCategory(){this.expect(35);let e=[];for(e.push(this.parseDataCategoryCondition());this.check(0);)this.advance(),e.push(this.parseDataCategoryCondition());return{conditions:e}}parseDataCategoryCondition(){let e=this.consumeIdentifier().text,r=this.peek(),t;if(r.kind===33||r.kind===30||r.kind===34||r.kind===31)t=this.advance().text;else throw this.error(`Expected data category selector (AT, ABOVE, BELOW, ABOVE_OR_BELOW) at position ${r.start}`);let n=this.match(138),a=[];for(a.push(this.consumeIdentifier().text);this.match(143);)a.push(this.consumeIdentifier().text);return n&&this.expect(139),{groupName:e,selector:t,parameters:a}}};function D(i,e){let r=e||{},t=ne(i),n=new K(t,r),a;if(r.allowPartialQuery?a=n.parseSelectStatementPartial():a=n.parseSelectStatement(!1),!n.isAtEnd()&&!r.ignoreParseErrors){let o=t[n.getPos()];throw new Error(`Unexpected token "${o.text}" at position ${o.start}. Expected end of query.`)}return a}function ae(i,e){try{return D(i,e),!0}catch{return!1}}function oe(i){return i===32||i===9||i===10||i===13||i===12}function z(i,e){let r=[],t=i.length,n=0;for(;n<t;){let a=i.charCodeAt(n);if(a===39){for(n++;n<t;){let o=i.charCodeAt(n);if(o===92){n+=2;continue}if(o===39){n++;break}n++}continue}if(a===47){let o=n+1<t?i.charCodeAt(n+1):0;if(o===47){let u=n;for(n+=2;n<t;){let l=i.charCodeAt(n);if(l===10||l===13)break;n++}if(r.push({type:"line",text:i.substring(u,n),start:u,end:n}),e)return r;continue}if(o===42){let u=n;for(n+=2;n<t;){if(i.charCodeAt(n)===42&&n+1<t&&i.charCodeAt(n+1)===47){n+=2;break}n++}if(r.push({type:"block",text:i.substring(u,n),start:u,end:n}),e)return r;continue}}n++}return r}function le(i){return z(i,!1)}function ue(i){return z(i,!0).length>0}function Ee(i){let e=z(i,!1);if(e.length===0)return i;let r="",t=0;for(let n of e){r+=i.substring(t,n.start);let a=r.length>0?r.charCodeAt(r.length-1):0,o=n.end<i.length?i.charCodeAt(n.end):0;a!==0&&!oe(a)&&o!==0&&!oe(o)&&(r+=" "),t=n.end}return r+=i.substring(t),r}function d(i){return typeof i=="string"}function ve(i){return i?i.every(e=>d(e)):!1}function L(i){return Number.isFinite(i)}function N(i){return i==null}function O(i,e,r){return N(i)?"":`${r||""}${i}${e||""}`}function he(i,e=!1){return Array.isArray(i)?i.length>0?`(${i.join(", ")})`:e?"()":"":e?`(${i||""})`:i||""}function ce(i,e,r=""){return L(i)&&i>0?new Array(i).fill(e).join(r):""}function J(i){return!i.parameters||i.parameters.length===0?[]:ve(i.parameters)?i.parameters:d(i.parameters[0])?[i.parameters[0]]:J(i.parameters[0])}function pe(i){if(!i.parameters||i.parameters.length===0)return!1;let e=i.parameters[0];return d(e)?!1:!!e.isAggregateFn}function b(i){return i&&!N(i.alias)}function fe(i){return d(i.field)&&!Array.isArray(i.relationships)&&!Array.isArray(i.conditions)}function Ae(i){return!N(i.functionName||i.fn)}function de(i){return d(i.field)&&Array.isArray(i.relationships)}function Ne(i){return!N(i.subquery)}function Re(i){return d(i.field)&&Array.isArray(i.conditions)}function g(i){return d(i.relationshipName)}function ee(i){return!!i&&!!i.type&&i.type==="FieldSubquery"}function Ce(i){return!!i&&!!i.operator&&!!i.right}function Te(i){return!!i&&!!i.operator&&!!i.right}function P(i){return!!i&&!!i.operator&&!!i.right}function _e(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)}function Se(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)&&(i.literalType==="DATE_LITERAL"||Array.isArray(i.literalType)&&i.literalType[0]==="DATE_LITERAL")}function Ie(i){return i&&d(i.field)&&d(i.operator)&&!N(i.value)&&!N(i.dateLiteralVariable)}function v(i){return i&&!N(i.fn)&&d(i.operator)&&!N(i.value)}function y(i){return i&&L(i.openParen)&&N(i.operator)&&N(i.field)&&N(i.fn)&&N(i.closeParen)}function Y(i){return i&&d(i.field)&&d(i.operator)&&!N(i.valueQuery)&&N(i.value)}function w(i){return i&&!N(i.field)}function Le(i){return i&&!N(i.fn)}function U(i){return i&&!N(i.field)}function Oe(i){return i&&!N(i.fn)}function Ye(i){return["IN","NOT IN","INCLUDES","EXCLUDES"].includes(i)}function ge(i,e,r){if(N(e))return i;if(r&&e!=="APEX_BIND_VARIABLE"&&Ye(r)&&!Array.isArray(i)&&(i=[i],e=Array.isArray(e)?e:[e]),Array.isArray(e)&&Array.isArray(i))return i.map((t,n)=>we(t,e?.[n]));switch(Array.isArray(e)&&(e=e[0]),e){case"STRING":return Array.isArray(i)?i.filter(Boolean).map(t=>Z(t)):Z(i);case"APEX_BIND_VARIABLE":return`:${i}`;default:return i}}function we(i,e){switch(e){case"STRING":return Z(i);case"NULL":return"null";default:return i}}function Z(i){if(d(i)&&i.startsWith("'")&&i.endsWith("'")&&i.length>=2)return i;let e=String(i??"");return`'${Be(e)}'`}var $e=/[nNrRtTbBfF"'\\_%]/,We=/^[0-9a-fA-F]{4}$/;function Be(i){let e="";for(let r=0;r<i.length;r++){let t=i[r];if(t==="\\"){let n=i[r+1];n!==void 0&&$e.test(n)?(e+=t+n,r++):n==="u"&&We.test(i.substr(r+2,4))?(e+=i.substr(r,6),r+=5):e+="\\\\"}else t==="'"?e+="\\'":e+=t}return e}function Ve(i){return me(i)}function me(i){if(typeof i=="string")return{type:"Field",field:i};if(Ae(i)){let e=[];return i.parameters&&(e=Array.isArray(i.parameters)?i.parameters:[i.parameters]),{type:"FieldFunctionExpression",functionName:i.functionName||i.fn,parameters:e,alias:i.alias}}else{if(de(i))return{type:"FieldRelationship",field:i.field,relationships:i.relationships,objectPrefix:i.objectPrefix};if(Ne(i))return{type:"FieldSubquery",subquery:i.subquery};if(Re(i))return{type:"FieldTypeof",field:i.field,conditions:i.conditions};if(fe(i))return{type:"Field",field:i.field,objectPrefix:i.objectPrefix};throw new TypeError("The input object provided did not match any valid field types")}}function Qe(i,e){if(!i)return[];i=ee(i)?i.subquery:i;let r=i.fields;if(!r)return[];let t={};i.groupBy&&(t=(Array.isArray(i.groupBy)?i.groupBy:[i.groupBy]).reduce((l,h)=>(U(h)&&(l[h.field.toLocaleLowerCase()]=h.field),l),{}));let n=-1,a=(g(i)?i.relationshipName:i.sObject||"").toLowerCase(),o=(i.sObjectAlias||"").toLowerCase();return r.flatMap(l=>{switch(l.type){case"Field":return l.alias||l.field;case"FieldFunctionExpression":{let h=J(l);if(h=h.map(E=>{if(E.includes(".")){let R=E.split("."),f=R[0].toLowerCase();return(f===o||f===a)&&(R=R.slice(1)),R.join(".")}return E}),l.alias&&(l.isAggregateFn||e))return l.alias;if(l.alias){let E=h[0];return E.includes(".")?(h=E.split(".").slice(0,-1),h.push(l.alias),h.join(".")):l.alias}return l.isAggregateFn||pe(l)||e?(n++,`expr${n}`):h.length>0?h.join("."):l.functionName}case"FieldRelationship":{let h=l.relationships[0].toLowerCase();return b(l)?l.alias:l.rawValue&&t[l.rawValue.toLocaleLowerCase()]?l.field:h===o||h===a?l.relationships.concat([l.field]).slice(1).join("."):l.relationships.concat([l.field]).join(".")}case"FieldSubquery":return l.subquery.relationshipName;case"FieldTypeof":{let h=new Set,E=[];return l.conditions.forEach(R=>{R.fieldList.forEach(f=>{h.has(f)||(h.add(f),E.push(`${l.field}.${f}`))})}),E}default:break}}).filter(l=>d(l))}var $=class{constructor(e,r){this.currIndent=1;this.enabled=e,this.options={numIndent:r.numIndent??1,fieldMaxLineLength:r.fieldMaxLineLength??60,fieldSubqueryParensOnOwnLine:r.fieldSubqueryParensOnOwnLine??!0,whereClauseOperatorsIndented:!0,newLineAfterKeywords:r.newLineAfterKeywords??!1,logging:r.logging??!1},this.options.newLineAfterKeywords&&(this.options.fieldSubqueryParensOnOwnLine=!0)}log(e){this.options.logging&&console.log(e)}getIndent(e=0){return this.repeatChar((this.currIndent+e)*(this.options.numIndent||1)," ")}repeatChar(e,r){return new Array(e).fill(r).join("")}setSubquery(e){this.currIndent=e?this.currIndent+=1:this.currIndent-=1}stepCurrIndex(e){this.currIndent+=e}formatFields(e){function r(t){e.fields[t-1]&&(e.fields[t-1].suffix=e.fields[t-1].suffix.trim())}if(e.fields.forEach((t,n)=>{t.suffix=e.fields.length-1===n?"":", "}),this.enabled){let t=0,n=!1;e.fields.forEach((a,o)=>{a.isSubquery?(r(o),a.prefix=`
7
+ ${this.getIndent()}`,a.suffix=e.fields.length-1===o?"":", ",t=0,n=!0):Array.isArray(a.typeOfClause)?(r(o),a.prefix=`
8
+ ${this.getIndent()}`,n=!0):L(this.options.fieldMaxLineLength)&&(t+=a.text.length+a.suffix.length,(t>this.options.fieldMaxLineLength||n)&&(r(o),(!this.options.newLineAfterKeywords||o>0)&&(a.prefix+=`
9
+ ${this.getIndent()}`),t=0,n=!1)),this.log(a)})}}formatTyeOfField(e,r){return this.enabled&&this.options.newLineAfterKeywords?r.map((t,n)=>n===0?t:n===r.length-1?`${this.getIndent()}${t}`:`${this.getIndent()} ${t}`).join(`
10
+ `):e}formatTypeofFieldCondition(e){let r="",t=e.fieldList.join(", ");if(this.enabled&&this.options.newLineAfterKeywords){let n=this.getIndent();r=`${e.type}`,e.objectType?r+=`
11
11
  ${n} ${e.objectType}
12
12
  ${n} THEN
13
- ${n} ${t}`:s+=`
14
- ${n} ${t}`}else s=e.type,e.objectType?s+=` ${e.objectType} THEN ${t}`:s+=` ${t}`;return s}formatSubquery(e,s=2,t=!1){t&&s++;let n="(",a=")";return this.enabled&&(this.options.fieldSubqueryParensOnOwnLine||this.options.newLineAfterKeywords?(e=e.replace(/\n/g,`
15
- ${this.repeatChar(s," ")}`),n=`(
16
- ${this.repeatChar(s," ")}`,a=`
17
- ${this.repeatChar(s-1," ")})`):e=e.replace(/\n/g,`
13
+ ${n} ${t}`:r+=`
14
+ ${n} ${t}`}else r=e.type,e.objectType?r+=` ${e.objectType} THEN ${t}`:r+=` ${t}`;return r}formatSubquery(e,r=2,t=!1){t&&r++;let n="(",a=")";return this.enabled&&(this.options.fieldSubqueryParensOnOwnLine||this.options.newLineAfterKeywords?(e=e.replace(/\n/g,`
15
+ ${this.repeatChar(r," ")}`),n=`(
16
+ ${this.repeatChar(r," ")}`,a=`
17
+ ${this.repeatChar(r-1," ")})`):e=e.replace(/\n/g,`
18
18
  `)),`${n}${e}${a}`}formatClause(e){return this.enabled?this.options.newLineAfterKeywords?`
19
19
  ${e}
20
20
  ${this.getIndent()}`:`
21
21
  ${e}`:` ${e}`}formatText(e){return this.enabled&&(this.options.newLineAfterKeywords||e.startsWith(`
22
- `))?e:` ${e}`}formatWithIndent(e){return this.enabled?`${this.getIndent()}${e}`:e}formatOrderByArray(e){if(this.enabled){let s=0,t="";return e.forEach((n,a)=>{let o=e[a+1];s+=n.length,o&&(s+o.length>(this.options.fieldMaxLineLength||0)||this.options.newLineAfterKeywords)?(t+=`${n},
23
- `,s=0):t+=`${n}${o?", ":""}`}),t}else return e.join(", ")}formatParens(e,s,t=!1){let n="";if(L(e)&&e>0)if(this.enabled)if(s==="("){for(let a=0;a<e;a++)t&&a===e-1?n+="(":a===0?n+=`(
22
+ `))?e:` ${e}`}formatWithIndent(e){return this.enabled?`${this.getIndent()}${e}`:e}formatOrderByArray(e){if(this.enabled){let r=0,t="";return e.forEach((n,a)=>{let o=e[a+1];r+=n.length,o&&(r+o.length>(this.options.fieldMaxLineLength||0)||this.options.newLineAfterKeywords)?(t+=`${n},
23
+ `,r=0):t+=`${n}${o?", ":""}`}),t}else return e.join(", ")}formatParens(e,r,t=!1){let n="";if(L(e)&&e>0)if(this.enabled)if(r==="("){for(let a=0;a<e;a++)t&&a===e-1?n+="(":a===0?n+=`(
24
24
  `:(this.currIndent++,n+=`${this.getIndent()}(
25
25
  `);(!t||e>1)&&this.currIndent++}else for(let a=e-1;a>=0;a--)t&&a===e-1?n+=")":(this.currIndent--,n+=`
26
- ${this.getIndent()})`);else n+=oe(e,s);return n}formatWhereClauseOperators(e,s,t=0){let n=e==="NOT";return this.enabled&&!n?`
27
- ${this.getIndent(t)}${e} ${s}`:`${n?"":" "}${e} ${s}`}formatAddNewLine(e=" ",s){return this.enabled&&!s?`
28
- `:e}};function We(i,e,s){return Ie(D(i,s),{format:!0,formatOptions:e})}function Ie(i,e={}){if(!i)return"";e=e||{},e.format=!!e.format,e.logging&&(console.time("composer"),console.log("Composing Query:",i),console.log("Format output:",e.format));let s=new W(i,e).query;return e.logging&&console.timeEnd("composer"),s}var W=class{constructor(e,s={}){this.soql=e;this.logging=!1;this.format=!1;s={autoCompose:!0,...s};let{logging:t,format:n}=s;this.logging=!!t,this.format=!!n,this.query="",this.formatter=new $(this.format,{logging:this.logging,...s.formatOptions}),s.autoCompose&&this.start()}start(){this.query=this.parseQuery(this.soql)}log(e){this.logging&&console.log("Current SOQL:",e)}parseFn(e){let s;return e.rawValue?s=e.rawValue:(s=e.functionName,s+=`(${(e.parameters||[]).map(t=>d(t)?t:this.parseFn(t)).join(", ")})`),e.alias&&(s+=` ${e.alias}`),s}parseQuery(e){let s={fields:this.parseFields(e.fields||[]).map(a=>({text:a.text,typeOfClause:a.typeOfClause,isSubquery:a.text.startsWith("("),prefix:"",suffix:""})),isSubquery:g(e),lineBreaks:[]},t="";e.fields&&(t+=this.formatter.formatClause("SELECT").trimStart()),this.formatter.formatFields(s);let n="";if(s.fields.forEach(a=>{Array.isArray(a.typeOfClause)?n+=`${a.prefix}${this.formatter.formatTyeOfField(a.text,a.typeOfClause)}${a.suffix}`:n+=`${a.prefix}${a.text}${a.suffix}`}),t+=this.formatter.formatText(n),(g(e)?e.relationshipName:e.sObject)&&(t+=this.formatter.formatClause("FROM")),g(e)){let a=e.sObjectPrefix||[];a.push(e.relationshipName),t+=this.formatter.formatText(`${a.join(".")}${O(e.sObjectAlias,""," ")}`)}else e.sObject&&(t+=this.formatter.formatText(`${e.sObject}${O(e.sObjectAlias,""," ")}`));return this.log(t),e.usingScope&&(t+=this.formatter.formatClause("USING SCOPE"),t+=this.formatter.formatText(e.usingScope),this.log(t)),e.where&&(t+=this.formatter.formatClause("WHERE"),t+=this.formatter.formatText(this.parseWhereOrHavingClause(e.where)),this.log(t)),e.groupBy&&(t+=this.formatter.formatClause("GROUP BY"),t+=this.formatter.formatText(this.parseGroupByClause(e.groupBy)),this.log(t),e.having&&(t+=this.formatter.formatClause("HAVING"),t+=this.formatter.formatText(this.parseWhereOrHavingClause(e.having)),this.log(t))),e.orderBy&&(!Array.isArray(e.orderBy)||e.orderBy.length>0)&&(t+=this.formatter.formatClause("ORDER BY"),t+=this.formatter.formatText(this.parseOrderBy(e.orderBy)),this.log(t)),L(e.limit)&&(t+=this.formatter.formatClause("LIMIT"),t+=this.formatter.formatText(`${e.limit}`),this.log(t)),L(e.offset)&&(t+=this.formatter.formatClause("OFFSET"),t+=this.formatter.formatText(`${e.offset}`),this.log(t)),e.withDataCategory&&(t+=this.formatter.formatClause("WITH DATA CATEGORY"),t+=this.formatter.formatText(this.parseWithDataCategory(e.withDataCategory)),this.log(t)),e.withSecurityEnforced&&(t+=this.formatter.formatClause("WITH SECURITY_ENFORCED"),this.log(t)),e.withAccessLevel&&(t+=this.formatter.formatClause(`WITH ${e.withAccessLevel}`),this.log(t)),e.for&&(t+=this.formatter.formatClause("FOR"),t+=this.formatter.formatText(e.for),this.log(t)),e.update&&(t+=this.formatter.formatClause("UPDATE"),t+=this.formatter.formatText(e.update),this.log(t)),t.trim()}parseFields(e){return e.map(s=>{let t="",n,a=s.objectPrefix?`${s.objectPrefix}.`:"";switch(s.type){case"Field":{t=`${a}${s.field}${s.alias?` ${s.alias}`:""}`;break}case"FieldFunctionExpression":{let o="";s.parameters&&(o=s.parameters.map(E=>d(E)?E:this.parseFields([E]).map(l=>l.text)).join(", ")),t=`${s.functionName}(${o})${s.alias?` ${s.alias}`:""}`;break}case"FieldRelationship":{t=`${a}${s.relationships.join(".")}.${s.field}${b(s)?` ${s.alias}`:""}`;break}case"FieldSubquery":{t=this.formatter.formatSubquery(this.parseQuery(s.subquery));break}case"FieldTypeof":{n=this.parseTypeOfField(s),t=n.join(" ");break}default:break}return{text:t,typeOfClause:n}})}parseTypeOfField(e){let s=[`TYPEOF ${e.field}`].concat(e.conditions.map(t=>this.formatter.formatTypeofFieldCondition(t)));return s.push("END"),s}parseWhereOrHavingClause(e,s=0,t=!1){let n="",a=e.left,o=!1;if(a&&(n+=this.formatter.formatParens(a.openParen,"(",y(a)),!y(a))){s=s+(a.openParen||0)-(a.closeParen||0),t&&s++;let E="";E+=v(a)?this.parseFn(a.fn):a.field,E+=` ${a.operator} `,Y(a)?E+=this.formatter.formatSubquery(this.parseQuery(a.valueQuery),1,!0):E+=ae(_e(a.value,a.literalType,a.operator)),n+=this.formatter.formatWithIndent(E),n+=this.formatter.formatParens(a.closeParen,")",t)}if(P(e)){let E=O(e.operator);o=E==="NOT";let l=this.formatter.formatWhereClauseOperators(E,this.parseWhereOrHavingClause(e.right,s,y(a)),s);return`${o?n.trimRight():n}${l}`.trim()}else return n.trim()}parseGroupByClause(e){return(Array.isArray(e)?e:[e]).map(s=>U(s)?s.field:this.parseFn(s.fn)).join(", ")}parseOrderBy(e){if(Array.isArray(e))return this.formatter.formatOrderByArray(e.map(s=>this.parseOrderBy(s)));{let s="";return w(e)?s=`${O(e.field," ")}`:s+=`${this.parseFn(e.fn)} `,s+=`${O(e.order," ")}${O(e.nulls,"","NULLS ")}`,s.trim()}}parseWithDataCategory(e){return e.conditions.map(s=>{let t=s.parameters.length>1?`(${s.parameters.join(", ")})`:`${s.parameters.join(", ")}`;return`${s.groupName} ${s.selector} ${t}`}).join(" AND ")}};
26
+ ${this.getIndent()})`);else n+=ce(e,r);return n}formatWhereClauseOperators(e,r,t=0){let n=e==="NOT";return this.enabled&&!n?`
27
+ ${this.getIndent(t)}${e} ${r}`:`${n?"":" "}${e} ${r}`}formatAddNewLine(e=" ",r){return this.enabled&&!r?`
28
+ `:e}};function Xe(i,e,r){return Fe(D(i,r),{format:!0,formatOptions:e})}function Fe(i,e={}){if(!i)return"";e=e||{},e.format=!!e.format,e.logging&&(console.time("composer"),console.log("Composing Query:",i),console.log("Format output:",e.format));let r=new W(i,e).query;return e.logging&&console.timeEnd("composer"),r}var W=class{constructor(e,r={}){this.soql=e;this.logging=!1;this.format=!1;r={autoCompose:!0,...r};let{logging:t,format:n}=r;this.logging=!!t,this.format=!!n,this.query="",this.formatter=new $(this.format,{logging:this.logging,...r.formatOptions}),r.autoCompose&&this.start()}start(){this.query=this.parseQuery(this.soql)}log(e){this.logging&&console.log("Current SOQL:",e)}parseFn(e){let r;return e.rawValue?r=e.rawValue:(r=e.functionName,r+=`(${(e.parameters||[]).map(t=>d(t)?t:this.parseFn(t)).join(", ")})`),e.alias&&(r+=` ${e.alias}`),r}parseQuery(e){let r={fields:this.parseFields(e.fields||[]).map(a=>({text:a.text,typeOfClause:a.typeOfClause,isSubquery:a.text.startsWith("("),prefix:"",suffix:""})),isSubquery:g(e),lineBreaks:[]},t="";e.fields&&(t+=this.formatter.formatClause("SELECT").trimStart()),this.formatter.formatFields(r);let n="";if(r.fields.forEach(a=>{Array.isArray(a.typeOfClause)?n+=`${a.prefix}${this.formatter.formatTyeOfField(a.text,a.typeOfClause)}${a.suffix}`:n+=`${a.prefix}${a.text}${a.suffix}`}),t+=this.formatter.formatText(n),(g(e)?e.relationshipName:e.sObject)&&(t+=this.formatter.formatClause("FROM")),g(e)){let a=e.sObjectPrefix||[];a.push(e.relationshipName),t+=this.formatter.formatText(`${a.join(".")}${O(e.sObjectAlias,""," ")}`)}else e.sObject&&(t+=this.formatter.formatText(`${e.sObject}${O(e.sObjectAlias,""," ")}`));return this.log(t),e.usingScope&&(t+=this.formatter.formatClause("USING SCOPE"),t+=this.formatter.formatText(e.usingScope),this.log(t)),e.where&&(t+=this.formatter.formatClause("WHERE"),t+=this.formatter.formatText(this.parseWhereOrHavingClause(e.where)),this.log(t)),e.groupBy&&(t+=this.formatter.formatClause("GROUP BY"),t+=this.formatter.formatText(this.parseGroupByClause(e.groupBy)),this.log(t),e.having&&(t+=this.formatter.formatClause("HAVING"),t+=this.formatter.formatText(this.parseWhereOrHavingClause(e.having)),this.log(t))),e.orderBy&&(!Array.isArray(e.orderBy)||e.orderBy.length>0)&&(t+=this.formatter.formatClause("ORDER BY"),t+=this.formatter.formatText(this.parseOrderBy(e.orderBy)),this.log(t)),L(e.limit)&&(t+=this.formatter.formatClause("LIMIT"),t+=this.formatter.formatText(`${e.limit}`),this.log(t)),L(e.offset)&&(t+=this.formatter.formatClause("OFFSET"),t+=this.formatter.formatText(`${e.offset}`),this.log(t)),e.withDataCategory&&(t+=this.formatter.formatClause("WITH DATA CATEGORY"),t+=this.formatter.formatText(this.parseWithDataCategory(e.withDataCategory)),this.log(t)),e.withSecurityEnforced&&(t+=this.formatter.formatClause("WITH SECURITY_ENFORCED"),this.log(t)),e.withAccessLevel&&(t+=this.formatter.formatClause(`WITH ${e.withAccessLevel}`),this.log(t)),e.for&&(t+=this.formatter.formatClause("FOR"),t+=this.formatter.formatText(e.for),this.log(t)),e.update&&(t+=this.formatter.formatClause("UPDATE"),t+=this.formatter.formatText(e.update),this.log(t)),t.trim()}parseFields(e){return e.map(r=>{let t="",n,a=r.objectPrefix?`${r.objectPrefix}.`:"";switch(r.type){case"Field":{t=`${a}${r.field}${r.alias?` ${r.alias}`:""}`;break}case"FieldFunctionExpression":{let o="";r.parameters&&(o=r.parameters.map(u=>d(u)?u:this.parseFields([u]).map(l=>l.text)).join(", ")),t=`${r.functionName}(${o})${r.alias?` ${r.alias}`:""}`;break}case"FieldRelationship":{t=`${a}${r.relationships.join(".")}.${r.field}${b(r)?` ${r.alias}`:""}`;break}case"FieldSubquery":{t=this.formatter.formatSubquery(this.parseQuery(r.subquery));break}case"FieldTypeof":{n=this.parseTypeOfField(r),t=n.join(" ");break}default:break}return{text:t,typeOfClause:n}})}parseTypeOfField(e){let r=[`TYPEOF ${e.field}`].concat(e.conditions.map(t=>this.formatter.formatTypeofFieldCondition(t)));return r.push("END"),r}parseWhereOrHavingClause(e,r=0,t=!1){let n="",a=e.left,o=!1;if(a&&(n+=this.formatter.formatParens(a.openParen,"(",y(a)),!y(a))){r=r+(a.openParen||0)-(a.closeParen||0),t&&r++;let u="";u+=v(a)?this.parseFn(a.fn):a.field,u+=` ${a.operator} `,Y(a)?u+=this.formatter.formatSubquery(this.parseQuery(a.valueQuery),1,!0):u+=he(ge(a.value,a.literalType,a.operator)),n+=this.formatter.formatWithIndent(u),n+=this.formatter.formatParens(a.closeParen,")",t)}if(P(e)){let u=O(e.operator);o=u==="NOT";let l=this.formatter.formatWhereClauseOperators(u,this.parseWhereOrHavingClause(e.right,r,y(a)),r);return`${o?n.trimRight():n}${l}`.trim()}else return n.trim()}parseGroupByClause(e){return(Array.isArray(e)?e:[e]).map(r=>U(r)?r.field:this.parseFn(r.fn)).join(", ")}parseOrderBy(e){if(Array.isArray(e))return this.formatter.formatOrderByArray(e.map(r=>this.parseOrderBy(r)));{let r="";return w(e)?r=`${O(e.field," ")}`:r+=`${this.parseFn(e.fn)} `,r+=`${O(e.order," ")}${O(e.nulls,"","NULLS ")}`,r.trim()}}parseWithDataCategory(e){return e.conditions.map(r=>{let t=r.parameters.length>1?`(${r.parameters.join(", ")})`:`${r.parameters.join(", ")}`;return`${r.groupName} ${r.selector} ${t}`}).join(" AND ")}};