@jetstreamapp/soql-parser-js 7.1.1 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.2.1
4
+
5
+ Jun 8, 2026
6
+
7
+ ### Bug Fixes
8
+
9
+ - **Escape single quotes and lone backslashes in composed `STRING` values** — `composeQuery` previously wrapped `STRING` literal values in single quotes without escaping their contents, so a value like `med'ia` produced invalid SOQL (`Industry = 'med'ia'`). String values are now escaped before being wrapped: bare single quotes become `\'` and lone backslashes become `\\`. Backslash sequences that are already valid SOQL escapes (`\n`, `\r`, `\t`, `\b`, `\f`, `\"`, `\'`, `\\`, `\_`, `\%`, `\uXXXX`, including their uppercase variants) are left unchanged so callers can pre-escape values themselves. Values that are already wrapped in single quotes (e.g. round-tripped through `parseQuery`) are passed through unchanged.
10
+
11
+ ## 7.2.0
12
+
13
+ May 11, 2026
14
+
15
+ ### LWC Distribution
16
+
17
+ The LWC build now produces two artifacts to support different deployment workflows:
18
+
19
+ - **Standalone JS file** at `dist/lwc/soqlParserJs.js` — a single bundled file that SFDX users can drop directly into their project's `lwc/soqlParserJs/` folder alongside their own `.js-meta.xml`. Also published to npm and attached to each GitHub Release.
20
+ - **Ready-to-deploy metadata package** at `dist/lwc-packaged/` — contains `package.xml`, `lwc/soqlParserJs/soqlParserJs.js`, and `soqlParserJs.js-meta.xml`. Deploy directly with `sf project deploy start --metadata-dir dist/lwc-packaged --target-org <alias>`, no SFDX project required.
21
+ - **Pre-zipped metadata package on GitHub Releases** — every release attaches `soql-parser-js-lwc-v<version>.zip` (the metadata package, pre-zipped) so users can grab a single archive, and deploy without cloning or running `npm install`.
22
+ - **Fixed LWC compiler compatibility** — lowered the LWC bundle's esbuild target to `es2020`, which down-levels ES2022 syntax (e.g. static class initialization blocks) that the Salesforce LWC compiler does not yet support.
23
+ - **Configurable Salesforce API version** — added the `salesforceApiVersion` field to `package.json` (currently `66.0`); the value is stamped into both `package.xml` and `.js-meta.xml` at build time, so bumping the API version is a one-line change.
24
+
25
+ ### Release Pipeline
26
+
27
+ - **npm tarball attached to GitHub Releases** — every release now attaches `jetstreamapp-soql-parser-js-<version>.tgz`.
28
+ - **Version banner on all bundles** — `esm`, `cjs`, `cli`, and `lwc` bundles all start with a `/*! ... */` header listing the package name, version, repository URL, and license. Banner values are sourced from `package.json`, so they stay in sync automatically with each release.
29
+
3
30
  ## 7.1.1
4
31
 
5
32
  Apr 25, 2026
package/README.md CHANGED
@@ -510,52 +510,74 @@ WHERE Name LIKE 'a%'
510
510
 
511
511
  ## Using in LWC
512
512
 
513
- The easiest way to utilize this library in LWC is to deploy the compiled code as a web component in your org.
513
+ The library can be used as a Lightning Web Component in your Salesforce org. The build produces two artifacts to support different workflows:
514
514
 
