UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 29.9 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(global,()=>(()=>{"use strict";var e={523:e=>{e.exports=require("./logger")},1145:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createOutboundDeclarations=void 0,t.createAxiosDeclaration=a,t.createNodeFetchDeclaration=c,t.createRequestDeclaration=l,t.createPgDeclaration=u,t.createIoRedisDeclaration=p,t.generateIoRedisFunctionId=d;const i=n(5809),o=n(8528),r=n(3903),s=n(9850);function a(){return[f("axios","Axios","request",i.hudConfig.axiosFunctionId)]}function c(){return[f("node-fetch","node-fetch","fetch",i.hudConfig.nodeFetchFunctionId),...Object.entries(i.hudConfig.nodeFetchBodiesFunctionIds).map(([e,t])=>f("node-fetch","node-fetch",e,t))]}function l(){return[f("request","request","request",i.hudConfig.requestFunctionId),...Object.entries(i.hudConfig.requestMethodFunctionIds).map(([e,t])=>f("request","request",e,t))]}function u(){return[f("pg","Client","connect",i.hudConfig.pgConnectFunctionId),f("pg","Client","query",i.hudConfig.pgQueryFunctionId),f("pg","Client","end",i.hudConfig.pgEndFunctionId)]}function p(e){return e&&0!==e.length?e.map(e=>f("ioredis","Redis",e,d(e))):[]}function d(e){return(0,i.functionUuidToBase64)((0,r.v5)(`ioredis-${e}`,i.hudConfig.functionUuidNamespace))}function f(e,t,n,i){return{id_generated:!0,module:e,third_party_module:e,file:`${e}.js`,format:"commonjs",async:!0,runtime_function_id:(0,s.rawFunctionIdToUuidFunctionId)(i),type:o.EntityType.ClassMethod,methodKind:"method",symbol:{sourcemap_location_hints:[{name:n,line:0,column:0,source:`${e}.js`}],name:n,format:"%s"},scope_chain:[{type:o.EntityType.Program,symbol:{sourcemap_location_hints:[]},context:{},childrenCount:{},siblingIndex:0},{type:o.EntityType.ClassDeclaration,symbol:{sourcemap_location_hints:[{name:t,line:0,column:0,source:`${e}.js`}],name:t,format:"%s"},context:{},childrenCount:{},siblingIndex:0}],original_location:{file:`${e}.js`,start_line:0,end_line:0,start_column:0,end_column:0},parameters:[],start_line:0,end_line:0,start_column:0,source_code_hash:"1",bundler_build_id:"1",was_bundler_build_id_generated:!0,has_input_map:!0,sourcemap_crc:1,file_path_checksum:1,file_checksum:1,declarations_count:1,childrenCount:{},siblingIndex:0,context:{}}}t.createOutboundDeclarations={axios:a,"node-fetch":c,request:l,pg:u,ioredis:p}},1498:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getDeclarationsBatchRequest=function(e){const t=(new Date).toISOString();return{...o.HudClient.defaultRequest,type:"FunctionDeclaration",arr:e,send_time:t,event_version:i.FUNCTION_DECLARATION_VERSION}};const i=n(8528),o=n(4672)},1602:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getScope=function(e,t,n){const r=(0,i.getEntityType)(e);if(r){const s=(0,i.getEntityIdentity)(e.node),a=(0,o.getContextualData)(e,n),c=s?s.loc?[n(s.loc.start,s.name,s.loc.filename??t)]:[]:e.node.loc?[n(e.node.loc.start,void 0,e.node.loc.filename??t)]:[],l=c[0]?.name??s?.name;return{type:r,context:a,symbol:{name:l,sourcemap_location_hints:c,format:l?"%s":void 0},methodKind:(0,o.getMethodKind)(e.node)}}};const i=n(5203),o=n(9127)},2535:function(e,t,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getSymbolName=function(e){let t=e.name;const n=e.sourcemap_location_hints;if(n.length>0&&n.every(e=>e.name)){const i=n.map(e=>e.name?.startsWith("#")?e.name?.slice(1):e.name);e.format?Array.from(e.format.matchAll(/%s/g)).length!==i.length?o.worker_logger.warning("Format string does not match number of location hints",{format:e.format,locationHints:i}):t=r.default.format(e.format,...i):t=i.join(".")}return t??""},t.getNodeLocation=function(e,t,n=void 0){const i=e.loc?.start,r=e.loc?.end;if(!i||!r)return o.worker_logger.info("Node without location",{filename:n,type:e.type}),{start:{source:null,line:-1,column:-1},end:{source:null,line:-1,column:-1}};const s=t({line:i.line,column:i.column}),a=t({line:r.line,column:r.column});return null!==s.line&&null!==s.column&&null!==a.line&&null!==a.column||(o.worker_logger.debug("Could not find location for function",{filename:n,type:e.type,locStart:i,locEnd:r}),s.line=-1,s.column=-1,a.line=-1,a.column=-1),{start:{source:s.source,line:s.line,column:s.column},end:{source:a.source,line:a.line,column:a.column}}};const o=n(523),r=i(n(9023))},2546:e=>{e.exports=require("./lib")},2784:e=>{e.exports=require("../native/_index")},3176:e=>{e.exports=require("buffer-crc32")},3903:e=>{e.exports=require("uuid")},4634:e=>{e.exports=require("source-map")},4672:e=>{e.exports=require("./client")},5203:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getEntityType=function(e){const{node:t}=e;return i.types.isFunctionDeclaration(t)?o.EntityType.FunctionDeclaration:i.types.isFunctionExpression(t)?o.EntityType.FunctionExpression:i.types.isArrowFunctionExpression(t)?o.EntityType.FunctionArrow:i.types.isObjectMethod(t)?o.EntityType.ObjectMethod:i.types.isStaticBlock(t)||i.types.isClassMethod(t)?o.EntityType.ClassMethod:i.types.isClassPrivateMethod(t)?o.EntityType.ClassPrivateMethod:i.types.isClassDeclaration(t)?o.EntityType.ClassDeclaration:i.types.isClassExpression(t)?o.EntityType.ClassExpression:i.types.isForInStatement(t)||i.types.isForOfStatement(t)||i.types.isForStatement(t)?o.EntityType.ForLoop:i.types.isBlockStatement(t)?function(e){const t=e.parentPath.node;if(!(i.types.isFunctionDeclaration(t)||i.types.isFunctionExpression(t)||i.types.isArrowFunctionExpression(t)||i.types.isClassMethod(t)||i.types.isObjectMethod(t)||i.types.isClassPrivateMethod(t)))if(i.types.isIfStatement(t)){if("consequent"===e.parentKey)return o.EntityType.IfConsequent;if("alternate"===e.parentKey)return o.EntityType.IfAlternate;if("test"===e.parentKey)return o.EntityType.IfTest}else{if(i.types.isBlockStatement(t)||i.types.isProgram(t))return o.EntityType.Block;if(i.types.isTryStatement(t)){if("block"===e.parentKey)return o.EntityType.Try;if("finalizer"===e.parentKey)return o.EntityType.Finally}else{if(i.types.isCatchClause(t))return;if(i.types.isWhileStatement(t))return"test"===e.parentKey?o.EntityType.WhileTest:o.EntityType.Do;if(i.types.isDoWhileStatement(t))return"test"===e.parentKey?o.EntityType.WhileTest:o.EntityType.Do;if(!(i.types.isForStatement(t)||i.types.isForInStatement(t)||i.types.isForOfStatement(t)))return;if("test"===e.parentKey)return o.EntityType.ForTest;if("body"===e.parentKey)return o.EntityType.ForBlock}}}(e):i.types.isProgram(t)?o.EntityType.Program:i.types.isDoWhileStatement(t)?o.EntityType.DoWhile:i.types.isWhileStatement(t)?o.EntityType.While:i.types.isCatchClause(t)?o.EntityType.Catch:i.types.isObjectExpression(t)?o.EntityType.ObjectExpression:i.types.isWithStatement(t)?o.EntityType.With:i.types.isSwitchStatement(t)?o.EntityType.Switch:i.types.isSwitchCase(t)?o.EntityType.SwitchCase:i.types.isTryStatement(t)?o.EntityType.TryCatch:i.types.isIfStatement(t)?o.EntityType.If:o.EntityType.Other},t.getEntityIdentity=function(e){return i.types.isFunctionDeclaration(e)?i.types.isIdentifier(e.id)?e.id:void r.worker_logger.info("Function declaration without an identifier"):i.types.isClassDeclaration(e)?i.types.isIdentifier(e.id)?e.id:void r.worker_logger.info("Class declaration without an identifier"):i.types.isFunctionExpression(e)||i.types.isClassExpression(e)?i.types.isIdentifier(e.id)?e.id:void 0:i.types.isClassMethod(e)?i.types.isIdentifier(e.key)?e.key:void r.worker_logger.info("Class method without an identifier"):i.types.isObjectMethod(e)?i.types.isIdentifier(e.key)?e.key:void r.worker_logger.info("Object method without an identifier"):i.types.isClassPrivateMethod(e)?i.types.isIdentifier(e.key.id)?e.key.id:void r.worker_logger.info("Class private method without an identifier"):void 0};const i=n(6346),o=n(8528),r=n(523)},5809:e=>{e.exports=require("./config")},6066:function(e,t,n){var i=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||i(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(1498),t),o(n(9850),t),o(n(1145),t),o(n(9127),t)},6346:e=>{e.exports=require("@babel/core")},6760:e=>{e.exports=require("node:path")},6864:function(e,t,n){var i,o=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=i(e),s=0;s<n.length;s++)"default"!==n[s]&&o(t,e,n[s]);return r(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.getParameterInfo=function(e,t){return e.node.params.map(e=>{try{return p(e,t)}catch{return}}).filter(e=>void 0!==e)};const a=s(n(6346)),c=n(8528),l=n(523);function u(e,t){if(a.types.isIdentifier(e.argument)){const n=e.argument.loc?t(e.argument.loc.start):void 0;return{name:n?.name??e.argument.name,type:c.ParameterTypes[e.type],sourcemap_location_hint:n}}{l.worker_logger.warning("Unsupported rest element",{type:e.argument.type});const n=e.loc?t(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:n}}}function p(e,t){if(e)switch(e?.type){case"Identifier":return function(e,t){const n=e.loc?t(e.loc.start,e.name):void 0;return{name:n?.name??e.name,type:c.ParameterTypes[e.type],sourcemap_location_hint:n}}(e,t);case"AssignmentPattern":return function(e,t,n,i){const o=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:o,left:t,right:i}}(e,p(e.left,t),t,function(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"BigIntLiteral":case"DecimalLiteral":return{type:e.type,value:e.value};case"RegExpLiteral":return{type:e.type,value:e.pattern}}return{type:e.type}}(e.right));case"ArrayPattern":return function(e,t,n){const i=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:i,elements:t}}(e,e.elements.map(e=>p(e,t)).filter(e=>void 0!==e),t);case"RestElement":return u(e,t);case"ObjectPattern":{const n=[];return e.properties.forEach(e=>{if(a.types.isObjectProperty(e)){const i=a.types.isIdentifier(e.key)&&a.types.isIdentifier(e.value)||a.types.isAssignmentPattern(e.value)?void 0:p(e.key,t);n.push(function(e,t,n,i){const o=e.loc?t(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:o,key:n,value:i}}(e,t,i,p(e.value,t)))}else a.types.isRestElement(e)&&n.push(u(e,t))}),function(e,t,n){const i=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:i,properties:t}}(e,n,t)}default:l.worker_logger.warning("Unsupported parameter type",{type:e.type})}}},8528:e=>{e.exports=require("./dto")},9011:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.NamespaceScopeAlias=t.ScopableAlias=void 0,t.isHudScopeable=function(e){return i.types.isArrowFunctionExpression(e)||i.types.isBlockStatement(e)||i.types.isCatchClause(e)||i.types.isClassMethod(e)||i.types.isClassPrivateMethod(e)||i.types.isDeclareModule(e)||i.types.isDoExpression(e)||i.types.isDoWhileStatement(e)||i.types.isForInStatement(e)||i.types.isForOfStatement(e)||i.types.isForStatement(e)||i.types.isFunctionDeclaration(e)||i.types.isFunctionExpression(e)||i.types.isIfStatement(e)||i.types.isLabeledStatement(e)||i.types.isObjectMethod(e)||i.types.isProgram(e)||i.types.isStaticBlock(e)||i.types.isSwitchCase(e)||i.types.isTSModuleBlock(e)||i.types.isTryStatement(e)||i.types.isWhileStatement(e)||i.types.isWithStatement(e)||i.types.isClassDeclaration(e)||i.types.isClassExpression(e)||i.types.isObjectExpression(e)||i.types.isSwitchStatement(e)},t.isNamespaceScopeable=function(e){return i.types.isFunction(e)||i.types.isClass(e)||i.types.isObjectExpression(e)};const i=n(6346);t.ScopableAlias="ArrowFunctionExpression|BlockStatement|CatchClause|ClassMethod|ClassPrivateMethod|DeclareModule|DoExpression|DoWhileStatement|ForInStatement|ForOfStatement|ForStatement|FunctionDeclaration|FunctionExpression|IfStatement|LabeledStatement|ObjectMethod|StaticBlock|SwitchCase|TSModuleBlock|TryStatement|WhileStatement|WithStatement|ClassDeclaration|ClassExpression|ObjectExpression|SwitchStatement",t.NamespaceScopeAlias="FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod|ClassMethod|ClassPrivateMethod|ClassDeclaration|ClassExpression|ObjectExpression"},9023:e=>{e.exports=require("util")},9127:function(e,t,n){var i,o=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=i(e),s=0;s<n.length;s++)"default"!==n[s]&&o(t,e,n[s]);return r(t,e),t});Object.defineProperty(t,"__esModule",{value:!0}),t.getFunctionIdentifier=function(e){const{node:t}=e;if(c.types.isFunctionDeclaration(t)||c.types.isFunctionExpression(t)){if(c.types.isIdentifier(t.id))return t.id}else if(c.types.isClassMethod(t)){if(c.types.isIdentifier(t.key))return t.key}else if(c.types.isClassPrivateMethod(t)){if(c.types.isIdentifier(t.key.id))return t.key.id}else if(c.types.isObjectMethod(t)&&c.types.isIdentifier(t.key))return t.key},t.getContextSymbol=h,t.getContextualData=function(e,t){let n,i;(e.isFunctionExpression()||e.isArrowFunctionExpression()||e.isClassExpression())&&(n=function(e,t){const n=e.parentPath;if(n.isCallExpression())for(const[i,o]of n.node.arguments.entries())if(o===e.node){const o=n.node.callee;let r;try{r=m(o,t)}catch(t){if(!(t instanceof u.HudUnsupportedError))throw t;{const n=`${o.type}-${e.node.type}`;b.has(n)||(p.worker_logger.warning("could not get callee symbol recursively",{error:t,errorMessage:t.message,calleType:o.type,nodeType:e.node.type}),b.add(n))}}const s=g(n.node,t);return{callee:{symbol:r,argsCount:n.node.arguments.length,args:s},index:i}}}(e,t)),(e.isFunctionExpression()||e.isArrowFunctionExpression())&&(i=function(e){const t=e.parentPath;return!!t.isCallExpression()&&t.node.callee===e.node}(e));const o=h(e,t);return o&&(o.name=(0,d.getSymbolName)(o)),{symbol:o,callback:n,immediatelyInvoked:i}},t.getMethodKind=function(e){if(a.types.isClassMethod(e)||a.types.isObjectMethod(e)||a.types.isClassPrivateMethod(e))return e.kind};const a=s(n(6346)),c=n(6346),l=n(8528),u=n(2546),p=n(523),d=n(2535);function f(e,t,n){const i=e.loc?n(e.loc.start,t,e.loc.filename):void 0;return{name:i?.name??t,sourcemap_location_hints:i?[i]:[],format:"%s"}}function m(e,t){if(c.types.isIdentifier(e)){const n=e.loc?[t(e.loc.start,e.name,e.loc.filename)]:[];return{name:n[0]?.name??e.name,sourcemap_location_hints:n,format:"%s"}}if(c.types.isMemberExpression(e)||c.types.isOptionalMemberExpression(e)){let n;n=c.types.isThisExpression(e.object)?{name:"this",sourcemap_location_hints:e.object.loc?[t(e.object.loc.start,"this",e.object.loc.filename)]:[]}:m(e.object,t);const i=m(e.property,t),o=e.computed?n.name+"["+i.name+"]":n.name+"."+i.name,r=n.format??"%s",s=i.format??"%s",a=e.computed?`${r}[${s}]`:`${r}.${s}`;return{name:o,sourcemap_location_hints:[...n.sourcemap_location_hints,...i.sourcemap_location_hints],format:a}}if(c.types.isOptionalCallExpression(e)||c.types.isCallExpression(e))return m(e.callee,t);if(c.types.isSequenceExpression(e))return m(e.expressions[e.expressions.length-1],t);if(c.types.isArrayExpression(e))return{name:"[]",sourcemap_location_hints:e.loc?[t(e.loc.start,"[]",e.loc.filename)]:[],format:"%s"};if(c.types.isObjectExpression(e))return{name:"{}",sourcemap_location_hints:e.loc?[t(e.loc.start,"{}",e.loc.filename)]:[],format:"%s"};if(c.types.isStringLiteral(e)){const n=e.loc?[t(e.loc.start,e.value,e.loc.filename)]:[];return{name:`"${n[0]?.name??e.value}"`,sourcemap_location_hints:n,format:'"%s"'}}throw new u.HudUnsupportedError("Unsupported left side of assignment - "+e.type+"loc - "+JSON.stringify(e.loc))}const y=new Set;function h(e,t){const{node:n}=e;if(e.isExpression())try{return function(e,t){const{parent:n}=e;if(c.types.isVariableDeclarator(n)&&c.types.isIdentifier(n.id))return f(n,n.id.name,t);if(c.types.isObjectProperty(n)&&c.types.isIdentifier(n.key))return f(n,n.key.name,t);if(c.types.isClassProperty(n)&&c.types.isIdentifier(n.key))return f(n,n.key.name,t);if(c.types.isAssignmentExpression(n))return m(n.left,t);if(c.types.isAssignmentPattern(n))return m(n.left,t);throw new u.HudUnsupportedError(`Unsupported parent type - ${n.type} for me ${e.node.type}`)}(e,t)}catch(t){if(t instanceof u.HudUnsupportedError){const n=`${e.parentPath?.node.type}`;return void(y.has(n)||(p.worker_logger.warning("getContextSymbol: Unsupported parent node type",{parentType:e.parentPath?.node.type,error:t,errorMessage:t.message}),y.add(n)))}throw t}p.worker_logger.debug("getContextSymbol; Unsupported node type",{type:n.type})}function g(e,t){const n=[];return e.arguments.forEach((e,i)=>{let o,r;if(c.types.isStringLiteral(e)?(o=l.ArgumentTypes.StringLiteral,r=e.value):c.types.isTemplateLiteral(e)?(o=l.ArgumentTypes.TemplateString,r=function(e){let t="";const n=e.quasis,i=e.expressions;for(let e=0;e<n.length;e++)t+=n[e].value.cooked,e<i.length&&(t+=`\${${_(i[e])}}`);return t=`\`${t}\``,t}(e)):c.types.isIdentifier(e)&&(o=l.ArgumentTypes.Identifier,r=e.name),o&&r){const s=c.types.isIdentifier(e)?e.name:void 0,a=e.loc?t(e.loc.start,s):void 0;n.push({index:i,type:o,value:a?.name??r,sourcemap_location_hint:a})}}),n}function _(e){if(c.types.isIdentifier(e))return e.name;if(c.types.isStringLiteral(e))return e.value;if(c.types.isCallExpression(e)||c.types.isOptionalCallExpression(e)){const t=e;if(c.types.isIdentifier(t.callee))return t.callee.name;if(c.types.isMemberExpression(t.callee)||c.types.isOptionalMemberExpression(t.callee)){let e="";const n=t.callee;if(c.types.isThisExpression(n.object)?e+="this.":c.types.isIdentifier(n.object)&&(e+=`${n.object.name}.`),""!==e&&c.types.isIdentifier(n.property))return e+=`${n.property.name}`,e}}return""}const b=new Set},9850:function(e,t,n){var i,o=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,o)}:function(e,t,n,i){void 0===i&&(i=n),e[i]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=i(e),s=0;s<n.length;s++)"default"!==n[s]&&o(t,e,n[s]);return r(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.fixSourceMap=F,t.getRealPositionNothingFunc=O,t.getRealPositionOffsetsFunc=I,t.getRealPositionSourceMapFunc=M,t.parseDeclarations=async function(e,t,n=null,i,o=!1){const{filename:r,bundlerBuildId:s,bundlerBuildIdGenerated:a,lineOffset:O,columnOffset:D,file_path_checksum:A,file_checksum:B,functionIds:q,sourceCodeHash:N,moduleBase:$,isNextJsApp:R,marksCount:U,prebundle_file_checksum:W}=e,L=W??B;if(g.worker_logger.debug("Parsing code",{filename:r}),i)try{if(!T){const e=(0,h.myRequire)("ts-node");T=e.create({...i,transpileOnly:!0,typeCheck:!1})}const e=function(e,t,n){try{return n.compile(e,t)}catch(e){return void g.worker_logger.warning("ts file pass, but failed to compile with ts-node",{filename:t,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}(t,r,T);if(!e)return{declarations:[],blacklist:{file_path_checksum:A,file_checksum:L,uuids:q},generatedAsyncFunctions:[]};t=e}catch(e){return g.worker_logger.error("Failed to require and compile ts file",{filename:r,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),{declarations:[],blacklist:{file_path_checksum:A,file_checksum:L,uuids:q},generatedAsyncFunctions:[]}}else if(r.endsWith(".ts")||r.endsWith(".mts"))return g.worker_logger.error("ts file pass, but not found ts-options"),{declarations:[],blacklist:{file_path_checksum:A,file_checksum:L,uuids:q},generatedAsyncFunctions:[]};const K=(0,_.default)(t).readUInt32BE();if(K!==B)return g.worker_logger.warning("File checksum mismatch",{filename:r,file_path_checksum:A,diskFileChecksum:K,file_checksum:B,functionIds:q}),{declarations:[],blacklist:{file_path_checksum:A,file_checksum:L,uuids:q},generatedAsyncFunctions:[]};let H,J,V=(e,t,n)=>({name:t??void 0,line:e.line,column:e.column,source:n??void 0});if(function(e){return void 0!==e.lineOffset&&void 0!==e.columnOffset&&(0!==e.lineOffset||0!==e.columnOffset)}(e))V=I(O,D);else{const e=(0,b.getSourceMap)(r,t);try{null!==e&&(J=(0,_.default)(e).readUInt32BE(),f.hudConfig.userConfig.disableSourceMapsResolution?.value||(H=JSON.parse(e),H&&(V=M(await new u.SourceMapConsumer(F(H))))))}catch(e){g.worker_logger.error("Failed to parse source map",{filename:r,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}g.worker_logger.debug("Parsing code",{filename:r});const z=[],G=new S(t,$),Q=G.getRemainingMarksCount(),X=await c.parseAsync(t,C);if(null===X)return g.worker_logger.warning("Failed parsing code to tree",{filename:r,file_path_checksum:A,diskFileChecksum:K,file_checksum:L,functionIds:q}),{declarations:[],blacklist:{file_path_checksum:A,file_checksum:L,uuids:q},generatedAsyncFunctions:[]};g.worker_logger.debug("Parsed code to tree",{filename:r});const Y=[{type:l.EntityType.Program,symbol:{sourcemap_location_hints:[]},context:{},childrenCount:{},siblingIndex:0}],Z=new Set,ee=[];g.worker_logger.debug("Traversing declarations",{filename:r}),n?.postMessage("eventlooptime"),c.traverse(X,{AssignmentExpression:{enter(e){const t=function(e){try{const{node:t}=e,n=t.left;if("MemberExpression"!==n.type)return;const i=n.object;if("Identifier"!==i.type)return;if("globalThis"!==i.name)return;const o=n.property;if("Identifier"!==o.type)return;if(o.name!==f.hudConfig.esbuildFunctionIdVar)return;const r=t.right;if("StringLiteral"!==r.type)return;const s=r.value.split(":");if(2!==s.length)return;return{functionId:j(s[0]),functionHash:s[1]}}catch{return}}(e);t&&(ee[ee.length-1]=t)}},[w.NamespaceScopeAlias]:{enter(e){const{node:t}=e;if(!(0,w.isNamespaceScopeable)(t))return;const n=Y[Y.length-1],i=(0,E.getScope)(e,r,V);if(!i)return;const o=n.childrenCount[i.type]||0,s={...i,childrenCount:{},siblingIndex:o};n.childrenCount[i.type]=o+1,Y.push(s),Z.add(t),e.isFunction()&&ee.push(null)},exit(e){const{node:n}=e;!function(){if(e.isFunction()){const n=ee.pop()??null,i=function(e,t,n,i,o,r,s,a){try{const l=(0,h.getInstrumentedThirdPartyModuleInfo)(n);let u;if(l){if(!function(e,t){const n=(0,d.getFunctionIdentifier)(e);if(!n)return!1;const i=n.name;return t.functions.includes(i)}(e,l))return;u=l.moduleName}const b=P(e);if(!b)throw new Error("Function node has no block start location");const E=e;if(void 0===e.node.start||null===e.node.start||void 0===e.node.end||null===e.node.end)throw new Error("Function node has no start or end location");let w=a?.functionId??null;const C=null===w;null===w&&(w=function(e,t,n,i){const o=i.slice(0,n),r=`${e}_${t}_${Buffer.byteLength(o,"utf8")}`;return p.v5(r,f.hudConfig.functionUuidNamespace).toString()}(t,n,b.start-(o-1),r));const S=a?.functionHash??(c=r.slice(e.node.start,e.node.end),(0,_.default)(c).readUInt32BE().toString());if(!S)return void g.worker_logger.warning("Function hash not found",{functionId:w,filename:n});const F=E.node.async||!1,O=E.node.loc?s(E.node.loc.start,void 0,n):void 0,I=E.node.loc?s(E.node.loc.end,void 0,n):void 0,M=O?.source??n,T=(0,v.getEntityType)(E),j=(0,d.getMethodKind)(E.node),D=(0,d.getContextualData)(E,s),A=(0,k.getParameterInfo)(E,s),{siblingIndex:B,childrenCount:q}=i[i.length-1],N=i.slice(0,-1),$=(0,d.getFunctionIdentifier)(E),R=$?$.loc?[s($.loc.start,$.name,M)]:[]:E.node.loc?[s(E.node.loc.start,void 0,M)]:[],U=R[0]?.name??$?.name,W={name:U,sourcemap_location_hints:R,format:U?"%s":void 0};return W.name&&(W.name=(0,x.getSymbolName)(W)),{module:m.default.parse(M).name,symbol:W,context:D,file:M,type:T,format:y.Format.cjs,parameters:A,async:F,start_line:O?.line??-1,end_line:I?.line??-1,start_column:O?.column??-1,source_code_hash:S,runtime_function_id:w,scope_chain:N,methodKind:j,siblingIndex:B,childrenCount:q,third_party_module:u,original_location:{file:n,start_line:e.node.loc?.start?.line,end_line:e.node.loc?.end?.line,start_column:e.node.loc?.start?.column,end_column:e.node.loc?.end?.column},id_generated:C}}catch(e){g.worker_logger.error("Failed to handle function",{filename:n,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}var c}(e,N,r,Y,$,t,V,n);if(!i)return;if(!R)return void z.push(i);const o=P(e);if(!o)return;G.functionContainsMark(o.start,o.end)&&z.push(i)}}(),Z.has(n)&&(Y.pop(),Z.delete(n))}}}),g.worker_logger.debug("Traversed declarations",{filename:r}),R&&U!==z.length&&g.worker_logger.warning("Marks count mismatch while parsing declarations",{filename:r,marksCount:U,declarationsCount:z.length,remainingMarks:G.getRemainingMarksCount(),initialMarkCount:Q});const{declarations:te,blacklist:ne,generatedAsyncFunctions:ie}=function(e,t,n,i,o,r,s,a,c,l){t=t.map(j);const u=new Set(t),p=new Set(e.map(e=>e.runtime_function_id));let d=[];const f=[],m=[];e.forEach(e=>{u.has(e.runtime_function_id)?d.push({...e,declarations_count:0,bundler_build_id:n,was_bundler_build_id_generated:i,has_input_map:void 0!==o,sourcemap_crc:r,file_path_checksum:s,file_checksum:a}):l&&e.id_generated?e.async&&m.push(e):f.push(e)}),d=d.map(e=>({...e,declarations_count:d.length})),f.length>0&&g.worker_logger.warning("Function IDs mismatch, missing instrumentation",{filename:c,runtimeFunctionIds:t,missingInstrumentation:f});const y=new Set;u.forEach(e=>{p.has(e)||y.add(e)});const h=y.size>0;return h&&g.worker_logger.error("Function IDs mismatch, missing declarations",{filename:c,missingRuntimeFunctionIds:[...y]}),{declarations:d,blacklist:h?{file_path_checksum:s,file_checksum:a,uuids:[...y]}:void 0,generatedAsyncFunctions:m}}(z,q,s,a,H,J,A,L,r,o);return{declarations:te,blacklist:ne,generatedAsyncFunctions:ie}},t.rawFunctionIdToUuidFunctionId=j;const c=s(n(6346)),l=n(8528),u=n(4634),p=s(n(3903)),d=n(9127),f=n(5809),m=a(n(6760)),y=n(8528),h=n(2546),g=n(523),_=a(n(3176)),b=n(2784),v=n(5203),k=n(6864),E=n(1602),x=n(2535),w=n(9011),C={babelrc:!1,configFile:!1};class S{markPositions=[];moduleBase;constructor(e,t){this.moduleBase=t,this.findMarkPositions(e)}findMarkPositions(e){const t=f.hudConfig.nextJsMarkVarName;let n=0,i=e.indexOf(t,n);for(;-1!==i;)this.markPositions.push(i),n=i+t.length,i=e.indexOf(t,n)}functionContainsMark(e,t){const n=e-this.moduleBase,i=t-this.moduleBase;let o=!1,r=0;for(let e=0;e<this.markPositions.length;e++){const t=this.markPositions[e];if(t>=n&&t<=i){o=!0,r=e;break}}return o&&this.markPositions.splice(r,1),o}getRemainingMarksCount(){return this.markPositions.length}}function F(e){let t;return t="string"==typeof e?JSON.parse(e):e,t.sources=t.sources.map(e=>e.replace(/^webpack:\/\/(?:@[^/]+?[/])?[^/]+\//,"")),t}function O(){return(e,t,n)=>({name:t??void 0,line:e.line,column:e.column,source:n??void 0})}function I(e,t){return(n,i,o)=>({name:i??void 0,line:n.line+(e||0),column:n.column+(1===n.line&&t||0),source:o??void 0})}function M(e){return(t,n,i)=>{const o=e.originalPositionFor({line:t.line,column:t.column});return o?{name:o.name??n,line:o.line??-1,column:o.column??-1,source:o.source??i,resolved:!0,server:{name:n,line:t.line,column:t.column,source:i}}:{name:n??void 0,line:t.line,column:t.column,source:i??void 0,resolved:!1}}}function P(e){let t=e.node.body.loc?.start?.index;if(void 0===t)return null;"ArrowFunctionExpression"===e.node.type&&e.node.body.extra?.parenthesized&&e.node.body.extra?.parenStart&&Number.isInteger(e.node.body.extra.parenStart)&&(t=e.node.body.extra.parenStart);const n=e.node.end;return null==n?null:{start:t,end:n}}let T;function j(e){try{return p.stringify(Buffer.from(e+"==","base64"))}catch(t){throw g.worker_logger.error("Failed to convert raw function id to uuid function id",{rawFunctionId:e,error:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0}),t}}}},t={};return function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(6066)})()); //# sourceMappingURL=declarations.js.map