@libp2p/interface
Advanced tools
Comparing version 2.0.1 to 2.1.0
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PInterface = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var X=(t,r)=>{for(var e in r)n(t,e,{get:r[e],enumerable:!0})},Y=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of V(r))!W.call(t,o)&&o!==e&&n(t,o,{get:()=>r[o],enumerable:!(s=Q(r,o))||s.enumerable});return t};var Z=t=>Y(n({},"__esModule",{value:!0}),t);var mr={};X(mr,{AbortError:()=>c,AlreadyStartedError:()=>U,ConnectionClosedError:()=>E,ConnectionClosingError:()=>f,ConnectionFailedError:()=>h,DialError:()=>D,FaultTolerance:()=>i,InvalidCIDError:()=>P,InvalidCryptoExchangeError:()=>l,InvalidMessageError:()=>w,InvalidMultiaddrError:()=>g,InvalidMultihashError:()=>L,InvalidParametersError:()=>u,InvalidPeerIdError:()=>I,InvalidPrivateKeyError:()=>x,InvalidPublicKeyError:()=>m,KEEP_ALIVE:()=>sr,LimitedConnectionError:()=>K,ListenError:()=>N,MuxerClosedError:()=>y,NotFoundError:()=>v,NotStartedError:()=>M,ProtocolError:()=>C,StreamResetError:()=>b,StreamStateError:()=>S,StrictNoSign:()=>ar,StrictSign:()=>nr,TimeoutError:()=>T,TooManyInboundProtocolStreamsError:()=>R,TooManyOutboundProtocolStreamsError:()=>_,TopicValidatorResult:()=>a,TypedEventEmitter:()=>B,UnexpectedPeerError:()=>p,UnsupportedKeyTypeError:()=>F,UnsupportedOperationError:()=>d,UnsupportedProtocolError:()=>A,connectionSymbol:()=>q,contentRoutingSymbol:()=>k,isConnection:()=>$,isPeerId:()=>er,isPrivateKey:()=>rr,isPublicKey:()=>z,isStartable:()=>j,isTransport:()=>ir,peerDiscoverySymbol:()=>tr,peerIdSymbol:()=>G,peerRoutingSymbol:()=>or,serviceCapabilities:()=>lr,serviceDependencies:()=>ur,setMaxListeners:()=>O,start:()=>cr,stop:()=>pr,transportSymbol:()=>H});var q=Symbol.for("@libp2p/connection");function $(t){return t!=null&&!!t[q]}var k=Symbol.for("@libp2p/content-routing");function z(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}function rr(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1")&&z(t.publicKey)&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.sign=="function"}var tr=Symbol.for("@libp2p/peer-discovery");var G=Symbol.for("@libp2p/peer-id");function er(t){return!!t?.[G]}var or=Symbol.for("@libp2p/peer-routing");var sr="keep-alive";var nr="StrictSign",ar="StrictNoSign",a;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(a||(a={}));var H=Symbol.for("@libp2p/transport");function ir(t){return t!=null&&!!t[H]}var i;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(i||(i={}));var c=class extends Error{static name="AbortError";constructor(r="The operation was aborted"){super(r),this.name="AbortError"}},p=class extends Error{static name="UnexpectedPeerError";constructor(r="Unexpected Peer"){super(r),this.name="UnexpectedPeerError"}},l=class extends Error{static name="InvalidCryptoExchangeError";constructor(r="Invalid crypto exchange"){super(r),this.name="InvalidCryptoExchangeError"}},u=class extends Error{static name="InvalidParametersError";constructor(r="Invalid parameters"){super(r),this.name="InvalidParametersError"}},m=class extends Error{static name="InvalidPublicKeyError";constructor(r="Invalid public key"){super(r),this.name="InvalidPublicKeyError"}},x=class extends Error{static name="InvalidPrivateKeyError";constructor(r="Invalid private key"){super(r),this.name="InvalidPrivateKeyError"}},d=class extends Error{static name="UnsupportedOperationError";constructor(r="Unsupported operation"){super(r),this.name="UnsupportedOperationError"}},f=class extends Error{static name="ConnectionClosingError";constructor(r="The connection is closing"){super(r),this.name="ConnectionClosingError"}},E=class extends Error{static name="ConnectionClosedError";constructor(r="The connection is closed"){super(r),this.name="ConnectionClosedError"}},h=class extends Error{static name="ConnectionFailedError";constructor(r="Connection failed"){super(r),this.name="ConnectionFailedError"}},y=class extends Error{static name="MuxerClosedError";constructor(r="The muxer is closed"){super(r),this.name="MuxerClosedError"}},b=class extends Error{static name="StreamResetError";constructor(r="The stream has been reset"){super(r),this.name="StreamResetError"}},S=class extends Error{static name="StreamStateError";constructor(r="The stream is in an invalid state"){super(r),this.name="StreamStateError"}},v=class extends Error{static name="NotFoundError";constructor(r="Not found"){super(r),this.name="NotFoundError"}},I=class extends Error{static name="InvalidPeerIdError";constructor(r="Invalid PeerID"){super(r),this.name="InvalidPeerIdError"}},g=class extends Error{static name="InvalidMultiaddrError";constructor(r="Invalid multiaddr"){super(r),this.name="InvalidMultiaddrError"}},P=class extends Error{static name="InvalidCIDError";constructor(r="Invalid CID"){super(r),this.name="InvalidCIDError"}},L=class extends Error{static name="InvalidMultihashError";constructor(r="Invalid Multihash"){super(r),this.name="InvalidMultihashError"}},A=class extends Error{static name="UnsupportedProtocolError";constructor(r="Unsupported protocol error"){super(r),this.name="UnsupportedProtocolError"}},w=class extends Error{static name="InvalidMessageError";constructor(r="Invalid message"){super(r),this.name="InvalidMessageError"}},C=class extends Error{static name="ProtocolError";constructor(r="Protocol error"){super(r),this.name="ProtocolError"}},T=class extends Error{static name="TimeoutError";constructor(r="Timed out"){super(r),this.name="TimeoutError"}},M=class extends Error{static name="NotStartedError";constructor(r="Not started"){super(r),this.name="NotStartedError"}},U=class extends Error{static name="AlreadyStartedError";constructor(r="Already started"){super(r),this.name="AlreadyStartedError"}},D=class extends Error{static name="DialError";constructor(r="Dial error"){super(r),this.name="DialError"}},N=class extends Error{static name="ListenError";constructor(r="Listen error"){super(r),this.name="ListenError"}},K=class extends Error{static name="LimitedConnectionError";constructor(r="Limited connection"){super(r),this.name="LimitedConnectionError"}},R=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(r="Too many inbound protocol streams"){super(r),this.name="TooManyInboundProtocolStreamsError"}},_=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(r="Too many outbound protocol streams"){super(r),this.name="TooManyOutboundProtocolStreamsError"}},F=class extends Error{static name="UnsupportedKeyTypeError";constructor(r="Unsupported key type"){super(r),this.name="UnsupportedKeyTypeError"}};var O=(t,...r)=>{try{[...r]}catch{}};var B=class extends EventTarget{#r=new Map;constructor(){super(),O(1/0,this)}listenerCount(r){let e=this.#r.get(r);return e==null?0:e.length}addEventListener(r,e,s){super.addEventListener(r,e,s);let o=this.#r.get(r);o==null&&(o=[],this.#r.set(r,o)),o.push({callback:e,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(r,e,s){super.removeEventListener(r.toString(),e??null,s);let o=this.#r.get(r);o!=null&&(o=o.filter(({callback:J})=>J!==e),this.#r.set(r,o))}dispatchEvent(r){let e=super.dispatchEvent(r),s=this.#r.get(r.type);return s==null||(s=s.filter(({once:o})=>!o),this.#r.set(r.type,s)),e}safeDispatchEvent(r,e={}){return this.dispatchEvent(new CustomEvent(r,e))}};function j(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function cr(...t){let r=[];for(let e of t)j(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(r.map(async e=>{await e.start()})),await Promise.all(r.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function pr(...t){let r=[];for(let e of t)j(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(r.map(async e=>{await e.stop()})),await Promise.all(r.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var lr=Symbol.for("@libp2p/service-capabilities"),ur=Symbol.for("@libp2p/service-dependencies");return Z(mr);})(); | ||
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Y=(t,r)=>{for(var e in r)n(t,e,{get:r[e],enumerable:!0})},Z=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of W(r))!X.call(t,o)&&o!==e&&n(t,o,{get:()=>r[o],enumerable:!(s=V(r,o))||s.enumerable});return t};var $=t=>Z(n({},"__esModule",{value:!0}),t);var dr={};Y(dr,{AbortError:()=>c,AlreadyStartedError:()=>U,ConnectionClosedError:()=>E,ConnectionClosingError:()=>f,ConnectionFailedError:()=>h,DialError:()=>D,FaultTolerance:()=>i,InvalidCIDError:()=>P,InvalidCryptoExchangeError:()=>l,InvalidMessageError:()=>w,InvalidMultiaddrError:()=>g,InvalidMultihashError:()=>L,InvalidParametersError:()=>u,InvalidPeerIdError:()=>I,InvalidPrivateKeyError:()=>x,InvalidPublicKeyError:()=>m,KEEP_ALIVE:()=>nr,LimitedConnectionError:()=>K,ListenError:()=>N,MuxerClosedError:()=>b,NotFoundError:()=>v,NotStartedError:()=>M,ProtocolError:()=>C,StreamResetError:()=>y,StreamStateError:()=>S,StrictNoSign:()=>ir,StrictSign:()=>ar,TimeoutError:()=>T,TooManyInboundProtocolStreamsError:()=>R,TooManyOutboundProtocolStreamsError:()=>_,TopicValidatorResult:()=>a,TypedEventEmitter:()=>O,UnexpectedPeerError:()=>p,UnsupportedKeyTypeError:()=>B,UnsupportedOperationError:()=>d,UnsupportedProtocolError:()=>A,connectionSymbol:()=>q,contentRoutingSymbol:()=>rr,isConnection:()=>k,isPeerId:()=>or,isPrivateKey:()=>tr,isPubSub:()=>cr,isPublicKey:()=>z,isStartable:()=>j,isTransport:()=>pr,peerDiscoverySymbol:()=>er,peerIdSymbol:()=>G,peerRoutingSymbol:()=>sr,pubSubSymbol:()=>H,serviceCapabilities:()=>mr,serviceDependencies:()=>xr,setMaxListeners:()=>F,start:()=>lr,stop:()=>ur,transportSymbol:()=>J});var q=Symbol.for("@libp2p/connection");function k(t){return t!=null&&!!t[q]}var rr=Symbol.for("@libp2p/content-routing");function z(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1")&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.toMultihash=="function"&&typeof t.toCID=="function"&&typeof t.verify=="function"}function tr(t){return t==null?!1:(t.type==="RSA"||t.type==="Ed25519"||t.type==="secp256k1")&&z(t.publicKey)&&t.raw instanceof Uint8Array&&typeof t.equals=="function"&&typeof t.sign=="function"}var er=Symbol.for("@libp2p/peer-discovery");var G=Symbol.for("@libp2p/peer-id");function or(t){return!!t?.[G]}var sr=Symbol.for("@libp2p/peer-routing");var nr="keep-alive";var ar="StrictSign",ir="StrictNoSign",a;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(a||(a={}));var H=Symbol.for("@libp2p/pubsub");function cr(t){return!!t?.[H]}var J=Symbol.for("@libp2p/transport");function pr(t){return t!=null&&!!t[J]}var i;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(i||(i={}));var c=class extends Error{static name="AbortError";constructor(r="The operation was aborted"){super(r),this.name="AbortError"}},p=class extends Error{static name="UnexpectedPeerError";constructor(r="Unexpected Peer"){super(r),this.name="UnexpectedPeerError"}},l=class extends Error{static name="InvalidCryptoExchangeError";constructor(r="Invalid crypto exchange"){super(r),this.name="InvalidCryptoExchangeError"}},u=class extends Error{static name="InvalidParametersError";constructor(r="Invalid parameters"){super(r),this.name="InvalidParametersError"}},m=class extends Error{static name="InvalidPublicKeyError";constructor(r="Invalid public key"){super(r),this.name="InvalidPublicKeyError"}},x=class extends Error{static name="InvalidPrivateKeyError";constructor(r="Invalid private key"){super(r),this.name="InvalidPrivateKeyError"}},d=class extends Error{static name="UnsupportedOperationError";constructor(r="Unsupported operation"){super(r),this.name="UnsupportedOperationError"}},f=class extends Error{static name="ConnectionClosingError";constructor(r="The connection is closing"){super(r),this.name="ConnectionClosingError"}},E=class extends Error{static name="ConnectionClosedError";constructor(r="The connection is closed"){super(r),this.name="ConnectionClosedError"}},h=class extends Error{static name="ConnectionFailedError";constructor(r="Connection failed"){super(r),this.name="ConnectionFailedError"}},b=class extends Error{static name="MuxerClosedError";constructor(r="The muxer is closed"){super(r),this.name="MuxerClosedError"}},y=class extends Error{static name="StreamResetError";constructor(r="The stream has been reset"){super(r),this.name="StreamResetError"}},S=class extends Error{static name="StreamStateError";constructor(r="The stream is in an invalid state"){super(r),this.name="StreamStateError"}},v=class extends Error{static name="NotFoundError";constructor(r="Not found"){super(r),this.name="NotFoundError"}},I=class extends Error{static name="InvalidPeerIdError";constructor(r="Invalid PeerID"){super(r),this.name="InvalidPeerIdError"}},g=class extends Error{static name="InvalidMultiaddrError";constructor(r="Invalid multiaddr"){super(r),this.name="InvalidMultiaddrError"}},P=class extends Error{static name="InvalidCIDError";constructor(r="Invalid CID"){super(r),this.name="InvalidCIDError"}},L=class extends Error{static name="InvalidMultihashError";constructor(r="Invalid Multihash"){super(r),this.name="InvalidMultihashError"}},A=class extends Error{static name="UnsupportedProtocolError";constructor(r="Unsupported protocol error"){super(r),this.name="UnsupportedProtocolError"}},w=class extends Error{static name="InvalidMessageError";constructor(r="Invalid message"){super(r),this.name="InvalidMessageError"}},C=class extends Error{static name="ProtocolError";constructor(r="Protocol error"){super(r),this.name="ProtocolError"}},T=class extends Error{static name="TimeoutError";constructor(r="Timed out"){super(r),this.name="TimeoutError"}},M=class extends Error{static name="NotStartedError";constructor(r="Not started"){super(r),this.name="NotStartedError"}},U=class extends Error{static name="AlreadyStartedError";constructor(r="Already started"){super(r),this.name="AlreadyStartedError"}},D=class extends Error{static name="DialError";constructor(r="Dial error"){super(r),this.name="DialError"}},N=class extends Error{static name="ListenError";constructor(r="Listen error"){super(r),this.name="ListenError"}},K=class extends Error{static name="LimitedConnectionError";constructor(r="Limited connection"){super(r),this.name="LimitedConnectionError"}},R=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(r="Too many inbound protocol streams"){super(r),this.name="TooManyInboundProtocolStreamsError"}},_=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(r="Too many outbound protocol streams"){super(r),this.name="TooManyOutboundProtocolStreamsError"}},B=class extends Error{static name="UnsupportedKeyTypeError";constructor(r="Unsupported key type"){super(r),this.name="UnsupportedKeyTypeError"}};var F=(t,...r)=>{try{[...r]}catch{}};var O=class extends EventTarget{#r=new Map;constructor(){super(),F(1/0,this)}listenerCount(r){let e=this.#r.get(r);return e==null?0:e.length}addEventListener(r,e,s){super.addEventListener(r,e,s);let o=this.#r.get(r);o==null&&(o=[],this.#r.set(r,o)),o.push({callback:e,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(r,e,s){super.removeEventListener(r.toString(),e??null,s);let o=this.#r.get(r);o!=null&&(o=o.filter(({callback:Q})=>Q!==e),this.#r.set(r,o))}dispatchEvent(r){let e=super.dispatchEvent(r),s=this.#r.get(r.type);return s==null||(s=s.filter(({once:o})=>!o),this.#r.set(r.type,s)),e}safeDispatchEvent(r,e={}){return this.dispatchEvent(new CustomEvent(r,e))}};function j(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function lr(...t){let r=[];for(let e of t)j(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(r.map(async e=>{await e.start()})),await Promise.all(r.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function ur(...t){let r=[];for(let e of t)j(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(r.map(async e=>{await e.stop()})),await Promise.all(r.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var mr=Symbol.for("@libp2p/service-capabilities"),xr=Symbol.for("@libp2p/service-dependencies");return $(dr);})(); | ||
return Libp2PInterface})); |
@@ -127,3 +127,123 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js'; | ||
} | ||
export interface HistogramOptions extends MetricOptions { | ||
/** | ||
* Buckets for the histogram | ||
*/ | ||
buckets?: number[]; | ||
} | ||
/** | ||
* Create tracked metrics that are expensive to calculate by passing | ||
* a function that is only invoked when metrics are being scraped | ||
*/ | ||
export interface CalculatedHistogramOptions<T = number> extends HistogramOptions { | ||
/** | ||
* An optional function invoked to calculate the component metric instead of | ||
* using `.observe` | ||
*/ | ||
calculate: CalculateMetric<T>; | ||
} | ||
export interface Histogram { | ||
/** | ||
* Observe the passed value | ||
*/ | ||
observe(value: number): void; | ||
/** | ||
* Reset this histogram to its default value | ||
*/ | ||
reset(): void; | ||
/** | ||
* Start a timed metric, call the returned function to | ||
* stop the timer | ||
*/ | ||
timer(): StopTimer; | ||
} | ||
export interface HistogramGroup<T extends string = any> { | ||
/** | ||
* Observe the passed value for the named key in the group | ||
*/ | ||
observe(values: Partial<Record<T, number>>): void; | ||
/** | ||
* Reset the passed key in this histogram group to its default value | ||
* or all keys if no key is passed | ||
*/ | ||
reset(): void; | ||
/** | ||
* Start a timed metric for the named key in the group, call | ||
* the returned function to stop the timer | ||
*/ | ||
timer(key: string): StopTimer; | ||
} | ||
export interface SummaryOptions extends MetricOptions { | ||
/** | ||
* Percentiles for the summary | ||
*/ | ||
percentiles?: number[]; | ||
/** | ||
* Configure how old a bucket can be before it is reset for sliding window | ||
*/ | ||
maxAgeSeconds?: number; | ||
/** | ||
* Configure how many buckets in the sliding window | ||
*/ | ||
ageBuckets?: number; | ||
/** | ||
* Remove entries without any new values in the last `maxAgeSeconds` | ||
*/ | ||
pruneAgedBuckets?: boolean; | ||
/** | ||
* Control compression of data in t-digest | ||
*/ | ||
compressCount?: number; | ||
} | ||
/** | ||
* Create tracked metrics that are expensive to calculate by passing | ||
* a function that is only invoked when metrics are being scraped | ||
*/ | ||
export interface CalculatedSummaryOptions<T = number> extends SummaryOptions { | ||
/** | ||
* An optional function invoked to calculate the component metric instead of | ||
* using `.observe` | ||
*/ | ||
calculate: CalculateMetric<T>; | ||
} | ||
/** | ||
* A tracked summary loosely based on the Summary interface exposed | ||
* by the prom-client module | ||
*/ | ||
export interface Summary { | ||
/** | ||
* Observe the passed value | ||
*/ | ||
observe(value: number): void; | ||
/** | ||
* Reset this summary to its default value | ||
*/ | ||
reset(): void; | ||
/** | ||
* Start a timed metric, call the returned function to | ||
* stop the timer | ||
*/ | ||
timer(): StopTimer; | ||
} | ||
/** | ||
* A group of tracked summaries loosely based on the Summary interface | ||
* exposed by the prom-client module | ||
*/ | ||
export interface SummaryGroup<T extends string = any> { | ||
/** | ||
* Observe the passed value for the named key in the group | ||
*/ | ||
observe(values: Partial<Record<T, number>>): void; | ||
/** | ||
* Reset the passed key in this summary group to its default value | ||
* or all keys if no key is passed | ||
*/ | ||
reset(): void; | ||
/** | ||
* Start a timed metric for the named key in the group, call | ||
* the returned function to stop the timer | ||
*/ | ||
timer(key: string): StopTimer; | ||
} | ||
/** | ||
* The libp2p metrics tracking object. This interface is only concerned | ||
@@ -303,3 +423,25 @@ * with the collection of metrics, please see the individual implementations | ||
registerCounterGroup: ((name: string, options?: MetricOptions) => CounterGroup) & ((name: string, options: CalculatedMetricOptions<Record<string, number>>) => void); | ||
/** | ||
* Register an arbitrary histogram. Call this to set help/labels for histograms | ||
* and observe them by calling methods on the returned histogram object | ||
*/ | ||
registerHistogram: ((name: string, options?: HistogramOptions) => Histogram) & ((name: string, options: CalculatedHistogramOptions) => void); | ||
/** | ||
* Register a a group of related histograms. Call this to set help/labels for | ||
* groups of related histograms that will be updated with by calling the `.observe` | ||
* method on the returned histogram group object | ||
*/ | ||
registerHistogramGroup: ((name: string, options?: HistogramOptions) => HistogramGroup) & ((name: string, options: CalculatedHistogramOptions<Record<string, number>>) => void); | ||
/** | ||
* Register an arbitrary summary. Call this to set help/labels for summaries | ||
* and observe them by calling methods on the returned summary object | ||
*/ | ||
registerSummary: ((name: string, options?: SummaryOptions) => Summary) & ((name: string, options: CalculatedSummaryOptions) => void); | ||
/** | ||
* Register a a group of related summaries. Call this to set help/labels for | ||
* groups of related summaries that will be updated with by calling the `.observe` | ||
* method on the returned summary group object | ||
*/ | ||
registerSummaryGroup: ((name: string, options?: SummaryOptions) => SummaryGroup) & ((name: string, options: CalculatedSummaryOptions<Record<string, number>>) => void); | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -236,3 +236,12 @@ import type { Stream } from '../connection/index.js'; | ||
} | ||
/** | ||
* All Pubsub implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export declare const pubSubSymbol: unique symbol; | ||
/** | ||
* Returns true if the passed argument is a PubSub implementation | ||
*/ | ||
export declare function isPubSub(obj?: any): obj is PubSub; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -36,2 +36,13 @@ /** | ||
})(TopicValidatorResult || (TopicValidatorResult = {})); | ||
/** | ||
* All Pubsub implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export const pubSubSymbol = Symbol.for('@libp2p/pubsub'); | ||
/** | ||
* Returns true if the passed argument is a PubSub implementation | ||
*/ | ||
export function isPubSub(obj) { | ||
return Boolean(obj?.[pubSubSymbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -40,3 +40,5 @@ { | ||
".:AddressSorter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.AddressSorter.html", | ||
"CalculatedHistogramOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.CalculatedHistogramOptions.html", | ||
"CalculatedMetricOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.CalculatedMetricOptions.html", | ||
"CalculatedSummaryOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.CalculatedSummaryOptions.html", | ||
"ComponentLogger": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ComponentLogger.html", | ||
@@ -67,2 +69,5 @@ ".:ComponentLogger": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ComponentLogger.html", | ||
"EventObject": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.EventObject.html", | ||
"Histogram": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.Histogram.html", | ||
"HistogramGroup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.HistogramGroup.html", | ||
"HistogramOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.HistogramOptions.html", | ||
"IdentifyResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.IdentifyResult.html", | ||
@@ -143,2 +148,5 @@ ".:IdentifyResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.IdentifyResult.html", | ||
"SubscriptionChangeData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.SubscriptionChangeData.html", | ||
"Summary": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.Summary.html", | ||
"SummaryGroup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.SummaryGroup.html", | ||
"SummaryOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.SummaryOptions.html", | ||
"Tag": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.Tag.html", | ||
@@ -189,2 +197,3 @@ "TagOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.TagOptions.html", | ||
"peerRoutingSymbol": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface.peerRoutingSymbol.html", | ||
"pubSubSymbol": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface.pubSubSymbol.html", | ||
"serviceCapabilities": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface.serviceCapabilities.html", | ||
@@ -198,2 +207,3 @@ ".:serviceCapabilities": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface.serviceCapabilities.html", | ||
"isPrivateKey": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface.isPrivateKey.html", | ||
"isPubSub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface.isPubSub.html", | ||
"isPublicKey": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface.isPublicKey.html", | ||
@@ -200,0 +210,0 @@ "isStartable": "https://libp2p.github.io/js-libp2p/functions/_libp2p_interface.isStartable.html", |
{ | ||
"name": "@libp2p/interface", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "The interface implemented by a libp2p node", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -145,3 +145,143 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js' | ||
export interface HistogramOptions extends MetricOptions { | ||
/** | ||
* Buckets for the histogram | ||
*/ | ||
buckets?: number[] | ||
} | ||
/** | ||
* Create tracked metrics that are expensive to calculate by passing | ||
* a function that is only invoked when metrics are being scraped | ||
*/ | ||
export interface CalculatedHistogramOptions<T = number> extends HistogramOptions { | ||
/** | ||
* An optional function invoked to calculate the component metric instead of | ||
* using `.observe` | ||
*/ | ||
calculate: CalculateMetric<T> | ||
} | ||
export interface Histogram { | ||
/** | ||
* Observe the passed value | ||
*/ | ||
observe(value: number): void | ||
/** | ||
* Reset this histogram to its default value | ||
*/ | ||
reset(): void | ||
/** | ||
* Start a timed metric, call the returned function to | ||
* stop the timer | ||
*/ | ||
timer(): StopTimer | ||
} | ||
export interface HistogramGroup<T extends string = any> { | ||
/** | ||
* Observe the passed value for the named key in the group | ||
*/ | ||
observe(values: Partial<Record<T, number>>): void | ||
/** | ||
* Reset the passed key in this histogram group to its default value | ||
* or all keys if no key is passed | ||
*/ | ||
reset(): void | ||
/** | ||
* Start a timed metric for the named key in the group, call | ||
* the returned function to stop the timer | ||
*/ | ||
timer(key: string): StopTimer | ||
} | ||
export interface SummaryOptions extends MetricOptions { | ||
/** | ||
* Percentiles for the summary | ||
*/ | ||
percentiles?: number[] | ||
/** | ||
* Configure how old a bucket can be before it is reset for sliding window | ||
*/ | ||
maxAgeSeconds?: number | ||
/** | ||
* Configure how many buckets in the sliding window | ||
*/ | ||
ageBuckets?: number | ||
/** | ||
* Remove entries without any new values in the last `maxAgeSeconds` | ||
*/ | ||
pruneAgedBuckets?: boolean | ||
/** | ||
* Control compression of data in t-digest | ||
*/ | ||
compressCount?: number | ||
} | ||
/** | ||
* Create tracked metrics that are expensive to calculate by passing | ||
* a function that is only invoked when metrics are being scraped | ||
*/ | ||
export interface CalculatedSummaryOptions<T = number> extends SummaryOptions { | ||
/** | ||
* An optional function invoked to calculate the component metric instead of | ||
* using `.observe` | ||
*/ | ||
calculate: CalculateMetric<T> | ||
} | ||
/** | ||
* A tracked summary loosely based on the Summary interface exposed | ||
* by the prom-client module | ||
*/ | ||
export interface Summary { | ||
/** | ||
* Observe the passed value | ||
*/ | ||
observe(value: number): void | ||
/** | ||
* Reset this summary to its default value | ||
*/ | ||
reset(): void | ||
/** | ||
* Start a timed metric, call the returned function to | ||
* stop the timer | ||
*/ | ||
timer(): StopTimer | ||
} | ||
/** | ||
* A group of tracked summaries loosely based on the Summary interface | ||
* exposed by the prom-client module | ||
*/ | ||
export interface SummaryGroup<T extends string = any> { | ||
/** | ||
* Observe the passed value for the named key in the group | ||
*/ | ||
observe(values: Partial<Record<T, number>>): void | ||
/** | ||
* Reset the passed key in this summary group to its default value | ||
* or all keys if no key is passed | ||
*/ | ||
reset(): void | ||
/** | ||
* Start a timed metric for the named key in the group, call | ||
* the returned function to stop the timer | ||
*/ | ||
timer(key: string): StopTimer | ||
} | ||
/** | ||
* The libp2p metrics tracking object. This interface is only concerned | ||
@@ -326,2 +466,28 @@ * with the collection of metrics, please see the individual implementations | ||
registerCounterGroup: ((name: string, options?: MetricOptions) => CounterGroup) & ((name: string, options: CalculatedMetricOptions<Record<string, number>>) => void) | ||
/** | ||
* Register an arbitrary histogram. Call this to set help/labels for histograms | ||
* and observe them by calling methods on the returned histogram object | ||
*/ | ||
registerHistogram: ((name: string, options?: HistogramOptions) => Histogram) & ((name: string, options: CalculatedHistogramOptions) => void) | ||
/** | ||
* Register a a group of related histograms. Call this to set help/labels for | ||
* groups of related histograms that will be updated with by calling the `.observe` | ||
* method on the returned histogram group object | ||
*/ | ||
registerHistogramGroup: ((name: string, options?: HistogramOptions) => HistogramGroup) & ((name: string, options: CalculatedHistogramOptions<Record<string, number>>) => void) | ||
/** | ||
* Register an arbitrary summary. Call this to set help/labels for summaries | ||
* and observe them by calling methods on the returned summary object | ||
*/ | ||
registerSummary: ((name: string, options?: SummaryOptions) => Summary) & ((name: string, options: CalculatedSummaryOptions) => void) | ||
/** | ||
* Register a a group of related summaries. Call this to set help/labels for | ||
* groups of related summaries that will be updated with by calling the `.observe` | ||
* method on the returned summary group object | ||
*/ | ||
registerSummaryGroup: ((name: string, options?: SummaryOptions) => SummaryGroup) & ((name: string, options: CalculatedSummaryOptions<Record<string, number>>) => void) | ||
} |
@@ -271,1 +271,14 @@ import type { Stream } from '../connection/index.js' | ||
} | ||
/** | ||
* All Pubsub implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export const pubSubSymbol = Symbol.for('@libp2p/pubsub') | ||
/** | ||
* Returns true if the passed argument is a PubSub implementation | ||
*/ | ||
export function isPubSub (obj?: any): obj is PubSub { | ||
return Boolean(obj?.[pubSubSymbol]) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
314774
7351