515
- :warning: The minified version ends up with `$A` characters in the output, which causes the deployment to SFD to fail, so we have created an unminified version of the library just for Salesforce.
515
+ | Artifact | What it is | Best for |
516
+ | ------------------------------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------- |
517
+ | `dist/lwc/soqlParserJs.js` | Standalone bundled JS file (no metadata) | SFDX projects — drop into your existing `lwc/soqlParserJs/` folder |
518
+ | `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 |
516
519
 
517
- ### Obtaining the build artifacts
520
+ 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.
518
521
 
519
- We don't store the built artifacts on github, so you will need to obtain from NPM or run the build command yourself.
522
+ ### Option 1: SFDX project — drop in the standalone JS file
520
523
 
521
- #### Download from NPM
524
+ If you already have an SFDX project, the easiest path is to grab the standalone `soqlParserJs.js` and place it in your project's `lwc/soqlParserJs/` folder alongside a `soqlParserJs.js-meta.xml` file you provide yourself.
522
525
 
523
- Download from [npm](https://www.npmjs.com/package/@jetstreamapp/soql-parser-js)
526
+ Sources for the standalone JS:
524
527
 
525
- **Either:**
528
+ - **GitHub Releases** — every release attaches `soqlParserJs.js` directly to the [Releases page](https://github.com/jetstreamapp/soql-parser-js/releases).
529
+ - **npm** — `npm install @jetstreamapp/soql-parser-js`, then copy from `node_modules/@jetstreamapp/soql-parser-js/dist/lwc/soqlParserJs.js`.
530
+ - **Local build** — clone the repo, run `npm install && npm run build:lwc`, and find the file at `dist/lwc/soqlParserJs.js`.
526
531
 
527
- 1. Go to the "Code Tab" on the [npm](https://www.npmjs.com/package/@jetstreamapp/soql-parser-js) listing
528
- 1. Navigate to `/dist/lwc.index.mjs`
529
- 2. Install this project in an existing node library by running `npm install @jetstreamapp/soql-parser-js`
530
- 1. then navigating to the downloaded code in this folder: `node_modules/@jetstreamapp/soql-parser-js/dist/lwc`
532
+ Your SFDX folder should look like:
531
533
 
532
- #### Build the files yourself
534
+ ```
535
+ force-app/main/default/lwc/soqlParserJs/
536
+ ├── soqlParserJs.js <-- copied from this project
537
+ └── soqlParserJs.js-meta.xml <-- your own (example below)
538
+ ```
533
539
 
534
- 1. Clone/download the repository from GitHub
535
- 2. Ensure you have node installed (version 22 or higher)
536
- 3. Install dependencies with `npm install`
537
- 4. Run `npm build:lwc`
538
- 5. The output will be placed in `/dist/lwc.index.mjs`
540
+ A minimal `soqlParserJs.js-meta.xml`:
539
541
 
540
- ### Deploying and Using in Salesforce
542
+ ```xml
543
+ <?xml version="1.0" encoding="UTF-8"?>
544
+ <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
545
+ <apiVersion>66.0</apiVersion>
546
+ <isExposed>false</isExposed>
547
+ </LightningComponentBundle>
548
+ ```
541
549
 
542
- Copy `index.mjs` into an LWC component.
550
+ ### Option 2: Direct deployment — use the pre-built metadata package
543
551
 
544
- For example:
552
+ If you don't have an SFDX project, download the pre-zipped metadata package, extract, and deploy:
545
553
 
554
+ ```bash
555
+ # Download soql-parser-js-lwc-v<version>.zip from the GitHub Releases page, then:
556
+ unzip soql-parser-js-lwc-v<version>.zip -d soql-parser-js-lwc
557
+ sf project deploy start --metadata-dir soql-parser-js-lwc --target-org <your-org-alias>
546
558
  ```
547
- soqlParserJsLib
548
- - soqlParserJsLib.js <--- copy the code here
549
- - soqlParserJsLib.js-meta.xml
559
+
560
+ Or, if you've built locally, the equivalent directory is `dist/lwc-packaged/`:
561
+
562
+ ```bash
563
+ sf project deploy start --metadata-dir dist/lwc-packaged --target-org <your-org-alias>
550
564
  ```
551
565
 
552
- After you have deployed the LWC, you can import it just like any other LWC import.
566
+ Legacy `sfdx` CLI alternative:
567
+
568
+ ```bash
569
+ sfdx force:mdapi:deploy -d <path-to-package> -w 10
570
+ ```
571
+
572
+ ### Using in Salesforce
573
+
574
+ The deployed component is `c/soqlParserJs`. It is intentionally a library component (`isExposed=false`), so you don't drop it on a Lightning page directly — instead, import its exports from your own LWC:
553
575
 
554
576
  ```js
