@libp2p/simple-metrics 1.1.2-a82ff8221 → 1.1.2-a8ec2bcb7
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 +1 -1
- package/package.json +3 -3
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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 ue=Object.create;var j=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var $=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),he=(t,e)=>{for(var r in e)j(t,r,{get:e[r],enumerable:!0})},G=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of le(e))!pe.call(t,s)&&s!==r&&j(t,s,{get:()=>e[s],enumerable:!(n=fe(e,s))||n.enumerable});return t};var me=(t,e,r)=>(r=t!=null?ue(de(t)):{},G(e||!t||!t.__esModule?j(r,"default",{value:t,enumerable:!0}):r,t)),be=t=>G(j({},"__esModule",{value:!0}),t);var K=$((dr,Z)=>{var I=1e3,O=I*60,P=O*60,M=P*24,Ce=M*7,ge=M*365.25;Z.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return xe(t);if(r==="number"&&isFinite(t))return e.long?ye(t):we(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function xe(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*ge;case"weeks":case"week":case"w":return r*Ce;case"days":case"day":case"d":return r*M;case"hours":case"hour":case"hrs":case"hr":case"h":return r*P;case"minutes":case"minute":case"mins":case"min":case"m":return r*O;case"seconds":case"second":case"secs":case"sec":case"s":return r*I;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function we(t){var e=Math.abs(t);return e>=M?Math.round(t/M)+"d":e>=P?Math.round(t/P)+"h":e>=O?Math.round(t/O)+"m":e>=I?Math.round(t/I)+"s":t+"ms"}function ye(t){var e=Math.abs(t);return e>=M?D(t,e,M,"day"):e>=P?D(t,e,P,"hour"):e>=O?D(t,e,O,"minute"):e>=I?D(t,e,I,"second"):t+" ms"}function D(t,e,r,n){var s=e>=r*1.5;return Math.round(t/r)+" "+n+(s?"s":"")}});var W=$((pr,Q)=>{function ve(t){r.debug=r,r.default=r,r.coerce=f,r.disable=d,r.enable=s,r.enabled=m,r.humanize=K(),r.destroy=E,Object.keys(t).forEach(o=>{r[o]=t[o]}),r.names=[],r.skips=[],r.formatters={};function e(o){let i=0;for(let l=0;l<o.length;l++)i=(i<<5)-i+o.charCodeAt(l),i|=0;return r.colors[Math.abs(i)%r.colors.length]}r.selectColor=e;function r(o){let i,l=null,k,a;function c(...p){if(!c.enabled)return;let h=c,C=Number(new Date),v=C-(i||C);h.diff=v,h.prev=i,h.curr=C,i=C,p[0]=r.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let b=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(F,x)=>{if(F==="%%")return"%";b++;let A=r.formatters[x];if(typeof A=="function"){let U=p[b];F=A.call(h,U),p.splice(b,1),b--}return F}),r.formatArgs.call(h,p),(h.log||r.log).apply(h,p)}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:()=>l!==null?l:(k!==r.namespaces&&(k=r.namespaces,a=r.enabled(o)),a),set:p=>{l=p}}),typeof r.init=="function"&&r.init(c),c}function n(o,i){let l=r(this.namespace+(typeof i>"u"?":":i)+o);return l.log=this.log,l}function s(o){r.save(o),r.namespaces=o,r.names=[],r.skips=[];let i,l=(typeof o=="string"?o:"").split(/[\s,]+/),k=l.length;for(i=0;i<k;i++)l[i]&&(o=l[i].replace(/\*/g,".*?"),o[0]==="-"?r.skips.push(new RegExp("^"+o.slice(1)+"$")):r.names.push(new RegExp("^"+o+"$")))}function d(){let o=[...r.names.map(u),...r.skips.map(u).map(i=>"-"+i)].join(",");return r.enable(""),o}function m(o){if(o[o.length-1]==="*")return!0;let i,l;for(i=0,l=r.skips.length;i<l;i++)if(r.skips[i].test(o))return!1;for(i=0,l=r.names.length;i<l;i++)if(r.names[i].test(o))return!0;return!1}function u(o){return o.toString().substring(2,o.toString().length-2).replace(/\.\*\?$/,"*")}function f(o){return o instanceof Error?o.stack||o.message:o}function E(){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.enable(r.load()),r}Q.exports=ve});var Y=$((w,L)=>{w.formatArgs=Ae;w.save=Ee;w.load=Se;w.useColors=Fe;w.storage=Me();w.destroy=(()=>{let t=!1;return()=>{t||(t=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();w.colors=["#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 Fe(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ae(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+L.exports.humanize(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,s=>{s!=="%%"&&(r++,s==="%c"&&(n=r))}),t.splice(n,0,e)}w.log=console.debug||console.log||(()=>{});function Ee(t){try{t?w.storage.setItem("debug",t):w.storage.removeItem("debug")}catch{}}function Se(){let t;try{t=w.storage.getItem("debug")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function Me(){try{return localStorage}catch{}}L.exports=W()(w);var{formatters:ke}=L.exports;ke.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var qe={};he(qe,{simpleMetrics:()=>_e});var X=Symbol.for("@libp2p/service-capabilities"),Ve=Symbol.for("@libp2p/service-dependencies");var y=me(Y(),1);var hr=new Uint8Array(0);function H(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ue(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var d=t.charAt(s),m=d.charCodeAt(0);if(r[m]!==255)throw new TypeError(d+" is ambiguous");r[m]=s}var u=t.length,f=t.charAt(0),E=Math.log(u)/Math.log(256),o=Math.log(256)/Math.log(u);function i(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var c=0,p=0,h=0,C=a.length;h!==C&&a[h]===0;)h++,c++;for(var v=(C-h)*o+1>>>0,b=new Uint8Array(v);h!==C;){for(var S=a[h],F=0,x=v-1;(S!==0||F<p)&&x!==-1;x--,F++)S+=256*b[x]>>>0,b[x]=S%u>>>0,S=S/u>>>0;if(S!==0)throw new Error("Non-zero carry");p=F,h++}for(var A=v-p;A!==v&&b[A]===0;)A++;for(var U=f.repeat(c);A<v;++A)U+=t.charAt(b[A]);return U}function l(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var c=0;if(a[c]!==" "){for(var p=0,h=0;a[c]===f;)p++,c++;for(var C=(a.length-c)*E+1>>>0,v=new Uint8Array(C);a[c];){var b=r[a.charCodeAt(c)];if(b===255)return;for(var S=0,F=C-1;(b!==0||S<h)&&F!==-1;F--,S++)b+=u*v[F]>>>0,v[F]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");h=S,c++}if(a[c]!==" "){for(var x=C-h;x!==C&&v[x]===0;)x++;for(var A=new Uint8Array(p+(C-x)),U=p;x!==C;)A[U++]=v[x++];return A}}}function k(a){var c=l(a);if(c)return c;throw new Error(`Non-${e} character`)}return{encode:i,decodeUnsafe:l,decode:k}}var Ie=Ue,Oe=Ie,ee=Oe;var _=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")}},q=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 re(this,e)}},R=class{decoders;constructor(e){this.decoders=e}or(e){return re(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 re(t,e){return new R({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var V=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new _(e,r,n),this.decoder=new q(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:t,prefix:e,encode:r,decode:n}){return new V(t,e,r,n)}function T({name:t,prefix:e,alphabet:r}){let{encode:n,decode:s}=ee(r,t);return te({prefix:e,name:t,encode:n,decode:d=>H(s(d))})}function Pe(t,e,r,n){let s={};for(let o=0;o<e.length;++o)s[e[o]]=o;let d=t.length;for(;t[d-1]==="=";)--d;let m=new Uint8Array(d*r/8|0),u=0,f=0,E=0;for(let o=0;o<d;++o){let i=s[t[o]];if(i===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|i,u+=r,u>=8&&(u-=8,m[E++]=255&f>>u)}if(u>=r||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return m}function ze(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,d="",m=0,u=0;for(let f=0;f<t.length;++f)for(u=u<<8|t[f],m+=8;m>r;)m-=r,d+=e[s&u>>m];if(m!==0&&(d+=e[s&u<<r-m]),n)for(;d.length*r&7;)d+="=";return d}function g({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return te({prefix:e,name:t,encode(s){return ze(s,n,r)},decode(s){return Pe(s,n,r,t)}})}var ne=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),yr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ar=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Er=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Sr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),kr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oe=T({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Or=T({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var se=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});y.default.formatters.b=t=>t==null?"undefined":oe.baseEncode(t);y.default.formatters.t=t=>t==null?"undefined":ne.baseEncode(t);y.default.formatters.m=t=>t==null?"undefined":se.baseEncode(t);y.default.formatters.p=t=>t==null?"undefined":t.toString();y.default.formatters.c=t=>t==null?"undefined":t.toString();y.default.formatters.k=t=>t==null?"undefined":t.toString();y.default.formatters.a=t=>t==null?"undefined":t.toString();function Ne(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function ie(t){let e=Ne(`${t}:trace`);return y.default.enabled(`${t}:trace`)&&y.default.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=(0,y.default)(`${t}:trace`)),Object.assign((0,y.default)(t),{error:(0,y.default)(`${t}:error`),trace:e})}function je(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var ae=je;function De(t){return t[Symbol.asyncIterator]!=null}function ce(t){return t?.then!=null}function Le(t,e){let r=0;if(De(t))return async function*(){for await(let f of t){let E=e(f,r++);ce(E)&&await E,yield f}}();let n=ae(t),{value:s,done:d}=n.next();if(d===!0)return function*(){}();if(typeof e(s,r++)?.then=="function")return async function*(){yield s;for await(let f of n){let E=e(f,r++);ce(E)&&await E,yield f}}();let u=e;return function*(){yield s;for(let f of n)u(f,r++),yield f}()}var B=Le;var $e=ie("libp2p:simple-metrics"),z=class{value=0;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}}},N=class{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 s=typeof n=="number"?n:1;this.values[r]+=Number(s)})}decrement(e){Object.entries(e).forEach(([r,n])=>{this.values[r]=this.values[r]??0;let s=typeof n=="number"?n:1;this.values[r]-=Number(s)})}reset(){this.values={}}timer(e){let r=Date.now();return()=>{this.values[e]=Date.now()-r}}},J=class{metrics=new Map;transferStats;started;interval;intervalMs;onMetrics;constructor(e,r){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";[X]=["@libp2p/metrics"];isStarted(){return this.started}start(){this.started=!0,this.interval=setInterval(this._emitMetrics,this.intervalMs)}stop(){this.started=!1,clearInterval(this.interval)}_emitMetrics(){Promise.resolve().then(async()=>{let e={};for(let[r,n]of this.metrics.entries())n instanceof z?e[r]=n.value:n instanceof N?e[r]=n.values:e[r]=await n();this.onMetrics(structuredClone(e))}).catch(e=>{$e.error("could not invoke onMetrics callback",e)})}_incrementValue(e,r){let n=this.transferStats.get(e)??0;this.transferStats.set(e,n+r)}_track(e,r){let n=this,s=e.sink;e.sink=async function(u){await s(B(u,f=>{n._incrementValue(`${r} sent`,f.byteLength)}))};let d=e.source;e.source=B(d,m=>{n._incrementValue(`${r} received`,m.byteLength)})}trackMultiaddrConnection(e){this._track(e,"global")}trackProtocolStream(e,r){e.protocol!=null&&this._track(e,e.protocol)}registerMetric(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(r?.calculate!=null){this.metrics.set(e,r.calculate);return}let n=new z;return this.metrics.set(e,n),n}registerMetricGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(r?.calculate!=null){this.metrics.set(e,r.calculate);return}let n=new N;return this.metrics.set(e,n),n}registerCounter(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(r?.calculate!=null){this.metrics.set(e,r.calculate);return}let n=new z;return this.metrics.set(e,n),n}registerCounterGroup(e,r={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(r?.calculate!=null){this.metrics.set(e,r.calculate);return}let n=new N;return this.metrics.set(e,n),n}};function _e(t){return e=>new J(e,t)}return be(qe);})();
|
|
2
|
+
"use strict";var Libp2PSimpleMetrics=(()=>{var ue=Object.create;var j=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var $=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),he=(r,e)=>{for(var t in e)j(r,t,{get:e[t],enumerable:!0})},G=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of le(e))!pe.call(r,s)&&s!==t&&j(r,s,{get:()=>e[s],enumerable:!(n=fe(e,s))||n.enumerable});return r};var me=(r,e,t)=>(t=r!=null?ue(de(r)):{},G(e||!r||!r.__esModule?j(t,"default",{value:r,enumerable:!0}):t,r)),be=r=>G(j({},"__esModule",{value:!0}),r);var K=$((dr,Z)=>{var I=1e3,O=I*60,P=O*60,M=P*24,Ce=M*7,ge=M*365.25;Z.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return xe(r);if(t==="number"&&isFinite(r))return e.long?ye(r):we(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function xe(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*ge;case"weeks":case"week":case"w":return t*Ce;case"days":case"day":case"d":return t*M;case"hours":case"hour":case"hrs":case"hr":case"h":return t*P;case"minutes":case"minute":case"mins":case"min":case"m":return t*O;case"seconds":case"second":case"secs":case"sec":case"s":return t*I;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function we(r){var e=Math.abs(r);return e>=M?Math.round(r/M)+"d":e>=P?Math.round(r/P)+"h":e>=O?Math.round(r/O)+"m":e>=I?Math.round(r/I)+"s":r+"ms"}function ye(r){var e=Math.abs(r);return e>=M?D(r,e,M,"day"):e>=P?D(r,e,P,"hour"):e>=O?D(r,e,O,"minute"):e>=I?D(r,e,I,"second"):r+" ms"}function D(r,e,t,n){var s=e>=t*1.5;return Math.round(r/t)+" "+n+(s?"s":"")}});var W=$((pr,Q)=>{function ve(r){t.debug=t,t.default=t,t.coerce=f,t.disable=d,t.enable=s,t.enabled=m,t.humanize=K(),t.destroy=E,Object.keys(r).forEach(o=>{t[o]=r[o]}),t.names=[],t.skips=[],t.formatters={};function e(o){let i=0;for(let l=0;l<o.length;l++)i=(i<<5)-i+o.charCodeAt(l),i|=0;return t.colors[Math.abs(i)%t.colors.length]}t.selectColor=e;function t(o){let i,l=null,k,a;function c(...p){if(!c.enabled)return;let h=c,C=Number(new Date),v=C-(i||C);h.diff=v,h.prev=i,h.curr=C,i=C,p[0]=t.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let b=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(F,x)=>{if(F==="%%")return"%";b++;let A=t.formatters[x];if(typeof A=="function"){let U=p[b];F=A.call(h,U),p.splice(b,1),b--}return F}),t.formatArgs.call(h,p),(h.log||t.log).apply(h,p)}return c.namespace=o,c.useColors=t.useColors(),c.color=t.selectColor(o),c.extend=n,c.destroy=t.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>l!==null?l:(k!==t.namespaces&&(k=t.namespaces,a=t.enabled(o)),a),set:p=>{l=p}}),typeof t.init=="function"&&t.init(c),c}function n(o,i){let l=t(this.namespace+(typeof i>"u"?":":i)+o);return l.log=this.log,l}function s(o){t.save(o),t.namespaces=o,t.names=[],t.skips=[];let i,l=(typeof o=="string"?o:"").split(/[\s,]+/),k=l.length;for(i=0;i<k;i++)l[i]&&(o=l[i].replace(/\*/g,".*?"),o[0]==="-"?t.skips.push(new RegExp("^"+o.slice(1)+"$")):t.names.push(new RegExp("^"+o+"$")))}function d(){let o=[...t.names.map(u),...t.skips.map(u).map(i=>"-"+i)].join(",");return t.enable(""),o}function m(o){if(o[o.length-1]==="*")return!0;let i,l;for(i=0,l=t.skips.length;i<l;i++)if(t.skips[i].test(o))return!1;for(i=0,l=t.names.length;i<l;i++)if(t.names[i].test(o))return!0;return!1}function u(o){return o.toString().substring(2,o.toString().length-2).replace(/\.\*\?$/,"*")}function f(o){return o instanceof Error?o.stack||o.message:o}function E(){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 t.enable(t.load()),t}Q.exports=ve});var Y=$((w,L)=>{w.formatArgs=Ae;w.save=Ee;w.load=Se;w.useColors=Fe;w.storage=Me();w.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();w.colors=["#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 Fe(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let r;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(r[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ae(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+L.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,n=0;r[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(t++,s==="%c"&&(n=t))}),r.splice(n,0,e)}w.log=console.debug||console.log||(()=>{});function Ee(r){try{r?w.storage.setItem("debug",r):w.storage.removeItem("debug")}catch{}}function Se(){let r;try{r=w.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Me(){try{return localStorage}catch{}}L.exports=W()(w);var{formatters:ke}=L.exports;ke.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var qe={};he(qe,{simpleMetrics:()=>_e});var X=Symbol.for("@libp2p/service-capabilities"),Re=Symbol.for("@libp2p/service-dependencies");var y=me(Y(),1);var hr=new Uint8Array(0);function H(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ue(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var s=0;s<r.length;s++){var d=r.charAt(s),m=d.charCodeAt(0);if(t[m]!==255)throw new TypeError(d+" is ambiguous");t[m]=s}var u=r.length,f=r.charAt(0),E=Math.log(u)/Math.log(256),o=Math.log(256)/Math.log(u);function i(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var c=0,p=0,h=0,C=a.length;h!==C&&a[h]===0;)h++,c++;for(var v=(C-h)*o+1>>>0,b=new Uint8Array(v);h!==C;){for(var S=a[h],F=0,x=v-1;(S!==0||F<p)&&x!==-1;x--,F++)S+=256*b[x]>>>0,b[x]=S%u>>>0,S=S/u>>>0;if(S!==0)throw new Error("Non-zero carry");p=F,h++}for(var A=v-p;A!==v&&b[A]===0;)A++;for(var U=f.repeat(c);A<v;++A)U+=r.charAt(b[A]);return U}function l(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var c=0;if(a[c]!==" "){for(var p=0,h=0;a[c]===f;)p++,c++;for(var C=(a.length-c)*E+1>>>0,v=new Uint8Array(C);a[c];){var b=t[a.charCodeAt(c)];if(b===255)return;for(var S=0,F=C-1;(b!==0||S<h)&&F!==-1;F--,S++)b+=u*v[F]>>>0,v[F]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");h=S,c++}if(a[c]!==" "){for(var x=C-h;x!==C&&v[x]===0;)x++;for(var A=new Uint8Array(p+(C-x)),U=p;x!==C;)A[U++]=v[x++];return A}}}function k(a){var c=l(a);if(c)return c;throw new Error(`Non-${e} character`)}return{encode:i,decodeUnsafe:l,decode:k}}var Ie=Ue,Oe=Ie,ee=Oe;var _=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},q=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 re(this,e)}},V=class{decoders;constructor(e){this.decoders=e}or(e){return re(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 re(r,e){return new V({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var R=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new _(e,t,n),this.decoder=new q(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new R(r,e,t,n)}function T({name:r,prefix:e,alphabet:t}){let{encode:n,decode:s}=ee(t,r);return te({prefix:e,name:r,encode:n,decode:d=>H(s(d))})}function Pe(r,e,t,n){let s={};for(let o=0;o<e.length;++o)s[e[o]]=o;let d=r.length;for(;r[d-1]==="=";)--d;let m=new Uint8Array(d*t/8|0),u=0,f=0,E=0;for(let o=0;o<d;++o){let i=s[r[o]];if(i===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|i,u+=t,u>=8&&(u-=8,m[E++]=255&f>>u)}if(u>=t||255&f<<8-u)throw new SyntaxError("Unexpected end of data");return m}function ze(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,d="",m=0,u=0;for(let f=0;f<r.length;++f)for(u=u<<8|r[f],m+=8;m>t;)m-=t,d+=e[s&u>>m];if(m!==0&&(d+=e[s&u<<t-m]),n)for(;d.length*t&7;)d+="=";return d}function g({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return te({prefix:e,name:r,encode(s){return ze(s,n,t)},decode(s){return Pe(s,n,t,r)}})}var ne=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),yr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ar=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Er=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Sr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),kr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var oe=T({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Or=T({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var se=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});y.default.formatters.b=r=>r==null?"undefined":oe.baseEncode(r);y.default.formatters.t=r=>r==null?"undefined":ne.baseEncode(r);y.default.formatters.m=r=>r==null?"undefined":se.baseEncode(r);y.default.formatters.p=r=>r==null?"undefined":r.toString();y.default.formatters.c=r=>r==null?"undefined":r.toString();y.default.formatters.k=r=>r==null?"undefined":r.toString();y.default.formatters.a=r=>r==null?"undefined":r.toString();function Ne(r){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=r,e.destroy=()=>!0,e.extend=()=>e,e}function ie(r){let e=Ne(`${r}:trace`);return y.default.enabled(`${r}:trace`)&&y.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(e=(0,y.default)(`${r}:trace`)),Object.assign((0,y.default)(r),{error:(0,y.default)(`${r}:error`),trace:e})}function je(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:s=>{n.push(s)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var ae=je;function De(r){return r[Symbol.asyncIterator]!=null}function ce(r){return r?.then!=null}function Le(r,e){let t=0;if(De(r))return async function*(){for await(let f of r){let E=e(f,t++);ce(E)&&await E,yield f}}();let n=ae(r),{value:s,done:d}=n.next();if(d===!0)return function*(){}();if(typeof e(s,t++)?.then=="function")return async function*(){yield s;for await(let f of n){let E=e(f,t++);ce(E)&&await E,yield f}}();let u=e;return function*(){yield s;for(let f of n)u(f,t++),yield f}()}var B=Le;var $e=ie("libp2p:simple-metrics"),z=class{value=0;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}}},N=class{values={};update(e){Object.entries(e).forEach(([t,n])=>{this.values[t]=n})}increment(e){Object.entries(e).forEach(([t,n])=>{this.values[t]=this.values[t]??0;let s=typeof n=="number"?n:1;this.values[t]+=Number(s)})}decrement(e){Object.entries(e).forEach(([t,n])=>{this.values[t]=this.values[t]??0;let s=typeof n=="number"?n:1;this.values[t]-=Number(s)})}reset(){this.values={}}timer(e){let t=Date.now();return()=>{this.values[e]=Date.now()-t}}},J=class{metrics=new Map;transferStats;started;interval;intervalMs;onMetrics;constructor(e,t){this.started=!1,this._emitMetrics=this._emitMetrics.bind(this),this.intervalMs=t.intervalMs??1e3,this.onMetrics=t.onMetrics,this.transferStats=new Map}[Symbol.toStringTag]="@libp2p/metrics-simple";[X]=["@libp2p/metrics"];isStarted(){return this.started}start(){this.started=!0,this.interval=setInterval(this._emitMetrics,this.intervalMs)}stop(){this.started=!1,clearInterval(this.interval)}_emitMetrics(){Promise.resolve().then(async()=>{let e={};for(let[t,n]of this.metrics.entries())n instanceof z?e[t]=n.value:n instanceof N?e[t]=n.values:e[t]=await n();this.onMetrics(structuredClone(e))}).catch(e=>{$e.error("could not invoke onMetrics callback",e)})}_incrementValue(e,t){let n=this.transferStats.get(e)??0;this.transferStats.set(e,n+t)}_track(e,t){let n=this,s=e.sink;e.sink=async function(u){await s(B(u,f=>{n._incrementValue(`${t} sent`,f.byteLength)}))};let d=e.source;e.source=B(d,m=>{n._incrementValue(`${t} received`,m.byteLength)})}trackMultiaddrConnection(e){this._track(e,"global")}trackProtocolStream(e,t){e.protocol!=null&&this._track(e,e.protocol)}registerMetric(e,t={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(t?.calculate!=null){this.metrics.set(e,t.calculate);return}let n=new z;return this.metrics.set(e,n),n}registerMetricGroup(e,t={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(t?.calculate!=null){this.metrics.set(e,t.calculate);return}let n=new N;return this.metrics.set(e,n),n}registerCounter(e,t={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(t?.calculate!=null){this.metrics.set(e,t.calculate);return}let n=new z;return this.metrics.set(e,n),n}registerCounterGroup(e,t={}){if(e==null||e.trim()==="")throw new Error("Metric name is required");if(t?.calculate!=null){this.metrics.set(e,t.calculate);return}let n=new N;return this.metrics.set(e,n),n}};function _e(r){return e=>new J(e,r)}return be(qe);})();
|
|
3
3
|
return Libp2PSimpleMetrics}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/simple-metrics",
|
|
3
|
-
"version": "1.1.2-
|
|
3
|
+
"version": "1.1.2-a8ec2bcb7",
|
|
4
4
|
"description": "Simple in-memory metrics gathering for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-simple#readme",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"dep-check": "aegir dep-check -i events"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@libp2p/interface": "1.6.1-
|
|
54
|
-
"@libp2p/logger": "4.0.17-
|
|
53
|
+
"@libp2p/interface": "1.6.1-a8ec2bcb7",
|
|
54
|
+
"@libp2p/logger": "4.0.17-a8ec2bcb7",
|
|
55
55
|
"it-foreach": "^2.1.0",
|
|
56
56
|
"it-stream-types": "^2.0.1"
|
|
57
57
|
},
|