@libp2p/simple-metrics 2.0.21 → 2.0.22-4a416447c
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/index.min.js +2 -2
- package/dist/index.min.js.map +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -3
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +26 -9
- package/dist/typedoc-urls.json +0 -10
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PSimpleMetrics = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PSimpleMetrics=(()=>{var
|
|
2
|
+
"use strict";var Libp2PSimpleMetrics=(()=>{var Oe=Object.create;var q=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Be=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},ae=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $e(e))!De.call(t,i)&&i!==r&&q(t,i,{get:()=>e[i],enumerable:!(n=Ne(e,i))||n.enumerable});return t};var Ie=(t,e,r)=>(r=t!=null?Oe(je(t)):{},ae(e||!t||!t.__esModule?q(r,"default",{value:t,enumerable:!0}):r,t)),Te=t=>ae(q({},"__esModule",{value:!0}),t);var ne=j((Ar,ye)=>{function M(){}M.prototype.clear=function(){this._root=null,this.size=0};M.prototype.find=function(t){for(var e=this._root;e!==null;){var r=this._comparator(t,e.data);if(r===0)return e.data;e=e.get_child(r>0)}return null};M.prototype.findIter=function(t){for(var e=this._root,r=this.iterator();e!==null;){var n=this._comparator(t,e.data);if(n===0)return r._cursor=e,r;r._ancestors.push(e),e=e.get_child(n>0)}return null};M.prototype.lowerBound=function(t){for(var e=this._root,r=this.iterator(),n=this._comparator;e!==null;){var i=n(t,e.data);if(i===0)return r._cursor=e,r;r._ancestors.push(e),e=e.get_child(i>0)}for(var s=r._ancestors.length-1;s>=0;--s)if(e=r._ancestors[s],n(t,e.data)<0)return r._cursor=e,r._ancestors.length=s,r;return r._ancestors.length=0,r};M.prototype.upperBound=function(t){for(var e=this.lowerBound(t),r=this._comparator;e.data()!==null&&r(e.data(),t)===0;)e.next();return e};M.prototype.min=function(){var t=this._root;if(t===null)return null;for(;t.left!==null;)t=t.left;return t.data};M.prototype.max=function(){var t=this._root;if(t===null)return null;for(;t.right!==null;)t=t.right;return t.data};M.prototype.iterator=function(){return new O(this)};M.prototype.each=function(t){for(var e=this.iterator(),r;(r=e.next())!==null;)if(t(r)===!1)return};M.prototype.reach=function(t){for(var e=this.iterator(),r;(r=e.prev())!==null;)if(t(r)===!1)return};function O(t){this._tree=t,this._ancestors=[],this._cursor=null}O.prototype.data=function(){return this._cursor!==null?this._cursor.data:null};O.prototype.next=function(){if(this._cursor===null){var t=this._tree._root;t!==null&&this._minNode(t)}else if(this._cursor.right===null){var e;do if(e=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.right===e)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return this._cursor!==null?this._cursor.data:null};O.prototype.prev=function(){if(this._cursor===null){var t=this._tree._root;t!==null&&this._maxNode(t)}else if(this._cursor.left===null){var e;do if(e=this._cursor,this._ancestors.length)this._cursor=this._ancestors.pop();else{this._cursor=null;break}while(this._cursor.left===e)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return this._cursor!==null?this._cursor.data:null};O.prototype._minNode=function(t){for(;t.left!==null;)this._ancestors.push(t),t=t.left;this._cursor=t};O.prototype._maxNode=function(t){for(;t.right!==null;)this._ancestors.push(t),t=t.right;this._cursor=t};ye.exports=M});var Fe=j((Er,xe)=>{var ut=ne();function N(t){this.data=t,this.left=null,this.right=null,this.red=!0}N.prototype.get_child=function(t){return t?this.right:this.left};N.prototype.set_child=function(t,e){t?this.right=e:this.left=e};function R(t){this._root=null,this._comparator=t,this.size=0}R.prototype=new ut;R.prototype.insert=function(t){var e=!1;if(this._root===null)this._root=new N(t),e=!0,this.size++;else{var r=new N(void 0),n=0,i=0,s=null,a=r,l=null,h=this._root;for(a.right=this._root;;){if(h===null?(h=new N(t),l.set_child(n,h),e=!0,this.size++):A(h.left)&&A(h.right)&&(h.red=!0,h.left.red=!1,h.right.red=!1),A(h)&&A(l)){var w=a.right===s;h===l.get_child(i)?a.set_child(w,D(s,!i)):a.set_child(w,Ce(s,!i))}var o=this._comparator(h.data,t);if(o===0)break;i=n,n=o<0,s!==null&&(a=s),s=l,l=h,h=h.get_child(n)}this._root=r.right}return this._root.red=!1,e};R.prototype.remove=function(t){if(this._root===null)return!1;var e=new N(void 0),r=e;r.right=this._root;for(var n=null,i=null,s=null,a=1;r.get_child(a)!==null;){var l=a;i=n,n=r,r=r.get_child(a);var h=this._comparator(t,r.data);if(a=h>0,h===0&&(s=r),!A(r)&&!A(r.get_child(a))){if(A(r.get_child(!a))){var w=D(r,a);n.set_child(l,w),n=w}else if(!A(r.get_child(!a))){var o=n.get_child(!l);if(o!==null)if(!A(o.get_child(!l))&&!A(o.get_child(l)))n.red=!1,o.red=!0,r.red=!0;else{var c=i.right===n;A(o.get_child(l))?i.set_child(c,Ce(n,l)):A(o.get_child(!l))&&i.set_child(c,D(n,l));var f=i.get_child(c);f.red=!0,r.red=!0,f.left.red=!1,f.right.red=!1}}}}return s!==null&&(s.data=r.data,n.set_child(n.right===r,r.get_child(r.left===null)),this.size--),this._root=e.right,this._root!==null&&(this._root.red=!1),s!==null};function A(t){return t!==null&&t.red}function D(t,e){var r=t.get_child(!e);return t.set_child(!e,r.get_child(e)),r.set_child(e,t),t.red=!0,r.red=!1,r}function Ce(t,e){return t.set_child(!e,D(t.get_child(!e),!e)),D(t,e)}xe.exports=R});var Ee=j((kr,Ae)=>{var ct=ne();function B(t){this.data=t,this.left=null,this.right=null}B.prototype.get_child=function(t){return t?this.right:this.left};B.prototype.set_child=function(t,e){t?this.right=e:this.left=e};function J(t){this._root=null,this._comparator=t,this.size=0}J.prototype=new ct;J.prototype.insert=function(t){if(this._root===null)return this._root=new B(t),this.size++,!0;for(var e=0,r=null,n=this._root;;){if(n===null)return n=new B(t),r.set_child(e,n),ret=!0,this.size++,!0;if(this._comparator(n.data,t)===0)return!1;e=this._comparator(n.data,t)<0,r=n,n=n.get_child(e)}};J.prototype.remove=function(t){if(this._root===null)return!1;var e=new B(void 0),r=e;r.right=this._root;for(var n=null,i=null,s=1;r.get_child(s)!==null;){n=r,r=r.get_child(s);var a=this._comparator(t,r.data);s=a>0,a===0&&(i=r)}return i!==null?(i.data=r.data,n.set_child(n.right===r,r.get_child(r.left===null)),this._root=e.right,this.size--,!0):!1};Ae.exports=J});var Me=j((Mr,ke)=>{ke.exports={RBTree:Fe(),BinTree:Ee()}});var Ue=j((Sr,Ve)=>{var lt=Me().RBTree;function p(t,e,r){this.discrete=t===!1,this.delta=t||.01,this.K=e===void 0?25:e,this.CX=r===void 0?1.1:r,this.centroids=new lt(Se),this.nreset=0,this.reset()}p.prototype.reset=function(){this.centroids.clear(),this.n=0,this.nreset+=1,this.last_cumulate=0};p.prototype.size=function(){return this.centroids.size};p.prototype.toArray=function(t){var e=[];return t?(this._cumulate(!0),this.centroids.each(function(r){e.push(r)})):this.centroids.each(function(r){e.push({mean:r.mean,n:r.n})}),e};p.prototype.summary=function(){var t=this.discrete?"exact ":"approximating ",e=[t+this.n+" samples using "+this.size()+" centroids","min = "+this.percentile(0),"Q1 = "+this.percentile(.25),"Q2 = "+this.percentile(.5),"Q3 = "+this.percentile(.75),"max = "+this.percentile(1)];return e.join(`
|
|
3
3
|
`)};function Se(t,e){return t.mean>e.mean?1:t.mean<e.mean?-1:0}function ht(t,e){return t.mean_cumn-e.mean_cumn}p.prototype.push=function(t,e){e=e||1,t=Array.isArray(t)?t:[t];for(var r=0;r<t.length;r++)this._digest(t[r],e)};p.prototype.push_centroid=function(t){t=Array.isArray(t)?t:[t];for(var e=0;e<t.length;e++)this._digest(t[e].mean,t[e].n)};p.prototype._cumulate=function(t){if(!(this.n===this.last_cumulate||!t&&this.CX&&this.CX>this.n/this.last_cumulate)){var e=0;this.centroids.each(function(r){r.mean_cumn=e+r.n/2,e=r.cumn=e+r.n}),this.n=this.last_cumulate=e}};p.prototype.find_nearest=function(t){if(this.size()===0)return null;var e=this.centroids.lowerBound({mean:t}),r=e.data()===null?e.prev():e.data();if(r.mean===t||this.discrete)return r;var n=e.prev();return n&&Math.abs(n.mean-t)<Math.abs(r.mean-t)?n:r};p.prototype._new_centroid=function(t,e,r){var n={mean:t,n:e,cumn:r};return this.centroids.insert(n),this.n+=e,n};p.prototype._addweight=function(t,e,r){e!==t.mean&&(t.mean+=r*(e-t.mean)/(t.n+r)),t.cumn+=r,t.mean_cumn+=r/2,t.n+=r,this.n+=r};p.prototype._digest=function(t,e){var r=this.centroids.min(),n=this.centroids.max(),i=this.find_nearest(t);if(i&&i.mean===t)this._addweight(i,t,e);else if(i===r)this._new_centroid(t,e,0);else if(i===n)this._new_centroid(t,e,this.n);else if(this.discrete)this._new_centroid(t,e,i.cumn);else{var s=i.mean_cumn/this.n,a=Math.floor(4*this.n*this.delta*s*(1-s));a-i.n>=e?this._addweight(i,t,e):this._new_centroid(t,e,i.cumn)}this._cumulate(!1),!this.discrete&&this.K&&this.size()>this.K/this.delta&&this.compress()};p.prototype.bound_mean=function(t){var e=this.centroids.upperBound({mean:t}),r=e.prev(),n=r.mean===t?r:e.next();return[r,n]};p.prototype.p_rank=function(t){var e=Array.isArray(t)?t:[t],r=e.map(this._p_rank,this);return Array.isArray(t)?r:r[0]};p.prototype._p_rank=function(t){if(this.size()!==0){{if(t<this.centroids.min().mean)return 0;if(t>this.centroids.max().mean)return 1}this._cumulate(!0);var e=this.bound_mean(t),r=e[0],n=e[1];if(this.discrete)return r.cumn/this.n;var i=r.mean_cumn;return r!==n&&(i+=(t-r.mean)*(n.mean_cumn-r.mean_cumn)/(n.mean-r.mean)),i/this.n}};p.prototype.bound_mean_cumn=function(t){this.centroids._comparator=ht;var e=this.centroids.upperBound({mean_cumn:t});this.centroids._comparator=Se;var r=e.prev(),n=r&&r.mean_cumn===t?r:e.next();return[r,n]};p.prototype.percentile=function(t){var e=Array.isArray(t)?t:[t],r=e.map(this._percentile,this);return Array.isArray(t)?r:r[0]};p.prototype._percentile=function(t){if(this.size()!==0){this._cumulate(!0);var e=this.n*t,r=this.bound_mean_cumn(e),n=r[0],i=r[1];return i===n||n===null||i===null?(n||i).mean:this.discrete?e<=n.cumn?n.mean:i.mean:n.mean+(e-n.mean_cumn)*(i.mean-n.mean)/(i.mean_cumn-n.mean_cumn)}};function ft(t){var e=Math.floor(Math.random()*t.length);return t.splice(e,1)[0]}p.prototype.compress=function(){if(!this.compressing){var t=this.toArray();for(this.reset(),this.compressing=!0;t.length>0;)this.push_centroid(ft(t));this._cumulate(!0),this.compressing=!1}};function V(t){this.config=t||{},this.mode=this.config.mode||"auto",p.call(this,this.mode==="cont"?t.delta:!1),this.digest_ratio=this.config.ratio||.9,this.digest_thresh=this.config.thresh||1e3,this.n_unique=0}V.prototype=Object.create(p.prototype);V.prototype.constructor=V;V.prototype.push=function(t){p.prototype.push.call(this,t),this.check_continuous()};V.prototype._new_centroid=function(t,e,r){this.n_unique+=1,p.prototype._new_centroid.call(this,t,e,r)};V.prototype._addweight=function(t,e,r){t.n===1&&(this.n_unique-=1),p.prototype._addweight.call(this,t,e,r)};V.prototype.check_continuous=function(){return this.mode!=="auto"||this.size()<this.digest_thresh?!1:this.n_unique/this.size()>this.digest_ratio?(this.mode="cont",this.discrete=!1,this.delta=this.config.delta||.01,this.compress(),!0):!1};Ve.exports={TDigest:p,Digest:V}});var mt={};Be(mt,{simpleMetrics:()=>dt});var ue=Symbol.for("@libp2p/service-capabilities");var Lt=new Uint8Array(0);function le(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ce(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ce(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function qe(t){return t?.buffer instanceof ArrayBuffer}function ce(t){return qe(t)?t:t.slice()}function Le(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var s=0;s<t.length;s++){var a=t.charAt(s),l=a.charCodeAt(0);if(n[l]!==255)throw new TypeError(a+" is ambiguous");if(n[l]=s,r){var h=a.toLowerCase().charCodeAt(0),w=a.toUpperCase().charCodeAt(0);h!==l&&(n[h]=s),w!==l&&(n[w]=s)}}var o=t.length,c=t.charAt(0),f=Math.log(o)/Math.log(256),U=Math.log(256)/Math.log(o);function I(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var d=0,x=0,v=0,g=u.length;v!==g&&u[v]===0;)v++,d++;for(var E=(g-v)*U+1>>>0,m=new Uint8Array(E);v!==g;){for(var F=u[v],k=0,y=E-1;(F!==0||k<x)&&y!==-1;y--,k++)F+=256*m[y]>>>0,m[y]=F%o>>>0,F=F/o>>>0;if(F!==0)throw new Error("Non-zero carry");x=k,v++}for(var S=E-x;S!==E&&m[S]===0;)S++;for(var T=c.repeat(d);S<E;++S)T+=t.charAt(m[S]);return T}function $(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var d=0;if(u[d]!==" "){for(var x=0,v=0;u[d]===c;)x++,d++;for(var g=(u.length-d)*f+1>>>0,E=new Uint8Array(g);u[d];){var m=n[u.charCodeAt(d)];if(m===255)return;for(var F=0,k=g-1;(m!==0||F<v)&&k!==-1;k--,F++)m+=o*E[k]>>>0,E[k]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");v=F,d++}if(u[d]!==" "){for(var y=g-v;y!==g&&E[y]===0;)y++;for(var S=new Uint8Array(x+(g-y)),T=x;y!==g;)S[T++]=E[y++];return S}}}function C(u){var d=$(u);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:I,decodeUnsafe:$,decode:C}}var Pe=Le,Re=Pe,he=Re;var Z=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},W=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return fe(this,e)}},H=class{decoders;constructor(e){this.decoders=e}or(e){return fe(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fe(t,e){return new H({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Y=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Z(e,r,n),this.decoder=new W(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function pe({name:t,prefix:e,encode:r,decode:n}){return new Y(t,e,r,n)}function ee({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:i,decode:s}=he(r,t,n);return pe({prefix:e,name:t,encode:i,decode:a=>le(s(a))})}function Je(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),a=0,l=0,h=0;for(let w=0;w<i;++w){let o=e[t[w]];if(o===void 0)throw new SyntaxError(`Non-${n} character`);l=l<<r|o,a+=r,a>=8&&(a-=8,s[h++]=255&l>>a)}if(a>=r||(255&l<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ge(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,s="",a=0,l=0;for(let h=0;h<t.length;++h)for(l=l<<8|t[h],a+=8;a>r;)a-=r,s+=e[i&l>>a];if(a!==0&&(s+=e[i&l<<r-a]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Xe(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let i=t[n].toLowerCase(),s=t[n].toUpperCase();i!==t[n]&&(r[i]=n),s!==t[n]&&(r[s]=n)}return r}function b({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:i=!1}){let s=Xe(n,i);return pe({prefix:e,name:t,encode(a){return Ge(a,n,r)},decode(a){return Je(a,s,r,t)}})}var de=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Kt=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Zt=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Wt=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ht=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Yt=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),er=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),tr=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),rr=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var me=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sr=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ge=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ur=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cr=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),lr=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function L(t,e){if(typeof t=="string")return Qe(t);if(typeof t=="number")return We(t,e);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(t)}`)}function Qe(t){if(typeof t!="string"||t.length===0||t.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(t)}`);let e=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(t);if(!e?.groups)return NaN;let{value:r,unit:n="ms"}=e.groups,i=parseFloat(r),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return i*315576e5;case"months":case"month":case"mo":return i*26298e5;case"weeks":case"week":case"w":return i*6048e5;case"days":case"day":case"d":return i*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return i*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return i*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return i*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(t)}`)}}function Ke(t){let e=Math.abs(t);return e>=315576e5?`${Math.round(t/315576e5)}y`:e>=26298e5?`${Math.round(t/26298e5)}mo`:e>=6048e5?`${Math.round(t/6048e5)}w`:e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function Ze(t){let e=Math.abs(t);return e>=315576e5?z(t,e,315576e5,"year"):e>=26298e5?z(t,e,26298e5,"month"):e>=6048e5?z(t,e,6048e5,"week"):e>=864e5?z(t,e,864e5,"day"):e>=36e5?z(t,e,36e5,"hour"):e>=6e4?z(t,e,6e4,"minute"):e>=1e3?z(t,e,1e3,"second"):`${t} ms`}function We(t,e){if(typeof t!="number"||!Number.isFinite(t))throw new Error("Value provided to ms.format() must be of type number.");return e?.long?Ze(t):Ke(t)}function z(t,e,r,n){let i=e>=r*1.5;return`${Math.round(t/r)} ${n}${i?"s":""}`}function te(t){r.debug=r,r.default=r,r.coerce=h,r.disable=s,r.enable=i,r.enabled=a,r.humanize=L,r.destroy=w,Object.keys(t).forEach(o=>{r[o]=t[o]}),r.names=[],r.skips=[],r.formatters={};function e(o){let c=0;for(let f=0;f<o.length;f++)c=(c<<5)-c+o.charCodeAt(f),c|=0;return r.colors[Math.abs(c)%r.colors.length]}r.selectColor=e;function r(o,c){let f,U=null,I,$;function C(...u){if(!C.enabled)return;let d=C,x=Number(new Date),v=x-(f||x);d.diff=v,d.prev=f,d.curr=x,f=x,u[0]=r.coerce(u[0]),typeof u[0]!="string"&&u.unshift("%O");let g=0;u[0]=u[0].replace(/%([a-zA-Z%])/g,(m,F)=>{if(m==="%%")return"%";g++;let k=r.formatters[F];if(typeof k=="function"){let y=u[g];m=k.call(d,y),u.splice(g,1),g--}return m}),r.formatArgs.call(d,u),c?.onLog!=null&&c.onLog(...u),(d.log||r.log).apply(d,u)}return C.namespace=o,C.useColors=r.useColors(),C.color=r.selectColor(o),C.extend=n,C.destroy=r.destroy,Object.defineProperty(C,"enabled",{enumerable:!0,configurable:!1,get:()=>U!==null?U:(I!==r.namespaces&&(I=r.namespaces,$=r.enabled(o)),$),set:u=>{U=u}}),typeof r.init=="function"&&r.init(C),C}function n(o,c){let f=r(this.namespace+(typeof c>"u"?":":c)+o);return f.log=this.log,f}function i(o){r.save(o),r.namespaces=o,r.names=[],r.skips=[];let c,f=(typeof o=="string"?o:"").split(/[\s,]+/),U=f.length;for(c=0;c<U;c++)f[c]&&(o=f[c].replace(/\*/g,".*?"),o[0]==="-"?r.skips.push(new RegExp("^"+o.substr(1)+"$")):r.names.push(new RegExp("^"+o+"$")))}function s(){let o=[...r.names.map(l),...r.skips.map(l).map(c=>"-"+c)].join(",");return r.enable(""),o}function a(o){if(o[o.length-1]==="*")return!0;let c,f;for(c=0,f=r.skips.length;c<f;c++)if(r.skips[c].test(o))return!1;for(c=0,f=r.names.length;c<f;c++)if(r.names[c].test(o))return!0;return!1}function l(o){return o.toString().substring(2,o.toString().length-2).replace(/\.\*\?$/,"*")}function h(o){return o instanceof Error?o.stack??o.message:o}function w(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var P=it(),He=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Ye(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function et(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+L(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}var tt=console.debug??console.log??(()=>{});function rt(t){try{t?P?.setItem("debug",t):P?.removeItem("debug")}catch{}}function nt(){let t;try{t=P?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function it(){try{return localStorage}catch{}}function st(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var be=te({formatArgs:et,save:rt,load:nt,useColors:Ye,setupFormatters:st,colors:He,storage:P,log:tt});var _=be;_.formatters.b=t=>t==null?"undefined":me.baseEncode(t);_.formatters.t=t=>t==null?"undefined":de.baseEncode(t);_.formatters.m=t=>t==null?"undefined":ge.baseEncode(t);_.formatters.p=t=>t==null?"undefined":t.toString();_.formatters.c=t=>t==null?"undefined":t.toString();_.formatters.k=t=>t==null?"undefined":t.toString();_.formatters.a=t=>t==null?"undefined":t.toString();function we(t,e=""){let r=_e(t.message),n=_e(t.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(`
|
|
4
4
|
`).join(`
|
|
5
5
|
${e}`)}`:`${r}
|
|
@@ -10,6 +10,6 @@ ${e}`)}`:n!=null?`${n.split(`
|
|
|
10
10
|
${e}`)}`:r!=null?`${r}`:`${t.toString()}`}function ot(t){return t instanceof AggregateError||t?.name==="AggregateError"&&Array.isArray(t.errors)}function ve(t,e=""){if(ot(t)){let r=we(t,e);return t.errors.length>0?(e=`${e} `,r+=`
|
|
11
11
|
${e}${t.errors.map(n=>`${ve(n,`${e}`)}`).join(`
|
|
12
12
|
${e}`)}`):r+=`
|
|
13
|
-
${e}[Error list was empty]`,r.trim()}return we(t,e)}_.formatters.e=t=>t==null?"undefined":ve(t);function at(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function re(t,e){let r=at(`${t}:trace`);return _.enabled(`${t}:trace`)&&_.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=_(`${t}:trace`,e)),Object.assign(_(t,e),{error:_(`${t}:error`,e),trace:r,newScope:n=>re(`${t}:${n}`,e)})}function _e(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var ze=Ie(Ue(),1),pt=re("libp2p:simple-metrics"),G=class{value=0;calculate;constructor(e){this.calculate=e?.calculate}async collect(){return this.calculate!=null?this.calculate():this.value}update(e){this.value=e}increment(e=1){this.value+=e}decrement(e=1){this.value-=e}reset(){this.value=0}timer(){let e=Date.now();return()=>{this.value=Date.now()-e}}},X=class{values={};calculate;constructor(e){this.calculate=e?.calculate}async collect(){return this.calculate!=null?this.calculate():this.values}update(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=n})}increment(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=this.values[r]??0;let i=typeof n=="number"?n:1;this.values[r]+=Number(i)})}decrement(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=this.values[r]??0;let i=typeof n=="number"?n:1;this.values[r]-=Number(i)})}reset(){this.values={}}timer(e){let r=Date.now();return()=>{this.values[e]=Date.now()-r}}},Q=class{bucketValues=new Map;countValue=0;sumValue=0;calculate;constructor(e){let r=[...e?.buckets??[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],1/0];for(let n of r)this.bucketValues.set(n,0);this.calculate=e?.calculate}async collect(){return this.calculate!=null&&this.observe(await this.calculate()),{count:this.countValue,sum:this.sumValue,buckets:
|
|
13
|
+
${e}[Error list was empty]`,r.trim()}return we(t,e)}_.formatters.e=t=>t==null?"undefined":ve(t);function at(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e.useColors=()=>!1,e}function re(t,e){let r=at(`${t}:trace`);return _.enabled(`${t}:trace`)&&_.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=_(`${t}:trace`,e)),Object.assign(_(t,e),{error:_(`${t}:error`,e),trace:r,newScope:n=>re(`${t}:${n}`,e)})}function _e(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var ze=Ie(Ue(),1),pt=re("libp2p:simple-metrics"),G=class{value=0;calculate;constructor(e){this.calculate=e?.calculate}async collect(){return this.calculate!=null?this.calculate():this.value}update(e){this.value=e}increment(e=1){this.value+=e}decrement(e=1){this.value-=e}reset(){this.value=0}timer(){let e=Date.now();return()=>{this.value=Date.now()-e}}},X=class{values={};calculate;constructor(e){this.calculate=e?.calculate}async collect(){return this.calculate!=null?this.calculate():this.values}update(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=n})}increment(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=this.values[r]??0;let i=typeof n=="number"?n:1;this.values[r]+=Number(i)})}decrement(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=this.values[r]??0;let i=typeof n=="number"?n:1;this.values[r]-=Number(i)})}reset(){this.values={}}timer(e){let r=Date.now();return()=>{this.values[e]=Date.now()-r}}},Q=class{bucketValues=new Map;countValue=0;sumValue=0;calculate;constructor(e){let r=[...e?.buckets??[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],1/0];for(let n of r)this.bucketValues.set(n,0);this.calculate=e?.calculate}async collect(){return this.calculate!=null&&this.observe(await this.calculate()),{count:this.countValue,sum:this.sumValue,buckets:Object.fromEntries(this.bucketValues)}}observe(e){this.countValue++,this.sumValue+=e;for(let[r,n]of this.bucketValues.entries())e<=r&&this.bucketValues.set(r,n+1)}reset(){this.countValue=0,this.sumValue=0;for(let e of this.bucketValues.keys())this.bucketValues.set(e,0)}timer(){let e=Date.now();return()=>{this.observe(Date.now()-e)}}},ie=class{histograms={};opts;calculate;constructor(e){this.histograms={},this.opts={buckets:e?.buckets},this.calculate=e?.calculate}async collect(){this.calculate!=null&&this.observe(await this.calculate());let e={};for(let[r,n]of Object.entries(this.histograms))e[r]=await n.collect();return e}observe(e){for(let[r,n]of Object.entries(e))this.histograms[r]===void 0&&(this.histograms[r]=new Q(this.opts)),this.histograms[r].observe(n)}reset(){for(let e of Object.values(this.histograms))e.reset()}timer(e){let r=Date.now();return()=>{this.observe({[e]:Date.now()-r})}}},K=class{sumValue=0;countValue=0;percentiles;tdigest=new ze.TDigest(.01);compressCount;calculate;constructor(e){this.percentiles=e?.percentiles??[.01,.05,.5,.9,.95,.99,.999],this.compressCount=e?.compressCount??1e3,this.calculate=e?.calculate}async collect(){return this.calculate!=null&&this.observe(await this.calculate()),{count:this.countValue,sum:this.sumValue,percentiles:Object.fromEntries(this.percentiles.map(e=>[e,this.tdigest.percentile(e)]))}}observe(e){this.sumValue+=e,this.countValue++,this.tdigest.push(e),this.tdigest.size()>this.compressCount&&this.tdigest.compress()}reset(){this.sumValue=0,this.countValue=0,this.tdigest.reset()}timer(){let e=Date.now();return()=>{this.observe(Date.now()-e)}}},se=class{summaries={};opts;calculate;constructor(e){this.summaries={},this.opts={percentiles:e?.percentiles,compressCount:e?.compressCount},this.calculate=e?.calculate}async collect(){return this.calculate!=null&&this.observe(await this.calculate()),{...Object.fromEntries(Object.entries(this.summaries).map(([e,r])=>[e,{count:r.countValue,sum:r.sumValue,percentiles:Object.fromEntries(r.percentiles.map(n=>[n,r.tdigest.percentile(n)]))}]))}}observe(e){for(let[r,n]of Object.entries(e))this.summaries[r]===void 0&&(this.summaries[r]=new K(this.opts)),this.summaries[r].observe(n)}reset(){for(let e of Object.values(this.summaries))e.reset()}timer(e){let r=Date.now();return()=>{this.observe({[e]:Date.now()-r})}}},oe=class{metrics=new Map;transferStats;started;interval;intervalMs;onMetrics;log;constructor(e,r){this.log=e.logger.forComponent("libp2p:simple-metrics"),this.started=!1,this._emitMetrics=this._emitMetrics.bind(this),this.intervalMs=r.intervalMs??1e3,this.onMetrics=r.onMetrics,this.transferStats=new Map}[Symbol.toStringTag]="@libp2p/metrics-simple";[ue]=["@libp2p/metrics"];isStarted(){return this.started}start(){this.started=!0,this.interval=setInterval(this._emitMetrics,this.intervalMs)}stop(){this.started=!1,clearInterval(this.interval),this.transferStats.clear()}_emitMetrics(){Promise.resolve().then(async()=>{let e={};for(let[r,n]of this.metrics.entries())e[r]=await n.collect();this.onMetrics(structuredClone(e))}).catch(e=>{pt.error("could not invoke onMetrics callback - %e",e)})}_incrementValue(e,r){let n=this.transferStats.get(e)??0;this.transferStats.set(e,n+r)}_track(e,r){let n=e.dispatchEvent.bind(e);e.dispatchEvent=s=>(s.type==="message"&&this._incrementValue(`${r} received`,s.data.byteLength),n(s));let i=e.send.bind(e);e.send=s=>(this._incrementValue(`${r} sent`,s.byteLength),i(s))}trackMultiaddrConnection(e){this._track(e,"global")}trackProtocolStream(e){e.protocol!=null&&this._track(e,e.protocol)}registerMetric(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new G(r),this.metrics.set(e,n),n)}registerMetricGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new X(r),this.metrics.set(e,n),n)}registerCounter(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new G(r),this.metrics.set(e,n),n)}registerCounterGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new X(r),this.metrics.set(e,n),n)}registerHistogram(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new Q(r),this.metrics.set(e,n),n)}registerHistogramGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new ie(r),this.metrics.set(e,n),n)}registerSummary(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new K(r),this.metrics.set(e,n),n)}registerSummaryGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");let n=this.metrics.get(e);return n!=null?(this.log("reuse existing metric",e),n):(n=new se(r),this.metrics.set(e,n),n)}createTrace(){}traceFunction(e,r){return r}};function dt(t){return e=>new oe(e,t)}return Te(mt);})();
|
|
14
14
|
return Libp2PSimpleMetrics}));
|
|
15
15
|
//# sourceMappingURL=index.min.js.map
|