wspromisify 2.11.3 → 3.0.0

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.
package/dist/bundle.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=Symbol("Placeholder"),t=t=>{let n=0;for(const s of t)s!==e&&n++;return n},n=(t,n)=>{const s=t.length,i=t.slice(),o=n.length;let r=o,l=0;for(;r&&l<s;l++)i[l]===e&&(i[l]=n[o-r],r--);for(l=s;r;l++,r--)i[l]=n[o-r];return i},s=(e,i,o)=>{const r=e.length-i.length-t(o);if(r<1)return e(...n(i,o));{const t=(...t)=>s(e,n(i,o),t);return t.$args_left=r,t}},i=e=>(...n)=>e.length>t(n)?s(e,[],n):e(...n);function o(t){return function(n,...s){return s.length>0?n===e?(t=>function(n){return n===e?t:t(n)})((e=>t(e,s[0]))):t(n,s[0]):e=>t(n,e)}}function r(e){return i(e)}const l=e=>e.length,c=/^(.*?)(8|16|32|64)(Clamped)?Array$/,u=void 0,a=1/0,h=e=>typeof e,d=e=>null===e,f=e=>"number"==h(e);const p=e=>d(e)||(e=>e===u)(e),g={u:"U",b:"B",n:"N",s:"S",f:"F"},m=Symbol(),y=e=>{const t=h(e);return"object"===t?d(e)?"Null":e.constructor.name:g[t[0]]+t.slice(1)},_=o(((e,t)=>y(t)===e)),w=o(((e,t)=>e===t)),b=o(((e,t)=>{const n=y(e);if(w(n,y(t))&&(w(n,"Object")||w(n,"Array")||(e=>c.test(e))(n))){if(d(e)||d(t))return w(e,t);if(w(e,t))return!0;for(const n of[e,t])for(const s in n)if(!(w(n,t)&&s in e||w(n,e)&&s in t&&b(e[s],t[s])))return!1;return!0}return w(e,t)})),k=o(((e,t)=>(t.push(e),t))),S=r(((e,t,n)=>n.reduce(e,t))),v=o(((e,t)=>{const n=(e=>Array.isArray(e))(t);let s,i;n&&(s=0,i=[]);for(let s in t)e(t[s],s)||(n?i.push(+s):delete t[s]);if(n)for(const e of i)t.splice(e-s++,1);return t})),P=i(((e,t,n,s)=>e(s)?t(s):n(s))),E=(...t)=>(...n)=>{let s,i=!0;for(let o=l(t)-1;o>-1;o--)i?(i=!1,s=t[o](...n)):s=s===e?t[o]():t[o](s);return s},A=o(((e,t)=>t[e])),C=r(((e,t,n)=>n.slice(e,f(t)?t:a))),j=A(0);C(1,a);const N=o(((e,t)=>t.find(e))),W=e=>()=>e,$=o(((e,t)=>(e(t),t))),q=W(!0),O=W(!1),T=o(((e,t)=>t(...e))),x=e=>(...t)=>{const n=e(...t),s=function(e){return"function"===h(e)}(n);return s&&n.$args_left?x(n):(e=>!e)(n)},z=o(((e,t)=>S(((t,n)=>N((t=>e(n,t)),t)?t:k(n,t)),[],t)));z(b);const Q=e=>{let t,n=!1;return function(...s){return n?t:(n=!0,t=e(...s))}},R=(e,t,n)=>l(t)?p(n)?e:E((s=>s in n?R(e,C(1,a,t),n[s]):e),j)(t):n,B=r(R);B(u),E(P(b(m),O,q),B(m));const M=r(((e,t,n)=>t(n)&&e(n))),I=x,L=Symbol("Placeholder"),D=e=>{let t=0;for(const n of e)n!==L&&t++;return t},U=(e,t)=>{const n=e.length,s=e.slice(),i=t.length;let o=i,r=0;for(;o&&r<n;r++)s[r]===L&&(s[r]=t[i-o],o--);for(r=n;o;r++,o--)s[r]=t[i-o];return s},F=(e,t,n)=>{const s=e.length-t.length-D(n);if(s<1)return e(...U(t,n));{const i=(...s)=>F(e,U(t,n),s);return i.$args_left=s,i}},J=e=>(...t)=>e.length>D(t)?F(e,[],t):e(...t);function G(e){return function(t,...n){return n.length>0?t===L?(e=>function(t){return t===L?e:e(t)})((t=>e(t,n[0]))):e(t,n[0]):n=>e(t,n)}}function H(e){return J(e)}const K=e=>e.length,V=/^(.*?)(8|16|32|64)(Clamped)?Array$/,X=void 0,Y=1/0,Z=e=>typeof e,ee=e=>null===e,te={u:"U",b:"B",n:"N",s:"S",f:"F"},ne=Symbol(),se=e=>{const t=Z(e);return"object"===t?ee(e)?"Null":e.constructor.name:te[t[0]]+t.slice(1)},ie=G(((e,t)=>se(t)===e)),oe=G(((e,t)=>e===t)),re=G(((e,t)=>{const n=se(e);if(oe(n,se(t))&&(oe(n,"Object")||oe(n,"Array")||(s=n,V.test(s)))){if(ee(e)||ee(t))return oe(e,t);if(oe(e,t))return!0;for(const n of[e,t])for(const s in n)if(!(oe(n,t)&&s in e||oe(n,e)&&s in t&&re(e[s],t[s])))return!1;return!0}var s;return oe(e,t)})),le=G(((e,t)=>(t.push(e),t))),ce=H(((e,t,n)=>n.reduce(e,t))),ue=J(((e,t,n,s)=>e(s)?t(s):n(s))),ae=H(((e,t,n)=>ue(e,t,ye,n))),he=(...e)=>(...t)=>{let n,s=!0;for(let i=K(e)-1;i>-1;i--)s?(s=!1,n=e[i](...t)):n=n===L?e[i]():e[i](n);return n},de=G(((e,t)=>t[e])),fe=H(((e,t,n)=>n.slice(e,(e=>"number"==Z(e))(t)?t:Y))),pe=de(0);fe(1,Y);const ge=G(((e,t)=>t.find(e))),me=e=>()=>e,ye=e=>e,_e=G(((e,t)=>t.split(e))),we=me(!0),be=me(!1),ke=G(((e,t)=>ce(((t,n)=>ge((t=>e(n,t)),t)?t:le(n,t)),[],t)))(re),Se=(e,t,n)=>K(t)?(e=>ee(e)||(e=>e===X)(e))(n)?e:he((s=>s in n?Se(e,fe(1,Y,t),n[s]):e),pe)(t):n,ve=H(Se);ve(X),he(ue(re(ne),be,we),ve(ne));const Pe=G(((e,t)=>t.map(e))),{floor:Ee}=Math,Ae="0123456789abcdefghijklmnopqrstuvwxyz",Ce=ie("String"),je=ae(Ce,_e("")),Ne=he((e=>Object.fromEntries(e)),Pe(((e,t)=>[e,t])),je);class We{is_str;delim;abc;abclen;c2pos;standard;setABC(e,t=""){if(this.is_str=Ce(e),this.delim=t,!he(oe(K(n=e)),K,ke,je)(n))throw new Error("Not all chars are unique!");var n;this.abc=e,this.abclen=K(e),this.standard=!!this.is_str&&Ae.startsWith(e),this.c2pos=Ne(e)}zip(e){const{abc:t,abclen:n,delim:s}=this;let i="",o=!0;for(;e>0;)i=t[e%n]+(o?"":s)+i,e=Ee(e/n),o=!1;return i||"0"}unzip(e){const{standard:t,abclen:n,c2pos:s,delim:i,is_str:o}=this;if("0"===e)return 0;if(t)return parseInt(e,n);const r=o?e:e.split(i),l=K(r);let c=0;for(let e=0;e<l;e++)c+=s[r[e]]*n**(l-e-1);return c}constructor(e,t){t?this.setABC(e,t):this.setABC(e||Ae+"ABCDEFGHIJKLMNOPQRSTUVWXYZ")}}const $e=new We;$e.setABC.bind($e),$e.zip.bind($e),$e.unzip.bind($e);const qe=(()=>{try{return WebSocket||null}catch{return null}})(),Oe=(e,t,n)=>e.addEventListener(t,n),Te=(e,t)=>setTimeout(t,e),xe={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,reconnection_attempts:1/0,max_idle_time:1/0,lazy:!1,socket:null,adapter:(e,t)=>new WebSocket(e,t),encode:(e,t,{server:n})=>JSON.stringify({[n.id_key]:e,[n.data_key]:t}),decode:e=>JSON.parse(e),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"},ping:{interval:55,content:{}}},{random:ze}=Math,Qe=new We,Re=T([]),Be=M(_("Number"),I(isNaN)),Me={_is_ping:!0},Ie=e=>e&&clearTimeout(e),Le=e=>{const t=Qe.zip(2147483637*ze()|0);return t in e?Le(e):t};class De{ws=null;intentionally_closed=!1;reconnect_timeout=null;queue={};onReadyQueue=[];onCloseQueue=[];handlers={open:[],close:[],message:[],error:[],timeout:[]};config={};ping_timer=null;idle_timer=null;get opened(){return 1===this.ws?.readyState}init_flush(){v(O,this.queue)}call(e,...t){for(const n of this.handlers[e])n(...t)}log(e,t=null,n=null){const{config:s}=this;setTimeout((()=>{null===n?s.timer?s.log(e,null,t):s.log(e,t):s.log(e,n,t)}))}resetPing(){const{config:{ping:e},ping_timer:t}=this;e&&(p(t)||clearTimeout(t),this.ping_timer=Te(1e3*e.interval,(async()=>{const{ping_timer:t,opened:n}=this;n?(await this.send(e.content,Me),this.resetPing()):clearTimeout(t)})))}resetIdle(){const{config:{max_idle_time:e},idle_timer:t}=this;e!==1/0&&(p(t)||clearTimeout(t),this.idle_timer=Te(1e3*e,(()=>this.opened&&this.close())))}initSocket(e){const{queue:t,config:n}=this;this.ws=e,this.onReadyQueue.forEach((e=>e())),this.onReadyQueue.splice(0);const{id_key:s,data_key:i}=n.server;this.call("open",e);for(const n in t)e.send(t[n].msg);null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),this.resetPing(),this.resetIdle(),Oe(e,"close",(async(...e)=>{this.ws=null,this.onCloseQueue.forEach(Re),this.onCloseQueue.splice(0),this.call("close",...e);let{reconnect:t,reconnection_attempts:s}=n;if(Be(t)){const e=async()=>{if(this.intentionally_closed||!s)return;s--,this.log("reconnect"),p(this.ws)||(this.ws.close(),this.ws=null);const n=await this.connect();p(n)||(this.reconnect_timeout=setTimeout(e,1e3*t))};e()}})),Oe(e,"message",(e=>{try{const t=n.decode(e.data);this.call("message",{...e,data:t});let o=!1;if(_("Object",t)&&s in t){const e=this.queue[t[s]];if(e){const n=e.sent_time?Date.now()-e.sent_time:null;this.log("message",t[i],n),e.ff(t[i]),o=!0}}o||this.log("message-ext",t)}catch(t){console.error(t,`WSP: Decode error. Got: ${e.data}`)}this.resetPing()}))}opening=!1;connect(){return new Promise((e=>{if(this.opened||this.opening)return e(null);this.opening=!0;const t=this.config,n=t.socket||t.adapter(t.url,t.protocols);if(!n||n.readyState>1)return this.opening=!1,this.ws=null,this.log("error","ready() on closing or closed state! status 2."),e(2);const s=Q((t=>{this.opening=!1,e(t)}));Oe(n,"error",Q((e=>{this.ws=null,this.log("error","status 3. Err: "+(e.message||e)),this.call("error",e),s(3)}))),n.readyState?(this.initSocket(n),s(null)):Oe(n,"open",Q((()=>{this.log("open"),this.initSocket(n),s(null)})))}))}get socket(){return this.ws}async ready(){return new Promise((e=>{this.config.lazy||this.opened?e():this.onReadyQueue.push(e)}))}on(e,t,n=q,s=!1){const i=e=>n(e)&&t(e);return s?Oe(this.ws,e,i):this.handlers[e].push(i),i}off(e,t,n=!1){if(n)return((e,t,n)=>e.removeEventListener(t,n))(this.ws,e,t);const s=this.handlers[e],i=s.indexOf(t);~i&&s.splice(i,1)}async close(){return new Promise(((e,t)=>{null===this.ws?t("WSP: closing a non-inited socket!"):(this.onCloseQueue.push((()=>{this.init_flush(),e(null)})),this.ws.close(),this.ws=null,this.intentionally_closed=!0)}))}open(){if(!this.opened)return this.intentionally_closed=!1,this.connect()}addEventListener(e,t,n={}){return this.on(e,t,n.predicate,n.raw)}removeEventListener(e,t,n={}){return this.off(e,t,n.raw)}async prepareMessage(e,t={}){this.log(t._is_ping?"ping":"send",e);const{config:n,queue:s}=this,{pipes:i,server:{data_key:o}}=n,{top:r,_is_ping:l}=t,c=Le(s);if("object"==typeof r&&r[o])throw new Error(`Attempting to set data key/token via ${t._is_ping?"ping":"send"}() options!`);for(const t of i)e=t(e);const[u,a]=await Promise.all([n.encode(c,e,n),this.connect()]);if(a)throw new Error("ERR while opening connection #"+a);const h=$((()=>delete this.queue[c]));return{id:c,msg:u,timeout:t=>Te(n.timeout,(()=>{c in s&&(this.call("timeout",e),t({"Websocket timeout expired":n.timeout,"for the message":e}),h())})),cleanup:h,send:()=>this.opened&&(this.ws.send(u),this.resetPing(),!l&&this.resetIdle())}}async send(e,t={}){const{id:n,msg:s,timeout:i,cleanup:o,send:r}=await this.prepareMessage(e,t),{queue:l,config:c}=this;return new Promise(((e,t)=>{const o=i(t);l[n]={msg:s,data_type:c.data_type,sent_time:c.timer?Date.now():null,ff(t){Ie(o),e(t)}},r()})).finally(o)}async*stream(e,t={}){const{id:n,msg:s,timeout:i,cleanup:o,send:r}=await this.prepareMessage(e,t),{queue:l,config:c}=this;let u,a=!1,h=null;for(l[n]={msg:s,ff:e=>{e?.done&&(delete e.done,a=!0,setTimeout(o)),u(e)},data_type:c.data_type,sent_time:c.timer?Date.now():null},r();!a;)yield await new Promise(((e,t)=>{h=i(t),u=e})).catch((e=>o(e))).finally((()=>{Ie(h),h=null}))}constructor(e={}){this.config=(e=>{if(null===qe&&!("adapter"in e))throw new Error("\n This platform has no native WebSocket implementation.\n Please use 'ws' package as an adapter.\n See https://github.com/houd1ni/WebsocketPromisify/issues/23\n ");const t=Object.assign({},xe,e),n=t.url;if("/"==n[0])try{const e=location.protocol.includes("s:")?"wss":"ws";t.url=`${e}://${location.hostname}:${location.port}${n}`}catch(e){throw new Error("WSP: URL starting with / in non-browser environment!")}return t})(e),this.config.lazy||this.connect()}}exports.WebSocketClient=De,exports.default=De;
1
+ "use strict";const t=Symbol("Placeholder"),e=e=>{let n=0;for(const s of e)s!==t&&n++;return n},n=(e,n)=>{const s=e.length,i=e.slice(),r=n.length;let o=r,c=0;for(;o&&c<s;c++)i[c]===t&&(i[c]=n[r-o],o--);for(c=s;o;c++,o--)i[c]=n[r-o];return i},s=(t,i,r)=>{const o=t.length-i.length-e(r);if(o<1)return t(...n(i,r));{const e=(...e)=>s(t,n(i,r),e);return e.$args_left=o,e}},i=t=>(...n)=>t.length>e(n)?s(t,[],n):t(...n);function r(e){return function(n,...s){return s.length>0?n===t?(e=>function(n){return n===t?e:e(n)})(t=>e(t,s[0])):e(n,s[0]):t=>e(n,t)}}function o(t){return i(t)}const c=t=>t.length,a=/^(.*?)(8|16|32|64)(Clamped)?Array$/,l={__proto__:!0,constructor:!0,prototype:!0},h=void 0,u=1/0,d=t=>typeof t,f=t=>null===t,m=t=>"number"==d(t),p=t=>f(t)||(t=>t===h)(t),g=t=>!(t in l),{isNaN:_}=Number,y={u:"U",b:"B",n:"N",s:"S",f:"F",o:"O"},b=Symbol(),w=t=>y[t[0]]+t.slice(1),k=t=>{const e=d(t);return"object"===e?f(t)?"Null":t.constructor?.name||w(e):"number"===e&&_(t)?"NaN":w(e)},S=r((t,e)=>k(e)===t),v=r((t,e)=>t===e),P=r((t,e)=>{const n=k(t);if(v(n,k(e))&&(v(n,"Object")||v(n,"Array")||(t=>a.test(t))(n))){if(f(t)||f(e))return v(t,e);if(v(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(v(n,e)&&s in t||v(n,t)&&s in e&&P(t[s],e[s])))return!1;return!0}return v(t,e)}),A=t=>()=>t,E=r((t,e)=>(e.push(t),e)),N=o((t,e,n)=>n.reduce(t,e)),j=t=>r((e,n)=>{for(let s in n)if(g(s))switch(k(n[s])){case"Array":if(t>1&&"Array"===k(e[s]))switch(t){case 2:const i=e[s],r=n[s];for(const e in r)i[e]?j(t)(i[e],r[e]):i[e]=r[e];break;case 3:e[s].push(...n[s])}else e[s]=n[s];break;case"Object":if("Object"===k(e[s])){j(t)(e[s],n[s]);break}default:e[s]=n[s]}return e}),q=j(1),z=(t,e)=>{const n=c(e);for(let s=t;s<n;s++)e[s]=e[s+1];return e.length=n-1,e},O=new Set,x=r((t,e)=>{let n,s=c(e);for(let i=0;i<s;i++){n=t(e[i]),O.has(n)?(z(i,e),s--,i--):O.add(n)}return O.clear(),e});x(t=>t);const W=i((t,e,n,s)=>t(s)?e(s):n(s)),$=(...e)=>(...n)=>{let s,i=!0;for(let r=c(e)-1;r>-1;r--)i?(i=!1,s=e[r](...n)):s=s===t?e[r]():e[r](s);return s},C=r((t,e)=>e[t]),M=o((t,e,n)=>n.slice(t,m(e)?e:u)),B=C(0);M(1,u);const T=r((t,e)=>t*e),L=r((t,e)=>e.find(t)),R=r((t,e)=>(t(e),e)),I=A(!0),U=A(!1),Z=()=>{},D=r((t,e)=>N((e,n)=>L(e=>t(n,e),e)?e:E(n,e),[],e));D(P);const F=t=>{let e,n=!1;return function(...s){return n?e:(n=!0,e=t(...s))}},J=(t,e,n)=>c(e)?p(n)?t:$(s=>s in n?J(t,M(1,u,e),n[s]):t,B)(e):n,G=o(J);G(h),$(W(P(b),U,I),G(b));const H=Symbol("Placeholder"),K=t=>{let e=0;for(const n of t)n!==H&&e++;return e},Q=(t,e)=>{const n=t.length,s=t.slice(),i=e.length;let r=i,o=0;for(;r&&o<n;o++)s[o]===H&&(s[o]=e[i-r],r--);for(o=n;r;o++,r--)s[o]=e[i-r];return s},V=(t,e,n)=>{const s=t.length-e.length-K(n);if(s<1)return t(...Q(e,n));{const i=(...s)=>V(t,Q(e,n),s);return i.$args_left=s,i}},X=t=>(...e)=>t.length>K(e)?V(t,[],e):t(...e);function Y(t){return function(e,...n){return n.length>0?e===H?(t=>function(e){return e===H?t:t(e)})(e=>t(e,n[0])):t(e,n[0]):n=>t(e,n)}}function tt(t){return X(t)}const et=t=>t.length,nt=/^(.*?)(8|16|32|64)(Clamped)?Array$/,st=void 0,it=1/0,rt=t=>typeof t,ot=t=>null===t,ct={u:"U",b:"B",n:"N",s:"S",f:"F"},at=Symbol(),lt=t=>{const e=rt(t);return"object"===e?ot(t)?"Null":t.constructor.name:ct[e[0]]+e.slice(1)},ht=Y((t,e)=>lt(e)===t),ut=Y((t,e)=>t===e),dt=Y((t,e)=>{const n=lt(t);if(ut(n,lt(e))&&(ut(n,"Object")||ut(n,"Array")||(s=n,nt.test(s)))){if(ot(t)||ot(e))return ut(t,e);if(ut(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(ut(n,e)&&s in t||ut(n,t)&&s in e&&dt(t[s],e[s])))return!1;return!0}var s;return ut(t,e)}),ft=Y((t,e)=>(e.push(t),e)),mt=tt((t,e,n)=>n.reduce(t,e)),pt=X((t,e,n,s)=>t(s)?e(s):n(s)),gt=tt((t,e,n)=>pt(t,e,vt,n)),_t=(...t)=>(...e)=>{let n,s=!0;for(let i=et(t)-1;i>-1;i--)s?(s=!1,n=t[i](...e)):n=n===H?t[i]():t[i](n);return n},yt=Y((t,e)=>e[t]),bt=tt((t,e,n)=>n.slice(t,(t=>"number"==rt(t))(e)?e:it)),wt=yt(0);bt(1,it);const kt=Y((t,e)=>e.find(t)),St=t=>()=>t,vt=t=>t,Pt=Y((t,e)=>e.split(t)),At=St(!0),Et=St(!1),Nt=Y((t,e)=>mt((e,n)=>kt(e=>t(n,e),e)?e:ft(n,e),[],e))(dt),jt=(t,e,n)=>et(e)?(t=>ot(t)||(t=>t===st)(t))(n)?t:_t(s=>s in n?jt(t,bt(1,it,e),n[s]):t,wt)(e):n,qt=tt(jt);qt(st),_t(pt(dt(at),Et,At),qt(at));const zt=Y((t,e)=>e.map(t)),{floor:Ot}=Math,xt="0123456789abcdefghijklmnopqrstuvwxyz",Wt=ht("String"),$t=gt(Wt,Pt("")),Ct=_t(t=>Object.fromEntries(t),zt((t,e)=>[t,e]),$t);class Mt{is_str;delim;abc;abclen;c2pos;standard;setABC(t,e=""){if(this.is_str=Wt(t),this.delim=e,!_t(ut(et(n=t)),et,Nt,$t)(n))throw new Error("Not all chars are unique!");var n;this.abc=t,this.abclen=et(t),this.standard=!!this.is_str&&xt.startsWith(t),this.c2pos=Ct(t)}zip(t){const{abc:e,abclen:n,delim:s}=this;let i="",r=!0;for(;t>0;)i=e[t%n]+(r?"":s)+i,t=Ot(t/n),r=!1;return i||"0"}unzip(t){const{standard:e,abclen:n,c2pos:s,delim:i,is_str:r}=this;if("0"===t)return 0;if(e)return parseInt(t,n);const o=r?t:t.split(i),c=et(o);let a=0;for(let t=0;t<c;t++)a+=s[o[t]]*n**(c-t-1);return a}constructor(t,e){e?this.setABC(t,e):this.setABC(t||xt+"ABCDEFGHIJKLMNOPQRSTUVWXYZ")}}const Bt=new Mt;Bt.setABC.bind(Bt),Bt.zip.bind(Bt),Bt.unzip.bind(Bt);const Tt=(()=>{try{return WebSocket||null}catch{return null}})(),Lt=(t,e,n)=>t.addEventListener(e,n),Rt=(t,e)=>setTimeout(e,t),{min:It,random:Ut}=Math,Zt=t=>{if(null===Tt&&!("adapter"in t))throw new Error("\n This platform has no native WebSocket implementation.\n Please use 'ws' package as an adapter.\n See https://github.com/houd1ni/WebsocketPromisify/issues/23\n ");const e=q({data_type:"json",log:()=>null,timer:!1,url:"",timeout:1.4,reconnect:{stop_after:45,on_timeout:!0,on_break:!0,time_fn:({base:t,max:e,jitter:n},s)=>It(e,t**(s+Ut()*n)),params:{base:2,max:20,jitter:.1}},max_idle_time:1/0,lazy:!1,socket:null,adapter:(t,e)=>new WebSocket(t,e),encode:(t,e,{server:n})=>JSON.stringify({[n.id_key]:t,[n.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"},ping:{interval:55,out:"ping",in:"pong"}},t),n=e.url;if("/"==n[0])try{const t=location.protocol.includes("s:")?"wss":"ws";e.url=`${t}://${location.hostname}:${location.port}${n}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e},{random:Dt}=Math,Ft=null,Jt=1/0,Gt=Promise.resolve(Ft),Ht="message",Kt="message-ext",Qt=new Mt,Vt=()=>Date.now()/1e3,Xt=T(1e3),Yt=t=>t&&clearTimeout(t),te=t=>null===t,ee=S("String"),ne=S("Object"),se=(t,e,n,s=.5)=>{const i=Xt(s),r=setTimeout(()=>{const s=t.indexOf(e);~s&&(t.splice(s),n(`could not close in ${i}ms!`))},1e3*i);t.push((...t)=>{Yt(r),e(...t)})},ie=t=>{const e=Qt.zip(2147483637*Dt()|0);return e in t?ie(t):e},re=(t,...e)=>{for(const n of t)n(...e);return t},oe=t=>(t.splice(0),t),ce=(t,e)=>e(t);exports.WebSocketClient=class{ws=Ft;intentionally_closed=!1;reconnect_timeout=Ft;queue={send:new Map,on_ready:[],on_close:[],on_ready_fail:[]};handlers={open:[],close:[],message:[],[Kt]:[],error:[],timeout:[]};config={};ping_timer=Ft;idle_timer=Ft;zombie_timer=Ft;router=ce;get opened(){return 1===this.ws?.readyState}call(t,...e){for(const n of this.handlers[t])n(...e)}log(t,e=Ft,n=Ft){const{config:s}=this;setTimeout(()=>{te(n)?s.timer?s.log(t,Ft,e):s.log(t,e):s.log(t,n,e)})}resetPing(){const{config:{ping:t},ping_timer:e}=this;t&&(Yt(e),this.ping_timer=Rt(Xt(t.interval),async()=>{const{ping_timer:e,opened:n}=this;n?(this.ws.send(t.out),this.resetPing()):Yt(e)}))}resetZombieProbe(){const{config:t}=this;if(t.ping){const e=t.ping.timeout;Yt(this.zombie_timer),e!==1/0&&(this.zombie_timer=Rt(Xt(e||t.timeout),()=>this.close().catch(Z)))}}resetIdle(){const{config:{max_idle_time:t},idle_timer:e}=this;t!==1/0&&(Yt(e),this.idle_timer=Rt(Xt(t),()=>this.opened&&this.close()))}_reconnecting=!1;reconnect_start=0;async reconnect(t=0){if(this._reconnecting&&0===t)return;this.log("reconnect"),this._reconnecting=!0,this.reconnect_start=Vt(),p(this.ws)||this.terminate();const{queue:e}=this;if(t>0&&p(await this.connect()))oe(re(e.on_ready)),oe(e.on_ready_fail),this._reconnecting=!1,this.reconnect_timeout=Ft;else{const{stop_after:n,time_fn:s,params:i}=this.config.reconnect;Vt()-this.reconnect_start>n?(this.terminate(),oe(re(e.on_ready_fail)),oe(e.on_ready),this._reconnecting=!1,this.reconnect_timeout=Ft):this.reconnect_timeout=Rt(Xt(s(i,t)),this.reconnect.bind(this,t+1))}}resetReconnect(){te(this.reconnect_timeout)||(Yt(this.reconnect_timeout),this.reconnect_timeout=Ft)}initSocket(t){const{queue:e,config:n,router:s}=this;this.ws=t,oe(re(this.queue.on_ready));const{id_key:i,data_key:r}=n.server;this.call("open",t);for(const{msg:n}of e.send.values())t.send(n);this.resetReconnect(),this.resetZombieProbe(),this.resetPing(),this.resetIdle(),Lt(t,"close",async(...t)=>{this.ws=Ft,oe(re(e.on_close)),this.call("close",...t),!this.intentionally_closed&&n.reconnect.on_break&&this.reconnect()});const{ping:o}=n,c=t=>{try{const e=n.decode(t),{send:s}=this.queue;let o=!1;if(ne(e)&&i in e){const t=e[i];if(s.has(t)){const n=s.get(t),i=e[r],c=n.sent_time?Vt()-n.sent_time:Ft;this.log(Ht,i,c),n.ff(i),o=!0}}const c=o?Ht:Kt;this.log(c,e),this.call(c,{data:e})}catch(e){console.error(e,`WSP: Decode error. Got: ${t}`)}};Lt(t,Ht,t=>{const e=ee(t.data)?t.data:new Uint8Array(t.data);this.resetZombieProbe(),this.resetPing(),o&&P(e,o.in)||s(e,c)})}_opening=!1;connect(){return this.opened||this._opening||this.opened||this._opening?Gt:new Promise(t=>{this._opening=!0;const e=this.config,n=e.socket||e.adapter(e.url,e.protocols);if(p(n)||n.readyState>1)return this._opening=!1,this.ws=Ft,this.log("error","ready() on closing or closed state! status 2."),t(2);const s=F(e=>{this._opening=!1,t(e)});Lt(n,"error",F(t=>{this.ws=Ft,this.log("error","status 3. Err: "+(t.message||t)),this.call("error",t),s(3)})),n.readyState?(this.initSocket(n),s(Ft)):Lt(n,"open",F(()=>{this.log("open"),this.initSocket(n),s(Ft)}))})}get socket(){return this.ws}async ready(t=Jt){return new Promise((e,n)=>{const{on_ready:s}=this.queue;this.config.lazy||this.opened?e():t===Jt?s.push(e):se(s,e,n)})}on(t,e,n=I,s=!1){const i=t=>n(t)&&e(t);return s?Lt(this.ws,t,i):this.handlers[t].push(i),i}off(t,e,n=!1){if(n)return((t,e,n)=>t.removeEventListener(e,n))(this.ws,t,e);const s=this.handlers[t],i=s.indexOf(e);~i&&s.splice(i,1)}terminate(){this.ws?.close(),this.ws=Ft,this.intentionally_closed=!0}async close(t=.5){return new Promise((e,n)=>{te(this.ws)?e(Ft):(se(this.queue.on_close,e,n,t),this.terminate())})}open(){if(!this.opened)return this.intentionally_closed=!1,this.connect()}addEventListener(t,e,n={}){return this.on(t,e,n.predicate,n.raw)}removeEventListener(t,e,n={}){return this.off(t,e,n.raw)}async prepareMessage(t,e={}){this.log("send",t);const{config:n,queue:{send:s,on_ready_fail:i}}=this,{pipes:r,server:{data_key:o}}=n,{top:c}=e,a=ie(s);if(ne(c)&&o in c)throw new Error("\n Attempting to set data key/token via send() options!\n ");for(const e of r)t=e(t);const[l,h]=await Promise.all([n.encode(a,t,n),this.connect()]);if(h)throw new Error("ERR while opening connection > "+h);const u=c?.timeout||n.timeout,d=R(()=>s.delete(a));return{id:a,msg:l,timeout:e=>Rt(Xt(u),()=>{if(s.has(a)){this.call("timeout",t),d();const s=()=>e({"Websocket timeout expired":u,"for the message":t});n.reconnect.on_timeout?(i.push(s),this.reconnect()):s()}}),cleanup:d,send:()=>this.opened&&(this.ws.send(l),this.resetPing(),this.resetIdle())}}async send(t,e={}){const{id:n,msg:s,timeout:i,cleanup:r,send:o}=await this.prepareMessage(t,e),{queue:{send:c},config:a}=this;return new Promise((t,e)=>{const r=i(e);c.set(n,{msg:s,data_type:a.data_type,sent_time:a.timer?Vt():Ft,ff(e){Yt(r),t(e)}}),o()}).finally(r)}async*stream(t,e={}){const{id:n,msg:s,timeout:i,cleanup:r,send:o}=await this.prepareMessage(t,e),{queue:{send:c},config:a}=this;let l,h=!1,u=Ft;for(c.set(n,{msg:s,ff:t=>{t?.done&&(delete t.done,h=!0,setTimeout(r)),l(t)},data_type:a.data_type,sent_time:a.timer?Vt():Ft}),o();!h;)yield await new Promise((t,e)=>{u=i(e),l=t}).catch(r).finally(()=>Yt(u))}route(t){this.router=t}constructor(t){this.config=Zt(t),this.config.lazy||this.connect()}};
package/dist/bundle.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { AnyFunc } from 'pepka';
4
+
3
5
  declare namespace wsc {
4
6
  interface DataObject {
5
7
  [key: string]: any;
@@ -18,6 +20,11 @@ declare namespace wsc {
18
20
  type Predicate = (data: any) => boolean;
19
21
  type DataPipe = (message: any) => any;
20
22
  type DataType = "json" | "string";
23
+ interface TimeFnParams {
24
+ base: number;
25
+ max: number;
26
+ jitter: number;
27
+ }
21
28
  interface Config {
22
29
  data_type: DataType;
23
30
  log(event: string, time?: number | null, message?: any): void;
@@ -25,8 +32,20 @@ declare namespace wsc {
25
32
  timer: boolean;
26
33
  url: string;
27
34
  timeout: number;
28
- reconnect: number;
29
- reconnection_attempts: number;
35
+ reconnect: {
36
+ stop_after: number;
37
+ on_timeout: boolean;
38
+ on_break: boolean;
39
+ time_fn: import("pepka").AnyFunc<number, [
40
+ params: wsc.TimeFnParams,
41
+ attempt: number
42
+ ]>;
43
+ params: {
44
+ base: number;
45
+ max: number;
46
+ jitter: number;
47
+ };
48
+ };
30
49
  max_idle_time: number;
31
50
  lazy: boolean;
32
51
  socket: Socket | null;
@@ -43,14 +62,15 @@ declare namespace wsc {
43
62
  };
44
63
  ping: {
45
64
  interval: number;
46
- content: any;
47
- };
65
+ timeout?: number;
66
+ in: string | Uint8Array;
67
+ out: string | Uint8Array;
68
+ } | false;
48
69
  }
49
- type UserConfig = Partial<Config>;
70
+ type UserConfig = import("type-fest").PartialDeep<Config> & Pick<Config, "url">;
50
71
  type SendOptions = Partial<{
51
72
  top: any;
52
73
  data_type: DataType;
53
- _is_ping: boolean;
54
74
  }>;
55
75
  interface Message {
56
76
  msg: any;
@@ -59,52 +79,81 @@ declare namespace wsc {
59
79
  sent_time: number | null;
60
80
  }
61
81
  }
62
- export declare class WebSocketClient {
82
+ declare const label_message_ext = "message-ext";
83
+ export type EventHandler<T extends keyof WebSocketEventMap> = AnyFunc<any, [
84
+ WebSocketEventMap[T]
85
+ ]>;
86
+ export type RouteHandler<T> = AnyFunc<any, [
87
+ data: T,
88
+ next: AnyFunc
89
+ ]>;
90
+ export type EventHandlers = {
91
+ open: EventHandler<"open">[];
92
+ close: EventHandler<"close">[];
93
+ error: EventHandler<"error">[];
94
+ message: AnyFunc<any, [
95
+ WebSocketEventMap["message"] & {
96
+ data: any;
97
+ }
98
+ ]>[];
99
+ [label_message_ext]: AnyFunc<any, [
100
+ WebSocketEventMap["message"] & {
101
+ data: any;
102
+ }
103
+ ]>[];
104
+ timeout: AnyFunc<any, [
105
+ data: any
106
+ ]>[];
107
+ };
108
+ export declare class WebSocketClient<T extends Uint8Array | string = string> {
63
109
  private ws;
64
110
  private intentionally_closed;
65
111
  private reconnect_timeout;
66
112
  private queue;
67
- private onReadyQueue;
68
- private onCloseQueue;
69
113
  private handlers;
70
114
  private config;
71
115
  private ping_timer;
72
116
  private idle_timer;
117
+ private zombie_timer;
118
+ private router;
73
119
  private get opened();
74
- private init_flush;
75
120
  private call;
76
121
  private log;
77
122
  private resetPing;
123
+ private resetZombieProbe;
78
124
  private resetIdle;
125
+ private _reconnecting;
126
+ private reconnect_start;
127
+ private reconnect;
128
+ private resetReconnect;
79
129
  private initSocket;
80
- private opening;
130
+ private _opening;
131
+ /** returns status if won't open or null if ok. */
81
132
  private connect;
82
133
  get socket(): wsc.Socket | null;
83
- ready(): Promise<void>;
84
- on(event_name: wsc.WSEvent, handler: wsc.EventHandler, predicate?: wsc.Predicate, raw?: boolean): wsc.EventHandler;
85
- off(event_name: wsc.WSEvent, handler: wsc.EventHandler, raw?: boolean): void;
86
- close(): wsc.AsyncErrCode;
134
+ ready(timeout?: number): Promise<void>;
135
+ on(event_name: keyof EventHandlers, handler: wsc.EventHandler, predicate?: wsc.Predicate, raw?: boolean): wsc.EventHandler;
136
+ off(event_name: keyof EventHandlers, handler: wsc.EventHandler, raw?: boolean): void;
137
+ private terminate;
138
+ close(timeout?: number): wsc.AsyncErrCode;
87
139
  open(): Promise<number | null> | undefined;
88
- addEventListener(e: wsc.WSEvent, cb: wsc.EventHandler, opts?: {
140
+ addEventListener(e: keyof EventHandlers, cb: wsc.EventHandler, opts?: {
89
141
  predicate?: wsc.Predicate;
90
142
  raw?: boolean;
91
143
  }): wsc.EventHandler;
92
- removeEventListener(e: wsc.WSEvent, handler: wsc.EventHandler, opts?: {
144
+ removeEventListener(e: keyof EventHandlers, handler: wsc.EventHandler, opts?: {
93
145
  predicate?: wsc.Predicate;
94
146
  raw?: boolean;
95
147
  }): void;
96
148
  private prepareMessage;
97
- /** .send(your_data) wraps request to server with {id: `hash`, data: `actually your data`},
149
+ /** .send(your_data) wraps request to server with {id: `unique_id`, data: `actually your data`},
98
150
  returns a Promise that will be rejected after a timeout or
99
151
  resolved if server returns the same signature: {id: `same_hash`, data: `response data`}.
100
152
  */
101
153
  send<RequestDataType = any, ResponseDataType = any>(message_data: RequestDataType, opts?: wsc.SendOptions): Promise<ResponseDataType>;
102
154
  stream<RequestDataType = any, ResponseDataType = any>(message_data: RequestDataType, opts?: wsc.SendOptions): AsyncGenerator<ResponseDataType, void, unknown>;
103
- constructor(user_config?: wsc.UserConfig);
155
+ route(handler: RouteHandler<T>): void;
156
+ constructor(user_config: wsc.UserConfig);
104
157
  }
105
158
 
106
- export {
107
- WebSocketClient as default,
108
- };
109
-
110
159
  export {};
package/dist/bundle.mjs CHANGED
@@ -1 +1 @@
1
- const t=Symbol("Placeholder"),e=e=>{let n=0;for(const s of e)s!==t&&n++;return n},n=(e,n)=>{const s=e.length,i=e.slice(),o=n.length;let r=o,l=0;for(;r&&l<s;l++)i[l]===t&&(i[l]=n[o-r],r--);for(l=s;r;l++,r--)i[l]=n[o-r];return i},s=(t,i,o)=>{const r=t.length-i.length-e(o);if(r<1)return t(...n(i,o));{const e=(...e)=>s(t,n(i,o),e);return e.$args_left=r,e}},i=t=>(...n)=>t.length>e(n)?s(t,[],n):t(...n);function o(e){return function(n,...s){return s.length>0?n===t?(e=>function(n){return n===t?e:e(n)})((t=>e(t,s[0]))):e(n,s[0]):t=>e(n,t)}}function r(t){return i(t)}const l=t=>t.length,c=/^(.*?)(8|16|32|64)(Clamped)?Array$/,a=void 0,u=1/0,h=t=>typeof t,d=t=>null===t,f=t=>"number"==h(t);const p=t=>d(t)||(t=>t===a)(t),g={u:"U",b:"B",n:"N",s:"S",f:"F"},m=Symbol(),y=t=>{const e=h(t);return"object"===e?d(t)?"Null":t.constructor.name:g[e[0]]+e.slice(1)},_=o(((t,e)=>y(e)===t)),w=o(((t,e)=>t===e)),b=o(((t,e)=>{const n=y(t);if(w(n,y(e))&&(w(n,"Object")||w(n,"Array")||(t=>c.test(t))(n))){if(d(t)||d(e))return w(t,e);if(w(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(w(n,e)&&s in t||w(n,t)&&s in e&&b(t[s],e[s])))return!1;return!0}return w(t,e)})),k=o(((t,e)=>(e.push(t),e))),S=r(((t,e,n)=>n.reduce(t,e))),v=o(((t,e)=>{const n=(t=>Array.isArray(t))(e);let s,i;n&&(s=0,i=[]);for(let s in e)t(e[s],s)||(n?i.push(+s):delete e[s]);if(n)for(const t of i)e.splice(t-s++,1);return e})),P=i(((t,e,n,s)=>t(s)?e(s):n(s))),E=(...e)=>(...n)=>{let s,i=!0;for(let o=l(e)-1;o>-1;o--)i?(i=!1,s=e[o](...n)):s=s===t?e[o]():e[o](s);return s},A=o(((t,e)=>e[t])),C=r(((t,e,n)=>n.slice(t,f(e)?e:u))),N=A(0);C(1,u);const $=o(((t,e)=>e.find(t))),j=t=>()=>t,q=o(((t,e)=>(t(e),e))),T=j(!0),W=j(!1),z=o(((t,e)=>e(...t))),O=t=>(...e)=>{const n=t(...e),s=function(t){return"function"===h(t)}(n);return s&&n.$args_left?O(n):(t=>!t)(n)},Q=o(((t,e)=>S(((e,n)=>$((e=>t(n,e)),e)?e:k(n,e)),[],e)));Q(b);const R=t=>{let e,n=!1;return function(...s){return n?e:(n=!0,e=t(...s))}},x=(t,e,n)=>l(e)?p(n)?t:E((s=>s in n?x(t,C(1,u,e),n[s]):t),N)(e):n,B=r(x);B(a),E(P(b(m),W,T),B(m));const I=r(((t,e,n)=>e(n)&&t(n))),L=O,M=Symbol("Placeholder"),D=t=>{let e=0;for(const n of t)n!==M&&e++;return e},U=(t,e)=>{const n=t.length,s=t.slice(),i=e.length;let o=i,r=0;for(;o&&r<n;r++)s[r]===M&&(s[r]=e[i-o],o--);for(r=n;o;r++,o--)s[r]=e[i-o];return s},F=(t,e,n)=>{const s=t.length-e.length-D(n);if(s<1)return t(...U(e,n));{const i=(...s)=>F(t,U(e,n),s);return i.$args_left=s,i}},J=t=>(...e)=>t.length>D(e)?F(t,[],e):t(...e);function G(t){return function(e,...n){return n.length>0?e===M?(t=>function(e){return e===M?t:t(e)})((e=>t(e,n[0]))):t(e,n[0]):n=>t(e,n)}}function H(t){return J(t)}const K=t=>t.length,V=/^(.*?)(8|16|32|64)(Clamped)?Array$/,X=void 0,Y=1/0,Z=t=>typeof t,tt=t=>null===t,et={u:"U",b:"B",n:"N",s:"S",f:"F"},nt=Symbol(),st=t=>{const e=Z(t);return"object"===e?tt(t)?"Null":t.constructor.name:et[e[0]]+e.slice(1)},it=G(((t,e)=>st(e)===t)),ot=G(((t,e)=>t===e)),rt=G(((t,e)=>{const n=st(t);if(ot(n,st(e))&&(ot(n,"Object")||ot(n,"Array")||(s=n,V.test(s)))){if(tt(t)||tt(e))return ot(t,e);if(ot(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(ot(n,e)&&s in t||ot(n,t)&&s in e&&rt(t[s],e[s])))return!1;return!0}var s;return ot(t,e)})),lt=G(((t,e)=>(e.push(t),e))),ct=H(((t,e,n)=>n.reduce(t,e))),at=J(((t,e,n,s)=>t(s)?e(s):n(s))),ut=H(((t,e,n)=>at(t,e,yt,n))),ht=(...t)=>(...e)=>{let n,s=!0;for(let i=K(t)-1;i>-1;i--)s?(s=!1,n=t[i](...e)):n=n===M?t[i]():t[i](n);return n},dt=G(((t,e)=>e[t])),ft=H(((t,e,n)=>n.slice(t,(t=>"number"==Z(t))(e)?e:Y))),pt=dt(0);ft(1,Y);const gt=G(((t,e)=>e.find(t))),mt=t=>()=>t,yt=t=>t,_t=G(((t,e)=>e.split(t))),wt=mt(!0),bt=mt(!1),kt=G(((t,e)=>ct(((e,n)=>gt((e=>t(n,e)),e)?e:lt(n,e)),[],e)))(rt),St=(t,e,n)=>K(e)?(t=>tt(t)||(t=>t===X)(t))(n)?t:ht((s=>s in n?St(t,ft(1,Y,e),n[s]):t),pt)(e):n,vt=H(St);vt(X),ht(at(rt(nt),bt,wt),vt(nt));const Pt=G(((t,e)=>e.map(t))),{floor:Et}=Math,At="0123456789abcdefghijklmnopqrstuvwxyz",Ct=it("String"),Nt=ut(Ct,_t("")),$t=ht((t=>Object.fromEntries(t)),Pt(((t,e)=>[t,e])),Nt);class jt{is_str;delim;abc;abclen;c2pos;standard;setABC(t,e=""){if(this.is_str=Ct(t),this.delim=e,!ht(ot(K(n=t)),K,kt,Nt)(n))throw new Error("Not all chars are unique!");var n;this.abc=t,this.abclen=K(t),this.standard=!!this.is_str&&At.startsWith(t),this.c2pos=$t(t)}zip(t){const{abc:e,abclen:n,delim:s}=this;let i="",o=!0;for(;t>0;)i=e[t%n]+(o?"":s)+i,t=Et(t/n),o=!1;return i||"0"}unzip(t){const{standard:e,abclen:n,c2pos:s,delim:i,is_str:o}=this;if("0"===t)return 0;if(e)return parseInt(t,n);const r=o?t:t.split(i),l=K(r);let c=0;for(let t=0;t<l;t++)c+=s[r[t]]*n**(l-t-1);return c}constructor(t,e){e?this.setABC(t,e):this.setABC(t||At+"ABCDEFGHIJKLMNOPQRSTUVWXYZ")}}const qt=new jt;qt.setABC.bind(qt),qt.zip.bind(qt),qt.unzip.bind(qt);const Tt=(()=>{try{return WebSocket||null}catch{return null}})(),Wt=(t,e,n)=>t.addEventListener(e,n),zt=(t,e)=>setTimeout(e,t),Ot={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,reconnection_attempts:1/0,max_idle_time:1/0,lazy:!1,socket:null,adapter:(t,e)=>new WebSocket(t,e),encode:(t,e,{server:n})=>JSON.stringify({[n.id_key]:t,[n.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"},ping:{interval:55,content:{}}},{random:Qt}=Math,Rt=new jt,xt=z([]),Bt=I(_("Number"),L(isNaN)),It={_is_ping:!0},Lt=t=>t&&clearTimeout(t),Mt=t=>{const e=Rt.zip(2147483637*Qt()|0);return e in t?Mt(t):e};class Dt{ws=null;intentionally_closed=!1;reconnect_timeout=null;queue={};onReadyQueue=[];onCloseQueue=[];handlers={open:[],close:[],message:[],error:[],timeout:[]};config={};ping_timer=null;idle_timer=null;get opened(){return 1===this.ws?.readyState}init_flush(){v(W,this.queue)}call(t,...e){for(const n of this.handlers[t])n(...e)}log(t,e=null,n=null){const{config:s}=this;setTimeout((()=>{null===n?s.timer?s.log(t,null,e):s.log(t,e):s.log(t,n,e)}))}resetPing(){const{config:{ping:t},ping_timer:e}=this;t&&(p(e)||clearTimeout(e),this.ping_timer=zt(1e3*t.interval,(async()=>{const{ping_timer:e,opened:n}=this;n?(await this.send(t.content,It),this.resetPing()):clearTimeout(e)})))}resetIdle(){const{config:{max_idle_time:t},idle_timer:e}=this;t!==1/0&&(p(e)||clearTimeout(e),this.idle_timer=zt(1e3*t,(()=>this.opened&&this.close())))}initSocket(t){const{queue:e,config:n}=this;this.ws=t,this.onReadyQueue.forEach((t=>t())),this.onReadyQueue.splice(0);const{id_key:s,data_key:i}=n.server;this.call("open",t);for(const n in e)t.send(e[n].msg);null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),this.resetPing(),this.resetIdle(),Wt(t,"close",(async(...t)=>{this.ws=null,this.onCloseQueue.forEach(xt),this.onCloseQueue.splice(0),this.call("close",...t);let{reconnect:e,reconnection_attempts:s}=n;if(Bt(e)){const t=async()=>{if(this.intentionally_closed||!s)return;s--,this.log("reconnect"),p(this.ws)||(this.ws.close(),this.ws=null);const n=await this.connect();p(n)||(this.reconnect_timeout=setTimeout(t,1e3*e))};t()}})),Wt(t,"message",(t=>{try{const e=n.decode(t.data);this.call("message",{...t,data:e});let o=!1;if(_("Object",e)&&s in e){const t=this.queue[e[s]];if(t){const n=t.sent_time?Date.now()-t.sent_time:null;this.log("message",e[i],n),t.ff(e[i]),o=!0}}o||this.log("message-ext",e)}catch(e){console.error(e,`WSP: Decode error. Got: ${t.data}`)}this.resetPing()}))}opening=!1;connect(){return new Promise((t=>{if(this.opened||this.opening)return t(null);this.opening=!0;const e=this.config,n=e.socket||e.adapter(e.url,e.protocols);if(!n||n.readyState>1)return this.opening=!1,this.ws=null,this.log("error","ready() on closing or closed state! status 2."),t(2);const s=R((e=>{this.opening=!1,t(e)}));Wt(n,"error",R((t=>{this.ws=null,this.log("error","status 3. Err: "+(t.message||t)),this.call("error",t),s(3)}))),n.readyState?(this.initSocket(n),s(null)):Wt(n,"open",R((()=>{this.log("open"),this.initSocket(n),s(null)})))}))}get socket(){return this.ws}async ready(){return new Promise((t=>{this.config.lazy||this.opened?t():this.onReadyQueue.push(t)}))}on(t,e,n=T,s=!1){const i=t=>n(t)&&e(t);return s?Wt(this.ws,t,i):this.handlers[t].push(i),i}off(t,e,n=!1){if(n)return((t,e,n)=>t.removeEventListener(e,n))(this.ws,t,e);const s=this.handlers[t],i=s.indexOf(e);~i&&s.splice(i,1)}async close(){return new Promise(((t,e)=>{null===this.ws?e("WSP: closing a non-inited socket!"):(this.onCloseQueue.push((()=>{this.init_flush(),t(null)})),this.ws.close(),this.ws=null,this.intentionally_closed=!0)}))}open(){if(!this.opened)return this.intentionally_closed=!1,this.connect()}addEventListener(t,e,n={}){return this.on(t,e,n.predicate,n.raw)}removeEventListener(t,e,n={}){return this.off(t,e,n.raw)}async prepareMessage(t,e={}){this.log(e._is_ping?"ping":"send",t);const{config:n,queue:s}=this,{pipes:i,server:{data_key:o}}=n,{top:r,_is_ping:l}=e,c=Mt(s);if("object"==typeof r&&r[o])throw new Error(`Attempting to set data key/token via ${e._is_ping?"ping":"send"}() options!`);for(const e of i)t=e(t);const[a,u]=await Promise.all([n.encode(c,t,n),this.connect()]);if(u)throw new Error("ERR while opening connection #"+u);const h=q((()=>delete this.queue[c]));return{id:c,msg:a,timeout:e=>zt(n.timeout,(()=>{c in s&&(this.call("timeout",t),e({"Websocket timeout expired":n.timeout,"for the message":t}),h())})),cleanup:h,send:()=>this.opened&&(this.ws.send(a),this.resetPing(),!l&&this.resetIdle())}}async send(t,e={}){const{id:n,msg:s,timeout:i,cleanup:o,send:r}=await this.prepareMessage(t,e),{queue:l,config:c}=this;return new Promise(((t,e)=>{const o=i(e);l[n]={msg:s,data_type:c.data_type,sent_time:c.timer?Date.now():null,ff(e){Lt(o),t(e)}},r()})).finally(o)}async*stream(t,e={}){const{id:n,msg:s,timeout:i,cleanup:o,send:r}=await this.prepareMessage(t,e),{queue:l,config:c}=this;let a,u=!1,h=null;for(l[n]={msg:s,ff:t=>{t?.done&&(delete t.done,u=!0,setTimeout(o)),a(t)},data_type:c.data_type,sent_time:c.timer?Date.now():null},r();!u;)yield await new Promise(((t,e)=>{h=i(e),a=t})).catch((t=>o(t))).finally((()=>{Lt(h),h=null}))}constructor(t={}){this.config=(t=>{if(null===Tt&&!("adapter"in t))throw new Error("\n This platform has no native WebSocket implementation.\n Please use 'ws' package as an adapter.\n See https://github.com/houd1ni/WebsocketPromisify/issues/23\n ");const e=Object.assign({},Ot,t),n=e.url;if("/"==n[0])try{const t=location.protocol.includes("s:")?"wss":"ws";e.url=`${t}://${location.hostname}:${location.port}${n}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e})(t),this.config.lazy||this.connect()}}export{Dt as WebSocketClient,Dt as default};
1
+ const t=Symbol("Placeholder"),e=e=>{let n=0;for(const s of e)s!==t&&n++;return n},n=(e,n)=>{const s=e.length,i=e.slice(),r=n.length;let o=r,c=0;for(;o&&c<s;c++)i[c]===t&&(i[c]=n[r-o],o--);for(c=s;o;c++,o--)i[c]=n[r-o];return i},s=(t,i,r)=>{const o=t.length-i.length-e(r);if(o<1)return t(...n(i,r));{const e=(...e)=>s(t,n(i,r),e);return e.$args_left=o,e}},i=t=>(...n)=>t.length>e(n)?s(t,[],n):t(...n);function r(e){return function(n,...s){return s.length>0?n===t?(e=>function(n){return n===t?e:e(n)})(t=>e(t,s[0])):e(n,s[0]):t=>e(n,t)}}function o(t){return i(t)}const c=t=>t.length,a=/^(.*?)(8|16|32|64)(Clamped)?Array$/,l={__proto__:!0,constructor:!0,prototype:!0},h=void 0,u=1/0,d=t=>typeof t,f=t=>null===t,m=t=>"number"==d(t),p=t=>f(t)||(t=>t===h)(t),g=t=>!(t in l),{isNaN:_}=Number,y={u:"U",b:"B",n:"N",s:"S",f:"F",o:"O"},b=Symbol(),w=t=>y[t[0]]+t.slice(1),k=t=>{const e=d(t);return"object"===e?f(t)?"Null":t.constructor?.name||w(e):"number"===e&&_(t)?"NaN":w(e)},S=r((t,e)=>k(e)===t),v=r((t,e)=>t===e),P=r((t,e)=>{const n=k(t);if(v(n,k(e))&&(v(n,"Object")||v(n,"Array")||(t=>a.test(t))(n))){if(f(t)||f(e))return v(t,e);if(v(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(v(n,e)&&s in t||v(n,t)&&s in e&&P(t[s],e[s])))return!1;return!0}return v(t,e)}),A=t=>()=>t,E=r((t,e)=>(e.push(t),e)),N=o((t,e,n)=>n.reduce(t,e)),j=t=>r((e,n)=>{for(let s in n)if(g(s))switch(k(n[s])){case"Array":if(t>1&&"Array"===k(e[s]))switch(t){case 2:const i=e[s],r=n[s];for(const e in r)i[e]?j(t)(i[e],r[e]):i[e]=r[e];break;case 3:e[s].push(...n[s])}else e[s]=n[s];break;case"Object":if("Object"===k(e[s])){j(t)(e[s],n[s]);break}default:e[s]=n[s]}return e}),q=j(1),z=(t,e)=>{const n=c(e);for(let s=t;s<n;s++)e[s]=e[s+1];return e.length=n-1,e},O=new Set,x=r((t,e)=>{let n,s=c(e);for(let i=0;i<s;i++){n=t(e[i]),O.has(n)?(z(i,e),s--,i--):O.add(n)}return O.clear(),e});x(t=>t);const $=i((t,e,n,s)=>t(s)?e(s):n(s)),W=(...e)=>(...n)=>{let s,i=!0;for(let r=c(e)-1;r>-1;r--)i?(i=!1,s=e[r](...n)):s=s===t?e[r]():e[r](s);return s},M=r((t,e)=>e[t]),B=o((t,e,n)=>n.slice(t,m(e)?e:u)),C=M(0);B(1,u);const T=r((t,e)=>t*e),L=r((t,e)=>e.find(t)),R=r((t,e)=>(t(e),e)),I=A(!0),U=A(!1),Z=()=>{},D=r((t,e)=>N((e,n)=>L(e=>t(n,e),e)?e:E(n,e),[],e));D(P);const F=t=>{let e,n=!1;return function(...s){return n?e:(n=!0,e=t(...s))}},J=(t,e,n)=>c(e)?p(n)?t:W(s=>s in n?J(t,B(1,u,e),n[s]):t,C)(e):n,G=o(J);G(h),W($(P(b),U,I),G(b));const H=Symbol("Placeholder"),K=t=>{let e=0;for(const n of t)n!==H&&e++;return e},Q=(t,e)=>{const n=t.length,s=t.slice(),i=e.length;let r=i,o=0;for(;r&&o<n;o++)s[o]===H&&(s[o]=e[i-r],r--);for(o=n;r;o++,r--)s[o]=e[i-r];return s},V=(t,e,n)=>{const s=t.length-e.length-K(n);if(s<1)return t(...Q(e,n));{const i=(...s)=>V(t,Q(e,n),s);return i.$args_left=s,i}},X=t=>(...e)=>t.length>K(e)?V(t,[],e):t(...e);function Y(t){return function(e,...n){return n.length>0?e===H?(t=>function(e){return e===H?t:t(e)})(e=>t(e,n[0])):t(e,n[0]):n=>t(e,n)}}function tt(t){return X(t)}const et=t=>t.length,nt=/^(.*?)(8|16|32|64)(Clamped)?Array$/,st=void 0,it=1/0,rt=t=>typeof t,ot=t=>null===t,ct={u:"U",b:"B",n:"N",s:"S",f:"F"},at=Symbol(),lt=t=>{const e=rt(t);return"object"===e?ot(t)?"Null":t.constructor.name:ct[e[0]]+e.slice(1)},ht=Y((t,e)=>lt(e)===t),ut=Y((t,e)=>t===e),dt=Y((t,e)=>{const n=lt(t);if(ut(n,lt(e))&&(ut(n,"Object")||ut(n,"Array")||(s=n,nt.test(s)))){if(ot(t)||ot(e))return ut(t,e);if(ut(t,e))return!0;for(const n of[t,e])for(const s in n)if(!(ut(n,e)&&s in t||ut(n,t)&&s in e&&dt(t[s],e[s])))return!1;return!0}var s;return ut(t,e)}),ft=Y((t,e)=>(e.push(t),e)),mt=tt((t,e,n)=>n.reduce(t,e)),pt=X((t,e,n,s)=>t(s)?e(s):n(s)),gt=tt((t,e,n)=>pt(t,e,vt,n)),_t=(...t)=>(...e)=>{let n,s=!0;for(let i=et(t)-1;i>-1;i--)s?(s=!1,n=t[i](...e)):n=n===H?t[i]():t[i](n);return n},yt=Y((t,e)=>e[t]),bt=tt((t,e,n)=>n.slice(t,(t=>"number"==rt(t))(e)?e:it)),wt=yt(0);bt(1,it);const kt=Y((t,e)=>e.find(t)),St=t=>()=>t,vt=t=>t,Pt=Y((t,e)=>e.split(t)),At=St(!0),Et=St(!1),Nt=Y((t,e)=>mt((e,n)=>kt(e=>t(n,e),e)?e:ft(n,e),[],e))(dt),jt=(t,e,n)=>et(e)?(t=>ot(t)||(t=>t===st)(t))(n)?t:_t(s=>s in n?jt(t,bt(1,it,e),n[s]):t,wt)(e):n,qt=tt(jt);qt(st),_t(pt(dt(at),Et,At),qt(at));const zt=Y((t,e)=>e.map(t)),{floor:Ot}=Math,xt="0123456789abcdefghijklmnopqrstuvwxyz",$t=ht("String"),Wt=gt($t,Pt("")),Mt=_t(t=>Object.fromEntries(t),zt((t,e)=>[t,e]),Wt);class Bt{is_str;delim;abc;abclen;c2pos;standard;setABC(t,e=""){if(this.is_str=$t(t),this.delim=e,!_t(ut(et(n=t)),et,Nt,Wt)(n))throw new Error("Not all chars are unique!");var n;this.abc=t,this.abclen=et(t),this.standard=!!this.is_str&&xt.startsWith(t),this.c2pos=Mt(t)}zip(t){const{abc:e,abclen:n,delim:s}=this;let i="",r=!0;for(;t>0;)i=e[t%n]+(r?"":s)+i,t=Ot(t/n),r=!1;return i||"0"}unzip(t){const{standard:e,abclen:n,c2pos:s,delim:i,is_str:r}=this;if("0"===t)return 0;if(e)return parseInt(t,n);const o=r?t:t.split(i),c=et(o);let a=0;for(let t=0;t<c;t++)a+=s[o[t]]*n**(c-t-1);return a}constructor(t,e){e?this.setABC(t,e):this.setABC(t||xt+"ABCDEFGHIJKLMNOPQRSTUVWXYZ")}}const Ct=new Bt;Ct.setABC.bind(Ct),Ct.zip.bind(Ct),Ct.unzip.bind(Ct);const Tt=(()=>{try{return WebSocket||null}catch{return null}})(),Lt=(t,e,n)=>t.addEventListener(e,n),Rt=(t,e)=>setTimeout(e,t),{min:It,random:Ut}=Math,Zt=t=>{if(null===Tt&&!("adapter"in t))throw new Error("\n This platform has no native WebSocket implementation.\n Please use 'ws' package as an adapter.\n See https://github.com/houd1ni/WebsocketPromisify/issues/23\n ");const e=q({data_type:"json",log:()=>null,timer:!1,url:"",timeout:1.4,reconnect:{stop_after:45,on_timeout:!0,on_break:!0,time_fn:({base:t,max:e,jitter:n},s)=>It(e,t**(s+Ut()*n)),params:{base:2,max:20,jitter:.1}},max_idle_time:1/0,lazy:!1,socket:null,adapter:(t,e)=>new WebSocket(t,e),encode:(t,e,{server:n})=>JSON.stringify({[n.id_key]:t,[n.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"},ping:{interval:55,out:"ping",in:"pong"}},t),n=e.url;if("/"==n[0])try{const t=location.protocol.includes("s:")?"wss":"ws";e.url=`${t}://${location.hostname}:${location.port}${n}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e},{random:Dt}=Math,Ft=null,Jt=1/0,Gt=Promise.resolve(Ft),Ht="message",Kt="message-ext",Qt=new Bt,Vt=()=>Date.now()/1e3,Xt=T(1e3),Yt=t=>t&&clearTimeout(t),te=t=>null===t,ee=S("String"),ne=S("Object"),se=(t,e,n,s=.5)=>{const i=Xt(s),r=setTimeout(()=>{const s=t.indexOf(e);~s&&(t.splice(s),n(`could not close in ${i}ms!`))},1e3*i);t.push((...t)=>{Yt(r),e(...t)})},ie=t=>{const e=Qt.zip(2147483637*Dt()|0);return e in t?ie(t):e},re=(t,...e)=>{for(const n of t)n(...e);return t},oe=t=>(t.splice(0),t),ce=(t,e)=>e(t);class ae{ws=Ft;intentionally_closed=!1;reconnect_timeout=Ft;queue={send:new Map,on_ready:[],on_close:[],on_ready_fail:[]};handlers={open:[],close:[],message:[],[Kt]:[],error:[],timeout:[]};config={};ping_timer=Ft;idle_timer=Ft;zombie_timer=Ft;router=ce;get opened(){return 1===this.ws?.readyState}call(t,...e){for(const n of this.handlers[t])n(...e)}log(t,e=Ft,n=Ft){const{config:s}=this;setTimeout(()=>{te(n)?s.timer?s.log(t,Ft,e):s.log(t,e):s.log(t,n,e)})}resetPing(){const{config:{ping:t},ping_timer:e}=this;t&&(Yt(e),this.ping_timer=Rt(Xt(t.interval),async()=>{const{ping_timer:e,opened:n}=this;n?(this.ws.send(t.out),this.resetPing()):Yt(e)}))}resetZombieProbe(){const{config:t}=this;if(t.ping){const e=t.ping.timeout;Yt(this.zombie_timer),e!==1/0&&(this.zombie_timer=Rt(Xt(e||t.timeout),()=>this.close().catch(Z)))}}resetIdle(){const{config:{max_idle_time:t},idle_timer:e}=this;t!==1/0&&(Yt(e),this.idle_timer=Rt(Xt(t),()=>this.opened&&this.close()))}_reconnecting=!1;reconnect_start=0;async reconnect(t=0){if(this._reconnecting&&0===t)return;this.log("reconnect"),this._reconnecting=!0,this.reconnect_start=Vt(),p(this.ws)||this.terminate();const{queue:e}=this;if(t>0&&p(await this.connect()))oe(re(e.on_ready)),oe(e.on_ready_fail),this._reconnecting=!1,this.reconnect_timeout=Ft;else{const{stop_after:n,time_fn:s,params:i}=this.config.reconnect;Vt()-this.reconnect_start>n?(this.terminate(),oe(re(e.on_ready_fail)),oe(e.on_ready),this._reconnecting=!1,this.reconnect_timeout=Ft):this.reconnect_timeout=Rt(Xt(s(i,t)),this.reconnect.bind(this,t+1))}}resetReconnect(){te(this.reconnect_timeout)||(Yt(this.reconnect_timeout),this.reconnect_timeout=Ft)}initSocket(t){const{queue:e,config:n,router:s}=this;this.ws=t,oe(re(this.queue.on_ready));const{id_key:i,data_key:r}=n.server;this.call("open",t);for(const{msg:n}of e.send.values())t.send(n);this.resetReconnect(),this.resetZombieProbe(),this.resetPing(),this.resetIdle(),Lt(t,"close",async(...t)=>{this.ws=Ft,oe(re(e.on_close)),this.call("close",...t),!this.intentionally_closed&&n.reconnect.on_break&&this.reconnect()});const{ping:o}=n,c=t=>{try{const e=n.decode(t),{send:s}=this.queue;let o=!1;if(ne(e)&&i in e){const t=e[i];if(s.has(t)){const n=s.get(t),i=e[r],c=n.sent_time?Vt()-n.sent_time:Ft;this.log(Ht,i,c),n.ff(i),o=!0}}const c=o?Ht:Kt;this.log(c,e),this.call(c,{data:e})}catch(e){console.error(e,`WSP: Decode error. Got: ${t}`)}};Lt(t,Ht,t=>{const e=ee(t.data)?t.data:new Uint8Array(t.data);this.resetZombieProbe(),this.resetPing(),o&&P(e,o.in)||s(e,c)})}_opening=!1;connect(){return this.opened||this._opening||this.opened||this._opening?Gt:new Promise(t=>{this._opening=!0;const e=this.config,n=e.socket||e.adapter(e.url,e.protocols);if(p(n)||n.readyState>1)return this._opening=!1,this.ws=Ft,this.log("error","ready() on closing or closed state! status 2."),t(2);const s=F(e=>{this._opening=!1,t(e)});Lt(n,"error",F(t=>{this.ws=Ft,this.log("error","status 3. Err: "+(t.message||t)),this.call("error",t),s(3)})),n.readyState?(this.initSocket(n),s(Ft)):Lt(n,"open",F(()=>{this.log("open"),this.initSocket(n),s(Ft)}))})}get socket(){return this.ws}async ready(t=Jt){return new Promise((e,n)=>{const{on_ready:s}=this.queue;this.config.lazy||this.opened?e():t===Jt?s.push(e):se(s,e,n)})}on(t,e,n=I,s=!1){const i=t=>n(t)&&e(t);return s?Lt(this.ws,t,i):this.handlers[t].push(i),i}off(t,e,n=!1){if(n)return((t,e,n)=>t.removeEventListener(e,n))(this.ws,t,e);const s=this.handlers[t],i=s.indexOf(e);~i&&s.splice(i,1)}terminate(){this.ws?.close(),this.ws=Ft,this.intentionally_closed=!0}async close(t=.5){return new Promise((e,n)=>{te(this.ws)?e(Ft):(se(this.queue.on_close,e,n,t),this.terminate())})}open(){if(!this.opened)return this.intentionally_closed=!1,this.connect()}addEventListener(t,e,n={}){return this.on(t,e,n.predicate,n.raw)}removeEventListener(t,e,n={}){return this.off(t,e,n.raw)}async prepareMessage(t,e={}){this.log("send",t);const{config:n,queue:{send:s,on_ready_fail:i}}=this,{pipes:r,server:{data_key:o}}=n,{top:c}=e,a=ie(s);if(ne(c)&&o in c)throw new Error("\n Attempting to set data key/token via send() options!\n ");for(const e of r)t=e(t);const[l,h]=await Promise.all([n.encode(a,t,n),this.connect()]);if(h)throw new Error("ERR while opening connection > "+h);const u=c?.timeout||n.timeout,d=R(()=>s.delete(a));return{id:a,msg:l,timeout:e=>Rt(Xt(u),()=>{if(s.has(a)){this.call("timeout",t),d();const s=()=>e({"Websocket timeout expired":u,"for the message":t});n.reconnect.on_timeout?(i.push(s),this.reconnect()):s()}}),cleanup:d,send:()=>this.opened&&(this.ws.send(l),this.resetPing(),this.resetIdle())}}async send(t,e={}){const{id:n,msg:s,timeout:i,cleanup:r,send:o}=await this.prepareMessage(t,e),{queue:{send:c},config:a}=this;return new Promise((t,e)=>{const r=i(e);c.set(n,{msg:s,data_type:a.data_type,sent_time:a.timer?Vt():Ft,ff(e){Yt(r),t(e)}}),o()}).finally(r)}async*stream(t,e={}){const{id:n,msg:s,timeout:i,cleanup:r,send:o}=await this.prepareMessage(t,e),{queue:{send:c},config:a}=this;let l,h=!1,u=Ft;for(c.set(n,{msg:s,ff:t=>{t?.done&&(delete t.done,h=!0,setTimeout(r)),l(t)},data_type:a.data_type,sent_time:a.timer?Vt():Ft}),o();!h;)yield await new Promise((t,e)=>{u=i(e),l=t}).catch(r).finally(()=>Yt(u))}route(t){this.router=t}constructor(t){this.config=Zt(t),this.config.lazy||this.connect()}}export{ae as WebSocketClient};
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
42
42
  "all": "npm run dev && npm run prod"
43
43
  },
44
- "version": "2.11.3",
44
+ "version": "3.0.0",
45
45
  "type": "module",
46
46
  "exports": {
47
47
  ".": {
@@ -57,23 +57,24 @@
57
57
  "@rollup/plugin-replace": "^6.0.3",
58
58
  "@rollup/plugin-terser": "^1.0.0",
59
59
  "@types/express": "^5.0.6",
60
- "@types/node": "^25.4.0",
60
+ "@types/node": "^25.7.0",
61
61
  "@types/ws": "^8.18.1",
62
- "codecov": "^3.6.3",
62
+ "codecov": "^3.8.3",
63
63
  "cross-env": "^10.1.0",
64
64
  "dts-bundle-generator": "^9.5.1",
65
65
  "nyc": "^18.0.0",
66
- "rollup": "^4.59.0",
67
- "rollup-plugin-typescript2": "^0.36.0",
66
+ "rollup": "^4.60.3",
67
+ "rollup-plugin-typescript2": "^0.37.0",
68
68
  "ts-node": "^10.9.2",
69
69
  "tsx": "^4.21.0",
70
- "typescript": "^5.9.3",
70
+ "type-fest": "^5.6.0",
71
+ "typescript": "^6.0.3",
71
72
  "uvu": "^0.5.6",
72
- "ws": "^8.19.0"
73
+ "ws": "^8.20.1"
73
74
  },
74
75
  "types": "./dist/bundle.d.ts",
75
76
  "dependencies": {
76
- "pepka": "^1.6.23",
77
+ "pepka": "^1.12.3",
77
78
  "zipnum": "^2.1.3"
78
79
  }
79
80
  }
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ esbuild: true
package/tsconfig.json CHANGED
@@ -12,8 +12,8 @@
12
12
  "noUnusedParameters": true,
13
13
  "noUnusedLocals": false,
14
14
  "rootDir": ".",
15
- "baseUrl": ".",
16
15
  "allowSyntheticDefaultImports": true,
16
+ "types": ["@types/node"],
17
17
  "outDir": "dist/ts"
18
18
  },
19
19
  "include": [ "src/**/*", "test/**/*" ]