dd-trace
Version:
Datadog APM tracing client for JavaScript
1 lines • 26.2 kB
JavaScript
(()=>{"use strict";var e={};e.d=(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{JSONPath:()=>JSONPath});let r=require("vm");let Hooks=class Hooks{add(e,t,r){if("string"!=typeof arguments[0])for(let e in arguments[0])this.add(e,arguments[0][e],arguments[1]);else(Array.isArray(e)?e:[e]).forEach(function(e){this[e]=this[e]||[],t&&this[e][r?"unshift":"push"](t)},this)}run(e,t){this[e]=this[e]||[],this[e].forEach(function(e){e.call(t&&t.context?t.context:t,t)})}};let Plugins=class Plugins{constructor(e){this.jsep=e,this.registered={}}register(...e){e.forEach(e=>{if("object"!=typeof e||!e.name||!e.init)throw Error("Invalid JSEP plugin format");this.registered[e.name]||(e.init(this.jsep),this.registered[e.name]=e)})}};let Jsep=class Jsep{static get version(){return"1.4.0"}static toString(){return"JavaScript Expression Parser (JSEP) v"+Jsep.version}static addUnaryOp(e){return Jsep.max_unop_len=Math.max(e.length,Jsep.max_unop_len),Jsep.unary_ops[e]=1,Jsep}static addBinaryOp(e,t,r){return Jsep.max_binop_len=Math.max(e.length,Jsep.max_binop_len),Jsep.binary_ops[e]=t,r?Jsep.right_associative.add(e):Jsep.right_associative.delete(e),Jsep}static addIdentifierChar(e){return Jsep.additional_identifier_chars.add(e),Jsep}static addLiteral(e,t){return Jsep.literals[e]=t,Jsep}static removeUnaryOp(e){return delete Jsep.unary_ops[e],e.length===Jsep.max_unop_len&&(Jsep.max_unop_len=Jsep.getMaxKeyLen(Jsep.unary_ops)),Jsep}static removeAllUnaryOps(){return Jsep.unary_ops={},Jsep.max_unop_len=0,Jsep}static removeIdentifierChar(e){return Jsep.additional_identifier_chars.delete(e),Jsep}static removeBinaryOp(e){return delete Jsep.binary_ops[e],e.length===Jsep.max_binop_len&&(Jsep.max_binop_len=Jsep.getMaxKeyLen(Jsep.binary_ops)),Jsep.right_associative.delete(e),Jsep}static removeAllBinaryOps(){return Jsep.binary_ops={},Jsep.max_binop_len=0,Jsep}static removeLiteral(e){return delete Jsep.literals[e],Jsep}static removeAllLiterals(){return Jsep.literals={},Jsep}get char(){return this.expr.charAt(this.index)}get code(){return this.expr.charCodeAt(this.index)}constructor(e){this.expr=e,this.index=0}static parse(e){return new Jsep(e).parse()}static getMaxKeyLen(e){return Math.max(0,...Object.keys(e).map(e=>e.length))}static isDecimalDigit(e){return e>=48&&e<=57}static binaryPrecedence(e){return Jsep.binary_ops[e]||0}static isIdentifierStart(e){return e>=65&&e<=90||e>=97&&e<=122||e>=128&&!Jsep.binary_ops[String.fromCharCode(e)]||Jsep.additional_identifier_chars.has(String.fromCharCode(e))}static isIdentifierPart(e){return Jsep.isIdentifierStart(e)||Jsep.isDecimalDigit(e)}throwError(e){let t=Error(e+" at character "+this.index);throw t.index=this.index,t.description=e,t}runHook(e,t){if(Jsep.hooks[e]){let r={context:this,node:t};return Jsep.hooks.run(e,r),r.node}return t}searchHook(e){if(Jsep.hooks[e]){let t={context:this};return Jsep.hooks[e].find(function(e){return e.call(t.context,t),t.node}),t.node}}gobbleSpaces(){let e=this.code;for(;e===Jsep.SPACE_CODE||e===Jsep.TAB_CODE||e===Jsep.LF_CODE||e===Jsep.CR_CODE;)e=this.expr.charCodeAt(++this.index);this.runHook("gobble-spaces")}parse(){this.runHook("before-all");let e=this.gobbleExpressions(),t=1===e.length?e[0]:{type:Jsep.COMPOUND,body:e};return this.runHook("after-all",t)}gobbleExpressions(e){let t=[],r,s;for(;this.index<this.expr.length;)if((r=this.code)===Jsep.SEMCOL_CODE||r===Jsep.COMMA_CODE)this.index++;else if(s=this.gobbleExpression())t.push(s);else if(this.index<this.expr.length){if(r===e)break;this.throwError('Unexpected "'+this.char+'"')}return t}gobbleExpression(){let e=this.searchHook("gobble-expression")||this.gobbleBinaryExpression();return this.gobbleSpaces(),this.runHook("after-expression",e)}gobbleBinaryOp(){this.gobbleSpaces();let e=this.expr.substr(this.index,Jsep.max_binop_len),t=e.length;for(;t>0;){if(Jsep.binary_ops.hasOwnProperty(e)&&(!Jsep.isIdentifierStart(this.code)||this.index+e.length<this.expr.length&&!Jsep.isIdentifierPart(this.expr.charCodeAt(this.index+e.length))))return this.index+=t,e;e=e.substr(0,--t)}return!1}gobbleBinaryExpression(){let e,t,r,s,i,n,a,o,p;if(!(n=this.gobbleToken())||!(t=this.gobbleBinaryOp()))return n;for(i={value:t,prec:Jsep.binaryPrecedence(t),right_a:Jsep.right_associative.has(t)},(a=this.gobbleToken())||this.throwError("Expected expression after "+t),s=[n,i,a];t=this.gobbleBinaryOp();){if(0===(r=Jsep.binaryPrecedence(t))){this.index-=t.length;break}i={value:t,prec:r,right_a:Jsep.right_associative.has(t)},p=t;let comparePrev=e=>i.right_a&&e.right_a?r>e.prec:r<=e.prec;for(;s.length>2&&comparePrev(s[s.length-2]);)a=s.pop(),t=s.pop().value,n=s.pop(),e={type:Jsep.BINARY_EXP,operator:t,left:n,right:a},s.push(e);(e=this.gobbleToken())||this.throwError("Expected expression after "+p),s.push(i,e)}for(o=s.length-1,e=s[o];o>1;)e={type:Jsep.BINARY_EXP,operator:s[o-1].value,left:s[o-2],right:e},o-=2;return e}gobbleToken(){let e,t,r,s;if(this.gobbleSpaces(),s=this.searchHook("gobble-token"))return this.runHook("after-token",s);if(e=this.code,Jsep.isDecimalDigit(e)||e===Jsep.PERIOD_CODE)return this.gobbleNumericLiteral();if(e===Jsep.SQUOTE_CODE||e===Jsep.DQUOTE_CODE)s=this.gobbleStringLiteral();else if(e===Jsep.OBRACK_CODE)s=this.gobbleArray();else{for(r=(t=this.expr.substr(this.index,Jsep.max_unop_len)).length;r>0;){if(Jsep.unary_ops.hasOwnProperty(t)&&(!Jsep.isIdentifierStart(this.code)||this.index+t.length<this.expr.length&&!Jsep.isIdentifierPart(this.expr.charCodeAt(this.index+t.length)))){this.index+=r;let e=this.gobbleToken();return e||this.throwError("missing unaryOp argument"),this.runHook("after-token",{type:Jsep.UNARY_EXP,operator:t,argument:e,prefix:!0})}t=t.substr(0,--r)}Jsep.isIdentifierStart(e)?(s=this.gobbleIdentifier(),Jsep.literals.hasOwnProperty(s.name)?s={type:Jsep.LITERAL,value:Jsep.literals[s.name],raw:s.name}:s.name===Jsep.this_str&&(s={type:Jsep.THIS_EXP})):e===Jsep.OPAREN_CODE&&(s=this.gobbleGroup())}return s?(s=this.gobbleTokenProperty(s),this.runHook("after-token",s)):this.runHook("after-token",!1)}gobbleTokenProperty(e){this.gobbleSpaces();let t=this.code;for(;t===Jsep.PERIOD_CODE||t===Jsep.OBRACK_CODE||t===Jsep.OPAREN_CODE||t===Jsep.QUMARK_CODE;){let r;if(t===Jsep.QUMARK_CODE){if(this.expr.charCodeAt(this.index+1)!==Jsep.PERIOD_CODE)break;r=!0,this.index+=2,this.gobbleSpaces(),t=this.code}this.index++,t===Jsep.OBRACK_CODE?((e={type:Jsep.MEMBER_EXP,computed:!0,object:e,property:this.gobbleExpression()}).property||this.throwError('Unexpected "'+this.char+'"'),this.gobbleSpaces(),(t=this.code)!==Jsep.CBRACK_CODE&&this.throwError("Unclosed ["),this.index++):t===Jsep.OPAREN_CODE?e={type:Jsep.CALL_EXP,arguments:this.gobbleArguments(Jsep.CPAREN_CODE),callee:e}:(t===Jsep.PERIOD_CODE||r)&&(r&&this.index--,this.gobbleSpaces(),e={type:Jsep.MEMBER_EXP,computed:!1,object:e,property:this.gobbleIdentifier()}),r&&(e.optional=!0),this.gobbleSpaces(),t=this.code}return e}gobbleNumericLiteral(){let e="",t,r;for(;Jsep.isDecimalDigit(this.code);)e+=this.expr.charAt(this.index++);if(this.code===Jsep.PERIOD_CODE)for(e+=this.expr.charAt(this.index++);Jsep.isDecimalDigit(this.code);)e+=this.expr.charAt(this.index++);if("e"===(t=this.char)||"E"===t){for(e+=this.expr.charAt(this.index++),("+"===(t=this.char)||"-"===t)&&(e+=this.expr.charAt(this.index++));Jsep.isDecimalDigit(this.code);)e+=this.expr.charAt(this.index++);Jsep.isDecimalDigit(this.expr.charCodeAt(this.index-1))||this.throwError("Expected exponent ("+e+this.char+")")}return r=this.code,Jsep.isIdentifierStart(r)?this.throwError("Variable names cannot start with a number ("+e+this.char+")"):(r===Jsep.PERIOD_CODE||1===e.length&&e.charCodeAt(0)===Jsep.PERIOD_CODE)&&this.throwError("Unexpected period"),{type:Jsep.LITERAL,value:parseFloat(e),raw:e}}gobbleStringLiteral(){let e="",t=this.index,r=this.expr.charAt(this.index++),s=!1;for(;this.index<this.expr.length;){let t=this.expr.charAt(this.index++);if(t===r){s=!0;break}if("\\"===t)switch(t=this.expr.charAt(this.index++)){case"n":e+="\n";break;case"r":e+="\r";break;case"t":e+=" ";break;case"b":e+="\b";break;case"f":e+="\f";break;case"v":e+="\v";break;default:e+=t}else e+=t}return s||this.throwError('Unclosed quote after "'+e+'"'),{type:Jsep.LITERAL,value:e,raw:this.expr.substring(t,this.index)}}gobbleIdentifier(){let e=this.code,t=this.index;for(Jsep.isIdentifierStart(e)?this.index++:this.throwError("Unexpected "+this.char);this.index<this.expr.length;)if(e=this.code,Jsep.isIdentifierPart(e))this.index++;else break;return{type:Jsep.IDENTIFIER,name:this.expr.slice(t,this.index)}}gobbleArguments(e){let t=[],r=!1,s=0;for(;this.index<this.expr.length;){this.gobbleSpaces();let i=this.code;if(i===e){r=!0,this.index++,e===Jsep.CPAREN_CODE&&s&&s>=t.length&&this.throwError("Unexpected token "+String.fromCharCode(e));break}if(i===Jsep.COMMA_CODE){if(this.index++,++s!==t.length){if(e===Jsep.CPAREN_CODE)this.throwError("Unexpected token ,");else if(e===Jsep.CBRACK_CODE)for(let e=t.length;e<s;e++)t.push(null)}}else if(t.length!==s&&0!==s)this.throwError("Expected comma");else{let e=this.gobbleExpression();e&&e.type!==Jsep.COMPOUND||this.throwError("Expected comma"),t.push(e)}}return r||this.throwError("Expected "+String.fromCharCode(e)),t}gobbleGroup(){this.index++;let e=this.gobbleExpressions(Jsep.CPAREN_CODE);if(this.code===Jsep.CPAREN_CODE)return(this.index++,1===e.length)?e[0]:!!e.length&&{type:Jsep.SEQUENCE_EXP,expressions:e};this.throwError("Unclosed (")}gobbleArray(){return this.index++,{type:Jsep.ARRAY_EXP,elements:this.gobbleArguments(Jsep.CBRACK_CODE)}}};Object.assign(Jsep,{hooks:new Hooks,plugins:new Plugins(Jsep),COMPOUND:"Compound",SEQUENCE_EXP:"SequenceExpression",IDENTIFIER:"Identifier",MEMBER_EXP:"MemberExpression",LITERAL:"Literal",THIS_EXP:"ThisExpression",CALL_EXP:"CallExpression",UNARY_EXP:"UnaryExpression",BINARY_EXP:"BinaryExpression",ARRAY_EXP:"ArrayExpression",TAB_CODE:9,LF_CODE:10,CR_CODE:13,SPACE_CODE:32,PERIOD_CODE:46,COMMA_CODE:44,SQUOTE_CODE:39,DQUOTE_CODE:34,OPAREN_CODE:40,CPAREN_CODE:41,OBRACK_CODE:91,CBRACK_CODE:93,QUMARK_CODE:63,SEMCOL_CODE:59,COLON_CODE:58,unary_ops:{"-":1,"!":1,"~":1,"+":1},binary_ops:{"||":1,"??":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10,"**":11},right_associative:new Set(["**"]),additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"}),Jsep.max_unop_len=Jsep.getMaxKeyLen(Jsep.unary_ops),Jsep.max_binop_len=Jsep.getMaxKeyLen(Jsep.binary_ops);let index_node_esm_jsep=e=>new Jsep(e).parse(),s=Object.getOwnPropertyNames(class{});Object.getOwnPropertyNames(Jsep).filter(e=>!s.includes(e)&&void 0===index_node_esm_jsep[e]).forEach(e=>{index_node_esm_jsep[e]=Jsep[e]}),index_node_esm_jsep.Jsep=Jsep,index_node_esm_jsep.plugins.register({name:"ternary",init(e){e.hooks.add("after-expression",function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;let r=t.node,s=this.gobbleExpression();if(s||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;let i=this.gobbleExpression();if(i||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:r,consequent:s,alternate:i},r.operator&&e.binary_ops[r.operator]<=.9){let s=r;for(;s.right.operator&&e.binary_ops[s.right.operator]<=.9;)s=s.right;t.node.test=s.right,s.right=t.node,t.node=r}}else this.throwError("Expected :")}})}});let i={name:"assignment",assignmentOperators:new Set(["=","*=","**=","/=","%=","+=","-=","<<=",">>=",">>>=","&=","^=","|=","||=","&&=","??="]),updateOperators:[43,45],assignmentPrecedence:.9,init(e){let t=[e.IDENTIFIER,e.MEMBER_EXP];function updateBinariesToAssignments(e){i.assignmentOperators.has(e.operator)?(e.type="AssignmentExpression",updateBinariesToAssignments(e.left),updateBinariesToAssignments(e.right)):e.operator||Object.values(e).forEach(e=>{e&&"object"==typeof e&&updateBinariesToAssignments(e)})}i.assignmentOperators.forEach(t=>e.addBinaryOp(t,i.assignmentPrecedence,!0)),e.hooks.add("gobble-token",function(e){let r=this.code;i.updateOperators.some(e=>e===r&&e===this.expr.charCodeAt(this.index+1))&&(this.index+=2,e.node={type:"UpdateExpression",operator:43===r?"++":"--",argument:this.gobbleTokenProperty(this.gobbleIdentifier()),prefix:!0},e.node.argument&&t.includes(e.node.argument.type)||this.throwError(`Unexpected ${e.node.operator}`))}),e.hooks.add("after-token",function(e){if(e.node){let r=this.code;i.updateOperators.some(e=>e===r&&e===this.expr.charCodeAt(this.index+1))&&(t.includes(e.node.type)||this.throwError(`Unexpected ${e.node.operator}`),this.index+=2,e.node={type:"UpdateExpression",operator:43===r?"++":"--",argument:e.node,prefix:!1})}}),e.hooks.add("after-expression",function(e){e.node&&updateBinariesToAssignments(e.node)})}};index_node_esm_jsep.plugins.register({name:"regex",init(e){e.hooks.add("gobble-token",function(t){if(47===this.code){let r=++this.index,s=!1;for(;this.index<this.expr.length;){if(47===this.code&&!s){let s,i=this.expr.slice(r,this.index),n="";for(;++this.index<this.expr.length;){let e=this.code;if(e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57)n+=this.char;else break}try{s=new RegExp(i,n)}catch(e){this.throwError(e.message)}return t.node={type:e.LITERAL,value:s,raw:this.expr.slice(r-1,this.index)},t.node=this.gobbleTokenProperty(t.node),t.node}this.code===e.OBRACK_CODE?s=!0:s&&this.code===e.CBRACK_CODE&&(s=!1),this.index+=92===this.code?2:1}this.throwError("Unclosed Regex")}})}},i),index_node_esm_jsep.addUnaryOp("typeof"),index_node_esm_jsep.addUnaryOp("void"),index_node_esm_jsep.addLiteral("null",null),index_node_esm_jsep.addLiteral("undefined",void 0);let n=new Set(["constructor","__proto__","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]),a={evalAst(e,t){switch(e.type){case"BinaryExpression":case"LogicalExpression":return a.evalBinaryExpression(e,t);case"Compound":return a.evalCompound(e,t);case"ConditionalExpression":return a.evalConditionalExpression(e,t);case"Identifier":return a.evalIdentifier(e,t);case"Literal":return a.evalLiteral(e,t);case"MemberExpression":return a.evalMemberExpression(e,t);case"UnaryExpression":return a.evalUnaryExpression(e,t);case"ArrayExpression":return a.evalArrayExpression(e,t);case"CallExpression":return a.evalCallExpression(e,t);case"AssignmentExpression":return a.evalAssignmentExpression(e,t);default:throw SyntaxError("Unexpected expression",e)}},evalBinaryExpression:(e,t)=>({"||":(e,t)=>e||t(),"&&":(e,t)=>e&&t(),"|":(e,t)=>e|t(),"^":(e,t)=>e^t(),"&":(e,t)=>e&t(),"==":(e,t)=>e==t(),"!=":(e,t)=>e!=t(),"===":(e,t)=>e===t(),"!==":(e,t)=>e!==t(),"<":(e,t)=>e<t(),">":(e,t)=>e>t(),"<=":(e,t)=>e<=t(),">=":(e,t)=>e>=t(),"<<":(e,t)=>e<<t(),">>":(e,t)=>e>>t(),">>>":(e,t)=>e>>>t(),"+":(e,t)=>e+t(),"-":(e,t)=>e-t(),"*":(e,t)=>e*t(),"/":(e,t)=>e/t(),"%":(e,t)=>e%t()})[e.operator](a.evalAst(e.left,t),()=>a.evalAst(e.right,t)),evalCompound(e,t){let r;for(let s=0;s<e.body.length;s++){"Identifier"===e.body[s].type&&["var","let","const"].includes(e.body[s].name)&&e.body[s+1]&&"AssignmentExpression"===e.body[s+1].type&&(s+=1);let i=e.body[s];r=a.evalAst(i,t)}return r},evalConditionalExpression:(e,t)=>a.evalAst(e.test,t)?a.evalAst(e.consequent,t):a.evalAst(e.alternate,t),evalIdentifier(e,t){if(Object.hasOwn(t,e.name))return t[e.name];throw ReferenceError(`${e.name} is not defined`)},evalLiteral:e=>e.value,evalMemberExpression(e,t){let r=String(e.computed?a.evalAst(e.property):e.property.name),s=a.evalAst(e.object,t);if(null==s||!Object.hasOwn(s,r)&&n.has(r))throw TypeError(`Cannot read properties of ${s} (reading '${r}')`);let i=s[r];return"function"==typeof i?i.bind(s):i},evalUnaryExpression:(e,t)=>({"-":e=>-a.evalAst(e,t),"!":e=>!a.evalAst(e,t),"~":e=>~a.evalAst(e,t),"+":e=>+a.evalAst(e,t),typeof:e=>typeof a.evalAst(e,t),void:e=>void a.evalAst(e,t)})[e.operator](e.argument),evalArrayExpression:(e,t)=>e.elements.map(e=>a.evalAst(e,t)),evalCallExpression(e,t){let r=e.arguments.map(e=>a.evalAst(e,t)),s=a.evalAst(e.callee,t);if(s===Function)throw Error("Function constructor is disabled");return s(...r)},evalAssignmentExpression(e,t){if("Identifier"!==e.left.type)throw SyntaxError("Invalid left-hand side in assignment");let r=e.left.name,s=a.evalAst(e.right,t);return t[r]=s,t[r]}};let SafeScript=class SafeScript{constructor(e){this.code=e,this.ast=index_node_esm_jsep(this.code)}runInNewContext(e){let t=Object.assign(Object.create(null),e);return a.evalAst(this.ast,t)}};function push(e,t){return(e=e.slice()).push(t),e}function unshift(e,t){return(t=t.slice()).unshift(e),t}let NewError=class NewError extends Error{constructor(e){super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'),this.avoidNew=!0,this.value=e,this.name="NewError"}};function JSONPath(e,t,r,s,i){if(!(this instanceof JSONPath))try{return new JSONPath(e,t,r,s,i)}catch(e){if(!e.avoidNew)throw e;return e.value}"string"==typeof e&&(i=s,s=r,r=t,t=e,e=null);let n=e&&"object"==typeof e;if(e=e||{},this.json=e.json||r,this.path=e.path||t,this.resultType=e.resultType||"value",this.flatten=e.flatten||!1,this.wrap=!Object.hasOwn(e,"wrap")||e.wrap,this.sandbox=e.sandbox||{},this.eval=void 0===e.eval?"safe":e.eval,this.ignoreEvalErrors=void 0!==e.ignoreEvalErrors&&e.ignoreEvalErrors,this.parent=e.parent||null,this.parentProperty=e.parentProperty||null,this.callback=e.callback||s||null,this.otherTypeCallback=e.otherTypeCallback||i||function(){throw TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==e.autostart){let s={path:n?e.path:t};n?"json"in e&&(s.json=e.json):s.json=r;let i=this.evaluate(s);if(!i||"object"!=typeof i)throw new NewError(i);return i}}JSONPath.prototype.evaluate=function(e,t,r,s){let i=this.parent,n=this.parentProperty,{flatten:a,wrap:o}=this;if(this.currResultType=this.resultType,this.currEval=this.eval,this.currSandbox=this.sandbox,r=r||this.callback,this.currOtherTypeCallback=s||this.otherTypeCallback,t=t||this.json,(e=e||this.path)&&"object"==typeof e&&!Array.isArray(e)){if(!e.path&&""!==e.path)throw TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!Object.hasOwn(e,"json"))throw TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');({json:t}=e),a=Object.hasOwn(e,"flatten")?e.flatten:a,this.currResultType=Object.hasOwn(e,"resultType")?e.resultType:this.currResultType,this.currSandbox=Object.hasOwn(e,"sandbox")?e.sandbox:this.currSandbox,o=Object.hasOwn(e,"wrap")?e.wrap:o,this.currEval=Object.hasOwn(e,"eval")?e.eval:this.currEval,r=Object.hasOwn(e,"callback")?e.callback:r,this.currOtherTypeCallback=Object.hasOwn(e,"otherTypeCallback")?e.otherTypeCallback:this.currOtherTypeCallback,i=Object.hasOwn(e,"parent")?e.parent:i,n=Object.hasOwn(e,"parentProperty")?e.parentProperty:n,e=e.path}if(i=i||null,n=n||null,Array.isArray(e)&&(e=JSONPath.toPathString(e)),!e&&""!==e||!t)return;let p=JSONPath.toPathArray(e);"$"===p[0]&&p.length>1&&p.shift(),this._hasParentSelector=null;let h=this._trace(p,t,["$"],i,n,r).filter(function(e){return e&&!e.isParentSelector});return h.length?o||1!==h.length||h[0].hasArrExpr?h.reduce((e,t)=>{let r=this._getPreferredOutput(t);return a&&Array.isArray(r)?e=e.concat(r):e.push(r),e},[]):this._getPreferredOutput(h[0]):o?[]:void 0},JSONPath.prototype._getPreferredOutput=function(e){let t=this.currResultType;switch(t){case"all":{let t=Array.isArray(e.path)?e.path:JSONPath.toPathArray(e.path);return e.pointer=JSONPath.toPointer(t),e.path="string"==typeof e.path?e.path:JSONPath.toPathString(e.path),e}case"value":case"parent":case"parentProperty":return e[t];case"path":return JSONPath.toPathString(e[t]);case"pointer":return JSONPath.toPointer(e.path);default:throw TypeError("Unknown result type")}},JSONPath.prototype._handleCallback=function(e,t,r){if(t){let s=this._getPreferredOutput(e);e.path="string"==typeof e.path?e.path:JSONPath.toPathString(e.path),t(s,r,e)}},JSONPath.prototype._trace=function(e,t,r,s,i,n,a,o){let p;if(!e.length)return p={path:r,value:t,parent:s,parentProperty:i,hasArrExpr:a},this._handleCallback(p,n,"value"),p;let h=e[0],l=e.slice(1),c=[];function addRet(e){Array.isArray(e)?e.forEach(e=>{c.push(e)}):c.push(e)}if(("string"!=typeof h||o)&&t&&Object.hasOwn(t,h))addRet(this._trace(l,t[h],push(r,h),t,h,n,a));else if("*"===h)this._walk(t,e=>{addRet(this._trace(l,t[e],push(r,e),t,e,n,!0,!0))});else if(".."===h)addRet(this._trace(l,t,r,s,i,n,a)),this._walk(t,s=>{"object"==typeof t[s]&&addRet(this._trace(e.slice(),t[s],push(r,s),t,s,n,!0))});else if("^"===h)return this._hasParentSelector=!0,{path:r.slice(0,-1),expr:l,isParentSelector:!0};else if("~"===h)return p={path:push(r,h),value:i,parent:s,parentProperty:null},this._handleCallback(p,n,"property"),p;else if("$"===h)addRet(this._trace(l,t,r,null,null,n,a));else if(/^(-?\d*):(-?\d*):?(\d*)$/u.test(h))addRet(this._slice(h,l,t,r,s,i,n));else if(0===h.indexOf("?(")){if(!1===this.currEval)throw Error("Eval [?(expr)] prevented in JSONPath expression.");let e=h.replace(/^\?\((.*?)\)$/u,"$1"),a=/@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(e);a?this._walk(t,e=>{let o=[a[2]],p=a[1]?t[e][a[1]]:t[e];this._trace(o,p,r,s,i,n,!0).length>0&&addRet(this._trace(l,t[e],push(r,e),t,e,n,!0))}):this._walk(t,a=>{this._eval(e,t[a],a,r,s,i)&&addRet(this._trace(l,t[a],push(r,a),t,a,n,!0))})}else if("("===h[0]){if(!1===this.currEval)throw Error("Eval [(expr)] prevented in JSONPath expression.");addRet(this._trace(unshift(this._eval(h,t,r.at(-1),r.slice(0,-1),s,i),l),t,r,s,i,n,a))}else if("@"===h[0]){let e=!1,a=h.slice(1,-2);switch(a){case"scalar":t&&["object","function"].includes(typeof t)||(e=!0);break;case"boolean":case"string":case"undefined":case"function":typeof t===a&&(e=!0);break;case"integer":Number.isFinite(t)&&!(t%1)&&(e=!0);break;case"number":Number.isFinite(t)&&(e=!0);break;case"nonFinite":"number"!=typeof t||Number.isFinite(t)||(e=!0);break;case"object":t&&typeof t===a&&(e=!0);break;case"array":Array.isArray(t)&&(e=!0);break;case"other":e=this.currOtherTypeCallback(t,r,s,i);break;case"null":null===t&&(e=!0);break;default:throw TypeError("Unknown value type "+a)}if(e)return p={path:r,value:t,parent:s,parentProperty:i},this._handleCallback(p,n,"value"),p}else if("`"===h[0]&&t&&Object.hasOwn(t,h.slice(1))){let e=h.slice(1);addRet(this._trace(l,t[e],push(r,e),t,e,n,a,!0))}else if(h.includes(","))for(let e of h.split(","))addRet(this._trace(unshift(e,l),t,r,s,i,n,!0));else!o&&t&&Object.hasOwn(t,h)&&addRet(this._trace(l,t[h],push(r,h),t,h,n,a,!0));if(this._hasParentSelector)for(let e=0;e<c.length;e++){let r=c[e];if(r&&r.isParentSelector){let o=this._trace(r.expr,t,r.path,s,i,n,a);if(Array.isArray(o)){c[e]=o[0];let t=o.length;for(let r=1;r<t;r++)e++,c.splice(e,0,o[r])}else c[e]=o}}return c},JSONPath.prototype._walk=function(e,t){if(Array.isArray(e)){let r=e.length;for(let e=0;e<r;e++)t(e)}else e&&"object"==typeof e&&Object.keys(e).forEach(e=>{t(e)})},JSONPath.prototype._slice=function(e,t,r,s,i,n,a){if(!Array.isArray(r))return;let o=r.length,p=e.split(":"),h=p[2]&&Number.parseInt(p[2])||1,l=p[0]&&Number.parseInt(p[0])||0,c=p[1]&&Number.parseInt(p[1])||o;l=l<0?Math.max(0,l+o):Math.min(o,l),c=c<0?Math.max(0,c+o):Math.min(o,c);let d=[];for(let e=l;e<c;e+=h)this._trace(unshift(e,t),r,s,i,n,a,!0).forEach(e=>{d.push(e)});return d},JSONPath.prototype._eval=function(e,t,r,s,i,n){this.currSandbox._$_parentProperty=n,this.currSandbox._$_parent=i,this.currSandbox._$_property=r,this.currSandbox._$_root=this.json,this.currSandbox._$_v=t;let a=e.includes("@path");a&&(this.currSandbox._$_path=JSONPath.toPathString(s.concat([r])));let o=this.currEval+"Script:"+e;if(!JSONPath.cache[o]){let t=e.replaceAll("@parentProperty","_$_parentProperty").replaceAll("@parent","_$_parent").replaceAll("@property","_$_property").replaceAll("@root","_$_root").replaceAll(/@([.\s)[])/gu,"_$_v$1");if(a&&(t=t.replaceAll("@path","_$_path")),"safe"===this.currEval||!0===this.currEval||void 0===this.currEval)JSONPath.cache[o]=new this.safeVm.Script(t);else if("native"===this.currEval)JSONPath.cache[o]=new this.vm.Script(t);else if("function"==typeof this.currEval&&this.currEval.prototype&&Object.hasOwn(this.currEval.prototype,"runInNewContext")){let e=this.currEval;JSONPath.cache[o]=new e(t)}else if("function"==typeof this.currEval)JSONPath.cache[o]={runInNewContext:e=>this.currEval(t,e)};else throw TypeError(`Unknown "eval" property "${this.currEval}"`)}try{return JSONPath.cache[o].runInNewContext(this.currSandbox)}catch(t){if(this.ignoreEvalErrors)return!1;throw Error("jsonPath: "+t.message+": "+e)}},JSONPath.cache={},JSONPath.toPathString=function(e){let t=e.length,r="$";for(let s=1;s<t;s++)/^(~|\^|@.*?\(\))$/u.test(e[s])||(r+=/^[0-9*]+$/u.test(e[s])?"["+e[s]+"]":"['"+e[s]+"']");return r},JSONPath.toPointer=function(e){let t=e.length,r="";for(let s=1;s<t;s++)/^(~|\^|@.*?\(\))$/u.test(e[s])||(r+="/"+e[s].toString().replaceAll("~","~0").replaceAll("/","~1"));return r},JSONPath.toPathArray=function(e){let{cache:t}=JSONPath;if(t[e])return t[e].concat();let r=[],s=e.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu,";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu,function(e,t){return"[#"+(r.push(t)-1)+"]"}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu,function(e,t){return"['"+t.replaceAll(".","%@%").replaceAll("~","%%@@%%")+"']"}).replaceAll("~",";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu,";").replaceAll("%@%",".").replaceAll("%%@@%%","~").replaceAll(/(?:;)?(\^+)(?:;)?/gu,function(e,t){return";"+t.split("").join(";")+";"}).replaceAll(/;;;|;;/gu,";..;").replaceAll(/;$|'?\]|'$/gu,"").split(";").map(function(e){let t=e.match(/#(\d+)/u);return t&&t[1]?r[t[1]]:e});return t[e]=s,t[e].concat()},JSONPath.prototype.safeVm={Script:SafeScript},JSONPath.prototype.vm=r,module.exports=t})();