@libdbm/libcel-ts 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,14 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class p extends Error{constructor(t,e,i){super(`${t} at ${e}:${i}`),this.line=e,this.column=i,this.name="ParseError"}}var s=(r=>(r.NULL="NULL",r.TRUE="TRUE",r.FALSE="FALSE",r.INT="INT",r.UINT="UINT",r.DOUBLE="DOUBLE",r.STRING="STRING",r.BYTES="BYTES",r.IDENTIFIER="IDENTIFIER",r.PLUS="PLUS",r.MINUS="MINUS",r.STAR="STAR",r.SLASH="SLASH",r.PERCENT="PERCENT",r.EQ="EQ",r.NE="NE",r.LT="LT",r.LE="LE",r.GT="GT",r.GE="GE",r.LOGICAL_AND="LOGICAL_AND",r.LOGICAL_OR="LOGICAL_OR",r.BANG="BANG",r.IN="IN",r.LPAREN="LPAREN",r.RPAREN="RPAREN",r.LBRACKET="LBRACKET",r.RBRACKET="RBRACKET",r.LBRACE="LBRACE",r.RBRACE="RBRACE",r.DOT="DOT",r.COMMA="COMMA",r.COLON="COLON",r.QUESTION="QUESTION",r.EOF="EOF",r))(s||{});class h{constructor(t,e,i,n){this.type=t,this.value=e,this.line=i,this.column=n}toString(){return`${this.type}(${this.value})`}}class H{constructor(t){this.input=t,this.position=0,this.line=1,this.column=1,this.lookahead=[]}next(){return this.lookahead.length>0?this.lookahead.shift():this.token()}peek(t){for(;this.lookahead.length<t;)this.lookahead.push(this.token());return this.lookahead[t-1]}step(){if(this.position>=this.input.length)return;const t=this.input[this.position];this.position++,t==="\r"?(this.position<this.input.length&&this.input[this.position]===`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class U extends Error{constructor(t,n,i){super(`${t} at ${n}:${i}`),this.line=n,this.column=i,this.name="ParseError"}}var o=(e=>(e.NULL="NULL",e.TRUE="TRUE",e.FALSE="FALSE",e.INT="INT",e.UINT="UINT",e.DOUBLE="DOUBLE",e.STRING="STRING",e.BYTES="BYTES",e.IDENTIFIER="IDENTIFIER",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.EQ="EQ",e.NE="NE",e.LT="LT",e.LE="LE",e.GT="GT",e.GE="GE",e.LOGICAL_AND="LOGICAL_AND",e.LOGICAL_OR="LOGICAL_OR",e.BANG="BANG",e.IN="IN",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DOT="DOT",e.COMMA="COMMA",e.COLON="COLON",e.QUESTION="QUESTION",e.EOF="EOF",e))(o||{});class w{constructor(t,n,i,r){this.type=t,this.value=n,this.line=i,this.column=r}toString(){return`${this.type}(${this.value})`}}class Me{constructor(t){this.input=t,this.position=0,this.line=1,this.column=1,this.lookahead=[]}next(){return this.lookahead.length>0?this.lookahead.shift():this.token()}peek(t){for(;this.lookahead.length<t;)this.lookahead.push(this.token());return this.lookahead[t-1]}step(){if(this.position>=this.input.length)return;const t=this.input[this.position];this.position++,t==="\r"?(this.position<this.input.length&&this.input[this.position]===`
2
2
  `&&this.position++,this.line++,this.column=1):t===`
3
- `?(this.line++,this.column=1):this.column++}forward(t){for(let e=0;e<t;e++)this.step()}token(){if(this.whitespace(),this.position>=this.input.length)return new h("EOF","",this.line,this.column);const t=this.position,e=this.line,i=this.column,n=this.input[this.position];switch(n){case"(":return this.step(),new h("LPAREN","(",e,i);case")":return this.step(),new h("RPAREN",")",e,i);case"[":return this.step(),new h("LBRACKET","[",e,i);case"]":return this.step(),new h("RBRACKET","]",e,i);case"{":return this.step(),new h("LBRACE","{",e,i);case"}":return this.step(),new h("RBRACE","}",e,i);case",":return this.step(),new h("COMMA",",",e,i);case".":return this.step(),new h("DOT",".",e,i);case":":return this.step(),new h("COLON",":",e,i);case"?":return this.step(),new h("QUESTION","?",e,i);case"+":return this.step(),new h("PLUS","+",e,i);case"*":return this.step(),new h("STAR","*",e,i);case"/":return this.step(),new h("SLASH","/",e,i);case"%":return this.step(),new h("PERCENT","%",e,i)}if(n==="&"&&this.peekChar()==="&")return this.forward(2),new h("LOGICAL_AND","&&",e,i);if(n==="|"&&this.peekChar()==="|")return this.forward(2),new h("LOGICAL_OR","||",e,i);if(n==="="&&this.peekChar()==="=")return this.forward(2),new h("EQ","==",e,i);if(n==="!"&&this.peekChar()==="=")return this.forward(2),new h("NE","!=",e,i);if(n==="<"&&this.peekChar()==="=")return this.forward(2),new h("LE","<=",e,i);if(n===">"&&this.peekChar()==="=")return this.forward(2),new h("GE",">=",e,i);if(n==="<")return this.step(),new h("LT","<",e,i);if(n===">")return this.step(),new h("GT",">",e,i);if(n==="!")return this.step(),new h("BANG","!",e,i);if(n==="-")return this.step(),new h("MINUS","-",e,i);if(n==='"'||n==="'")return this.string(e,i,t);if((n==="r"||n==="R")&&this.position+1<this.input.length){const o=this.input[this.position+1];if(o==='"'||o==="'")return this.string(e,i,t)}if((n==="b"||n==="B")&&this.position+1<this.input.length){const o=this.input[this.position+1];if(o==='"'||o==="'")return this.bytes(e,i,t)}if(this.isDigit(n))return this.number(e,i,t);if(this.isLetter(n)||n==="_")return this.identifier(e,i,t);throw new p(`Unexpected character: ${n}`,e,i)}string(t,e,i){let n=!1;if((this.input[this.position]==="r"||this.input[this.position]==="R")&&(n=!0,this.step()),this.position+2<this.input.length){const l=this.input.substring(this.position,this.position+3);if(l==='"""'||l==="'''"){const c=this.input[this.position];for(this.forward(3);this.position+2<this.input.length;){if(this.input[this.position]===c&&this.input[this.position+1]===c&&this.input[this.position+2]===c)return this.forward(3),new h("STRING",this.input.substring(i,this.position),t,e);this.step()}throw new p("Unterminated triple-quoted string",t,e)}}const o=this.input[this.position];for(this.step();this.position<this.input.length;){const l=this.input[this.position];if(l===o)return this.step(),new h("STRING",this.input.substring(i,this.position),t,e);l==="\\"&&!n&&this.position+1<this.input.length?this.forward(2):this.step()}throw new p("Unterminated string",t,e)}bytes(t,e,i){this.step();const n=this.input[this.position];for(this.step();this.position<this.input.length;){const o=this.input[this.position];if(o===n)return this.step(),new h("BYTES",this.input.substring(i,this.position),t,e);o==="\\"&&this.position+1<this.input.length?this.forward(2):this.step()}throw new p("Unterminated bytes literal",t,e)}number(t,e,i){if(this.input[this.position]==="0"&&this.position+1<this.input.length){const l=this.input[this.position+1];if(l==="x"||l==="X"){for(this.forward(2);this.position<this.input.length&&this.isHexDigit(this.input[this.position]);)this.step();if(this.position<this.input.length){const c=this.input[this.position];if(c==="u"||c==="U")return this.step(),new h("UINT",this.input.substring(i,this.position),t,e)}return new h("INT",this.input.substring(i,this.position),t,e)}}for(;this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step();let n=!1;if(this.position<this.input.length&&this.input[this.position]===".")for(n=!0,this.step();this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step();if(this.position<this.input.length){const l=this.input[this.position];if(l==="e"||l==="E"){if(n=!0,this.step(),this.position<this.input.length){const c=this.input[this.position];(c==="+"||c==="-")&&this.step()}for(;this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step()}}if(!n&&this.position<this.input.length){const l=this.input[this.position];if(l==="u"||l==="U")return this.step(),new h("UINT",this.input.substring(i,this.position),t,e)}const o=n?"DOUBLE":"INT";return new h(o,this.input.substring(i,this.position),t,e)}identifier(t,e,i){for(;this.position<this.input.length;){const l=this.input[this.position];if(!this.isLetterOrDigit(l)&&l!=="_")break;this.step()}const n=this.input.substring(i,this.position),o=this.typeOf(n);return new h(o,n,t,e)}typeOf(t){switch(t){case"null":return"NULL";case"true":return"TRUE";case"false":return"FALSE";case"in":return"IN";default:return"IDENTIFIER"}}whitespace(){for(;this.position<this.input.length;){const t=this.input[this.position];if(t!==" "&&t!==" "&&t!==`
4
- `&&t!=="\r")break;this.step()}}peekChar(){const t=this.position+1;return t>=this.input.length?"\0":this.input[t]}isHexDigit(t){return t>="0"&&t<="9"||t>="a"&&t<="f"||t>="A"&&t<="F"}isDigit(t){return t>="0"&&t<="9"}isLetter(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isLetterOrDigit(t){return this.isLetter(t)||this.isDigit(t)}}var u=(r=>(r.ADD="ADD",r.SUBTRACT="SUBTRACT",r.MULTIPLY="MULTIPLY",r.DIVIDE="DIVIDE",r.MODULO="MODULO",r.EQUAL="EQUAL",r.NOT_EQUAL="NOT_EQUAL",r.LESS="LESS",r.LESS_EQUAL="LESS_EQUAL",r.GREATER="GREATER",r.GREATER_EQUAL="GREATER_EQUAL",r.IN="IN",r.LOGICAL_AND="LOGICAL_AND",r.LOGICAL_OR="LOGICAL_OR",r))(u||{}),A=(r=>(r.NOT="NOT",r.NEGATE="NEGATE",r))(A||{}),w=(r=>(r.NULL_VALUE="NULL_VALUE",r.BOOL="BOOL",r.INT="INT",r.UINT="UINT",r.DOUBLE="DOUBLE",r.STRING="STRING",r.BYTES="BYTES",r))(w||{});class d{constructor(t,e){this.value=t,this.literalType=e}accept(t){return t.visitLiteral(this)}}class S{constructor(t){this.name=t}accept(t){return t.visitIdentifier(this)}}class R{constructor(t,e,i=!1){this.operand=t,this.field=e,this.isTest=i}accept(t){return t.visitSelect(this)}}class D{constructor(t,e){this.operand=t,this.index=e}accept(t){return t.visitIndex(this)}}class y{constructor(t,e,i,n=!1){this.target=t,this.functionName=e,this.args=i,this.isMacro=n}accept(t){return t.visitCall(this)}}class T{constructor(t){this.elements=t}accept(t){return t.visitList(this)}}class B{constructor(t,e){this.key=t,this.value=e}}class b{constructor(t){this.entries=t}accept(t){return t.visitMap(this)}}class x{constructor(t,e){this.field=t,this.value=e}}class m{constructor(t,e){this.typeName=t,this.fields=e}accept(t){return t.visitStruct(this)}}class V{constructor(t,e,i,n,o,l,c){this.variable=t,this.range=e,this.accumulator=i,this.initializer=n,this.condition=o,this.step=l,this.result=c}accept(t){return t.visitComprehension(this)}}class N{constructor(t,e){this.op=t,this.operand=e}accept(t){return t.visitUnary(this)}}class L{constructor(t,e,i){this.op=t,this.left=e,this.right=i}accept(t){return t.visitBinary(this)}}class G{constructor(t,e,i){this.condition=t,this.thenExpr=e,this.otherwiseExpr=i}accept(t){return t.visitConditional(this)}}const X=new Set(["map","filter","all","exists","existsOne"]);class ${constructor(t){this.lexer=new H(t),this.current=this.lexer.next()}parse(){const t=this.parseExpr();if(this.current.type!==s.EOF)throw new p(`Unexpected token after expression: ${this.current.value}`,this.current.line,this.current.column);return t}parseExpr(){const t=this.parseConditionalOr();if(this.match(s.QUESTION)){const e=this.parseConditionalOr();this.expect(s.COLON);const i=this.parseExpr();return new G(t,e,i)}return t}parseConditionalOr(){let t=this.parseConditionalAnd();for(;this.match(s.LOGICAL_OR);){const e=this.parseConditionalAnd();t=new L(u.LOGICAL_OR,t,e)}return t}parseConditionalAnd(){let t=this.parseRelation();for(;this.match(s.LOGICAL_AND);){const e=this.parseRelation();t=new L(u.LOGICAL_AND,t,e)}return t}parseRelation(){let t=this.parseAddition();for(;this.isRelationalOp(this.current.type);){const e=this.current.type;this.advance();const i=this.parseAddition();t=new L(this.toBinaryOp(e),t,i)}return t}parseAddition(){let t=this.parseMultiplication();for(;this.current.type===s.PLUS||this.current.type===s.MINUS;){const e=this.current.type;this.advance();const i=this.parseMultiplication();t=new L(e===s.PLUS?u.ADD:u.SUBTRACT,t,i)}return t}parseMultiplication(){let t=this.parseUnary();for(;this.current.type===s.STAR||this.current.type===s.SLASH||this.current.type===s.PERCENT;){const e=this.current.type;this.advance();const i=this.parseUnary(),n=e===s.STAR?u.MULTIPLY:e===s.SLASH?u.DIVIDE:u.MODULO;t=new L(n,t,i)}return t}parseUnary(){return this.current.type===s.BANG?(this.advance(),new N(A.NOT,this.parseUnary())):this.current.type===s.MINUS?(this.advance(),new N(A.NEGATE,this.parseUnary())):this.parseMember()}parseMember(){let t=this.parsePrimary();for(;;)if(this.current.type===s.DOT){this.advance();const e=this.expectIdentifier();if(this.current.type===s.LPAREN){this.advance();const i=this.parseExprList();this.expect(s.RPAREN);const n=X.has(e);t=new y(t,e,i,n)}else t=new R(t,e)}else if(this.current.type===s.LBRACKET){this.advance();const e=this.parseExpr();this.expect(s.RBRACKET),t=new D(t,e)}else break;return t}parsePrimary(){if(this.isLiteralToken(this.current.type))return this.parseLiteral();if(this.current.type===s.LBRACKET)return this.parseListLiteral();if(this.current.type===s.LBRACE)return this.parseMapOrStructLiteral(null);if(this.current.type===s.LPAREN){this.advance();const t=this.parseExpr();return this.expect(s.RPAREN),t}if(this.current.type===s.DOT){this.advance();const t=this.expectIdentifier();if(this.current.type===s.LPAREN){this.advance();const e=this.parseExprList();return this.expect(s.RPAREN),new y(null,t,e)}return new R(null,t)}if(this.current.type===s.IDENTIFIER){const t=this.current.value;if(this.advance(),this.current.type===s.LPAREN){this.advance();const e=this.parseExprList();return this.expect(s.RPAREN),new y(null,t,e)}if(this.current.type===s.DOT&&this.isQualifiedStructLiteral()){const e=this.parseQualifiedIdent(t);return this.parseMapOrStructLiteral(e)}return this.current.type===s.LBRACE?this.parseMapOrStructLiteral(t):new S(t)}throw new p(`Unexpected token: ${this.current.value}`,this.current.line,this.current.column)}parseListLiteral(){this.expect(s.LBRACKET);const t=[];return this.current.type!==s.RBRACKET&&(t.push(...this.parseExprList()),this.current.type===s.COMMA&&this.advance()),this.expect(s.RBRACKET),new T(t)}parseMapOrStructLiteral(t){if(this.expect(s.LBRACE),this.current.type===s.RBRACE)return this.advance(),t!==null?new m(t,[]):new b([]);if(this.current.type===s.IDENTIFIER&&this.peekAhead(1).type===s.COLON||t!==null){const i=this.parseFieldInits();return this.current.type===s.COMMA&&this.advance(),this.expect(s.RBRACE),new m(t,i)}else{const i=this.parseMapInits();return this.current.type===s.COMMA&&this.advance(),this.expect(s.RBRACE),new b(i)}}parseExprList(){const t=[],e=this.current.type;if(e===s.RPAREN||e===s.RBRACKET)return t;for(t.push(this.parseExpr());this.current.type===s.COMMA&&(this.advance(),!(this.current.type===s.RPAREN||this.current.type===s.RBRACKET));)t.push(this.parseExpr());return t}parseMapInits(){const t=[];for(t.push(this.parseMapInit());this.current.type===s.COMMA&&(this.advance(),this.current.type!==s.RBRACE);)t.push(this.parseMapInit());return t}parseMapInit(){const t=this.parseExpr();this.expect(s.COLON);const e=this.parseExpr();return new B(t,e)}parseFieldInits(){const t=[];for(t.push(this.parseFieldInit());this.current.type===s.COMMA&&(this.advance(),this.current.type!==s.RBRACE);)t.push(this.parseFieldInit());return t}parseFieldInit(){const t=this.expectIdentifier();this.expect(s.COLON);const e=this.parseExpr();return new x(t,e)}parseQualifiedIdent(t){let e=t;for(;this.current.type===s.DOT;)this.advance(),e+=".",e+=this.expectIdentifier();return e}parseLiteral(){const t=this.current;switch(this.advance(),t.type){case s.NULL:return new d(null,w.NULL_VALUE);case s.TRUE:return new d(!0,w.BOOL);case s.FALSE:return new d(!1,w.BOOL);case s.INT:return new d(this.parseIntLiteral(t.value),w.INT);case s.UINT:return new d(this.parseUintLiteral(t.value),w.UINT);case s.DOUBLE:return new d(parseFloat(t.value),w.DOUBLE);case s.STRING:return new d(this.parseStringLiteral(t.value),w.STRING);case s.BYTES:return new d(this.parseBytesLiteral(t.value),w.BYTES);default:throw new p(`Not a literal: ${t.value}`,t.line,t.column)}}parseIntLiteral(t){return t.startsWith("-0x")||t.startsWith("-0X")?-parseInt(t.substring(3),16):t.startsWith("0x")||t.startsWith("0X")?parseInt(t.substring(2),16):parseInt(t,10)}parseUintLiteral(t){const e=t.substring(0,t.length-1);return e.startsWith("0x")||e.startsWith("0X")?parseInt(e.substring(2),16):parseInt(e,10)}parseStringLiteral(t){const e=t.startsWith("r")||t.startsWith("R");let i;return e&&(t.substring(1).startsWith('"""')||t.substring(1).startsWith("'''"))?i=t.substring(4,t.length-3):t.startsWith('"""')||t.startsWith("'''")?(i=t.substring(3,t.length-3),i=this.unescapeString(i)):e?i=t.substring(2,t.length-1):(i=t.substring(1,t.length-1),i=this.unescapeString(i)),i}parseBytesLiteral(t){const e=t.substring(2,t.length-1);return this.unescapeString(e)}unescapeString(t){let e="",i=0;for(;i<t.length;)if(t[i]==="\\"&&i+1<t.length){const n=t[i+1];switch(n){case"\\":e+="\\",i+=2;break;case'"':e+='"',i+=2;break;case"'":e+="'",i+=2;break;case"`":e+="`",i+=2;break;case"?":e+="?",i+=2;break;case"a":e+="\x07",i+=2;break;case"b":e+="\b",i+=2;break;case"f":e+="\f",i+=2;break;case"n":e+=`
5
- `,i+=2;break;case"r":e+="\r",i+=2;break;case"t":e+=" ",i+=2;break;case"v":e+="\v",i+=2;break;case"x":if(i+3<t.length){const o=t.substring(i+2,i+4);e+=String.fromCharCode(parseInt(o,16)),i+=4}else e+=t[i],i++;break;case"u":if(i+5<t.length){const o=t.substring(i+2,i+6);e+=String.fromCharCode(parseInt(o,16)),i+=6}else e+=t[i],i++;break;case"U":if(i+9<t.length){const o=t.substring(i+2,i+10),l=parseInt(o,16);e+=String.fromCodePoint(l),i+=10}else e+=t[i],i++;break;default:if(i+3<t.length&&n>="0"&&n<="3"&&t[i+2]>="0"&&t[i+2]<="7"&&t[i+3]>="0"&&t[i+3]<="7"){const o=t.substring(i+1,i+4);e+=String.fromCharCode(parseInt(o,8)),i+=4}else e+=t[i],i++}}else e+=t[i],i++;return e}isLiteralToken(t){return t===s.NULL||t===s.TRUE||t===s.FALSE||t===s.INT||t===s.UINT||t===s.DOUBLE||t===s.STRING||t===s.BYTES}isRelationalOp(t){return t===s.LT||t===s.LE||t===s.GT||t===s.GE||t===s.EQ||t===s.NE||t===s.IN}toBinaryOp(t){switch(t){case s.LT:return u.LESS;case s.LE:return u.LESS_EQUAL;case s.GT:return u.GREATER;case s.GE:return u.GREATER_EQUAL;case s.EQ:return u.EQUAL;case s.NE:return u.NOT_EQUAL;case s.IN:return u.IN;default:throw new p(`Unknown relational operator: ${t}`,this.current.line,this.current.column)}}match(t){return this.current.type===t?(this.advance(),!0):!1}expect(t){if(this.current.type!==t)throw new p(`Expected ${t} but found ${this.current.type}`,this.current.line,this.current.column);this.advance()}expectIdentifier(){if(this.current.type!==s.IDENTIFIER)throw new p(`Expected identifier but found ${this.current.value}`,this.current.line,this.current.column);const t=this.current.value;return this.advance(),t}advance(){this.current=this.lexer.next()}peekAhead(t){return this.lexer.peek(t)}isQualifiedStructLiteral(){let t=1,e=this.peekAhead(t);if(e.type!==s.IDENTIFIER)return!1;for(t++,e=this.peekAhead(t);e.type===s.DOT;){if(t++,e=this.peekAhead(t),e.type!==s.IDENTIFIER)return!1;t++,e=this.peekAhead(t)}return e.type===s.LBRACE}}class a extends Error{constructor(t){super(t),this.name="EvaluationError"}}function C(r){if(r==null)return 0;if(typeof r=="string"||Array.isArray(r))return r.length;if(typeof r=="object"&&r!==null)return Object.keys(r).length;throw new Error(`size() not supported for type: ${typeof r}`)}function O(r){if(typeof r=="number")return Math.trunc(r);if(typeof r=="string"){const t=parseInt(r,10);if(isNaN(t))throw new Error(`Cannot convert to int: ${r}`);return t}if(typeof r=="boolean")return r?1:0;throw new Error(`Cannot convert to int: ${r}`)}function P(r){const t=O(r);if(t<0)throw new Error(`Cannot convert negative value to uint: ${r}`);return t}function _(r){if(typeof r=="number")return r;if(typeof r=="string"){const t=parseFloat(r);if(isNaN(t))throw new Error(`Cannot convert to double: ${r}`);return t}throw new Error(`Cannot convert to double: ${r}`)}function k(r){return r==null?"null":String(r)}function U(r){return typeof r=="boolean"?r:typeof r=="number"?r!==0:typeof r=="string"||Array.isArray(r)?r.length>0:typeof r=="object"&&r!==null?Object.keys(r).length>0:r!=null}function F(r){return r==null?"null":typeof r=="boolean"?"bool":typeof r=="number"?Number.isInteger(r)?"int":"double":typeof r=="string"?"string":Array.isArray(r)?"list":typeof r=="object"?"map":"unknown"}function Q(r,t){return typeof r=="object"&&r!==null&&typeof t=="string"?t in r:!1}function q(r,t){try{return new RegExp(t).test(r)}catch{throw new Error(`Invalid regex pattern: ${t}`)}}function W(r){if(r.length===0)throw new Error("max() requires at least one argument");let t=r[0];for(let e=1;e<r.length;e++)E(r[e],t)>0&&(t=r[e]);return t}function j(r){if(r.length===0)throw new Error("min() requires at least one argument");let t=r[0];for(let e=1;e<r.length;e++)E(r[e],t)<0&&(t=r[e]);return t}function E(r,t){if(r===null&&t===null)return 0;if(r===null)return-1;if(t===null)return 1;if(typeof r=="number"&&typeof t=="number")return r-t;if(typeof r=="string"&&typeof t=="string")return r.localeCompare(t);if(typeof r=="boolean"&&typeof t=="boolean")return r===t?0:r?1:-1;if(Array.isArray(r)&&Array.isArray(t)){const e=Math.min(r.length,t.length);for(let i=0;i<e;i++){const n=E(r[i],t[i]);if(n!==0)return n}return r.length-t.length}throw new Error(`Cannot compare types: ${typeof r} and ${typeof t}`)}function g(r,t){if(r==null||t===null||t===void 0)return r===t;if(Array.isArray(r)&&Array.isArray(t)){if(r.length!==t.length)return!1;for(let e=0;e<r.length;e++)if(!g(r[e],t[e]))return!1;return!0}if(typeof r=="object"&&typeof t=="object"&&!Array.isArray(r)&&!Array.isArray(t)){const e=Object.keys(r),i=Object.keys(t);if(e.length!==i.length)return!1;for(const n of e)if(!(n in t)||!g(r[n],t[n]))return!1;return!0}return r===t}function K(r,t){for(const e of r)if(g(e,t))return!0;return!1}const Z=Object.freeze(Object.defineProperty({__proto__:null,asBool:U,asDouble:_,asInt:O,asString:k,asUInt:P,compare:E,containsInArray:K,deepEquals:g,has:Q,matches:q,max:W,min:j,sizeOf:C,typeOf:F},Symbol.toStringTag,{value:"Module"}));class v{callFunction(t,e){switch(t){case"size":return C(e[0]);case"int":return O(e[0]);case"uint":return P(e[0]);case"double":return _(e[0]);case"string":return k(e[0]);case"bool":return U(e[0]);case"type":return F(e[0]);case"has":if(e.length!==2)throw new Error("has() requires 2 arguments");return Q(e[0],e[1]);case"matches":if(e.length!==2)throw new Error("matches() requires 2 arguments");return q(e[0],e[1]);case"max":return W(e);case"min":return j(e);default:throw new Error(`Unknown function: ${t}`)}}callMethod(t,e,i){if(t==null)throw new Error("Cannot call method on null");switch(e){case"contains":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.includes(i[0]);if(Array.isArray(t)&&i.length===1)return t.includes(i[0]);throw new Error("Invalid arguments for contains()");case"startsWith":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.startsWith(i[0]);throw new Error("startsWith() requires string target and argument");case"endsWith":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.endsWith(i[0]);throw new Error("endsWith() requires string target and argument");case"toLowerCase":if(typeof t=="string"&&i.length===0)return t.toLowerCase();throw new Error("toLowerCase() requires string target");case"toUpperCase":if(typeof t=="string"&&i.length===0)return t.toUpperCase();throw new Error("toUpperCase() requires string target");case"trim":if(typeof t=="string"&&i.length===0)return t.trim();throw new Error("trim() requires string target");case"replace":if(typeof t=="string"&&i.length===2&&typeof i[0]=="string"&&typeof i[1]=="string")return t.replaceAll(i[0],i[1]);throw new Error("replace() requires string target and 2 string arguments");case"split":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.split(i[0]);throw new Error("split() requires string target and separator");case"size":return C(t);case"map":case"filter":case"all":case"exists":case"existsOne":throw new a(`Macro function ${e} was not properly handled by the interpreter`);default:return this.callNativeMethod(t,e,i)}}callNativeMethod(t,e,i){if(typeof t[e]=="function")try{return t[e](...i)}catch(n){throw new a(`Invocation of method '${e}' failed: ${n instanceof Error?n.message:String(n)}`)}throw new Error(`No such method '${e}' on type ${typeof t} with ${i.length} argument(s)`)}}class z{constructor(t,e){this.variables=t??{},this.functions=e??new v}evaluate(t){return t.accept(this)}visitLiteral(t){return t.value}visitIdentifier(t){if(!(t.name in this.variables))throw new a(`Undefined variable: ${t.name}`);return this.variables[t.name]}visitSelect(t){const e=t.operand!==null?this.evaluate(t.operand):this.variables;if(e==null){if(t.isTest)return!1;throw new a(`Cannot select field ${t.field} from null`)}if(typeof e=="object"){if(t.isTest)return t.field in e;if(!(t.field in e))throw new a(`Field ${t.field} not found`);return e[t.field]}throw new a("Cannot select field from non-object type")}visitCall(t){if(t.isMacro&&t.target!==null){const i=this.evaluate(t.target);if(t.args.length===0)throw new a(`Macro ${t.functionName} requires arguments`);const n=t.args[0];if(!(n instanceof S))throw new a(`First argument to macro ${t.functionName} must be a variable name`);const o=n.name;if(t.args.length<2)throw new a(`Macro ${t.functionName} requires an expression argument`);const l=t.args[1];return this.evaluateMacro(i,t.functionName,o,l)}const e=[];for(const i of t.args)e.push(this.evaluate(i));if(t.target!==null){const i=this.evaluate(t.target);return this.functions.callMethod(i,t.functionName,e)}else return this.functions.callFunction(t.functionName,e)}evaluateMacro(t,e,i,n){if(!Array.isArray(t))throw new a(`Macro ${e} requires a list target`);const o=this.variables[i],l=i in this.variables;try{switch(e){case"map":{const c=[];for(const f of t)this.variables[i]=f,c.push(this.evaluate(n));return c}case"filter":{const c=[];for(const f of t)this.variables[i]=f,this.evaluate(n)===!0&&c.push(f);return c}case"all":{for(const c of t)if(this.variables[i]=c,this.evaluate(n)!==!0)return!1;return!0}case"exists":{for(const c of t)if(this.variables[i]=c,this.evaluate(n)===!0)return!0;return!1}case"existsOne":{let c=0;for(const f of t)if(this.variables[i]=f,this.evaluate(n)===!0&&(c++,c>1))return!1;return c===1}default:throw new a(`Unknown macro function: ${e}`)}}finally{l?this.variables[i]=o:delete this.variables[i]}}visitList(t){const e=[];for(const i of t.elements)e.push(this.evaluate(i));return e}visitMap(t){const e={};for(const i of t.entries){const n=this.evaluate(i.key),o=this.evaluate(i.value);e[n]=o}return e}visitStruct(t){const e={};for(const i of t.fields)e[i.field]=this.evaluate(i.value);return e}visitComprehension(t){const e=this.evaluate(t.range);if(!Array.isArray(e))throw new a("Comprehension range must be a list");const i=this.variables[t.variable],n=this.variables[t.accumulator],o=t.variable in this.variables,l=t.accumulator in this.variables;try{let c=this.evaluate(t.initializer);this.variables[t.accumulator]=c;for(const f of e)this.variables[t.variable]=f,this.evaluate(t.condition)===!0&&(c=this.evaluate(t.step),this.variables[t.accumulator]=c);return this.evaluate(t.result)}finally{o?this.variables[t.variable]=i:delete this.variables[t.variable],l?this.variables[t.accumulator]=n:delete this.variables[t.accumulator]}}visitUnary(t){const e=this.evaluate(t.operand);switch(t.op){case A.NOT:if(typeof e!="boolean")throw new a("NOT operator requires boolean operand");return!e;case A.NEGATE:if(typeof e!="number")throw new a("Negation requires numeric operand");return-e;default:throw new a(`Unknown unary operator: ${t.op}`)}}visitBinary(t){if(t.op===u.LOGICAL_AND)return this.evaluate(t.left)!==!0?!1:this.evaluate(t.right)===!0;if(t.op===u.LOGICAL_OR)return this.evaluate(t.left)===!0?!0:this.evaluate(t.right)===!0;const e=this.evaluate(t.left),i=this.evaluate(t.right);switch(t.op){case u.ADD:if(typeof e=="string"||typeof i=="string")return String(e)+String(i);if(Array.isArray(e)&&Array.isArray(i))return[...e,...i];if(typeof e=="number"&&typeof i=="number")return e+i;throw new a("Invalid operands for addition");case u.SUBTRACT:if(typeof e=="number"&&typeof i=="number")return e-i;throw new a("Subtraction requires numeric operands");case u.MULTIPLY:if(typeof e=="number"&&typeof i=="number")return e*i;if(typeof e=="string"&&typeof i=="number")return e.repeat(i);if(Array.isArray(e)&&typeof i=="number"){const n=[];for(let o=0;o<i;o++)n.push(...e);return n}throw new a("Invalid operands for multiplication");case u.DIVIDE:if(typeof e=="number"&&typeof i=="number"){if(i===0)throw new a("Division by zero");return e/i}throw new a("Division requires numeric operands");case u.MODULO:if(typeof e=="number"&&typeof i=="number"){if(i===0)throw new a("Modulo by zero");return e%i}throw new a("Modulo requires integer operands");case u.EQUAL:return g(e,i);case u.NOT_EQUAL:return!g(e,i);case u.LESS:return E(e,i)<0;case u.LESS_EQUAL:return E(e,i)<=0;case u.GREATER:return E(e,i)>0;case u.GREATER_EQUAL:return E(e,i)>=0;case u.IN:if(Array.isArray(i))return K(i,e);if(typeof i=="object"&&i!==null)return e in i;if(typeof i=="string"&&typeof e=="string")return i.includes(e);throw new a("IN operator requires list, map, or string on right side");default:throw new a(`Unknown binary operator: ${t.op}`)}}visitConditional(t){return this.evaluate(t.condition)===!0?this.evaluate(t.thenExpr):this.evaluate(t.otherwiseExpr)}visitIndex(t){const e=this.evaluate(t.operand),i=this.evaluate(t.index);if(e==null)throw new a("Cannot index null value");if(Array.isArray(e)){if(typeof i!="number")throw new a("List index must be an integer");const n=Math.trunc(i);if(n<0||n>=e.length)throw new a(`List index out of bounds: ${n}`);return e[n]}else if(typeof e=="object"){if(!(i in e))throw new a(`Map key not found: ${i}`);return e[i]}else if(typeof e=="string"){if(typeof i!="number")throw new a("String index must be an integer");const n=Math.trunc(i);if(n<0||n>=e.length)throw new a(`String index out of bounds: ${n}`);return e[n]}throw new a(`Cannot index type: ${typeof e}`)}}class Y{constructor(t,e){this.ast=t,this.functions=e}evaluate(t={}){return new z({...t},this.functions).evaluate(this.ast)}}class I{constructor(t){this.functions=t??new v}static compile(t,e){const i=new $(t);return new Y(i.parse(),e)}static eval(t,e,i){return this.compile(t,e).evaluate(i)}compile(t){return I.compile(t,this.functions)}eval(t,e={}){return I.eval(t,this.functions,e)}}exports.Binary=L;exports.BinaryOp=u;exports.CEL=I;exports.Call=y;exports.Comprehension=V;exports.Conditional=G;exports.EvaluationError=a;exports.FieldInitializer=x;exports.Identifier=S;exports.Index=D;exports.Interpreter=z;exports.ListExpression=T;exports.Literal=d;exports.LiteralType=w;exports.MapEntry=B;exports.MapExpression=b;exports.ParseError=p;exports.Parser=$;exports.Program=Y;exports.Select=R;exports.StandardFunctions=v;exports.Struct=m;exports.Unary=N;exports.UnaryOp=A;exports.Utilities=Z;exports.asBool=U;
3
+ `?(this.line++,this.column=1):this.column++}forward(t){for(let n=0;n<t;n++)this.step()}token(){if(this.whitespace(),this.position>=this.input.length)return new w("EOF","",this.line,this.column);const t=this.position,n=this.line,i=this.column,r=this.input[this.position];switch(r){case"(":return this.step(),new w("LPAREN","(",n,i);case")":return this.step(),new w("RPAREN",")",n,i);case"[":return this.step(),new w("LBRACKET","[",n,i);case"]":return this.step(),new w("RBRACKET","]",n,i);case"{":return this.step(),new w("LBRACE","{",n,i);case"}":return this.step(),new w("RBRACE","}",n,i);case",":return this.step(),new w("COMMA",",",n,i);case".":return this.step(),new w("DOT",".",n,i);case":":return this.step(),new w("COLON",":",n,i);case"?":return this.step(),new w("QUESTION","?",n,i);case"+":return this.step(),new w("PLUS","+",n,i);case"*":return this.step(),new w("STAR","*",n,i);case"/":return this.step(),new w("SLASH","/",n,i);case"%":return this.step(),new w("PERCENT","%",n,i)}if(r==="&"&&this.peekChar()==="&")return this.forward(2),new w("LOGICAL_AND","&&",n,i);if(r==="|"&&this.peekChar()==="|")return this.forward(2),new w("LOGICAL_OR","||",n,i);if(r==="="&&this.peekChar()==="=")return this.forward(2),new w("EQ","==",n,i);if(r==="!"&&this.peekChar()==="=")return this.forward(2),new w("NE","!=",n,i);if(r==="<"&&this.peekChar()==="=")return this.forward(2),new w("LE","<=",n,i);if(r===">"&&this.peekChar()==="=")return this.forward(2),new w("GE",">=",n,i);if(r==="<")return this.step(),new w("LT","<",n,i);if(r===">")return this.step(),new w("GT",">",n,i);if(r==="!")return this.step(),new w("BANG","!",n,i);if(r==="-")return this.step(),new w("MINUS","-",n,i);if(r==='"'||r==="'")return this.string(n,i,t);if((r==="r"||r==="R")&&this.position+1<this.input.length){const s=this.input[this.position+1];if(s==='"'||s==="'")return this.string(n,i,t)}if((r==="b"||r==="B")&&this.position+1<this.input.length){const s=this.input[this.position+1];if(s==='"'||s==="'")return this.bytes(n,i,t)}if(this.isDigit(r))return this.number(n,i,t);if(this.isLetter(r)||r==="_")return this.identifier(n,i,t);throw new U(`Unexpected character: ${r}`,n,i)}string(t,n,i){let r=!1;if((this.input[this.position]==="r"||this.input[this.position]==="R")&&(r=!0,this.step()),this.position+2<this.input.length){const c=this.input.substring(this.position,this.position+3);if(c==='"""'||c==="'''"){const u=this.input[this.position];for(this.forward(3);this.position+2<this.input.length;){if(this.input[this.position]===u&&this.input[this.position+1]===u&&this.input[this.position+2]===u)return this.forward(3),new w("STRING",this.input.substring(i,this.position),t,n);this.step()}throw new U("Unterminated triple-quoted string",t,n)}}const s=this.input[this.position];for(this.step();this.position<this.input.length;){const c=this.input[this.position];if(c===s)return this.step(),new w("STRING",this.input.substring(i,this.position),t,n);c==="\\"&&!r&&this.position+1<this.input.length?this.forward(2):this.step()}throw new U("Unterminated string",t,n)}bytes(t,n,i){this.step();const r=this.input[this.position];for(this.step();this.position<this.input.length;){const s=this.input[this.position];if(s===r)return this.step(),new w("BYTES",this.input.substring(i,this.position),t,n);s==="\\"&&this.position+1<this.input.length?this.forward(2):this.step()}throw new U("Unterminated bytes literal",t,n)}number(t,n,i){if(this.input[this.position]==="0"&&this.position+1<this.input.length){const c=this.input[this.position+1];if(c==="x"||c==="X"){for(this.forward(2);this.position<this.input.length&&this.isHexDigit(this.input[this.position]);)this.step();if(this.position<this.input.length){const u=this.input[this.position];if(u==="u"||u==="U")return this.step(),new w("UINT",this.input.substring(i,this.position),t,n)}return new w("INT",this.input.substring(i,this.position),t,n)}}for(;this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step();let r=!1;if(this.position<this.input.length&&this.input[this.position]===".")for(r=!0,this.step();this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step();if(this.position<this.input.length){const c=this.input[this.position];if(c==="e"||c==="E"){if(r=!0,this.step(),this.position<this.input.length){const u=this.input[this.position];(u==="+"||u==="-")&&this.step()}for(;this.position<this.input.length&&this.isDigit(this.input[this.position]);)this.step()}}if(!r&&this.position<this.input.length){const c=this.input[this.position];if(c==="u"||c==="U")return this.step(),new w("UINT",this.input.substring(i,this.position),t,n)}const s=r?"DOUBLE":"INT";return new w(s,this.input.substring(i,this.position),t,n)}identifier(t,n,i){for(;this.position<this.input.length;){const c=this.input[this.position];if(!this.isLetterOrDigit(c)&&c!=="_")break;this.step()}const r=this.input.substring(i,this.position),s=this.typeOf(r);return new w(s,r,t,n)}typeOf(t){switch(t){case"null":return"NULL";case"true":return"TRUE";case"false":return"FALSE";case"in":return"IN";default:return"IDENTIFIER"}}whitespace(){for(;this.position<this.input.length;){const t=this.input[this.position];if(t!==" "&&t!==" "&&t!==`
4
+ `&&t!=="\r")break;this.step()}}peekChar(){const t=this.position+1;return t>=this.input.length?"\0":this.input[t]}isHexDigit(t){return t>="0"&&t<="9"||t>="a"&&t<="f"||t>="A"&&t<="F"}isDigit(t){return t>="0"&&t<="9"}isLetter(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isLetterOrDigit(t){return this.isLetter(t)||this.isDigit(t)}}var h=(e=>(e.ADD="ADD",e.SUBTRACT="SUBTRACT",e.MULTIPLY="MULTIPLY",e.DIVIDE="DIVIDE",e.MODULO="MODULO",e.EQUAL="EQUAL",e.NOT_EQUAL="NOT_EQUAL",e.LESS="LESS",e.LESS_EQUAL="LESS_EQUAL",e.GREATER="GREATER",e.GREATER_EQUAL="GREATER_EQUAL",e.IN="IN",e.LOGICAL_AND="LOGICAL_AND",e.LOGICAL_OR="LOGICAL_OR",e))(h||{}),V=(e=>(e.NOT="NOT",e.NEGATE="NEGATE",e))(V||{}),O=(e=>(e.NULL_VALUE="NULL_VALUE",e.BOOL="BOOL",e.INT="INT",e.UINT="UINT",e.DOUBLE="DOUBLE",e.STRING="STRING",e.BYTES="BYTES",e))(O||{});class j{constructor(t,n){this.value=t,this.literalType=n}accept(t){return t.visitLiteral(this)}}class ct{constructor(t){this.name=t}accept(t){return t.visitIdentifier(this)}}class Z{constructor(t,n,i=!1){this.operand=t,this.field=n,this.isTest=i}accept(t){return t.visitSelect(this)}}class un{constructor(t,n){this.operand=t,this.index=n}accept(t){return t.visitIndex(this)}}class st{constructor(t,n,i,r=!1){this.target=t,this.functionName=n,this.args=i,this.isMacro=r}accept(t){return t.visitCall(this)}}class an{constructor(t){this.elements=t}accept(t){return t.visitList(this)}}class hn{constructor(t,n){this.key=t,this.value=n}}class $t{constructor(t){this.entries=t}accept(t){return t.visitMap(this)}}class fn{constructor(t,n){this.field=t,this.value=n}}class Mt{constructor(t,n){this.typeName=t,this.fields=n}accept(t){return t.visitStruct(this)}}class Ce{constructor(t,n,i,r,s,c,u){this.variable=t,this.range=n,this.accumulator=i,this.initializer=r,this.condition=s,this.step=c,this.result=u}accept(t){return t.visitComprehension(this)}}class ut{constructor(t,n){this.op=t,this.operand=n}accept(t){return t.visitUnary(this)}}class H{constructor(t,n,i){this.op=t,this.left=n,this.right=i}accept(t){return t.visitBinary(this)}}class xt{constructor(t,n,i){this.condition=t,this.thenExpr=n,this.otherwiseExpr=i}accept(t){return t.visitConditional(this)}}const Ue=new TextEncoder,Be=new TextDecoder("utf-8");function B(e){return e instanceof Uint8Array}function bt(e){return Ue.encode(e)}function Pt(e){return Be.decode(e)}function ln(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function pn(e,t){const n=Math.min(e.length,t.length);for(let i=0;i<n;i++){const r=e[i]<<24>>24,s=t[i]<<24>>24;if(r!==s)return r<s?-1:1}return e.length-t.length}function dn(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}function at(e){let t="";for(const n of e)t+=n.toString(16).padStart(2,"0");return t}class l extends Error{constructor(t){super(t),this.name="EvaluationError"}}class a extends Error{constructor(t){super(t),this.name="ArgumentError"}}function Vt(e){return e instanceof l||e instanceof a}const K=-(2n**63n),it=2n**63n-1n;function Te(e){return typeof e=="bigint"}function De(e){return typeof e=="number"}function M(e){return typeof e=="bigint"||typeof e=="number"}function wn(e){if(e<K||e>it)throw new l("Integer overflow");return e}function gn(e){return Number.isNaN(e)?0n:e>=2**63?it:e<=-9223372036854776e3?K:BigInt(Math.trunc(e))}function Zt(e){return e===0?0:e}function Jt(e,t){const n=Zt(e),i=Zt(t);if(n<i)return-1;if(n>i)return 1;const r=Number.isNaN(n),s=Number.isNaN(i);return r&&s?0:r?1:s?-1:0}function vt(e,t){if(Number.isInteger(t)){const i=BigInt(t);return e<i?-1:e>i?1:0}const n=BigInt(Math.floor(t));return e<=n?-1:1}function mt(e,t){if(typeof e=="bigint"&&typeof t=="bigint")return e<t?-1:e>t?1:0;if(typeof e=="number"&&typeof t=="number")return Jt(e,t);const n=typeof e=="number"?e:t;return Number.isFinite(n)?typeof e=="bigint"?vt(e,t):-vt(t,e):Jt(Number(e),Number(t))}function kt(e){if(Number.isNaN(e))return"NaN";if(e===1/0)return"Infinity";if(e===-1/0)return"-Infinity";if(e===0)return Object.is(e,-0)?"-0.0":"0.0";const t=Math.abs(e);if(t>=.001&&t<1e7){const s=String(e);return s.includes(".")?s:s+".0"}const[n,i]=e.toExponential().split("e");return`${n.includes(".")?n:n+".0"}E${i.replace("+","")}`}const xe=new Set(["map","filter","all","exists","existsOne","sortBy"]),Pe=256;class bn{constructor(t){this.depth=0,this.lexer=new Me(t),this.current=this.lexer.next()}parse(){const t=this.parseExpr();if(this.current.type!==o.EOF)throw new U(`Unexpected token after expression: ${this.current.value}`,this.current.line,this.current.column);return t}parseExpr(){if(++this.depth>Pe)throw new U("Expression nesting too deep",this.current.line,this.current.column);try{const t=this.parseConditionalOr();if(this.match(o.QUESTION)){const n=this.parseConditionalOr();this.expect(o.COLON);const i=this.parseExpr();return new xt(t,n,i)}return t}finally{this.depth--}}parseConditionalOr(){let t=this.parseConditionalAnd();for(;this.match(o.LOGICAL_OR);){const n=this.parseConditionalAnd();t=new H(h.LOGICAL_OR,t,n)}return t}parseConditionalAnd(){let t=this.parseRelation();for(;this.match(o.LOGICAL_AND);){const n=this.parseRelation();t=new H(h.LOGICAL_AND,t,n)}return t}parseRelation(){let t=this.parseAddition();for(;this.isRelationalOp(this.current.type);){const n=this.current.type;this.advance();const i=this.parseAddition();t=new H(this.toBinaryOp(n),t,i)}return t}parseAddition(){let t=this.parseMultiplication();for(;this.current.type===o.PLUS||this.current.type===o.MINUS;){const n=this.current.type;this.advance();const i=this.parseMultiplication();t=new H(n===o.PLUS?h.ADD:h.SUBTRACT,t,i)}return t}parseMultiplication(){let t=this.parseUnary();for(;this.current.type===o.STAR||this.current.type===o.SLASH||this.current.type===o.PERCENT;){const n=this.current.type;this.advance();const i=this.parseUnary(),r=n===o.STAR?h.MULTIPLY:n===o.SLASH?h.DIVIDE:h.MODULO;t=new H(r,t,i)}return t}parseUnary(){return this.current.type===o.BANG?(this.advance(),new ut(V.NOT,this.parseUnary())):this.current.type===o.MINUS?(this.advance(),new ut(V.NEGATE,this.parseUnary())):this.parseMember()}parseMember(){let t=this.parsePrimary();for(;;)if(this.current.type===o.DOT){this.advance();const n=this.expectIdentifier();if(this.current.type===o.LPAREN){this.advance();const i=this.parseExprList();this.expect(o.RPAREN);const r=xe.has(n);t=new st(t,n,i,r)}else t=new Z(t,n)}else if(this.current.type===o.LBRACKET){this.advance();const n=this.parseExpr();this.expect(o.RBRACKET),t=new un(t,n)}else break;return t}parsePrimary(){if(this.isLiteralToken(this.current.type))return this.parseLiteral();if(this.current.type===o.LBRACKET)return this.parseListLiteral();if(this.current.type===o.LBRACE)return this.parseMapOrStructLiteral(null);if(this.current.type===o.LPAREN){this.advance();const t=this.parseExpr();return this.expect(o.RPAREN),t}if(this.current.type===o.DOT){this.advance();const t=this.expectIdentifier();if(this.current.type===o.LPAREN){this.advance();const n=this.parseExprList();return this.expect(o.RPAREN),new st(null,t,n)}return new Z(null,t)}if(this.current.type===o.IDENTIFIER){const t=this.current.value;if(this.advance(),this.current.type===o.LPAREN){const n=this.current.line,i=this.current.column;this.advance();const r=this.parseExprList();return this.expect(o.RPAREN),t==="has"&&r.length===1?this.test(r[0],n,i):new st(null,t,r)}if(this.current.type===o.DOT&&this.isQualifiedStructLiteral()){const n=this.parseQualifiedIdent(t);return this.parseMapOrStructLiteral(n)}return this.current.type===o.LBRACE?this.parseMapOrStructLiteral(t):new ct(t)}throw new U(`Unexpected token: ${this.current.value}`,this.current.line,this.current.column)}test(t,n,i){if(t instanceof Z)return new Z(t.operand,t.field,!0);throw new U("has() requires a field selection, for example has(a.b)",n,i)}parseListLiteral(){this.expect(o.LBRACKET);const t=[];return this.current.type!==o.RBRACKET&&(t.push(...this.parseExprList()),this.current.type===o.COMMA&&this.advance()),this.expect(o.RBRACKET),new an(t)}parseMapOrStructLiteral(t){if(this.expect(o.LBRACE),this.current.type===o.RBRACE)return this.advance(),t!==null?new Mt(t,[]):new $t([]);if(this.current.type===o.IDENTIFIER&&this.peekAhead(1).type===o.COLON||t!==null){const i=this.parseFieldInits();return this.current.type===o.COMMA&&this.advance(),this.expect(o.RBRACE),new Mt(t,i)}else{const i=this.parseMapInits();return this.current.type===o.COMMA&&this.advance(),this.expect(o.RBRACE),new $t(i)}}parseExprList(){const t=[],n=this.current.type;if(n===o.RPAREN||n===o.RBRACKET)return t;for(t.push(this.parseExpr());this.current.type===o.COMMA&&(this.advance(),!(this.current.type===o.RPAREN||this.current.type===o.RBRACKET));)t.push(this.parseExpr());return t}parseMapInits(){const t=[];for(t.push(this.parseMapInit());this.current.type===o.COMMA&&(this.advance(),this.current.type!==o.RBRACE);)t.push(this.parseMapInit());return t}parseMapInit(){const t=this.parseExpr();this.expect(o.COLON);const n=this.parseExpr();return new hn(t,n)}parseFieldInits(){const t=[];for(t.push(this.parseFieldInit());this.current.type===o.COMMA&&(this.advance(),this.current.type!==o.RBRACE);)t.push(this.parseFieldInit());return t}parseFieldInit(){const t=this.expectIdentifier();this.expect(o.COLON);const n=this.parseExpr();return new fn(t,n)}parseQualifiedIdent(t){let n=t;for(;this.current.type===o.DOT;)this.advance(),n+=".",n+=this.expectIdentifier();return n}parseLiteral(){const t=this.current;switch(this.advance(),t.type){case o.NULL:return new j(null,O.NULL_VALUE);case o.TRUE:return new j(!0,O.BOOL);case o.FALSE:return new j(!1,O.BOOL);case o.INT:return new j(this.parseIntLiteral(t),O.INT);case o.UINT:return new j(this.parseUintLiteral(t),O.UINT);case o.DOUBLE:return new j(Number(t.value),O.DOUBLE);case o.STRING:return new j(this.parseStringLiteral(t.value),O.STRING);case o.BYTES:return new j(this.parseBytesLiteral(t.value),O.BYTES);default:throw new U(`Not a literal: ${t.value}`,t.line,t.column)}}parseIntLiteral(t){const n=t.value,i=n.startsWith("-"),r=i?n.substring(1):n,s=BigInt(r);return this.checkRange(i?-s:s,t)}parseUintLiteral(t){const n=t.value.substring(0,t.value.length-1);return this.checkRange(BigInt(n),t)}checkRange(t,n){if(t<K||t>it)throw new U(`Integer literal out of range: ${n.value}`,n.line,n.column);return t}parseStringLiteral(t){const n=t.startsWith("r")||t.startsWith("R");let i;return n&&(t.substring(1).startsWith('"""')||t.substring(1).startsWith("'''"))?i=t.substring(4,t.length-3):t.startsWith('"""')||t.startsWith("'''")?(i=t.substring(3,t.length-3),i=this.unescapeString(i)):n?i=t.substring(2,t.length-1):(i=t.substring(1,t.length-1),i=this.unescapeString(i)),i}parseBytesLiteral(t){const n=t.substring(2,t.length-1);return this.unescapeBytes(n)}unescapeBytes(t){const n=[];let i="";const r=()=>{i.length>0&&(n.push(...bt(i)),i="")};let s=0;for(;s<t.length;){if(t[s]!=="\\"||s+1>=t.length){i+=t[s],s++;continue}const c=t[s+1],u=this.simpleEscape(c);u!==null?(i+=u,s+=2):c==="x"&&s+4<=t.length?(r(),n.push(parseInt(t.substring(s+2,s+4),16)),s+=4):c==="u"&&s+6<=t.length?(i+=String.fromCharCode(parseInt(t.substring(s+2,s+6),16)),s+=6):c==="U"&&s+10<=t.length?(i+=String.fromCodePoint(parseInt(t.substring(s+2,s+10),16)),s+=10):this.isOctal(t,s)?(r(),n.push(parseInt(t.substring(s+1,s+4),8)),s+=4):(i+=t[s],s++)}return r(),Uint8Array.from(n)}simpleEscape(t){switch(t){case"\\":return"\\";case'"':return'"';case"'":return"'";case"`":return"`";case"?":return"?";case"a":return"\x07";case"b":return"\b";case"f":return"\f";case"n":return`
5
+ `;case"r":return"\r";case"t":return" ";case"v":return"\v";default:return null}}isOctal(t,n){return n+3<t.length&&t[n+1]>="0"&&t[n+1]<="3"&&t[n+2]>="0"&&t[n+2]<="7"&&t[n+3]>="0"&&t[n+3]<="7"}unescapeString(t){let n="",i=0;for(;i<t.length;)if(t[i]==="\\"&&i+1<t.length){const r=t[i+1];switch(r){case"\\":n+="\\",i+=2;break;case'"':n+='"',i+=2;break;case"'":n+="'",i+=2;break;case"`":n+="`",i+=2;break;case"?":n+="?",i+=2;break;case"a":n+="\x07",i+=2;break;case"b":n+="\b",i+=2;break;case"f":n+="\f",i+=2;break;case"n":n+=`
6
+ `,i+=2;break;case"r":n+="\r",i+=2;break;case"t":n+=" ",i+=2;break;case"v":n+="\v",i+=2;break;case"x":if(i+3<t.length){const s=t.substring(i+2,i+4);n+=String.fromCharCode(parseInt(s,16)),i+=4}else n+=t[i],i++;break;case"u":if(i+5<t.length){const s=t.substring(i+2,i+6);n+=String.fromCharCode(parseInt(s,16)),i+=6}else n+=t[i],i++;break;case"U":if(i+9<t.length){const s=t.substring(i+2,i+10),c=parseInt(s,16);n+=String.fromCodePoint(c),i+=10}else n+=t[i],i++;break;default:if(i+3<t.length&&r>="0"&&r<="3"&&t[i+2]>="0"&&t[i+2]<="7"&&t[i+3]>="0"&&t[i+3]<="7"){const s=t.substring(i+1,i+4);n+=String.fromCharCode(parseInt(s,8)),i+=4}else n+=t[i],i++}}else n+=t[i],i++;return n}isLiteralToken(t){return t===o.NULL||t===o.TRUE||t===o.FALSE||t===o.INT||t===o.UINT||t===o.DOUBLE||t===o.STRING||t===o.BYTES}isRelationalOp(t){return t===o.LT||t===o.LE||t===o.GT||t===o.GE||t===o.EQ||t===o.NE||t===o.IN}toBinaryOp(t){switch(t){case o.LT:return h.LESS;case o.LE:return h.LESS_EQUAL;case o.GT:return h.GREATER;case o.GE:return h.GREATER_EQUAL;case o.EQ:return h.EQUAL;case o.NE:return h.NOT_EQUAL;case o.IN:return h.IN;default:throw new U(`Unknown relational operator: ${t}`,this.current.line,this.current.column)}}match(t){return this.current.type===t?(this.advance(),!0):!1}expect(t){if(this.current.type!==t)throw new U(`Expected ${t} but found ${this.current.type}`,this.current.line,this.current.column);this.advance()}expectIdentifier(){if(this.current.type!==o.IDENTIFIER)throw new U(`Expected identifier but found ${this.current.value}`,this.current.line,this.current.column);const t=this.current.value;return this.advance(),t}advance(){this.current=this.lexer.next()}peekAhead(t){return this.lexer.peek(t)}isQualifiedStructLiteral(){let t=1,n=this.peekAhead(t);if(n.type!==o.IDENTIFIER)return!1;for(t++,n=this.peekAhead(t);n.type===o.DOT;){if(t++,n=this.peekAhead(t),n.type!==o.IDENTIFIER)return!1;t++,n=this.peekAhead(t)}return n.type===o.LBRACE}}const p=class p{constructor(t){this.name=t}static of(t){return p.BY_NAME.get(t)??null}static isType(t){return t instanceof p}equals(t){return t instanceof p&&t.name===this.name}toString(){return this.name}};p.NULL=new p("null_type"),p.BOOL=new p("bool"),p.INT=new p("int"),p.UINT=new p("uint"),p.DOUBLE=new p("double"),p.STRING=new p("string"),p.BYTES=new p("bytes"),p.LIST=new p("list"),p.MAP=new p("map"),p.TIMESTAMP=new p("timestamp"),p.DURATION=new p("duration"),p.TYPE=new p("type"),p.UNKNOWN=new p("unknown"),p.BY_NAME=new Map([p.NULL,p.BOOL,p.INT,p.UINT,p.DOUBLE,p.STRING,p.BYTES,p.LIST,p.MAP,p.TIMESTAMP,p.DURATION,p.TYPE].map(t=>[t.name,t]));let N=p;const ht=86400n;function Gt(e,t){const n=e/t;return e%t!==0n&&e<0n!=t<0n?n-1n:n}function ft(e,t){const n=e%t;return n!==0n&&n<0n!=t<0n?n+t:n}function Et(e,t,n){const i=t<=2?e-1n:e,r=(i>=0n?i:i-399n)/400n,s=i-r*400n,u=(153n*(BigInt(t)+(t>2?-3n:9n))+2n)/5n+BigInt(n)-1n,d=s*365n+s/4n-s/100n+u;return r*146097n+d-719468n}function mn(e){const t=e+719468n,n=(t>=0n?t:t-146096n)/146097n,i=t-n*146097n,r=(i-i/1460n+i/36524n-i/146096n)/365n,s=r+n*400n,c=i-(365n*r+r/4n-r/100n),u=(5n*c+2n)/153n,d=Number(c-(153n*u+2n)/5n+1n),E=Number(u<10n?u+3n:u-9n);return{year:E<=2?s+1n:s,month:E,day:d}}function ke(e){return e%4n===0n&&(e%100n!==0n||e%400n===0n)}function Ge(e,t){switch(t){case 2:return ke(e)?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}}function lt(e){const t=Gt(e,ht),n=Number(ft(e,ht)),{year:i,month:r,day:s}=mn(t);return{year:i,month:r,day:s,hour:Math.floor(n/3600),minute:Math.floor(n%3600/60),second:n%60,weekday:Number(ft(t+4n,7n)),dayOfYear:Number(t-Et(i,1,1))+1}}const tn=new Map;function qe(e){if(typeof e!="string")throw new a(`Time zone must be a string: ${String(e)}`);const t=tn.get(e);if(t)return t;let n;try{n=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",era:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}catch{throw new a(`Invalid time zone: ${e}`)}return tn.set(e,n),n}const nn=8640000000000n;function Fe(e,t){if(t>nn||t<-nn)throw new l("Timestamp out of range for time zone conversion");const n=e.formatToParts(new Date(Number(t)*1e3)),i=u=>n.find(d=>d.type===u)?.value??"0";let r=BigInt(i("year"));i("era").startsWith("B")&&(r=1n-r);const s=Number(i("hour"))%24;return Et(r,Number(i("month")),Number(i("day")))*ht+BigInt(s*3600+Number(i("minute"))*60+Number(i("second")))-t}function En(e,t){if(t==null)return lt(e);const n=qe(t);return lt(e+Fe(n,e))}const _=1000000000n,je=/^-?(?:\d+(?:\.\d+)?(?:ns|us|µs|ms|s|m|h))+$/,Qe=/(\d+)(?:\.(\d+))?(ns|us|µs|ms|s|m|h)/g,ze={ns:1n,us:1000n,µs:1000n,ms:1000000n,s:_,m:_*60n,h:_*3600n},S=class S{constructor(t,n){this.seconds=t,this.nanos=n}static ofSeconds(t,n=0n){const i=t+Gt(n,_),r=Number(ft(n,_));return new S(i,r)}static ofNanos(t){return S.ofSeconds(0n,t)}static ofMillis(t){return S.ofSeconds(0n,t*1000000n)}static ofMinutes(t){return new S(t*60n,0)}static ofHours(t){return new S(t*3600n,0)}static parse(t){if(!je.test(t))throw new a(`Invalid duration format: ${t}`);const n=Array.from(t.matchAll(Qe)),i=Math.max(0,...n.map(E=>E[2]?.length??0)),r=10n**BigInt(i);let s=0n;for(const E of n){const b=E[1],A=E[2]??"",L=BigInt(b+A)*10n**BigInt(i-A.length);s+=L*ze[E[3]]}let c=s/r;s%r*2n>=r&&(c+=1n);const u=c/_;if(u>S.SPAN)throw new a(`Duration out of range: ${t}`);const d=S.ofSeconds(u,c%_);return t.startsWith("-")?d.negated():d}static isDuration(t){return t instanceof S}isNegative(){return this.seconds<0n}isZero(){return this.seconds===0n&&this.nanos===0}negated(){return S.ofSeconds(-this.seconds,-BigInt(this.nanos))}plus(t){return S.ofSeconds(this.seconds+t.seconds,BigInt(this.nanos+t.nanos))}minus(t){return S.ofSeconds(this.seconds-t.seconds,BigInt(this.nanos-t.nanos))}toNanos(){return this.seconds*_+BigInt(this.nanos)}toMillis(){return this.toNanos()/1000000n}toSeconds(){return this.seconds}toMinutes(){return this.seconds/60n}toHours(){return this.seconds/3600n}compareTo(t){return this.seconds!==t.seconds?this.seconds<t.seconds?-1:1:this.nanos-t.nanos}equals(t){return t instanceof S&&t.seconds===this.seconds&&t.nanos===this.nanos}toString(){if(this.isNegative())return"-"+this.negated().toString();if(this.nanos===0)return`${this.seconds}s`;const t=String(this.nanos).padStart(9,"0").replace(/0+$/,"");return`${this.seconds}.${t}s`}};S.SPAN=315576000000n,S.ZERO=new S(0n,0);let I=S;const en=1000000000n,Ye=/^([+-]?\d{4,9})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?([Zz]|[+-]\d{2}:\d{2})$/,C=class C{constructor(t,n){this.seconds=t,this.nanos=n}static ofEpochSeconds(t,n=0n){const i=t+Gt(n,en),r=Number(ft(n,en));if(i<C.MIN_SECONDS||i>C.MAX_SECONDS)throw new a(`Timestamp out of range: ${t}`);return new C(i,r)}static ofEpochMillis(t){return C.ofEpochSeconds(0n,t*1000000n)}static fromDate(t){const n=t.getTime();if(Number.isNaN(n))throw new a("Invalid timestamp value: Invalid Date");return C.ofEpochMillis(BigInt(n))}static now(){return C.ofEpochMillis(BigInt(Date.now()))}static parse(t){const n=Ye.exec(t);if(!n)throw new a(`Invalid timestamp value: ${t}`);const i=BigInt(n[1]),r=Number(n[2]),s=Number(n[3]),c=Number(n[4]),u=Number(n[5]),d=Number(n[6]??"0"),E=Number((n[7]??"").padEnd(9,"0")),b=n[8];if(r<1||r>12||s<1||s>Ge(i,r)||c>23||u>59||d>59)throw new a(`Invalid timestamp value: ${t}`);let A=0n;if(b!=="Z"&&b!=="z"){const k=b.startsWith("-")?-1n:1n,St=Number(b.slice(1,3)),Xt=Number(b.slice(4,6));if(St>18||Xt>59)throw new a(`Invalid timestamp value: ${t}`);A=k*BigInt(St*3600+Xt*60)}const L=Et(i,r,s)*ht+BigInt(c*3600+u*60+d)-A;return C.ofEpochSeconds(L,BigInt(E))}static isTimestamp(t){return t instanceof C}toDate(){return new Date(Number(this.seconds)*1e3+Math.floor(this.nanos/1e6))}plus(t){return this.shift(t.seconds,t.nanos)}minus(t){return this.shift(-t.seconds,-t.nanos)}shift(t,n){try{return C.ofEpochSeconds(this.seconds+t,BigInt(this.nanos+n))}catch(i){throw i instanceof a?new l("Timestamp out of range"):i}}until(t){return I.ofSeconds(t.seconds-this.seconds,BigInt(t.nanos-this.nanos))}compareTo(t){return this.seconds!==t.seconds?this.seconds<t.seconds?-1:1:this.nanos-t.nanos}equals(t){return t instanceof C&&t.seconds===this.seconds&&t.nanos===this.nanos}toString(){const t=lt(this.seconds),n=s=>String(s).padStart(2,"0");let i;t.year>9999n?i="+"+t.year:t.year<0n?i="-"+String(-t.year).padStart(4,"0"):i=String(t.year).padStart(4,"0");let r="";return this.nanos!==0&&(this.nanos%1e6===0?r="."+String(this.nanos/1e6).padStart(3,"0"):this.nanos%1e3===0?r="."+String(this.nanos/1e3).padStart(6,"0"):r="."+String(this.nanos).padStart(9,"0")),`${i}-${n(t.month)}-${n(t.day)}T${n(t.hour)}:${n(t.minute)}:${n(t.second)}${r}Z`}};C.MIN_SECONDS=-31557014167219200n,C.MAX_SECONDS=31556889864403199n;let y=C,_e=0;const rn=new WeakMap;let Ke=0;function sn(e){let t=rn.get(e);return t===void 0&&(t=++Ke,rn.set(e,t)),t}function We(e){return Number.isNaN(e)?`nan:${++_e}`:e===0?"n:0":Number.isInteger(e)?`n:${BigInt(e)}`:`n:${e}`}function P(e){if(e==null)return"z";switch(typeof e){case"boolean":return e?"b:1":"b:0";case"string":return`s${e.length}:${e}`;case"bigint":return`n:${e}`;case"number":return We(e);case"object":break;default:return`o:${sn(e)}`}if(B(e))return`y:${at(e)}`;if(Array.isArray(e))return`[${e.map(P).join(",")}]`;if(e instanceof Map){const n=Array.from(e.entries(),([i,r])=>`${P(i)}=${P(r)}`);return n.sort(),`{${n.join(",")}}`}if(e instanceof y)return`t:${e.seconds}.${e.nanos}`;if(e instanceof I)return`d:${e.seconds}.${e.nanos}`;if(e instanceof N)return`T:${e.name}`;const t=Object.getPrototypeOf(e);if(t===Object.prototype||t===null){const n=Object.entries(e).map(([i,r])=>`${P(i)}=${P(r)}`);return n.sort(),`{${n.join(",")}}`}return`o:${sn(e)}`}class qt{constructor(){this.keys=new Set}add(t){const n=P(t);return this.keys.has(n)?!1:(this.keys.add(n),!0)}has(t){return this.keys.has(P(t))}get size(){return this.keys.size}}class In{constructor(){this.entries=new Map}set(t,n){this.entries.set(P(t),n)}get(t){return this.entries.get(P(t))}has(t){return this.entries.has(P(t))}get size(){return this.entries.size}}function Ct(e){return J(e,new Set,!0)}function ot(e){return J(e,new Set,!1)}function W(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function J(e,t,n){switch(typeof e){case"undefined":return null;case"number":return n&&Number.isInteger(e)?BigInt(e):e;case"bigint":case"string":case"boolean":return e;case"object":break;default:return e}return e===null?null:e instanceof Uint8Array||e instanceof y||e instanceof I||e instanceof N?e:e instanceof Date?y.fromDate(e):Array.isArray(e)?Ot(e,t,()=>e.map(i=>J(i,t,n))):e instanceof Map?Ot(e,t,()=>{const i=new Map;for(const[r,s]of e)i.set(J(r,t,n),J(s,t,n));return i}):W(e)?Ot(e,t,()=>{const i=new Map;for(const[r,s]of Object.entries(e))i.set(r,J(s,t,n));return i}):e}function Ot(e,t,n){if(t.has(e))throw new a("Cyclic value");t.add(e);try{return n()}finally{t.delete(e)}}const D=1e6,He=I.SPAN,Xe=/^[+-]?\d+$/,Ve=/^[+-]?(?:\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|Infinity|NaN)$/;function q(e,t){if(e>D)throw new l(`${t} exceeds the evaluation limit of ${D}`)}function Ze(e){return e instanceof Map}function It(e){let t=0;for(let n=0;n<e.length;n++){const i=e.charCodeAt(n);if(i>=55296&&i<=56319&&n+1<e.length){const r=e.charCodeAt(n+1);r>=56320&&r<=57343&&n++}t++}return t}function Ft(e,t){let n=0;for(let i=t;i>0;i--){if(n>=e.length)return-1;const r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){const s=e.charCodeAt(n+1);n+=s>=56320&&s<=57343?2:1}else n++}return n>e.length?-1:n}function Ut(e){if(e==null)return 0n;if(typeof e=="string")return BigInt(It(e));if(B(e)||Array.isArray(e))return BigInt(e.length);if(e instanceof Map)return BigInt(e.size);if(W(e))return BigInt(Object.keys(e).length);throw new a(`size() not supported for type: ${X(e)}`)}function g(e){if(typeof e=="bigint")return e;if(typeof e=="number")return gn(e);if(typeof e=="string"){if(Xe.test(e.trim())&&e.trim()===e){const t=BigInt(e);if(t>=K&&t<=it)return t}throw new a(`Cannot convert to int: ${e}`)}if(typeof e=="boolean")return e?1n:0n;if(e instanceof y)return e.seconds;throw new a(`Cannot convert to int: ${R(e)}`)}function yn(e){const t=g(e);if(t<0n)throw new a(`Cannot convert negative value to uint: ${R(e)}`);return t}function T(e){if(typeof e=="number")return e;if(typeof e=="bigint")return Number(e);if(typeof e=="string"){const t=e.trim();if(Ve.test(t))return Number(t);throw new a(`Cannot convert to double: ${e}`)}throw new a(`Cannot convert to double: ${R(e)}`)}function R(e){return e==null?"null":typeof e=="string"?e:typeof e=="number"?kt(e):typeof e=="bigint"||typeof e=="boolean"?String(e):B(e)?Pt(e):Array.isArray(e)?`[${e.map(R).join(", ")}]`:e instanceof Map?`{${Array.from(e,([t,n])=>`${R(t)}=${R(n)}`).join(", ")}}`:W(e)?`{${Object.entries(e).map(([t,n])=>`${t}=${R(n)}`).join(", ")}}`:String(e)}function yt(e){if(B(e))return e;if(typeof e=="string")return bt(e);throw new a(`Cannot convert to bytes: ${R(e)}`)}function jt(e){return typeof e=="boolean"?e:typeof e=="bigint"?e!==0n:typeof e=="number"?e!==0:typeof e=="string"||Array.isArray(e)?e.length>0:e instanceof Map?e.size>0:W(e)?Object.keys(e).length>0:e!=null}function X(e){if(e==null)return N.NULL;switch(typeof e){case"boolean":return N.BOOL;case"bigint":return N.INT;case"number":return N.DOUBLE;case"string":return N.STRING;case"object":break;default:return N.UNKNOWN}return B(e)?N.BYTES:e instanceof y?N.TIMESTAMP:e instanceof I?N.DURATION:Array.isArray(e)?N.LIST:e instanceof Map||W(e)?N.MAP:e instanceof N?N.TYPE:N.UNKNOWN}function Nn(e,t){return e instanceof Map?pt(e,t):W(e)?typeof t=="string"&&Object.prototype.hasOwnProperty.call(e,t):!1}function pt(e,t){if(e.has(t))return!0;for(const n of e.keys())if(Q(n,t))return!0;return!1}function An(e,t){if(e.has(t))return e.get(t);for(const[n,i]of e)if(Q(n,t))return i}function Bt(e,t){let n;try{n=new RegExp(t)}catch{throw new a(`Invalid regular expression: ${t}`)}return n.test(e)}function Qt(e){if(e==null)return y.now();if(e instanceof y)return e;if(e instanceof Date)return y.fromDate(e);if(typeof e=="string")return y.parse(e);if(typeof e=="bigint")return y.ofEpochSeconds(e);throw new a(`Invalid timestamp value: ${R(e)}`)}function Je(e){return I.parse(e)}function Ln(e){if(e instanceof I)return e;if(typeof e=="string")return I.parse(e);throw new a(`Cannot convert to duration: ${R(e)}`)}function z(e,t){const n=e instanceof y?e:Qt(e);return{instant:n,fields:En(n.seconds,t??null)}}function Sn(e,t=null){return BigInt(z(e,t).fields.day)}function On(e,t=null){return BigInt(z(e,t).fields.month-1)}function Rn(e,t=null){return z(e,t).fields.year}function $n(e,t=null){return e instanceof I?e.toHours():BigInt(z(e,t).fields.hour)}function Mn(e,t=null){return e instanceof I?e.toMinutes():BigInt(z(e,t).fields.minute)}function Cn(e,t=null){return e instanceof I?e.toSeconds():BigInt(z(e,t).fields.second)}function Un(e,t=null){return e instanceof I?e.toMillis():BigInt(Math.floor(z(e,t).instant.nanos/1e6))}function Bn(e,t=null){return BigInt(z(e,t).fields.weekday)}function Tn(e,t=null){return BigInt(z(e,t).fields.dayOfYear-1)}function zt(e){if(e.length===0)throw new a("max() requires at least one argument");let t=e[0];for(let n=1;n<e.length;n++)tt(e[n],t)>0&&(t=e[n]);return t}function Yt(e){if(e.length===0)throw new a("min() requires at least one argument");let t=e[0];for(let n=1;n<e.length;n++)tt(e[n],t)<0&&(t=e[n]);return t}function Q(e,t){if(e==null||t===null||t===void 0)return(e??null)===(t??null);if(B(e)&&B(t))return ln(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Q(e[r],t[r]))return!1;return!0}const n=on(e),i=on(t);if(n&&i){if(n.size!==i.size)return!1;const r=new In;for(const[s,c]of i)r.set(s,c);for(const[s,c]of n)if(!r.has(s)||!Q(c,r.get(s)))return!1;return!0}return(typeof e=="bigint"||typeof e=="number")&&(typeof t=="bigint"||typeof t=="number")?Number.isNaN(e)||Number.isNaN(t)?!1:mt(e,t)===0:e instanceof y||e instanceof I||e instanceof N?e.equals(t):e===t}function on(e){return e instanceof Map?e:W(e)?new Map(Object.entries(e)):null}const ve=Q;function tt(e,t){if((typeof e=="bigint"||typeof e=="number")&&(typeof t=="bigint"||typeof t=="number"))return mt(e,t);if(typeof e=="string"&&typeof t=="string")return e<t?-1:e>t?1:0;if(typeof e=="boolean"&&typeof t=="boolean")return e===t?0:e?1:-1;if(e instanceof y&&t instanceof y||e instanceof I&&t instanceof I)return e.compareTo(t);if(B(e)&&B(t))return pn(e,t);throw new a("Cannot compare values of different types")}function Nt(e,t){for(const n of e)if(Q(n,t))return!0;return!1}const ti=Object.freeze(Object.defineProperty({__proto__:null,LIMIT:D,SPAN:He,asBool:jt,asBytes:yt,asDouble:T,asDuration:Ln,asInt:g,asString:R,asUInt:yn,codePointCount:It,compare:tt,contains:pt,containsInArray:Nt,dateOf:Sn,deepEquals:ve,duration:Je,equals:Q,has:Nn,hoursOf:$n,isMap:Ze,limit:q,matches:Bt,max:zt,millisecondsOf:Un,min:Yt,minutesOf:Mn,monthOf:On,offsetByCodePoints:Ft,order:mt,ordinalOf:Tn,secondsOf:Cn,select:An,sizeOf:Ut,timestamp:Qt,typeOf:X,weekdayOf:Bn,yearOf:Rn},Symbol.toStringTag,{value:"Module"}));function v(e,t,n){if(t<0n||t>BigInt(It(e)))throw new a(`${n}() index out of range: ${t}`);return Ft(e,Number(t))}function Tt(e,t){return t<0?-1n:BigInt(It(e.substring(0,t)))}function Dn(e,t){const n=v(e,t,"charAt");return n===e.length?"":String.fromCodePoint(e.codePointAt(n))}function xn(e,t,n=0n){return Tt(e,e.indexOf(t,v(e,n,"indexOf")))}function Pn(e,t,n){return n===void 0?Tt(e,e.lastIndexOf(t)):Tt(e,e.lastIndexOf(t,v(e,n,"lastIndexOf")))}function kn(e){return e.replace(/[A-Z]/g,t=>String.fromCharCode(t.charCodeAt(0)+32))}function Gn(e){return e.replace(/[a-z]/g,t=>String.fromCharCode(t.charCodeAt(0)-32))}function qn(e,t,n){if(n===void 0)return e.substring(v(e,t,"substring"));if(t>n)throw new a(`substring() range out of bounds: ${t}:${n}`);return e.substring(v(e,t,"substring"),v(e,n,"substring"))}function Fn(e){return Array.from(e).reverse().join("")}function jn(e,t,n,i=-1n){if(i===0n||t==="")return e;let r="",s=0,c=0n;for(;i<0n||c<i;){const u=e.indexOf(t,s);if(u<0)break;r+=e.substring(s,u)+n,q(r.length,"replace()"),s=u+t.length,c++}return r+=e.substring(s),q(r.length,"replace()"),r}function Qn(e,t,n=-1n){if(n===0n)return[];let i;if(t===""?i=e===""?[""]:[...e.split(""),""]:i=e.split(t),n>0n&&BigInt(i.length)>n){const r=Number(n)-1;i=[...i.slice(0,r),i.slice(r).join(t)]}return i}function zn(e,t){let n=Math.max(0,e.length-1)*t.length;for(const r of e){if(typeof r!="string")throw new a("join() requires a list of strings");n+=r.length,q(n,"join()")}let i="";for(const r of e)i.length>0&&(i+=t),i+=r;return i}function Yn(e,t){let n="",i=0,r=0;for(;r<e.length;){const s=e[r];if(s!=="%"){n+=s,r++;continue}if(r+1>=e.length)throw new a("format() has a trailing '%'");if(e[r+1]==="%"){n+="%",r+=2;continue}let c=-1,u=r+1;if(e[u]==="."){u++;const d=u;for(;u<e.length&&e[u]>="0"&&e[u]<="9";)u++;if(u===d)throw new a("format() precision requires digits");c=ni(e.substring(d,u))}if(u>=e.length)throw new a("format() has an incomplete verb");if(i>=t.length)throw new a("format() has more verbs than arguments");if(n+=ei(e[u],c,t[i]),n.length>D)throw new l(`format() output exceeds the evaluation limit of ${D}`);i++,r=u+1}if(i!==t.length)throw new a("format() has more arguments than verbs");return n}function ni(e){const t=e.length>18?1/0:Number(e);if(t>D)throw new l(`format() precision exceeds the evaluation limit of ${D}`);return t}function ei(e,t,n){switch(e){case"s":return R(n);case"d":return g(n).toString();case"f":return dt(T(n),t<0?6:t);case"e":return ii(T(n),t<0?6:t);case"b":return typeof n=="boolean"?String(n):Dt(g(n),2);case"o":return Dt(g(n),8);case"x":return cn(n,!1);case"X":return cn(n,!0);default:throw new a(`format() has an unknown verb: %${e}`)}}function Dt(e,t){return BigInt.asUintN(64,e).toString(t)}function dt(e,t){if(!Number.isFinite(e))throw new a(`Cannot format non-finite value: ${e}`);const n=e<0,[i,r]=Math.abs(e).toExponential().split("e"),s=i.replace(".",""),c=s.length-1-Number(r);let u=BigInt(s);if(c<=t)u*=10n**BigInt(t-c);else{const L=10n**BigInt(c-t),k=u/L;u=u%L*2n>=L?k+1n:k}const d=u.toString().padStart(t+1,"0"),E=d.substring(0,d.length-t),b=d.substring(d.length-t),A=t>0?`${E}.${b}`:E;return n&&u!==0n?`-${A}`:A}function ii(e,t){if(e===0)return dt(0,t)+"e+00";if(!Number.isFinite(e))throw new a(`Cannot format non-finite value: ${e}`);const n=Math.floor(Math.log10(Math.abs(e))),i=e/Math.pow(10,n),r=n<0?"-":"+",s=Math.abs(n);return`${dt(i,t)}e${r}${s<10?"0":""}${s}`}function cn(e,t){let n;return B(e)?n=at(e):typeof e=="string"?n=at(bt(e)):n=Dt(g(e),16),t?n.toUpperCase():n}function _n(e){let t="";for(let n=0;n<e.length;n++){const i=e[n],r=e.charCodeAt(n);switch(i){case"\\":t+="\\\\";break;case'"':t+='\\"';break;case`
7
+ `:t+="\\n";break;case"\r":t+="\\r";break;case" ":t+="\\t";break;case"\b":t+="\\b";break;case"\f":t+="\\f";break;case"\x07":t+="\\a";break;case"\v":t+="\\v";break;default:r<32||r===127?t+="\\u"+r.toString(16).padStart(4,"0"):t+=i}}return t}function _t(e){return`"${_n(e)}"`}function Kn(e){let t="";for(const n of e)switch(n){case 92:t+="\\\\";break;case 34:t+='\\"';break;case 10:t+="\\n";break;case 13:t+="\\r";break;case 9:t+="\\t";break;default:n<32||n>=127?t+="\\x"+n.toString(16).padStart(2,"0"):t+=String.fromCharCode(n)}return t}const ri=Object.freeze(Object.defineProperty({__proto__:null,charAt:Dn,escape:_n,escapeBytes:Kn,fixed:dt,format:Yn,indexOf:xn,join:zn,lastIndexOf:Pn,lower:kn,quote:_t,replace:jn,reverse:Fn,split:Qn,substring:qn,upper:Gn},Symbol.toStringTag,{value:"Module"}));function At(e,t){try{return new RegExp(e,t)}catch{throw new a(`Invalid regular expression: ${e}`)}}function Lt(e){return At(e,""),new RegExp(`${e}|`).exec("").length-1}function Wn(e,t,n,i=-1n){const r=At(t,"g"),s=si(n,Lt(t),t);let c="",u=0,d=0n,E;for(;(E=r.exec(e))!==null&&!(i>=0n&&d>=i);)c+=e.substring(u,E.index)+oi(s,E),q(c.length,"regex.replace()"),u=E.index+E[0].length,E[0].length===0&&r.lastIndex++,d++;return c+=e.substring(u),q(c.length,"regex.replace()"),c}function Hn(e,t){const n=Lt(t);if(n>1)throw new a(`extract() supports at most one capture group: ${t}`);const i=At(t,"").exec(e);return i===null?null:n===1?i[1]??null:i[0]}function Xn(e,t){const n=Lt(t);if(n>1)throw new a(`extractAll() supports at most one capture group: ${t}`);const i=At(t,"g"),r=[];let s;for(;(s=i.exec(e))!==null;){const c=n===1?s[1]:s[0];c!==void 0&&r.push(c),s[0].length===0&&i.lastIndex++}return r}function si(e,t,n){const i=[];let r="",s=0;for(;s<e.length;){const c=e[s];if(c==="\\"&&s+1<e.length){const u=e[s+1];if(u>="0"&&u<="9"){const d=u.charCodeAt(0)-48;if(d>t)throw new a(`Replacement refers to group ${d} but ${n} has ${t}`);r.length>0&&(i.push({text:r}),r=""),i.push({group:d})}else r+="\\"+u;s+=2}else r+=c,s++}return r.length>0&&i.push({text:r}),i}function oi(e,t){let n="";for(const i of e)"text"in i?n+=i.text:n+=t[i.group]??"";return n}const ci=Object.freeze(Object.defineProperty({__proto__:null,extract:Hn,extractAll:Xn,groupCount:Lt,replace:Wn},Symbol.toStringTag,{value:"Module"}));function Vn(e){const t=new qt,n=[];for(const i of e)t.add(i)&&n.push(i);return n}function Kt(e,t=1n){if(t<1n)throw new a("flatten() depth must be at least 1");const n=[];for(const i of e)Array.isArray(i)?n.push(...t>1n?Kt(i,t-1n):i):n.push(i);return n}function Zn(e){return[...e].reverse()}function Jn(e,t,n){if(t<0n||n>BigInt(e.length)||t>n)throw new a(`slice() range out of bounds: ${t}:${n}`);return e.slice(Number(t),Number(n))}function vn(e){return[...e].sort(tt)}function te(e){if(e.length===0)throw new a("first() requires a non-empty list");return e[0]}function ne(e){if(e.length===0)throw new a("last() requires a non-empty list");return e[e.length-1]}function ee(e){if(e>BigInt(D))throw new l(`range() exceeds the evaluation limit of ${D}`);const t=[];for(let n=0n;n<e;n++)t.push(n);return t}function ui(e,t){return Nt(e,t)}const ai=Object.freeze(Object.defineProperty({__proto__:null,contains:ui,distinct:Vn,first:te,flatten:Kt,last:ne,range:ee,reverse:Zn,slice:Jn,sort:vn},Symbol.toStringTag,{value:"Module"}));function ie(e){const t=new qt;for(const n of e)t.add(n);return t}function wt(e,t){const n=ie(e);return t.every(i=>n.has(i))}function re(e,t){return wt(e,t)&&wt(t,e)}function se(e,t){const n=ie(e);return t.some(i=>n.has(i))}const hi=Object.freeze(Object.defineProperty({__proto__:null,contains:wt,equivalent:re,intersects:se},Symbol.toStringTag,{value:"Module"}));function oe(e){return e.length===1&&Array.isArray(e[0])?e[0]:e}function ce(e){return zt(oe(e))}function ue(e){return Yt(oe(e))}function ae(e){if(typeof e=="number")return Math.abs(e);const t=g(e);if(t===K)throw new l("Integer overflow");return t<0n?-t:t}function he(e){return Math.ceil(T(e))}function fe(e){return Math.floor(T(e))}function le(e){const t=T(e);return t<0?-Math.round(-t):Math.round(t)}function pe(e){const t=T(e);return t<0?Math.ceil(t):Math.floor(t)}function de(e){if(typeof e=="number")return Math.sign(e);const t=g(e);return t<0n?-1n:t>0n?1n:0n}function we(e){return Math.sqrt(T(e))}function ge(e){return Number.isNaN(T(e))}function be(e){const t=T(e);return t===1/0||t===-1/0}function me(e){return Number.isFinite(T(e))}function Ee(e,t){return BigInt.asIntN(64,g(e)&g(t))}function Ie(e,t){return BigInt.asIntN(64,g(e)|g(t))}function ye(e,t){return BigInt.asIntN(64,g(e)^g(t))}function Ne(e){return BigInt.asIntN(64,~g(e))}function Ae(e){const t=g(e);if(t<0n)throw new a(`Shift count must not be negative: ${t}`);return t}function Le(e,t){const n=Ae(t);return n>=64n?0n:BigInt.asIntN(64,g(e)<<n)}function Se(e,t){const n=Ae(t);return n>=64n?0n:BigInt.asIntN(64,BigInt.asUintN(64,g(e))>>n)}const fi=Object.freeze(Object.defineProperty({__proto__:null,abs:ae,and:Ee,ceil:he,floor:fe,greatest:ce,isFinite:me,isInf:be,isNaN:ge,least:ue,left:Le,not:Ne,or:Ie,right:Se,round:le,sign:de,sqrt:we,trunc:pe,xor:ye},Symbol.toStringTag,{value:"Module"})),G="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",li=new Map(Array.from(G,(e,t)=>[e,t]));function Oe(e){const t=yt(e);q(4*Math.ceil(t.length/3),"base64.encode()");let n="",i=0;for(;i+2<t.length;i+=3){const s=t[i]<<16|t[i+1]<<8|t[i+2];n+=G[s>>18]+G[s>>12&63]+G[s>>6&63]+G[s&63]}const r=t.length-i;if(r===1){const s=t[i]<<16;n+=G[s>>18]+G[s>>12&63]+"=="}else if(r===2){const s=t[i]<<16|t[i+1]<<8;n+=G[s>>18]+G[s>>12&63]+G[s>>6&63]+"="}return n}function Wt(e){if(typeof e!="string")throw new a("base64.decode() requires string arguments");let t=e,n=0;for(;t.endsWith("=")&&n<2;)t=t.substring(0,t.length-1),n++;const i=t.length%4;if(t.includes("=")||i===1||n>0&&(i===0||n!==4-i))throw new a(`Invalid base64 input: ${e}`);const r=[];let s=0,c=0;for(const u of t){const d=li.get(u);if(d===void 0)throw new a(`Invalid base64 input: ${e}`);s=(s<<6|d)&65535,c+=6,c>=8&&(c-=8,r.push(s>>c&255))}return Uint8Array.from(r)}function pi(e){return Pt(Wt(e))}const di=Object.freeze(Object.defineProperty({__proto__:null,decode:Wt,encode:Oe,text:pi},Symbol.toStringTag,{value:"Module"})),wi=new Set(["math.greatest","math.least","math.abs","math.ceil","math.floor","math.round","math.trunc","math.sign","math.sqrt","math.isNaN","math.isInf","math.isFinite","math.bitAnd","math.bitOr","math.bitXor","math.bitNot","math.bitShiftLeft","math.bitShiftRight","sets.contains","sets.equivalent","sets.intersects","base64.encode","base64.decode","lists.range","strings.quote","regex.replace","regex.extract","regex.extractAll"]),gi=new Set(["map","filter","all","exists","existsOne","sortBy"]),bi=new Set(["getDate","getMonth","getFullYear","getHours","getMinutes","getSeconds","getMilliseconds","getDayOfWeek","getDayOfYear"]);function f(e,t,n,i){if(t.length<n||t.length>i)throw new a(`${e}() requires ${n===i?n:`${n} to ${i}`} argument(s)`)}function F(e){return e.length>1?e[1]:null}function m(e,t){if(typeof e=="string")return e;throw new a(`${t}() requires string arguments`)}function $(e,t){if(Array.isArray(e))return e;throw new a(`${t}() requires a list`)}function x(e,t,n){return f(e,t,1,1),n(t[0])}function et(e,t,n){return f(e,t,2,2),n(t[0],t[1])}class Ht{knows(t){return wi.has(t)}callFunction(t,n){if(t.indexOf(".")>0)return this.callQualified(t,n);switch(t){case"size":return f(t,n,1,1),Ut(n[0]);case"int":return f(t,n,1,1),g(n[0]);case"uint":return f(t,n,1,1),yn(n[0]);case"double":return f(t,n,1,1),T(n[0]);case"string":return f(t,n,1,1),R(n[0]);case"bool":return f(t,n,1,1),jt(n[0]);case"type":return f(t,n,1,1),X(n[0]);case"has":if(n.length!==2)throw new a("has() requires 2 arguments");return Nn(n[0],n[1]);case"matches":if(n.length!==2)throw new a("matches() requires 2 arguments");return Bt(m(n[0],t),m(n[1],t));case"timestamp":return f(t,n,0,1),Qt(n.length>0?n[0]:null);case"duration":return f(t,n,1,1),Ln(n[0]);case"getDate":return f(t,n,1,2),Sn(n[0],F(n));case"getMonth":return f(t,n,1,2),On(n[0],F(n));case"getFullYear":return f(t,n,1,2),Rn(n[0],F(n));case"getHours":return f(t,n,1,2),$n(n[0],F(n));case"getMinutes":return f(t,n,1,2),Mn(n[0],F(n));case"getSeconds":return f(t,n,1,2),Cn(n[0],F(n));case"getDayOfWeek":return f(t,n,1,2),Bn(n[0],F(n));case"getDayOfYear":return f(t,n,1,2),Tn(n[0],F(n));case"getMilliseconds":return f(t,n,1,2),Un(n[0],F(n));case"bytes":return f(t,n,1,1),yt(n[0]);case"dyn":return f(t,n,1,1),n[0];case"max":return zt(n);case"min":return Yt(n);default:throw new a(`Unknown function: ${t}`)}}callMethod(t,n,i){if(t==null)throw new a("Cannot call method on null");switch(n){case"contains":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.includes(i[0]);if(Array.isArray(t)&&i.length===1)return Nt(t,i[0]);throw new a("Invalid arguments for contains()");case"startsWith":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.startsWith(i[0]);throw new a("startsWith() requires string target and argument");case"endsWith":if(typeof t=="string"&&i.length===1&&typeof i[0]=="string")return t.endsWith(i[0]);throw new a("endsWith() requires string target and argument");case"toLowerCase":if(typeof t=="string"&&i.length===0)return t.toLowerCase();throw new a("toLowerCase() requires string target");case"toUpperCase":if(typeof t=="string"&&i.length===0)return t.toUpperCase();throw new a("toUpperCase() requires string target");case"trim":if(typeof t=="string"&&i.length===0)return t.trim();throw new a("trim() requires string target");case"replace":return f(n,i,2,3),jn(m(t,n),m(i[0],n),m(i[1],n),i.length>2?g(i[2]):-1n);case"split":return f(n,i,1,2),Qn(m(t,n),m(i[0],n),i.length>1?g(i[1]):-1n);case"charAt":return f(n,i,1,1),Dn(m(t,n),g(i[0]));case"indexOf":return f(n,i,1,2),xn(m(t,n),m(i[0],n),i.length>1?g(i[1]):0n);case"lastIndexOf":return f(n,i,1,2),Pn(m(t,n),m(i[0],n),i.length>1?g(i[1]):void 0);case"lowerAscii":return f(n,i,0,0),kn(m(t,n));case"upperAscii":return f(n,i,0,0),Gn(m(t,n));case"substring":return f(n,i,1,2),qn(m(t,n),g(i[0]),i.length>1?g(i[1]):void 0);case"join":return f(n,i,0,1),zn($(t,n),i.length>0?m(i[0],n):"");case"format":return f(n,i,1,1),Yn(m(t,n),$(i[0],n));case"matches":return f(n,i,1,1),Bt(m(t,n),m(i[0],n));case"reverse":return f(n,i,0,0),Array.isArray(t)?Zn(t):Fn(m(t,n));case"distinct":return f(n,i,0,0),Vn($(t,n));case"flatten":return f(n,i,0,1),Kt($(t,n),i.length>0?g(i[0]):1n);case"slice":return f(n,i,2,2),Jn($(t,n),g(i[0]),g(i[1]));case"sort":return f(n,i,0,0),vn($(t,n));case"first":return f(n,i,0,0),te($(t,n));case"last":return f(n,i,0,0),ne($(t,n));case"size":return Ut(t);default:if(bi.has(n))return f(n,i,0,1),this.callFunction(n,[t,...i]);if(gi.has(n))throw new l(`Macro function ${n} was not properly handled by the interpreter`);return this.callNativeMethod(t,n,i)}}callQualified(t,n){switch(t){case"math.greatest":return ce(n);case"math.least":return ue(n);case"math.abs":return x(t,n,ae);case"math.ceil":return x(t,n,he);case"math.floor":return x(t,n,fe);case"math.round":return x(t,n,le);case"math.trunc":return x(t,n,pe);case"math.sign":return x(t,n,de);case"math.sqrt":return x(t,n,we);case"math.isNaN":return x(t,n,ge);case"math.isInf":return x(t,n,be);case"math.isFinite":return x(t,n,me);case"math.bitAnd":return et(t,n,Ee);case"math.bitOr":return et(t,n,Ie);case"math.bitXor":return et(t,n,ye);case"math.bitNot":return x(t,n,Ne);case"math.bitShiftLeft":return et(t,n,Le);case"math.bitShiftRight":return et(t,n,Se);case"sets.contains":return f(t,n,2,2),wt($(n[0],t),$(n[1],t));case"sets.equivalent":return f(t,n,2,2),re($(n[0],t),$(n[1],t));case"sets.intersects":return f(t,n,2,2),se($(n[0],t),$(n[1],t));case"base64.encode":return f(t,n,1,1),Oe(n[0]);case"base64.decode":return f(t,n,1,1),Wt(m(n[0],t));case"lists.range":return f(t,n,1,1),ee(g(n[0]));case"strings.quote":return f(t,n,1,1),_t(m(n[0],t));case"regex.replace":return f(t,n,3,4),Wn(m(n[0],t),m(n[1],t),m(n[2],t),n.length>3?g(n[3]):-1n);case"regex.extract":return f(t,n,2,2),Hn(m(n[0],t),m(n[1],t));case"regex.extractAll":return f(t,n,2,2),Xn(m(n[0],t),m(n[1],t));default:throw new a(`Unknown function: ${t}`)}}callNativeMethod(t,n,i){const r=t[n];if(typeof r=="function")try{return r.apply(t,i)}catch(s){throw new l(`Invocation of method '${n}' failed: ${s instanceof Error?s.message:String(s)}`)}throw new a(`No such method '${n}' on type ${X(t)} with ${i.length} argument(s)`)}}const mi={[h.LOGICAL_AND]:"&&",[h.LOGICAL_OR]:"||"};class Re{constructor(t,n){if(this.variables=new Map,t instanceof Map)for(const[i,r]of t)this.variables.set(i,Ct(r));else if(t)for(const[i,r]of Object.entries(t))this.variables.set(i,Ct(r));this.functions=n??new Ht}evaluate(t){return t.accept(this)}visitLiteral(t){return t.value}visitIdentifier(t){if(!this.variables.has(t.name)){const n=N.of(t.name);if(n!==null)return n;throw new l(`Undefined variable: ${t.name}`)}return this.variables.get(t.name)}visitSelect(t){const n=t.operand!==null?this.evaluate(t.operand):this.variables;if(n==null){if(t.isTest)return!1;throw new l(`Cannot select field ${t.field} from null`)}if(n instanceof Map){if(t.isTest)return n.has(t.field);if(!n.has(t.field))throw new l(`Field ${t.field} not found`);return n.get(t.field)}throw new l("Cannot select field from non-map type")}visitCall(t){if(t.isMacro&&t.target!==null){const i=this.evaluate(t.target);if(t.args.length===0)throw new l(`Macro ${t.functionName} requires arguments`);const r=t.args[0];if(!(r instanceof ct))throw new l(`First argument to macro ${t.functionName} must be a variable name`);if(t.args.length<2)throw new l(`Macro ${t.functionName} requires an expression argument`);const s=t.args.slice(1);return this.evaluateMacro(i,t.functionName,r.name,s)}const n=[];for(const i of t.args)n.push(this.evaluate(i));if(t.target!==null){const i=this.qualify(t.target);if(i!==null){const s=`${i}.${t.functionName}`;if(!this.variables.has(this.root(i))&&this.knows(s))return ot(this.functions.callFunction(s,n))}const r=this.evaluate(t.target);return ot(this.functions.callMethod(r,t.functionName,n))}return ot(this.functions.callFunction(t.functionName,n))}knows(t){return this.functions.knows?.(t)??!1}qualify(t){if(t instanceof ct)return t.name;if(t instanceof Z&&t.operand!==null&&!t.isTest){const n=this.qualify(t.operand);return n===null?null:`${n}.${t.field}`}return null}root(t){const n=t.indexOf(".");return n<0?t:t.substring(0,n)}evaluateMacro(t,n,i,r){let s;if(Array.isArray(t))s=t;else if(t instanceof Map)s=Array.from(t.keys());else throw new l(`Macro ${n} requires a list or map target`);const c=this.variables.get(i),u=this.variables.has(i),d=b=>{this.variables.set(i,b)},E=r[0];try{switch(n){case"map":{const b=r.length>1?r[0]:null,A=r.length>1?r[1]:E,L=[];for(const k of s)d(k),!(b!==null&&!this.test(b,n))&&L.push(this.evaluate(A));return L}case"filter":{const b=[];for(const A of s)d(A),this.test(E,n)&&b.push(A);return b}case"all":{for(const b of s)if(d(b),!this.test(E,n))return!1;return!0}case"exists":{for(const b of s)if(d(b),this.test(E,n))return!0;return!1}case"existsOne":{let b=0;for(const A of s)if(d(A),this.test(E,n)&&(b++,b>1))return!1;return b===1}case"sortBy":{const b=[];for(const L of s)d(L),b.push(this.evaluate(E));const A=s.map((L,k)=>k);return A.sort((L,k)=>tt(b[L],b[k])),A.map(L=>s[L])}default:throw new l(`Unknown macro function: ${n}`)}}finally{u?this.variables.set(i,c):this.variables.delete(i)}}test(t,n){const i=this.evaluate(t);if(typeof i!="boolean")throw new l(`Macro ${n} requires a boolean predicate`);return i}visitList(t){const n=[];for(const i of t.elements)n.push(this.evaluate(i));return n}visitMap(t){const n=new Map;for(const i of t.entries){const r=this.evaluate(i.key),s=this.evaluate(i.value);n.set(r,s)}return n}visitStruct(t){const n=new Map;for(const i of t.fields)n.set(i.field,this.evaluate(i.value));return n}visitComprehension(t){const n=this.evaluate(t.range);if(!Array.isArray(n))throw new l("Comprehension range must be a list");const i=this.variables.get(t.variable),r=this.variables.get(t.accumulator),s=this.variables.has(t.variable),c=this.variables.has(t.accumulator);try{let u=this.evaluate(t.initializer);this.variables.set(t.accumulator,u);for(const d of n)this.variables.set(t.variable,d),this.evaluate(t.condition)===!0&&(u=this.evaluate(t.step),this.variables.set(t.accumulator,u));return this.evaluate(t.result)}finally{s?this.variables.set(t.variable,i):this.variables.delete(t.variable),c?this.variables.set(t.accumulator,r):this.variables.delete(t.accumulator)}}visitUnary(t){const n=this.evaluate(t.operand);switch(t.op){case V.NOT:if(typeof n!="boolean")throw new l("NOT operator requires boolean operand");return!n;case V.NEGATE:if(typeof n=="bigint"){if(n===K)throw new l("Integer overflow");return-n}if(typeof n=="number")return-n;if(n instanceof I)return n.negated();throw new l("Negation requires numeric operand");default:throw new l(`Unknown unary operator: ${t.op}`)}}visitBinary(t){if(t.op===h.LOGICAL_AND)return this.combine(t,!1);if(t.op===h.LOGICAL_OR)return this.combine(t,!0);const n=this.evaluate(t.left),i=this.evaluate(t.right);switch(t.op){case h.ADD:{if(B(n)&&B(i))return q(n.length+i.length,"Bytes concatenation"),dn(n,i);if(n instanceof y&&i instanceof I)return n.plus(i);if(n instanceof I&&i instanceof y)return i.plus(n);if(n instanceof I&&i instanceof I)return n.plus(i);if(typeof n=="string"||typeof i=="string"){const r=R(n),s=R(i);return q(r.length+s.length,"String concatenation"),r+s}if(Array.isArray(n)&&Array.isArray(i))return q(n.length+i.length,"List concatenation"),[...n,...i];if(M(n)&&M(i))return this.arithmetic(n,i,(r,s)=>r+s,(r,s)=>r+s);throw new l("Invalid operands for addition")}case h.SUBTRACT:{if(n instanceof y&&i instanceof y)return i.until(n);if(n instanceof y&&i instanceof I||n instanceof I&&i instanceof I)return n.minus(i);if(M(n)&&M(i))return this.arithmetic(n,i,(r,s)=>r-s,(r,s)=>r-s);throw new l("Subtraction requires numeric operands")}case h.MULTIPLY:{if(M(n)&&M(i))return this.arithmetic(n,i,(r,s)=>r*s,(r,s)=>r*s);if(typeof n=="string"&&M(i)){const r=this.repetitions(i,n.length);return n.repeat(r)}if(Array.isArray(n)&&M(i)){const r=this.repetitions(i,n.length),s=[];for(let c=0;c<r;c++)s.push(...n);return s}throw new l("Invalid operands for multiplication")}case h.DIVIDE:{if(M(n)&&M(i)){if(typeof n=="number"||typeof i=="number")return Number(n)/Number(i);if(i===0n)throw new l("Division by zero");if(n===K&&i===-1n)throw new l("Integer overflow");return n/i}throw new l("Division requires numeric operands")}case h.MODULO:{if(typeof n=="bigint"&&typeof i=="bigint"){if(i===0n)throw new l("Modulo by zero");return n%i}throw new l("Modulo requires integer operands")}case h.EQUAL:return Q(n,i);case h.NOT_EQUAL:return!Q(n,i);case h.LESS:return this.compare(n,i)<0;case h.LESS_EQUAL:return this.compare(n,i)<=0;case h.GREATER:return this.compare(n,i)>0;case h.GREATER_EQUAL:return this.compare(n,i)>=0;case h.IN:{if(Array.isArray(i))return Nt(i,n);if(i instanceof Map)return pt(i,n);if(typeof i=="string"&&typeof n=="string")return i.includes(n);throw new l("IN operator requires list, map, or string on right side")}default:throw new l(`Unknown binary operator: ${t.op}`)}}combine(t,n){const i=this.attempt(t.left);if(i===n)return n;const r=this.attempt(t.right);if(r===n)return n;if(i instanceof Error)throw i;if(r instanceof Error)throw r;if(typeof i!="boolean"||typeof r!="boolean"){const s=mi[t.op]??t.op;throw new l(`Logical operator ${s} requires boolean operands`)}return!n}attempt(t){try{return this.evaluate(t)}catch(n){if(Vt(n))return n;throw n}}visitConditional(t){const n=this.evaluate(t.condition);if(typeof n!="boolean")throw new l("Conditional requires a boolean condition");return n?this.evaluate(t.thenExpr):this.evaluate(t.otherwiseExpr)}visitIndex(t){const n=this.evaluate(t.operand),i=this.evaluate(t.index);if(n==null)throw new l("Cannot index null value");if(Array.isArray(n)){if(!M(i))throw new l("List index must be an integer");const r=Number(typeof i=="number"?Math.trunc(i):i);if(r<0||r>=n.length)throw new l(`List index out of bounds: ${r}`);return n[r]}if(n instanceof Map){if(!pt(n,i))throw new l(`Map key not found: ${R(i)}`);return An(n,i)}if(B(n)){if(!M(i))throw new l("Bytes index must be an integer");const r=Number(typeof i=="number"?Math.trunc(i):i);if(r<0||r>=n.length)throw new l(`Bytes index out of bounds: ${r}`);return BigInt(n[r])}if(typeof n=="string"){if(!M(i))throw new l("String index must be an integer");const r=Number(typeof i=="number"?Math.trunc(i):i),s=r<0?-1:Ft(n,r);if(s<0||s>=n.length)throw new l(`String index out of bounds: ${r}`);return String.fromCodePoint(n.codePointAt(s))}throw new l(`Cannot index type: ${X(n)}`)}repetitions(t,n){const i=typeof t=="bigint"?t:BigInt(Math.trunc(t));if(i<0n)throw new l(`Repetition count must not be negative: ${i}`);if(i>BigInt(D)||i*BigInt(n)>BigInt(D))throw new l(`Repetition exceeds the evaluation limit of ${D}`);return Number(i)}arithmetic(t,n,i,r){return typeof t=="bigint"&&typeof n=="bigint"?wn(i(t,n)):r(Number(t),Number(n))}compare(t,n){if(t==null&&n==null)return 0;if(t==null)return-1;if(n==null)return 1;if(Array.isArray(t)&&Array.isArray(n)){const i=Math.min(t.length,n.length);for(let r=0;r<i;r++){const s=this.compare(t[r],n[r]);if(s!==0)return s}return t.length-n.length}try{return tt(t,n)}catch(i){throw Vt(i)?new l(`Cannot compare types: ${X(t)} and ${X(n)}`):i}}}class $e{constructor(t,n){this.ast=t,this.functions=n}evaluate(t={}){return new Re(t,this.functions).evaluate(this.ast)}}class gt{constructor(t){this.functions=t??new Ht}static compile(t,n){const i=new bn(t);return new $e(i.parse(),n)}static eval(t,n,i){return this.compile(t,n).evaluate(i)}compile(t){return gt.compile(t,this.functions)}eval(t,n={}){return gt.eval(t,this.functions,n)}}const rt=1,Rt=8,Ei=9;class nt{constructor(t,n,i){this.wrap=t,this.indent=n,this.width=i}static compact(){return new nt(!1,0,Number.MAX_SAFE_INTEGER)}static pretty(){return new nt(!0,2,100)}}class Y{constructor(t){this.options=t,this.level=0}static print(t,n=nt.compact()){return new Y(n).text(t)}static precedence(t){if(t instanceof xt)return rt;if(t instanceof H)switch(t.op){case h.LOGICAL_OR:return 2;case h.LOGICAL_AND:return 3;case h.EQUAL:case h.NOT_EQUAL:case h.LESS:case h.LESS_EQUAL:case h.GREATER:case h.GREATER_EQUAL:case h.IN:return 4;case h.ADD:case h.SUBTRACT:return 5;case h.MULTIPLY:case h.DIVIDE:case h.MODULO:return 6}return t instanceof ut?7:Ei}static spelling(t){switch(t){case h.ADD:return"+";case h.SUBTRACT:return"-";case h.MULTIPLY:return"*";case h.DIVIDE:return"/";case h.MODULO:return"%";case h.EQUAL:return"==";case h.NOT_EQUAL:return"!=";case h.LESS:return"<";case h.LESS_EQUAL:return"<=";case h.GREATER:return">";case h.GREATER_EQUAL:return">=";case h.LOGICAL_AND:return"&&";case h.LOGICAL_OR:return"||";case h.IN:return"in"}}static decimal(t){if(!Number.isFinite(t))throw new a(`Cannot render ${t} as a CEL literal`);return kt(t)}text(t){if(this.options.wrap){const n=Y.print(t,nt.compact());if(this.level*this.options.indent+n.length<=this.options.width)return n}return t.accept(this)}render(t,n){const i=this.text(t);return Y.precedence(t)<n?`(${i})`:i}nested(t){const n=this.options.wrap?1:0;this.level+=n;try{return t()}finally{this.level-=n}}visitLiteral(t){const n=t.value;switch(t.literalType){case O.NULL_VALUE:return"null";case O.BOOL:case O.INT:return String(n);case O.UINT:return`${n}u`;case O.DOUBLE:return Y.decimal(T(n));case O.STRING:return _t(R(n));case O.BYTES:return`b"${Kn(yt(n))}"`}}visitIdentifier(t){return t.name}visitSelect(t){const i=`${t.operand===null?"":this.render(t.operand,Rt)}.${t.field}`;return t.isTest?`has(${i})`:i}visitCall(t){const n=t.target===null?"":`${this.render(t.target,Rt)}.`,i=this.nested(()=>t.args.map(r=>this.text(r)));return`${n}${t.functionName}${this.group("(",i,")")}`}visitList(t){return this.group("[",this.parts(t.elements),"]")}visitMap(t){const n=this.nested(()=>t.entries.map(i=>`${this.text(i.key)}: ${this.text(i.value)}`));return this.group("{",n,"}")}visitStruct(t){const n=this.nested(()=>t.fields.map(i=>`${i.field}: ${this.text(i.value)}`));return`${t.typeName??""}${this.group("{",n,"}")}`}visitComprehension(t){const n=[t.variable,this.text(t.range),t.accumulator,this.text(t.initializer),this.text(t.condition),this.text(t.step),this.text(t.result)];return`__comprehension__${this.group("(",n,")")}`}visitUnary(t){return(t.op===V.NOT?"!":"-")+this.render(t.operand,7)}visitBinary(t){const n=Y.precedence(t),i=this.render(t.left,n),r=this.render(t.right,n+1),s=Y.spelling(t.op);return this.options.wrap&&(t.op===h.LOGICAL_AND||t.op===h.LOGICAL_OR)?`${i}
8
+ ${this.pad(this.level)}${s} ${r}`:`${i} ${s} ${r}`}visitConditional(t){const n=this.render(t.condition,rt+1),[i,r]=this.nested(()=>[this.render(t.thenExpr,rt+1),this.render(t.otherwiseExpr,rt)]);if(this.options.wrap){const s=this.pad(this.level+1);return`${n}
9
+ ${s}? ${i}
10
+ ${s}: ${r}`}return`${n} ? ${i} : ${r}`}visitIndex(t){return`${this.render(t.operand,Rt)}[${this.text(t.index)}]`}parts(t){return this.nested(()=>t.map(n=>this.text(n)))}group(t,n,i){if(!this.options.wrap||n.length===0)return`${t}${n.join(", ")}${i}`;const r=this.pad(this.level+1);return`${t}
11
+ ${r}${n.join(`,
12
+ ${r}`)}
13
+ ${this.pad(this.level)}${i}`}pad(t){return" ".repeat(t*this.options.indent)}}exports.ArgumentError=a;exports.Binary=H;exports.BinaryOp=h;exports.CEL=gt;exports.Call=st;exports.Codecs=di;exports.Comprehension=Ce;exports.Conditional=xt;exports.Duration=I;exports.EvaluationError=l;exports.FieldInitializer=fn;exports.INT64_MAX=it;exports.INT64_MIN=K;exports.Identifier=ct;exports.Index=un;exports.Interpreter=Re;exports.KeyMap=In;exports.KeySet=qt;exports.ListExpression=an;exports.Lists=ai;exports.Literal=j;exports.LiteralType=O;exports.MapEntry=hn;exports.MapExpression=$t;exports.Maths=fi;exports.ParseError=U;exports.Parser=bn;exports.Printer=Y;exports.PrinterOptions=nt;exports.Program=$e;exports.Regexes=ci;exports.Select=Z;exports.Sets=hi;exports.StandardFunctions=Ht;exports.Strings=ri;exports.Struct=Mt;exports.Timestamp=y;exports.Type=N;exports.Unary=ut;exports.UnaryOp=V;exports.Utilities=ti;exports.asBool=jt;exports.bytesCompare=pn;exports.bytesEqual=ln;exports.bytesToHex=at;exports.canonicalKey=P;exports.checkInt64=wn;exports.civilFromDays=mn;exports.concatBytes=dn;exports.daysFromCivil=Et;exports.fieldsOf=En;exports.isBytes=B;exports.isDouble=De;exports.isInt=Te;exports.isNumeric=M;exports.isPlainObject=W;exports.javaDoubleToString=kt;exports.normalize=Ct;exports.normalizeResult=ot;exports.order=mt;exports.truncateToInt64=gn;exports.utcFields=lt;exports.utf8Decode=Pt;exports.utf8Encode=bt;
6
14
  //# sourceMappingURL=index.cjs.map