@lidofinance/api-rpc 0.0.3
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/README.md +23 -0
- package/dist/index.cjs +57 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +41 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @lidofinance/api-rpc
|
|
2
|
+
|
|
3
|
+
Extension of [fetchRpc](https://www.npmjs.com/package/@lidofinance/rpc), to track common RPC metrics.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @lidofinance/api-rpc`
|
|
8
|
+
|
|
9
|
+
## Getting started
|
|
10
|
+
|
|
11
|
+
It's only a factory, which extends `fetchRpc`, where you need to pass prom-client's `registry` and prefix for all
|
|
12
|
+
tracked metrics.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { trackedFetchRpcFactory } from '@lidofinance/api-rpc';
|
|
16
|
+
import { registry } from './metrics';
|
|
17
|
+
import { METRICS_PREFIX } from '../config';
|
|
18
|
+
|
|
19
|
+
export const fetchRPC = trackedFetchRpcFactory({
|
|
20
|
+
registry,
|
|
21
|
+
prefix: METRICS_PREFIX,
|
|
22
|
+
});
|
|
23
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var $3WQie$lidofinancerpc = require("@lidofinance/rpc");
|
|
2
|
+
var $3WQie$lidofinanceapimetrics = require("@lidofinance/api-metrics");
|
|
3
|
+
|
|
4
|
+
function $parcel$exportWildcard(dest, source) {
|
|
5
|
+
Object.keys(source).forEach(function(key) {
|
|
6
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(dest, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return source[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return dest;
|
|
19
|
+
}
|
|
20
|
+
function $parcel$export(e, n, v, s) {
|
|
21
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
22
|
+
}
|
|
23
|
+
var $47b14a281d9aea1d$exports = {};
|
|
24
|
+
|
|
25
|
+
$parcel$export($47b14a281d9aea1d$exports, "trackedFetchRpcFactory", () => $47b14a281d9aea1d$export$78b2eac677e7bce5);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const $47b14a281d9aea1d$export$78b2eac677e7bce5 = ({ prefix: prefix , registry: registry })=>{
|
|
29
|
+
const { rpcRequestCount: rpcRequestCount , rpcRequestMethods: rpcRequestMethods , rpcResponseTime: rpcResponseTime } = (0, $3WQie$lidofinanceapimetrics.rpcMetricsFactory)(prefix, registry);
|
|
30
|
+
return async (url, init, { chainId: chainId })=>{
|
|
31
|
+
const provider = (0, $3WQie$lidofinanceapimetrics.getProviderLabel)(url);
|
|
32
|
+
rpcRequestCount.labels({
|
|
33
|
+
chainId: chainId,
|
|
34
|
+
provider: provider
|
|
35
|
+
}).inc();
|
|
36
|
+
for (const { method: method } of Array.isArray(init.body) ? init.body : [
|
|
37
|
+
init.body
|
|
38
|
+
])rpcRequestMethods.labels({
|
|
39
|
+
method: method
|
|
40
|
+
}).inc();
|
|
41
|
+
const responseTime = rpcResponseTime.startTimer();
|
|
42
|
+
const response = await (0, $3WQie$lidofinancerpc.fetchRpc)(url, init);
|
|
43
|
+
const status = (0, $3WQie$lidofinanceapimetrics.getStatusLabel)(response.status);
|
|
44
|
+
responseTime({
|
|
45
|
+
chainId: chainId,
|
|
46
|
+
provider: provider,
|
|
47
|
+
status: status
|
|
48
|
+
});
|
|
49
|
+
return response;
|
|
50
|
+
};
|
|
51
|
+
};
|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AAA;CACF;;AD9BD","sources":["packages/api/rpc/src/index.ts","packages/api/rpc/src/trackedFetchRpcFactory.ts"],"sourcesContent":["export * from './trackedFetchRpcFactory'\n","import { Registry } from 'prom-client'\nimport { FetchRpc, fetchRpc } from '@lidofinance/rpc'\nimport { rpcMetricsFactory, getProviderLabel, getStatusLabel } from '@lidofinance/api-metrics'\n\nexport type TrackedFetchRpcFactoryParameters = {\n prefix: string\n registry: Registry\n}\n\nexport type TrackedFetchRPC = FetchRpc<{ chainId: string | number }>\n\nexport const trackedFetchRpcFactory = ({ prefix, registry }: TrackedFetchRpcFactoryParameters): TrackedFetchRPC => {\n const { rpcRequestCount, rpcRequestMethods, rpcResponseTime } = rpcMetricsFactory(prefix, registry)\n\n return async (url, init, { chainId }) => {\n const provider = getProviderLabel(url)\n\n rpcRequestCount.labels({ chainId, provider }).inc()\n for (const { method } of Array.isArray(init.body) ? init.body : [init.body]) {\n rpcRequestMethods.labels({ method }).inc()\n }\n const responseTime = rpcResponseTime.startTimer()\n\n const response = await fetchRpc(url, init)\n\n const status = getStatusLabel(response.status)\n responseTime({ chainId, provider, status })\n\n return response\n }\n}\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Registry } from "prom-client";
|
|
2
|
+
import { FetchRpc } from "@lidofinance/rpc";
|
|
3
|
+
export type TrackedFetchRpcFactoryParameters = {
|
|
4
|
+
prefix: string;
|
|
5
|
+
registry: Registry;
|
|
6
|
+
};
|
|
7
|
+
export type TrackedFetchRPC = FetchRpc<{
|
|
8
|
+
chainId: string | number;
|
|
9
|
+
}>;
|
|
10
|
+
export const trackedFetchRpcFactory: ({ prefix, registry }: TrackedFetchRpcFactoryParameters) => TrackedFetchRPC;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAIA,+CAA+C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,8BAA8B,SAAS;IAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC,CAAA;AAEpE,OAAO,MAAM,+CAAgD,gCAAgC,KAAG,eAmB/F,CAAA","sources":["packages/api/rpc/src/src/trackedFetchRpcFactory.ts","packages/api/rpc/src/src/index.ts","packages/api/rpc/src/index.ts"],"sourcesContent":[null,null,"export * from './trackedFetchRpcFactory'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {fetchRpc as $1xKrC$fetchRpc} from "@lidofinance/rpc";
|
|
2
|
+
import {rpcMetricsFactory as $1xKrC$rpcMetricsFactory, getProviderLabel as $1xKrC$getProviderLabel, getStatusLabel as $1xKrC$getStatusLabel} from "@lidofinance/api-metrics";
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
var $a3758ff406a352af$exports = {};
|
|
8
|
+
|
|
9
|
+
$parcel$export($a3758ff406a352af$exports, "trackedFetchRpcFactory", () => $a3758ff406a352af$export$78b2eac677e7bce5);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const $a3758ff406a352af$export$78b2eac677e7bce5 = ({ prefix: prefix , registry: registry })=>{
|
|
13
|
+
const { rpcRequestCount: rpcRequestCount , rpcRequestMethods: rpcRequestMethods , rpcResponseTime: rpcResponseTime } = (0, $1xKrC$rpcMetricsFactory)(prefix, registry);
|
|
14
|
+
return async (url, init, { chainId: chainId })=>{
|
|
15
|
+
const provider = (0, $1xKrC$getProviderLabel)(url);
|
|
16
|
+
rpcRequestCount.labels({
|
|
17
|
+
chainId: chainId,
|
|
18
|
+
provider: provider
|
|
19
|
+
}).inc();
|
|
20
|
+
for (const { method: method } of Array.isArray(init.body) ? init.body : [
|
|
21
|
+
init.body
|
|
22
|
+
])rpcRequestMethods.labels({
|
|
23
|
+
method: method
|
|
24
|
+
}).inc();
|
|
25
|
+
const responseTime = rpcResponseTime.startTimer();
|
|
26
|
+
const response = await (0, $1xKrC$fetchRpc)(url, init);
|
|
27
|
+
const status = (0, $1xKrC$getStatusLabel)(response.status);
|
|
28
|
+
responseTime({
|
|
29
|
+
chainId: chainId,
|
|
30
|
+
provider: provider,
|
|
31
|
+
status: status
|
|
32
|
+
});
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export {$a3758ff406a352af$export$78b2eac677e7bce5 as trackedFetchRpcFactory};
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;ACAA;;AAWO,MAAM,yCAAsB,GAAG,CAAC,UAAE,MAAM,CAAA,YAAE,QAAQ,CAAA,EAAoC,GAAsB;IACjH,MAAM,mBAAE,eAAe,CAAA,qBAAE,iBAAiB,CAAA,mBAAE,eAAe,CAAA,EAAE,GAAG,CAAA,GAAA,wBAAiB,CAAA,CAAC,MAAM,EAAE,QAAQ,CAAC;IAEnG,OAAO,OAAO,GAAG,EAAE,IAAI,EAAE,WAAE,OAAO,CAAA,EAAE,GAAK;QACvC,MAAM,QAAQ,GAAG,CAAA,GAAA,uBAAgB,CAAA,CAAC,GAAG,CAAC;QAEtC,eAAe,CAAC,MAAM,CAAC;qBAAE,OAAO;sBAAE,QAAQ;SAAE,CAAC,CAAC,GAAG,EAAE;QACnD,KAAK,MAAM,UAAE,MAAM,CAAA,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG;YAAC,IAAI,CAAC,IAAI;SAAC,CACzE,iBAAiB,CAAC,MAAM,CAAC;oBAAE,MAAM;SAAE,CAAC,CAAC,GAAG,EAAE;QAE5C,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,EAAE;QAEjD,MAAM,QAAQ,GAAG,MAAM,CAAA,GAAA,eAAQ,CAAA,CAAC,GAAG,EAAE,IAAI,CAAC;QAE1C,MAAM,MAAM,GAAG,CAAA,GAAA,qBAAc,CAAA,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC9C,YAAY,CAAC;qBAAE,OAAO;sBAAE,QAAQ;oBAAE,MAAM;SAAE,CAAC;QAE3C,OAAO,QAAQ,CAAA;KAChB,CAAA;CACF;;AD9BD","sources":["packages/api/rpc/src/index.ts","packages/api/rpc/src/trackedFetchRpcFactory.ts"],"sourcesContent":["export * from './trackedFetchRpcFactory'\n","import { Registry } from 'prom-client'\nimport { FetchRpc, fetchRpc } from '@lidofinance/rpc'\nimport { rpcMetricsFactory, getProviderLabel, getStatusLabel } from '@lidofinance/api-metrics'\n\nexport type TrackedFetchRpcFactoryParameters = {\n prefix: string\n registry: Registry\n}\n\nexport type TrackedFetchRPC = FetchRpc<{ chainId: string | number }>\n\nexport const trackedFetchRpcFactory = ({ prefix, registry }: TrackedFetchRpcFactoryParameters): TrackedFetchRPC => {\n const { rpcRequestCount, rpcRequestMethods, rpcResponseTime } = rpcMetricsFactory(prefix, registry)\n\n return async (url, init, { chainId }) => {\n const provider = getProviderLabel(url)\n\n rpcRequestCount.labels({ chainId, provider }).inc()\n for (const { method } of Array.isArray(init.body) ? init.body : [init.body]) {\n rpcRequestMethods.labels({ method }).inc()\n }\n const responseTime = rpcResponseTime.startTimer()\n\n const response = await fetchRpc(url, init)\n\n const status = getStatusLabel(response.status)\n responseTime({ chainId, provider, status })\n\n return response\n }\n}\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lidofinance/api-rpc",
|
|
3
|
+
"description": "FetchRpc extension for api",
|
|
4
|
+
"repository": "git@github.com:lidofinance/lido-ui-blocks.git",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "0.0.3",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">= 16"
|
|
12
|
+
},
|
|
13
|
+
"source": "./src/index.ts",
|
|
14
|
+
"main": "dist/index.cjs",
|
|
15
|
+
"module": "dist/index.mjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "parcel build",
|
|
19
|
+
"format": "prettier --check src",
|
|
20
|
+
"format:fix": "yarn format --write",
|
|
21
|
+
"types": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"prom-client": "^14.0.0",
|
|
25
|
+
"@lidofinance/rpc": "0.0.3",
|
|
26
|
+
"@lidofinance/api-metrics": "0.0.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@lidofinance/config-prettier": "0.0.1",
|
|
30
|
+
"prom-client": "^14.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|