kubo-rpc-client-esm-cjs
Version:
A client library for the Kubo RPC API
49 lines • 2.23 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStat = void 0;
const cid_1 = require("multiformats/cid");
const configure_js_1 = require("../lib/configure.js");
const to_url_search_params_js_1 = require("../lib/to-url-search-params.js");
const peer_id_1 = require("@libp2p/peer-id");
exports.createStat = (0, configure_js_1.configure)(api => {
/**
* @type {import('../types').BitswapAPI["stat"]}
*/
function stat(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const res = yield api.post('bitswap/stat', {
searchParams: (0, to_url_search_params_js_1.toUrlSearchParams)(options),
signal: options.signal,
headers: options.headers
});
return toCoreInterface(yield res.json());
});
}
return stat;
});
/**
* @param {any} res
*/
function toCoreInterface(res) {
return {
provideBufLen: res.ProvideBufLen,
wantlist: (res.Wantlist || []).map((/** @type {{ '/': string }} */ k) => cid_1.CID.parse(k['/'])),
peers: (res.Peers || []).map((/** @type {string} */ str) => (0, peer_id_1.peerIdFromString)(str)),
blocksReceived: BigInt(res.BlocksReceived),
dataReceived: BigInt(res.DataReceived),
blocksSent: BigInt(res.BlocksSent),
dataSent: BigInt(res.DataSent),
dupBlksReceived: BigInt(res.DupBlksReceived),
dupDataReceived: BigInt(res.DupDataReceived)
};
}
//# sourceMappingURL=stat.js.map