UNPKG

hud-sdk

Version:

Hud's Node SDK

2 lines 31.8 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 o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(global,()=>(()=>{"use strict";var e={523:e=>{e.exports=require("./logger")},1145:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MONGOOSE_QUERY_OPS=t.MONGO_COLLECTION_METHODS=t.CLICKHOUSE_CLIENT_METHODS=t.createOutboundDeclarations=void 0,t.createAxiosDeclaration=a,t.createNodeFetchDeclaration=c,t.createRequestDeclaration=l,t.createPgDeclaration=u,t.createClickHouseDeclaration=d,t.createIoRedisDeclaration=p,t.generateOutboundFunctionId=f,t.createMongoDeclaration=m,t.createMongooseDeclaration=y;const o=n(5809),i=n(8528),r=n(3903),s=n(9850);function a(){return[h("axios","Axios","request",o.hudConfig.axiosFunctionId)]}function c(){return[h("node-fetch","node-fetch","fetch",o.hudConfig.nodeFetchFunctionId),...Object.entries(o.hudConfig.nodeFetchBodiesFunctionIds).map(([e,t])=>h("node-fetch","node-fetch",e,t))]}function l(){return[h("request","request","request",o.hudConfig.requestFunctionId),...Object.entries(o.hudConfig.requestMethodFunctionIds).map(([e,t])=>h("request","request",e,t))]}function u(){return[h("pg","Client","connect",o.hudConfig.pgConnectFunctionId),h("pg","Client","query",o.hudConfig.pgQueryFunctionId),h("pg","Client","end",o.hudConfig.pgEndFunctionId)]}function d(){const e={query:o.hudConfig.clickhouseQueryFunctionId,exec:o.hudConfig.clickhouseExecFunctionId,command:o.hudConfig.clickhouseCommandFunctionId,insert:o.hudConfig.clickhouseInsertFunctionId,close:o.hudConfig.clickhouseCloseFunctionId};return t.CLICKHOUSE_CLIENT_METHODS.map(t=>h("@clickhouse/client","ClickHouseClient",t,e[t]))}function p(e){return e&&0!==e.length?e.map(e=>h("ioredis","Redis",e,f("ioredis",e))):[]}function f(e,t){return(0,o.functionUuidToBase64)((0,r.v5)(`${e}-${t}`,o.hudConfig.functionUuidNamespace))}function m(){return[h("mongodb","MongoClient","connect",f("mongodb","connect")),...t.MONGO_COLLECTION_METHODS.map(e=>h("mongodb","Collection",e,f("mongodb",e)))]}function y(){return[h("mongoose","mongoose","connect",f("mongoose","connect")),h("mongoose","mongoose","createConnection",f("mongoose","createConnection")),...t.MONGOOSE_QUERY_OPS.map(e=>h("mongoose","Query",e,f("mongoose",e))),h("mongoose","Aggregate","aggregate",f("mongoose","aggregate")),h("mongoose","Model","insertMany",f("mongoose","insertMany")),h("mongoose","Model","save",f("mongoose","save"))]}function h(e,t,n,o){return{id_generated:!0,module:e,third_party_module:e,file:`${e}.js`,format:"commonjs",async:!0,runtime_function_id:(0,s.rawFunctionIdToUuidFunctionId)(o),type:i.EntityType.ClassMethod,methodKind:"method",symbol:{sourcemap_location_hints:[{name:n,line:0,column:0,source:`${e}.js`}],name:n,format:"%s"},scope_chain:[{type:i.EntityType.Program,symbol:{sourcemap_location_hints:[]},context:{},childrenCount:{},siblingIndex:0},{type:i.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,"@clickhouse/client":d,ioredis:p,mongodb:m,mongoose:y},t.CLICKHOUSE_CLIENT_METHODS=["query","exec","command","insert","close"],t.MONGO_COLLECTION_METHODS=["findOne","countDocuments","distinct","insertOne","insertMany","updateOne","updateMany","replaceOne","deleteOne","deleteMany","findOneAndUpdate","findOneAndDelete","find","aggregate"],t.MONGOOSE_QUERY_OPS=["find","findOne","count","countDocuments","estimatedDocumentCount","deleteOne","deleteMany","findOneAndDelete","updateOne","updateMany","replaceOne","findOneAndUpdate","findOneAndReplace","distinct"]},1427:e=>{e.exports=require("./nativerequire")},1498:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getDeclarationsBatchRequest=function(e){const t=(new Date).toISOString();return{...i.HudClient.defaultRequest,type:"FunctionDeclaration",arr:e,send_time:t,event_version:o.FUNCTION_DECLARATION_VERSION}};const o=n(8528),i=n(4672)},1602:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getScope=function(e,t,n){const r=(0,o.getEntityType)(e);if(r){const s=(0,o.getEntityIdentity)(e.node),a=(0,i.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,i.getMethodKind)(e.node)}}};const o=n(5203),i=n(9127)},2535:function(e,t,n){var o=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 o=n.map(e=>e.name?.startsWith("#")?e.name?.slice(1):e.name);e.format?Array.from(e.format.matchAll(/%s/g)).length!==o.length?i.worker_logger.warning("Format string does not match number of location hints",{format:e.format,locationHints:o}):t=r.default.format(e.format,...o):t=o.join(".")}return t??""},t.getNodeLocation=function(e,t,n=void 0){const o=e.loc?.start,r=e.loc?.end;if(!o||!r)return i.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:o.line,column:o.column}),a=t({line:r.line,column:r.column});return null!==s.line&&null!==s.column&&null!==a.line&&null!==a.column||(i.worker_logger.debug("Could not find location for function",{filename:n,type:e.type,locStart:o,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 i=n(523),r=o(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 o.types.isFunctionDeclaration(t)?i.EntityType.FunctionDeclaration:o.types.isFunctionExpression(t)?i.EntityType.FunctionExpression:o.types.isArrowFunctionExpression(t)?i.EntityType.FunctionArrow:o.types.isObjectMethod(t)?i.EntityType.ObjectMethod:o.types.isStaticBlock(t)||o.types.isClassMethod(t)?i.EntityType.ClassMethod:o.types.isClassPrivateMethod(t)?i.EntityType.ClassPrivateMethod:o.types.isClassDeclaration(t)?i.EntityType.ClassDeclaration:o.types.isClassExpression(t)?i.EntityType.ClassExpression:o.types.isForInStatement(t)||o.types.isForOfStatement(t)||o.types.isForStatement(t)?i.EntityType.ForLoop:o.types.isBlockStatement(t)?function(e){const t=e.parentPath.node;if(!(o.types.isFunctionDeclaration(t)||o.types.isFunctionExpression(t)||o.types.isArrowFunctionExpression(t)||o.types.isClassMethod(t)||o.types.isObjectMethod(t)||o.types.isClassPrivateMethod(t)))if(o.types.isIfStatement(t)){if("consequent"===e.parentKey)return i.EntityType.IfConsequent;if("alternate"===e.parentKey)return i.EntityType.IfAlternate;if("test"===e.parentKey)return i.EntityType.IfTest}else{if(o.types.isBlockStatement(t)||o.types.isProgram(t))return i.EntityType.Block;if(o.types.isTryStatement(t)){if("block"===e.parentKey)return i.EntityType.Try;if("finalizer"===e.parentKey)return i.EntityType.Finally}else{if(o.types.isCatchClause(t))return;if(o.types.isWhileStatement(t))return"test"===e.parentKey?i.EntityType.WhileTest:i.EntityType.Do;if(o.types.isDoWhileStatement(t))return"test"===e.parentKey?i.EntityType.WhileTest:i.EntityType.Do;if(!(o.types.isForStatement(t)||o.types.isForInStatement(t)||o.types.isForOfStatement(t)))return;if("test"===e.parentKey)return i.EntityType.ForTest;if("body"===e.parentKey)return i.EntityType.ForBlock}}}(e):o.types.isProgram(t)?i.EntityType.Program:o.types.isDoWhileStatement(t)?i.EntityType.DoWhile:o.types.isWhileStatement(t)?i.EntityType.While:o.types.isCatchClause(t)?i.EntityType.Catch:o.types.isObjectExpression(t)?i.EntityType.ObjectExpression:o.types.isWithStatement(t)?i.EntityType.With:o.types.isSwitchStatement(t)?i.EntityType.Switch:o.types.isSwitchCase(t)?i.EntityType.SwitchCase:o.types.isTryStatement(t)?i.EntityType.TryCatch:o.types.isIfStatement(t)?i.EntityType.If:i.EntityType.Other},t.getEntityIdentity=function(e){return o.types.isFunctionDeclaration(e)?o.types.isIdentifier(e.id)?e.id:void r.worker_logger.info("Function declaration without an identifier"):o.types.isClassDeclaration(e)?o.types.isIdentifier(e.id)?e.id:void r.worker_logger.info("Class declaration without an identifier"):o.types.isFunctionExpression(e)||o.types.isClassExpression(e)?o.types.isIdentifier(e.id)?e.id:void 0:o.types.isClassMethod(e)?o.types.isIdentifier(e.key)?e.key:void r.worker_logger.info("Class method without an identifier"):o.types.isObjectMethod(e)?o.types.isIdentifier(e.key)?e.key:void r.worker_logger.info("Object method without an identifier"):o.types.isClassPrivateMethod(e)?o.types.isIdentifier(e.key.id)?e.key.id:void r.worker_logger.info("Class private method without an identifier"):void 0};const o=n(6346),i=n(8528),r=n(523)},5809:e=>{e.exports=require("./config")},6066:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(1498),t),i(n(9850),t),i(n(1145),t),i(n(9127),t)},6346:e=>{e.exports=require("@babel/core")},6760:e=>{e.exports=require("node:path")},6864:function(e,t,n){var o,i=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=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||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),s=0;s<n.length;s++)"default"!==n[s]&&i(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 d(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 d(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,o){const i=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:i,left:t,right:o}}(e,d(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 o=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:o,elements:t}}(e,e.elements.map(e=>d(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 o=a.types.isIdentifier(e.key)&&a.types.isIdentifier(e.value)||a.types.isAssignmentPattern(e.value)?void 0:d(e.key,t);n.push(function(e,t,n,o){const i=e.loc?t(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:i,key:n,value:o}}(e,t,o,d(e.value,t)))}else a.types.isRestElement(e)&&n.push(u(e,t))}),function(e,t,n){const o=e.loc?n(e.loc.start):void 0;return{type:c.ParameterTypes[e.type],sourcemap_location_hint:o,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 o.types.isArrowFunctionExpression(e)||o.types.isBlockStatement(e)||o.types.isCatchClause(e)||o.types.isClassMethod(e)||o.types.isClassPrivateMethod(e)||o.types.isDeclareModule(e)||o.types.isDoExpression(e)||o.types.isDoWhileStatement(e)||o.types.isForInStatement(e)||o.types.isForOfStatement(e)||o.types.isForStatement(e)||o.types.isFunctionDeclaration(e)||o.types.isFunctionExpression(e)||o.types.isIfStatement(e)||o.types.isLabeledStatement(e)||o.types.isObjectMethod(e)||o.types.isProgram(e)||o.types.isStaticBlock(e)||o.types.isSwitchCase(e)||o.types.isTSModuleBlock(e)||o.types.isTryStatement(e)||o.types.isWhileStatement(e)||o.types.isWithStatement(e)||o.types.isClassDeclaration(e)||o.types.isClassExpression(e)||o.types.isObjectExpression(e)||o.types.isSwitchStatement(e)},t.isNamespaceScopeable=function(e){return o.types.isFunction(e)||o.types.isClass(e)||o.types.isObjectExpression(e)};const o=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 o,i=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=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||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),s=0;s<n.length;s++)"default"!==n[s]&&i(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,o;(e.isFunctionExpression()||e.isArrowFunctionExpression()||e.isClassExpression())&&(n=function(e,t){const n=e.parentPath;if(n.isCallExpression())for(const[o,i]of n.node.arguments.entries())if(i===e.node){const i=n.node.callee;let r;try{r=m(i,t)}catch(t){if(!(t instanceof u.HudUnsupportedError))throw t;{const n=`${i.type}-${e.node.type}`;b.has(n)||(d.worker_logger.warning("could not get callee symbol recursively",{error:t,errorMessage:t.message,calleType:i.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:o}}}(e,t)),(e.isFunctionExpression()||e.isArrowFunctionExpression())&&(o=function(e){const t=e.parentPath;return!!t.isCallExpression()&&t.node.callee===e.node}(e));const i=h(e,t);return i&&(i.name=(0,p.getSymbolName)(i)),{symbol:i,callback:n,immediatelyInvoked:o}},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),d=n(523),p=n(2535);function f(e,t,n){const o=e.loc?n(e.loc.start,t,e.loc.filename):void 0;return{name:o?.name??t,sourcemap_location_hints:o?[o]:[],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 o=m(e.property,t),i=e.computed?n.name+"["+o.name+"]":n.name+"."+o.name,r=n.format??"%s",s=o.format??"%s",a=e.computed?`${r}[${s}]`:`${r}.${s}`;return{name:i,sourcemap_location_hints:[...n.sourcemap_location_hints,...o.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)||(d.worker_logger.warning("getContextSymbol: Unsupported parent node type",{parentType:e.parentPath?.node.type,error:t,errorMessage:t.message}),y.add(n)))}throw t}d.worker_logger.debug("getContextSymbol; Unsupported node type",{type:n.type})}function g(e,t){const n=[];return e.arguments.forEach((e,o)=>{let i,r;if(c.types.isStringLiteral(e)?(i=l.ArgumentTypes.StringLiteral,r=e.value):c.types.isTemplateLiteral(e)?(i=l.ArgumentTypes.TemplateString,r=function(e){let t="";const n=e.quasis,o=e.expressions;for(let e=0;e<n.length;e++)t+=n[e].value.cooked,e<o.length&&(t+=`\${${_(o[e])}}`);return t=`\`${t}\``,t}(e)):c.types.isIdentifier(e)&&(i=l.ArgumentTypes.Identifier,r=e.name),i&&r){const s=c.types.isIdentifier(e)?e.name:void 0,a=e.loc?t(e.loc.start,s):void 0;n.push({index:o,type:i,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 o,i=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=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||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),s=0;s<n.length;s++)"default"!==n[s]&&i(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=I,t.getRealPositionNothingFunc=M,t.getRealPositionOffsetsFunc=F,t.getRealPositionSourceMapFunc=T,t.parseDeclarations=async function(e,t,n=null,o,i=!1){const{filename:r,bundlerBuildId:s,bundlerBuildIdGenerated:a,lineOffset:_,columnOffset:M,file_path_checksum:A,file_checksum:B,functionIds:L,sourceCodeHash:U,moduleBase:R,isNextJsApp:$,marksCount:H,prebundle_file_checksum:K}=e,W=K??B,G=o?N(o):void 0;g.worker_logger.debug("Parsing code",{filename:r});const J={declarations:[],blacklist:{file_path_checksum:A,file_checksum:W,uuids:L},generatedAsyncFunctions:[]};if([".ts",".mts",".cts",".tsx"].some(e=>r.endsWith(e))){if(!o)return g.worker_logger.error("ts file found but no ts-node config available",{filename:r}),J;const e=j(t,r,G);if(!e)return J;const n=D(e);if(n!==B)return g.worker_logger.warning("File checksum mismatch",{filename:r,file_path_checksum:A,compiledChecksum:n,file_checksum:B,functionIds:L,transpileOnly:o?.transpileOnly}),J;t=e}else{const e=D(t);if(e!==B){let n=!1;if(o?.allowJs){const e=j(t,r,G);if(!e)return J;D(e)===B&&(n=!0,t=e)}if(!n)return g.worker_logger.warning("File checksum mismatch",{filename:r,file_path_checksum:A,diskFileChecksum:e,file_checksum:B,functionIds:L,transpileOnly:o?.transpileOnly}),J}}let Q,V,z=(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))z=F(_,M);else{const e=(0,v.getSourceMap)(r,t);try{null!==e&&(V=(0,b.default)(e).readUInt32BE(),f.hudConfig.userConfig.disableSourceMapsResolution?.value||(Q=JSON.parse(e),Q&&(z=T(await new u.SourceMapConsumer(I(Q))))))}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 Y=[],X=new w(t,R),Z=X.getRemainingMarksCount(),ee=await c.parseAsync(t,S);if(null===ee)return g.worker_logger.warning("Failed parsing code to tree",{filename:r,file_path_checksum:A,file_checksum:W,functionIds:L}),{declarations:[],blacklist:{file_path_checksum:A,file_checksum:W,uuids:L},generatedAsyncFunctions:[]};g.worker_logger.debug("Parsed code to tree",{filename:r});const te=[{type:l.EntityType.Program,symbol:{sourcemap_location_hints:[]},context:{},childrenCount:{},siblingIndex:0}],ne=new Set,oe=[];g.worker_logger.debug("Traversing declarations",{filename:r}),n?.postMessage("eventlooptime"),c.traverse(ee,{AssignmentExpression:{enter(e){const t=function(e){try{const{node:t}=e,n=t.left;if("MemberExpression"!==n.type)return;const o=n.object;if("Identifier"!==o.type)return;if("globalThis"!==o.name)return;const i=n.property;if("Identifier"!==i.type)return;if(i.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:q(s[0]),functionHash:s[1]}}catch{return}}(e);t&&(oe[oe.length-1]=t)}},[x.NamespaceScopeAlias]:{enter(e){const{node:t}=e;if(!(0,x.isNamespaceScopeable)(t))return;const n=te[te.length-1],o=(0,C.getScope)(e,r,z);if(!o)return;const i=n.childrenCount[o.type]||0,s={...o,childrenCount:{},siblingIndex:i};n.childrenCount[o.type]=i+1,te.push(s),ne.add(t),e.isFunction()&&oe.push(null)},exit(e){const{node:n}=e;!function(){if(e.isFunction()){const n=oe.pop()??null,o=function(e,t,n,o,i,r,s,a){try{const l=(0,h.getInstrumentedThirdPartyModuleInfo)(n);let u;if(l){if(!function(e,t){const n=(0,p.getFunctionIdentifier)(e);if(!n)return!1;const o=n.name;return t.functions.includes(o)}(e,l))return;u=l.moduleName}if(!1===f.hudConfig.userConfig.instrumentOneLiners?.value&&function(e){const t=e.node;if("ArrowFunctionExpression"!==t.type)return!1;if(t.async||t.generator)return!1;if("BlockStatement"!==t.body.type)return!0;const n=t.body;return 1===n.body.length&&"ReturnStatement"===n.body[0].type}(e))return;const _=P(e);if(!_)throw new Error("Function node has no block start location");const v=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 C=a?.functionId??null;const x=null===C;if(null===C){C=function(e,t,n){const o=`${e}_${t}_${n}`;return d.v5(o,f.hudConfig.functionUuidNamespace).toString()}(t,n,Buffer.byteLength(r.slice(0,_.start),"utf8")-(i-1))}const S=a?.functionHash??(c=r.slice(e.node.start,e.node.end),(0,b.default)(c).readUInt32BE().toString());if(!S)return void g.worker_logger.warning("Function hash not found",{functionId:C,filename:n});const w=v.node.async||!1,I=v.node.loc?s(v.node.loc.start,void 0,n):void 0,M=v.node.loc?s(v.node.loc.end,void 0,n):void 0,F=I?.source??n,T=(0,O.getEntityType)(v),j=(0,p.getMethodKind)(v.node),D=(0,p.getContextualData)(v,s),A=(0,E.getParameterInfo)(v,s),{siblingIndex:N,childrenCount:q}=o[o.length-1],B=o.slice(0,-1),L=(0,p.getFunctionIdentifier)(v),U=L?L.loc?[s(L.loc.start,L.name,F)]:[]:v.node.loc?[s(v.node.loc.start,void 0,F)]:[],R=U[0]?.name??L?.name,$={name:R,sourcemap_location_hints:U,format:R?"%s":void 0};return $.name&&($.name=(0,k.getSymbolName)($)),{module:m.default.parse(F).name,symbol:$,context:D,file:F,type:T,format:y.Format.cjs,parameters:A,async:w,start_line:I?.line??-1,end_line:M?.line??-1,start_column:I?.column??-1,source_code_hash:S,runtime_function_id:C,scope_chain:B,methodKind:j,siblingIndex:N,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:x}}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,U,r,te,R,t,z,n);if(!o)return;if(!$)return void Y.push(o);const i=P(e);if(!i)return;X.functionContainsMark(i.start,i.end)&&Y.push(o)}}(),ne.has(n)&&(te.pop(),ne.delete(n))}}}),g.worker_logger.debug("Traversed declarations",{filename:r}),$&&H!==Y.length&&g.worker_logger.warning("Marks count mismatch while parsing declarations",{filename:r,marksCount:H,declarationsCount:Y.length,remainingMarks:X.getRemainingMarksCount(),initialMarkCount:Z});const{declarations:ie,blacklist:re,generatedAsyncFunctions:se}=function(e,t,n,o,i,r,s,a,c,l){t=t.map(q);const u=new Set(t),d=new Set(e.map(e=>e.runtime_function_id));let p=[];const f=[],m=[];e.forEach(e=>{u.has(e.runtime_function_id)?p.push({...e,declarations_count:0,bundler_build_id:n,was_bundler_build_id_generated:o,has_input_map:void 0!==i,sourcemap_crc:r,file_path_checksum:s,file_checksum:a}):l&&e.id_generated?e.async&&m.push(e):f.push(e)}),p=p.map(e=>({...e,declarations_count:p.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=>{d.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:p,blacklist:h?{file_path_checksum:s,file_checksum:a,uuids:[...y]}:void 0,generatedAsyncFunctions:m}}(Y,L,s,a,Q,V,A,W,r,i);return{declarations:ie,blacklist:re,generatedAsyncFunctions:se}},t.rawFunctionIdToUuidFunctionId=q;const c=s(n(6346)),l=n(8528),u=n(4634),d=s(n(3903)),p=n(9127),f=n(5809),m=a(n(6760)),y=n(8528),h=n(2546),g=n(523),_=n(1427),b=a(n(3176)),v=n(2784),O=n(5203),E=n(6864),C=n(1602),k=n(2535),x=n(9011),S={babelrc:!1,configFile:!1};class w{markPositions=[];moduleBase;constructor(e,t){this.moduleBase=t,this.findMarkPositions(e)}findMarkPositions(e){const t=f.hudConfig.nextJsMarkVarName;let n=0,o=e.indexOf(t,n);for(;-1!==o;)this.markPositions.push(o),n=o+t.length,o=e.indexOf(t,n)}functionContainsMark(e,t){const n=e-this.moduleBase,o=t-this.moduleBase;let i=!1,r=0;for(let e=0;e<this.markPositions.length;e++){const t=this.markPositions[e];if(t>=n&&t<=o){i=!0,r=e;break}}return i&&this.markPositions.splice(r,1),i}getRemainingMarksCount(){return this.markPositions.length}}function I(e){let t;return t="string"==typeof e?JSON.parse(e):e,t.sources=t.sources.map(e=>e.replace(/^webpack:\/\/(?:@[^/]+?[/])?[^/]+\//,"")),t}function M(){return(e,t,n)=>({name:t??void 0,line:e.line,column:e.column,source:n??void 0})}function F(e,t){return(n,o,i)=>({name:o??void 0,line:n.line+(e||0),column:n.column+(1===n.line&&t||0),source:i??void 0})}function T(e){return(t,n,o)=>{const i=e.originalPositionFor({line:t.line,column:t.column});return i?{name:i.name??n,line:i.line??-1,column:i.column??-1,source:i.source??o,resolved:!0,server:{name:n,line:t.line,column:t.column,source:o}}:{name:n??void 0,line:t.line,column:t.column,source:o??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}}function j(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})}}function D(e){return(0,b.default)(e).readUInt32BE()}let A;function N(e){if(!A){const t=(0,_.myRequire)("ts-node");A=t.create({...e,transpileOnly:!0,typeCheck:!1})}return A}function q(e){try{return d.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(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,n),r.exports}(6066)})()); //# sourceMappingURL=declarations.js.map