@libp2p/devtools-metrics 1.0.0-d101aac4b → 1.0.1-21fe841f2
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 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/rpc/index.d.ts +35 -14
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/rpc.d.ts.map +1 -1
- package/dist/src/rpc/rpc.js +22 -2
- package/dist/src/rpc/rpc.js.map +1 -1
- package/dist/src/utils/find-capability.d.ts +2 -0
- package/dist/src/utils/find-capability.d.ts.map +1 -0
- package/dist/src/utils/find-capability.js +9 -0
- package/dist/src/utils/find-capability.js.map +1 -0
- package/dist/src/utils/gather-capabilities.d.ts +2 -0
- package/dist/src/utils/gather-capabilities.d.ts.map +1 -0
- package/dist/src/utils/gather-capabilities.js +12 -0
- package/dist/src/utils/gather-capabilities.js.map +1 -0
- package/dist/src/utils/get-pubsub.d.ts +3 -0
- package/dist/src/utils/get-pubsub.d.ts.map +1 -0
- package/dist/src/utils/get-pubsub.js +9 -0
- package/dist/src/utils/get-pubsub.js.map +1 -0
- package/package.json +9 -8
- package/src/index.ts +48 -2
- package/src/rpc/index.ts +42 -17
- package/src/rpc/rpc.ts +25 -7
- package/src/utils/find-capability.ts +9 -0
- package/src/utils/gather-capabilities.ts +14 -0
- package/src/utils/get-pubsub.ts +12 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { gatherCapabilities } from './gather-capabilities.js'
|
|
2
|
+
|
|
3
|
+
export function findCapability (capability: string, components: any): any | undefined {
|
|
4
|
+
for (const [name, capabilities] of Object.entries(gatherCapabilities(components))) {
|
|
5
|
+
if (capabilities.includes(capability)) {
|
|
6
|
+
return components[name]
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { serviceCapabilities } from '@libp2p/interface'
|
|
2
|
+
|
|
3
|
+
export function gatherCapabilities (components: any): Record<string, string[]> {
|
|
4
|
+
const capabilities: Record<string, string[]> = {}
|
|
5
|
+
const services: Record<string, any> = components.components ?? components
|
|
6
|
+
|
|
7
|
+
Object.entries(services).forEach(([name, component]) => {
|
|
8
|
+
if (component?.[serviceCapabilities] != null && Array.isArray(component[serviceCapabilities])) {
|
|
9
|
+
capabilities[name] = component[serviceCapabilities]
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return capabilities
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InvalidParametersError, isPubSub } from '@libp2p/interface'
|
|
2
|
+
import type { PubSub } from '@libp2p/interface'
|
|
3
|
+
|
|
4
|
+
export function getPubSub (component: string, components: any): PubSub {
|
|
5
|
+
const pubsub = components[component]
|
|
6
|
+
|
|
7
|
+
if (!isPubSub(pubsub)) {
|
|
8
|
+
throw new InvalidParametersError(`Component ${component} did not implement the PubSub interface`)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return pubsub
|
|
12
|
+
}
|