UNPKG

kubo-rpc-client-esm-cjs

Version:
41 lines 2.14 kB
"use strict"; 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.createId = void 0; const object_to_camel_js_1 = require("./lib/object-to-camel.js"); const multiaddr_1 = require("@multiformats/multiaddr"); 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.createId = (0, configure_js_1.configure)(api => { /** * @type {import('./types').RootAPI["id"]} */ function id(options = {}) { return __awaiter(this, void 0, void 0, function* () { const res = yield api.post('id', { signal: options.signal, searchParams: (0, to_url_search_params_js_1.toUrlSearchParams)(Object.assign({ arg: options.peerId ? options.peerId.toString() : undefined }, options)), headers: options.headers }); const data = yield res.json(); const output = Object.assign({}, (0, object_to_camel_js_1.objectToCamel)(data)); output.id = (0, peer_id_1.peerIdFromString)(output.id); if (output.addresses) { output.addresses = output.addresses.map((/** @type {string} */ ma) => (0, multiaddr_1.multiaddr)(ma)); } // @ts-expect-error server output is not typed return output; }); } return id; }); //# sourceMappingURL=id.js.map