insite-ws 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var H=Object.defineProperty;var D=r=>{throw TypeError(r)};var K=(r,o,e)=>o in r?H(r,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[o]=e;var c=(r,o,e)=>K(r,typeof o!="symbol"?o+"":o,e),F=(r,o,e)=>o.has(r)||D("Cannot "+e);var n=(r,o,e)=>(F(r,o,"read from private field"),e?e.call(r):o.get(r)),p=(r,o,e)=>o.has(r)?D("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(r):o.set(r,e),q=(r,o,e,t)=>(F(r,o,"write to private field"),t?t.call(r,e):o.set(r,e),e);import z from"eventemitter3";function m(){}function B(r,o=0,e={}){let{leading:t=!1,trailing:s=!0}=e,{maxWait:l=1/0}=e,i,f,u,d,a,P,x,N,C=async()=>{let w=Date.now();w>=u?(i=void 0,u=void 0,clearTimeout(f),typeof x=="function"&&await x(),h.resolve(N),h.promise.isResolved=!0,P=t):(clearTimeout(i),i=setTimeout(C,u-w))},_=Number.isFinite(l)?()=>{x===S&&(x=!1),S(),f=setTimeout(_,l)}:null;async function S(){return N=await r.apply(d,a)}t&&typeof t=="boolean"&&(t=S),P=t,s&&typeof s=="boolean"&&(s=S),x=s;let h=Object.assign(function(...w){return a=w,d=this,u=Date.now()+o,x=s,h.promise.isResolved&&(h.promise=Object.assign(new Promise(J=>{h.resolve=J,typeof P=="function"&&(P(),P=!1,x===S&&(x=!1)),i||(i=setTimeout(C,o),_&&(f=setTimeout(_,l)))}),{isResolved:!1})),h.promise},{callback:r,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:m,run:S,clear:async w=>{clearTimeout(i),i=void 0,clearTimeout(f),h.promise.isResolved=!0,h.resolve(w?await S():N)}});return h}B.noop=Object.assign(()=>{},{callback:m,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:m,run:m,clear:m});function U(r,o,e,t,s=!0){return Array.isArray(r)&&(r=r.length),typeof t!="string"&&(s=t??!0,t=e),(s?`${r}\xA0`:"")+U.raw(r,o,e,t)}U.raw=(r,o,e,t=e)=>{r=Math.abs(r);let s=r%10,l=r%100;return s===1&&l!==11?o:s>=2&&s<=4&&!(l>=12&&l<=15)?e:t};var T=new WeakMap,L=class extends Promise{constructor(e){let t,s;super((l,i)=>{t=l,s=i});c(this,"isPending",!0);c(this,"isFulfilled",!1);c(this,"isRejected",!1);c(this,"state","pending");c(this,"result");c(this,"resolve",e=>{if(this.isPending){this.isPending=!1,this.isFulfilled=!0,this.state="fulfilled",this.result=e;let t=T.get(this);t&&(t.resolve.call(this,e),T.delete(this))}});c(this,"reject",e=>{if(this.isPending){this.isPending=!1,this.isRejected=!0,this.state="rejected",this.result=e;let t=T.get(this);t&&(t.reject.call(this,e),T.delete(this))}});T.set(this,{resolve:t,reject:s}),e?.(this.resolve,this.reject)}};function V(r="",o=""){return`${r}${Date.now().toString(36)}${Math.round(Math.random()*Number.MAX_SAFE_INTEGER).toString(36)}${o}`}var y={request:"~r-q",response:"~r-s"};var Y=0,b,k,g,R,A,O,$,j,v,M,E,W,I=class I extends z{constructor(e={}){super();c(this,"isWebSocket",!0);c(this,"isWebSocketServer",!1);c(this,"isWebSocketServerClient",!1);c(this,"url");c(this,"name");c(this,"protocols");c(this,"reconnectAfter");p(this,b);c(this,"isUsed",!1);c(this,"isAutoReconnecting",!1);c(this,"webSocket",null);p(this,k,B(I.defib,65e3));p(this,g);p(this,R,()=>{n(this,g).resolve(),this.emit("open"),n(this,k).call(this)});p(this,A,({data:e})=>{if(n(this,k).call(this),e)try{let[t,...s]=JSON.parse(e);this.emit("message",t,...s),this.emit(`message:${t}`,...s)}catch(t){n(this,O).call(this,t)}else this.webSocket.send("")});p(this,O,e=>{e instanceof Event&&(e=void 0),n(this,g).isPending&&n(this,g).reject(e),this.emit("error",e)});p(this,$);p(this,j,e=>{process.env.NODE_ENV==="development"&&!n(this,b)&&console.info(`\u{1F50C} WS ${this.name} is closed ${e.code?`with code ${e.code}`:""} ${e.code&&e.reason?"and ":""}${e.reason?`reason "${e.reason}"`:""}`),n(this,k).clear();let t=this.webSocket;t.removeEventListener("open",n(this,R)),t.removeEventListener("message",n(this,A)),t.removeEventListener("error",n(this,O)),t.removeEventListener("close",n(this,j)),delete this.send,this.emit("close",e),this.webSocket=null,this.reconnectAfter&&![1002,3500,4e3].includes(e.code)&&(process.env.NODE_ENV==="development"&&!n(this,b)&&console.info(`\u{1F50C} WS ${this.name} will try to reconnect in 2 seconds`),q(this,$,setTimeout(()=>this.open().catch(m),this.reconnectAfter)))});c(this,"connect",this.open);c(this,"disconnect",this.close);p(this,v,[]);p(this,M,()=>{for(let e of n(this,v))this.webSocket.send(e);n(this,v).length=0});p(this,E,new Map);c(this,"onRequest",this.addRequestListener);c(this,"offRequest",this.removeRequestListener);p(this,W,async(e,t,...s)=>{let l=n(this,E).get(t),i,f=null;if(l)try{i=await l.apply(this,s)}catch(u){if(u instanceof Error){let{message:d,...a}=u;f={message:d,...a}}}else f={message:`Unknown request kind "${t}"`};this.sendMessage(`${y.response}-${e}`,f,i)});let{url:t=globalThis.__insite?.wss_url??"/",name:s=(Y++).toString(),protocols:l,immediately:i=!0,reconnectAfter:f=2e3,on:u,quiet:d=!1}=e;if(this.url=t,this.name=s,this.protocols=l,this.reconnectAfter=f,this.on(`message:${y.request}`,n(this,W)),u)for(let a in u)u[a]&&this.on(a,u[a]);q(this,b,d),this.url&&i&&this.open().catch(m),this.on("error",a=>a&&console.error("\u{1F50C}\u2757\uFE0F WS",`${this.name}:`,a))}get isConnecting(){return this.webSocket?this.webSocket.readyState===WebSocket.CONNECTING:null}get isOpen(){return this.webSocket?this.webSocket.readyState===WebSocket.OPEN:null}get isClosing(){return this.webSocket?this.webSocket.readyState===WebSocket.CLOSING:null}get isClosed(){return!this.webSocket||this.webSocket.readyState===WebSocket.CLOSED}async open(e={}){clearTimeout(n(this,$)),this.isUsed=!0,this.isAutoReconnecting=!!this.reconnectAfter,await this.close(4e3,"reopen");let t;return e.url&&this.url!==e.url&&(t=this.url,this.url=e.url),e.protocols&&(this.protocols=e.protocols),q(this,g,new L((s,l)=>{if(this.url){let i=new WebSocket(this.url,this.protocols);i.addEventListener("open",n(this,R)),i.addEventListener("message",n(this,A)),i.addEventListener("error",n(this,O)),i.addEventListener("close",n(this,j),{once:!0}),this.send=i.send.bind(i),this.webSocket=i,t&&this.emit("server-change",this.url,t),this.emit("connecting")}else this.webSocket=null,delete this.send,l(new Error("url prop is not set"))})),n(this,g)}close(e=3500,t="manual"){return clearTimeout(n(this,$)),t==="manual"&&(this.isAutoReconnecting=!1),new Promise(s=>{this.isConnecting||this.isOpen?(this.webSocket.addEventListener("close",()=>s(),{once:!0}),this.webSocket.close(e,t)):s()})}sendMessage(...e){let t=JSON.stringify(e);this.isOpen?this.webSocket.send(t):(n(this,v).length||this.once("open",n(this,M)),n(this,v).push(t))}sendRequest(...e){let t=V(),s=`message:${y.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(s,e.splice(-1,1)[0]),this.sendMessage(y.request,t,...e),this):new Promise((l,i)=>{this.once(s,(f,u)=>{if(f){let{message:d,...a}=f;i(Object.assign(new Error(d),a))}else l(u)}),this.sendMessage(y.request,t,...e)})}addRequestListener(e,t){return n(this,E).set(e,t),this}removeRequestListener(e){return n(this,E).delete(e),this}static defib(){this.isOpen&&(process.env.NODE_ENV==="development"&&!n(this,b)&&console.info(`\u{1F50C} WS ${this.name} has no heartbeat, going offline`),this.webSocket.close())}};b=new WeakMap,k=new WeakMap,g=new WeakMap,R=new WeakMap,A=new WeakMap,O=new WeakMap,$=new WeakMap,j=new WeakMap,v=new WeakMap,M=new WeakMap,E=new WeakMap,W=new WeakMap;var G=I;export{G as WS};
1
+ var H=Object.defineProperty;var D=o=>{throw TypeError(o)};var K=(o,r,e)=>r in o?H(o,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[r]=e;var c=(o,r,e)=>K(o,typeof r!="symbol"?r+"":r,e),F=(o,r,e)=>r.has(o)||D("Cannot "+e);var n=(o,r,e)=>(F(o,r,"read from private field"),e?e.call(o):r.get(o)),p=(o,r,e)=>r.has(o)?D("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(o):r.set(o,e),A=(o,r,e,t)=>(F(o,r,"write to private field"),t?t.call(o,e):r.set(o,e),e);import z from"eventemitter3";function h(){}function _(o,r=0,e={}){let{leading:t=!1,trailing:s=!0}=e,{maxWait:l=1/0}=e,i,f,u,d,a,R,x,I,B=async()=>{let b=Date.now();b>=u?(i=void 0,u=void 0,clearTimeout(f),typeof x=="function"&&await x(),m.resolve(I),m.promise.isResolved=!0,R=t):(clearTimeout(i),i=setTimeout(B,u-b))},N=Number.isFinite(l)?()=>{x===S&&(x=!1),S(),f=setTimeout(N,l)}:null;async function S(){return I=await o.apply(d,a)}t&&typeof t=="boolean"&&(t=S),R=t,s&&typeof s=="boolean"&&(s=S),x=s;let m=Object.assign(function(...b){return a=b,d=this,u=Date.now()+r,x=s,m.promise.isResolved&&(m.promise=Object.assign(new Promise(J=>{m.resolve=J,typeof R=="function"&&(R(),R=!1,x===S&&(x=!1)),i||(i=setTimeout(B,r),N&&(f=setTimeout(N,l)))}),{isResolved:!1})),m.promise},{callback:o,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:h,run:S,clear:async b=>{clearTimeout(i),i=void 0,clearTimeout(f),m.promise.isResolved=!0,m.resolve(b?await S():I)}});return m}_.noop=Object.assign(()=>{},{callback:h,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:h,run:h,clear:h});function U(o,r,e,t,s=!0){return Array.isArray(o)&&(o=o.length),typeof t!="string"&&(s=t??!0,t=e),(s?`${o}\xA0`:"")+U.raw(o,r,e,t)}U.raw=(o,r,e,t=e)=>{o=Math.abs(o);let s=o%10,l=o%100;return s===1&&l!==11?r:s>=2&&s<=4&&!(l>=12&&l<=15)?e:t};var T=new WeakMap,q=class extends Promise{constructor(e){let t,s;super((l,i)=>{t=l,s=i});c(this,"isPending",!0);c(this,"isFulfilled",!1);c(this,"isRejected",!1);c(this,"state","pending");c(this,"result");c(this,"resolve",e=>{if(this.isPending){this.isPending=!1,this.isFulfilled=!0,this.state="fulfilled",this.result=e;let t=T.get(this);t&&(t.resolve.call(this,e),T.delete(this))}});c(this,"reject",e=>{if(this.isPending){this.isPending=!1,this.isRejected=!0,this.state="rejected",this.result=e;let t=T.get(this);t&&(t.reject.call(this,e),T.delete(this))}});T.set(this,{resolve:t,reject:s}),e?.(this.resolve,this.reject)}};function V(o="",r=""){return`${o}${Date.now().toString(36)}${Math.round(Math.random()*Number.MAX_SAFE_INTEGER).toString(36)}${r}`}var y={request:"~r-q",response:"~r-s"};var Y=0,w,k,g,P,M,$,O,j,v,L,E,W,C=class C extends z{constructor(e={}){super();c(this,"isWebSocket",!0);c(this,"isWebSocketServer",!1);c(this,"isWebSocketServerClient",!1);c(this,"url");c(this,"name");c(this,"protocols");c(this,"reconnectAfter");p(this,w);c(this,"isUsed",!1);c(this,"isAutoReconnecting",!1);c(this,"webSocket",null);p(this,k,_(C.defib,65e3));p(this,g);p(this,P,()=>{n(this,g).resolve(),this.emit("open"),n(this,k).call(this)});p(this,M,({data:e})=>{if(n(this,k).call(this),e)try{let[t,...s]=JSON.parse(e);this.emit("message",t,...s),this.emit(`message:${t}`,...s)}catch(t){n(this,$).call(this,t)}else this.webSocket.send("")});p(this,$,e=>{e instanceof Event&&(e=void 0),n(this,g).isPending&&n(this,g).reject(e),this.emit("error",e)});p(this,O);p(this,j,e=>{process.env.NODE_ENV==="development"&&!n(this,w)&&console.info(`\u{1F50C} WS ${this.name} is closed ${e.code?`with code ${e.code}`:""} ${e.code&&e.reason?"and ":""}${e.reason?`reason "${e.reason}"`:""}`),n(this,k).clear();let t=this.webSocket;t.removeEventListener("open",n(this,P)),t.removeEventListener("message",n(this,M)),t.removeEventListener("error",n(this,$)),t.removeEventListener("close",n(this,j)),delete this.send,this.emit("close",e),this.webSocket=null,this.reconnectAfter&&![1002,3500,4e3].includes(e.code)&&(process.env.NODE_ENV==="development"&&!n(this,w)&&console.info(`\u{1F50C} WS ${this.name} will try to reconnect in 2 seconds`),A(this,O,setTimeout(()=>this.open().catch(h),this.reconnectAfter)))});c(this,"connect",this.open);c(this,"disconnect",this.close);p(this,v,[]);p(this,L,()=>{for(let e of n(this,v))this.webSocket.send(e);n(this,v).length=0});p(this,E,new Map);c(this,"onRequest",this.addRequestListener);c(this,"offRequest",this.removeRequestListener);p(this,W,async(e,t,...s)=>{let l=n(this,E).get(t),i,f=null;if(l)try{i=await l.apply(this,s)}catch(u){if(u instanceof Error){let{message:d,...a}=u;f={message:d,...a}}}else f={message:`Unknown request kind "${t}"`};this.sendMessage(`${y.response}-${e}`,f,i)});let{url:t=globalThis.__insite?.wss_url??"/",name:s=(Y++).toString(),protocols:l,immediately:i=!0,reconnectAfter:f=2e3,on:u,quiet:d=!1}=e;if(this.url=t,this.name=s,this.protocols=l,this.reconnectAfter=f,this.on(`message:${y.request}`,n(this,W)),u)for(let a in u)u[a]&&this.on(a,u[a]);A(this,w,d),this.url&&i&&this.open().catch(h),this.on("error",a=>a&&console.error("\u{1F50C}\u2757\uFE0F WS",`${this.name}:`,a))}get isConnecting(){return this.webSocket?this.webSocket.readyState===WebSocket.CONNECTING:null}get isOpen(){return this.webSocket?this.webSocket.readyState===WebSocket.OPEN:null}get isClosing(){return this.webSocket?this.webSocket.readyState===WebSocket.CLOSING:null}get isClosed(){return!this.webSocket||this.webSocket.readyState===WebSocket.CLOSED}async open(e={}){clearTimeout(n(this,O)),this.isUsed=!0,this.isAutoReconnecting=!!this.reconnectAfter,await this.close(4e3,"reopen");let t;return e.url&&this.url!==e.url&&(t=this.url,this.url=e.url),e.protocols&&(this.protocols=e.protocols),A(this,g,new q((s,l)=>{if(this.url){let i=new WebSocket(this.url,this.protocols);i.addEventListener("open",n(this,P)),i.addEventListener("message",n(this,M)),i.addEventListener("error",n(this,$)),i.addEventListener("close",n(this,j),{once:!0}),this.send=i.send.bind(i),this.webSocket=i,t&&this.emit("server-change",this.url,t),this.emit("connecting")}else this.webSocket=null,delete this.send,l(new Error("url prop is not set"))})),n(this,g)}close(e=3500,t="manual"){return clearTimeout(n(this,O)),t==="manual"&&(this.isAutoReconnecting=!1),new Promise(s=>{this.isConnecting||this.isOpen?(this.webSocket.addEventListener("close",()=>s(),{once:!0}),this.webSocket.close(e,t)):s()})}sendMessage(...e){let t=JSON.stringify(e);this.isOpen?this.webSocket.send(t):(n(this,v).length||this.once("open",n(this,L)),n(this,v).push(t))}sendRequest(...e){let t=V(),s=`message:${y.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(s,e.splice(-1,1)[0]),this.sendMessage(y.request,t,...e),this):new Promise((l,i)=>{this.once(s,(f,u)=>{if(f){let{message:d,...a}=f;i(Object.assign(new Error(d),a))}else l(u)}),this.sendMessage(y.request,t,...e)})}addRequestListener(e,t){return n(this,E).set(e,t),this}removeRequestListener(e){return n(this,E).delete(e),this}static defib(){this.isOpen&&(process.env.NODE_ENV==="development"&&!n(this,w)&&console.info(`\u{1F50C} WS ${this.name} has no heartbeat, going offline`),this.webSocket.close())}};w=new WeakMap,k=new WeakMap,g=new WeakMap,P=new WeakMap,M=new WeakMap,$=new WeakMap,O=new WeakMap,j=new WeakMap,v=new WeakMap,L=new WeakMap,E=new WeakMap,W=new WeakMap;var G=C;export{G as WS};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WSServer.d.ts","sourceRoot":"","sources":["../../src/server/WSServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAgC,MAAM,IAAI,CAAC;AAKnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAA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AAE,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAEzG,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAK1F,QAAQ,CAAC,iBAAiB,QAAQ;IAClC,QAAQ,CAAC,uBAAuB,SAAS;IACzC,QAAQ,CAAC,WAAW,SAAS;IAE7B,IAAI,SAAQ;IACZ,IAAI,SAAQ;IACZ,IAAI,QAAQ,WAEX;IAED,MAAM,+IAAC;IAEP,IAAI,GAAG,YAEN;IAID,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC;IAMhE,SAAS,SANgB,MAAM,YAAY,eAAe,CAAC,IAAI,CAAC,UAM5B;IAEpC,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAMlC,UAAU,SANkB,MAAM,UAMM;IAwJxC,MAAM,CAAC,SAAS,CAAC,KAAK,SAAS,cAAc,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa;CAMjH"}
@@ -1,2 +1,6 @@
1
- import{WebSocketServer as N}from"ws";import{createServer as L,resolveSSL as _,showServerListeningMessage as P}from"insite-common/backend";var m={request:"~r-q",response:"~r-s"};var b=Symbol("heartbeatInterval"),d=Symbol("defib"),h=Symbol("pingTs");var B=["forwarded","x-forwarded","forwarded-for","x-forwarded-for","x-real-ip","cf-connecting-ip","do-connecting-ip","x-appengine-user-ip","true-client-ip","fastly-client-ip","client-ip","x-client-ip","x-proxyuser-ip","x-cluster-client-ip"],R,g,C=/^.*?((?:\d{1,3}\.){3}\d{1,3}).*$/;function E(o){if(g===void 0||R!==o.headers.host){g=void 0,{host:R}=o.headers;for(let e of B){let t=o.headers[e];typeof t=="string"&&C.test(t)&&(g=e)}g??=o.socket.remoteAddress&&C.test(o.socket.remoteAddress)?!1:null}switch(g){case!1:return o.socket.remoteAddress.replace(C,"$1");case null:return"127.0.0.1";default:return o.headers[g].replace(C,"$1")}}import{WebSocket as D}from"ws";function v(){}function k(o,e=0,t={}){let{leading:r=!1,trailing:n=!0}=t,{maxWait:s=1/0}=t,i,a,c,S,W,y,u,O,M=async()=>{let x=Date.now();x>=c?(i=void 0,c=void 0,clearTimeout(a),typeof u=="function"&&await u(),f.resolve(O),f.promise.isResolved=!0,y=r):(clearTimeout(i),i=setTimeout(M,c-x))},$=Number.isFinite(s)?()=>{u===p&&(u=!1),p(),a=setTimeout($,s)}:null;async function p(){return O=await o.apply(S,W)}r&&typeof r=="boolean"&&(r=p),y=r,n&&typeof n=="boolean"&&(n=p),u=n;let f=Object.assign(function(...x){return W=x,S=this,c=Date.now()+e,u=n,f.promise.isResolved&&(f.promise=Object.assign(new Promise(w=>{f.resolve=w,typeof y=="function"&&(y(),y=!1,u===p&&(u=!1)),i||(i=setTimeout(M,e),$&&(a=setTimeout($,s)))}),{isResolved:!1})),f.promise},{callback:o,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:v,run:p,clear:async x=>{clearTimeout(i),i=void 0,clearTimeout(a),f.promise.isResolved=!0,f.resolve(x?await p():O)}});return f}k.noop=Object.assign(()=>{},{callback:v,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:v,run:v,clear:v});function j(o,e,t,r,n=!0){return Array.isArray(o)&&(o=o.length),typeof r!="string"&&(n=r??!0,r=t),(n?`${o}\xA0`:"")+j.raw(o,e,t,r)}j.raw=(o,e,t,r=t)=>{o=Math.abs(o);let n=o%10,s=o%100;return n===1&&s!==11?e:n>=2&&n<=4&&!(s>=12&&s<=15)?t:r};function I(o="",e=""){return`${o}${Date.now().toString(36)}${Math.round(Math.random()*Number.MAX_SAFE_INTEGER).toString(36)}${e}`}var l=class o extends D{on(e,t){return super.on(e,t)}get isConnecting(){return this.readyState===this.CONNECTING}get isOpen(){return this.readyState===this.OPEN}get isClosing(){return this.readyState===this.CLOSING}get isClosed(){return this.readyState===this.CLOSED}isWebSocketServerClient=!0;isWebSocketServer=!1;isWebSocket=!1;wss;userAgent="";remoteAddress="";[d]=o.makeDefib.call(this);latency=0;[h];[b]=o.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}sendRequest(...e){let t=I(),r=`message:${m.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(r,e.splice(-1,1)[0]),this.sendMessage(m.request,t,...e),this):new Promise((n,s)=>{this.once(r,(i,a)=>{if(i){let{message:c,...S}=i;s(Object.assign(new Error(c),S))}else n(a)}),this.sendMessage(m.request,t,...e)})}static makeDefib(){return k(()=>this.terminate(),65e3)}static makeHeartbeatInterval(){return setInterval(()=>{this[h]=Date.now(),this.send("")},5e3)}};var A=class o extends N{constructor(e){let{ssl:t,port:r,server:n=L(o.makeProps(e)),...s}=e;super({WebSocket:l,...s,server:n}),this.server=n,e.server?new Promise(i=>void(n.listening?i():n.on("listening",i))).then(()=>P(this)):this.server.listen(typeof r=="string"?Number.parseInt(r):r??(this.isS?443:80),()=>P(this)),this.on("connection",this.#n),this.on(`client-message:${m.request}`,this.#r),this.on("error",i=>console.error(`${this.icon}\u2757\uFE0F WS Server:`,i)),this.on("close",()=>console.error(`${this.icon}\u2757\uFE0F WS Server closed`))}on(e,t){return super.on(e,t)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;icon="\u{1F50C}";name="WS";get protocol(){return`ws${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}#e=new Map;addRequestListener(e,t){return this.#e.set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.#e.delete(e),this}offRequest=this.removeRequestListener;#r=async(e,t,r,...n)=>{let s=this.#e.get(r),i,a=null;if(s)try{i=await s.call(this,e,...n)}catch(c){if(c instanceof Error){let{message:S,...W}=c;a={message:S,...W}}process.env.NODE_ENV==="development"&&console.error(`${this.icon}\u2757\uFE0F WS Server request "${r}" (${t}):`,c)}else a={message:`Unknown request kind "${r}"`};e.sendMessage(`${m.response}-${t}`,a,i)};#n(e,t){if(!(e instanceof l)){Object.defineProperties(e,{isConnecting:{get:Object.getOwnPropertyDescriptor(l.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(l.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosed").get}});let{terminate:r}=e;Object.assign(e,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[d]:l.makeDefib.call(e),latency:0,[b]:l.makeHeartbeatInterval.call(e),sendMessage:l.prototype.sendMessage,sendRequest:l.prototype.sendRequest,terminate(){try{r.call(e)}catch(n){console.error(n)}}})}Object.assign(e,{wss:this,userAgent:t.headers["user-agent"]??"",remoteAddress:E(t)}),e[d](),e.on("message",r=>this.#o(e,r)),e.on("error",r=>this.#t(e,r)),e.on("close",(...r)=>this.#s(e,...r)),this.emit("client-connect",e,t),process.env.NODE_ENV==="development"&&console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m","connected")}#o(e,t){let r=t.toString();if(e[d](),r)try{let[n,...s]=JSON.parse(r);e.emit(`message:${n}`,...s),this.emit("client-message",e,n,...s),this.emit(`client-message:${n}`,e,...s)}catch(n){this.#t(e,n)}else e[h]&&(e.latency=Date.now()-e[h],delete e[h])}#t(e,t){t instanceof Event&&(t=void 0),console.error(`${this.icon}\u2757\uFE0F WS Server client`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m:`:"\x1B[3manonymous\x1B[0m:",t),this.emit("client-error",e,t)}#s(e,t,r){if(process.env.NODE_ENV==="development"){let n=r.toString();console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m",`disconnected ${t?`with code ${t}`:""} ${t&&n?"and ":""}${n?`reason "${n}"`:""}`)}e[d].clear(),clearInterval(e[b]),this.emit("client-close",e),this.emit("client-closed",e)}static makeProps({ssl:e}){return{..._(e)}}};export{A as WSServer,l as WSServerClient};
1
+ import{WebSocketServer as D}from"ws";function g(){}function O(t,e=0,r={}){let{leading:o=!1,trailing:n=!0}=r,{maxWait:s=1/0}=r,i,c,a,S,b,v,u,W,$=async()=>{let x=Date.now();x>=a?(i=void 0,a=void 0,clearTimeout(c),typeof u=="function"&&await u(),f.resolve(W),f.promise.isResolved=!0,v=o):(clearTimeout(i),i=setTimeout($,a-x))},C=Number.isFinite(s)?()=>{u===p&&(u=!1),p(),c=setTimeout(C,s)}:null;async function p(){return W=await t.apply(S,b)}o&&typeof o=="boolean"&&(o=p),v=o,n&&typeof n=="boolean"&&(n=p),u=n;let f=Object.assign(function(...x){return b=x,S=this,a=Date.now()+e,u=n,f.promise.isResolved&&(f.promise=Object.assign(new Promise(q=>{f.resolve=q,typeof v=="function"&&(v(),v=!1,u===p&&(u=!1)),i||(i=setTimeout($,e),C&&(c=setTimeout(C,s)))}),{isResolved:!1})),f.promise},{callback:t,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:g,run:p,clear:async x=>{clearTimeout(i),i=void 0,clearTimeout(c),f.promise.isResolved=!0,f.resolve(x?await p():W)}});return f}O.noop=Object.assign(()=>{},{callback:g,promise:Object.assign(Promise.resolve(),{isResolved:!0}),resolve:g,run:g,clear:g});function k(t,e=" ",r=1){if(!t)return t;let o=e.repeat(r);return t.split(`
2
+ `).map(n=>`${o}${n}`).join(`
3
+ `)}function P(t){return!!t&&typeof t=="object"&&"errorResponse"in t&&!!t.errorResponse&&typeof t.errorResponse=="object"&&"errInfo"in t.errorResponse}function R(t){return P(t)&&t.errorResponse.errmsg==="Document failed validation"&&(t.message=`${t.errorResponse.errmsg}
4
+ ${k(`failingDocumentId: ${t.errorResponse.errInfo?.failingDocumentId}
5
+ schemaRulesNotSatisfied: ${JSON.stringify(t.errorResponse.errInfo?.details?.schemaRulesNotSatisfied,null," ")}`," ")}`),t}function E(t,e,r,o,n=!0){return Array.isArray(t)&&(t=t.length),typeof o!="string"&&(n=o??!0,o=r),(n?`${t}\xA0`:"")+E.raw(t,e,r,o)}E.raw=(t,e,r,o=r)=>{t=Math.abs(t);let n=t%10,s=t%100;return n===1&&s!==11?e:n>=2&&n<=4&&!(s>=12&&s<=15)?r:o};function M(t="",e=""){return`${t}${Date.now().toString(36)}${Math.round(Math.random()*Number.MAX_SAFE_INTEGER).toString(36)}${e}`}import{createServer as N,getRemoteAddress as A,resolveSSL as L,showServerListeningMessage as T}from"insite-common/backend";var m={request:"~r-q",response:"~r-s"};var y=Symbol("heartbeatInterval"),d=Symbol("defib"),h=Symbol("pingTs");import{WebSocket as B}from"ws";var l=class t extends B{on(e,r){return super.on(e,r)}get isConnecting(){return this.readyState===this.CONNECTING}get isOpen(){return this.readyState===this.OPEN}get isClosing(){return this.readyState===this.CLOSING}get isClosed(){return this.readyState===this.CLOSED}isWebSocketServerClient=!0;isWebSocketServer=!1;isWebSocket=!1;wss;userAgent="";remoteAddress="";[d]=t.makeDefib.call(this);latency=0;[h];[y]=t.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}sendRequest(...e){let r=M(),o=`message:${m.response}-${r}`;return typeof e.at(-1)=="function"?(this.once(o,e.splice(-1,1)[0]),this.sendMessage(m.request,r,...e),this):new Promise((n,s)=>{this.once(o,(i,c)=>{if(i){let{message:a,...S}=i;s(Object.assign(new Error(a),S))}else n(c)}),this.sendMessage(m.request,r,...e)})}static makeDefib(){return O(()=>this.terminate(),65e3)}static makeHeartbeatInterval(){return setInterval(()=>{this[h]=Date.now(),this.send("")},5e3)}};var j=class t extends D{constructor(e){let{ssl:r,port:o,server:n=N(t.makeProps(e)),...s}=e;super({WebSocket:l,...s,server:n}),this.server=n,e.server?new Promise(i=>void(n.listening?i():n.on("listening",i))).then(()=>T(this)):this.server.listen(typeof o=="string"?Number.parseInt(o):o??(this.isS?443:80),()=>T(this)),this.on("connection",this.#o),this.on(`client-message:${m.request}`,this.#r),this.on("error",i=>console.error(`${this.icon}\u2757\uFE0F WS Server:`,i)),this.on("close",()=>console.error(`${this.icon}\u2757\uFE0F WS Server closed`))}on(e,r){return super.on(e,r)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;icon="\u{1F50C}";name="WS";get protocol(){return`ws${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}#e=new Map;addRequestListener(e,r){return this.#e.set(e,r),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.#e.delete(e),this}offRequest=this.removeRequestListener;#r=async(e,r,o,...n)=>{let s=this.#e.get(o),i,c=null;if(s)try{i=await s.call(this,e,...n)}catch(a){if(process.env.NODE_ENV==="development"&&R(a),a instanceof Error){let{message:S,...b}=a;c={message:S,...b}}process.env.NODE_ENV==="development"&&console.error(`${this.icon}\u2757\uFE0F WS Server request "${o}" (${r}):`,a)}else c={message:`Unknown request kind "${o}"`};e.sendMessage(`${m.response}-${r}`,c,i)};#o(e,r){if(!(e instanceof l)){Object.defineProperties(e,{isConnecting:{get:Object.getOwnPropertyDescriptor(l.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(l.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(l.prototype,"isClosed").get}});let{terminate:o}=e;Object.assign(e,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[d]:l.makeDefib.call(e),latency:0,[y]:l.makeHeartbeatInterval.call(e),sendMessage:l.prototype.sendMessage,sendRequest:l.prototype.sendRequest,terminate(){try{o.call(e)}catch(n){console.error(n)}}})}Object.assign(e,{wss:this,userAgent:r.headers["user-agent"]??"",remoteAddress:A(r)}),e[d](),e.on("message",o=>this.#n(e,o)),e.on("error",o=>this.#t(e,o)),e.on("close",(...o)=>this.#s(e,...o)),this.emit("client-connect",e,r),process.env.NODE_ENV==="development"&&console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m","connected")}#n(e,r){let o=r.toString();if(e[d](),o)try{let[n,...s]=JSON.parse(o);e.emit(`message:${n}`,...s),this.emit("client-message",e,n,...s),this.emit(`client-message:${n}`,e,...s)}catch(n){this.#t(e,n)}else e[h]&&(e.latency=Date.now()-e[h],delete e[h])}#t(e,r){r instanceof Event&&(r=void 0),console.error(`${this.icon}\u2757\uFE0F WS Server client`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m:`:"\x1B[3manonymous\x1B[0m:",r),this.emit("client-error",e,r)}#s(e,r,o){if(process.env.NODE_ENV==="development"){let n=o.toString();console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m",`disconnected ${r?`with code ${r}`:""} ${r&&n?"and ":""}${n?`reason "${n}"`:""}`)}e[d].clear(),clearInterval(e[y]),this.emit("client-close",e),this.emit("client-closed",e)}static makeProps({ssl:e}){return{...L(e)}}};export{j as WSServer,l as WSServerClient};
2
6
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/server/WSServer.ts", "../../src/common.ts", "../../src/server/symbols.ts", "../../src/server/utils.ts", "../../src/server/WSServerClient.ts", "../../../../../@nesvet/npm/n/src/noop.ts", "../../../../../@nesvet/npm/n/src/debounce.ts", "../../../../../@nesvet/npm/n/src/howmuch.ts", "../../../../../@nesvet/npm/n/src/uid.ts"],
4
- "sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer, type RawData, type WebSocket } from \"ws\";\nimport { createServer, resolveSSL, showServerListeningMessage } from \"insite-common/backend\";\nimport { requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { getRemoteAddress } from \"./utils\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient<WSSC>,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tnew Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tthis.on(`client-message:${requestHeaders.request}`, this.#handleRequest);\n\t\t\n\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\n\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: WSServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: WSServer<WSSC>, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: WSServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: WSServer<WSSC>) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: WSServer<WSSC>, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: WSServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: WSServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as unknown as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon = \"\uD83D\uDD0C\";\n\tname = \"WS\";\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t#requestListeners = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis.#requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis.#requestListeners.delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleRequest = async (wssc: WSSC, id: string, kind: string, ...rest: unknown[]) => {\n\t\tconst listener = this.#requestListeners.get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\tconsole.error(`${this.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\twssc.sendMessage(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\tif (!(wssc instanceof WSServerClient)) { /* Compatibility with Bun */\n\t\t\tObject.defineProperties(wssc, {\n\t\t\t\tisConnecting: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isConnecting\")!.get\n\t\t\t\t},\n\t\t\t\tisOpen: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isOpen\")!.get\n\t\t\t\t},\n\t\t\t\tisClosing: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosing\")!.get\n\t\t\t\t},\n\t\t\t\tisClosed: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosed\")!.get\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tconst { terminate } = wssc as WebSocket;\n\t\t\t\n\t\t\tObject.assign(wssc, {\n\t\t\t\tisWebSocketServerClient: true,\n\t\t\t\tisWebSocketServer: false,\n\t\t\t\tisWebSocket: false,\n\t\t\t\t[defibSymbol]: WSServerClient.makeDefib.call(wssc),\n\t\t\t\tlatency: 0,\n\t\t\t\t[heartbeatIntervalSymbol]: WSServerClient.makeHeartbeatInterval.call(wssc),\n\t\t\t\tsendMessage: WSServerClient.prototype.sendMessage,\n\t\t\t\tsendRequest: WSServerClient.prototype.sendRequest,\n\t\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tterminate.call(wssc);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\twssc.on(\"message\", data => this.#handleClientMessage(wssc, data));\n\t\twssc.on(\"error\", error => this.#handleClientError(wssc, error));\n\t\twssc.on(\"close\", (...args) => this.#handleClientClose(wssc, ...args));\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t\t\n\t}\n\t\n\t\n\t#handleClientMessage(wssc: WSSC, data: RawData) {\n\t\tconst message = data.toString();\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\twssc.emit(`message:${kind}`, ...rest);\n\t\t\t\tthis.emit(\"client-message\", wssc, kind, ...rest);\n\t\t\t\tthis.emit(`client-message:${kind}`, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#handleClientError(wssc, error as Error);\n\t\t\t}\n\t\telse if (wssc[pingTsSymbol]) {\n\t\t\twssc.latency = Date.now() - wssc[pingTsSymbol];\n\t\t\tdelete wssc[pingTsSymbol];\n\t\t}\n\t\t\n\t}\n\t\n\t#handleClientError(wssc: WSSC, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tconsole.error(\n\t\t\t`${this.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\terror\n\t\t);\n\t\t\n\t\tthis.emit(\"client-error\", wssc, error);\n\t\t\n\t}\n\t\n\t#handleClientClose(wssc: WSSC, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t);\n\t\t}\n\t\t\n\t\twssc[defibSymbol].clear();\n\t\tclearInterval(wssc[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.emit(\"client-close\", wssc);\n\t\tthis.emit(\"client-closed\", wssc);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n", "export const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const pingTsSymbol = Symbol(\"pingTs\");\n", "import type { IncomingMessage } from \"node:http\";\n\n\nconst headersThatMayContainRemoteAddress = [\n\t\"forwarded\",\n\t\"x-forwarded\",\n\t\"forwarded-for\",\n\t\"x-forwarded-for\",\n\t\"x-real-ip\",\n\t\"cf-connecting-ip\",\n\t\"do-connecting-ip\",\n\t\"x-appengine-user-ip\",\n\t\"true-client-ip\",\n\t\"fastly-client-ip\",\n\t\"client-ip\",\n\t\"x-client-ip\",\n\t\"x-proxyuser-ip\",\n\t\"x-cluster-client-ip\"\n] as const;\n\nlet host: string | undefined;\nlet headerWithRemoteAddress: typeof headersThatMayContainRemoteAddress[number] | false | null | undefined;\n\nconst remoteAddressRegExp = /^.*?((?:\\d{1,3}\\.){3}\\d{1,3}).*$/;\n\nexport function getRemoteAddress(request: IncomingMessage) {\n\tif (headerWithRemoteAddress === undefined || host !== request.headers.host) {\n\t\theaderWithRemoteAddress = undefined;\n\t\t({ host } = request.headers);\n\t\t\n\t\tfor (const headerName of headersThatMayContainRemoteAddress) {\n\t\t\tconst header = request.headers[headerName];\n\t\t\tif (typeof header == \"string\" && remoteAddressRegExp.test(header))\n\t\t\t\theaderWithRemoteAddress = headerName;\n\t\t}\n\t\t\n\t\theaderWithRemoteAddress ??=\n\t\t\trequest.socket.remoteAddress && remoteAddressRegExp.test(request.socket.remoteAddress) ?\n\t\t\t\tfalse :\n\t\t\t\tnull;\n\t}\n\t\n\tswitch (headerWithRemoteAddress) {\n\t\tcase false:\n\t\t\treturn request.socket.remoteAddress!.replace(remoteAddressRegExp, \"$1\");\n\t\t\n\t\tcase null:\n\t\t\treturn \"127.0.0.1\";\n\t\t\n\t\tdefault:\n\t\t\treturn (request.headers[headerWithRemoteAddress] as string).replace(remoteAddressRegExp, \"$1\");\n\t}\n}\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { debounce, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient<WSSC extends WSServerClient = any> extends WebSocket {\n\ton(event: \"close\", listener: (this: WSSC, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: WSSC, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: WSSC, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: WSSC, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: WSSC) => void): this;\n\ton(event: \"ping\" | \"pong\", listener: (this: WSSC, data: Buffer) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<WSSC>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[defibSymbol] = WSServerClient.makeDefib.call(this);\n\t\n\tlatency = 0;\n\t\n\t[pingTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.response}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps));\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeDefib(this: WSServerClient<any>) {\n\t\treturn debounce(() => this.terminate(), heartbeatInterval + heartbeatGap);\n\t}\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient<any>) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[pingTsSymbol] = Date.now();\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, heartbeatInterval);\n\t}\n\t\n}\n", "export function noop() { /**/ }\n", "import { noop } from \"./noop.js\";\n\n\ntype Callback<Result> = (...args: unknown[]) => Result;\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\ntype NumberOrUndefined = number | undefined;\n\ntype DebouncedFunction<Result> = {\n\t(this: unknown, ..._args: unknown[]): Promise<Result>;\n};\n\nexport type Debounced<Result> = {\n\tcallback: Callback<Result>;\n\tpromise: {\n\t\tisResolved: boolean;\n\t} & Promise<unknown>;\n\tresolve: (value: Result) => void;\n\trun(): Promise<Result>;\n\tclear(shouldRun?: boolean): Promise<void>;\n} & DebouncedFunction<Result>;\n\n\nexport function debounce<Result>(callback: Callback<Result>, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: NumberOrUndefined;\n\tlet maxWaitTimeout: NumberOrUndefined;\n\tlet end: NumberOrUndefined;\n\tlet context: unknown;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: Result;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\tdebounced.resolve(result);\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\trun();\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\treturn (result = await callback.apply(context, args));\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<Result> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (debounced.promise.isResolved)\n\t\t\tdebounced.promise = Object.assign(new Promise(resolve => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\tinitial = false;\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}), {\n\t\t\t\tisResolved: false\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<Result>, {\n\t\tcallback,\n\t\tpromise: Object.assign(Promise.resolve(), {\n\t\t\tisResolved: true\n\t\t}),\n\t\tresolve: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\t\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: Object.assign(Promise.resolve(), {\n\t\tisResolved: true\n\t}),\n\tresolve: noop,\n\trun: noop,\n\tclear: noop\n}) as unknown as Debounced<void>;\n\n\nexport function throttle<Result>(callback: Callback<Result>, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export function uid(prefix: string | undefined = \"\", postfix: string | undefined = \"\") {\n\treturn `${prefix}${Date.now().toString(36)}${Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36)}${postfix}`;\n}\n"],
5
- "mappings": "AAEA,OAAS,mBAAAA,MAAqD,KAC9D,OAAS,gBAAAC,EAAc,cAAAC,EAAY,8BAAAC,MAAkC,wBCA9D,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,ECNO,IAAMC,EAA0B,OAAO,mBAAmB,EACpDC,EAAc,OAAO,OAAO,EAC5BC,EAAe,OAAO,QAAQ,ECC3C,IAAMC,EAAqC,CAC1C,YACA,cACA,gBACA,kBACA,YACA,mBACA,mBACA,sBACA,iBACA,mBACA,YACA,cACA,iBACA,qBACD,EAEIC,EACAC,EAEEC,EAAsB,mCAErB,SAASC,EAAiBC,EAA0B,CAC1D,GAAIH,IAA4B,QAAaD,IAASI,EAAQ,QAAQ,KAAM,CAC3EH,EAA0B,OACzB,CAAE,KAAAD,CAAK,EAAII,EAAQ,QAEpB,QAAWC,KAAcN,EAAoC,CAC5D,IAAMO,EAASF,EAAQ,QAAQC,CAAU,EACrC,OAAOC,GAAU,UAAYJ,EAAoB,KAAKI,CAAM,IAC/DL,EAA0BI,EAC5B,CAEAJ,IACCG,EAAQ,OAAO,eAAiBF,EAAoB,KAAKE,EAAQ,OAAO,aAAa,EACpF,GACA,IACH,CAEA,OAAQH,EAAyB,CAChC,IAAK,GACJ,OAAOG,EAAQ,OAAO,cAAe,QAAQF,EAAqB,IAAI,EAEvE,KAAK,KACJ,MAAO,YAER,QACC,OAAQE,EAAQ,QAAQH,CAAuB,EAAa,QAAQC,EAAqB,IAAI,CAC/F,CACD,CCnDA,OAAkB,aAAAK,MAAiB,KCD7B,SAAUC,GAAI,CAAU,CCuBxB,SAAUC,EAAiBC,EAA4BC,EAAQ,EAAGC,EAAmB,CAAA,EAAE,CAC5F,GAAI,CAAE,QAAAC,E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,KAAK,IAAI,EAAIA,EAAKiB,CAAY,EAC7C,OAAOjB,EAAKiB,CAAY,EAG1B,CAEAH,GAAmBd,EAAYL,EAAkC,CAC5DA,aAAiB,QACpBA,EAAQ,QAET,QAAQ,MACP,GAAG,KAAK,IAAI,gCACZ,SAAUK,EAAO,UAAWA,EAAK,KAA2B,KAAK,WAAa,2BAC9EL,CACD,EAEA,KAAK,KAAK,eAAgBK,EAAML,CAAK,CAEtC,CAEAqB,GAAmBhB,EAAYkB,EAAcC,EAAgB,CAE5D,GAAI,QAAQ,IAAI,WAAa,cAAe,CAC3C,IAAMC,EAAeD,EAAO,SAAS,EAErC,QAAQ,KACP,GAAG,KAAK,IAAI,cACZ,SAAUnB,EAAO,UAAWA,EAAK,KAA2B,KAAK,UAAY,0BAC7E,gBAAgBkB,EAAO,aAAaA,CAAI,GAAK,EAAE,IAAIA,GAAQE,EAAe,OAAS,EAAE,GAAGA,EAAe,WAAWA,CAAY,IAAM,EAAE,EACvI,CACD,CAEApB,EAAKS,CAAW,EAAE,MAAM,EACxB,cAAcT,EAAKU,CAAuB,CAAC,EAE3C,KAAK,KAAK,eAAgBV,CAAI,EAC9B,KAAK,KAAK,gBAAiBA,CAAI,CAEhC,CAGA,OAAO,UAAwC,CAAE,IAAAqB,CAAI,EAA6D,CACjH,MAAO,CACN,GAAGC,EAAWD,CAAG,CAClB,CACD,CAED",
6
- "names": ["WebSocketServer", "createServer", "resolveSSL", "showServerListeningMessage", "requestHeaders", "heartbeatIntervalSymbol", "defibSymbol", "pingTsSymbol", "headersThatMayContainRemoteAddress", "host", "headerWithRemoteAddress", "remoteAddressRegExp", "getRemoteAddress", "request", "headerName", "header", "WebSocket", "noop", "debounce", "callback", "limit", "options", "leading", "trailing", "maxWait", "timeout", "maxWaitTimeout", "end", "context", "args", "initial", "final", "result", "expired", "n", "debounced", "maxWaitExpired", "run", "_args", "resolve", "noop", "shouldRun", "howmuch", "number", "one", "two", "five", "shouldPrintNumber", "u", "d", "uid", "prefix", "postfix", "WSServerClient", "_WSServerClient", "WebSocket", "event", "listener", "defibSymbol", "pingTsSymbol", "heartbeatIntervalSymbol", "args", "id", "uid", "eventName", "requestHeaders", "resolve", "reject", "error", "result", "message", "restProps", "debounce", "WSServer", "_WSServer", "WebSocketServer", "options", "_", "port", "server", "createServer", "wssOptions", "WSServerClient", "resolve", "showServerListeningMessage", "#handleConnection", "requestHeaders", "#handleRequest", "error", "event", "listener", "#requestListeners", "kind", "wssc", "id", "rest", "result", "requestError", "message", "restProps", "request", "terminate", "defibSymbol", "heartbeatIntervalSymbol", "getRemoteAddress", "data", "#handleClientMessage", "#handleClientError", "args", "#handleClientClose", "pingTsSymbol", "code", "reason", "reasonString", "ssl", "resolveSSL"]
3
+ "sources": ["../../src/server/WSServer.ts", "../../../../../@nesvet/npm/n/src/noop.ts", "../../../../../@nesvet/npm/n/src/debounce.ts", "../../../../../@nesvet/npm/n/src/indent.ts", "../../../../../@nesvet/npm/n/src/handleMongoError.ts", "../../../../../@nesvet/npm/n/src/howmuch.ts", "../../../../../@nesvet/npm/n/src/uid.ts", "../../src/common.ts", "../../src/server/symbols.ts", "../../src/server/WSServerClient.ts"],
4
+ "sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer, type RawData, type WebSocket } from \"ws\";\nimport { handleMongoError } from \"@nesvet/n\";\nimport {\n\tcreateServer,\n\tgetRemoteAddress,\n\tresolveSSL,\n\tshowServerListeningMessage\n} from \"insite-common/backend\";\nimport { requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient<WSSC>,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tnew Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tthis.on(`client-message:${requestHeaders.request}`, this.#handleRequest);\n\t\t\n\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\n\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: WSServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: WSServer<WSSC>, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: WSServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: WSServer<WSSC>) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: WSServer<WSSC>, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: WSServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: WSServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSServer<WSSC>, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as unknown as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon = \"\uD83D\uDD0C\";\n\tname = \"WS\";\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t#requestListeners = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis.#requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis.#requestListeners.delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleRequest = async (wssc: WSSC, id: string, kind: string, ...rest: unknown[]) => {\n\t\tconst listener = this.#requestListeners.get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\thandleMongoError(error);\n\t\t\t\t\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\tconsole.error(`${this.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\twssc.sendMessage(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\tif (!(wssc instanceof WSServerClient)) { /* Compatibility with Bun */\n\t\t\tObject.defineProperties(wssc, {\n\t\t\t\tisConnecting: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isConnecting\")!.get\n\t\t\t\t},\n\t\t\t\tisOpen: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isOpen\")!.get\n\t\t\t\t},\n\t\t\t\tisClosing: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosing\")!.get\n\t\t\t\t},\n\t\t\t\tisClosed: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosed\")!.get\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tconst { terminate } = wssc as WebSocket;\n\t\t\t\n\t\t\tObject.assign(wssc, {\n\t\t\t\tisWebSocketServerClient: true,\n\t\t\t\tisWebSocketServer: false,\n\t\t\t\tisWebSocket: false,\n\t\t\t\t[defibSymbol]: WSServerClient.makeDefib.call(wssc),\n\t\t\t\tlatency: 0,\n\t\t\t\t[heartbeatIntervalSymbol]: WSServerClient.makeHeartbeatInterval.call(wssc),\n\t\t\t\tsendMessage: WSServerClient.prototype.sendMessage,\n\t\t\t\tsendRequest: WSServerClient.prototype.sendRequest,\n\t\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tterminate.call(wssc);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\twssc.on(\"message\", data => this.#handleClientMessage(wssc, data));\n\t\twssc.on(\"error\", error => this.#handleClientError(wssc, error));\n\t\twssc.on(\"close\", (...args) => this.#handleClientClose(wssc, ...args));\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t\t\n\t}\n\t\n\t\n\t#handleClientMessage(wssc: WSSC, data: RawData) {\n\t\tconst message = data.toString();\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\twssc.emit(`message:${kind}`, ...rest);\n\t\t\t\tthis.emit(\"client-message\", wssc, kind, ...rest);\n\t\t\t\tthis.emit(`client-message:${kind}`, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#handleClientError(wssc, error as Error);\n\t\t\t}\n\t\telse if (wssc[pingTsSymbol]) {\n\t\t\twssc.latency = Date.now() - wssc[pingTsSymbol];\n\t\t\tdelete wssc[pingTsSymbol];\n\t\t}\n\t\t\n\t}\n\t\n\t#handleClientError(wssc: WSSC, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tconsole.error(\n\t\t\t`${this.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\terror\n\t\t);\n\t\t\n\t\tthis.emit(\"client-error\", wssc, error);\n\t\t\n\t}\n\t\n\t#handleClientClose(wssc: WSSC, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t);\n\t\t}\n\t\t\n\t\twssc[defibSymbol].clear();\n\t\tclearInterval(wssc[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.emit(\"client-close\", wssc);\n\t\tthis.emit(\"client-closed\", wssc);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n}\n", "export function noop() { /**/ }\n", "import { noop } from \"./noop.js\";\n\n\ntype Callback<Result> = (...args: unknown[]) => Result;\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\ntype NumberOrUndefined = number | undefined;\n\ntype DebouncedFunction<Result> = {\n\t(this: unknown, ..._args: unknown[]): Promise<Result>;\n};\n\nexport type Debounced<Result> = {\n\tcallback: Callback<Result>;\n\tpromise: {\n\t\tisResolved: boolean;\n\t} & Promise<unknown>;\n\tresolve: (value: Result) => void;\n\trun(): Promise<Result>;\n\tclear(shouldRun?: boolean): Promise<void>;\n} & DebouncedFunction<Result>;\n\n\nexport function debounce<Result>(callback: Callback<Result>, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: NumberOrUndefined;\n\tlet maxWaitTimeout: NumberOrUndefined;\n\tlet end: NumberOrUndefined;\n\tlet context: unknown;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: Result;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\tdebounced.resolve(result);\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\trun();\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\treturn (result = await callback.apply(context, args));\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<Result> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (debounced.promise.isResolved)\n\t\t\tdebounced.promise = Object.assign(new Promise(resolve => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\tinitial = false;\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}), {\n\t\t\t\tisResolved: false\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<Result>, {\n\t\tcallback,\n\t\tpromise: Object.assign(Promise.resolve(), {\n\t\t\tisResolved: true\n\t\t}),\n\t\tresolve: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\t\n\t\t\tdebounced.promise.isResolved = true;\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: Object.assign(Promise.resolve(), {\n\t\tisResolved: true\n\t}),\n\tresolve: noop,\n\trun: noop,\n\tclear: noop\n}) as unknown as Debounced<void>;\n\n\nexport function throttle<Result>(callback: Callback<Result>, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "export function indent(string: string, indentation: string = \"\\t\", times: number = 1): string {\n\tif (!string)\n\t\treturn string;\n\t\n\tconst prefix = indentation.repeat(times);\n\t\n\treturn string.split(\"\\n\").map(line => `${prefix}${line}`).join(\"\\n\");\n}\n", "import { indent } from \"./indent.js\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\ntype MongoServerError = {\n\terrorResponse: {\n\t\terrmsg: string;\n\t\terrInfo?: {\n\t\t\t[key: string]: any;\n\t\t};\n\t};\n\t[key: string]: any;\n};\n\nfunction isMongoServerError(error: unknown): error is MongoServerError {\n\treturn (\n\t\t!!error &&\n\t\ttypeof error == \"object\" &&\n\t\t\"errorResponse\" in error &&\n\t\t!!error.errorResponse &&\n\t\ttypeof error.errorResponse == \"object\" &&\n\t\t\"errInfo\" in error.errorResponse\n\t);\n}\n\nexport function handleMongoError<E extends MongoServerError>(error: E): E;\nexport function handleMongoError(error: any): any;\nexport function handleMongoError(error: any) {\n\tif (isMongoServerError(error) && error.errorResponse.errmsg === \"Document failed validation\")\n\t\terror.message = `${error.errorResponse.errmsg}\\n${indent(`failingDocumentId: ${error.errorResponse.errInfo?.failingDocumentId}\\nschemaRulesNotSatisfied: ${JSON.stringify(error.errorResponse.errInfo?.details?.schemaRulesNotSatisfied, null, \" \")}`, \" \")}`;\n\t\n\treturn error;\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export function uid(prefix: string | undefined = \"\", postfix: string | undefined = \"\") {\n\treturn `${prefix}${Date.now().toString(36)}${Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36)}${postfix}`;\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n", "export const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const pingTsSymbol = Symbol(\"pingTs\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { debounce, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient<WSSC extends WSServerClient = any> extends WebSocket {\n\ton(event: \"close\", listener: (this: WSSC, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: WSSC, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: WSSC, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: WSSC, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: WSSC) => void): this;\n\ton(event: \"ping\" | \"pong\", listener: (this: WSSC, data: Buffer) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<WSSC>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[defibSymbol] = WSServerClient.makeDefib.call(this);\n\t\n\tlatency = 0;\n\t\n\t[pingTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.response}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps));\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeDefib(this: WSServerClient<any>) {\n\t\treturn debounce(() => this.terminate(), heartbeatInterval + heartbeatGap);\n\t}\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient<any>) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[pingTsSymbol] = Date.now();\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, heartbeatInterval);\n\t}\n\t\n}\n"],
5
+ "mappings": "AAEA,OAAS,mBAAAA,MAAqD,KCFxD,SAAUC,GAAI,CAAU,CCuBxB,SAAUC,EAAiBC,EAA4BC,EAAQ,EAAGC,EAAmB,CAAA,EAAE,CAC5F,GAAI,CAAE,QAAAC,EAAU,GAAO,SAAAC,EAAW,EAAI,EAAKF,EACrC,CAAE,QAAAG,EAAU,GAAQ,EAAKH,EAE3BI,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEEC,EAAU,SAAW,CAE1B,IAAMC,EAAI,KAAK,IAAG,EAEdA,GAAKP,GACRF,EAAU,OACVE,EAAM,OAC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AAgBmB,EAAO,aAAaA,CAAI,GAAK,EAAE,IAAIA,GAAQE,EAAe,OAAS,EAAE,GAAGA,EAAe,WAAWA,CAAY,IAAM,EAAE,EACvI,CACD,CAEArB,EAAKU,CAAW,EAAE,MAAM,EACxB,cAAcV,EAAKW,CAAuB,CAAC,EAE3C,KAAK,KAAK,eAAgBX,CAAI,EAC9B,KAAK,KAAK,gBAAiBA,CAAI,CAEhC,CAGA,OAAO,UAAwC,CAAE,IAAAsB,CAAI,EAA6D,CACjH,MAAO,CACN,GAAGC,EAAWD,CAAG,CAClB,CACD,CAED",
6
+ "names": ["WebSocketServer", "noop", "debounce", "callback", "limit", "options", "leading", "trailing", "maxWait", "timeout", "maxWaitTimeout", "end", "context", "args", "initial", "final", "result", "expired", "n", "debounced", "maxWaitExpired", "run", "_args", "resolve", "noop", "shouldRun", "indent", "string", "indentation", "times", "prefix", "line", "isMongoServerError", "error", "handleMongoError", "indent", "howmuch", "number", "one", "two", "five", "shouldPrintNumber", "u", "d", "uid", "prefix", "postfix", "createServer", "getRemoteAddress", "resolveSSL", "showServerListeningMessage", "requestHeaders", "heartbeatIntervalSymbol", "defibSymbol", "pingTsSymbol", "WebSocket", "WSServerClient", "_WSServerClient", "WebSocket", "event", "listener", "defibSymbol", "pingTsSymbol", "heartbeatIntervalSymbol", "args", "id", "uid", "eventName", "requestHeaders", "resolve", "reject", "error", "result", "message", "restProps", "debounce", "WSServer", "_WSServer", "WebSocketServer", "options", "_", "port", "server", "createServer", "wssOptions", "WSServerClient", "resolve", "showServerListeningMessage", "#handleConnection", "requestHeaders", "#handleRequest", "error", "event", "listener", "#requestListeners", "kind", "wssc", "id", "rest", "result", "requestError", "handleMongoError", "message", "restProps", "request", "terminate", "defibSymbol", "heartbeatIntervalSymbol", "getRemoteAddress", "data", "#handleClientMessage", "#handleClientError", "args", "#handleClientClose", "pingTsSymbol", "code", "reason", "reasonString", "ssl", "resolveSSL"]
7
7
  }
@@ -10,6 +10,6 @@ export type Options<WSSC extends WSServerClient> = Omit<ServerOptions<typeof WSS
10
10
  new (...args: any[]): WSSC;
11
11
  };
12
12
  };
13
- export type RequestListener<WSSC extends WSServerClient> = (wscc: WSSC, ...args: any[]) => any | Promise<any>;
13
+ export type RequestListener<WSSC extends WSServerClient> = (wscc: WSSC, ...args: any[]) => Promise<any> | any;
14
14
  export type CompatibleListener = () => void;
15
15
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMvD,MAAM,MAAM,OAAO,CAAC,IAAI,SAAS,cAAc,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,cAAc,CAAC,EAAE,MAAM,CAAC,GAAG;IACvG,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACrB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,cAAc,GAAG;QACnC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;KAC3B,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,cAAc,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAE9G,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMvD,MAAM,MAAM,OAAO,CAAC,IAAI,SAAS,cAAc,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,cAAc,CAAC,EAAE,MAAM,CAAC,GAAG;IACvG,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACrB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,cAAc,GAAG;QACnC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;KAC3B,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,cAAc,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAE9G,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "insite-ws",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "inSite WebSockets",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./server": "./dist/server/index.js",
8
8
  "./client": "./dist/client/index.js"
9
9
  },
10
- "packageManager": "bun@1.2.3",
10
+ "packageManager": "bun@1.2.7",
11
11
  "scripts": {
12
12
  "test": "echo \"Error: no test specified\" && exit 1",
13
13
  "build": "bun .conveyer.js",
@@ -25,16 +25,16 @@
25
25
  "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@nesvet/n": "^1.1.24",
28
+ "@nesvet/n": "^1.1.28",
29
29
  "eventemitter3": "^5.0.1",
30
- "insite-common": "^2.2.0",
30
+ "insite-common": "^2.2.2",
31
31
  "ws": "^8.18.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@nesvet/conveyer": "^2.4.3",
35
- "@nesvet/eslint-config": "^2.0.48",
36
- "@types/node": "^22.13.5",
37
- "@types/ws": "^8.5.14",
38
- "typescript": "^5.7.3"
34
+ "@nesvet/conveyer": "^2.5.1",
35
+ "@nesvet/eslint-config": "^2.0.51",
36
+ "@types/node": "^22.13.14",
37
+ "@types/ws": "^8.18.0",
38
+ "typescript": "^5.8.2"
39
39
  }
40
40
  }
@@ -1,3 +0,0 @@
1
- import type { IncomingMessage } from "node:http";
2
- export declare function getRemoteAddress(request: IncomingMessage): string;
3
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAyBjD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,UA2BxD"}