555
577
  import { LightningElement } from 'lwc';
556
- import { parseQuery } from 'c/soqlParserJsLib';
578
+ import { parseQuery } from 'c/soqlParserJs';
557
579
 
558
- export default class SoqlParserJs extends LightningElement {
580
+ export default class MyComponent extends LightningElement {
559
581
  parsedQuery;
560
582
 
561
583
  get parsedQueryString() {
@@ -570,12 +592,14 @@ export default class SoqlParserJs extends LightningElement {
570
592
 
571
593
  ```html
572
594
  <template>
573
- <button class="slds-button slds-button_neutral" onclick="{handleClick}">Click Me</button>
595
+ <button class="slds-button slds-button_neutral" onclick={handleClick}>Click Me</button>
574
596
 
575
597
  <p>Parsed Query: {parsedQueryString}</p>
576
598
  </template>
577
599
  ```
578
600
 
601
+ All public exports of the library (`parseQuery`, `composeQuery`, `formatQuery`, `isQueryValid`, the various utility functions, etc.) are available as named imports from `c/soqlParserJs`.
602
+
579
603
  ## CLI
580
604
 
581
605
  Install globally or use `npx` to interact with the cli.
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,9 @@
1
- "use strict";var B=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var Fe=(i,e)=>{for(var s in e)B(i,s,{get:e[s],enumerable:!0})},ge=(i,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Le(e))!Oe.call(i,n)&&n!==s&&B(i,n,{get:()=>e[n],enumerable:!(t=Ie(e,n))||t.enumerable});return i};var me=i=>ge(B({},"__esModule",{value:!0}),i);var Ye={};Fe(Ye,{Compose:()=>W,composeQuery:()=>Se,formatQuery:()=>ve,getComposedField:()=>Me,getField:()=>_e,getFlattenedFields:()=>Pe,hasAlias:()=>b,isFieldSubquery:()=>Z,isGroupByField:()=>U,isGroupByFn:()=>Te,isHavingClauseWithRightCondition:()=>fe,isNegationCondition:()=>y,isOrderByField:()=>w,isOrderByFn:()=>Re,isQueryValid:()=>se,isString:()=>f,isSubquery:()=>F,isValueCondition:()=>Ae,isValueFunctionCondition:()=>v,isValueQueryCondition:()=>Y,isValueWithDateLiteralCondition:()=>de,isValueWithDateNLiteralCondition:()=>Ne,isWhereClauseWithRightCondition:()=>ce,isWhereOrHavingClauseWithRightCondition:()=>P,parseQuery:()=>D});module.exports=me(Ye);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 g(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 ee(i){return i>=76&&i<=78}function G(i){return i>=79&&i<=101}function M(i){return i>=102&&i<=122}function te(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 ie(i){return i>=132&&i<=137}var ye=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]]),c=[];(function(){for(let e of Object.keys(T)){let s=T[e];typeof s=="number"&&(c[s]=e)}c[72]="toLabel",c[73]="convertTimezone",c[74]="convertCurrency",c[157]="StringIdentifier",c[150]="DATE",c[32]="new",c[125]="MineAndMyGroups",c[127]="MyTerritory",c[128]="MyTeamTerritory",c[130]="AllPrivate",c[123]="Delegated",c[124]="Everything",c[126]="Mine",c[129]="Team",c[131]="Mru",c[159]="Identifier",c[132]="EQUAL",c[156]="UNSIGNED_INTEGER",c[155]="SIGNED_INTEGER",c[154]="UNSIGNED_DECIMAL",c[153]="SIGNED_DECIMAL",c[151]="CURRENCY_PREFIXED_DECIMAL",c[152]="CURRENCY_PREFIXED_INTEGER"})();function d(i){return c[i]||T[i]}function q(i){return i>=65&&i<=90||i>=97&&i<=122}function p(i){return i>=48&&i<=57}function V(i){return q(i)||p(i)||i===95}function k(i){return i===32||i===9||i===10||i===13||i===12}function re(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===39){let a=t;for(t++;t<s;){let E=i.charCodeAt(t);if(E===92){t+=2;continue}if(E===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(p(n)){if(t+9<s&&i.charCodeAt(t+4)===45&&i.charCodeAt(t+7)===45){let o=!0;for(let h of[0,1,2,3,5,6,8,9])if(!p(i.charCodeAt(t+h))){o=!1;break}if(o)if(t+10<s&&(i.charCodeAt(t+10)===84||i.charCodeAt(t+10)===116)){let h=t;for(t+=11;t<s;){let l=i.charCodeAt(t);if(p(l)||l===58)t++;else break}if(t<s&&i.charCodeAt(t)===46)for(t++;t<s&&p(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&&p(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 E=i.charCodeAt(t);if(p(E)||E===58)t++;else break}}e.push({kind:149,text:i.substring(h,t),start:h});continue}else{let h=t;t+=10,e.push({kind:150,text:i.substring(h,t),start:h});continue}}let a=t;for(;t<s&&p(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&p(i.charCodeAt(t+1))){for(t++;t<s&&p(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(p(a)){let o=t;for(t++;t<s&&p(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&p(i.charCodeAt(t+1))){for(t++;t<s&&p(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&&p(i.charCodeAt(t+2))){let o=t;for(t+=2;t<s&&p(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&&p(i.charCodeAt(t+1))){let a=t;for(t++;t<s&&p(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 E=i.charCodeAt(t);if(V(E)||E===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 h=o.toUpperCase();if(h==="ORDER"&&!o.includes(".")){let E=H(i,t,"BY");if(E!==-1){let u=i.substring(a,E);e.push({kind:21,text:u,start:a}),t=E;continue}}if(h==="GROUP"&&!o.includes(".")){let E=H(i,t,"BY");if(E!==-1){let u=i.substring(a,E);e.push({kind:10,text:u,start:a}),t=E;continue}}if(h==="DATA"&&!o.includes(".")){let E=H(i,t,"CATEGORY");if(E!==-1){let u=i.substring(a,E);e.push({kind:35,text:u,start:a}),t=E;continue}}if(o.length>=4){let E=o.substring(0,3);if(J(E)){let u=o.substring(3);if(xe(u)){u.includes(".")?e.push({kind:151,text:o,start:a}):e.push({kind:152,text:o,start:a});continue}}}if(o.length===3&&J(o)){let E=t,u=t,R=!1;if(u<s&&i.charCodeAt(u)===45&&(R=!0,u++),R&&u<s&&p(i.charCodeAt(u))){for(;u<s&&p(i.charCodeAt(u));)u++;if(u<s&&i.charCodeAt(u)===46&&u+1<s&&p(i.charCodeAt(u+1))){for(u++;u<s&&p(i.charCodeAt(u));)u++;let A=i.substring(a,u);e.push({kind:151,text:A,start:a}),t=u;continue}if(u>=s||!V(i.charCodeAt(u))&&i.charCodeAt(u)!==46){let A=i.substring(a,u);e.push({kind:152,text:A,start:a}),t=u;continue}t=E}}if(o.includes(".")){e.push({kind:159,text:o,start:a});continue}let l=ye.get(h);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 h=0;h<a;h++){let l=i.charCodeAt(n+h),E=s.charCodeAt(h);if((l>=97&&l<=122?l-32:l)!==E)return-1}let o=n+a;if(o<t){let h=i.charCodeAt(o);if(V(h)||h===46)return-1}return o}function J(i){for(let e=0;e<i.length;e++)if(!q(i.charCodeAt(e)))return!1;return!0}function xe(i){if(i.length===0)return!1;let e=0;if(i.charCodeAt(e)===45&&e++,e>=i.length||!p(i.charCodeAt(e)))return!1;for(;e<i.length&&p(i.charCodeAt(e));)e++;if(e<i.length&&i.charCodeAt(e)===46){if(e++,e>=i.length||!p(i.charCodeAt(e)))return!1;for(;e<i.length&&p(i.charCodeAt(e));)e++}return e===i.length}var De=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(g(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)||De.has(e.kind)||e.kind===37&&this.peekAt(1).kind===156)}getLiteralType(e){let s=d(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=d(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=d(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(te(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 h={},l=h,E=null;for(;this.hasNegationPrefix();){let A=0;for(;this.check(138)&&this.isNegationAhead();)this.advance(),A++,a.left++;if(this.check(17)){this.advance();let _={left:A>0?{openParen:A}:null,operator:"NOT",right:{left:{}}};E?E.right=_:h=_,E=_,l=_.right}else break}l.left=this.parseExpression(e,s,a),t?o&&(n.operator=o,n.right=h):(t=h,n=h);let u=h;for(;u.right&&u.right.left!==void 0;){let A=u.right;if(A.right&&A.right.left!==void 0)u=A;else{u=A;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):g(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 h=this.parseOperator(),l=h.operator,E=h.isSet,u,R,A;if(E)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,A=S.dateLiteralVariable}else{let S=this.parseAtomicValue();u=S.value,R=S.literalType,A=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,A!==void 0&&(C.dateLiteralVariable=A),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(ie(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:d(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 h={values:s,literalType:o};return a&&(h.dateLiteralVariable=n),h}tokenKindFromTypeName(e){for(let s=0;s<=160;s++)if(d(s)===e)return s;return 159}parseArrayItem(){let e=this.peek();if(e.kind===157)return{value:this.advance().text,type:d(157)};if(e.kind===158)return{value:this.advance().text,type:d(158)};if(e.kind===151)return{value:this.advance().text,type:d(151)};if(e.kind===152)return{value:this.advance().text,type:d(152)};if(j(e.kind)){let s=this.advance();return{value:s.text,type:d(s.kind)}}if(e.kind===149)return{value:this.advance().text,type:d(149)};if(e.kind===150)return{value:this.advance().text,type:d(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:d(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:d(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(g(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=d(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=d(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(ee(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=d(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")}:g(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:d(n.kind),parameters:a,rawValue:`${n.text}(${a.join(", ")})`}}}else m(e.kind)&&s.kind===138?t={fn:this.parseAggregateFunction(!1)}:g(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=d(this.advance().kind):this.check(3)&&(t.order=d(this.advance().kind)),this.check(19))if(this.advance(),this.check(8))t.nulls=d(this.advance().kind);else if(this.check(14))t.nulls=d(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=re(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 se(i,e){try{return D(i,e),!0}catch{return!1}}function f(i){return typeof i=="string"}function be(i){return i?i.every(e=>f(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 ne(i,e=!1){return Array.isArray(i)?i.length>0?`(${i.join(", ")})`:e?"()":"":e?`(${i||""})`:i||""}function ae(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?[]:be(i.parameters)?i.parameters:f(i.parameters[0])?[i.parameters[0]]:z(i.parameters[0])}function oe(i){if(!i.parameters||i.parameters.length===0)return!1;let e=i.parameters[0];return f(e)?!1:!!e.isAggregateFn}function b(i){return i&&!N(i.alias)}function le(i){return f(i.field)&&!Array.isArray(i.relationships)&&!Array.isArray(i.conditions)}function ue(i){return!N(i.functionName||i.fn)}function Ee(i){return f(i.field)&&Array.isArray(i.relationships)}function he(i){return!N(i.subquery)}function pe(i){return f(i.field)&&Array.isArray(i.conditions)}function F(i){return f(i.relationshipName)}function Z(i){return!!i&&!!i.type&&i.type==="FieldSubquery"}function ce(i){return!!i&&!!i.operator&&!!i.right}function fe(i){return!!i&&!!i.operator&&!!i.right}function P(i){return!!i&&!!i.operator&&!!i.right}function Ae(i){return i&&f(i.field)&&f(i.operator)&&!N(i.value)}function de(i){return i&&f(i.field)&&f(i.operator)&&!N(i.value)&&(i.literalType==="DATE_LITERAL"||Array.isArray(i.literalType)&&i.literalType[0]==="DATE_LITERAL")}function Ne(i){return i&&f(i.field)&&f(i.operator)&&!N(i.value)&&!N(i.dateLiteralVariable)}function v(i){return i&&!N(i.fn)&&f(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&&f(i.field)&&f(i.operator)&&!N(i.valueQuery)&&N(i.value)}function w(i){return i&&!N(i.field)}function Re(i){return i&&!N(i.fn)}function U(i){return i&&!N(i.field)}function Te(i){return i&&!N(i.fn)}function Ue(i){return["IN","NOT IN","INCLUDES","EXCLUDES"].includes(i)}function Ce(i,e,s){if(N(e))return i;if(s&&e!=="APEX_BIND_VARIABLE"&&Ue(s)&&!Array.isArray(i)&&(i=[i],e=Array.isArray(e)?e:[e]),Array.isArray(e)&&Array.isArray(i))return i.map((t,n)=>ke(t,e?.[n]));switch(Array.isArray(e)&&(e=e[0]),e){case"STRING":return Array.isArray(i)?i.filter(Boolean).map(t=>f(t)&&t.startsWith("'")?t:`'${t??""}'`):(i=String(i??""),f(i)&&i.startsWith("'")?i:`'${i??""}'`);case"APEX_BIND_VARIABLE":return`:${i}`;default:return i}}function ke(i,e){switch(e){case"STRING":return f(i)&&i.startsWith("'")?i:`'${i??""}'`;case"NULL":return"null";default:return i}}function Me(i){return _e(i)}function _e(i){if(typeof i=="string")return{type:"Field",field:i};if(ue(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(Ee(i))return{type:"FieldRelationship",field:i.field,relationships:i.relationships,objectPrefix:i.objectPrefix};if(he(i))return{type:"FieldSubquery",subquery:i.subquery};if(pe(i))return{type:"FieldTypeof",field:i.field,conditions:i.conditions};if(le(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 Pe(i,e){if(!i)return[];i=Z(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,E)=>(U(E)&&(l[E.field.toLocaleLowerCase()]=E.field),l),{}));let n=-1,a=(F(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 E=z(l);if(E=E.map(u=>{if(u.includes(".")){let R=u.split("."),A=R[0].toLowerCase();return(A===o||A===a)&&(R=R.slice(1)),R.join(".")}return u}),l.alias&&(l.isAggregateFn||e))return l.alias;if(l.alias){let u=E[0];return u.includes(".")?(E=u.split(".").slice(0,-1),E.push(l.alias),E.join(".")):l.alias}return l.isAggregateFn||oe(l)||e?(n++,`expr${n}`):E.length>0?E.join("."):l.functionName}case"FieldRelationship":{let E=l.relationships[0].toLowerCase();return b(l)?l.alias:l.rawValue&&t[l.rawValue.toLocaleLowerCase()]?l.field:E===o||E===a?l.relationships.concat([l.field]).slice(1).join("."):l.relationships.concat([l.field]).join(".")}case"FieldSubquery":return l.subquery.relationshipName;case"FieldTypeof":{let E=new Set,u=[];return l.conditions.forEach(R=>{R.fieldList.forEach(A=>{E.has(A)||(E.add(A),u.push(`${l.field}.${A}`))})}),u}default:break}}).filter(l=>f(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=`
1
+ /*!
2
+ * @jetstreamapp/soql-parser-js v7.2.1
3
+ * https://github.com/jetstreamapp/soql-parser-js
4
+ * @license MIT
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]]),c=[];(function(){for(let e of Object.keys(T)){let s=T[e];typeof s=="number"&&(c[s]=e)}c[72]="toLabel",c[73]="convertTimezone",c[74]="convertCurrency",c[157]="StringIdentifier",c[150]="DATE",c[32]="new",c[125]="MineAndMyGroups",c[127]="MyTerritory",c[128]="MyTeamTerritory",c[130]="AllPrivate",c[123]="Delegated",c[124]="Everything",c[126]="Mine",c[129]="Team",c[131]="Mru",c[159]="Identifier",c[132]="EQUAL",c[156]="UNSIGNED_INTEGER",c[155]="SIGNED_INTEGER",c[154]="UNSIGNED_DECIMAL",c[153]="SIGNED_DECIMAL",c[151]="CURRENCY_PREFIXED_DECIMAL",c[152]="CURRENCY_PREFIXED_INTEGER"})();function A(i){return c[i]||T[i]}function q(i){return i>=65&&i<=90||i>=97&&i<=122}function p(i){return i>=48&&i<=57}function V(i){return q(i)||p(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===39){let a=t;for(t++;t<s;){let E=i.charCodeAt(t);if(E===92){t+=2;continue}if(E===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(p(n)){if(t+9<s&&i.charCodeAt(t+4)===45&&i.charCodeAt(t+7)===45){let o=!0;for(let h of[0,1,2,3,5,6,8,9])if(!p(i.charCodeAt(t+h))){o=!1;break}if(o)if(t+10<s&&(i.charCodeAt(t+10)===84||i.charCodeAt(t+10)===116)){let h=t;for(t+=11;t<s;){let l=i.charCodeAt(t);if(p(l)||l===58)t++;else break}if(t<s&&i.charCodeAt(t)===46)for(t++;t<s&&p(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&&p(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 E=i.charCodeAt(t);if(p(E)||E===58)t++;else break}}e.push({kind:149,text:i.substring(h,t),start:h});continue}else{let h=t;t+=10,e.push({kind:150,text:i.substring(h,t),start:h});continue}}let a=t;for(;t<s&&p(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&p(i.charCodeAt(t+1))){for(t++;t<s&&p(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(p(a)){let o=t;for(t++;t<s&&p(i.charCodeAt(t));)t++;if(t<s&&i.charCodeAt(t)===46&&t+1<s&&p(i.charCodeAt(t+1))){for(t++;t<s&&p(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&&p(i.charCodeAt(t+2))){let o=t;for(t+=2;t<s&&p(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&&p(i.charCodeAt(t+1))){let a=t;for(t++;t<s&&p(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 E=i.charCodeAt(t);if(V(E)||E===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 h=o.toUpperCase();if(h==="ORDER"&&!o.includes(".")){let E=H(i,t,"BY");if(E!==-1){let u=i.substring(a,E);e.push({kind:21,text:u,start:a}),t=E;continue}}if(h==="GROUP"&&!o.includes(".")){let E=H(i,t,"BY");if(E!==-1){let u=i.substring(a,E);e.push({kind:10,text:u,start:a}),t=E;continue}}if(h==="DATA"&&!o.includes(".")){let E=H(i,t,"CATEGORY");if(E!==-1){let u=i.substring(a,E);e.push({kind:35,text:u,start:a}),t=E;continue}}if(o.length>=4){let E=o.substring(0,3);if(ee(E)){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 E=t,u=t,R=!1;if(u<s&&i.charCodeAt(u)===45&&(R=!0,u++),R&&u<s&&p(i.charCodeAt(u))){for(;u<s&&p(i.charCodeAt(u));)u++;if(u<s&&i.charCodeAt(u)===46&&u+1<s&&p(i.charCodeAt(u+1))){for(u++;u<s&&p(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=E}}if(o.includes(".")){e.push({kind:159,text:o,start:a});continue}let l=xe.get(h);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 h=0;h<a;h++){let l=i.charCodeAt(n+h),E=s.charCodeAt(h);if((l>=97&&l<=122?l-32:l)!==E)return-1}let o=n+a;if(o<t){let h=i.charCodeAt(o);if(V(h)||h===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||!p(i.charCodeAt(e)))return!1;for(;e<i.length&&p(i.charCodeAt(e));)e++;if(e<i.length&&i.charCodeAt(e)===46){if(e++,e>=i.length||!p(i.charCodeAt(e)))return!1;for(;e<i.length&&p(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 h={},l=h,E=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:{}}};E?E.right=_:h=_,E=_,l=_.right}else break}l.left=this.parseExpression(e,s,a),t?o&&(n.operator=o,n.right=h):(t=h,n=h);let u=h;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 h=this.parseOperator(),l=h.operator,E=h.isSet,u,R,f;if(E)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 h={values:s,literalType:o};return a&&(h.dateLiteralVariable=n),h}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 pe(i){return!N(i.subquery)}function ce(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(pe(i))return{type:"FieldSubquery",subquery:i.subquery};if(ce(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,E)=>(U(E)&&(l[E.field.toLocaleLowerCase()]=E.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 E=Z(l);if(E=E.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=E[0];return u.includes(".")?(E=u.split(".").slice(0,-1),E.push(l.alias),E.join(".")):l.alias}return l.isAggregateFn||le(l)||e?(n++,`expr${n}`):E.length>0?E.join("."):l.functionName}case"FieldRelationship":{let E=l.relationships[0].toLowerCase();return b(l)?l.alias:l.rawValue&&t[l.rawValue.toLocaleLowerCase()]?l.field:E===o||E===a?l.relationships.concat([l.field]).slice(1).join("."):l.relationships.concat([l.field]).join(".")}case"FieldSubquery":return l.subquery.relationshipName;case"FieldTypeof":{let E=new Set,u=[];return l.conditions.forEach(R=>{R.fieldList.forEach(f=>{E.has(f)||(E.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=`
2
7
  ${this.getIndent()}`,a.suffix=e.fields.length-1===o?"":", ",t=0,n=!0):Array.isArray(a.typeOfClause)?(s(o),a.prefix=`
3
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+=`
4
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(`
@@ -18,6 +23,6 @@ ${e}`:` ${e}`}formatText(e){return this.enabled&&(this.options.newLineAfterKeywo
18
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+=`(
19
24
  `:(this.currIndent++,n+=`${this.getIndent()}(
20
25
  `);(!t||e>1)&&this.currIndent++}else for(let a=e-1;a>=0;a--)t&&a===e-1?n+=")":(this.currIndent--,n+=`
21
- ${this.getIndent()})`);else n+=ae(e,s);return n}formatWhereClauseOperators(e,s,t=0){let n=e==="NOT";return this.enabled&&!n?`
26
+ ${this.getIndent()})`);else n+=oe(e,s);return n}formatWhereClauseOperators(e,s,t=0){let n=e==="NOT";return this.enabled&&!n?`
22
27
  ${this.getIndent(t)}${e} ${s}`:`${n?"":" "}${e} ${s}`}formatAddNewLine(e=" ",s){return this.enabled&&!s?`
23
- `:e}};function ve(i,e,s){return Se(D(i,s),{format:!0,formatOptions:e})}function Se(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=>f(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:F(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),(F(e)?e.relationshipName:e.sObject)&&(t+=this.formatter.formatClause("FROM")),F(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(h=>f(h)?h:this.parseFields([h]).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 h="";h+=v(a)?this.parseFn(a.fn):a.field,h+=` ${a.operator} `,Y(a)?h+=this.formatter.formatSubquery(this.parseQuery(a.valueQuery),1,!0):h+=ne(Ce(a.value,a.literalType,a.operator)),n+=this.formatter.formatWithIndent(h),n+=this.formatter.formatParens(a.closeParen,")",t)}if(P(e)){let h=O(e.operator);o=h==="NOT";let l=this.formatter.formatWhereClauseOperators(h,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 ")}};
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(h=>d(h)?h:this.parseFields([h]).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 h="";h+=v(a)?this.parseFn(a.fn):a.field,h+=` ${a.operator} `,Y(a)?h+=this.formatter.formatSubquery(this.parseQuery(a.valueQuery),1,!0):h+=ae(_e(a.value,a.literalType,a.operator)),n+=this.formatter.formatWithIndent(h),n+=this.formatter.formatParens(a.closeParen,")",t)}if(P(e)){let h=O(e.operator);o=h==="NOT";let l=this.formatter.formatWhereClauseOperators(h,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 ")}};