"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let s of __getOwnPropNames(t))__hasOwnProp.call(e,s)||s===o||__defProp(e,s,{get:()=>t[s],enumerable:!(r=__getOwnPropDesc(t,s))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),socketConnection_exports={};__export(socketConnection_exports,{SocketConnection:()=>SocketConnection,compareSemver:()=>compareSemver}),module.exports=__toCommonJS(socketConnection_exports);class SocketConnection{constructor(e){this._pendingBuffers=[],this._socket=e,e.on("data",e=>this._onData(e)),e.on("close",()=>{this.onclose?.()}),e.on("error",e=>console.error(`error: ${e.message}`))}async send(e){await new Promise((t,o)=>{this._socket.write(`${JSON.stringify(e)}
`,e=>{e?o(e):t(void 0)})})}close(){this._socket.destroy()}_onData(e){let t=e.indexOf("\n");if(-1===t)return void this._pendingBuffers.push(e);this._pendingBuffers.push(e.slice(0,t));let o=Buffer.concat(this._pendingBuffers).toString();this._dispatchMessage(o);let r=t+1;for(t=e.indexOf("\n",r);-1!==t;){let o=e.toString(void 0,r,t);this._dispatchMessage(o),r=t+1,t=e.indexOf("\n",r)}this._pendingBuffers=[e.slice(r)]}_dispatchMessage(e){try{this.onmessage?.(JSON.parse(e))}catch(e){console.error("failed to dispatch message",e)}}}function compareSemver(e,t){let o=e.replace(/-.*$/,""),r=t.replace(/-.*$/,""),s=o.split(".").map(Number),n=r.split(".").map(Number);for(let e=0;e<3;e++){if(s[e]>n[e])return 1;if(s[e]<n[e])return -1}let i=parseSuffixTimestamp(e),p=parseSuffixTimestamp(t);return i>p?1:i<p?-1:0}function parseSuffixTimestamp(e){let t=e.match(/^\d+\.\d+\.\d+-(?:alpha|beta)-(.+)$/);if(!t)return 1/0;let o=t[1];return/^\d{4}-\d{2}-\d{2}$/.test(o)?new Date(o).getTime():Number(o)}