hud-sdk
Version:
Hud's Node SDK
2 lines • 28.9 kB
JavaScript
!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=s,t.createNodeFetchDeclaration=a,t.createRequestDeclaration=c,t.createPgDeclaration=l;const i=n(5809),o=n(8528),r=n(9850);function s(){return[u("axios","Axios","request",i.hudConfig.axiosFunctionId)]}function a(){return[u("node-fetch","node-fetch","fetch",i.hudConfig.nodeFetchFunctionId),...Object.entries(i.hudConfig.nodeFetchBodiesFunctionIds).map(([e,t])=>u("node-fetch","node-fetch",e,t))]}function c(){return[u("request","request","request",i.hudConfig.requestFunctionId),...Object.entries(i.hudConfig.requestMethodFunctionIds).map(([e,t])=>u("request","request",e,t))]}function l(){return[u("pg","Client","connect",i.hudConfig.pgConnectFunctionId),u("pg","Client","query",i.hudConfig.pgQueryFunctionId),u("pg","Client","end",i.hudConfig.pgEndFunctionId)]}function u(e,t,n,i){return{module:e,third_party_module:e,file:`${e}.js`,format:"commonjs",async:!0,runtime_function_id:(0,r.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:s,"node-fetch":a,request:c,pg:l}},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")},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(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=g,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=y(o,t)}catch(t){if(!(t instanceof u.HudUnsupportedError))throw t;{const n=`${o.type}-${e.node.type}`;v.has(n)||(p.worker_logger.warning("could not get callee symbol recursively",{error:t,errorMessage:t.message,calleType:o.type,nodeType:e.node.type}),v.add(n))}}const s=_(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=g(e,t);return o&&(o.name=(0,f.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(9772),f=n(2535);function m(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 y(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)]:[]}:y(e.object,t);const i=y(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 y(e.callee,t);if(c.types.isSequenceExpression(e))return(0,d.isHudAwaitSequence)(e)?y((0,d.getHudAwaitSequenceElement)(e),t):y(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 h=new Set;function g(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 m(n,n.id.name,t);if(c.types.isObjectProperty(n)&&c.types.isIdentifier(n.key))return m(n,n.key.name,t);if(c.types.isClassProperty(n)&&c.types.isIdentifier(n.key))return m(n,n.key.name,t);if(c.types.isAssignmentExpression(n))return y(n.left,t);if(c.types.isAssignmentPattern(n))return y(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(h.has(n)||(p.worker_logger.warning("getContextSymbol: Unsupported parent node type",{parentType:e.parentPath?.node.type,error:t,errorMessage:t.message}),h.add(n)))}throw t}p.worker_logger.debug("getContextSymbol; Unsupported node type",{type:n.type})}function _(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+=`\${${b(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 b(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 v=new Set},9772:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isHudAwaitSequence=function(e){if(e.expressions.length<2)return!1;const t=e.expressions[e.expressions.length-1];return!!i.types.isIdentifier(t)&&!!t.name.startsWith(o.hudConfig.wrapVarPrefix)},t.getHudAwaitSequenceElement=function(e){const t=e.expressions[0];if(!i.types.isAssignmentExpression(t))throw new r.HudUnsupportedError("Expected assignment expression");const{left:n,right:s}=t;if(!i.types.isIdentifier(n)||!n.name.startsWith(o.hudConfig.wrapVarPrefix))throw new r.HudUnsupportedError("Expected identifier starting with "+o.hudConfig.wrapVarPrefix);return s};const i=n(6346),o=n(5809),r=n(2546)},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=O,t.getRealPositionNothingFunc=F,t.getRealPositionOffsetsFunc=P,t.getRealPositionSourceMapFunc=I,t.parseDeclarations=async function(e,t,n=null,i){const{filename:o,bundlerBuildId:r,bundlerBuildIdGenerated:s,lineOffset:a,columnOffset:F,file_path_checksum:D,file_checksum:A,functionIds:q,sourceCodeHash:B,moduleBase:N,isNextJsApp:$,marksCount:W}=e;if(g.worker_logger.debug("Parsing code",{filename:o}),i)try{if(!j){const e=(0,h.myRequire)("ts-node");j=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,o,j);if(!e)return{declarations:[],blacklist:{file_path_checksum:D,file_checksum:A,uuids:q}};t=e}catch(e){return g.worker_logger.error("Failed to require and compile ts file",{filename:o,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0}),{declarations:[],blacklist:{file_path_checksum:D,file_checksum:A,uuids:q}}}else if(o.endsWith(".ts")||o.endsWith(".mts"))return g.worker_logger.error("ts file pass, but not found ts-options"),{declarations:[],blacklist:{file_path_checksum:D,file_checksum:A,uuids:q}};const U=(0,_.default)(t).readUInt32BE();if(U!==A)return g.worker_logger.warning("File checksum mismatch",{filename:o,file_path_checksum:D,diskFileChecksum:U,file_checksum:A,functionIds:q}),{declarations:[],blacklist:{file_path_checksum:D,file_checksum:A,uuids:q}};let L,K,H=(e,t,n)=>({name:t??void 0,line:e.line,column:e.column,source:n??void 0});if(a&&F)H=P(a,F);else{const e=(0,b.getSourceMap)(o,t);try{null!==e&&(K=(0,_.default)(e).readUInt32BE(),f.hudConfig.userConfig.disableSourceMapsResolution?.value||(L=JSON.parse(e),L&&(H=I(await new u.SourceMapConsumer(O(L))))))}catch(e){g.worker_logger.error("Failed to parse source map",{filename:o,error:e instanceof Error?e.message:void 0,stack:e instanceof Error?e.stack:void 0})}}g.worker_logger.debug("Parsing code",{filename:o});const R=[],J=new S(t,N),V=J.getRemainingMarksCount(),z=await c.parseAsync(t,C);if(null===z)return g.worker_logger.warning("Failed parsing code to tree",{filename:o,file_path_checksum:D,diskFileChecksum:U,file_checksum:A,functionIds:q}),{declarations:[],blacklist:{file_path_checksum:D,file_checksum:A,uuids:q}};g.worker_logger.debug("Parsed code to tree",{filename:o});const G=[{type:l.EntityType.Program,symbol:{sourcemap_location_hints:[]},context:{},childrenCount:{},siblingIndex:0}],Q=new Set;g.worker_logger.debug("Traversing declarations",{filename:o}),n?.postMessage("eventlooptime"),c.traverse(z,{[w.NamespaceScopeAlias]:{enter(e){const{node:t}=e;if(!(0,w.isNamespaceScopeable)(t))return;const n=G[G.length-1],i=(0,E.getScope)(e,o,H);if(!i)return;const r=n.childrenCount[i.type]||0,s={...i,childrenCount:{},siblingIndex:r};n.childrenCount[i.type]=r+1,G.push(s),Q.add(t)},exit(e){const{node:n}=e;if(e.isFunction()){const n=function(e,t,n,i,o,r,s){try{const c=(0,h.getInstrumentedThirdPartyModuleInfo)(n);let l;if(c){if(!function(e,t){const n=(0,d.getFunctionIdentifier)(e);if(!n)return!1;const i=n.name;return t.functions.includes(i)}(e,c))return;l=c.moduleName}const u=M(e);if(!u)throw new Error("Function node has no block start location");const b=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");const E=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,u.start-(o-1),r),w=(a=r.slice(e.node.start,e.node.end),(0,_.default)(a).readUInt32BE().toString());if(!w)return void g.worker_logger.warning("Function hash not found",{functionID:E,filename:n});const C=b.node.async||!1,S=b.node.loc?s(b.node.loc.start,void 0,n):void 0,O=b.node.loc?s(b.node.loc.end,void 0,n):void 0,F=S?.source??n,P=(0,v.getEntityType)(b),I=(0,d.getMethodKind)(b.node),j=(0,d.getContextualData)(b,s),T=(0,k.getParameterInfo)(b,s),{siblingIndex:D,childrenCount:A}=i[i.length-1],q=i.slice(0,-1),B=(0,d.getFunctionIdentifier)(b),N=B?B.loc?[s(B.loc.start,B.name,F)]:[]:b.node.loc?[s(b.node.loc.start,void 0,F)]:[],$=N[0]?.name??B?.name,W={name:$,sourcemap_location_hints:N,format:$?"%s":void 0};return W.name&&(W.name=(0,x.getSymbolName)(W)),{module:m.default.parse(F).name,symbol:W,context:j,file:F,type:P,format:y.Format.cjs,parameters:T,async:C,start_line:S?.line??-1,end_line:O?.line??-1,start_column:S?.column??-1,source_code_hash:w,runtime_function_id:E,scope_chain:q,methodKind:I,siblingIndex:D,childrenCount:A,third_party_module:l,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}}}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 a}(e,B,o,G,N,t,H);if(n)if($){const t=M(e);t&&J.functionContainsMark(t.start,t.end)&&R.push(n)}else R.push(n)}Q.has(n)&&(G.pop(),Q.delete(n))}}}),g.worker_logger.debug("Traversed declarations",{filename:o}),$&&W!==R.length&&g.worker_logger.warning("Marks count mismatch while parsing declarations",{filename:o,marksCount:W,declarationsCount:R.length,remainingMarks:J.getRemainingMarksCount(),initialMarkCount:V});const{declarations:X,blacklist:Y}=function(e,t,n,i,o,r,s,a,c){t=t.map(T);const l=new Set(t),u=new Set(e.map(e=>e.runtime_function_id));let p=[];const d=[];e.forEach(e=>{l.has(e.runtime_function_id)?p.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}):d.push(e)}),p=p.map(e=>({...e,declarations_count:p.length})),d.length>0&&g.worker_logger.warning("Function IDs mismatch, missing instrumentation",{filename:c,runtimeFunctionIds:t});const f=new Set;l.forEach(e=>{u.has(e)||f.add(e)});const m=f.size>0;return m&&g.worker_logger.error("Function IDs mismatch, missing declarations",{filename:c,missingRuntimeFunctionIds:[...f]}),{declarations:p,blacklist:m?{file_path_checksum:s,file_checksum:a,uuids:[...f]}:void 0}}(R,q,r,s,L,K,D,A,o);return{declarations:X,blacklist:Y}},t.rawFunctionIdToUuidFunctionId=T;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 O(e){let t;return t="string"==typeof e?JSON.parse(e):e,t.sources=t.sources.map(e=>e.replace(/^webpack:\/\/(?:@[^/]+?[/])?[^/]+\//,"")),t}function F(){return(e,t,n)=>({name:t??void 0,line:e.line,column:e.column,source:n??void 0})}function P(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 I(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 M(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 j;function T(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