@jetstreamapp/soql-parser-js 7.1.1 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +51 -27
- package/dist/cjs/index.js +5 -0
- package/dist/cli/index.js +5 -0
- package/dist/esm/index.mjs +5 -0
- package/dist/lwc/soqlParserJs.js +28 -0
- package/package.json +13 -7
- package/dist/lwc/index.js +0 -2975
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.2.0
|
|
4
|
+
|
|
5
|
+
May 11, 2026
|
|
6
|
+
|
|
7
|
+
### LWC Distribution
|
|
8
|
+
|
|
9
|
+
The LWC build now produces two artifacts to support different deployment workflows:
|
|
10
|
+
|
|
11
|
+
- **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.
|
|
12
|
+
- **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.
|
|
13
|
+
- **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`.
|
|
14
|
+
- **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.
|
|
15
|
+
- **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.
|
|
16
|
+
|
|
17
|
+
### Release Pipeline
|
|
18
|
+
|
|
19
|
+
- **npm tarball attached to GitHub Releases** — every release now attaches `jetstreamapp-soql-parser-js-<version>.tgz`.
|
|
20
|
+
- **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.
|
|
21
|
+
|
|
3
22
|
## 7.1.1
|
|
4
23
|
|
|
5
24
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
522
|
+
### Option 1: SFDX project — drop in the standalone JS file
|
|
520
523
|
|
|
521
|
-
|
|
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
|
-
|
|
526
|
+
Sources for the standalone JS:
|
|
524
527
|
|
|
525
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
550
|
+
### Option 2: Direct deployment — use the pre-built metadata package
|
|
543
551
|
|
|
544
|
-
|
|
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
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
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/
|
|
578
|
+
import { parseQuery } from 'c/soqlParserJs';
|
|
557
579
|
|
|
558
|
-
export default class
|
|
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=
|
|
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,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @jetstreamapp/soql-parser-js v7.2.0
|
|
3
|
+
* https://github.com/jetstreamapp/soql-parser-js
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
"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=`
|
|
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+=`
|
package/dist/cli/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @jetstreamapp/soql-parser-js v7.2.0
|
|
3
|
+
* https://github.com/jetstreamapp/soql-parser-js
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
"use strict";var R=(i=>(i[i.AND=0]="AND",i[i.AS=1]="AS",i[i.ASC=2]="ASC",i[i.DESC=3]="DESC",i[i.CUBE=4]="CUBE",i[i.ELSE=5]="ELSE",i[i.EXCLUDES=6]="EXCLUDES",i[i.FALSE=7]="FALSE",i[i.FIRST=8]="FIRST",i[i.FROM=9]="FROM",i[i.GROUP_BY=10]="GROUP_BY",i[i.HAVING=11]="HAVING",i[i.IN=12]="IN",i[i.INCLUDES=13]="INCLUDES",i[i.LAST=14]="LAST",i[i.LIKE=15]="LIKE",i[i.LIMIT=16]="LIMIT",i[i.NOT=17]="NOT",i[i.NULL=18]="NULL",i[i.NULLS=19]="NULLS",i[i.OR=20]="OR",i[i.ORDER_BY=21]="ORDER_BY",i[i.ROLLUP=22]="ROLLUP",i[i.SELECT=23]="SELECT",i[i.TRUE=24]="TRUE",i[i.USING=25]="USING",i[i.WHERE=26]="WHERE",i[i.WITH=27]="WITH",i[i.FOR=28]="FOR",i[i.UPDATE=29]="UPDATE",i[i.ABOVE=30]="ABOVE",i[i.ABOVE_OR_BELOW=31]="ABOVE_OR_BELOW",i[i.APEX_NEW=32]="APEX_NEW",i[i.AT=33]="AT",i[i.BELOW=34]="BELOW",i[i.DATA_CATEGORY=35]="DATA_CATEGORY",i[i.END=36]="END",i[i.OFFSET=37]="OFFSET",i[i.REFERENCE=38]="REFERENCE",i[i.SCOPE=39]="SCOPE",i[i.TRACKING=40]="TRACKING",i[i.THEN=41]="THEN",i[i.TYPEOF=42]="TYPEOF",i[i.VIEW=43]="VIEW",i[i.VIEWSTAT=44]="VIEWSTAT",i[i.WHEN=45]="WHEN",i[i.SECURITY_ENFORCED=46]="SECURITY_ENFORCED",i[i.SYSTEM_MODE=47]="SYSTEM_MODE",i[i.USER_MODE=48]="USER_MODE",i[i.CALENDAR_MONTH=49]="CALENDAR_MONTH",i[i.CALENDAR_QUARTER=50]="CALENDAR_QUARTER",i[i.CALENDAR_YEAR=51]="CALENDAR_YEAR",i[i.DAY_IN_MONTH=52]="DAY_IN_MONTH",i[i.DAY_IN_WEEK=53]="DAY_IN_WEEK",i[i.DAY_IN_YEAR=54]="DAY_IN_YEAR",i[i.DAY_ONLY=55]="DAY_ONLY",i[i.FISCAL_MONTH=56]="FISCAL_MONTH",i[i.FISCAL_QUARTER=57]="FISCAL_QUARTER",i[i.FISCAL_YEAR=58]="FISCAL_YEAR",i[i.HOUR_IN_DAY=59]="HOUR_IN_DAY",i[i.WEEK_IN_MONTH=60]="WEEK_IN_MONTH",i[i.WEEK_IN_YEAR=61]="WEEK_IN_YEAR",i[i.AVG=62]="AVG",i[i.COUNT=63]="COUNT",i[i.COUNT_DISTINCT=64]="COUNT_DISTINCT",i[i.MIN=65]="MIN",i[i.MAX=66]="MAX",i[i.SUM=67]="SUM",i[i.DISTANCE=68]="DISTANCE",i[i.GEOLOCATION=69]="GEOLOCATION",i[i.FIELDS=70]="FIELDS",i[i.FORMAT=71]="FORMAT",i[i.TOLABEL=72]="TOLABEL",i[i.CONVERT_TIMEZONE=73]="CONVERT_TIMEZONE",i[i.CONVERT_CURRENCY=74]="CONVERT_CURRENCY",i[i.GROUPING=75]="GROUPING",i[i.ALL=76]="ALL",i[i.CUSTOM=77]="CUSTOM",i[i.STANDARD=78]="STANDARD",i[i.YESTERDAY=79]="YESTERDAY",i[i.TODAY=80]="TODAY",i[i.TOMORROW=81]="TOMORROW",i[i.LAST_WEEK=82]="LAST_WEEK",i[i.THIS_WEEK=83]="THIS_WEEK",i[i.NEXT_WEEK=84]="NEXT_WEEK",i[i.LAST_MONTH=85]="LAST_MONTH",i[i.THIS_MONTH=86]="THIS_MONTH",i[i.NEXT_MONTH=87]="NEXT_MONTH",i[i.LAST_90_DAYS=88]="LAST_90_DAYS",i[i.NEXT_90_DAYS=89]="NEXT_90_DAYS",i[i.THIS_QUARTER=90]="THIS_QUARTER",i[i.LAST_QUARTER=91]="LAST_QUARTER",i[i.NEXT_QUARTER=92]="NEXT_QUARTER",i[i.THIS_YEAR=93]="THIS_YEAR",i[i.LAST_YEAR=94]="LAST_YEAR",i[i.NEXT_YEAR=95]="NEXT_YEAR",i[i.THIS_FISCAL_QUARTER=96]="THIS_FISCAL_QUARTER",i[i.LAST_FISCAL_QUARTER=97]="LAST_FISCAL_QUARTER",i[i.NEXT_FISCAL_QUARTER=98]="NEXT_FISCAL_QUARTER",i[i.THIS_FISCAL_YEAR=99]="THIS_FISCAL_YEAR",i[i.LAST_FISCAL_YEAR=100]="LAST_FISCAL_YEAR",i[i.NEXT_FISCAL_YEAR=101]="NEXT_FISCAL_YEAR",i[i.NEXT_N_DAYS=102]="NEXT_N_DAYS",i[i.LAST_N_DAYS=103]="LAST_N_DAYS",i[i.N_DAYS_AGO=104]="N_DAYS_AGO",i[i.NEXT_N_WEEKS=105]="NEXT_N_WEEKS",i[i.LAST_N_WEEKS=106]="LAST_N_WEEKS",i[i.N_WEEKS_AGO=107]="N_WEEKS_AGO",i[i.NEXT_N_MONTHS=108]="NEXT_N_MONTHS",i[i.LAST_N_MONTHS=109]="LAST_N_MONTHS",i[i.N_MONTHS_AGO=110]="N_MONTHS_AGO",i[i.NEXT_N_QUARTERS=111]="NEXT_N_QUARTERS",i[i.LAST_N_QUARTERS=112]="LAST_N_QUARTERS",i[i.N_QUARTERS_AGO=113]="N_QUARTERS_AGO",i[i.NEXT_N_YEARS=114]="NEXT_N_YEARS",i[i.LAST_N_YEARS=115]="LAST_N_YEARS",i[i.N_YEARS_AGO=116]="N_YEARS_AGO",i[i.NEXT_N_FISCAL_QUARTERS=117]="NEXT_N_FISCAL_QUARTERS",i[i.LAST_N_FISCAL_QUARTERS=118]="LAST_N_FISCAL_QUARTERS",i[i.N_FISCAL_QUARTERS_AGO=119]="N_FISCAL_QUARTERS_AGO",i[i.NEXT_N_FISCAL_YEARS=120]="NEXT_N_FISCAL_YEARS",i[i.LAST_N_FISCAL_YEARS=121]="LAST_N_FISCAL_YEARS",i[i.N_FISCAL_YEARS_AGO=122]="N_FISCAL_YEARS_AGO",i[i.DELEGATED=123]="DELEGATED",i[i.EVERYTHING=124]="EVERYTHING",i[i.MINE_AND_MY_GROUPS=125]="MINE_AND_MY_GROUPS",i[i.MINE=126]="MINE",i[i.MY_TERRITORY=127]="MY_TERRITORY",i[i.MY_TEAM_TERRITORY=128]="MY_TEAM_TERRITORY",i[i.TEAM=129]="TEAM",i[i.ALL_PRIVATE=130]="ALL_PRIVATE",i[i.MRU=131]="MRU",i[i.EQUAL=132]="EQUAL",i[i.NOT_EQUAL=133]="NOT_EQUAL",i[i.LESS_THAN=134]="LESS_THAN",i[i.LESS_THAN_OR_EQUAL=135]="LESS_THAN_OR_EQUAL",i[i.GREATER_THAN=136]="GREATER_THAN",i[i.GREATER_THAN_OR_EQUAL=137]="GREATER_THAN_OR_EQUAL",i[i.L_PAREN=138]="L_PAREN",i[i.R_PAREN=139]="R_PAREN",i[i.L_SQUARE_BRACKET=140]="L_SQUARE_BRACKET",i[i.R_SQUARE_BRACKET=141]="R_SQUARE_BRACKET",i[i.DOT=142]="DOT",i[i.COMMA=143]="COMMA",i[i.COLON=144]="COLON",i[i.SEMICOLON=145]="SEMICOLON",i[i.ASTERISK=146]="ASTERISK",i[i.PLUS=147]="PLUS",i[i.MINUS=148]="MINUS",i[i.DATETIME=149]="DATETIME",i[i.DATE_TOKEN=150]="DATE_TOKEN",i[i.CURRENCY_PREFIXED_DECIMAL=151]="CURRENCY_PREFIXED_DECIMAL",i[i.CURRENCY_PREFIXED_INTEGER=152]="CURRENCY_PREFIXED_INTEGER",i[i.SIGNED_DECIMAL=153]="SIGNED_DECIMAL",i[i.UNSIGNED_DECIMAL=154]="UNSIGNED_DECIMAL",i[i.SIGNED_INTEGER=155]="SIGNED_INTEGER",i[i.UNSIGNED_INTEGER=156]="UNSIGNED_INTEGER",i[i.STRING_LITERAL=157]="STRING_LITERAL",i[i.GEOLOCATION_UNIT=158]="GEOLOCATION_UNIT",i[i.IDENTIFIER=159]="IDENTIFIER",i[i.EOF=160]="EOF",i))(R||{});function y(s){return s>=49&&s<=61}function F(s){return s>=62&&s<=67}function B(s){return s>=68&&s<=69}function H(s){return s===70}function b(s){return s>=71&&s<=75}function se(s){return s>=76&&s<=78}function M(s){return s>=79&&s<=101}function P(s){return s>=102&&s<=122}function ne(s){return s>=123&&s<=131}function g(s){return s===159||s>=30&&s<=48||s>=49&&s<=61||s>=62&&s<=67||s>=68&&s<=69||s===70||s>=71&&s<=75||s>=76&&s<=78||s>=79&&s<=101||s>=102&&s<=122||s>=123&&s<=131||s===158||s===152}function Q(s){return s===153||s===154||s===155||s===156}function ae(s){return s>=132&&s<=137}var he=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]]),h=[];(function(){for(let e of Object.keys(R)){let r=R[e];typeof r=="number"&&(h[r]=e)}h[72]="toLabel",h[73]="convertTimezone",h[74]="convertCurrency",h[157]="StringIdentifier",h[150]="DATE",h[32]="new",h[125]="MineAndMyGroups",h[127]="MyTerritory",h[128]="MyTeamTerritory",h[130]="AllPrivate",h[123]="Delegated",h[124]="Everything",h[126]="Mine",h[129]="Team",h[131]="Mru",h[159]="Identifier",h[132]="EQUAL",h[156]="UNSIGNED_INTEGER",h[155]="SIGNED_INTEGER",h[154]="UNSIGNED_DECIMAL",h[153]="SIGNED_DECIMAL",h[151]="CURRENCY_PREFIXED_DECIMAL",h[152]="CURRENCY_PREFIXED_INTEGER"})();function f(s){return h[s]||R[s]}function V(s){return s>=65&&s<=90||s>=97&&s<=122}function c(s){return s>=48&&s<=57}function W(s){return V(s)||c(s)||s===95}function G(s){return s===32||s===9||s===10||s===13||s===12}function oe(s){let e=[],r=s.length,t=0;for(;t<r;){let n=s.charCodeAt(t);if(G(n)){for(t++;t<r&&G(s.charCodeAt(t));)t++;continue}if(n===39){let a=t;for(t++;t<r;){let p=s.charCodeAt(t);if(p===92){t+=2;continue}if(p===39){t++;break}t++}let o=s.substring(a,t),u=o.substring(1,o.length-1).toUpperCase();u==="MI"||u==="KM"?e.push({kind:158,text:o,start:a}):e.push({kind:157,text:o,start:a});continue}if(c(n)){if(t+9<r&&s.charCodeAt(t+4)===45&&s.charCodeAt(t+7)===45){let o=!0;for(let l of[0,1,2,3,5,6,8,9])if(!c(s.charCodeAt(t+l))){o=!1;break}if(o)if(t+10<r&&(s.charCodeAt(t+10)===84||s.charCodeAt(t+10)===116)){let l=t;for(t+=11;t<r;){let u=s.charCodeAt(t);if(c(u)||u===58)t++;else break}if(t<r&&s.charCodeAt(t)===46)for(t++;t<r&&c(s.charCodeAt(t));)t++;if(t<r){let u=s.charCodeAt(t);if(u===90||u===122)t++;else if(u===46){for(t++;t<r&&c(s.charCodeAt(t));)t++;t<r&&(s.charCodeAt(t)===90||s.charCodeAt(t)===122)&&t++}else if(u===43||u===45)for(t++;t<r;){let p=s.charCodeAt(t);if(c(p)||p===58)t++;else break}}e.push({kind:149,text:s.substring(l,t),start:l});continue}else{let l=t;t+=10,e.push({kind:150,text:s.substring(l,t),start:l});continue}}let a=t;for(;t<r&&c(s.charCodeAt(t));)t++;if(t<r&&s.charCodeAt(t)===46&&t+1<r&&c(s.charCodeAt(t+1))){for(t++;t<r&&c(s.charCodeAt(t));)t++;e.push({kind:154,text:s.substring(a,t),start:a});continue}e.push({kind:156,text:s.substring(a,t),start:a});continue}if(n===33){if(t+1<r&&s.charCodeAt(t+1)===61){e.push({kind:133,text:"!=",start:t}),t+=2;continue}throw new Error(`Unexpected character '!' at position ${t}`)}if(n===60){if(t+1<r){let a=s.charCodeAt(t+1);if(a===61){e.push({kind:135,text:"<=",start:t}),t+=2;continue}if(a===62){e.push({kind:133,text:"<>",start:t}),t+=2;continue}}e.push({kind:134,text:"<",start:t}),t++;continue}if(n===62){if(t+1<r&&s.charCodeAt(t+1)===61){e.push({kind:137,text:">=",start:t}),t+=2;continue}e.push({kind:136,text:">",start:t}),t++;continue}if(n===61){e.push({kind:132,text:"=",start:t}),t++;continue}if(n===40){e.push({kind:138,text:"(",start:t}),t++;continue}if(n===41){e.push({kind:139,text:")",start:t}),t++;continue}if(n===91){e.push({kind:140,text:"[",start:t}),t++;continue}if(n===93){e.push({kind:141,text:"]",start:t}),t++;continue}if(n===44){e.push({kind:143,text:",",start:t}),t++;continue}if(n===58){e.push({kind:144,text:":",start:t}),t++;continue}if(n===59){e.push({kind:145,text:";",start:t}),t++;continue}if(n===42){e.push({kind:146,text:"*",start:t}),t++;continue}if(n===43||n===45){if(t+1<r){let a=s.charCodeAt(t+1);if(c(a)){let o=t;for(t++;t<r&&c(s.charCodeAt(t));)t++;if(t<r&&s.charCodeAt(t)===46&&t+1<r&&c(s.charCodeAt(t+1))){for(t++;t<r&&c(s.charCodeAt(t));)t++;e.push({kind:153,text:s.substring(o,t),start:o});continue}e.push({kind:155,text:s.substring(o,t),start:o});continue}if(a===46&&t+2<r&&c(s.charCodeAt(t+2))){let o=t;for(t+=2;t<r&&c(s.charCodeAt(t));)t++;e.push({kind:153,text:s.substring(o,t),start:o});continue}}e.push({kind:n===43?147:148,text:s[t],start:t}),t++;continue}if(n===46){if(t+1<r&&c(s.charCodeAt(t+1))){let a=t;for(t++;t<r&&c(s.charCodeAt(t));)t++;e.push({kind:154,text:s.substring(a,t),start:a});continue}e.push({kind:142,text:".",start:t}),t++;continue}if(V(n)){let a=t;for(t++;t<r;){let p=s.charCodeAt(t);if(W(p)||p===46)t++;else break}let o=s.substring(a,t);if(o.includes(".."))throw new Error(`Invalid identifier with consecutive dots at position ${a}: "${o}"`);let l=o.toUpperCase();if(l==="ORDER"&&!o.includes(".")){let p=$(s,t,"BY");if(p!==-1){let E=s.substring(a,p);e.push({kind:21,text:E,start:a}),t=p;continue}}if(l==="GROUP"&&!o.includes(".")){let p=$(s,t,"BY");if(p!==-1){let E=s.substring(a,p);e.push({kind:10,text:E,start:a}),t=p;continue}}if(l==="DATA"&&!o.includes(".")){let p=$(s,t,"CATEGORY");if(p!==-1){let E=s.substring(a,p);e.push({kind:35,text:E,start:a}),t=p;continue}}if(o.length>=4){let p=o.substring(0,3);if(re(p)){let E=o.substring(3);if(fe(E)){E.includes(".")?e.push({kind:151,text:o,start:a}):e.push({kind:152,text:o,start:a});continue}}}if(o.length===3&&re(o)){let p=t,E=t,C=!1;if(E<r&&s.charCodeAt(E)===45&&(C=!0,E++),C&&E<r&&c(s.charCodeAt(E))){for(;E<r&&c(s.charCodeAt(E));)E++;if(E<r&&s.charCodeAt(E)===46&&E+1<r&&c(s.charCodeAt(E+1))){for(E++;E<r&&c(s.charCodeAt(E));)E++;let d=s.substring(a,E);e.push({kind:151,text:d,start:a}),t=E;continue}if(E>=r||!W(s.charCodeAt(E))&&s.charCodeAt(E)!==46){let d=s.substring(a,E);e.push({kind:152,text:d,start:a}),t=E;continue}t=p}}if(o.includes(".")){e.push({kind:159,text:o,start:a});continue}let u=he.get(l);if(u!==void 0){e.push({kind:u,text:o,start:a});continue}e.push({kind:159,text:o,start:a});continue}throw new Error(`Unexpected character '${s[t]}' (code ${n}) at position ${t}`)}return e.push({kind:160,text:"",start:t}),e}function $(s,e,r){let t=s.length,n=e;if(n>=t||!G(s.charCodeAt(n)))return-1;for(;n<t&&G(s.charCodeAt(n));)n++;let a=r.length;if(n+a>t)return-1;for(let l=0;l<a;l++){let u=s.charCodeAt(n+l),p=r.charCodeAt(l);if((u>=97&&u<=122?u-32:u)!==p)return-1}let o=n+a;if(o<t){let l=s.charCodeAt(o);if(W(l)||l===46)return-1}return o}function re(s){for(let e=0;e<s.length;e++)if(!V(s.charCodeAt(e)))return!1;return!0}function fe(s){if(s.length===0)return!1;let e=0;if(s.charCodeAt(e)===45&&e++,e>=s.length||!c(s.charCodeAt(e)))return!1;for(;e<s.length&&c(s.charCodeAt(e));)e++;if(e<s.length&&s.charCodeAt(e)===46){if(e++,e>=s.length||!c(s.charCodeAt(e)))return!1;for(;e<s.length&&c(s.charCodeAt(e));)e++}return e===s.length}var Ae=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]),j=class s{constructor(e,r){this.pos=0;this.tokens=e,this.config=r}getPos(){return this.pos}peek(){return this.tokens[this.pos]}peekAt(e){let r=this.pos+e;return r>=this.tokens.length?this.tokens[this.tokens.length-1]:this.tokens[r]}advance(){let e=this.tokens[this.pos];return e.kind!==160&&this.pos++,e}expect(e){let r=this.peek();if(r.kind!==e)throw this.error(`Expected ${R[e]} but found ${R[r.kind]} ("${r.text}") at position ${r.start}`);return this.advance()}match(e){return this.peek().kind===e?(this.advance(),!0):!1}check(e){return this.peek().kind===e}isAtEnd(){return this.peek().kind===160}error(e){return this.config.logErrors&&console.log(e),new Error(e)}static{this.CLAUSE_BOUNDARY_KINDS=new Set([26,21,10,11,16,37,27,28,29,25,160])}isAtClauseBoundary(){let e=this.peek().kind;return s.CLAUSE_BOUNDARY_KINDS.has(e)||e===139}synchronize(){for(;!this.isAtEnd();){if(this.isAtClauseBoundary())return;this.advance()}}consumeIdentifier(){let e=this.peek();if(g(e.kind))return this.advance();throw this.error(`Expected identifier but found ${R[e.kind]} ("${e.text}") at position ${e.start}`)}checkIdentifier(){return g(this.peek().kind)}isFunctionCall(){let e=this.peek(),r=this.peekAt(1);return(y(e.kind)||F(e.kind)||B(e.kind)||H(e.kind)||b(e.kind))&&r.kind===138}canBeAlias(){let e=this.peek();return!(!g(e.kind)||Ae.has(e.kind)||e.kind===37&&this.peekAt(1).kind===156)}getLiteralType(e){let r=f(e);return r==="UNSIGNED_INTEGER"||r==="SIGNED_INTEGER"?"INTEGER":r==="UNSIGNED_DECIMAL"||r==="SIGNED_DECIMAL"?"DECIMAL":r==="CURRENCY_PREFIXED_DECIMAL"?"DECIMAL_WITH_CURRENCY_PREFIX":r==="CURRENCY_PREFIXED_INTEGER"?"INTEGER_WITH_CURRENCY_PREFIX":r==="DATETIME"?"DATETIME":r==="DATE"?"DATE":r==="NULL"?"NULL":r==="StringIdentifier"||r==="Identifier"?"STRING":r==="TRUE"||r==="FALSE"?"BOOLEAN":M(e)?"DATE_LITERAL":P(e)?"DATE_N_LITERAL":"STRING"}parseSelectStatement(e=!1){let r=this.parseSelectClause(),t=this.parseFromClause(),n;e?(n={fields:r,relationshipName:t.sObject},t.sObjectPrefix&&(n.sObjectPrefix=t.sObjectPrefix)):n={fields:r,sObject:t.sObject},t.alias&&(n.sObjectAlias=t.alias),this.applySObjectAlias(n);let a=this.parseClauseStatements();return Object.assign(n,a),n}parseSelectStatementPartial(){let e,r;this.check(23)&&(e=this.parseSelectClause()),this.check(9)&&(r=this.parseFromClause());let t={};e&&(t.fields=e),r&&(t.sObject=r.sObject,r.alias&&(t.sObjectAlias=r.alias)),t.fields&&this.applySObjectAlias(t);let n=this.parseClauseStatements();return Object.assign(t,n),t}applySObjectAlias(e){if(!e.sObjectAlias||!Array.isArray(e.fields))return;let r=e.sObjectAlias;e.fields.forEach(t=>{t.relationships&&t.relationships[0]===r&&(t.relationships=t.relationships.slice(1),t.objectPrefix=r,t.relationships.length===0&&(delete t.relationships,t.type="Field"))})}parseSelectClause(){this.expect(23);let e=[];for(e.push(this.parseSelectField());this.match(143);)e.push(this.parseSelectField());return e}parseSelectField(){let e=this.peek(),r=this.peekAt(1);return e.kind===138&&r.kind===23?this.parseSelectClauseSubqueryIdentifier():e.kind===42?this.parseSelectClauseTypeOf():this.isFunctionCall()?this.parseSelectClauseFunctionIdentifier():this.parseSelectClauseIdentifier()}parseSelectClauseFunctionIdentifier(){let e=this.parseAnyFunction(!0);return this.canBeAlias()&&(e.alias=this.consumeIdentifier().text),e}parseSelectClauseSubqueryIdentifier(){this.expect(138);let e=this.parseSelectStatement(!0);return this.expect(139),{type:"FieldSubquery",subquery:e}}parseSelectClauseTypeOf(){this.expect(42);let e=this.consumeIdentifier().text,r=[];for(;this.check(45);){this.advance();let t=this.consumeIdentifier().text;this.expect(41);let n=[];for(n.push(this.consumeIdentifier().text);this.match(143);)n.push(this.consumeIdentifier().text);r.push({type:"WHEN",objectType:t,fieldList:n})}if(this.check(5)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);r.push({type:"ELSE",fieldList:t})}return this.expect(36),{type:"FieldTypeof",field:e,conditions:r}}parseSelectClauseIdentifier(){let r=this.consumeIdentifier().text,t;if(!r.includes("."))t={type:"Field",field:r};else{let n=r.split(".");t={type:"FieldRelationship",field:n[n.length-1],relationships:n.slice(0,n.length-1),rawValue:r}}return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseFromClause(){this.expect(9);let r=this.consumeIdentifier().text,t;if(r.includes(".")){let n=r.split(".");t={sObjectPrefix:n.slice(0,n.length-1),sObject:n[n.length-1]}}else t={sObject:r};return this.canBeAlias()&&(t.alias=this.consumeIdentifier().text),t}parseClauseStatements(){let e={},r=(t,n)=>{if(this.config.ignoreParseErrors)try{t(),this.isAtClauseBoundary()||(n&&n(),this.synchronize())}catch(a){this.config.logErrors&&console.log(a),n&&n(),this.synchronize()}else t()};for(this.check(25)&&r(()=>{e.usingScope=this.parseUsingScope()}),this.check(26)&&r(()=>{e.where=this.parseWhereClause()},()=>{delete e.where});this.check(27);)r(()=>{let t=this.parseWithClause();t.withSecurityEnforced&&(e.withSecurityEnforced=!0),t.withAccessLevel&&(e.withAccessLevel=t.withAccessLevel),t.withDataCategory&&(e.withDataCategory=t.withDataCategory)});return this.check(10)&&(r(()=>{e.groupBy=this.parseGroupByClause()}),this.check(11)&&r(()=>{e.having=this.parseHavingClause()})),this.check(21)&&r(()=>{e.orderBy=this.parseOrderByClause()}),this.check(16)&&r(()=>{this.advance(),e.limit=Number(this.expect(156).text)}),this.check(37)&&r(()=>{this.advance(),e.offset=Number(this.expect(156).text)}),this.check(28)&&r(()=>{this.advance();let t=this.peek();if(t.kind===43||t.kind===38||t.kind===29)e.for=f(this.advance().kind);else throw this.error(`Expected VIEW, REFERENCE, or UPDATE after FOR at position ${t.start}`)}),this.check(29)&&r(()=>{this.advance();let t=this.peek();if(t.kind===40||t.kind===44)e.update=f(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(ne(e.kind))return this.advance().text;if(g(e.kind))return this.advance().text;throw this.error(`Expected scope enumeration value at position ${e.start}`)}parseWhereClause(){return this.expect(26),this.parseConditionExpressions(!0,!0)}parseConditionExpressions(e,r){let t,n,a={left:0,right:0};for(;;){let o;if(t)if(this.check(0))o="AND",this.advance();else if(this.check(20))o="OR",this.advance();else break;let l={},u=l,p=null;for(;this.hasNegationPrefix();){let d=0;for(;this.check(138)&&this.isNegationAhead();)this.advance(),d++,a.left++;if(this.check(17)){this.advance();let I={left:d>0?{openParen:d}:null,operator:"NOT",right:{left:{}}};p?p.right=I:l=I,p=I,u=I.right}else break}u.left=this.parseExpression(e,r,a),t?o&&(n.operator=o,n.right=l):(t=l,n=l);let E=l;for(;E.right&&E.right.left!==void 0;){let d=E.right;if(d.right&&d.right.left!==void 0)E=d;else{E=d;break}}if(n=E,this.isAtEnd())break;let C=this.peek().kind;if(C!==0&&C!==20)break}if(a.left!==a.right)throw this.error(`Mismatched parentheses in WHERE/HAVING clause: ${a.left} open vs ${a.right} close`);return t}hasNegationPrefix(){let e=0;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}isNegationAhead(){let e=1;for(;this.peekAt(e).kind===138;)e++;return this.peekAt(e).kind===17}parseExpression(e,r,t){let n=0;for(;this.check(138)&&!this.isSubqueryStart()&&!this.isArrayExpressionStart();)this.advance(),n++,t&&t.left++;let a,o=!1;e&&F(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseAggregateFunction(!1),o=!0):r&&B(this.peek().kind)&&this.peek().kind===68&&this.peekAt(1).kind===138?(a=this.parseLocationFunction(!1),o=!0):y(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseDateFunction(!1),o=!0):b(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseOtherFunction(!1),o=!0):a=this.consumeIdentifier().text;let l=this.parseOperator(),u=l.operator,p=l.isSet,E,C,d;if(p)if(this.check(138)&&this.peekAt(1).kind===23)this.expect(138),E=this.parseSelectStatement(!1),this.expect(139),C="SUBQUERY";else if(this.config.allowApexBindVariables&&this.check(144))E=this.parseApexBindVariable().value,C="APEX_BIND_VARIABLE";else{let L=this.parseArrayExpression();E=L.values,C=L.literalType,d=L.dateLiteralVariable}else{let L=this.parseAtomicValue();E=L.value,C=L.literalType,d=L.dateLiteralVariable}let I=0;for(;this.check(139)&&(!t||t.left>t.right);)this.advance(),I++,t&&t.right++;let S={};return o?S.fn=a:S.field=a,S.operator=u,C==="SUBQUERY"?S.valueQuery=E:S.value=E,S.literalType=C,d!==void 0&&(S.dateLiteralVariable=d),n>0&&(S.openParen=n),I>0&&(S.closeParen=I),S}isSubqueryStart(){return this.check(138)&&this.peekAt(1).kind===23}isArrayExpressionStart(){return!1}parseOperator(){let e=this.peek();if(ae(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 ${R[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:f(this.advance().kind),literalType:"BOOLEAN"};if(M(e.kind))return{value:this.advance().text,literalType:"DATE_LITERAL"};if(P(e.kind)){let r=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${r.text}:${n}`,literalType:"DATE_N_LITERAL",dateLiteralVariable:n}}throw this.error(`Expected value but found ${R[e.kind]} ("${e.text}") at position ${e.start}`)}parseArrayExpression(){this.expect(138);let e=[];for(e.push(this.parseArrayItem());this.match(143);)e.push(this.parseArrayItem());this.expect(139);let r=e.map(u=>u.value),t=e.map(u=>u.type),n=e.map(u=>u.variable!==void 0?u.variable:null),a=n.some(u=>u!==null),o;new Set(t).size===1?o=this.getLiteralType(this.tokenKindFromTypeName(t[0])):o=t.map(u=>this.getLiteralType(this.tokenKindFromTypeName(u)));let l={values:r,literalType:o};return a&&(l.dateLiteralVariable=n),l}tokenKindFromTypeName(e){for(let r=0;r<=160;r++)if(f(r)===e)return r;return 159}parseArrayItem(){let e=this.peek();if(e.kind===157)return{value:this.advance().text,type:f(157)};if(e.kind===158)return{value:this.advance().text,type:f(158)};if(e.kind===151)return{value:this.advance().text,type:f(151)};if(e.kind===152)return{value:this.advance().text,type:f(152)};if(Q(e.kind)){let r=this.advance();return{value:r.text,type:f(r.kind)}}if(e.kind===149)return{value:this.advance().text,type:f(149)};if(e.kind===150)return{value:this.advance().text,type:f(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(M(e.kind))return{value:this.advance().text,type:f(e.kind)};if(P(e.kind)){let r=this.advance();this.expect(144);let t=this.peek(),n;if(t.kind===156||t.kind===155)n=Number(this.advance().text);else throw this.error(`Expected integer after date N literal colon at position ${t.start}`);return{value:`${r.text}:${n}`,type:f(r.kind),variable:n}}throw this.error(`Expected array value but found ${R[e.kind]} ("${e.text}") at position ${e.start}`)}parseApexBindVariable(){this.expect(144);let e=[];for(this.check(32)?e.push(this.parseApexBindNewInstantiation()):this.checkIdentifier()&&(this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):e.push(this.parseApexBindIdentifier()));this.check(142);)this.advance(),this.checkIdentifier()&&this.peekAt(1).kind===138?e.push(this.parseApexBindFunctionCall()):this.checkIdentifier()&&e.push(this.parseApexBindIdentifier());return{value:e.join(".")}}parseApexBindIdentifier(){let e=this.consumeIdentifier().text;return this.check(140)&&(e+=this.parseApexBindArrayAccessor()),e}parseApexBindNewInstantiation(){this.expect(32);let r=`new ${this.consumeIdentifier().text}`;if(this.check(134)){this.advance();let t=[];for(t.push(this.consumeIdentifier().text);this.match(143);)t.push(this.consumeIdentifier().text);this.expect(136),r+=`<${t.join(", ")}>`}return r+=this.parseApexBindFunctionParams(),this.check(140)&&(r+=this.parseApexBindArrayAccessor()),r}parseApexBindFunctionCall(){let r=this.consumeIdentifier().text+this.parseApexBindFunctionParams();return this.check(140)&&(r+=this.parseApexBindArrayAccessor()),r}parseApexBindFunctionParams(){this.expect(138);let e=[];if(!this.check(139))for(e.push(this.consumeIdentifier().text);this.match(143);)e.push(this.consumeIdentifier().text);return this.expect(139),`(${e.join(", ")})`}parseApexBindArrayAccessor(){this.expect(140);let e=this.peek(),r;if(e.kind===156)r=this.advance().text;else if(g(e.kind))r=this.advance().text;else throw this.error(`Expected integer or identifier in array accessor at position ${e.start}`);return this.expect(141),`[${r}]`}parseAnyFunction(e){let r=this.peek();if(y(r.kind))return this.parseDateFunction(e);if(F(r.kind))return this.parseAggregateFunction(e);if(r.kind===68)return this.parseLocationFunction(e);if(H(r.kind))return this.parseFieldsFunction(e);if(b(r.kind))return this.parseOtherFunction(e);throw this.error(`Expected function name but found ${R[r.kind]} at position ${r.start}`)}parseDateFunction(e){let r=this.advance(),t=f(r.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseAggregateFunction(e){let r=this.advance(),t=f(r.kind),n=this.parseFunctionExpression(!0,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,e&&(a.isAggregateFn=!0),a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseFieldsFunction(e){this.advance(),this.expect(138);let r=this.peek(),t;if(se(r.kind))t=this.advance().text;else if(g(r.kind))t=this.advance().text;else throw this.error(`Expected FIELDS function parameter at position ${r.start}`);this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="FIELDS",n.parameters=[t],n.rawValue=`FIELDS(${t})`,n}parseOtherFunction(e){let r=this.advance(),t=f(r.kind),n=this.parseFunctionExpression(!1,e),a={};return e&&(a.type="FieldFunctionExpression"),a.functionName=t,a.parameters=n,a.rawValue=`${r.text}(${n.map(o=>typeof o=="string"?o:o.rawValue).join(", ")})`,a}parseLocationFunction(e){this.advance(),this.expect(138);let r=this.consumeIdentifier().text;this.expect(143);let t;this.check(69)&&this.peekAt(1).kind===138?t=this.parseGeolocationFunction(e):t=this.consumeIdentifier().text,this.expect(143);let n=this.expect(158).text;this.expect(139);let a={};e&&(a.type="FieldFunctionExpression"),a.functionName="DISTANCE",a.parameters=[r,t,n],e&&(a.isAggregateFn=!0);let o=typeof t=="string"?t:t.rawValue;return a.rawValue=`DISTANCE(${r}, ${o}, ${n})`,a}parseGeolocationFunction(e){this.advance(),this.expect(138);let r=this.parseNumberValue();this.expect(143);let t=this.parseNumberValue();this.expect(139);let n={};return e&&(n.type="FieldFunctionExpression"),n.functionName="GEOLOCATION",n.parameters=[r,t],n.rawValue=`GEOLOCATION(${r}, ${t})`,n}parseNumberValue(){let e=this.peek();if(e.kind===156||e.kind===155||e.kind===154||e.kind===153)return this.advance().text;throw this.error(`Expected number but found ${R[e.kind]} ("${e.text}") at position ${e.start}`)}parseFunctionExpression(e,r=!0){this.expect(138);let t=[];if(!this.check(139))for(t.push(this.parseFunctionParam(e,r));this.match(143);)t.push(this.parseFunctionParam(e,r));return this.expect(139),t}parseFunctionParam(e,r){let t=this.peek(),n=this.peekAt(1);if(!e&&F(t.kind)&&n.kind===138)return this.parseAggregateFunction(r);if(b(t.kind)&&n.kind===138)return this.parseOtherFunction(r);if(t.kind===157)return this.advance().text;if(Q(t.kind))return this.advance().text;if(g(t.kind))return this.advance().text;throw this.error(`Expected function parameter but found ${R[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")}:y(e.kind)&&this.peekAt(1).kind===138?{fn:this.parseDateFunction(!1)}:{field:this.consumeIdentifier().text}}parseCubeOrRollupFunction(e){let r=this.advance(),t=this.parseFunctionExpression(!1);return{functionName:e,parameters:t,rawValue:`${e}(${t.join(", ")})`}}parseHavingClause(){return this.expect(11),this.parseConditionExpressions(!0,!1)}parseOrderByClause(){this.expect(21);let e=[];for(e.push(this.parseOrderByItem());this.match(143);)e.push(this.parseOrderByItem());return e}parseOrderByItem(){let e=this.peek(),r=this.peekAt(1),t;if(e.kind===75&&r.kind===138){let n=this.advance(),a=this.parseFunctionExpression(!1);t={fn:{functionName:f(n.kind),parameters:a,rawValue:`${n.text}(${a.join(", ")})`}}}else F(e.kind)&&r.kind===138?t={fn:this.parseAggregateFunction(!1)}:y(e.kind)&&r.kind===138?t={fn:this.parseDateFunction(!1)}:e.kind===68&&r.kind===138?t={fn:this.parseLocationFunction(!1)}:t={field:this.consumeIdentifier().text};if(this.check(2)?t.order=f(this.advance().kind):this.check(3)&&(t.order=f(this.advance().kind)),this.check(19))if(this.advance(),this.check(8))t.nulls=f(this.advance().kind);else if(this.check(14))t.nulls=f(this.advance().kind);else throw this.error(`Expected FIRST or LAST after NULLS at position ${this.peek().start}`);return t}parseWithClause(){this.expect(27);let e=this.peek();if(e.kind===46)return this.advance(),{withSecurityEnforced:!0};if(e.kind===48)return this.advance(),{withAccessLevel:"USER_MODE"};if(e.kind===47)return this.advance(),{withAccessLevel:"SYSTEM_MODE"};if(e.kind===35)return{withDataCategory:this.parseWithDataCategory()};throw this.error(`Expected SECURITY_ENFORCED, USER_MODE, SYSTEM_MODE, or DATA CATEGORY after WITH at position ${e.start}`)}parseWithDataCategory(){this.expect(35);let e=[];for(e.push(this.parseDataCategoryCondition());this.check(0);)this.advance(),e.push(this.parseDataCategoryCondition());return{conditions:e}}parseDataCategoryCondition(){let e=this.consumeIdentifier().text,r=this.peek(),t;if(r.kind===33||r.kind===30||r.kind===34||r.kind===31)t=this.advance().text;else throw this.error(`Expected data category selector (AT, ABOVE, BELOW, ABOVE_OR_BELOW) at position ${r.start}`);let n=this.match(138),a=[];for(a.push(this.consumeIdentifier().text);this.match(143);)a.push(this.consumeIdentifier().text);return n&&this.expect(139),{groupName:e,selector:t,parameters:a}}};function x(s,e){let r=e||{},t=oe(s),n=new j(t,r),a;if(r.allowPartialQuery?a=n.parseSelectStatementPartial():a=n.parseSelectStatement(!1),!n.isAtEnd()&&!r.ignoreParseErrors){let o=t[n.getPos()];throw new Error(`Unexpected token "${o.text}" at position ${o.start}. Expected end of query.`)}return a}function X(s,e){try{return x(s,e),!0}catch{return!1}}function _(s){return typeof s=="string"}function O(s){return Number.isFinite(s)}function T(s){return s==null}function m(s,e,r){return T(s)?"":`${r||""}${s}${e||""}`}function le(s,e=!1){return Array.isArray(s)?s.length>0?`(${s.join(", ")})`:e?"()":"":e?`(${s||""})`:s||""}function ue(s,e,r=""){return O(s)&&s>0?new Array(s).fill(e).join(r):""}function q(s){return s&&!T(s.alias)}function D(s){return _(s.relationshipName)}function K(s){return!!s&&!!s.operator&&!!s.right}function J(s){return s&&!T(s.fn)&&_(s.operator)&&!T(s.value)}function k(s){return s&&O(s.openParen)&&T(s.operator)&&T(s.field)&&T(s.fn)&&T(s.closeParen)}function z(s){return s&&_(s.field)&&_(s.operator)&&!T(s.valueQuery)&&T(s.value)}function Z(s){return s&&!T(s.field)}function ee(s){return s&&!T(s.field)}function de(s){return["IN","NOT IN","INCLUDES","EXCLUDES"].includes(s)}function Ee(s,e,r){if(T(e))return s;if(r&&e!=="APEX_BIND_VARIABLE"&&de(r)&&!Array.isArray(s)&&(s=[s],e=Array.isArray(e)?e:[e]),Array.isArray(e)&&Array.isArray(s))return s.map((t,n)=>Ne(t,e?.[n]));switch(Array.isArray(e)&&(e=e[0]),e){case"STRING":return Array.isArray(s)?s.filter(Boolean).map(t=>_(t)&&t.startsWith("'")?t:`'${t??""}'`):(s=String(s??""),_(s)&&s.startsWith("'")?s:`'${s??""}'`);case"APEX_BIND_VARIABLE":return`:${s}`;default:return s}}function Ne(s,e){switch(e){case"STRING":return _(s)&&s.startsWith("'")?s:`'${s??""}'`;case"NULL":return"null";default:return s}}var v=class{constructor(e,r){this.currIndent=1;this.enabled=e,this.options={numIndent:r.numIndent??1,fieldMaxLineLength:r.fieldMaxLineLength??60,fieldSubqueryParensOnOwnLine:r.fieldSubqueryParensOnOwnLine??!0,whereClauseOperatorsIndented:!0,newLineAfterKeywords:r.newLineAfterKeywords??!1,logging:r.logging??!1},this.options.newLineAfterKeywords&&(this.options.fieldSubqueryParensOnOwnLine=!0)}log(e){this.options.logging&&console.log(e)}getIndent(e=0){return this.repeatChar((this.currIndent+e)*(this.options.numIndent||1)," ")}repeatChar(e,r){return new Array(e).fill(r).join("")}setSubquery(e){this.currIndent=e?this.currIndent+=1:this.currIndent-=1}stepCurrIndex(e){this.currIndent+=e}formatFields(e){function r(t){e.fields[t-1]&&(e.fields[t-1].suffix=e.fields[t-1].suffix.trim())}if(e.fields.forEach((t,n)=>{t.suffix=e.fields.length-1===n?"":", "}),this.enabled){let t=0,n=!1;e.fields.forEach((a,o)=>{a.isSubquery?(r(o),a.prefix=`
|
|
2
7
|
${this.getIndent()}`,a.suffix=e.fields.length-1===o?"":", ",t=0,n=!0):Array.isArray(a.typeOfClause)?(r(o),a.prefix=`
|
|
3
8
|
${this.getIndent()}`,n=!0):O(this.options.fieldMaxLineLength)&&(t+=a.text.length+a.suffix.length,(t>this.options.fieldMaxLineLength||n)&&(r(o),(!this.options.newLineAfterKeywords||o>0)&&(a.prefix+=`
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @jetstreamapp/soql-parser-js v7.2.0
|
|
3
|
+
* https://github.com/jetstreamapp/soql-parser-js
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
1
6
|
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 g(i){return i>=62&&i<=67}function w(i){return i>=68&&i<=69}function $(i){return i===70}function y(i){return i>=71&&i<=75}function Z(i){return i>=76&&i<=78}function b(i){return i>=79&&i<=101}function U(i){return i>=102&&i<=122}function J(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 W(i){return i===153||i===154||i===155||i===156}function ee(i){return i>=132&&i<=137}var pe=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 B(i){return i>=65&&i<=90||i>=97&&i<=122}function p(i){return i>=48&&i<=57}function Y(i){return B(i)||p(i)||i===95}function D(i){return i===32||i===9||i===10||i===13||i===12}function te(i){let e=[],s=i.length,t=0;for(;t<s;){let n=i.charCodeAt(t);if(D(n)){for(t++;t<s&&D(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(B(n)){let a=t;for(t++;t<s;){let E=i.charCodeAt(t);if(Y(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=v(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=v(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=v(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(z(E)){let u=o.substring(3);if(ce(u)){u.includes(".")?e.push({kind:151,text:o,start:a}):e.push({kind:152,text:o,start:a});continue}}}if(o.length===3&&z(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||!Y(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=pe.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 v(i,e,s){let t=i.length,n=e;if(n>=t||!D(i.charCodeAt(n)))return-1;for(;n<t&&D(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(Y(h)||h===46)return-1}return o}function z(i){for(let e=0;e<i.length;e++)if(!B(i.charCodeAt(e)))return!1;return!0}function ce(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 fe=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]),H=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)||g(e.kind)||w(e.kind)||$(e.kind)||y(e.kind))&&s.kind===138}canBeAlias(){let e=this.peek();return!(!I(e.kind)||fe.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":b(e)?"DATE_LITERAL":U(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(J(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&&g(this.peek().kind)&&this.peekAt(1).kind===138?(a=this.parseAggregateFunction(!1),o=!0):s&&w(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):y(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(ee(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(b(e.kind))return{value:this.advance().text,literalType:"DATE_LITERAL"};if(U(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(W(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(b(e.kind))return{value:this.advance().text,type:d(e.kind)};if(U(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(F(s.kind))return this.parseDateFunction(e);if(g(s.kind))return this.parseAggregateFunction(e);if(s.kind===68)return this.parseLocationFunction(e);if($(s.kind))return this.parseFieldsFunction(e);if(y(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(Z(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&&g(t.kind)&&n.kind===138)return this.parseAggregateFunction(s);if(y(t.kind)&&n.kind===138)return this.parseOtherFunction(s);if(t.kind===157)return this.advance().text;if(W(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:d(n.kind),parameters:a,rawValue:`${n.text}(${a.join(", ")})`}}}else g(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=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 k(i,e){let s=e||{},t=te(i),n=new H(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 Ae(i,e){try{return k(i,e),!0}catch{return!1}}function A(i){return typeof i=="string"}function de(i){return i?i.every(e=>A(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 ie(i,e=!1){return Array.isArray(i)?i.length>0?`(${i.join(", ")})`:e?"()":"":e?`(${i||""})`:i||""}function re(i,e,s=""){return L(i)&&i>0?new Array(i).fill(e).join(s):""}function V(i){return!i.parameters||i.parameters.length===0?[]:de(i.parameters)?i.parameters:A(i.parameters[0])?[i.parameters[0]]:V(i.parameters[0])}function se(i){if(!i.parameters||i.parameters.length===0)return!1;let e=i.parameters[0];return A(e)?!1:!!e.isAggregateFn}function G(i){return i&&!N(i.alias)}function ne(i){return A(i.field)&&!Array.isArray(i.relationships)&&!Array.isArray(i.conditions)}function ae(i){return!N(i.functionName||i.fn)}function oe(i){return A(i.field)&&Array.isArray(i.relationships)}function le(i){return!N(i.subquery)}function ue(i){return A(i.field)&&Array.isArray(i.conditions)}function m(i){return A(i.relationshipName)}function Ee(i){return!!i&&!!i.type&&i.type==="FieldSubquery"}function Ne(i){return!!i&&!!i.operator&&!!i.right}function Re(i){return!!i&&!!i.operator&&!!i.right}function Q(i){return!!i&&!!i.operator&&!!i.right}function Te(i){return i&&A(i.field)&&A(i.operator)&&!N(i.value)}function Ce(i){return i&&A(i.field)&&A(i.operator)&&!N(i.value)&&(i.literalType==="DATE_LITERAL"||Array.isArray(i.literalType)&&i.literalType[0]==="DATE_LITERAL")}function _e(i){return i&&A(i.field)&&A(i.operator)&&!N(i.value)&&!N(i.dateLiteralVariable)}function X(i){return i&&!N(i.fn)&&A(i.operator)&&!N(i.value)}function x(i){return i&&L(i.openParen)&&N(i.operator)&&N(i.field)&&N(i.fn)&&N(i.closeParen)}function j(i){return i&&A(i.field)&&A(i.operator)&&!N(i.valueQuery)&&N(i.value)}function q(i){return i&&!N(i.field)}function Se(i){return i&&!N(i.fn)}function M(i){return i&&!N(i.field)}function Ie(i){return i&&!N(i.fn)}function Le(i){return["IN","NOT IN","INCLUDES","EXCLUDES"].includes(i)}function he(i,e,s){if(N(e))return i;if(s&&e!=="APEX_BIND_VARIABLE"&&Le(s)&&!Array.isArray(i)&&(i=[i],e=Array.isArray(e)?e:[e]),Array.isArray(e)&&Array.isArray(i))return i.map((t,n)=>Oe(t,e?.[n]));switch(Array.isArray(e)&&(e=e[0]),e){case"STRING":return Array.isArray(i)?i.filter(Boolean).map(t=>A(t)&&t.startsWith("'")?t:`'${t??""}'`):(i=String(i??""),A(i)&&i.startsWith("'")?i:`'${i??""}'`);case"APEX_BIND_VARIABLE":return`:${i}`;default:return i}}function Oe(i,e){switch(e){case"STRING":return A(i)&&i.startsWith("'")?i:`'${i??""}'`;case"NULL":return"null";default:return i}}function ke(i){return ge(i)}function ge(i){if(typeof i=="string")return{type:"Field",field:i};if(ae(i)){let e=[];return i.parameters&&(e=Array.isArray(i.parameters)?i.parameters:[i.parameters]),{type:"FieldFunctionExpression",functionName:i.functionName||i.fn,parameters:e,alias:i.alias}}else{if(oe(i))return{type:"FieldRelationship",field:i.field,relationships:i.relationships,objectPrefix:i.objectPrefix};if(le(i))return{type:"FieldSubquery",subquery:i.subquery};if(ue(i))return{type:"FieldTypeof",field:i.field,conditions:i.conditions};if(ne(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 Ge(i,e){if(!i)return[];i=Ee(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)=>(M(E)&&(l[E.field.toLocaleLowerCase()]=E.field),l),{}));let n=-1,a=(m(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=V(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||se(l)||e?(n++,`expr${n}`):E.length>0?E.join("."):l.functionName}case"FieldRelationship":{let E=l.relationships[0].toLowerCase();return G(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=>A(l))}var P=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+=`
|