@metrichor/jmespath
Advanced tools
Comparing version 0.1.10 to 0.2.0
@@ -1,2 +0,16 @@ | ||
const t=t=>null!==t&&"[object Object]"===Object.prototype.toString.call(t),e=(r,n)=>{if(r===n)return!0;if(typeof r!=typeof n)return!1;if(Array.isArray(r)&&Array.isArray(n)){if(r.length!==n.length)return!1;for(let t=0;t<r.length;t+=1)if(!e(r[t],n[t]))return!1;return!0}if(t(r)&&t(n)){const t=Object.entries(r),i=new Set(Object.keys(n));if(t.length!==i.size)return!1;for(const[r,s]of t){if(!e(s,n[r]))return!1;i.delete(r)}return 0===i.size}return!1},r=e=>{if(""===e||!1===e||null==e)return!0;if(Array.isArray(e)&&0===e.length)return!0;if(t(e)){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0}return!1},n="function"==typeof String.prototype.trimLeft?t=>t.trimLeft():t=>{const e=/^\s*(.*)/.exec(t);return e&&e[1]},i=t=>t>="0"&&t<="9"||"-"===t;var s;!function(t){t.TOK_EOF="EOF",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(s||(s={}));const o={"(":s.TOK_LPAREN,")":s.TOK_RPAREN,"*":s.TOK_STAR,",":s.TOK_COMMA,".":s.TOK_DOT,":":s.TOK_COLON,"@":s.TOK_CURRENT,$:s.TOK_ROOT,"]":s.TOK_RBRACKET,"{":s.TOK_LBRACE,"}":s.TOK_RBRACE},c={"!":!0,"<":!0,"=":!0,">":!0},h={"\t":!0,"\n":!0,"\r":!0," ":!0};const u=new class{constructor(){this._current=0}tokenize(t){const e=[];let r,n,u;for(this._current=0;this._current<t.length;)if((a=t[this._current])>="a"&&a<="z"||a>="A"&&a<="Z"||"_"===a)r=this._current,n=this.consumeUnquotedIdentifier(t),e.push({start:r,type:s.TOK_UNQUOTEDIDENTIFIER,value:n});else if(void 0!==o[t[this._current]])e.push({start:this._current,type:o[t[this._current]],value:t[this._current]}),this._current+=1;else if(i(t[this._current]))u=this.consumeNumber(t),e.push(u);else if("["===t[this._current])u=this.consumeLBracket(t),e.push(u);else if('"'===t[this._current])r=this._current,n=this.consumeQuotedIdentifier(t),e.push({start:r,type:s.TOK_QUOTEDIDENTIFIER,value:n});else if("'"===t[this._current])r=this._current,n=this.consumeRawStringLiteral(t),e.push({start:r,type:s.TOK_LITERAL,value:n});else if("`"===t[this._current]){r=this._current;const n=this.consumeLiteral(t);e.push({start:r,type:s.TOK_LITERAL,value:n})}else if(void 0!==c[t[this._current]])u=this.consumeOperator(t),u&&e.push(u);else if(void 0!==h[t[this._current]])this._current+=1;else if("&"===t[this._current])r=this._current,this._current+=1,"&"===t[this._current]?(this._current+=1,e.push({start:r,type:s.TOK_AND,value:"&&"})):e.push({start:r,type:s.TOK_EXPREF,value:"&"});else{if("|"!==t[this._current]){const e=new Error("Unknown character: "+t[this._current]);throw e.name="LexerError",e}r=this._current,this._current+=1,"|"===t[this._current]?(this._current+=1,e.push({start:r,type:s.TOK_OR,value:"||"})):e.push({start:r,type:s.TOK_PIPE,value:"|"})}var a;return e}consumeUnquotedIdentifier(t){const e=this._current;for(this._current+=1;this._current<t.length&&((r=t[this._current])>="a"&&r<="z"||r>="A"&&r<="Z"||r>="0"&&r<="9"||"_"===r);)this._current+=1;var r;return t.slice(e,this._current)}consumeQuotedIdentifier(t){const e=this._current;this._current+=1;const r=t.length;for(;'"'!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&'"'!==t[e+1]?e+=1:e+=2,this._current=e}return this._current+=1,JSON.parse(t.slice(e,this._current))}consumeRawStringLiteral(t){const e=this._current;this._current+=1;const r=t.length;for(;"'"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"'"!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;return t.slice(e+1,this._current-1).replace("\\'","'")}consumeNumber(t){const e=this._current;this._current+=1;const r=t.length;for(;i(t[this._current])&&this._current<r;)this._current+=1;return{start:e,value:parseInt(t.slice(e,this._current),10),type:s.TOK_NUMBER}}consumeLBracket(t){const e=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:e,type:s.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:e,type:s.TOK_FLATTEN,value:"[]"}):{start:e,type:s.TOK_LBRACKET,value:"["}}consumeOperator(t){const e=this._current,r=t[e];return this._current+=1,"!"===r?"="===t[this._current]?(this._current+=1,{start:e,type:s.TOK_NE,value:"!="}):{start:e,type:s.TOK_NOT,value:"!"}:"<"===r?"="===t[this._current]?(this._current+=1,{start:e,type:s.TOK_LTE,value:"<="}):{start:e,type:s.TOK_LT,value:"<"}:">"===r?"="===t[this._current]?(this._current+=1,{start:e,type:s.TOK_GTE,value:">="}):{start:e,type:s.TOK_GT,value:">"}:"="===r&&"="===t[this._current]?(this._current+=1,{start:e,type:s.TOK_EQ,value:"=="}):void 0}consumeLiteral(t){this._current+=1;const e=this._current,r=t.length;for(;"`"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"`"!==t[e+1]?e+=1:e+=2,this._current=e}let i=n(t.slice(e,this._current));i=i.replace("\\`","`");const s=this.looksLikeJSON(i)?JSON.parse(i):JSON.parse(`"${i}"`);return this._current+=1,s}looksLikeJSON(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0]))try{return JSON.parse(t),!0}catch(t){return!1}return!1}},a={[s.TOK_EOF]:0,[s.TOK_UNQUOTEDIDENTIFIER]:0,[s.TOK_QUOTEDIDENTIFIER]:0,[s.TOK_RBRACKET]:0,[s.TOK_RPAREN]:0,[s.TOK_COMMA]:0,[s.TOK_RBRACE]:0,[s.TOK_NUMBER]:0,[s.TOK_CURRENT]:0,[s.TOK_EXPREF]:0,[s.TOK_ROOT]:0,[s.TOK_PIPE]:1,[s.TOK_OR]:2,[s.TOK_AND]:3,[s.TOK_EQ]:5,[s.TOK_GT]:5,[s.TOK_LT]:5,[s.TOK_GTE]:5,[s.TOK_LTE]:5,[s.TOK_NE]:5,[s.TOK_FLATTEN]:9,[s.TOK_STAR]:20,[s.TOK_FILTER]:21,[s.TOK_DOT]:40,[s.TOK_NOT]:45,[s.TOK_LBRACE]:50,[s.TOK_LBRACKET]:55,[s.TOK_LPAREN]:60};const T=new class{constructor(){this.index=0,this.tokens=[]}parse(t){this.loadTokens(t),this.index=0;const e=this.expression(0);if(this.lookahead(0)!==s.TOK_EOF){const t=this.lookaheadToken(0);this.errorToken(t,`Unexpected token type: ${t.type}, value: ${t.value}`)}return e}loadTokens(t){this.tokens=[...u.tokenize(t),{type:s.TOK_EOF,value:"",start:t.length}]}expression(t){const e=this.lookaheadToken(0);this.advance();let r=this.nud(e),n=this.lookahead(0);for(;t<a[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r}lookahead(t){return this.tokens[this.index+t].type}lookaheadToken(t){return this.tokens[this.index+t]}advance(){this.index+=1}nud(t){let e,r,n;switch(t.type){case s.TOK_LITERAL:return{type:"Literal",value:t.value};case s.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:t.value};case s.TOK_QUOTEDIDENTIFIER:const i={type:"Field",name:t.value};if(this.lookahead(0)===s.TOK_LPAREN)throw new Error("Quoted identifier not allowed for function names.");return i;case s.TOK_NOT:return r=this.expression(a.Not),{type:"NotExpression",children:[r]};case s.TOK_STAR:return e={type:"Identity"},r=this.lookahead(0)===s.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(a.Star),{type:"ValueProjection",children:[e,r]};case s.TOK_FILTER:return this.led(t.type,{type:"Identity"});case s.TOK_LBRACE:return this.parseMultiselectHash();case s.TOK_FLATTEN:return e={type:s.TOK_FLATTEN,children:[{type:"Identity"}]},r=this.parseProjectionRHS(a.Flatten),{type:"Projection",children:[e,r]};case s.TOK_LBRACKET:return this.lookahead(0)===s.TOK_NUMBER||this.lookahead(0)===s.TOK_COLON?(r=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},r)):this.lookahead(0)===s.TOK_STAR&&this.lookahead(1)===s.TOK_RBRACKET?(this.advance(),this.advance(),r=this.parseProjectionRHS(a.Star),{children:[{type:"Identity"},r],type:"Projection"}):this.parseMultiselectList();case s.TOK_CURRENT:return{type:s.TOK_CURRENT};case s.TOK_ROOT:return{type:s.TOK_ROOT};case s.TOK_EXPREF:return n=this.expression(a.Expref),{type:"ExpressionReference",children:[n]};case s.TOK_LPAREN:const o=[];for(;this.lookahead(0)!==s.TOK_RPAREN;)this.lookahead(0)===s.TOK_CURRENT?(n={type:s.TOK_CURRENT},this.advance()):n=this.expression(0),o.push(n);return this.match(s.TOK_RPAREN),o[0];default:this.errorToken(t)}}led(t,e){let r;switch(t){case s.TOK_DOT:const n=a.Dot;return this.lookahead(0)!==s.TOK_STAR?(r=this.parseDotRHS(n),{type:"Subexpression",children:[e,r]}):(this.advance(),r=this.parseProjectionRHS(n),{type:"ValueProjection",children:[e,r]});case s.TOK_PIPE:return r=this.expression(a.Pipe),{type:s.TOK_PIPE,children:[e,r]};case s.TOK_OR:return r=this.expression(a.Or),{type:"OrExpression",children:[e,r]};case s.TOK_AND:return r=this.expression(a.And),{type:"AndExpression",children:[e,r]};case s.TOK_LPAREN:const i=e.name,o=[];let c;for(;this.lookahead(0)!==s.TOK_RPAREN;)this.lookahead(0)===s.TOK_CURRENT?(c={type:s.TOK_CURRENT},this.advance()):c=this.expression(0),this.lookahead(0)===s.TOK_COMMA&&this.match(s.TOK_COMMA),o.push(c);this.match(s.TOK_RPAREN);return{name:i,type:"Function",children:o};case s.TOK_FILTER:const h=this.expression(0);return this.match(s.TOK_RBRACKET),r=this.lookahead(0)===s.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(a.Filter),{type:"FilterProjection",children:[e,r,h]};case s.TOK_FLATTEN:return{type:"Projection",children:[{type:s.TOK_FLATTEN,children:[e]},this.parseProjectionRHS(a.Flatten)]};case s.TOK_EQ:case s.TOK_NE:case s.TOK_GT:case s.TOK_GTE:case s.TOK_LT:case s.TOK_LTE:return this.parseComparator(e,t);case s.TOK_LBRACKET:const u=this.lookaheadToken(0);return u.type===s.TOK_NUMBER||u.type===s.TOK_COLON?(r=this.parseIndexExpression(),this.projectIfSlice(e,r)):(this.match(s.TOK_STAR),this.match(s.TOK_RBRACKET),r=this.parseProjectionRHS(a.Star),{type:"Projection",children:[e,r]});default:return this.errorToken(this.lookaheadToken(0))}}match(t){if(this.lookahead(0)!==t){const e=this.lookaheadToken(0);this.errorToken(e,`Expected ${t}, got: ${e.type}`)}else this.advance()}errorToken(t,e=""){const r=new Error(e||`Invalid token (${t.type}): "${t.value}"`);throw r.name="ParserError",r}parseIndexExpression(){if(this.lookahead(0)===s.TOK_COLON||this.lookahead(1)===s.TOK_COLON)return this.parseSliceExpression();const t={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(s.TOK_RBRACKET),t}projectIfSlice(t,e){const r={type:"IndexExpression",children:[t,e]};return"Slice"===e.type?{children:[r,this.parseProjectionRHS(a.Star)],type:"Projection"}:r}parseSliceExpression(){const t=[null,null,null];let e=0,r=this.lookahead(0);for(;r!==s.TOK_RBRACKET&&e<3;){if(r===s.TOK_COLON)e+=1,this.advance();else if(r===s.TOK_NUMBER)t[e]=this.lookaheadToken(0).value,this.advance();else{const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error, unexpected token: ${t.value}(${t.type})`)}r=this.lookahead(0)}return this.match(s.TOK_RBRACKET),{children:t,type:"Slice"}}parseComparator(t,e){return{type:"Comparator",name:e,children:[t,this.expression(a[e])]}}parseDotRHS(t){const e=this.lookahead(0);if([s.TOK_UNQUOTEDIDENTIFIER,s.TOK_QUOTEDIDENTIFIER,s.TOK_STAR].includes(e))return this.expression(t);if(e===s.TOK_LBRACKET)return this.match(s.TOK_LBRACKET),this.parseMultiselectList();if(e===s.TOK_LBRACE)return this.match(s.TOK_LBRACE),this.parseMultiselectHash();const r=this.lookaheadToken(0);this.errorToken(r,`Syntax error, unexpected token: ${r.value}(${r.type})`)}parseProjectionRHS(t){if(a[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===s.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===s.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===s.TOK_DOT)return this.match(s.TOK_DOT),this.parseDotRHS(t);const e=this.lookaheadToken(0);this.errorToken(e,`Syntax error, unexpected token: ${e.value}(${e.type})`)}parseMultiselectList(){const t=[];for(;this.lookahead(0)!==s.TOK_RBRACKET;){const e=this.expression(0);if(t.push(e),this.lookahead(0)===s.TOK_COMMA&&(this.match(s.TOK_COMMA),this.lookahead(0)===s.TOK_RBRACKET))throw new Error("Unexpected token Rbracket")}return this.match(s.TOK_RBRACKET),{type:"MultiSelectList",children:t}}parseMultiselectHash(){const t=[],e=[s.TOK_UNQUOTEDIDENTIFIER,s.TOK_QUOTEDIDENTIFIER];let r,n,i,o;for(;;){if(r=this.lookaheadToken(0),!e.includes(r.type))throw new Error("Expecting an identifier token, got: "+r.type);if(n=r.value,this.advance(),this.match(s.TOK_COLON),i=this.expression(0),o={value:i,type:"KeyValuePair",name:n},t.push(o),this.lookahead(0)===s.TOK_COMMA)this.match(s.TOK_COMMA);else if(this.lookahead(0)===s.TOK_RBRACE){this.match(s.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:t}}};var _;!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"}(_||(_={}));class l{constructor(e){this.TYPE_NAME_TABLE={[_.TYPE_NUMBER]:"number",[_.TYPE_ANY]:"any",[_.TYPE_STRING]:"string",[_.TYPE_ARRAY]:"array",[_.TYPE_OBJECT]:"object",[_.TYPE_BOOLEAN]:"boolean",[_.TYPE_EXPREF]:"expression",[_.TYPE_NULL]:"null",[_.TYPE_ARRAY_NUMBER]:"Array<number>",[_.TYPE_ARRAY_STRING]:"Array<string>"},this.functionAbs=([t])=>Math.abs(t),this.functionAvg=([t])=>{let e=0;for(let r=0;r<t.length;r+=1)e+=t[r];return e/t.length},this.functionCeil=([t])=>Math.ceil(t),this.functionContains=t=>{const[e,r]=t;return e.includes(r)},this.functionEndsWith=t=>{const[e,r]=t;return e.includes(r,e.length-r.length)},this.functionFloor=([t])=>Math.floor(t),this.functionJoin=t=>{const[e,r]=t;return r.join(e)},this.functionKeys=([t])=>Object.keys(t),this.functionLength=([e])=>t(e)?Object.keys(e).length:e.length,this.functionMap=t=>{if(!this._interpreter)return[];const e=[],r=this._interpreter,n=t[0],i=t[1];for(let t=0;t<i.length;t+=1)e.push(r.visit(n,i[t]));return e},this.functionMax=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===_.TYPE_NUMBER)return Math.max(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)r.localeCompare(e[t])<0&&(r=e[t]);return r},this.functionMaxBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[_.TYPE_NUMBER,_.TYPE_STRING]);let i,s,o=-1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s>o&&(o=s,i=r[t]);return i},this.functionMerge=t=>{let e={};for(let r=0;r<t.length;r+=1){const n=t[r];e=Object.assign(e,n)}return e},this.functionMin=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===_.TYPE_NUMBER)return Math.min(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)e[t].localeCompare(r)<0&&(r=e[t]);return r},this.functionMinBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[_.TYPE_NUMBER,_.TYPE_STRING]);let i,s,o=1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s<o&&(o=s,i=r[t]);return i},this.functionNotNull=t=>{for(let e=0;e<t.length;e+=1)if(this.getTypeName(t[e])!==_.TYPE_NULL)return t[e];return null},this.functionReverse=([t])=>{if(this.getTypeName(t)===_.TYPE_STRING){const e=t;let r="";for(let t=e.length-1;t>=0;t-=1)r+=e[t];return r}const e=t.slice(0);return e.reverse(),e},this.functionSort=([t])=>[...t].sort(),this.functionSortBy=t=>{if(!this._interpreter)return[];const e=t[0].slice(0);if(0===e.length)return e;const r=this._interpreter,n=t[1],i=this.getTypeName(r.visit(n,e[0]));if(void 0!==i&&![_.TYPE_NUMBER,_.TYPE_STRING].includes(i))throw new Error(`TypeError: unexpected type (${this.TYPE_NAME_TABLE[i]})`);const s=[];for(let t=0;t<e.length;t+=1)s.push([t,e[t]]);s.sort(((t,e)=>{const s=r.visit(n,t[1]),o=r.visit(n,e[1]);if(this.getTypeName(s)!==i)throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[i]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(s)]}`);if(this.getTypeName(o)!==i)throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[i]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(o)]}`);return s>o?1:s<o?-1:t[0]-e[0]}));for(let t=0;t<s.length;t+=1)e[t]=s[t][1];return e},this.functionStartsWith=([t,e])=>t.startsWith(e),this.functionSum=([t])=>t.reduce(((t,e)=>t+e),0),this.functionToArray=([t])=>this.getTypeName(t)===_.TYPE_ARRAY?t:[t],this.functionToNumber=([t])=>{const e=this.getTypeName(t);let r;return e===_.TYPE_NUMBER?t:e!==_.TYPE_STRING||(r=+t,isNaN(r))?null:r},this.functionToString=([t])=>this.getTypeName(t)===_.TYPE_STRING?t:JSON.stringify(t),this.functionType=([t])=>{switch(this.getTypeName(t)){case _.TYPE_NUMBER:return"number";case _.TYPE_STRING:return"string";case _.TYPE_ARRAY:return"array";case _.TYPE_OBJECT:return"object";case _.TYPE_BOOLEAN:return"boolean";case _.TYPE_EXPREF:return"expref";case _.TYPE_NULL:return"null";default:return}},this.functionValues=([t])=>Object.values(t),this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[_.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[_.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[_.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[_.TYPE_STRING,_.TYPE_ARRAY]},{types:[_.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[_.TYPE_STRING]},{types:[_.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[_.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[_.TYPE_STRING]},{types:[_.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[_.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[_.TYPE_STRING,_.TYPE_ARRAY,_.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[_.TYPE_EXPREF]},{types:[_.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[_.TYPE_ARRAY_NUMBER,_.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[_.TYPE_ARRAY]},{types:[_.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[_.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[_.TYPE_ARRAY_NUMBER,_.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[_.TYPE_ARRAY]},{types:[_.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[_.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[_.TYPE_STRING,_.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[_.TYPE_ARRAY_STRING,_.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[_.TYPE_ARRAY]},{types:[_.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[_.TYPE_STRING]},{types:[_.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[_.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[_.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[_.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[_.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[_.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[_.TYPE_OBJECT]}]}},this._interpreter=e}registerFunction(t,e,r){if(t in this.functionTable)throw new Error(`Function already defined: ${t}()`);this.functionTable[t]={_func:e.bind(this),_signature:r}}callFunction(t,e){const r=this.functionTable[t];if(void 0===r)throw new Error(`Unknown function: ${t}()`);return this.validateArgs(t,e,r._signature),r._func.call(this,e)}validateInputSignatures(t,e){for(let r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error(`ArgumentError: ${t}() 'variadic' argument ${r+1} must occur last`)}validateArgs(t,e,r){var n,i;let s;this.validateInputSignatures(t,r);const o=r.filter((t=>{var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,c=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,h=e.length<o,u=e.length>r.length,a=h&&(!c&&o>1||c)?"at least ":"";if(c&&h||!c&&(h||u))throw s=r.length>1,new Error(`ArgumentError: ${t}() takes ${a}${o} argument${s?"s":""} but received ${e.length}`);let T,_,l;for(let n=0;n<r.length;n+=1){let i;for(l=!1,T=r[n].types,_=this.getTypeName(e[n]),i=0;i<T.length;i+=1)if(void 0!==_&&this.typeMatches(_,T[i],e[n])){l=!0;break}if(!l&&void 0!==_){const e=T.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ");throw new Error(`TypeError: ${t}() expected argument ${n+1} to be type (${e}) but received type ${this.TYPE_NAME_TABLE[_]} instead.`)}}}typeMatches(t,e,r){if(e===_.TYPE_ANY)return!0;if(e!==_.TYPE_ARRAY_STRING&&e!==_.TYPE_ARRAY_NUMBER&&e!==_.TYPE_ARRAY)return t===e;if(e===_.TYPE_ARRAY)return t===_.TYPE_ARRAY;if(t===_.TYPE_ARRAY){let t;e===_.TYPE_ARRAY_NUMBER?t=_.TYPE_NUMBER:e===_.TYPE_ARRAY_STRING&&(t=_.TYPE_STRING);for(let e=0;e<r.length;e+=1){const n=this.getTypeName(r[e]);if(void 0!==n&&void 0!==t&&!this.typeMatches(n,t,r[e]))return!1}return!0}return!1}getTypeName(t){switch(Object.prototype.toString.call(t)){case"[object String]":return _.TYPE_STRING;case"[object Number]":return _.TYPE_NUMBER;case"[object Array]":return _.TYPE_ARRAY;case"[object Boolean]":return _.TYPE_BOOLEAN;case"[object Null]":return _.TYPE_NULL;case"[object Object]":return t.jmespathType===s.TOK_EXPREF?_.TYPE_EXPREF:_.TYPE_OBJECT;default:return}}createKeyFunction(t,e){if(!this._interpreter)return;const r=this._interpreter;return n=>{const i=r.visit(t,n);if(!e.includes(this.getTypeName(i))){const t=`TypeError: expected one of (${e.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(i)]}`;throw new Error(t)}return i}}}const E=new class{constructor(){this._rootValue=null,this.runtime=new l(this)}search(t,e){return this._rootValue=e,this.visit(t,e)}visit(n,i){let o,c,h,u,a,T,_,l,E,R,p;switch(n.type){case"Field":return null===i?null:t(i)?(T=i[n.name],void 0===T?null:T):null;case"Subexpression":for(h=this.visit(n.children[0],i),R=1;R<n.children.length;R+=1)if(h=this.visit(n.children[1],h),null===h)return null;return h;case"IndexExpression":return _=this.visit(n.children[0],i),l=this.visit(n.children[1],_),l;case"Index":if(!Array.isArray(i))return null;let O=n.value;return O<0&&(O=i.length+O),h=i[O],void 0===h&&(h=null),h;case"Slice":if(!Array.isArray(i))return null;const f=[...n.children],A=this.computeSliceParams(i.length,f),[d,N,y]=A;if(h=[],y>0)for(R=d;R<N;R+=y)h.push(i[R]);else for(R=d;R>N;R+=y)h.push(i[R]);return h;case"Projection":if(p=this.visit(n.children[0],i),!Array.isArray(p))return null;for(E=[],R=0;R<p.length;R+=1)c=this.visit(n.children[1],p[R]),null!==c&&E.push(c);return E;case"ValueProjection":if(p=this.visit(n.children[0],i),!t(p))return null;E=[];const K=Object.values(p);for(R=0;R<K.length;R+=1)c=this.visit(n.children[1],K[R]),null!==c&&E.push(c);return E;case"FilterProjection":if(p=this.visit(n.children[0],i),!Array.isArray(p))return null;const P=[],Y=[];for(R=0;R<p.length;R+=1)o=this.visit(n.children[2],p[R]),r(o)||P.push(p[R]);for(let t=0;t<P.length;t+=1)c=this.visit(n.children[1],P[t]),null!==c&&Y.push(c);return Y;case"Comparator":switch(u=this.visit(n.children[0],i),a=this.visit(n.children[1],i),n.name){case s.TOK_EQ:h=e(u,a);break;case s.TOK_NE:h=!e(u,a);break;case s.TOK_GT:h=u>a;break;case s.TOK_GTE:h=u>=a;break;case s.TOK_LT:h=u<a;break;case s.TOK_LTE:h=u<=a;break;default:throw new Error("Unknown comparator: "+n.name)}return h;case s.TOK_FLATTEN:const g=this.visit(n.children[0],i);if(!Array.isArray(g))return null;let v=[];for(R=0;R<g.length;R+=1)c=g[R],Array.isArray(c)?v=[...v,...c]:v.push(c);return v;case"Identity":return i;case"MultiSelectList":if(null===i)return null;for(E=[],R=0;R<n.children.length;R+=1)E.push(this.visit(n.children[R],i));return E;case"MultiSelectHash":if(null===i)return null;let L;for(E={},R=0;R<n.children.length;R+=1)L=n.children[R],E[L.name]=this.visit(L.value,i);return E;case"OrExpression":return o=this.visit(n.children[0],i),r(o)&&(o=this.visit(n.children[1],i)),o;case"AndExpression":return u=this.visit(n.children[0],i),r(u)?u:this.visit(n.children[1],i);case"NotExpression":return u=this.visit(n.children[0],i),r(u);case"Literal":return n.value;case s.TOK_PIPE:return _=this.visit(n.children[0],i),this.visit(n.children[1],_);case s.TOK_CURRENT:return i;case s.TOK_ROOT:return this._rootValue;case"Function":const I=[];for(let t=0;t<n.children.length;t+=1)I.push(this.visit(n.children[t],i));return this.runtime.callFunction(n.name,I);case"ExpressionReference":const m=n.children[0];return m.jmespathType=s.TOK_EXPREF,m;default:throw new Error("Unknown node type: "+n.type)}}computeSliceParams(t,e){let[r,n,i]=e;if(null===i)i=1;else if(0===i){const t=new Error("Invalid slice, step cannot be 0");throw t.name="RuntimeError",t}const s=i<0;return r=null===r?s?t-1:0:this.capSliceRange(t,r,i),n=null===n?s?-1:t:this.capSliceRange(t,n,i),[r,n,i]}capSliceRange(t,e,r){let n=e;return n<0?(n+=t,n<0&&(n=r<0?-1:0)):n>=t&&(n=r<0?t-1:t),n}},R=_.TYPE_ANY,p=_.TYPE_ARRAY,O=_.TYPE_ARRAY_NUMBER,f=_.TYPE_ARRAY_STRING,A=_.TYPE_BOOLEAN,d=_.TYPE_EXPREF,N=_.TYPE_NULL,y=_.TYPE_NUMBER,K=_.TYPE_OBJECT,P=_.TYPE_STRING;function Y(t){return T.parse(t)}function g(t){return u.tokenize(t)}const v=(t,e,r)=>{E.runtime.registerFunction(t,e,r)};function L(t,e){const r=T.parse(e);return E.search(r,t)}const I=E,m={compile:Y,registerFunction:v,search:L,tokenize:g,TreeInterpreter:I,TYPE_ANY:R,TYPE_ARRAY_NUMBER:O,TYPE_ARRAY_STRING:f,TYPE_ARRAY:p,TYPE_BOOLEAN:A,TYPE_EXPREF:d,TYPE_NULL:N,TYPE_NUMBER:y,TYPE_OBJECT:K,TYPE_STRING:P};export default m;export{R as TYPE_ANY,p as TYPE_ARRAY,O as TYPE_ARRAY_NUMBER,f as TYPE_ARRAY_STRING,A as TYPE_BOOLEAN,d as TYPE_EXPREF,N as TYPE_NULL,y as TYPE_NUMBER,K as TYPE_OBJECT,P as TYPE_STRING,I as TreeInterpreter,Y as compile,m as jmespath,v as registerFunction,L as search,g as tokenize}; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function t(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)n[i]=s[o];return n}var e,r,n=function(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)},i=function(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var r=0;r<t.length;r+=1)if(!i(t[r],e[r]))return!1;return!0}if(n(t)&&n(e)){var s=Object.entries(t),o=new Set(Object.keys(e));if(s.length!==o.size)return!1;for(var a=0,u=s;a<u.length;a++){var c=u[a],h=c[0],T=c[1];if(!i(T,e[h]))return!1;o.delete(h)}return 0===o.size}return!1},s=function(t){if(""===t||!1===t||null==t)return!0;if(Array.isArray(t)&&0===t.length)return!0;if(n(t)){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}return!1},o=function(t){return t>="0"&&t<="9"||"-"===t};!function(t){t.TOK_EOF="EOF",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(r||(r={}));var a,u,c=((e={"(":r.TOK_LPAREN,")":r.TOK_RPAREN,"*":r.TOK_STAR,",":r.TOK_COMMA,".":r.TOK_DOT,":":r.TOK_COLON,"@":r.TOK_CURRENT}).$=r.TOK_ROOT,e["]"]=r.TOK_RBRACKET,e["{"]=r.TOK_LBRACE,e["}"]=r.TOK_RBRACE,e),h={"!":!0,"<":!0,"=":!0,">":!0},T={"\t":!0,"\n":!0,"\r":!0," ":!0},_=new(function(){function t(){this._current=0}return t.prototype.tokenize=function(t){var e,n,i,s,a=[];for(this._current=0;this._current<t.length;)if((s=t[this._current])>="a"&&s<="z"||s>="A"&&s<="Z"||"_"===s)e=this._current,n=this.consumeUnquotedIdentifier(t),a.push({start:e,type:r.TOK_UNQUOTEDIDENTIFIER,value:n});else if(void 0!==c[t[this._current]])a.push({start:this._current,type:c[t[this._current]],value:t[this._current]}),this._current+=1;else if(o(t[this._current]))i=this.consumeNumber(t),a.push(i);else if("["===t[this._current])i=this.consumeLBracket(t),a.push(i);else if('"'===t[this._current])e=this._current,n=this.consumeQuotedIdentifier(t),a.push({start:e,type:r.TOK_QUOTEDIDENTIFIER,value:n});else if("'"===t[this._current])e=this._current,n=this.consumeRawStringLiteral(t),a.push({start:e,type:r.TOK_LITERAL,value:n});else if("`"===t[this._current]){e=this._current;var u=this.consumeLiteral(t);a.push({start:e,type:r.TOK_LITERAL,value:u})}else if(void 0!==h[t[this._current]])(i=this.consumeOperator(t))&&a.push(i);else if(void 0!==T[t[this._current]])this._current+=1;else if("&"===t[this._current])e=this._current,this._current+=1,"&"===t[this._current]?(this._current+=1,a.push({start:e,type:r.TOK_AND,value:"&&"})):a.push({start:e,type:r.TOK_EXPREF,value:"&"});else{if("|"!==t[this._current]){var _=new Error("Unknown character: "+t[this._current]);throw _.name="LexerError",_}e=this._current,this._current+=1,"|"===t[this._current]?(this._current+=1,a.push({start:e,type:r.TOK_OR,value:"||"})):a.push({start:e,type:r.TOK_PIPE,value:"|"})}return a},t.prototype.consumeUnquotedIdentifier=function(t){var e,r=this._current;for(this._current+=1;this._current<t.length&&((e=t[this._current])>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||"_"===e);)this._current+=1;return t.slice(r,this._current)},t.prototype.consumeQuotedIdentifier=function(t){var e=this._current;this._current+=1;for(var r=t.length;'"'!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&'"'!==t[n+1]?n+=1:n+=2,this._current=n}return this._current+=1,JSON.parse(t.slice(e,this._current))},t.prototype.consumeRawStringLiteral=function(t){var e=this._current;this._current+=1;for(var r=t.length;"'"!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&"'"!==t[n+1]?n+=1:n+=2,this._current=n}return this._current+=1,t.slice(e+1,this._current-1).replace("\\'","'")},t.prototype.consumeNumber=function(t){var e=this._current;this._current+=1;for(var n=t.length;o(t[this._current])&&this._current<n;)this._current+=1;return{start:e,value:parseInt(t.slice(e,this._current),10),type:r.TOK_NUMBER}},t.prototype.consumeLBracket=function(t){var e=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:e,type:r.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:e,type:r.TOK_FLATTEN,value:"[]"}):{start:e,type:r.TOK_LBRACKET,value:"["}},t.prototype.consumeOperator=function(t){var e=this._current,n=t[e];return this._current+=1,"!"===n?"="===t[this._current]?(this._current+=1,{start:e,type:r.TOK_NE,value:"!="}):{start:e,type:r.TOK_NOT,value:"!"}:"<"===n?"="===t[this._current]?(this._current+=1,{start:e,type:r.TOK_LTE,value:"<="}):{start:e,type:r.TOK_LT,value:"<"}:">"===n?"="===t[this._current]?(this._current+=1,{start:e,type:r.TOK_GTE,value:">="}):{start:e,type:r.TOK_GT,value:">"}:"="===n&&"="===t[this._current]?(this._current+=1,{start:e,type:r.TOK_EQ,value:"=="}):void 0},t.prototype.consumeLiteral=function(t){this._current+=1;for(var e=this._current,r=t.length;"`"!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&"`"!==t[n+1]?n+=1:n+=2,this._current=n}var i=t.slice(e,this._current).trimLeft();i=i.replace("\\`","`");var s=this.looksLikeJSON(i)?JSON.parse(i):JSON.parse('"'+i+'"');return this._current+=1,s},t.prototype.looksLikeJSON=function(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0]))try{return JSON.parse(t),!0}catch(t){return!1}return!1},t}()),E=((a={})[r.TOK_EOF]=0,a[r.TOK_UNQUOTEDIDENTIFIER]=0,a[r.TOK_QUOTEDIDENTIFIER]=0,a[r.TOK_RBRACKET]=0,a[r.TOK_RPAREN]=0,a[r.TOK_COMMA]=0,a[r.TOK_RBRACE]=0,a[r.TOK_NUMBER]=0,a[r.TOK_CURRENT]=0,a[r.TOK_EXPREF]=0,a[r.TOK_ROOT]=0,a[r.TOK_PIPE]=1,a[r.TOK_OR]=2,a[r.TOK_AND]=3,a[r.TOK_EQ]=5,a[r.TOK_GT]=5,a[r.TOK_LT]=5,a[r.TOK_GTE]=5,a[r.TOK_LTE]=5,a[r.TOK_NE]=5,a[r.TOK_FLATTEN]=9,a[r.TOK_STAR]=20,a[r.TOK_FILTER]=21,a[r.TOK_DOT]=40,a[r.TOK_NOT]=45,a[r.TOK_LBRACE]=50,a[r.TOK_LBRACKET]=55,a[r.TOK_LPAREN]=60,a),l=new(function(){function e(){this.index=0,this.tokens=[]}return e.prototype.parse=function(t){this.loadTokens(t),this.index=0;var e=this.expression(0);if(this.lookahead(0)!==r.TOK_EOF){var n=this.lookaheadToken(0);this.errorToken(n,"Unexpected token type: "+n.type+", value: "+n.value)}return e},e.prototype.loadTokens=function(e){this.tokens=t(_.tokenize(e),[{type:r.TOK_EOF,value:"",start:e.length}])},e.prototype.expression=function(t){var e=this.lookaheadToken(0);this.advance();for(var r=this.nud(e),n=this.lookahead(0);t<E[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r},e.prototype.lookahead=function(t){return this.tokens[this.index+t].type},e.prototype.lookaheadToken=function(t){return this.tokens[this.index+t]},e.prototype.advance=function(){this.index+=1},e.prototype.nud=function(t){var e,n;switch(t.type){case r.TOK_LITERAL:return{type:"Literal",value:t.value};case r.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:t.value};case r.TOK_QUOTEDIDENTIFIER:var i={type:"Field",name:t.value};if(this.lookahead(0)===r.TOK_LPAREN)throw new Error("Quoted identifier not allowed for function names.");return i;case r.TOK_NOT:return{type:"NotExpression",children:[e=this.expression(E.Not)]};case r.TOK_STAR:return{type:"ValueProjection",children:[{type:"Identity"},e=this.lookahead(0)===r.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(E.Star)]};case r.TOK_FILTER:return this.led(t.type,{type:"Identity"});case r.TOK_LBRACE:return this.parseMultiselectHash();case r.TOK_FLATTEN:return{type:"Projection",children:[{type:r.TOK_FLATTEN,children:[{type:"Identity"}]},e=this.parseProjectionRHS(E.Flatten)]};case r.TOK_LBRACKET:return this.lookahead(0)===r.TOK_NUMBER||this.lookahead(0)===r.TOK_COLON?(e=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},e)):this.lookahead(0)===r.TOK_STAR&&this.lookahead(1)===r.TOK_RBRACKET?(this.advance(),this.advance(),{children:[{type:"Identity"},e=this.parseProjectionRHS(E.Star)],type:"Projection"}):this.parseMultiselectList();case r.TOK_CURRENT:return{type:r.TOK_CURRENT};case r.TOK_ROOT:return{type:r.TOK_ROOT};case r.TOK_EXPREF:return{type:"ExpressionReference",children:[n=this.expression(E.Expref)]};case r.TOK_LPAREN:for(var s=[];this.lookahead(0)!==r.TOK_RPAREN;)this.lookahead(0)===r.TOK_CURRENT?(n={type:r.TOK_CURRENT},this.advance()):n=this.expression(0),s.push(n);return this.match(r.TOK_RPAREN),s[0];default:this.errorToken(t)}},e.prototype.led=function(t,e){var n;switch(t){case r.TOK_DOT:var i=E.Dot;return this.lookahead(0)!==r.TOK_STAR?{type:"Subexpression",children:[e,n=this.parseDotRHS(i)]}:(this.advance(),{type:"ValueProjection",children:[e,n=this.parseProjectionRHS(i)]});case r.TOK_PIPE:return n=this.expression(E.Pipe),{type:r.TOK_PIPE,children:[e,n]};case r.TOK_OR:return{type:"OrExpression",children:[e,n=this.expression(E.Or)]};case r.TOK_AND:return{type:"AndExpression",children:[e,n=this.expression(E.And)]};case r.TOK_LPAREN:for(var s=e.name,o=[],a=void 0;this.lookahead(0)!==r.TOK_RPAREN;)this.lookahead(0)===r.TOK_CURRENT?(a={type:r.TOK_CURRENT},this.advance()):a=this.expression(0),this.lookahead(0)===r.TOK_COMMA&&this.match(r.TOK_COMMA),o.push(a);return this.match(r.TOK_RPAREN),{name:s,type:"Function",children:o};case r.TOK_FILTER:var u=this.expression(0);return this.match(r.TOK_RBRACKET),{type:"FilterProjection",children:[e,n=this.lookahead(0)===r.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(E.Filter),u]};case r.TOK_FLATTEN:return{type:"Projection",children:[{type:r.TOK_FLATTEN,children:[e]},this.parseProjectionRHS(E.Flatten)]};case r.TOK_EQ:case r.TOK_NE:case r.TOK_GT:case r.TOK_GTE:case r.TOK_LT:case r.TOK_LTE:return this.parseComparator(e,t);case r.TOK_LBRACKET:var c=this.lookaheadToken(0);return c.type===r.TOK_NUMBER||c.type===r.TOK_COLON?(n=this.parseIndexExpression(),this.projectIfSlice(e,n)):(this.match(r.TOK_STAR),this.match(r.TOK_RBRACKET),{type:"Projection",children:[e,n=this.parseProjectionRHS(E.Star)]});default:return this.errorToken(this.lookaheadToken(0))}},e.prototype.match=function(t){if(this.lookahead(0)!==t){var e=this.lookaheadToken(0);this.errorToken(e,"Expected "+t+", got: "+e.type)}else this.advance()},e.prototype.errorToken=function(t,e){void 0===e&&(e="");var r=new Error(e||"Invalid token ("+t.type+'): "'+t.value+'"');throw r.name="ParserError",r},e.prototype.parseIndexExpression=function(){if(this.lookahead(0)===r.TOK_COLON||this.lookahead(1)===r.TOK_COLON)return this.parseSliceExpression();var t={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(r.TOK_RBRACKET),t},e.prototype.projectIfSlice=function(t,e){var r={type:"IndexExpression",children:[t,e]};return"Slice"===e.type?{children:[r,this.parseProjectionRHS(E.Star)],type:"Projection"}:r},e.prototype.parseSliceExpression=function(){for(var t=[null,null,null],e=0,n=this.lookahead(0);n!==r.TOK_RBRACKET&&e<3;){if(n===r.TOK_COLON)e+=1,this.advance();else if(n===r.TOK_NUMBER)t[e]=this.lookaheadToken(0).value,this.advance();else{var i=this.lookaheadToken(0);this.errorToken(i,"Syntax error, unexpected token: "+i.value+"("+i.type+")")}n=this.lookahead(0)}return this.match(r.TOK_RBRACKET),{children:t,type:"Slice"}},e.prototype.parseComparator=function(t,e){return{type:"Comparator",name:e,children:[t,this.expression(E[e])]}},e.prototype.parseDotRHS=function(t){var e=this.lookahead(0);if([r.TOK_UNQUOTEDIDENTIFIER,r.TOK_QUOTEDIDENTIFIER,r.TOK_STAR].includes(e))return this.expression(t);if(e===r.TOK_LBRACKET)return this.match(r.TOK_LBRACKET),this.parseMultiselectList();if(e===r.TOK_LBRACE)return this.match(r.TOK_LBRACE),this.parseMultiselectHash();var n=this.lookaheadToken(0);this.errorToken(n,"Syntax error, unexpected token: "+n.value+"("+n.type+")")},e.prototype.parseProjectionRHS=function(t){if(E[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===r.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===r.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===r.TOK_DOT)return this.match(r.TOK_DOT),this.parseDotRHS(t);var e=this.lookaheadToken(0);this.errorToken(e,"Syntax error, unexpected token: "+e.value+"("+e.type+")")},e.prototype.parseMultiselectList=function(){for(var t=[];this.lookahead(0)!==r.TOK_RBRACKET;){var e=this.expression(0);if(t.push(e),this.lookahead(0)===r.TOK_COMMA&&(this.match(r.TOK_COMMA),this.lookahead(0)===r.TOK_RBRACKET))throw new Error("Unexpected token Rbracket")}return this.match(r.TOK_RBRACKET),{type:"MultiSelectList",children:t}},e.prototype.parseMultiselectHash=function(){for(var t,e,n,i=[],s=[r.TOK_UNQUOTEDIDENTIFIER,r.TOK_QUOTEDIDENTIFIER];;){if(t=this.lookaheadToken(0),!s.includes(t.type))throw new Error("Expecting an identifier token, got: "+t.type);if(e=t.value,this.advance(),this.match(r.TOK_COLON),n=this.expression(0),i.push({value:n,type:"KeyValuePair",name:e}),this.lookahead(0)===r.TOK_COMMA)this.match(r.TOK_COMMA);else if(this.lookahead(0)===r.TOK_RBRACE){this.match(r.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:i}},e}());!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"}(u||(u={}));var p=function(){function e(e){var r,i=this;this.TYPE_NAME_TABLE=((r={})[u.TYPE_NUMBER]="number",r[u.TYPE_ANY]="any",r[u.TYPE_STRING]="string",r[u.TYPE_ARRAY]="array",r[u.TYPE_OBJECT]="object",r[u.TYPE_BOOLEAN]="boolean",r[u.TYPE_EXPREF]="expression",r[u.TYPE_NULL]="null",r[u.TYPE_ARRAY_NUMBER]="Array<number>",r[u.TYPE_ARRAY_STRING]="Array<string>",r),this.functionAbs=function(t){var e=t[0];return Math.abs(e)},this.functionAvg=function(t){for(var e=t[0],r=0,n=0;n<e.length;n+=1)r+=e[n];return r/e.length},this.functionCeil=function(t){var e=t[0];return Math.ceil(e)},this.functionContains=function(t){var e=t[0],r=t[1];return e.includes(r)},this.functionEndsWith=function(t){var e=t[0],r=t[1];return e.includes(r,e.length-r.length)},this.functionFloor=function(t){var e=t[0];return Math.floor(e)},this.functionJoin=function(t){var e=t[0];return t[1].join(e)},this.functionKeys=function(t){var e=t[0];return Object.keys(e)},this.functionLength=function(t){var e=t[0];return n(e)?Object.keys(e).length:e.length},this.functionMap=function(t){if(!i._interpreter)return[];for(var e=[],r=i._interpreter,n=t[0],s=t[1],o=0;o<s.length;o+=1)e.push(r.visit(n,s[o]));return e},this.functionMax=function(t){var e=t[0];if(!e.length)return null;if(i.getTypeName(e[0])===u.TYPE_NUMBER)return Math.max.apply(Math,e);for(var r=e,n=r[0],s=1;s<r.length;s+=1)n.localeCompare(r[s])<0&&(n=r[s]);return n},this.functionMaxBy=function(t){for(var e,r,n=t[1],s=t[0],o=i.createKeyFunction(n,[u.TYPE_NUMBER,u.TYPE_STRING]),a=-1/0,c=0;c<s.length;c+=1)void 0!==(r=o&&o(s[c]))&&r>a&&(a=r,e=s[c]);return e},this.functionMerge=function(t){for(var e={},r=0;r<t.length;r+=1){var n=t[r];e=Object.assign(e,n)}return e},this.functionMin=function(t){var e=t[0];if(!e.length)return null;if(i.getTypeName(e[0])===u.TYPE_NUMBER)return Math.min.apply(Math,e);for(var r=e,n=r[0],s=1;s<r.length;s+=1)r[s].localeCompare(n)<0&&(n=r[s]);return n},this.functionMinBy=function(t){for(var e,r,n=t[1],s=t[0],o=i.createKeyFunction(n,[u.TYPE_NUMBER,u.TYPE_STRING]),a=1/0,c=0;c<s.length;c+=1)void 0!==(r=o&&o(s[c]))&&r<a&&(a=r,e=s[c]);return e},this.functionNotNull=function(t){for(var e=0;e<t.length;e+=1)if(i.getTypeName(t[e])!==u.TYPE_NULL)return t[e];return null},this.functionReverse=function(t){var e=t[0];if(i.getTypeName(e)===u.TYPE_STRING){for(var r=e,n="",s=r.length-1;s>=0;s-=1)n+=r[s];return n}var o=e.slice(0);return o.reverse(),o},this.functionSort=function(e){return t(e[0]).sort()},this.functionSortBy=function(t){if(!i._interpreter)return[];var e=t[0].slice(0);if(0===e.length)return e;var r=i._interpreter,n=t[1],s=i.getTypeName(r.visit(n,e[0]));if(void 0!==s&&![u.TYPE_NUMBER,u.TYPE_STRING].includes(s))throw new Error("TypeError: unexpected type ("+i.TYPE_NAME_TABLE[s]+")");for(var o=[],a=0;a<e.length;a+=1)o.push([a,e[a]]);o.sort((function(t,e){var o=r.visit(n,t[1]),a=r.visit(n,e[1]);if(i.getTypeName(o)!==s)throw new Error("TypeError: expected ("+i.TYPE_NAME_TABLE[s]+"), received "+i.TYPE_NAME_TABLE[i.getTypeName(o)]);if(i.getTypeName(a)!==s)throw new Error("TypeError: expected ("+i.TYPE_NAME_TABLE[s]+"), received "+i.TYPE_NAME_TABLE[i.getTypeName(a)]);return o>a?1:o<a?-1:t[0]-e[0]}));for(var c=0;c<o.length;c+=1)e[c]=o[c][1];return e},this.functionStartsWith=function(t){var e=t[0],r=t[1];return e.startsWith(r)},this.functionSum=function(t){return t[0].reduce((function(t,e){return t+e}),0)},this.functionToArray=function(t){var e=t[0];return i.getTypeName(e)===u.TYPE_ARRAY?e:[e]},this.functionToNumber=function(t){var e,r=t[0],n=i.getTypeName(r);return n===u.TYPE_NUMBER?r:n!==u.TYPE_STRING||(e=+r,isNaN(e))?null:e},this.functionToString=function(t){var e=t[0];return i.getTypeName(e)===u.TYPE_STRING?e:JSON.stringify(e)},this.functionType=function(t){var e=t[0];switch(i.getTypeName(e)){case u.TYPE_NUMBER:return"number";case u.TYPE_STRING:return"string";case u.TYPE_ARRAY:return"array";case u.TYPE_OBJECT:return"object";case u.TYPE_BOOLEAN:return"boolean";case u.TYPE_EXPREF:return"expref";case u.TYPE_NULL:return"null";default:return}},this.functionValues=function(t){var e=t[0];return Object.values(e)},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[u.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[u.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[u.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[u.TYPE_STRING,u.TYPE_ARRAY]},{types:[u.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[u.TYPE_STRING]},{types:[u.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[u.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[u.TYPE_STRING]},{types:[u.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[u.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[u.TYPE_STRING,u.TYPE_ARRAY,u.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[u.TYPE_EXPREF]},{types:[u.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[u.TYPE_ARRAY_NUMBER,u.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[u.TYPE_ARRAY]},{types:[u.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[u.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[u.TYPE_ARRAY_NUMBER,u.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[u.TYPE_ARRAY]},{types:[u.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[u.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[u.TYPE_STRING,u.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[u.TYPE_ARRAY_STRING,u.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[u.TYPE_ARRAY]},{types:[u.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[u.TYPE_STRING]},{types:[u.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[u.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[u.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[u.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[u.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[u.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[u.TYPE_OBJECT]}]}},this._interpreter=e}return e.prototype.registerFunction=function(t,e,r){if(t in this.functionTable)throw new Error("Function already defined: "+t+"()");this.functionTable[t]={_func:e.bind(this),_signature:r}},e.prototype.callFunction=function(t,e){var r=this.functionTable[t];if(void 0===r)throw new Error("Unknown function: "+t+"()");return this.validateArgs(t,e,r._signature),r._func.call(this,e)},e.prototype.validateInputSignatures=function(t,e){for(var r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error("ArgumentError: "+t+"() 'variadic' argument "+(r+1)+" must occur last")},e.prototype.validateArgs=function(t,e,r){var n,i,s,o=this;this.validateInputSignatures(t,r);var a,u,c,h=r.filter((function(t){var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,T=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,_=e.length<h,E=e.length>r.length,l=_&&(!T&&h>1||T)?"at least ":"";if(T&&_||!T&&(_||E))throw s=r.length>1,new Error("ArgumentError: "+t+"() takes "+l+h+" argument"+(s?"s":"")+" but received "+e.length);for(var p=0;p<r.length;p+=1){c=!1,a=r[p].types,u=this.getTypeName(e[p]);var f=void 0;for(f=0;f<a.length;f+=1)if(void 0!==u&&this.typeMatches(u,a[f],e[p])){c=!0;break}if(!c&&void 0!==u){var R=a.map((function(t){return o.TYPE_NAME_TABLE[t]})).join(" | ");throw new Error("TypeError: "+t+"() expected argument "+(p+1)+" to be type ("+R+") but received type "+this.TYPE_NAME_TABLE[u]+" instead.")}}},e.prototype.typeMatches=function(t,e,r){if(e===u.TYPE_ANY)return!0;if(e!==u.TYPE_ARRAY_STRING&&e!==u.TYPE_ARRAY_NUMBER&&e!==u.TYPE_ARRAY)return t===e;if(e===u.TYPE_ARRAY)return t===u.TYPE_ARRAY;if(t===u.TYPE_ARRAY){var n=void 0;e===u.TYPE_ARRAY_NUMBER?n=u.TYPE_NUMBER:e===u.TYPE_ARRAY_STRING&&(n=u.TYPE_STRING);for(var i=0;i<r.length;i+=1){var s=this.getTypeName(r[i]);if(void 0!==s&&void 0!==n&&!this.typeMatches(s,n,r[i]))return!1}return!0}return!1},e.prototype.getTypeName=function(t){switch(Object.prototype.toString.call(t)){case"[object String]":return u.TYPE_STRING;case"[object Number]":return u.TYPE_NUMBER;case"[object Array]":return u.TYPE_ARRAY;case"[object Boolean]":return u.TYPE_BOOLEAN;case"[object Null]":return u.TYPE_NULL;case"[object Object]":return t.jmespathType===r.TOK_EXPREF?u.TYPE_EXPREF:u.TYPE_OBJECT;default:return}},e.prototype.createKeyFunction=function(t,e){var r=this;if(this._interpreter){var n=this._interpreter;return function(i){var s=n.visit(t,i);if(!e.includes(r.getTypeName(s))){var o="TypeError: expected one of ("+e.map((function(t){return r.TYPE_NAME_TABLE[t]})).join(" | ")+"), received "+r.TYPE_NAME_TABLE[r.getTypeName(s)];throw new Error(o)}return s}}},e}(),f=new(function(){function e(){this._rootValue=null,this.runtime=new p(this)}return e.prototype.search=function(t,e){return this._rootValue=e,this.visit(t,e)},e.prototype.visit=function(e,o){var a,u,c,h,T,_,E,l,p,f;switch(e.type){case"Field":return null===o?null:n(o)?void 0===(_=o[e.name])?null:_:null;case"Subexpression":for(c=this.visit(e.children[0],o),p=1;p<e.children.length;p+=1)if(null===(c=this.visit(e.children[1],c)))return null;return c;case"IndexExpression":return E=this.visit(e.children[0],o),this.visit(e.children[1],E);case"Index":if(!Array.isArray(o))return null;var R=e.value;return R<0&&(R=o.length+R),void 0===(c=o[R])&&(c=null),c;case"Slice":if(!Array.isArray(o))return null;var O=t(e.children),y=this.computeSliceParams(o.length,O),v=y[0],A=y[1],d=y[2];if(c=[],d>0)for(p=v;p<A;p+=d)c.push(o[p]);else for(p=v;p>A;p+=d)c.push(o[p]);return c;case"Projection":if(f=this.visit(e.children[0],o),!Array.isArray(f))return null;for(l=[],p=0;p<f.length;p+=1)null!==(u=this.visit(e.children[1],f[p]))&&l.push(u);return l;case"ValueProjection":if(f=this.visit(e.children[0],o),!n(f))return null;l=[];var N=Object.values(f);for(p=0;p<N.length;p+=1)null!==(u=this.visit(e.children[1],N[p]))&&l.push(u);return l;case"FilterProjection":if(f=this.visit(e.children[0],o),!Array.isArray(f))return null;var K=[],P=[];for(p=0;p<f.length;p+=1)a=this.visit(e.children[2],f[p]),s(a)||K.push(f[p]);for(var Y=0;Y<K.length;Y+=1)null!==(u=this.visit(e.children[1],K[Y]))&&P.push(u);return P;case"Comparator":switch(h=this.visit(e.children[0],o),T=this.visit(e.children[1],o),e.name){case r.TOK_EQ:c=i(h,T);break;case r.TOK_NE:c=!i(h,T);break;case r.TOK_GT:c=h>T;break;case r.TOK_GTE:c=h>=T;break;case r.TOK_LT:c=h<T;break;case r.TOK_LTE:c=h<=T;break;default:throw new Error("Unknown comparator: "+e.name)}return c;case r.TOK_FLATTEN:var g=this.visit(e.children[0],o);if(!Array.isArray(g))return null;var L=[];for(p=0;p<g.length;p+=1)u=g[p],Array.isArray(u)?L=t(L,u):L.push(u);return L;case"Identity":return o;case"MultiSelectList":if(null===o)return null;for(l=[],p=0;p<e.children.length;p+=1)l.push(this.visit(e.children[p],o));return l;case"MultiSelectHash":if(null===o)return null;l={};var I=void 0;for(p=0;p<e.children.length;p+=1)l[(I=e.children[p]).name]=this.visit(I.value,o);return l;case"OrExpression":return a=this.visit(e.children[0],o),s(a)&&(a=this.visit(e.children[1],o)),a;case"AndExpression":return h=this.visit(e.children[0],o),s(h)?h:this.visit(e.children[1],o);case"NotExpression":return h=this.visit(e.children[0],o),s(h);case"Literal":return e.value;case r.TOK_PIPE:return E=this.visit(e.children[0],o),this.visit(e.children[1],E);case r.TOK_CURRENT:return o;case r.TOK_ROOT:return this._rootValue;case"Function":var m=[];for(Y=0;Y<e.children.length;Y+=1)m.push(this.visit(e.children[Y],o));return this.runtime.callFunction(e.name,m);case"ExpressionReference":var k=e.children[0];return k.jmespathType=r.TOK_EXPREF,k;default:throw new Error("Unknown node type: "+e.type)}},e.prototype.computeSliceParams=function(t,e){var r=e[0],n=e[1],i=e[2];if(null===i)i=1;else if(0===i){var s=new Error("Invalid slice, step cannot be 0");throw s.name="RuntimeError",s}var o=i<0;return[r=null===r?o?t-1:0:this.capSliceRange(t,r,i),n=null===n?o?-1:t:this.capSliceRange(t,n,i),i]},e.prototype.capSliceRange=function(t,e,r){var n=e;return n<0?(n+=t)<0&&(n=r<0?-1:0):n>=t&&(n=r<0?t-1:t),n},e}()),R=u.TYPE_ANY,O=u.TYPE_ARRAY,y=u.TYPE_ARRAY_NUMBER,v=u.TYPE_ARRAY_STRING,A=u.TYPE_BOOLEAN,d=u.TYPE_EXPREF,N=u.TYPE_NULL,K=u.TYPE_NUMBER,P=u.TYPE_OBJECT,Y=u.TYPE_STRING;function g(t){return l.parse(t)}function L(t){return _.tokenize(t)}var I=function(t,e,r){f.runtime.registerFunction(t,e,r)};function m(t,e){var r=l.parse(e);return f.search(r,t)}var k=f,S={compile:g,registerFunction:I,search:m,tokenize:L,TreeInterpreter:k,TYPE_ANY:R,TYPE_ARRAY_NUMBER:y,TYPE_ARRAY_STRING:v,TYPE_ARRAY:O,TYPE_BOOLEAN:A,TYPE_EXPREF:d,TYPE_NULL:N,TYPE_NUMBER:K,TYPE_OBJECT:P,TYPE_STRING:Y};export default S;export{R as TYPE_ANY,O as TYPE_ARRAY,y as TYPE_ARRAY_NUMBER,v as TYPE_ARRAY_STRING,A as TYPE_BOOLEAN,d as TYPE_EXPREF,N as TYPE_NULL,K as TYPE_NUMBER,P as TYPE_OBJECT,Y as TYPE_STRING,k as TreeInterpreter,g as compile,S as jmespath,I as registerFunction,m as search,L as tokenize}; | ||
//# sourceMappingURL=jmespath.esm.min.js.map |
@@ -1,2 +0,16 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jmespath={})}(this,(function(t){"use strict";const e=t=>null!==t&&"[object Object]"===Object.prototype.toString.call(t),r=(t,n)=>{if(t===n)return!0;if(typeof t!=typeof n)return!1;if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e+=1)if(!r(t[e],n[e]))return!1;return!0}if(e(t)&&e(n)){const e=Object.entries(t),i=new Set(Object.keys(n));if(e.length!==i.size)return!1;for(const[t,s]of e){if(!r(s,n[t]))return!1;i.delete(t)}return 0===i.size}return!1},n=t=>{if(""===t||!1===t||null==t)return!0;if(Array.isArray(t)&&0===t.length)return!0;if(e(t)){for(const e in t)if(t.hasOwnProperty(e))return!1;return!0}return!1},i="function"==typeof String.prototype.trimLeft?t=>t.trimLeft():t=>{const e=/^\s*(.*)/.exec(t);return e&&e[1]},s=t=>t>="0"&&t<="9"||"-"===t;var o;!function(t){t.TOK_EOF="EOF",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(o||(o={}));const c={"(":o.TOK_LPAREN,")":o.TOK_RPAREN,"*":o.TOK_STAR,",":o.TOK_COMMA,".":o.TOK_DOT,":":o.TOK_COLON,"@":o.TOK_CURRENT,$:o.TOK_ROOT,"]":o.TOK_RBRACKET,"{":o.TOK_LBRACE,"}":o.TOK_RBRACE},h={"!":!0,"<":!0,"=":!0,">":!0},u={"\t":!0,"\n":!0,"\r":!0," ":!0};const a=new class{constructor(){this._current=0}tokenize(t){const e=[];let r,n,i;for(this._current=0;this._current<t.length;)if((a=t[this._current])>="a"&&a<="z"||a>="A"&&a<="Z"||"_"===a)r=this._current,n=this.consumeUnquotedIdentifier(t),e.push({start:r,type:o.TOK_UNQUOTEDIDENTIFIER,value:n});else if(void 0!==c[t[this._current]])e.push({start:this._current,type:c[t[this._current]],value:t[this._current]}),this._current+=1;else if(s(t[this._current]))i=this.consumeNumber(t),e.push(i);else if("["===t[this._current])i=this.consumeLBracket(t),e.push(i);else if('"'===t[this._current])r=this._current,n=this.consumeQuotedIdentifier(t),e.push({start:r,type:o.TOK_QUOTEDIDENTIFIER,value:n});else if("'"===t[this._current])r=this._current,n=this.consumeRawStringLiteral(t),e.push({start:r,type:o.TOK_LITERAL,value:n});else if("`"===t[this._current]){r=this._current;const n=this.consumeLiteral(t);e.push({start:r,type:o.TOK_LITERAL,value:n})}else if(void 0!==h[t[this._current]])i=this.consumeOperator(t),i&&e.push(i);else if(void 0!==u[t[this._current]])this._current+=1;else if("&"===t[this._current])r=this._current,this._current+=1,"&"===t[this._current]?(this._current+=1,e.push({start:r,type:o.TOK_AND,value:"&&"})):e.push({start:r,type:o.TOK_EXPREF,value:"&"});else{if("|"!==t[this._current]){const e=new Error("Unknown character: "+t[this._current]);throw e.name="LexerError",e}r=this._current,this._current+=1,"|"===t[this._current]?(this._current+=1,e.push({start:r,type:o.TOK_OR,value:"||"})):e.push({start:r,type:o.TOK_PIPE,value:"|"})}var a;return e}consumeUnquotedIdentifier(t){const e=this._current;for(this._current+=1;this._current<t.length&&((r=t[this._current])>="a"&&r<="z"||r>="A"&&r<="Z"||r>="0"&&r<="9"||"_"===r);)this._current+=1;var r;return t.slice(e,this._current)}consumeQuotedIdentifier(t){const e=this._current;this._current+=1;const r=t.length;for(;'"'!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&'"'!==t[e+1]?e+=1:e+=2,this._current=e}return this._current+=1,JSON.parse(t.slice(e,this._current))}consumeRawStringLiteral(t){const e=this._current;this._current+=1;const r=t.length;for(;"'"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"'"!==t[e+1]?e+=1:e+=2,this._current=e}this._current+=1;return t.slice(e+1,this._current-1).replace("\\'","'")}consumeNumber(t){const e=this._current;this._current+=1;const r=t.length;for(;s(t[this._current])&&this._current<r;)this._current+=1;return{start:e,value:parseInt(t.slice(e,this._current),10),type:o.TOK_NUMBER}}consumeLBracket(t){const e=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:e,type:o.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:e,type:o.TOK_FLATTEN,value:"[]"}):{start:e,type:o.TOK_LBRACKET,value:"["}}consumeOperator(t){const e=this._current,r=t[e];return this._current+=1,"!"===r?"="===t[this._current]?(this._current+=1,{start:e,type:o.TOK_NE,value:"!="}):{start:e,type:o.TOK_NOT,value:"!"}:"<"===r?"="===t[this._current]?(this._current+=1,{start:e,type:o.TOK_LTE,value:"<="}):{start:e,type:o.TOK_LT,value:"<"}:">"===r?"="===t[this._current]?(this._current+=1,{start:e,type:o.TOK_GTE,value:">="}):{start:e,type:o.TOK_GT,value:">"}:"="===r&&"="===t[this._current]?(this._current+=1,{start:e,type:o.TOK_EQ,value:"=="}):void 0}consumeLiteral(t){this._current+=1;const e=this._current,r=t.length;for(;"`"!==t[this._current]&&this._current<r;){let e=this._current;"\\"!==t[e]||"\\"!==t[e+1]&&"`"!==t[e+1]?e+=1:e+=2,this._current=e}let n=i(t.slice(e,this._current));n=n.replace("\\`","`");const s=this.looksLikeJSON(n)?JSON.parse(n):JSON.parse(`"${n}"`);return this._current+=1,s}looksLikeJSON(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0]))try{return JSON.parse(t),!0}catch(t){return!1}return!1}},T={[o.TOK_EOF]:0,[o.TOK_UNQUOTEDIDENTIFIER]:0,[o.TOK_QUOTEDIDENTIFIER]:0,[o.TOK_RBRACKET]:0,[o.TOK_RPAREN]:0,[o.TOK_COMMA]:0,[o.TOK_RBRACE]:0,[o.TOK_NUMBER]:0,[o.TOK_CURRENT]:0,[o.TOK_EXPREF]:0,[o.TOK_ROOT]:0,[o.TOK_PIPE]:1,[o.TOK_OR]:2,[o.TOK_AND]:3,[o.TOK_EQ]:5,[o.TOK_GT]:5,[o.TOK_LT]:5,[o.TOK_GTE]:5,[o.TOK_LTE]:5,[o.TOK_NE]:5,[o.TOK_FLATTEN]:9,[o.TOK_STAR]:20,[o.TOK_FILTER]:21,[o.TOK_DOT]:40,[o.TOK_NOT]:45,[o.TOK_LBRACE]:50,[o.TOK_LBRACKET]:55,[o.TOK_LPAREN]:60};const _=new class{constructor(){this.index=0,this.tokens=[]}parse(t){this.loadTokens(t),this.index=0;const e=this.expression(0);if(this.lookahead(0)!==o.TOK_EOF){const t=this.lookaheadToken(0);this.errorToken(t,`Unexpected token type: ${t.type}, value: ${t.value}`)}return e}loadTokens(t){this.tokens=[...a.tokenize(t),{type:o.TOK_EOF,value:"",start:t.length}]}expression(t){const e=this.lookaheadToken(0);this.advance();let r=this.nud(e),n=this.lookahead(0);for(;t<T[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r}lookahead(t){return this.tokens[this.index+t].type}lookaheadToken(t){return this.tokens[this.index+t]}advance(){this.index+=1}nud(t){let e,r,n;switch(t.type){case o.TOK_LITERAL:return{type:"Literal",value:t.value};case o.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:t.value};case o.TOK_QUOTEDIDENTIFIER:const i={type:"Field",name:t.value};if(this.lookahead(0)===o.TOK_LPAREN)throw new Error("Quoted identifier not allowed for function names.");return i;case o.TOK_NOT:return r=this.expression(T.Not),{type:"NotExpression",children:[r]};case o.TOK_STAR:return e={type:"Identity"},r=this.lookahead(0)===o.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(T.Star),{type:"ValueProjection",children:[e,r]};case o.TOK_FILTER:return this.led(t.type,{type:"Identity"});case o.TOK_LBRACE:return this.parseMultiselectHash();case o.TOK_FLATTEN:return e={type:o.TOK_FLATTEN,children:[{type:"Identity"}]},r=this.parseProjectionRHS(T.Flatten),{type:"Projection",children:[e,r]};case o.TOK_LBRACKET:return this.lookahead(0)===o.TOK_NUMBER||this.lookahead(0)===o.TOK_COLON?(r=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},r)):this.lookahead(0)===o.TOK_STAR&&this.lookahead(1)===o.TOK_RBRACKET?(this.advance(),this.advance(),r=this.parseProjectionRHS(T.Star),{children:[{type:"Identity"},r],type:"Projection"}):this.parseMultiselectList();case o.TOK_CURRENT:return{type:o.TOK_CURRENT};case o.TOK_ROOT:return{type:o.TOK_ROOT};case o.TOK_EXPREF:return n=this.expression(T.Expref),{type:"ExpressionReference",children:[n]};case o.TOK_LPAREN:const s=[];for(;this.lookahead(0)!==o.TOK_RPAREN;)this.lookahead(0)===o.TOK_CURRENT?(n={type:o.TOK_CURRENT},this.advance()):n=this.expression(0),s.push(n);return this.match(o.TOK_RPAREN),s[0];default:this.errorToken(t)}}led(t,e){let r;switch(t){case o.TOK_DOT:const n=T.Dot;return this.lookahead(0)!==o.TOK_STAR?(r=this.parseDotRHS(n),{type:"Subexpression",children:[e,r]}):(this.advance(),r=this.parseProjectionRHS(n),{type:"ValueProjection",children:[e,r]});case o.TOK_PIPE:return r=this.expression(T.Pipe),{type:o.TOK_PIPE,children:[e,r]};case o.TOK_OR:return r=this.expression(T.Or),{type:"OrExpression",children:[e,r]};case o.TOK_AND:return r=this.expression(T.And),{type:"AndExpression",children:[e,r]};case o.TOK_LPAREN:const i=e.name,s=[];let c;for(;this.lookahead(0)!==o.TOK_RPAREN;)this.lookahead(0)===o.TOK_CURRENT?(c={type:o.TOK_CURRENT},this.advance()):c=this.expression(0),this.lookahead(0)===o.TOK_COMMA&&this.match(o.TOK_COMMA),s.push(c);this.match(o.TOK_RPAREN);return{name:i,type:"Function",children:s};case o.TOK_FILTER:const h=this.expression(0);return this.match(o.TOK_RBRACKET),r=this.lookahead(0)===o.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(T.Filter),{type:"FilterProjection",children:[e,r,h]};case o.TOK_FLATTEN:return{type:"Projection",children:[{type:o.TOK_FLATTEN,children:[e]},this.parseProjectionRHS(T.Flatten)]};case o.TOK_EQ:case o.TOK_NE:case o.TOK_GT:case o.TOK_GTE:case o.TOK_LT:case o.TOK_LTE:return this.parseComparator(e,t);case o.TOK_LBRACKET:const u=this.lookaheadToken(0);return u.type===o.TOK_NUMBER||u.type===o.TOK_COLON?(r=this.parseIndexExpression(),this.projectIfSlice(e,r)):(this.match(o.TOK_STAR),this.match(o.TOK_RBRACKET),r=this.parseProjectionRHS(T.Star),{type:"Projection",children:[e,r]});default:return this.errorToken(this.lookaheadToken(0))}}match(t){if(this.lookahead(0)!==t){const e=this.lookaheadToken(0);this.errorToken(e,`Expected ${t}, got: ${e.type}`)}else this.advance()}errorToken(t,e=""){const r=new Error(e||`Invalid token (${t.type}): "${t.value}"`);throw r.name="ParserError",r}parseIndexExpression(){if(this.lookahead(0)===o.TOK_COLON||this.lookahead(1)===o.TOK_COLON)return this.parseSliceExpression();const t={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(o.TOK_RBRACKET),t}projectIfSlice(t,e){const r={type:"IndexExpression",children:[t,e]};return"Slice"===e.type?{children:[r,this.parseProjectionRHS(T.Star)],type:"Projection"}:r}parseSliceExpression(){const t=[null,null,null];let e=0,r=this.lookahead(0);for(;r!==o.TOK_RBRACKET&&e<3;){if(r===o.TOK_COLON)e+=1,this.advance();else if(r===o.TOK_NUMBER)t[e]=this.lookaheadToken(0).value,this.advance();else{const t=this.lookaheadToken(0);this.errorToken(t,`Syntax error, unexpected token: ${t.value}(${t.type})`)}r=this.lookahead(0)}return this.match(o.TOK_RBRACKET),{children:t,type:"Slice"}}parseComparator(t,e){return{type:"Comparator",name:e,children:[t,this.expression(T[e])]}}parseDotRHS(t){const e=this.lookahead(0);if([o.TOK_UNQUOTEDIDENTIFIER,o.TOK_QUOTEDIDENTIFIER,o.TOK_STAR].includes(e))return this.expression(t);if(e===o.TOK_LBRACKET)return this.match(o.TOK_LBRACKET),this.parseMultiselectList();if(e===o.TOK_LBRACE)return this.match(o.TOK_LBRACE),this.parseMultiselectHash();const r=this.lookaheadToken(0);this.errorToken(r,`Syntax error, unexpected token: ${r.value}(${r.type})`)}parseProjectionRHS(t){if(T[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===o.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===o.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===o.TOK_DOT)return this.match(o.TOK_DOT),this.parseDotRHS(t);const e=this.lookaheadToken(0);this.errorToken(e,`Syntax error, unexpected token: ${e.value}(${e.type})`)}parseMultiselectList(){const t=[];for(;this.lookahead(0)!==o.TOK_RBRACKET;){const e=this.expression(0);if(t.push(e),this.lookahead(0)===o.TOK_COMMA&&(this.match(o.TOK_COMMA),this.lookahead(0)===o.TOK_RBRACKET))throw new Error("Unexpected token Rbracket")}return this.match(o.TOK_RBRACKET),{type:"MultiSelectList",children:t}}parseMultiselectHash(){const t=[],e=[o.TOK_UNQUOTEDIDENTIFIER,o.TOK_QUOTEDIDENTIFIER];let r,n,i,s;for(;;){if(r=this.lookaheadToken(0),!e.includes(r.type))throw new Error("Expecting an identifier token, got: "+r.type);if(n=r.value,this.advance(),this.match(o.TOK_COLON),i=this.expression(0),s={value:i,type:"KeyValuePair",name:n},t.push(s),this.lookahead(0)===o.TOK_COMMA)this.match(o.TOK_COMMA);else if(this.lookahead(0)===o.TOK_RBRACE){this.match(o.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:t}}};var l;!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"}(l||(l={}));class E{constructor(t){this.TYPE_NAME_TABLE={[l.TYPE_NUMBER]:"number",[l.TYPE_ANY]:"any",[l.TYPE_STRING]:"string",[l.TYPE_ARRAY]:"array",[l.TYPE_OBJECT]:"object",[l.TYPE_BOOLEAN]:"boolean",[l.TYPE_EXPREF]:"expression",[l.TYPE_NULL]:"null",[l.TYPE_ARRAY_NUMBER]:"Array<number>",[l.TYPE_ARRAY_STRING]:"Array<string>"},this.functionAbs=([t])=>Math.abs(t),this.functionAvg=([t])=>{let e=0;for(let r=0;r<t.length;r+=1)e+=t[r];return e/t.length},this.functionCeil=([t])=>Math.ceil(t),this.functionContains=t=>{const[e,r]=t;return e.includes(r)},this.functionEndsWith=t=>{const[e,r]=t;return e.includes(r,e.length-r.length)},this.functionFloor=([t])=>Math.floor(t),this.functionJoin=t=>{const[e,r]=t;return r.join(e)},this.functionKeys=([t])=>Object.keys(t),this.functionLength=([t])=>e(t)?Object.keys(t).length:t.length,this.functionMap=t=>{if(!this._interpreter)return[];const e=[],r=this._interpreter,n=t[0],i=t[1];for(let t=0;t<i.length;t+=1)e.push(r.visit(n,i[t]));return e},this.functionMax=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===l.TYPE_NUMBER)return Math.max(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)r.localeCompare(e[t])<0&&(r=e[t]);return r},this.functionMaxBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[l.TYPE_NUMBER,l.TYPE_STRING]);let i,s,o=-1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s>o&&(o=s,i=r[t]);return i},this.functionMerge=t=>{let e={};for(let r=0;r<t.length;r+=1){const n=t[r];e=Object.assign(e,n)}return e},this.functionMin=([t])=>{if(!t.length)return null;if(this.getTypeName(t[0])===l.TYPE_NUMBER)return Math.min(...t);const e=t;let r=e[0];for(let t=1;t<e.length;t+=1)e[t].localeCompare(r)<0&&(r=e[t]);return r},this.functionMinBy=t=>{const e=t[1],r=t[0],n=this.createKeyFunction(e,[l.TYPE_NUMBER,l.TYPE_STRING]);let i,s,o=1/0;for(let t=0;t<r.length;t+=1)s=n&&n(r[t]),void 0!==s&&s<o&&(o=s,i=r[t]);return i},this.functionNotNull=t=>{for(let e=0;e<t.length;e+=1)if(this.getTypeName(t[e])!==l.TYPE_NULL)return t[e];return null},this.functionReverse=([t])=>{if(this.getTypeName(t)===l.TYPE_STRING){const e=t;let r="";for(let t=e.length-1;t>=0;t-=1)r+=e[t];return r}const e=t.slice(0);return e.reverse(),e},this.functionSort=([t])=>[...t].sort(),this.functionSortBy=t=>{if(!this._interpreter)return[];const e=t[0].slice(0);if(0===e.length)return e;const r=this._interpreter,n=t[1],i=this.getTypeName(r.visit(n,e[0]));if(void 0!==i&&![l.TYPE_NUMBER,l.TYPE_STRING].includes(i))throw new Error(`TypeError: unexpected type (${this.TYPE_NAME_TABLE[i]})`);const s=[];for(let t=0;t<e.length;t+=1)s.push([t,e[t]]);s.sort(((t,e)=>{const s=r.visit(n,t[1]),o=r.visit(n,e[1]);if(this.getTypeName(s)!==i)throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[i]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(s)]}`);if(this.getTypeName(o)!==i)throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[i]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(o)]}`);return s>o?1:s<o?-1:t[0]-e[0]}));for(let t=0;t<s.length;t+=1)e[t]=s[t][1];return e},this.functionStartsWith=([t,e])=>t.startsWith(e),this.functionSum=([t])=>t.reduce(((t,e)=>t+e),0),this.functionToArray=([t])=>this.getTypeName(t)===l.TYPE_ARRAY?t:[t],this.functionToNumber=([t])=>{const e=this.getTypeName(t);let r;return e===l.TYPE_NUMBER?t:e!==l.TYPE_STRING||(r=+t,isNaN(r))?null:r},this.functionToString=([t])=>this.getTypeName(t)===l.TYPE_STRING?t:JSON.stringify(t),this.functionType=([t])=>{switch(this.getTypeName(t)){case l.TYPE_NUMBER:return"number";case l.TYPE_STRING:return"string";case l.TYPE_ARRAY:return"array";case l.TYPE_OBJECT:return"object";case l.TYPE_BOOLEAN:return"boolean";case l.TYPE_EXPREF:return"expref";case l.TYPE_NULL:return"null";default:return}},this.functionValues=([t])=>Object.values(t),this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[l.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[l.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[l.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[l.TYPE_STRING,l.TYPE_ARRAY]},{types:[l.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[l.TYPE_STRING]},{types:[l.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[l.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[l.TYPE_STRING]},{types:[l.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[l.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[l.TYPE_STRING,l.TYPE_ARRAY,l.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[l.TYPE_EXPREF]},{types:[l.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[l.TYPE_ARRAY_NUMBER,l.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[l.TYPE_ARRAY]},{types:[l.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[l.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[l.TYPE_ARRAY_NUMBER,l.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[l.TYPE_ARRAY]},{types:[l.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[l.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[l.TYPE_STRING,l.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[l.TYPE_ARRAY_STRING,l.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[l.TYPE_ARRAY]},{types:[l.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[l.TYPE_STRING]},{types:[l.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[l.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[l.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[l.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[l.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[l.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[l.TYPE_OBJECT]}]}},this._interpreter=t}registerFunction(t,e,r){if(t in this.functionTable)throw new Error(`Function already defined: ${t}()`);this.functionTable[t]={_func:e.bind(this),_signature:r}}callFunction(t,e){const r=this.functionTable[t];if(void 0===r)throw new Error(`Unknown function: ${t}()`);return this.validateArgs(t,e,r._signature),r._func.call(this,e)}validateInputSignatures(t,e){for(let r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error(`ArgumentError: ${t}() 'variadic' argument ${r+1} must occur last`)}validateArgs(t,e,r){var n,i;let s;this.validateInputSignatures(t,r);const o=r.filter((t=>{var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,c=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,h=e.length<o,u=e.length>r.length,a=h&&(!c&&o>1||c)?"at least ":"";if(c&&h||!c&&(h||u))throw s=r.length>1,new Error(`ArgumentError: ${t}() takes ${a}${o} argument${s?"s":""} but received ${e.length}`);let T,_,l;for(let n=0;n<r.length;n+=1){let i;for(l=!1,T=r[n].types,_=this.getTypeName(e[n]),i=0;i<T.length;i+=1)if(void 0!==_&&this.typeMatches(_,T[i],e[n])){l=!0;break}if(!l&&void 0!==_){const e=T.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ");throw new Error(`TypeError: ${t}() expected argument ${n+1} to be type (${e}) but received type ${this.TYPE_NAME_TABLE[_]} instead.`)}}}typeMatches(t,e,r){if(e===l.TYPE_ANY)return!0;if(e!==l.TYPE_ARRAY_STRING&&e!==l.TYPE_ARRAY_NUMBER&&e!==l.TYPE_ARRAY)return t===e;if(e===l.TYPE_ARRAY)return t===l.TYPE_ARRAY;if(t===l.TYPE_ARRAY){let t;e===l.TYPE_ARRAY_NUMBER?t=l.TYPE_NUMBER:e===l.TYPE_ARRAY_STRING&&(t=l.TYPE_STRING);for(let e=0;e<r.length;e+=1){const n=this.getTypeName(r[e]);if(void 0!==n&&void 0!==t&&!this.typeMatches(n,t,r[e]))return!1}return!0}return!1}getTypeName(t){switch(Object.prototype.toString.call(t)){case"[object String]":return l.TYPE_STRING;case"[object Number]":return l.TYPE_NUMBER;case"[object Array]":return l.TYPE_ARRAY;case"[object Boolean]":return l.TYPE_BOOLEAN;case"[object Null]":return l.TYPE_NULL;case"[object Object]":return t.jmespathType===o.TOK_EXPREF?l.TYPE_EXPREF:l.TYPE_OBJECT;default:return}}createKeyFunction(t,e){if(!this._interpreter)return;const r=this._interpreter;return n=>{const i=r.visit(t,n);if(!e.includes(this.getTypeName(i))){const t=`TypeError: expected one of (${e.map((t=>this.TYPE_NAME_TABLE[t])).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(i)]}`;throw new Error(t)}return i}}}const R=new class{constructor(){this._rootValue=null,this.runtime=new E(this)}search(t,e){return this._rootValue=e,this.visit(t,e)}visit(t,i){let s,c,h,u,a,T,_,l,E,R,p;switch(t.type){case"Field":return null===i?null:e(i)?(T=i[t.name],void 0===T?null:T):null;case"Subexpression":for(h=this.visit(t.children[0],i),R=1;R<t.children.length;R+=1)if(h=this.visit(t.children[1],h),null===h)return null;return h;case"IndexExpression":return _=this.visit(t.children[0],i),l=this.visit(t.children[1],_),l;case"Index":if(!Array.isArray(i))return null;let O=t.value;return O<0&&(O=i.length+O),h=i[O],void 0===h&&(h=null),h;case"Slice":if(!Array.isArray(i))return null;const f=[...t.children],A=this.computeSliceParams(i.length,f),[d,N,P]=A;if(h=[],P>0)for(R=d;R<N;R+=P)h.push(i[R]);else for(R=d;R>N;R+=P)h.push(i[R]);return h;case"Projection":if(p=this.visit(t.children[0],i),!Array.isArray(p))return null;for(E=[],R=0;R<p.length;R+=1)c=this.visit(t.children[1],p[R]),null!==c&&E.push(c);return E;case"ValueProjection":if(p=this.visit(t.children[0],i),!e(p))return null;E=[];const y=Object.values(p);for(R=0;R<y.length;R+=1)c=this.visit(t.children[1],y[R]),null!==c&&E.push(c);return E;case"FilterProjection":if(p=this.visit(t.children[0],i),!Array.isArray(p))return null;const K=[],Y=[];for(R=0;R<p.length;R+=1)s=this.visit(t.children[2],p[R]),n(s)||K.push(p[R]);for(let e=0;e<K.length;e+=1)c=this.visit(t.children[1],K[e]),null!==c&&Y.push(c);return Y;case"Comparator":switch(u=this.visit(t.children[0],i),a=this.visit(t.children[1],i),t.name){case o.TOK_EQ:h=r(u,a);break;case o.TOK_NE:h=!r(u,a);break;case o.TOK_GT:h=u>a;break;case o.TOK_GTE:h=u>=a;break;case o.TOK_LT:h=u<a;break;case o.TOK_LTE:h=u<=a;break;default:throw new Error("Unknown comparator: "+t.name)}return h;case o.TOK_FLATTEN:const g=this.visit(t.children[0],i);if(!Array.isArray(g))return null;let v=[];for(R=0;R<g.length;R+=1)c=g[R],Array.isArray(c)?v=[...v,...c]:v.push(c);return v;case"Identity":return i;case"MultiSelectList":if(null===i)return null;for(E=[],R=0;R<t.children.length;R+=1)E.push(this.visit(t.children[R],i));return E;case"MultiSelectHash":if(null===i)return null;let L;for(E={},R=0;R<t.children.length;R+=1)L=t.children[R],E[L.name]=this.visit(L.value,i);return E;case"OrExpression":return s=this.visit(t.children[0],i),n(s)&&(s=this.visit(t.children[1],i)),s;case"AndExpression":return u=this.visit(t.children[0],i),n(u)?u:this.visit(t.children[1],i);case"NotExpression":return u=this.visit(t.children[0],i),n(u);case"Literal":return t.value;case o.TOK_PIPE:return _=this.visit(t.children[0],i),this.visit(t.children[1],_);case o.TOK_CURRENT:return i;case o.TOK_ROOT:return this._rootValue;case"Function":const m=[];for(let e=0;e<t.children.length;e+=1)m.push(this.visit(t.children[e],i));return this.runtime.callFunction(t.name,m);case"ExpressionReference":const I=t.children[0];return I.jmespathType=o.TOK_EXPREF,I;default:throw new Error("Unknown node type: "+t.type)}}computeSliceParams(t,e){let[r,n,i]=e;if(null===i)i=1;else if(0===i){const t=new Error("Invalid slice, step cannot be 0");throw t.name="RuntimeError",t}const s=i<0;return r=null===r?s?t-1:0:this.capSliceRange(t,r,i),n=null===n?s?-1:t:this.capSliceRange(t,n,i),[r,n,i]}capSliceRange(t,e,r){let n=e;return n<0?(n+=t,n<0&&(n=r<0?-1:0)):n>=t&&(n=r<0?t-1:t),n}},p=l.TYPE_ANY,O=l.TYPE_ARRAY,f=l.TYPE_ARRAY_NUMBER,A=l.TYPE_ARRAY_STRING,d=l.TYPE_BOOLEAN,N=l.TYPE_EXPREF,P=l.TYPE_NULL,y=l.TYPE_NUMBER,K=l.TYPE_OBJECT,Y=l.TYPE_STRING;function g(t){return _.parse(t)}function v(t){return a.tokenize(t)}const L=(t,e,r)=>{R.runtime.registerFunction(t,e,r)};function m(t,e){const r=_.parse(e);return R.search(r,t)}const I=R,k={compile:g,registerFunction:L,search:m,tokenize:v,TreeInterpreter:I,TYPE_ANY:p,TYPE_ARRAY_NUMBER:f,TYPE_ARRAY_STRING:A,TYPE_ARRAY:O,TYPE_BOOLEAN:d,TYPE_EXPREF:N,TYPE_NULL:P,TYPE_NUMBER:y,TYPE_OBJECT:K,TYPE_STRING:Y};t.TYPE_ANY=p,t.TYPE_ARRAY=O,t.TYPE_ARRAY_NUMBER=f,t.TYPE_ARRAY_STRING=A,t.TYPE_BOOLEAN=d,t.TYPE_EXPREF=N,t.TYPE_NULL=P,t.TYPE_NUMBER=y,t.TYPE_OBJECT=K,t.TYPE_STRING=Y,t.TreeInterpreter=I,t.compile=g,t.default=k,t.jmespath=k,t.registerFunction=L,t.search=m,t.tokenize=v,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jmespath={})}(this,(function(t){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function e(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)n[i]=s[o];return n}var r,n,i=function(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)},s=function(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(var r=0;r<t.length;r+=1)if(!s(t[r],e[r]))return!1;return!0}if(i(t)&&i(e)){var n=Object.entries(t),o=new Set(Object.keys(e));if(n.length!==o.size)return!1;for(var a=0,u=n;a<u.length;a++){var c=u[a],T=c[0],h=c[1];if(!s(h,e[T]))return!1;o.delete(T)}return 0===o.size}return!1},o=function(t){if(""===t||!1===t||null==t)return!0;if(Array.isArray(t)&&0===t.length)return!0;if(i(t)){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}return!1},a=function(t){return t>="0"&&t<="9"||"-"===t};!function(t){t.TOK_EOF="EOF",t.TOK_UNQUOTEDIDENTIFIER="UnquotedIdentifier",t.TOK_QUOTEDIDENTIFIER="QuotedIdentifier",t.TOK_RBRACKET="Rbracket",t.TOK_RPAREN="Rparen",t.TOK_COMMA="Comma",t.TOK_COLON="Colon",t.TOK_RBRACE="Rbrace",t.TOK_NUMBER="Number",t.TOK_CURRENT="Current",t.TOK_ROOT="Root",t.TOK_EXPREF="Expref",t.TOK_PIPE="Pipe",t.TOK_OR="Or",t.TOK_AND="And",t.TOK_EQ="EQ",t.TOK_GT="GT",t.TOK_LT="LT",t.TOK_GTE="GTE",t.TOK_LTE="LTE",t.TOK_NE="NE",t.TOK_FLATTEN="Flatten",t.TOK_STAR="Star",t.TOK_FILTER="Filter",t.TOK_DOT="Dot",t.TOK_NOT="Not",t.TOK_LBRACE="Lbrace",t.TOK_LBRACKET="Lbracket",t.TOK_LPAREN="Lparen",t.TOK_LITERAL="Literal"}(n||(n={}));var u,c,T=((r={"(":n.TOK_LPAREN,")":n.TOK_RPAREN,"*":n.TOK_STAR,",":n.TOK_COMMA,".":n.TOK_DOT,":":n.TOK_COLON,"@":n.TOK_CURRENT}).$=n.TOK_ROOT,r["]"]=n.TOK_RBRACKET,r["{"]=n.TOK_LBRACE,r["}"]=n.TOK_RBRACE,r),h={"!":!0,"<":!0,"=":!0,">":!0},_={"\t":!0,"\n":!0,"\r":!0," ":!0},E=new(function(){function t(){this._current=0}return t.prototype.tokenize=function(t){var e,r,i,s,o=[];for(this._current=0;this._current<t.length;)if((s=t[this._current])>="a"&&s<="z"||s>="A"&&s<="Z"||"_"===s)e=this._current,r=this.consumeUnquotedIdentifier(t),o.push({start:e,type:n.TOK_UNQUOTEDIDENTIFIER,value:r});else if(void 0!==T[t[this._current]])o.push({start:this._current,type:T[t[this._current]],value:t[this._current]}),this._current+=1;else if(a(t[this._current]))i=this.consumeNumber(t),o.push(i);else if("["===t[this._current])i=this.consumeLBracket(t),o.push(i);else if('"'===t[this._current])e=this._current,r=this.consumeQuotedIdentifier(t),o.push({start:e,type:n.TOK_QUOTEDIDENTIFIER,value:r});else if("'"===t[this._current])e=this._current,r=this.consumeRawStringLiteral(t),o.push({start:e,type:n.TOK_LITERAL,value:r});else if("`"===t[this._current]){e=this._current;var u=this.consumeLiteral(t);o.push({start:e,type:n.TOK_LITERAL,value:u})}else if(void 0!==h[t[this._current]])(i=this.consumeOperator(t))&&o.push(i);else if(void 0!==_[t[this._current]])this._current+=1;else if("&"===t[this._current])e=this._current,this._current+=1,"&"===t[this._current]?(this._current+=1,o.push({start:e,type:n.TOK_AND,value:"&&"})):o.push({start:e,type:n.TOK_EXPREF,value:"&"});else{if("|"!==t[this._current]){var c=new Error("Unknown character: "+t[this._current]);throw c.name="LexerError",c}e=this._current,this._current+=1,"|"===t[this._current]?(this._current+=1,o.push({start:e,type:n.TOK_OR,value:"||"})):o.push({start:e,type:n.TOK_PIPE,value:"|"})}return o},t.prototype.consumeUnquotedIdentifier=function(t){var e,r=this._current;for(this._current+=1;this._current<t.length&&((e=t[this._current])>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||"_"===e);)this._current+=1;return t.slice(r,this._current)},t.prototype.consumeQuotedIdentifier=function(t){var e=this._current;this._current+=1;for(var r=t.length;'"'!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&'"'!==t[n+1]?n+=1:n+=2,this._current=n}return this._current+=1,JSON.parse(t.slice(e,this._current))},t.prototype.consumeRawStringLiteral=function(t){var e=this._current;this._current+=1;for(var r=t.length;"'"!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&"'"!==t[n+1]?n+=1:n+=2,this._current=n}return this._current+=1,t.slice(e+1,this._current-1).replace("\\'","'")},t.prototype.consumeNumber=function(t){var e=this._current;this._current+=1;for(var r=t.length;a(t[this._current])&&this._current<r;)this._current+=1;return{start:e,value:parseInt(t.slice(e,this._current),10),type:n.TOK_NUMBER}},t.prototype.consumeLBracket=function(t){var e=this._current;return this._current+=1,"?"===t[this._current]?(this._current+=1,{start:e,type:n.TOK_FILTER,value:"[?"}):"]"===t[this._current]?(this._current+=1,{start:e,type:n.TOK_FLATTEN,value:"[]"}):{start:e,type:n.TOK_LBRACKET,value:"["}},t.prototype.consumeOperator=function(t){var e=this._current,r=t[e];return this._current+=1,"!"===r?"="===t[this._current]?(this._current+=1,{start:e,type:n.TOK_NE,value:"!="}):{start:e,type:n.TOK_NOT,value:"!"}:"<"===r?"="===t[this._current]?(this._current+=1,{start:e,type:n.TOK_LTE,value:"<="}):{start:e,type:n.TOK_LT,value:"<"}:">"===r?"="===t[this._current]?(this._current+=1,{start:e,type:n.TOK_GTE,value:">="}):{start:e,type:n.TOK_GT,value:">"}:"="===r&&"="===t[this._current]?(this._current+=1,{start:e,type:n.TOK_EQ,value:"=="}):void 0},t.prototype.consumeLiteral=function(t){this._current+=1;for(var e=this._current,r=t.length;"`"!==t[this._current]&&this._current<r;){var n=this._current;"\\"!==t[n]||"\\"!==t[n+1]&&"`"!==t[n+1]?n+=1:n+=2,this._current=n}var i=t.slice(e,this._current).trimLeft();i=i.replace("\\`","`");var s=this.looksLikeJSON(i)?JSON.parse(i):JSON.parse('"'+i+'"');return this._current+=1,s},t.prototype.looksLikeJSON=function(t){if(""===t)return!1;if('[{"'.includes(t[0]))return!0;if(["true","false","null"].includes(t))return!0;if("-0123456789".includes(t[0]))try{return JSON.parse(t),!0}catch(t){return!1}return!1},t}()),l=((u={})[n.TOK_EOF]=0,u[n.TOK_UNQUOTEDIDENTIFIER]=0,u[n.TOK_QUOTEDIDENTIFIER]=0,u[n.TOK_RBRACKET]=0,u[n.TOK_RPAREN]=0,u[n.TOK_COMMA]=0,u[n.TOK_RBRACE]=0,u[n.TOK_NUMBER]=0,u[n.TOK_CURRENT]=0,u[n.TOK_EXPREF]=0,u[n.TOK_ROOT]=0,u[n.TOK_PIPE]=1,u[n.TOK_OR]=2,u[n.TOK_AND]=3,u[n.TOK_EQ]=5,u[n.TOK_GT]=5,u[n.TOK_LT]=5,u[n.TOK_GTE]=5,u[n.TOK_LTE]=5,u[n.TOK_NE]=5,u[n.TOK_FLATTEN]=9,u[n.TOK_STAR]=20,u[n.TOK_FILTER]=21,u[n.TOK_DOT]=40,u[n.TOK_NOT]=45,u[n.TOK_LBRACE]=50,u[n.TOK_LBRACKET]=55,u[n.TOK_LPAREN]=60,u),p=new(function(){function t(){this.index=0,this.tokens=[]}return t.prototype.parse=function(t){this.loadTokens(t),this.index=0;var e=this.expression(0);if(this.lookahead(0)!==n.TOK_EOF){var r=this.lookaheadToken(0);this.errorToken(r,"Unexpected token type: "+r.type+", value: "+r.value)}return e},t.prototype.loadTokens=function(t){this.tokens=e(E.tokenize(t),[{type:n.TOK_EOF,value:"",start:t.length}])},t.prototype.expression=function(t){var e=this.lookaheadToken(0);this.advance();for(var r=this.nud(e),n=this.lookahead(0);t<l[n];)this.advance(),r=this.led(n,r),n=this.lookahead(0);return r},t.prototype.lookahead=function(t){return this.tokens[this.index+t].type},t.prototype.lookaheadToken=function(t){return this.tokens[this.index+t]},t.prototype.advance=function(){this.index+=1},t.prototype.nud=function(t){var e,r;switch(t.type){case n.TOK_LITERAL:return{type:"Literal",value:t.value};case n.TOK_UNQUOTEDIDENTIFIER:return{type:"Field",name:t.value};case n.TOK_QUOTEDIDENTIFIER:var i={type:"Field",name:t.value};if(this.lookahead(0)===n.TOK_LPAREN)throw new Error("Quoted identifier not allowed for function names.");return i;case n.TOK_NOT:return{type:"NotExpression",children:[e=this.expression(l.Not)]};case n.TOK_STAR:return{type:"ValueProjection",children:[{type:"Identity"},e=this.lookahead(0)===n.TOK_RBRACKET&&{type:"Identity"}||this.parseProjectionRHS(l.Star)]};case n.TOK_FILTER:return this.led(t.type,{type:"Identity"});case n.TOK_LBRACE:return this.parseMultiselectHash();case n.TOK_FLATTEN:return{type:"Projection",children:[{type:n.TOK_FLATTEN,children:[{type:"Identity"}]},e=this.parseProjectionRHS(l.Flatten)]};case n.TOK_LBRACKET:return this.lookahead(0)===n.TOK_NUMBER||this.lookahead(0)===n.TOK_COLON?(e=this.parseIndexExpression(),this.projectIfSlice({type:"Identity"},e)):this.lookahead(0)===n.TOK_STAR&&this.lookahead(1)===n.TOK_RBRACKET?(this.advance(),this.advance(),{children:[{type:"Identity"},e=this.parseProjectionRHS(l.Star)],type:"Projection"}):this.parseMultiselectList();case n.TOK_CURRENT:return{type:n.TOK_CURRENT};case n.TOK_ROOT:return{type:n.TOK_ROOT};case n.TOK_EXPREF:return{type:"ExpressionReference",children:[r=this.expression(l.Expref)]};case n.TOK_LPAREN:for(var s=[];this.lookahead(0)!==n.TOK_RPAREN;)this.lookahead(0)===n.TOK_CURRENT?(r={type:n.TOK_CURRENT},this.advance()):r=this.expression(0),s.push(r);return this.match(n.TOK_RPAREN),s[0];default:this.errorToken(t)}},t.prototype.led=function(t,e){var r;switch(t){case n.TOK_DOT:var i=l.Dot;return this.lookahead(0)!==n.TOK_STAR?{type:"Subexpression",children:[e,r=this.parseDotRHS(i)]}:(this.advance(),{type:"ValueProjection",children:[e,r=this.parseProjectionRHS(i)]});case n.TOK_PIPE:return r=this.expression(l.Pipe),{type:n.TOK_PIPE,children:[e,r]};case n.TOK_OR:return{type:"OrExpression",children:[e,r=this.expression(l.Or)]};case n.TOK_AND:return{type:"AndExpression",children:[e,r=this.expression(l.And)]};case n.TOK_LPAREN:for(var s=e.name,o=[],a=void 0;this.lookahead(0)!==n.TOK_RPAREN;)this.lookahead(0)===n.TOK_CURRENT?(a={type:n.TOK_CURRENT},this.advance()):a=this.expression(0),this.lookahead(0)===n.TOK_COMMA&&this.match(n.TOK_COMMA),o.push(a);return this.match(n.TOK_RPAREN),{name:s,type:"Function",children:o};case n.TOK_FILTER:var u=this.expression(0);return this.match(n.TOK_RBRACKET),{type:"FilterProjection",children:[e,r=this.lookahead(0)===n.TOK_FLATTEN&&{type:"Identity"}||this.parseProjectionRHS(l.Filter),u]};case n.TOK_FLATTEN:return{type:"Projection",children:[{type:n.TOK_FLATTEN,children:[e]},this.parseProjectionRHS(l.Flatten)]};case n.TOK_EQ:case n.TOK_NE:case n.TOK_GT:case n.TOK_GTE:case n.TOK_LT:case n.TOK_LTE:return this.parseComparator(e,t);case n.TOK_LBRACKET:var c=this.lookaheadToken(0);return c.type===n.TOK_NUMBER||c.type===n.TOK_COLON?(r=this.parseIndexExpression(),this.projectIfSlice(e,r)):(this.match(n.TOK_STAR),this.match(n.TOK_RBRACKET),{type:"Projection",children:[e,r=this.parseProjectionRHS(l.Star)]});default:return this.errorToken(this.lookaheadToken(0))}},t.prototype.match=function(t){if(this.lookahead(0)!==t){var e=this.lookaheadToken(0);this.errorToken(e,"Expected "+t+", got: "+e.type)}else this.advance()},t.prototype.errorToken=function(t,e){void 0===e&&(e="");var r=new Error(e||"Invalid token ("+t.type+'): "'+t.value+'"');throw r.name="ParserError",r},t.prototype.parseIndexExpression=function(){if(this.lookahead(0)===n.TOK_COLON||this.lookahead(1)===n.TOK_COLON)return this.parseSliceExpression();var t={type:"Index",value:this.lookaheadToken(0).value};return this.advance(),this.match(n.TOK_RBRACKET),t},t.prototype.projectIfSlice=function(t,e){var r={type:"IndexExpression",children:[t,e]};return"Slice"===e.type?{children:[r,this.parseProjectionRHS(l.Star)],type:"Projection"}:r},t.prototype.parseSliceExpression=function(){for(var t=[null,null,null],e=0,r=this.lookahead(0);r!==n.TOK_RBRACKET&&e<3;){if(r===n.TOK_COLON)e+=1,this.advance();else if(r===n.TOK_NUMBER)t[e]=this.lookaheadToken(0).value,this.advance();else{var i=this.lookaheadToken(0);this.errorToken(i,"Syntax error, unexpected token: "+i.value+"("+i.type+")")}r=this.lookahead(0)}return this.match(n.TOK_RBRACKET),{children:t,type:"Slice"}},t.prototype.parseComparator=function(t,e){return{type:"Comparator",name:e,children:[t,this.expression(l[e])]}},t.prototype.parseDotRHS=function(t){var e=this.lookahead(0);if([n.TOK_UNQUOTEDIDENTIFIER,n.TOK_QUOTEDIDENTIFIER,n.TOK_STAR].includes(e))return this.expression(t);if(e===n.TOK_LBRACKET)return this.match(n.TOK_LBRACKET),this.parseMultiselectList();if(e===n.TOK_LBRACE)return this.match(n.TOK_LBRACE),this.parseMultiselectHash();var r=this.lookaheadToken(0);this.errorToken(r,"Syntax error, unexpected token: "+r.value+"("+r.type+")")},t.prototype.parseProjectionRHS=function(t){if(l[this.lookahead(0)]<10)return{type:"Identity"};if(this.lookahead(0)===n.TOK_LBRACKET)return this.expression(t);if(this.lookahead(0)===n.TOK_FILTER)return this.expression(t);if(this.lookahead(0)===n.TOK_DOT)return this.match(n.TOK_DOT),this.parseDotRHS(t);var e=this.lookaheadToken(0);this.errorToken(e,"Syntax error, unexpected token: "+e.value+"("+e.type+")")},t.prototype.parseMultiselectList=function(){for(var t=[];this.lookahead(0)!==n.TOK_RBRACKET;){var e=this.expression(0);if(t.push(e),this.lookahead(0)===n.TOK_COMMA&&(this.match(n.TOK_COMMA),this.lookahead(0)===n.TOK_RBRACKET))throw new Error("Unexpected token Rbracket")}return this.match(n.TOK_RBRACKET),{type:"MultiSelectList",children:t}},t.prototype.parseMultiselectHash=function(){for(var t,e,r,i=[],s=[n.TOK_UNQUOTEDIDENTIFIER,n.TOK_QUOTEDIDENTIFIER];;){if(t=this.lookaheadToken(0),!s.includes(t.type))throw new Error("Expecting an identifier token, got: "+t.type);if(e=t.value,this.advance(),this.match(n.TOK_COLON),r=this.expression(0),i.push({value:r,type:"KeyValuePair",name:e}),this.lookahead(0)===n.TOK_COMMA)this.match(n.TOK_COMMA);else if(this.lookahead(0)===n.TOK_RBRACE){this.match(n.TOK_RBRACE);break}}return{type:"MultiSelectHash",children:i}},t}());!function(t){t[t.TYPE_NUMBER=0]="TYPE_NUMBER",t[t.TYPE_ANY=1]="TYPE_ANY",t[t.TYPE_STRING=2]="TYPE_STRING",t[t.TYPE_ARRAY=3]="TYPE_ARRAY",t[t.TYPE_OBJECT=4]="TYPE_OBJECT",t[t.TYPE_BOOLEAN=5]="TYPE_BOOLEAN",t[t.TYPE_EXPREF=6]="TYPE_EXPREF",t[t.TYPE_NULL=7]="TYPE_NULL",t[t.TYPE_ARRAY_NUMBER=8]="TYPE_ARRAY_NUMBER",t[t.TYPE_ARRAY_STRING=9]="TYPE_ARRAY_STRING"}(c||(c={}));var f=function(){function t(t){var r,n=this;this.TYPE_NAME_TABLE=((r={})[c.TYPE_NUMBER]="number",r[c.TYPE_ANY]="any",r[c.TYPE_STRING]="string",r[c.TYPE_ARRAY]="array",r[c.TYPE_OBJECT]="object",r[c.TYPE_BOOLEAN]="boolean",r[c.TYPE_EXPREF]="expression",r[c.TYPE_NULL]="null",r[c.TYPE_ARRAY_NUMBER]="Array<number>",r[c.TYPE_ARRAY_STRING]="Array<string>",r),this.functionAbs=function(t){var e=t[0];return Math.abs(e)},this.functionAvg=function(t){for(var e=t[0],r=0,n=0;n<e.length;n+=1)r+=e[n];return r/e.length},this.functionCeil=function(t){var e=t[0];return Math.ceil(e)},this.functionContains=function(t){var e=t[0],r=t[1];return e.includes(r)},this.functionEndsWith=function(t){var e=t[0],r=t[1];return e.includes(r,e.length-r.length)},this.functionFloor=function(t){var e=t[0];return Math.floor(e)},this.functionJoin=function(t){var e=t[0];return t[1].join(e)},this.functionKeys=function(t){var e=t[0];return Object.keys(e)},this.functionLength=function(t){var e=t[0];return i(e)?Object.keys(e).length:e.length},this.functionMap=function(t){if(!n._interpreter)return[];for(var e=[],r=n._interpreter,i=t[0],s=t[1],o=0;o<s.length;o+=1)e.push(r.visit(i,s[o]));return e},this.functionMax=function(t){var e=t[0];if(!e.length)return null;if(n.getTypeName(e[0])===c.TYPE_NUMBER)return Math.max.apply(Math,e);for(var r=e,i=r[0],s=1;s<r.length;s+=1)i.localeCompare(r[s])<0&&(i=r[s]);return i},this.functionMaxBy=function(t){for(var e,r,i=t[1],s=t[0],o=n.createKeyFunction(i,[c.TYPE_NUMBER,c.TYPE_STRING]),a=-1/0,u=0;u<s.length;u+=1)void 0!==(r=o&&o(s[u]))&&r>a&&(a=r,e=s[u]);return e},this.functionMerge=function(t){for(var e={},r=0;r<t.length;r+=1){var n=t[r];e=Object.assign(e,n)}return e},this.functionMin=function(t){var e=t[0];if(!e.length)return null;if(n.getTypeName(e[0])===c.TYPE_NUMBER)return Math.min.apply(Math,e);for(var r=e,i=r[0],s=1;s<r.length;s+=1)r[s].localeCompare(i)<0&&(i=r[s]);return i},this.functionMinBy=function(t){for(var e,r,i=t[1],s=t[0],o=n.createKeyFunction(i,[c.TYPE_NUMBER,c.TYPE_STRING]),a=1/0,u=0;u<s.length;u+=1)void 0!==(r=o&&o(s[u]))&&r<a&&(a=r,e=s[u]);return e},this.functionNotNull=function(t){for(var e=0;e<t.length;e+=1)if(n.getTypeName(t[e])!==c.TYPE_NULL)return t[e];return null},this.functionReverse=function(t){var e=t[0];if(n.getTypeName(e)===c.TYPE_STRING){for(var r=e,i="",s=r.length-1;s>=0;s-=1)i+=r[s];return i}var o=e.slice(0);return o.reverse(),o},this.functionSort=function(t){return e(t[0]).sort()},this.functionSortBy=function(t){if(!n._interpreter)return[];var e=t[0].slice(0);if(0===e.length)return e;var r=n._interpreter,i=t[1],s=n.getTypeName(r.visit(i,e[0]));if(void 0!==s&&![c.TYPE_NUMBER,c.TYPE_STRING].includes(s))throw new Error("TypeError: unexpected type ("+n.TYPE_NAME_TABLE[s]+")");for(var o=[],a=0;a<e.length;a+=1)o.push([a,e[a]]);o.sort((function(t,e){var o=r.visit(i,t[1]),a=r.visit(i,e[1]);if(n.getTypeName(o)!==s)throw new Error("TypeError: expected ("+n.TYPE_NAME_TABLE[s]+"), received "+n.TYPE_NAME_TABLE[n.getTypeName(o)]);if(n.getTypeName(a)!==s)throw new Error("TypeError: expected ("+n.TYPE_NAME_TABLE[s]+"), received "+n.TYPE_NAME_TABLE[n.getTypeName(a)]);return o>a?1:o<a?-1:t[0]-e[0]}));for(var u=0;u<o.length;u+=1)e[u]=o[u][1];return e},this.functionStartsWith=function(t){var e=t[0],r=t[1];return e.startsWith(r)},this.functionSum=function(t){return t[0].reduce((function(t,e){return t+e}),0)},this.functionToArray=function(t){var e=t[0];return n.getTypeName(e)===c.TYPE_ARRAY?e:[e]},this.functionToNumber=function(t){var e,r=t[0],i=n.getTypeName(r);return i===c.TYPE_NUMBER?r:i!==c.TYPE_STRING||(e=+r,isNaN(e))?null:e},this.functionToString=function(t){var e=t[0];return n.getTypeName(e)===c.TYPE_STRING?e:JSON.stringify(e)},this.functionType=function(t){var e=t[0];switch(n.getTypeName(e)){case c.TYPE_NUMBER:return"number";case c.TYPE_STRING:return"string";case c.TYPE_ARRAY:return"array";case c.TYPE_OBJECT:return"object";case c.TYPE_BOOLEAN:return"boolean";case c.TYPE_EXPREF:return"expref";case c.TYPE_NULL:return"null";default:return}},this.functionValues=function(t){var e=t[0];return Object.values(e)},this.functionTable={abs:{_func:this.functionAbs,_signature:[{types:[c.TYPE_NUMBER]}]},avg:{_func:this.functionAvg,_signature:[{types:[c.TYPE_ARRAY_NUMBER]}]},ceil:{_func:this.functionCeil,_signature:[{types:[c.TYPE_NUMBER]}]},contains:{_func:this.functionContains,_signature:[{types:[c.TYPE_STRING,c.TYPE_ARRAY]},{types:[c.TYPE_ANY]}]},ends_with:{_func:this.functionEndsWith,_signature:[{types:[c.TYPE_STRING]},{types:[c.TYPE_STRING]}]},floor:{_func:this.functionFloor,_signature:[{types:[c.TYPE_NUMBER]}]},join:{_func:this.functionJoin,_signature:[{types:[c.TYPE_STRING]},{types:[c.TYPE_ARRAY_STRING]}]},keys:{_func:this.functionKeys,_signature:[{types:[c.TYPE_OBJECT]}]},length:{_func:this.functionLength,_signature:[{types:[c.TYPE_STRING,c.TYPE_ARRAY,c.TYPE_OBJECT]}]},map:{_func:this.functionMap,_signature:[{types:[c.TYPE_EXPREF]},{types:[c.TYPE_ARRAY]}]},max:{_func:this.functionMax,_signature:[{types:[c.TYPE_ARRAY_NUMBER,c.TYPE_ARRAY_STRING]}]},max_by:{_func:this.functionMaxBy,_signature:[{types:[c.TYPE_ARRAY]},{types:[c.TYPE_EXPREF]}]},merge:{_func:this.functionMerge,_signature:[{types:[c.TYPE_OBJECT],variadic:!0}]},min:{_func:this.functionMin,_signature:[{types:[c.TYPE_ARRAY_NUMBER,c.TYPE_ARRAY_STRING]}]},min_by:{_func:this.functionMinBy,_signature:[{types:[c.TYPE_ARRAY]},{types:[c.TYPE_EXPREF]}]},not_null:{_func:this.functionNotNull,_signature:[{types:[c.TYPE_ANY],variadic:!0}]},reverse:{_func:this.functionReverse,_signature:[{types:[c.TYPE_STRING,c.TYPE_ARRAY]}]},sort:{_func:this.functionSort,_signature:[{types:[c.TYPE_ARRAY_STRING,c.TYPE_ARRAY_NUMBER]}]},sort_by:{_func:this.functionSortBy,_signature:[{types:[c.TYPE_ARRAY]},{types:[c.TYPE_EXPREF]}]},starts_with:{_func:this.functionStartsWith,_signature:[{types:[c.TYPE_STRING]},{types:[c.TYPE_STRING]}]},sum:{_func:this.functionSum,_signature:[{types:[c.TYPE_ARRAY_NUMBER]}]},to_array:{_func:this.functionToArray,_signature:[{types:[c.TYPE_ANY]}]},to_number:{_func:this.functionToNumber,_signature:[{types:[c.TYPE_ANY]}]},to_string:{_func:this.functionToString,_signature:[{types:[c.TYPE_ANY]}]},type:{_func:this.functionType,_signature:[{types:[c.TYPE_ANY]}]},values:{_func:this.functionValues,_signature:[{types:[c.TYPE_OBJECT]}]}},this._interpreter=t}return t.prototype.registerFunction=function(t,e,r){if(t in this.functionTable)throw new Error("Function already defined: "+t+"()");this.functionTable[t]={_func:e.bind(this),_signature:r}},t.prototype.callFunction=function(t,e){var r=this.functionTable[t];if(void 0===r)throw new Error("Unknown function: "+t+"()");return this.validateArgs(t,e,r._signature),r._func.call(this,e)},t.prototype.validateInputSignatures=function(t,e){for(var r=0;r<e.length;r+=1)if("variadic"in e[r]&&r!==e.length-1)throw new Error("ArgumentError: "+t+"() 'variadic' argument "+(r+1)+" must occur last")},t.prototype.validateArgs=function(t,e,r){var n,i,s,o=this;this.validateInputSignatures(t,r);var a,u,c,T=r.filter((function(t){var e;return null!==(e=!t.optional)&&void 0!==e&&e})).length,h=null!==(i=null===(n=r[r.length-1])||void 0===n?void 0:n.variadic)&&void 0!==i&&i,_=e.length<T,E=e.length>r.length,l=_&&(!h&&T>1||h)?"at least ":"";if(h&&_||!h&&(_||E))throw s=r.length>1,new Error("ArgumentError: "+t+"() takes "+l+T+" argument"+(s?"s":"")+" but received "+e.length);for(var p=0;p<r.length;p+=1){c=!1,a=r[p].types,u=this.getTypeName(e[p]);var f=void 0;for(f=0;f<a.length;f+=1)if(void 0!==u&&this.typeMatches(u,a[f],e[p])){c=!0;break}if(!c&&void 0!==u){var R=a.map((function(t){return o.TYPE_NAME_TABLE[t]})).join(" | ");throw new Error("TypeError: "+t+"() expected argument "+(p+1)+" to be type ("+R+") but received type "+this.TYPE_NAME_TABLE[u]+" instead.")}}},t.prototype.typeMatches=function(t,e,r){if(e===c.TYPE_ANY)return!0;if(e!==c.TYPE_ARRAY_STRING&&e!==c.TYPE_ARRAY_NUMBER&&e!==c.TYPE_ARRAY)return t===e;if(e===c.TYPE_ARRAY)return t===c.TYPE_ARRAY;if(t===c.TYPE_ARRAY){var n=void 0;e===c.TYPE_ARRAY_NUMBER?n=c.TYPE_NUMBER:e===c.TYPE_ARRAY_STRING&&(n=c.TYPE_STRING);for(var i=0;i<r.length;i+=1){var s=this.getTypeName(r[i]);if(void 0!==s&&void 0!==n&&!this.typeMatches(s,n,r[i]))return!1}return!0}return!1},t.prototype.getTypeName=function(t){switch(Object.prototype.toString.call(t)){case"[object String]":return c.TYPE_STRING;case"[object Number]":return c.TYPE_NUMBER;case"[object Array]":return c.TYPE_ARRAY;case"[object Boolean]":return c.TYPE_BOOLEAN;case"[object Null]":return c.TYPE_NULL;case"[object Object]":return t.jmespathType===n.TOK_EXPREF?c.TYPE_EXPREF:c.TYPE_OBJECT;default:return}},t.prototype.createKeyFunction=function(t,e){var r=this;if(this._interpreter){var n=this._interpreter;return function(i){var s=n.visit(t,i);if(!e.includes(r.getTypeName(s))){var o="TypeError: expected one of ("+e.map((function(t){return r.TYPE_NAME_TABLE[t]})).join(" | ")+"), received "+r.TYPE_NAME_TABLE[r.getTypeName(s)];throw new Error(o)}return s}}},t}(),R=new(function(){function t(){this._rootValue=null,this.runtime=new f(this)}return t.prototype.search=function(t,e){return this._rootValue=e,this.visit(t,e)},t.prototype.visit=function(t,r){var a,u,c,T,h,_,E,l,p,f;switch(t.type){case"Field":return null===r?null:i(r)?void 0===(_=r[t.name])?null:_:null;case"Subexpression":for(c=this.visit(t.children[0],r),p=1;p<t.children.length;p+=1)if(null===(c=this.visit(t.children[1],c)))return null;return c;case"IndexExpression":return E=this.visit(t.children[0],r),this.visit(t.children[1],E);case"Index":if(!Array.isArray(r))return null;var R=t.value;return R<0&&(R=r.length+R),void 0===(c=r[R])&&(c=null),c;case"Slice":if(!Array.isArray(r))return null;var O=e(t.children),y=this.computeSliceParams(r.length,O),v=y[0],d=y[1],A=y[2];if(c=[],A>0)for(p=v;p<d;p+=A)c.push(r[p]);else for(p=v;p>d;p+=A)c.push(r[p]);return c;case"Projection":if(f=this.visit(t.children[0],r),!Array.isArray(f))return null;for(l=[],p=0;p<f.length;p+=1)null!==(u=this.visit(t.children[1],f[p]))&&l.push(u);return l;case"ValueProjection":if(f=this.visit(t.children[0],r),!i(f))return null;l=[];var N=Object.values(f);for(p=0;p<N.length;p+=1)null!==(u=this.visit(t.children[1],N[p]))&&l.push(u);return l;case"FilterProjection":if(f=this.visit(t.children[0],r),!Array.isArray(f))return null;var P=[],K=[];for(p=0;p<f.length;p+=1)a=this.visit(t.children[2],f[p]),o(a)||P.push(f[p]);for(var Y=0;Y<P.length;Y+=1)null!==(u=this.visit(t.children[1],P[Y]))&&K.push(u);return K;case"Comparator":switch(T=this.visit(t.children[0],r),h=this.visit(t.children[1],r),t.name){case n.TOK_EQ:c=s(T,h);break;case n.TOK_NE:c=!s(T,h);break;case n.TOK_GT:c=T>h;break;case n.TOK_GTE:c=T>=h;break;case n.TOK_LT:c=T<h;break;case n.TOK_LTE:c=T<=h;break;default:throw new Error("Unknown comparator: "+t.name)}return c;case n.TOK_FLATTEN:var g=this.visit(t.children[0],r);if(!Array.isArray(g))return null;var L=[];for(p=0;p<g.length;p+=1)u=g[p],Array.isArray(u)?L=e(L,u):L.push(u);return L;case"Identity":return r;case"MultiSelectList":if(null===r)return null;for(l=[],p=0;p<t.children.length;p+=1)l.push(this.visit(t.children[p],r));return l;case"MultiSelectHash":if(null===r)return null;l={};var m=void 0;for(p=0;p<t.children.length;p+=1)l[(m=t.children[p]).name]=this.visit(m.value,r);return l;case"OrExpression":return a=this.visit(t.children[0],r),o(a)&&(a=this.visit(t.children[1],r)),a;case"AndExpression":return T=this.visit(t.children[0],r),o(T)?T:this.visit(t.children[1],r);case"NotExpression":return T=this.visit(t.children[0],r),o(T);case"Literal":return t.value;case n.TOK_PIPE:return E=this.visit(t.children[0],r),this.visit(t.children[1],E);case n.TOK_CURRENT:return r;case n.TOK_ROOT:return this._rootValue;case"Function":var I=[];for(Y=0;Y<t.children.length;Y+=1)I.push(this.visit(t.children[Y],r));return this.runtime.callFunction(t.name,I);case"ExpressionReference":var k=t.children[0];return k.jmespathType=n.TOK_EXPREF,k;default:throw new Error("Unknown node type: "+t.type)}},t.prototype.computeSliceParams=function(t,e){var r=e[0],n=e[1],i=e[2];if(null===i)i=1;else if(0===i){var s=new Error("Invalid slice, step cannot be 0");throw s.name="RuntimeError",s}var o=i<0;return[r=null===r?o?t-1:0:this.capSliceRange(t,r,i),n=null===n?o?-1:t:this.capSliceRange(t,n,i),i]},t.prototype.capSliceRange=function(t,e,r){var n=e;return n<0?(n+=t)<0&&(n=r<0?-1:0):n>=t&&(n=r<0?t-1:t),n},t}()),O=c.TYPE_ANY,y=c.TYPE_ARRAY,v=c.TYPE_ARRAY_NUMBER,d=c.TYPE_ARRAY_STRING,A=c.TYPE_BOOLEAN,N=c.TYPE_EXPREF,P=c.TYPE_NULL,K=c.TYPE_NUMBER,Y=c.TYPE_OBJECT,g=c.TYPE_STRING;function L(t){return p.parse(t)}function m(t){return E.tokenize(t)}var I=function(t,e,r){R.runtime.registerFunction(t,e,r)};function k(t,e){var r=p.parse(e);return R.search(r,t)}var B=R,S={compile:L,registerFunction:I,search:k,tokenize:m,TreeInterpreter:B,TYPE_ANY:O,TYPE_ARRAY_NUMBER:v,TYPE_ARRAY_STRING:d,TYPE_ARRAY:y,TYPE_BOOLEAN:A,TYPE_EXPREF:N,TYPE_NULL:P,TYPE_NUMBER:K,TYPE_OBJECT:Y,TYPE_STRING:g};t.TYPE_ANY=O,t.TYPE_ARRAY=y,t.TYPE_ARRAY_NUMBER=v,t.TYPE_ARRAY_STRING=d,t.TYPE_BOOLEAN=A,t.TYPE_EXPREF=N,t.TYPE_NULL=P,t.TYPE_NUMBER=K,t.TYPE_OBJECT=Y,t.TYPE_STRING=g,t.TreeInterpreter=B,t.compile=L,t.default=S,t.jmespath=S,t.registerFunction=I,t.search=k,t.tokenize=m,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=jmespath.umd.min.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jmespath = exports.TreeInterpreter = exports.search = exports.registerFunction = exports.tokenize = exports.compile = exports.TYPE_STRING = exports.TYPE_OBJECT = exports.TYPE_NUMBER = exports.TYPE_NULL = exports.TYPE_EXPREF = exports.TYPE_BOOLEAN = exports.TYPE_ARRAY_STRING = exports.TYPE_ARRAY_NUMBER = exports.TYPE_ARRAY = exports.TYPE_ANY = void 0; | ||
const Parser_1 = require("./Parser"); | ||
const Lexer_1 = require("./Lexer"); | ||
const TreeInterpreter_1 = require("./TreeInterpreter"); | ||
const Runtime_1 = require("./Runtime"); | ||
var Parser_1 = __importDefault(require("./Parser")); | ||
var Lexer_1 = __importDefault(require("./Lexer")); | ||
var TreeInterpreter_1 = __importDefault(require("./TreeInterpreter")); | ||
var Runtime_1 = require("./Runtime"); | ||
exports.TYPE_ANY = Runtime_1.InputArgument.TYPE_ANY; | ||
@@ -19,3 +22,3 @@ exports.TYPE_ARRAY = Runtime_1.InputArgument.TYPE_ARRAY; | ||
function compile(expression) { | ||
const nodeTree = Parser_1.default.parse(expression); | ||
var nodeTree = Parser_1.default.parse(expression); | ||
return nodeTree; | ||
@@ -28,7 +31,8 @@ } | ||
exports.tokenize = tokenize; | ||
exports.registerFunction = (functionName, customFunction, signature) => { | ||
var registerFunction = function (functionName, customFunction, signature) { | ||
TreeInterpreter_1.default.runtime.registerFunction(functionName, customFunction, signature); | ||
}; | ||
exports.registerFunction = registerFunction; | ||
function search(data, expression) { | ||
const nodeTree = Parser_1.default.parse(expression); | ||
var nodeTree = Parser_1.default.parse(expression); | ||
return TreeInterpreter_1.default.search(nodeTree, data); | ||
@@ -39,6 +43,6 @@ } | ||
exports.jmespath = { | ||
compile, | ||
compile: compile, | ||
registerFunction: exports.registerFunction, | ||
search, | ||
tokenize, | ||
search: search, | ||
tokenize: tokenize, | ||
TreeInterpreter: exports.TreeInterpreter, | ||
@@ -45,0 +49,0 @@ TYPE_ANY: exports.TYPE_ANY, |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Lexer = exports.basicTokens = exports.Token = void 0; | ||
const utils_1 = require("./utils"); | ||
var index_1 = require("./utils/index"); | ||
var Token; | ||
@@ -38,16 +39,17 @@ (function (Token) { | ||
})(Token = exports.Token || (exports.Token = {})); | ||
exports.basicTokens = { | ||
'(': Token.TOK_LPAREN, | ||
')': Token.TOK_RPAREN, | ||
'*': Token.TOK_STAR, | ||
',': Token.TOK_COMMA, | ||
'.': Token.TOK_DOT, | ||
':': Token.TOK_COLON, | ||
'@': Token.TOK_CURRENT, | ||
['$']: Token.TOK_ROOT, | ||
']': Token.TOK_RBRACKET, | ||
'{': Token.TOK_LBRACE, | ||
'}': Token.TOK_RBRACE, | ||
}; | ||
const operatorStartToken = { | ||
exports.basicTokens = (_a = { | ||
'(': Token.TOK_LPAREN, | ||
')': Token.TOK_RPAREN, | ||
'*': Token.TOK_STAR, | ||
',': Token.TOK_COMMA, | ||
'.': Token.TOK_DOT, | ||
':': Token.TOK_COLON, | ||
'@': Token.TOK_CURRENT | ||
}, | ||
_a['$'] = Token.TOK_ROOT, | ||
_a[']'] = Token.TOK_RBRACKET, | ||
_a['{'] = Token.TOK_LBRACE, | ||
_a['}'] = Token.TOK_RBRACE, | ||
_a); | ||
var operatorStartToken = { | ||
'!': true, | ||
@@ -58,3 +60,3 @@ '<': true, | ||
}; | ||
const skipChars = { | ||
var skipChars = { | ||
'\t': true, | ||
@@ -65,18 +67,18 @@ '\n': true, | ||
}; | ||
class StreamLexer { | ||
constructor() { | ||
var StreamLexer = /** @class */ (function () { | ||
function StreamLexer() { | ||
this._current = 0; | ||
} | ||
tokenize(stream) { | ||
const tokens = []; | ||
StreamLexer.prototype.tokenize = function (stream) { | ||
var tokens = []; | ||
this._current = 0; | ||
let start; | ||
let identifier; | ||
let token; | ||
var start; | ||
var identifier; | ||
var token; | ||
while (this._current < stream.length) { | ||
if (utils_1.isAlpha(stream[this._current])) { | ||
if (index_1.isAlpha(stream[this._current])) { | ||
start = this._current; | ||
identifier = this.consumeUnquotedIdentifier(stream); | ||
tokens.push({ | ||
start, | ||
start: start, | ||
type: Token.TOK_UNQUOTEDIDENTIFIER, | ||
@@ -94,3 +96,3 @@ value: identifier, | ||
} | ||
else if (utils_1.isNum(stream[this._current])) { | ||
else if (index_1.isNum(stream[this._current])) { | ||
token = this.consumeNumber(stream); | ||
@@ -107,3 +109,3 @@ tokens.push(token); | ||
tokens.push({ | ||
start, | ||
start: start, | ||
type: Token.TOK_QUOTEDIDENTIFIER, | ||
@@ -113,7 +115,7 @@ value: identifier, | ||
} | ||
else if (stream[this._current] === `'`) { | ||
else if (stream[this._current] === "'") { | ||
start = this._current; | ||
identifier = this.consumeRawStringLiteral(stream); | ||
tokens.push({ | ||
start, | ||
start: start, | ||
type: Token.TOK_LITERAL, | ||
@@ -125,5 +127,5 @@ value: identifier, | ||
start = this._current; | ||
const literal = this.consumeLiteral(stream); | ||
var literal = this.consumeLiteral(stream); | ||
tokens.push({ | ||
start, | ||
start: start, | ||
type: Token.TOK_LITERAL, | ||
@@ -145,6 +147,6 @@ value: literal, | ||
this._current += 1; | ||
tokens.push({ start, type: Token.TOK_AND, value: '&&' }); | ||
tokens.push({ start: start, type: Token.TOK_AND, value: '&&' }); | ||
} | ||
else { | ||
tokens.push({ start, type: Token.TOK_EXPREF, value: '&' }); | ||
tokens.push({ start: start, type: Token.TOK_EXPREF, value: '&' }); | ||
} | ||
@@ -157,10 +159,10 @@ } | ||
this._current += 1; | ||
tokens.push({ start, type: Token.TOK_OR, value: '||' }); | ||
tokens.push({ start: start, type: Token.TOK_OR, value: '||' }); | ||
} | ||
else { | ||
tokens.push({ start, type: Token.TOK_PIPE, value: '|' }); | ||
tokens.push({ start: start, type: Token.TOK_PIPE, value: '|' }); | ||
} | ||
} | ||
else { | ||
const error = new Error(`Unknown character: ${stream[this._current]}`); | ||
var error = new Error("Unknown character: " + stream[this._current]); | ||
error.name = 'LexerError'; | ||
@@ -171,17 +173,17 @@ throw error; | ||
return tokens; | ||
} | ||
consumeUnquotedIdentifier(stream) { | ||
const start = this._current; | ||
}; | ||
StreamLexer.prototype.consumeUnquotedIdentifier = function (stream) { | ||
var start = this._current; | ||
this._current += 1; | ||
while (this._current < stream.length && utils_1.isAlphaNum(stream[this._current])) { | ||
while (this._current < stream.length && index_1.isAlphaNum(stream[this._current])) { | ||
this._current += 1; | ||
} | ||
return stream.slice(start, this._current); | ||
} | ||
consumeQuotedIdentifier(stream) { | ||
const start = this._current; | ||
}; | ||
StreamLexer.prototype.consumeQuotedIdentifier = function (stream) { | ||
var start = this._current; | ||
this._current += 1; | ||
const maxLength = stream.length; | ||
var maxLength = stream.length; | ||
while (stream[this._current] !== '"' && this._current < maxLength) { | ||
let current = this._current; | ||
var current = this._current; | ||
if (stream[current] === '\\' && (stream[current + 1] === '\\' || stream[current + 1] === '"')) { | ||
@@ -197,10 +199,10 @@ current += 2; | ||
return JSON.parse(stream.slice(start, this._current)); | ||
} | ||
consumeRawStringLiteral(stream) { | ||
const start = this._current; | ||
}; | ||
StreamLexer.prototype.consumeRawStringLiteral = function (stream) { | ||
var start = this._current; | ||
this._current += 1; | ||
const maxLength = stream.length; | ||
while (stream[this._current] !== `'` && this._current < maxLength) { | ||
let current = this._current; | ||
if (stream[current] === '\\' && (stream[current + 1] === '\\' || stream[current + 1] === `'`)) { | ||
var maxLength = stream.length; | ||
while (stream[this._current] !== "'" && this._current < maxLength) { | ||
var current = this._current; | ||
if (stream[current] === '\\' && (stream[current + 1] === '\\' || stream[current + 1] === "'")) { | ||
current += 2; | ||
@@ -214,31 +216,31 @@ } | ||
this._current += 1; | ||
const literal = stream.slice(start + 1, this._current - 1); | ||
return literal.replace(`\\'`, `'`); | ||
} | ||
consumeNumber(stream) { | ||
const start = this._current; | ||
var literal = stream.slice(start + 1, this._current - 1); | ||
return literal.replace("\\'", "'"); | ||
}; | ||
StreamLexer.prototype.consumeNumber = function (stream) { | ||
var start = this._current; | ||
this._current += 1; | ||
const maxLength = stream.length; | ||
while (utils_1.isNum(stream[this._current]) && this._current < maxLength) { | ||
var maxLength = stream.length; | ||
while (index_1.isNum(stream[this._current]) && this._current < maxLength) { | ||
this._current += 1; | ||
} | ||
const value = parseInt(stream.slice(start, this._current), 10); | ||
return { start, value, type: Token.TOK_NUMBER }; | ||
} | ||
consumeLBracket(stream) { | ||
const start = this._current; | ||
var value = parseInt(stream.slice(start, this._current), 10); | ||
return { start: start, value: value, type: Token.TOK_NUMBER }; | ||
}; | ||
StreamLexer.prototype.consumeLBracket = function (stream) { | ||
var start = this._current; | ||
this._current += 1; | ||
if (stream[this._current] === '?') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_FILTER, value: '[?' }; | ||
return { start: start, type: Token.TOK_FILTER, value: '[?' }; | ||
} | ||
if (stream[this._current] === ']') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_FLATTEN, value: '[]' }; | ||
return { start: start, type: Token.TOK_FLATTEN, value: '[]' }; | ||
} | ||
return { start, type: Token.TOK_LBRACKET, value: '[' }; | ||
} | ||
consumeOperator(stream) { | ||
const start = this._current; | ||
const startingChar = stream[start]; | ||
return { start: start, type: Token.TOK_LBRACKET, value: '[' }; | ||
}; | ||
StreamLexer.prototype.consumeOperator = function (stream) { | ||
var start = this._current; | ||
var startingChar = stream[start]; | ||
this._current += 1; | ||
@@ -248,5 +250,5 @@ if (startingChar === '!') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_NE, value: '!=' }; | ||
return { start: start, type: Token.TOK_NE, value: '!=' }; | ||
} | ||
return { start, type: Token.TOK_NOT, value: '!' }; | ||
return { start: start, type: Token.TOK_NOT, value: '!' }; | ||
} | ||
@@ -256,5 +258,5 @@ if (startingChar === '<') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_LTE, value: '<=' }; | ||
return { start: start, type: Token.TOK_LTE, value: '<=' }; | ||
} | ||
return { start, type: Token.TOK_LT, value: '<' }; | ||
return { start: start, type: Token.TOK_LT, value: '<' }; | ||
} | ||
@@ -264,17 +266,17 @@ if (startingChar === '>') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_GTE, value: '>=' }; | ||
return { start: start, type: Token.TOK_GTE, value: '>=' }; | ||
} | ||
return { start, type: Token.TOK_GT, value: '>' }; | ||
return { start: start, type: Token.TOK_GT, value: '>' }; | ||
} | ||
if (startingChar === '=' && stream[this._current] === '=') { | ||
this._current += 1; | ||
return { start, type: Token.TOK_EQ, value: '==' }; | ||
return { start: start, type: Token.TOK_EQ, value: '==' }; | ||
} | ||
} | ||
consumeLiteral(stream) { | ||
}; | ||
StreamLexer.prototype.consumeLiteral = function (stream) { | ||
this._current += 1; | ||
const start = this._current; | ||
const maxLength = stream.length; | ||
var start = this._current; | ||
var maxLength = stream.length; | ||
while (stream[this._current] !== '`' && this._current < maxLength) { | ||
let current = this._current; | ||
var current = this._current; | ||
if (stream[current] === '\\' && (stream[current + 1] === '\\' || stream[current + 1] === '`')) { | ||
@@ -288,14 +290,14 @@ current += 2; | ||
} | ||
let literalString = utils_1.trimLeft(stream.slice(start, this._current)); | ||
var literalString = stream.slice(start, this._current).trimLeft(); | ||
literalString = literalString.replace('\\`', '`'); | ||
const literal = this.looksLikeJSON(literalString) | ||
var literal = this.looksLikeJSON(literalString) | ||
? JSON.parse(literalString) | ||
: JSON.parse(`"${literalString}"`); | ||
: JSON.parse("\"" + literalString + "\""); | ||
this._current += 1; | ||
return literal; | ||
} | ||
looksLikeJSON(literalString) { | ||
const startingChars = '[{"'; | ||
const jsonLiterals = ['true', 'false', 'null']; | ||
const numberLooking = '-0123456789'; | ||
}; | ||
StreamLexer.prototype.looksLikeJSON = function (literalString) { | ||
var startingChars = '[{"'; | ||
var jsonLiterals = ['true', 'false', 'null']; | ||
var numberLooking = '-0123456789'; | ||
if (literalString === '') { | ||
@@ -320,6 +322,7 @@ return false; | ||
return false; | ||
} | ||
} | ||
}; | ||
return StreamLexer; | ||
}()); | ||
exports.Lexer = new StreamLexer(); | ||
exports.default = exports.Lexer; | ||
//# sourceMappingURL=Lexer.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Parser = void 0; | ||
const Lexer_1 = require("./Lexer"); | ||
const Lexer_2 = require("./Lexer"); | ||
const bindingPower = { | ||
[Lexer_1.Token.TOK_EOF]: 0, | ||
[Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER]: 0, | ||
[Lexer_1.Token.TOK_QUOTEDIDENTIFIER]: 0, | ||
[Lexer_1.Token.TOK_RBRACKET]: 0, | ||
[Lexer_1.Token.TOK_RPAREN]: 0, | ||
[Lexer_1.Token.TOK_COMMA]: 0, | ||
[Lexer_1.Token.TOK_RBRACE]: 0, | ||
[Lexer_1.Token.TOK_NUMBER]: 0, | ||
[Lexer_1.Token.TOK_CURRENT]: 0, | ||
[Lexer_1.Token.TOK_EXPREF]: 0, | ||
[Lexer_1.Token.TOK_ROOT]: 0, | ||
[Lexer_1.Token.TOK_PIPE]: 1, | ||
[Lexer_1.Token.TOK_OR]: 2, | ||
[Lexer_1.Token.TOK_AND]: 3, | ||
[Lexer_1.Token.TOK_EQ]: 5, | ||
[Lexer_1.Token.TOK_GT]: 5, | ||
[Lexer_1.Token.TOK_LT]: 5, | ||
[Lexer_1.Token.TOK_GTE]: 5, | ||
[Lexer_1.Token.TOK_LTE]: 5, | ||
[Lexer_1.Token.TOK_NE]: 5, | ||
[Lexer_1.Token.TOK_FLATTEN]: 9, | ||
[Lexer_1.Token.TOK_STAR]: 20, | ||
[Lexer_1.Token.TOK_FILTER]: 21, | ||
[Lexer_1.Token.TOK_DOT]: 40, | ||
[Lexer_1.Token.TOK_NOT]: 45, | ||
[Lexer_1.Token.TOK_LBRACE]: 50, | ||
[Lexer_1.Token.TOK_LBRACKET]: 55, | ||
[Lexer_1.Token.TOK_LPAREN]: 60, | ||
}; | ||
class TokenParser { | ||
constructor() { | ||
var Lexer_1 = __importStar(require("./Lexer")); | ||
var bindingPower = (_a = {}, | ||
_a[Lexer_1.Token.TOK_EOF] = 0, | ||
_a[Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER] = 0, | ||
_a[Lexer_1.Token.TOK_QUOTEDIDENTIFIER] = 0, | ||
_a[Lexer_1.Token.TOK_RBRACKET] = 0, | ||
_a[Lexer_1.Token.TOK_RPAREN] = 0, | ||
_a[Lexer_1.Token.TOK_COMMA] = 0, | ||
_a[Lexer_1.Token.TOK_RBRACE] = 0, | ||
_a[Lexer_1.Token.TOK_NUMBER] = 0, | ||
_a[Lexer_1.Token.TOK_CURRENT] = 0, | ||
_a[Lexer_1.Token.TOK_EXPREF] = 0, | ||
_a[Lexer_1.Token.TOK_ROOT] = 0, | ||
_a[Lexer_1.Token.TOK_PIPE] = 1, | ||
_a[Lexer_1.Token.TOK_OR] = 2, | ||
_a[Lexer_1.Token.TOK_AND] = 3, | ||
_a[Lexer_1.Token.TOK_EQ] = 5, | ||
_a[Lexer_1.Token.TOK_GT] = 5, | ||
_a[Lexer_1.Token.TOK_LT] = 5, | ||
_a[Lexer_1.Token.TOK_GTE] = 5, | ||
_a[Lexer_1.Token.TOK_LTE] = 5, | ||
_a[Lexer_1.Token.TOK_NE] = 5, | ||
_a[Lexer_1.Token.TOK_FLATTEN] = 9, | ||
_a[Lexer_1.Token.TOK_STAR] = 20, | ||
_a[Lexer_1.Token.TOK_FILTER] = 21, | ||
_a[Lexer_1.Token.TOK_DOT] = 40, | ||
_a[Lexer_1.Token.TOK_NOT] = 45, | ||
_a[Lexer_1.Token.TOK_LBRACE] = 50, | ||
_a[Lexer_1.Token.TOK_LBRACKET] = 55, | ||
_a[Lexer_1.Token.TOK_LPAREN] = 60, | ||
_a); | ||
var TokenParser = /** @class */ (function () { | ||
function TokenParser() { | ||
this.index = 0; | ||
this.tokens = []; | ||
} | ||
parse(expression) { | ||
TokenParser.prototype.parse = function (expression) { | ||
this.loadTokens(expression); | ||
this.index = 0; | ||
const ast = this.expression(0); | ||
var ast = this.expression(0); | ||
if (this.lookahead(0) !== Lexer_1.Token.TOK_EOF) { | ||
const token = this.lookaheadToken(0); | ||
this.errorToken(token, `Unexpected token type: ${token.type}, value: ${token.value}`); | ||
var token = this.lookaheadToken(0); | ||
this.errorToken(token, "Unexpected token type: " + token.type + ", value: " + token.value); | ||
} | ||
return ast; | ||
} | ||
loadTokens(expression) { | ||
this.tokens = [...Lexer_2.default.tokenize(expression), { type: Lexer_1.Token.TOK_EOF, value: '', start: expression.length }]; | ||
} | ||
expression(rbp) { | ||
const leftToken = this.lookaheadToken(0); | ||
}; | ||
TokenParser.prototype.loadTokens = function (expression) { | ||
this.tokens = __spreadArrays(Lexer_1.default.tokenize(expression), [{ type: Lexer_1.Token.TOK_EOF, value: '', start: expression.length }]); | ||
}; | ||
TokenParser.prototype.expression = function (rbp) { | ||
var leftToken = this.lookaheadToken(0); | ||
this.advance(); | ||
let left = this.nud(leftToken); | ||
let currentTokenType = this.lookahead(0); | ||
var left = this.nud(leftToken); | ||
var currentTokenType = this.lookahead(0); | ||
while (rbp < bindingPower[currentTokenType]) { | ||
@@ -65,16 +91,16 @@ this.advance(); | ||
return left; | ||
} | ||
lookahead(offset) { | ||
}; | ||
TokenParser.prototype.lookahead = function (offset) { | ||
return this.tokens[this.index + offset].type; | ||
} | ||
lookaheadToken(offset) { | ||
}; | ||
TokenParser.prototype.lookaheadToken = function (offset) { | ||
return this.tokens[this.index + offset]; | ||
} | ||
advance() { | ||
}; | ||
TokenParser.prototype.advance = function () { | ||
this.index += 1; | ||
} | ||
nud(token) { | ||
let left; | ||
let right; | ||
let expression; | ||
}; | ||
TokenParser.prototype.nud = function (token) { | ||
var left; | ||
var right; | ||
var expression; | ||
switch (token.type) { | ||
@@ -86,3 +112,3 @@ case Lexer_1.Token.TOK_LITERAL: | ||
case Lexer_1.Token.TOK_QUOTEDIDENTIFIER: | ||
const node = { type: 'Field', name: token.value }; | ||
var node = { type: 'Field', name: token.value }; | ||
if (this.lookahead(0) === Lexer_1.Token.TOK_LPAREN) { | ||
@@ -134,3 +160,3 @@ throw new Error('Quoted identifier not allowed for function names.'); | ||
case Lexer_1.Token.TOK_LPAREN: | ||
const args = []; | ||
var args = []; | ||
while (this.lookahead(0) !== Lexer_1.Token.TOK_RPAREN) { | ||
@@ -151,8 +177,8 @@ if (this.lookahead(0) === Lexer_1.Token.TOK_CURRENT) { | ||
} | ||
} | ||
led(tokenName, left) { | ||
let right; | ||
}; | ||
TokenParser.prototype.led = function (tokenName, left) { | ||
var right; | ||
switch (tokenName) { | ||
case Lexer_1.Token.TOK_DOT: | ||
const rbp = bindingPower.Dot; | ||
var rbp = bindingPower.Dot; | ||
if (this.lookahead(0) !== Lexer_1.Token.TOK_STAR) { | ||
@@ -175,5 +201,5 @@ right = this.parseDotRHS(rbp); | ||
case Lexer_1.Token.TOK_LPAREN: | ||
const name = left.name; | ||
const args = []; | ||
let expression; | ||
var name_1 = left.name; | ||
var args = []; | ||
var expression = void 0; | ||
while (this.lookahead(0) !== Lexer_1.Token.TOK_RPAREN) { | ||
@@ -193,6 +219,6 @@ if (this.lookahead(0) === Lexer_1.Token.TOK_CURRENT) { | ||
this.match(Lexer_1.Token.TOK_RPAREN); | ||
const node = { name, type: 'Function', children: args }; | ||
var node = { name: name_1, type: 'Function', children: args }; | ||
return node; | ||
case Lexer_1.Token.TOK_FILTER: | ||
const condition = this.expression(0); | ||
var condition = this.expression(0); | ||
this.match(Lexer_1.Token.TOK_RBRACKET); | ||
@@ -204,4 +230,4 @@ right = | ||
case Lexer_1.Token.TOK_FLATTEN: | ||
const leftNode = { type: Lexer_1.Token.TOK_FLATTEN, children: [left] }; | ||
const rightNode = this.parseProjectionRHS(bindingPower.Flatten); | ||
var leftNode = { type: Lexer_1.Token.TOK_FLATTEN, children: [left] }; | ||
var rightNode = this.parseProjectionRHS(bindingPower.Flatten); | ||
return { type: 'Projection', children: [leftNode, rightNode] }; | ||
@@ -216,3 +242,3 @@ case Lexer_1.Token.TOK_EQ: | ||
case Lexer_1.Token.TOK_LBRACKET: | ||
const token = this.lookaheadToken(0); | ||
var token = this.lookaheadToken(0); | ||
if (token.type === Lexer_1.Token.TOK_NUMBER || token.type === Lexer_1.Token.TOK_COLON) { | ||
@@ -229,4 +255,4 @@ right = this.parseIndexExpression(); | ||
} | ||
} | ||
match(tokenType) { | ||
}; | ||
TokenParser.prototype.match = function (tokenType) { | ||
if (this.lookahead(0) === tokenType) { | ||
@@ -237,16 +263,17 @@ this.advance(); | ||
else { | ||
const token = this.lookaheadToken(0); | ||
this.errorToken(token, `Expected ${tokenType}, got: ${token.type}`); | ||
var token = this.lookaheadToken(0); | ||
this.errorToken(token, "Expected " + tokenType + ", got: " + token.type); | ||
} | ||
} | ||
errorToken(token, message = '') { | ||
const error = new Error(message || `Invalid token (${token.type}): "${token.value}"`); | ||
}; | ||
TokenParser.prototype.errorToken = function (token, message) { | ||
if (message === void 0) { message = ''; } | ||
var error = new Error(message || "Invalid token (" + token.type + "): \"" + token.value + "\""); | ||
error.name = 'ParserError'; | ||
throw error; | ||
} | ||
parseIndexExpression() { | ||
}; | ||
TokenParser.prototype.parseIndexExpression = function () { | ||
if (this.lookahead(0) === Lexer_1.Token.TOK_COLON || this.lookahead(1) === Lexer_1.Token.TOK_COLON) { | ||
return this.parseSliceExpression(); | ||
} | ||
const node = { | ||
var node = { | ||
type: 'Index', | ||
@@ -258,5 +285,5 @@ value: this.lookaheadToken(0).value, | ||
return node; | ||
} | ||
projectIfSlice(left, right) { | ||
const indexExpr = { type: 'IndexExpression', children: [left, right] }; | ||
}; | ||
TokenParser.prototype.projectIfSlice = function (left, right) { | ||
var indexExpr = { type: 'IndexExpression', children: [left, right] }; | ||
if (right.type === 'Slice') { | ||
@@ -269,7 +296,7 @@ return { | ||
return indexExpr; | ||
} | ||
parseSliceExpression() { | ||
const parts = [null, null, null]; | ||
let index = 0; | ||
let currentTokenType = this.lookahead(0); | ||
}; | ||
TokenParser.prototype.parseSliceExpression = function () { | ||
var parts = [null, null, null]; | ||
var index = 0; | ||
var currentTokenType = this.lookahead(0); | ||
while (currentTokenType !== Lexer_1.Token.TOK_RBRACKET && index < 3) { | ||
@@ -285,4 +312,4 @@ if (currentTokenType === Lexer_1.Token.TOK_COLON) { | ||
else { | ||
const token = this.lookaheadToken(0); | ||
this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`); | ||
var token = this.lookaheadToken(0); | ||
this.errorToken(token, "Syntax error, unexpected token: " + token.value + "(" + token.type + ")"); | ||
} | ||
@@ -296,10 +323,10 @@ currentTokenType = this.lookahead(0); | ||
}; | ||
} | ||
parseComparator(left, comparator) { | ||
const right = this.expression(bindingPower[comparator]); | ||
}; | ||
TokenParser.prototype.parseComparator = function (left, comparator) { | ||
var right = this.expression(bindingPower[comparator]); | ||
return { type: 'Comparator', name: comparator, children: [left, right] }; | ||
} | ||
parseDotRHS(rbp) { | ||
const lookahead = this.lookahead(0); | ||
const exprTokens = [Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER, Lexer_1.Token.TOK_QUOTEDIDENTIFIER, Lexer_1.Token.TOK_STAR]; | ||
}; | ||
TokenParser.prototype.parseDotRHS = function (rbp) { | ||
var lookahead = this.lookahead(0); | ||
var exprTokens = [Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER, Lexer_1.Token.TOK_QUOTEDIDENTIFIER, Lexer_1.Token.TOK_STAR]; | ||
if (exprTokens.includes(lookahead)) { | ||
@@ -316,6 +343,6 @@ return this.expression(rbp); | ||
} | ||
const token = this.lookaheadToken(0); | ||
this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`); | ||
} | ||
parseProjectionRHS(rbp) { | ||
var token = this.lookaheadToken(0); | ||
this.errorToken(token, "Syntax error, unexpected token: " + token.value + "(" + token.type + ")"); | ||
}; | ||
TokenParser.prototype.parseProjectionRHS = function (rbp) { | ||
if (bindingPower[this.lookahead(0)] < 10) { | ||
@@ -334,9 +361,9 @@ return { type: 'Identity' }; | ||
} | ||
const token = this.lookaheadToken(0); | ||
this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`); | ||
} | ||
parseMultiselectList() { | ||
const expressions = []; | ||
var token = this.lookaheadToken(0); | ||
this.errorToken(token, "Syntax error, unexpected token: " + token.value + "(" + token.type + ")"); | ||
}; | ||
TokenParser.prototype.parseMultiselectList = function () { | ||
var expressions = []; | ||
while (this.lookahead(0) !== Lexer_1.Token.TOK_RBRACKET) { | ||
const expression = this.expression(0); | ||
var expression = this.expression(0); | ||
expressions.push(expression); | ||
@@ -352,10 +379,9 @@ if (this.lookahead(0) === Lexer_1.Token.TOK_COMMA) { | ||
return { type: 'MultiSelectList', children: expressions }; | ||
} | ||
parseMultiselectHash() { | ||
const pairs = []; | ||
const identifierTypes = [Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER, Lexer_1.Token.TOK_QUOTEDIDENTIFIER]; | ||
let keyToken; | ||
let keyName; | ||
let value; | ||
let node; | ||
}; | ||
TokenParser.prototype.parseMultiselectHash = function () { | ||
var pairs = []; | ||
var identifierTypes = [Lexer_1.Token.TOK_UNQUOTEDIDENTIFIER, Lexer_1.Token.TOK_QUOTEDIDENTIFIER]; | ||
var keyToken; | ||
var keyName; | ||
var value; | ||
// tslint:disable-next-line: prettier | ||
@@ -365,3 +391,3 @@ for (;;) { | ||
if (!identifierTypes.includes(keyToken.type)) { | ||
throw new Error(`Expecting an identifier token, got: ${keyToken.type}`); | ||
throw new Error("Expecting an identifier token, got: " + keyToken.type); | ||
} | ||
@@ -372,4 +398,3 @@ keyName = keyToken.value; | ||
value = this.expression(0); | ||
node = { value, type: 'KeyValuePair', name: keyName }; | ||
pairs.push(node); | ||
pairs.push({ value: value, type: 'KeyValuePair', name: keyName }); | ||
if (this.lookahead(0) === Lexer_1.Token.TOK_COMMA) { | ||
@@ -384,6 +409,7 @@ this.match(Lexer_1.Token.TOK_COMMA); | ||
return { type: 'MultiSelectHash', children: pairs }; | ||
} | ||
} | ||
}; | ||
return TokenParser; | ||
}()); | ||
exports.Parser = new TokenParser(); | ||
exports.default = exports.Parser; | ||
//# sourceMappingURL=Parser.js.map |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Runtime = exports.InputArgument = void 0; | ||
const Lexer_1 = require("./Lexer"); | ||
const utils_1 = require("./utils"); | ||
var Lexer_1 = require("./Lexer"); | ||
var utils_1 = require("./utils"); | ||
var InputArgument; | ||
@@ -19,22 +26,26 @@ (function (InputArgument) { | ||
})(InputArgument = exports.InputArgument || (exports.InputArgument = {})); | ||
class Runtime { | ||
constructor(interpreter) { | ||
this.TYPE_NAME_TABLE = { | ||
[InputArgument.TYPE_NUMBER]: 'number', | ||
[InputArgument.TYPE_ANY]: 'any', | ||
[InputArgument.TYPE_STRING]: 'string', | ||
[InputArgument.TYPE_ARRAY]: 'array', | ||
[InputArgument.TYPE_OBJECT]: 'object', | ||
[InputArgument.TYPE_BOOLEAN]: 'boolean', | ||
[InputArgument.TYPE_EXPREF]: 'expression', | ||
[InputArgument.TYPE_NULL]: 'null', | ||
[InputArgument.TYPE_ARRAY_NUMBER]: 'Array<number>', | ||
[InputArgument.TYPE_ARRAY_STRING]: 'Array<string>', | ||
}; | ||
this.functionAbs = ([inputValue]) => { | ||
var Runtime = /** @class */ (function () { | ||
function Runtime(interpreter) { | ||
var _a; | ||
var _this = this; | ||
this.TYPE_NAME_TABLE = (_a = {}, | ||
_a[InputArgument.TYPE_NUMBER] = 'number', | ||
_a[InputArgument.TYPE_ANY] = 'any', | ||
_a[InputArgument.TYPE_STRING] = 'string', | ||
_a[InputArgument.TYPE_ARRAY] = 'array', | ||
_a[InputArgument.TYPE_OBJECT] = 'object', | ||
_a[InputArgument.TYPE_BOOLEAN] = 'boolean', | ||
_a[InputArgument.TYPE_EXPREF] = 'expression', | ||
_a[InputArgument.TYPE_NULL] = 'null', | ||
_a[InputArgument.TYPE_ARRAY_NUMBER] = 'Array<number>', | ||
_a[InputArgument.TYPE_ARRAY_STRING] = 'Array<string>', | ||
_a); | ||
this.functionAbs = function (_a) { | ||
var inputValue = _a[0]; | ||
return Math.abs(inputValue); | ||
}; | ||
this.functionAvg = ([inputArray]) => { | ||
let sum = 0; | ||
for (let i = 0; i < inputArray.length; i += 1) { | ||
this.functionAvg = function (_a) { | ||
var inputArray = _a[0]; | ||
var sum = 0; | ||
for (var i = 0; i < inputArray.length; i += 1) { | ||
sum += inputArray[i]; | ||
@@ -44,24 +55,28 @@ } | ||
}; | ||
this.functionCeil = ([inputValue]) => { | ||
this.functionCeil = function (_a) { | ||
var inputValue = _a[0]; | ||
return Math.ceil(inputValue); | ||
}; | ||
this.functionContains = resolvedArgs => { | ||
const [searchable, searchValue] = resolvedArgs; | ||
this.functionContains = function (resolvedArgs) { | ||
var searchable = resolvedArgs[0], searchValue = resolvedArgs[1]; | ||
return searchable.includes(searchValue); | ||
}; | ||
this.functionEndsWith = resolvedArgs => { | ||
const [searchStr, suffix] = resolvedArgs; | ||
this.functionEndsWith = function (resolvedArgs) { | ||
var searchStr = resolvedArgs[0], suffix = resolvedArgs[1]; | ||
return searchStr.includes(suffix, searchStr.length - suffix.length); | ||
}; | ||
this.functionFloor = ([inputValue]) => { | ||
this.functionFloor = function (_a) { | ||
var inputValue = _a[0]; | ||
return Math.floor(inputValue); | ||
}; | ||
this.functionJoin = resolvedArgs => { | ||
const [joinChar, listJoin] = resolvedArgs; | ||
this.functionJoin = function (resolvedArgs) { | ||
var joinChar = resolvedArgs[0], listJoin = resolvedArgs[1]; | ||
return listJoin.join(joinChar); | ||
}; | ||
this.functionKeys = ([inputObject]) => { | ||
this.functionKeys = function (_a) { | ||
var inputObject = _a[0]; | ||
return Object.keys(inputObject); | ||
}; | ||
this.functionLength = ([inputValue]) => { | ||
this.functionLength = function (_a) { | ||
var inputValue = _a[0]; | ||
if (!utils_1.isObject(inputValue)) { | ||
@@ -72,10 +87,11 @@ return inputValue.length; | ||
}; | ||
this.functionMap = (resolvedArgs) => { | ||
if (!this._interpreter) | ||
this.functionMap = function (resolvedArgs) { | ||
if (!_this._interpreter) { | ||
return []; | ||
const mapped = []; | ||
const interpreter = this._interpreter; | ||
const exprefNode = resolvedArgs[0]; | ||
const elements = resolvedArgs[1]; | ||
for (let i = 0; i < elements.length; i += 1) { | ||
} | ||
var mapped = []; | ||
var interpreter = _this._interpreter; | ||
var exprefNode = resolvedArgs[0]; | ||
var elements = resolvedArgs[1]; | ||
for (var i = 0; i < elements.length; i += 1) { | ||
mapped.push(interpreter.visit(exprefNode, elements[i])); | ||
@@ -85,12 +101,14 @@ } | ||
}; | ||
this.functionMax = ([inputValue]) => { | ||
if (!inputValue.length) | ||
this.functionMax = function (_a) { | ||
var inputValue = _a[0]; | ||
if (!inputValue.length) { | ||
return null; | ||
const typeName = this.getTypeName(inputValue[0]); | ||
} | ||
var typeName = _this.getTypeName(inputValue[0]); | ||
if (typeName === InputArgument.TYPE_NUMBER) { | ||
return Math.max(...inputValue); | ||
return Math.max.apply(Math, inputValue); | ||
} | ||
const elements = inputValue; | ||
let maxElement = elements[0]; | ||
for (let i = 1; i < elements.length; i += 1) { | ||
var elements = inputValue; | ||
var maxElement = elements[0]; | ||
for (var i = 1; i < elements.length; i += 1) { | ||
if (maxElement.localeCompare(elements[i]) < 0) { | ||
@@ -102,10 +120,10 @@ maxElement = elements[i]; | ||
}; | ||
this.functionMaxBy = (resolvedArgs) => { | ||
const exprefNode = resolvedArgs[1]; | ||
const resolvedArray = resolvedArgs[0]; | ||
const keyFunction = this.createKeyFunction(exprefNode, [InputArgument.TYPE_NUMBER, InputArgument.TYPE_STRING]); | ||
let maxNumber = -Infinity; | ||
let maxRecord; | ||
let current; | ||
for (let i = 0; i < resolvedArray.length; i += 1) { | ||
this.functionMaxBy = function (resolvedArgs) { | ||
var exprefNode = resolvedArgs[1]; | ||
var resolvedArray = resolvedArgs[0]; | ||
var keyFunction = _this.createKeyFunction(exprefNode, [InputArgument.TYPE_NUMBER, InputArgument.TYPE_STRING]); | ||
var maxNumber = -Infinity; | ||
var maxRecord; | ||
var current; | ||
for (var i = 0; i < resolvedArray.length; i += 1) { | ||
current = keyFunction && keyFunction(resolvedArray[i]); | ||
@@ -119,6 +137,6 @@ if (current !== undefined && current > maxNumber) { | ||
}; | ||
this.functionMerge = resolvedArgs => { | ||
let merged = {}; | ||
for (let i = 0; i < resolvedArgs.length; i += 1) { | ||
const current = resolvedArgs[i]; | ||
this.functionMerge = function (resolvedArgs) { | ||
var merged = {}; | ||
for (var i = 0; i < resolvedArgs.length; i += 1) { | ||
var current = resolvedArgs[i]; | ||
merged = Object.assign(merged, current); | ||
@@ -131,12 +149,14 @@ // for (const key in current) { | ||
}; | ||
this.functionMin = ([inputValue]) => { | ||
if (!inputValue.length) | ||
this.functionMin = function (_a) { | ||
var inputValue = _a[0]; | ||
if (!inputValue.length) { | ||
return null; | ||
const typeName = this.getTypeName(inputValue[0]); | ||
} | ||
var typeName = _this.getTypeName(inputValue[0]); | ||
if (typeName === InputArgument.TYPE_NUMBER) { | ||
return Math.min(...inputValue); | ||
return Math.min.apply(Math, inputValue); | ||
} | ||
const elements = inputValue; | ||
let minElement = elements[0]; | ||
for (let i = 1; i < elements.length; i += 1) { | ||
var elements = inputValue; | ||
var minElement = elements[0]; | ||
for (var i = 1; i < elements.length; i += 1) { | ||
if (elements[i].localeCompare(minElement) < 0) { | ||
@@ -148,10 +168,10 @@ minElement = elements[i]; | ||
}; | ||
this.functionMinBy = (resolvedArgs) => { | ||
const exprefNode = resolvedArgs[1]; | ||
const resolvedArray = resolvedArgs[0]; | ||
const keyFunction = this.createKeyFunction(exprefNode, [InputArgument.TYPE_NUMBER, InputArgument.TYPE_STRING]); | ||
let minNumber = Infinity; | ||
let minRecord; | ||
let current; | ||
for (let i = 0; i < resolvedArray.length; i += 1) { | ||
this.functionMinBy = function (resolvedArgs) { | ||
var exprefNode = resolvedArgs[1]; | ||
var resolvedArray = resolvedArgs[0]; | ||
var keyFunction = _this.createKeyFunction(exprefNode, [InputArgument.TYPE_NUMBER, InputArgument.TYPE_STRING]); | ||
var minNumber = Infinity; | ||
var minRecord; | ||
var current; | ||
for (var i = 0; i < resolvedArray.length; i += 1) { | ||
current = keyFunction && keyFunction(resolvedArray[i]); | ||
@@ -165,5 +185,5 @@ if (current !== undefined && current < minNumber) { | ||
}; | ||
this.functionNotNull = (resolvedArgs) => { | ||
for (let i = 0; i < resolvedArgs.length; i += 1) { | ||
if (this.getTypeName(resolvedArgs[i]) !== InputArgument.TYPE_NULL) { | ||
this.functionNotNull = function (resolvedArgs) { | ||
for (var i = 0; i < resolvedArgs.length; i += 1) { | ||
if (_this.getTypeName(resolvedArgs[i]) !== InputArgument.TYPE_NULL) { | ||
return resolvedArgs[i]; | ||
@@ -174,8 +194,9 @@ } | ||
}; | ||
this.functionReverse = ([inputValue]) => { | ||
const typeName = this.getTypeName(inputValue); | ||
this.functionReverse = function (_a) { | ||
var inputValue = _a[0]; | ||
var typeName = _this.getTypeName(inputValue); | ||
if (typeName === InputArgument.TYPE_STRING) { | ||
const originalStr = inputValue; | ||
let reversedStr = ''; | ||
for (let i = originalStr.length - 1; i >= 0; i -= 1) { | ||
var originalStr = inputValue; | ||
var reversedStr = ''; | ||
for (var i = originalStr.length - 1; i >= 0; i -= 1) { | ||
reversedStr += originalStr[i]; | ||
@@ -185,34 +206,36 @@ } | ||
} | ||
const reversedArray = inputValue.slice(0); | ||
var reversedArray = inputValue.slice(0); | ||
reversedArray.reverse(); | ||
return reversedArray; | ||
}; | ||
this.functionSort = ([inputValue]) => { | ||
return [...inputValue].sort(); | ||
this.functionSort = function (_a) { | ||
var inputValue = _a[0]; | ||
return __spreadArrays(inputValue).sort(); | ||
}; | ||
this.functionSortBy = (resolvedArgs) => { | ||
if (!this._interpreter) | ||
this.functionSortBy = function (resolvedArgs) { | ||
if (!_this._interpreter) { | ||
return []; | ||
const sortedArray = resolvedArgs[0].slice(0); | ||
} | ||
var sortedArray = resolvedArgs[0].slice(0); | ||
if (sortedArray.length === 0) { | ||
return sortedArray; | ||
} | ||
const interpreter = this._interpreter; | ||
const exprefNode = resolvedArgs[1]; | ||
const requiredType = this.getTypeName(interpreter.visit(exprefNode, sortedArray[0])); | ||
var interpreter = _this._interpreter; | ||
var exprefNode = resolvedArgs[1]; | ||
var requiredType = _this.getTypeName(interpreter.visit(exprefNode, sortedArray[0])); | ||
if (requiredType !== undefined && ![InputArgument.TYPE_NUMBER, InputArgument.TYPE_STRING].includes(requiredType)) { | ||
throw new Error(`TypeError: unexpected type (${this.TYPE_NAME_TABLE[requiredType]})`); | ||
throw new Error("TypeError: unexpected type (" + _this.TYPE_NAME_TABLE[requiredType] + ")"); | ||
} | ||
const decorated = []; | ||
for (let i = 0; i < sortedArray.length; i += 1) { | ||
var decorated = []; | ||
for (var i = 0; i < sortedArray.length; i += 1) { | ||
decorated.push([i, sortedArray[i]]); | ||
} | ||
decorated.sort((a, b) => { | ||
const exprA = interpreter.visit(exprefNode, a[1]); | ||
const exprB = interpreter.visit(exprefNode, b[1]); | ||
if (this.getTypeName(exprA) !== requiredType) { | ||
throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[requiredType]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(exprA)]}`); | ||
decorated.sort(function (a, b) { | ||
var exprA = interpreter.visit(exprefNode, a[1]); | ||
var exprB = interpreter.visit(exprefNode, b[1]); | ||
if (_this.getTypeName(exprA) !== requiredType) { | ||
throw new Error("TypeError: expected (" + _this.TYPE_NAME_TABLE[requiredType] + "), received " + _this.TYPE_NAME_TABLE[_this.getTypeName(exprA)]); | ||
} | ||
else if (this.getTypeName(exprB) !== requiredType) { | ||
throw new Error(`TypeError: expected (${this.TYPE_NAME_TABLE[requiredType]}), received ${this.TYPE_NAME_TABLE[this.getTypeName(exprB)]}`); | ||
else if (_this.getTypeName(exprB) !== requiredType) { | ||
throw new Error("TypeError: expected (" + _this.TYPE_NAME_TABLE[requiredType] + "), received " + _this.TYPE_NAME_TABLE[_this.getTypeName(exprB)]); | ||
} | ||
@@ -224,3 +247,3 @@ if (exprA > exprB) { | ||
}); | ||
for (let j = 0; j < decorated.length; j += 1) { | ||
for (var j = 0; j < decorated.length; j += 1) { | ||
sortedArray[j] = decorated[j][1]; | ||
@@ -230,10 +253,13 @@ } | ||
}; | ||
this.functionStartsWith = ([searchable, searchStr]) => { | ||
this.functionStartsWith = function (_a) { | ||
var searchable = _a[0], searchStr = _a[1]; | ||
return searchable.startsWith(searchStr); | ||
}; | ||
this.functionSum = ([inputValue]) => { | ||
return inputValue.reduce((x, y) => x + y, 0); | ||
this.functionSum = function (_a) { | ||
var inputValue = _a[0]; | ||
return inputValue.reduce(function (x, y) { return x + y; }, 0); | ||
}; | ||
this.functionToArray = ([inputValue]) => { | ||
if (this.getTypeName(inputValue) === InputArgument.TYPE_ARRAY) { | ||
this.functionToArray = function (_a) { | ||
var inputValue = _a[0]; | ||
if (_this.getTypeName(inputValue) === InputArgument.TYPE_ARRAY) { | ||
return inputValue; | ||
@@ -243,5 +269,6 @@ } | ||
}; | ||
this.functionToNumber = ([inputValue]) => { | ||
const typeName = this.getTypeName(inputValue); | ||
let convertedValue; | ||
this.functionToNumber = function (_a) { | ||
var inputValue = _a[0]; | ||
var typeName = _this.getTypeName(inputValue); | ||
var convertedValue; | ||
if (typeName === InputArgument.TYPE_NUMBER) { | ||
@@ -258,4 +285,5 @@ return inputValue; | ||
}; | ||
this.functionToString = ([inputValue]) => { | ||
if (this.getTypeName(inputValue) === InputArgument.TYPE_STRING) { | ||
this.functionToString = function (_a) { | ||
var inputValue = _a[0]; | ||
if (_this.getTypeName(inputValue) === InputArgument.TYPE_STRING) { | ||
return inputValue; | ||
@@ -265,4 +293,5 @@ } | ||
}; | ||
this.functionType = ([inputValue]) => { | ||
switch (this.getTypeName(inputValue)) { | ||
this.functionType = function (_a) { | ||
var inputValue = _a[0]; | ||
switch (_this.getTypeName(inputValue)) { | ||
case InputArgument.TYPE_NUMBER: | ||
@@ -286,3 +315,4 @@ return 'number'; | ||
}; | ||
this.functionValues = ([inputObject]) => { | ||
this.functionValues = function (_a) { | ||
var inputObject = _a[0]; | ||
return Object.values(inputObject); | ||
@@ -528,5 +558,5 @@ }; | ||
} | ||
registerFunction(name, customFunction, signature) { | ||
Runtime.prototype.registerFunction = function (name, customFunction, signature) { | ||
if (name in this.functionTable) { | ||
throw new Error(`Function already defined: ${name}()`); | ||
throw new Error("Function already defined: " + name + "()"); | ||
} | ||
@@ -537,39 +567,40 @@ this.functionTable[name] = { | ||
}; | ||
} | ||
callFunction(name, resolvedArgs) { | ||
const functionEntry = this.functionTable[name]; | ||
}; | ||
Runtime.prototype.callFunction = function (name, resolvedArgs) { | ||
var functionEntry = this.functionTable[name]; | ||
if (functionEntry === undefined) { | ||
throw new Error(`Unknown function: ${name}()`); | ||
throw new Error("Unknown function: " + name + "()"); | ||
} | ||
this.validateArgs(name, resolvedArgs, functionEntry._signature); | ||
return functionEntry._func.call(this, resolvedArgs); | ||
} | ||
validateInputSignatures(name, signature) { | ||
for (let i = 0; i < signature.length; i += 1) { | ||
}; | ||
Runtime.prototype.validateInputSignatures = function (name, signature) { | ||
for (var i = 0; i < signature.length; i += 1) { | ||
if ('variadic' in signature[i] && i !== signature.length - 1) { | ||
throw new Error(`ArgumentError: ${name}() 'variadic' argument ${i + 1} must occur last`); | ||
throw new Error("ArgumentError: " + name + "() 'variadic' argument " + (i + 1) + " must occur last"); | ||
} | ||
} | ||
} | ||
validateArgs(name, args, signature) { | ||
}; | ||
Runtime.prototype.validateArgs = function (name, args, signature) { | ||
var _this = this; | ||
var _a, _b; | ||
let pluralized; | ||
var pluralized; | ||
this.validateInputSignatures(name, signature); | ||
const numberOfRequiredArgs = signature.filter(argSignature => { var _a; return (_a = !argSignature.optional) !== null && _a !== void 0 ? _a : false; }).length; | ||
const lastArgIsVariadic = (_b = (_a = signature[signature.length - 1]) === null || _a === void 0 ? void 0 : _a.variadic) !== null && _b !== void 0 ? _b : false; | ||
const tooFewArgs = args.length < numberOfRequiredArgs; | ||
const tooManyArgs = args.length > signature.length; | ||
const tooFewModifier = tooFewArgs && ((!lastArgIsVariadic && numberOfRequiredArgs > 1) || lastArgIsVariadic) ? 'at least ' : ''; | ||
var numberOfRequiredArgs = signature.filter(function (argSignature) { var _a; return (_a = !argSignature.optional) !== null && _a !== void 0 ? _a : false; }).length; | ||
var lastArgIsVariadic = (_b = (_a = signature[signature.length - 1]) === null || _a === void 0 ? void 0 : _a.variadic) !== null && _b !== void 0 ? _b : false; | ||
var tooFewArgs = args.length < numberOfRequiredArgs; | ||
var tooManyArgs = args.length > signature.length; | ||
var tooFewModifier = tooFewArgs && ((!lastArgIsVariadic && numberOfRequiredArgs > 1) || lastArgIsVariadic) ? 'at least ' : ''; | ||
if ((lastArgIsVariadic && tooFewArgs) || (!lastArgIsVariadic && (tooFewArgs || tooManyArgs))) { | ||
pluralized = signature.length > 1; | ||
throw new Error(`ArgumentError: ${name}() takes ${tooFewModifier}${numberOfRequiredArgs} argument${(pluralized && 's') || ''} but received ${args.length}`); | ||
throw new Error("ArgumentError: " + name + "() takes " + tooFewModifier + numberOfRequiredArgs + " argument" + ((pluralized && 's') || '') + " but received " + args.length); | ||
} | ||
let currentSpec; | ||
let actualType; | ||
let typeMatched; | ||
for (let i = 0; i < signature.length; i += 1) { | ||
var currentSpec; | ||
var actualType; | ||
var typeMatched; | ||
for (var i = 0; i < signature.length; i += 1) { | ||
typeMatched = false; | ||
currentSpec = signature[i].types; | ||
actualType = this.getTypeName(args[i]); | ||
let j; | ||
var j = void 0; | ||
for (j = 0; j < currentSpec.length; j += 1) { | ||
@@ -582,12 +613,12 @@ if (actualType !== undefined && this.typeMatches(actualType, currentSpec[j], args[i])) { | ||
if (!typeMatched && actualType !== undefined) { | ||
const expected = currentSpec | ||
.map((typeIdentifier) => { | ||
return this.TYPE_NAME_TABLE[typeIdentifier]; | ||
var expected = currentSpec | ||
.map(function (typeIdentifier) { | ||
return _this.TYPE_NAME_TABLE[typeIdentifier]; | ||
}) | ||
.join(' | '); | ||
throw new Error(`TypeError: ${name}() expected argument ${i + 1} to be type (${expected}) but received type ${this.TYPE_NAME_TABLE[actualType]} instead.`); | ||
throw new Error("TypeError: " + name + "() expected argument " + (i + 1) + " to be type (" + expected + ") but received type " + this.TYPE_NAME_TABLE[actualType] + " instead."); | ||
} | ||
} | ||
} | ||
typeMatches(actual, expected, argValue) { | ||
}; | ||
Runtime.prototype.typeMatches = function (actual, expected, argValue) { | ||
if (expected === InputArgument.TYPE_ANY) { | ||
@@ -603,3 +634,3 @@ return true; | ||
if (actual === InputArgument.TYPE_ARRAY) { | ||
let subtype; | ||
var subtype = void 0; | ||
if (expected === InputArgument.TYPE_ARRAY_NUMBER) { | ||
@@ -611,4 +642,4 @@ subtype = InputArgument.TYPE_NUMBER; | ||
} | ||
for (let i = 0; i < argValue.length; i += 1) { | ||
const typeName = this.getTypeName(argValue[i]); | ||
for (var i = 0; i < argValue.length; i += 1) { | ||
var typeName = this.getTypeName(argValue[i]); | ||
if (typeName !== undefined && subtype !== undefined && !this.typeMatches(typeName, subtype, argValue[i])) { | ||
@@ -625,4 +656,4 @@ return false; | ||
return false; | ||
} | ||
getTypeName(obj) { | ||
}; | ||
Runtime.prototype.getTypeName = function (obj) { | ||
switch (Object.prototype.toString.call(obj)) { | ||
@@ -647,13 +678,15 @@ case '[object String]': | ||
} | ||
} | ||
createKeyFunction(exprefNode, allowedTypes) { | ||
if (!this._interpreter) | ||
}; | ||
Runtime.prototype.createKeyFunction = function (exprefNode, allowedTypes) { | ||
var _this = this; | ||
if (!this._interpreter) { | ||
return; | ||
const interpreter = this._interpreter; | ||
const keyFunc = (x) => { | ||
const current = interpreter.visit(exprefNode, x); | ||
if (!allowedTypes.includes(this.getTypeName(current))) { | ||
const msg = `TypeError: expected one of (${allowedTypes | ||
.map(t => this.TYPE_NAME_TABLE[t]) | ||
.join(' | ')}), received ${this.TYPE_NAME_TABLE[this.getTypeName(current)]}`; | ||
} | ||
var interpreter = this._interpreter; | ||
var keyFunc = function (x) { | ||
var current = interpreter.visit(exprefNode, x); | ||
if (!allowedTypes.includes(_this.getTypeName(current))) { | ||
var msg = "TypeError: expected one of (" + allowedTypes | ||
.map(function (t) { return _this.TYPE_NAME_TABLE[t]; }) | ||
.join(' | ') + "), received " + _this.TYPE_NAME_TABLE[_this.getTypeName(current)]; | ||
throw new Error(msg); | ||
@@ -664,5 +697,6 @@ } | ||
return keyFunc; | ||
} | ||
} | ||
}; | ||
return Runtime; | ||
}()); | ||
exports.Runtime = Runtime; | ||
//# sourceMappingURL=Runtime.js.map |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TreeInterpreterInstance = exports.TreeInterpreter = void 0; | ||
const Lexer_1 = require("./Lexer"); | ||
const utils_1 = require("./utils"); | ||
const Runtime_1 = require("./Runtime"); | ||
class TreeInterpreter { | ||
constructor() { | ||
var utils_1 = require("./utils"); | ||
var Lexer_1 = require("./Lexer"); | ||
var Runtime_1 = require("./Runtime"); | ||
var TreeInterpreter = /** @class */ (function () { | ||
function TreeInterpreter() { | ||
this._rootValue = null; | ||
this.runtime = new Runtime_1.Runtime(this); | ||
} | ||
search(node, value) { | ||
TreeInterpreter.prototype.search = function (node, value) { | ||
this._rootValue = value; | ||
return this.visit(node, value); | ||
} | ||
visit(node, value) { | ||
let matched; | ||
let current; | ||
let result; | ||
let first; | ||
let second; | ||
let field; | ||
let left; | ||
let right; | ||
let collected; | ||
let i; | ||
let base; | ||
}; | ||
TreeInterpreter.prototype.visit = function (node, value) { | ||
var matched; | ||
var current; | ||
var result; | ||
var first; | ||
var second; | ||
var field; | ||
var left; | ||
var right; | ||
var collected; | ||
var i; | ||
var base; | ||
switch (node.type) { | ||
@@ -58,3 +65,3 @@ case 'Field': | ||
} | ||
let index = node.value; | ||
var index = node.value; | ||
if (index < 0) { | ||
@@ -72,8 +79,8 @@ index = value.length + index; | ||
} | ||
const sliceParams = [...node.children]; | ||
const computed = this.computeSliceParams(value.length, sliceParams); | ||
const [start, stop, step] = computed; | ||
var sliceParams = __spreadArrays(node.children); | ||
var computed = this.computeSliceParams(value.length, sliceParams); | ||
var start = computed[0], stop_1 = computed[1], step = computed[2]; | ||
result = []; | ||
if (step > 0) { | ||
for (i = start; i < stop; i += step) { | ||
for (i = start; i < stop_1; i += step) { | ||
result.push(value[i]); | ||
@@ -83,3 +90,3 @@ } | ||
else { | ||
for (i = start; i > stop; i += step) { | ||
for (i = start; i > stop_1; i += step) { | ||
result.push(value[i]); | ||
@@ -108,3 +115,3 @@ } | ||
collected = []; | ||
const values = Object.values(base); | ||
var values = Object.values(base); | ||
for (i = 0; i < values.length; i += 1) { | ||
@@ -122,4 +129,4 @@ current = this.visit(node.children[1], values[i]); | ||
} | ||
const filtered = []; | ||
const finalResults = []; | ||
var filtered = []; | ||
var finalResults = []; | ||
for (i = 0; i < base.length; i += 1) { | ||
@@ -131,3 +138,3 @@ matched = this.visit(node.children[2], base[i]); | ||
} | ||
for (let j = 0; j < filtered.length; j += 1) { | ||
for (var j = 0; j < filtered.length; j += 1) { | ||
current = this.visit(node.children[1], filtered[j]); | ||
@@ -162,15 +169,15 @@ if (current !== null) { | ||
default: | ||
throw new Error(`Unknown comparator: ${node.name}`); | ||
throw new Error("Unknown comparator: " + node.name); | ||
} | ||
return result; | ||
case Lexer_1.Token.TOK_FLATTEN: | ||
const original = this.visit(node.children[0], value); | ||
var original = this.visit(node.children[0], value); | ||
if (!Array.isArray(original)) { | ||
return null; | ||
} | ||
let merged = []; | ||
var merged = []; | ||
for (i = 0; i < original.length; i += 1) { | ||
current = original[i]; | ||
if (Array.isArray(current)) { | ||
merged = [...merged, ...current]; | ||
merged = __spreadArrays(merged, current); | ||
} | ||
@@ -198,3 +205,3 @@ else { | ||
collected = {}; | ||
let child; | ||
var child = void 0; | ||
for (i = 0; i < node.children.length; i += 1) { | ||
@@ -230,4 +237,4 @@ child = node.children[i]; | ||
case 'Function': | ||
const resolvedArgs = []; | ||
for (let j = 0; j < node.children.length; j += 1) { | ||
var resolvedArgs = []; | ||
for (var j = 0; j < node.children.length; j += 1) { | ||
resolvedArgs.push(this.visit(node.children[j], value)); | ||
@@ -237,11 +244,11 @@ } | ||
case 'ExpressionReference': | ||
const refNode = node.children[0]; | ||
var refNode = node.children[0]; | ||
refNode.jmespathType = Lexer_1.Token.TOK_EXPREF; | ||
return refNode; | ||
default: | ||
throw new Error(`Unknown node type: ${node.type}`); | ||
throw new Error("Unknown node type: " + node.type); | ||
} | ||
} | ||
computeSliceParams(arrayLength, sliceParams) { | ||
let [start, stop, step] = sliceParams; | ||
}; | ||
TreeInterpreter.prototype.computeSliceParams = function (arrayLength, sliceParams) { | ||
var start = sliceParams[0], stop = sliceParams[1], step = sliceParams[2]; | ||
if (step === null) { | ||
@@ -251,13 +258,13 @@ step = 1; | ||
else if (step === 0) { | ||
const error = new Error('Invalid slice, step cannot be 0'); | ||
var error = new Error('Invalid slice, step cannot be 0'); | ||
error.name = 'RuntimeError'; | ||
throw error; | ||
} | ||
const stepValueNegative = step < 0 ? true : false; | ||
var stepValueNegative = step < 0 ? true : false; | ||
start = start === null ? (stepValueNegative ? arrayLength - 1 : 0) : this.capSliceRange(arrayLength, start, step); | ||
stop = stop === null ? (stepValueNegative ? -1 : arrayLength) : this.capSliceRange(arrayLength, stop, step); | ||
return [start, stop, step]; | ||
} | ||
capSliceRange(arrayLength, actualValue, step) { | ||
let nextActualValue = actualValue; | ||
}; | ||
TreeInterpreter.prototype.capSliceRange = function (arrayLength, actualValue, step) { | ||
var nextActualValue = actualValue; | ||
if (nextActualValue < 0) { | ||
@@ -273,4 +280,5 @@ nextActualValue += arrayLength; | ||
return nextActualValue; | ||
} | ||
} | ||
}; | ||
return TreeInterpreter; | ||
}()); | ||
exports.TreeInterpreter = TreeInterpreter; | ||
@@ -277,0 +285,0 @@ exports.TreeInterpreterInstance = new TreeInterpreter(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAlphaNum = exports.isNum = exports.isAlpha = exports.trimLeft = exports.isFalse = exports.strictDeepEqual = exports.isObject = void 0; | ||
exports.isObject = (obj) => { | ||
exports.isAlphaNum = exports.isNum = exports.isAlpha = exports.isFalse = exports.strictDeepEqual = exports.isObject = void 0; | ||
var isObject = function (obj) { | ||
return obj !== null && Object.prototype.toString.call(obj) === '[object Object]'; | ||
}; | ||
exports.strictDeepEqual = (first, second) => { | ||
exports.isObject = isObject; | ||
var strictDeepEqual = function (first, second) { | ||
if (first === second) { | ||
@@ -18,3 +19,3 @@ return true; | ||
} | ||
for (let i = 0; i < first.length; i += 1) { | ||
for (var i = 0; i < first.length; i += 1) { | ||
if (!exports.strictDeepEqual(first[i], second[i])) { | ||
@@ -27,8 +28,9 @@ return false; | ||
if (exports.isObject(first) && exports.isObject(second)) { | ||
const firstEntries = Object.entries(first); | ||
const secondKeys = new Set(Object.keys(second)); | ||
var firstEntries = Object.entries(first); | ||
var secondKeys = new Set(Object.keys(second)); | ||
if (firstEntries.length !== secondKeys.size) { | ||
return false; | ||
} | ||
for (const [key, value] of firstEntries) { | ||
for (var _i = 0, firstEntries_1 = firstEntries; _i < firstEntries_1.length; _i++) { | ||
var _a = firstEntries_1[_i], key = _a[0], value = _a[1]; | ||
if (!exports.strictDeepEqual(value, second[key])) { | ||
@@ -43,3 +45,4 @@ return false; | ||
}; | ||
exports.isFalse = (obj) => { | ||
exports.strictDeepEqual = strictDeepEqual; | ||
var isFalse = function (obj) { | ||
if (obj === '' || obj === false || obj === null || obj === undefined) { | ||
@@ -52,3 +55,3 @@ return true; | ||
if (exports.isObject(obj)) { | ||
for (const key in obj) { | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
@@ -62,22 +65,18 @@ return false; | ||
}; | ||
exports.trimLeft = typeof String.prototype.trimLeft === 'function' | ||
? (str) => { | ||
return str.trimLeft(); | ||
} | ||
: (str) => { | ||
const match = /^\s*(.*)/.exec(str); | ||
return (match && match[1]); | ||
}; | ||
exports.isAlpha = (ch) => { | ||
exports.isFalse = isFalse; | ||
var isAlpha = function (ch) { | ||
// tslint:disable-next-line: strict-comparisons | ||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch === '_'; | ||
}; | ||
exports.isNum = (ch) => { | ||
exports.isAlpha = isAlpha; | ||
var isNum = function (ch) { | ||
// tslint:disable-next-line: strict-comparisons | ||
return (ch >= '0' && ch <= '9') || ch === '-'; | ||
}; | ||
exports.isAlphaNum = (ch) => { | ||
exports.isNum = isNum; | ||
var isAlphaNum = function (ch) { | ||
// tslint:disable-next-line: strict-comparisons | ||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch === '_'; | ||
}; | ||
exports.isAlphaNum = isAlphaNum; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { JSONValue } from '.'; | ||
import type { JSONValue } from './index'; | ||
export declare enum Token { | ||
@@ -34,3 +34,3 @@ TOK_EOF = "EOF", | ||
} | ||
export declare type LexerTokenValue = string | number | JSONValue; | ||
export declare type LexerTokenValue = JSONValue; | ||
export interface LexerToken { | ||
@@ -59,15 +59,3 @@ type: Token; | ||
export declare type ExpressionNodeTree = ASTNode | ExpressionNode | FieldNode | ValueNode; | ||
export declare const basicTokens: { | ||
'(': Token; | ||
')': Token; | ||
'*': Token; | ||
',': Token; | ||
'.': Token; | ||
':': Token; | ||
'@': Token; | ||
$: Token; | ||
']': Token; | ||
'{': Token; | ||
'}': Token; | ||
}; | ||
export declare const basicTokens: Record<string, Token>; | ||
declare class StreamLexer { | ||
@@ -74,0 +62,0 @@ _current: number; |
@@ -1,12 +0,12 @@ | ||
import { ComparitorNode, ExpressionNode, ExpressionNodeTree, LexerToken } from './Lexer'; | ||
import { ComparitorNode, ExpressionNode, ExpressionNodeTree, LexerToken, ASTNode } from './Lexer'; | ||
declare class TokenParser { | ||
index: number; | ||
tokens: LexerToken[]; | ||
parse(expression: string): ExpressionNodeTree; | ||
parse(expression: string): ASTNode; | ||
private loadTokens; | ||
expression(rbp: number): ExpressionNodeTree; | ||
expression(rbp: number): ASTNode; | ||
private lookahead; | ||
private lookaheadToken; | ||
private advance; | ||
nud(token: LexerToken): ExpressionNodeTree; | ||
nud(token: LexerToken): ASTNode; | ||
led(tokenName: string, left: ExpressionNodeTree): ExpressionNode | ComparitorNode; | ||
@@ -13,0 +13,0 @@ private match; |
@@ -1,4 +0,4 @@ | ||
import { TreeInterpreter } from './TreeInterpreter'; | ||
import { ExpressionNode } from './Lexer'; | ||
import { JSONValue } from '.'; | ||
import type { TreeInterpreter } from './TreeInterpreter'; | ||
import type { ExpressionNode } from './Lexer'; | ||
import type { JSONValue } from '.'; | ||
export declare enum InputArgument { | ||
@@ -5,0 +5,0 @@ TYPE_NUMBER = 0, |
@@ -1,4 +0,4 @@ | ||
import { ExpressionNodeTree } from './Lexer'; | ||
import type { ExpressionNodeTree } from './Lexer'; | ||
import { Runtime } from './Runtime'; | ||
import { JSONValue } from '.'; | ||
import type { JSONValue } from '.'; | ||
export declare class TreeInterpreter { | ||
@@ -5,0 +5,0 @@ runtime: Runtime; |
export declare const isObject: (obj: unknown) => obj is Record<string, unknown>; | ||
export declare const strictDeepEqual: (first: unknown, second: unknown) => boolean; | ||
export declare const isFalse: (obj: unknown) => boolean; | ||
export declare const trimLeft: (str: string) => string; | ||
export declare const isAlpha: (ch: string) => boolean; | ||
export declare const isNum: (ch: string) => boolean; | ||
export declare const isAlphaNum: (ch: string) => boolean; |
{ | ||
"name": "@metrichor/jmespath", | ||
"description": "Typescript implementation of the JMESPath spec (100% compliant)", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"author": { | ||
@@ -44,3 +44,3 @@ "name": "Oxford Nanopore Technologies", | ||
"perf": "node scripts/perf.js", | ||
"build": "tsc --outDir dist/lib -d --module commonjs --declarationDir dist/types && rollup -c rollup.config.ts", | ||
"build": "tsc --outDir dist/lib -d --module commonjs && rollup -c rollup.config.ts", | ||
"start": "rollup -c rollup.config.ts -w", | ||
@@ -52,51 +52,35 @@ "test": "jest --coverage", | ||
"report-coverage": "cat ./coverage/lcov.info | coveralls", | ||
"commit": "git-cz", | ||
"semantic-release": "semantic-release", | ||
"semantic-release-prepare": "ts-node scripts/semantic-release-prepare", | ||
"precommit": "lint-staged" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-typescript": "^6.0.0", | ||
"@types/jest": "^26.0.14", | ||
"@types/node": "^14.11.8", | ||
"@typescript-eslint/eslint-plugin": "^4.4.0", | ||
"@typescript-eslint/parser": "^4.4.0", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@rollup/plugin-typescript": "^8.1.1", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"benchmark": "^2.1.4", | ||
"colors": "^1.4.0", | ||
"commitizen": "^4.2.1", | ||
"coveralls": "^3.1.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^7.10.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"husky": "^4.3.0", | ||
"jest": "^26.5.2", | ||
"jest-cli": "^26.5.2", | ||
"jest-config": "^26.5.2", | ||
"lint-staged": "^10.4.0", | ||
"prettier": "^2.1.2", | ||
"prettier-eslint": "^11.0.0", | ||
"prompt": "^1.0.0", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"husky": "^5.0.9", | ||
"jest": "^26.6.3", | ||
"jest-cli": "^26.6.3", | ||
"jest-config": "^26.6.3", | ||
"lint-staged": "^10.5.4", | ||
"prettier": "^2.2.1", | ||
"prettier-eslint": "^12.0.0", | ||
"prompt": "^1.1.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.29.0", | ||
"rollup": "^2.38.5", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semantic-release": "^17.1.2", | ||
"shelljs": "^0.8.4", | ||
"ts-jest": "^26.4.1", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.0.3" | ||
"ts-jest": "^26.5.1", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.20.23", | ||
"typescript": "^4.1.3" | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
447670
28
5714