UNPKG

kubo-rpc-client-esm-cjs

Version:
52 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeStat = exports.decodeRemoteService = exports.encodeEndpoint = void 0; /** * @param {URL} url */ function encodeEndpoint(url) { const href = String(url); if (href === 'undefined') { throw Error('endpoint is required'); } // Workaround trailing `/` issue in go-ipfs // @see https://github.com/ipfs/go-ipfs/issues/7826 return href[href.length - 1] === '/' ? href.slice(0, -1) : href; } exports.encodeEndpoint = encodeEndpoint; /** * @param {any} json * @returns {import('../../../types').RemotePinServiceWithStat} */ function decodeRemoteService(json) { return Object.assign({ service: json.Service, endpoint: new URL(json.ApiEndpoint) }, (json.Stat && { stat: decodeStat(json.Stat) })); } exports.decodeRemoteService = decodeRemoteService; /** * @param {any} json * @returns {import('../../../types').Stat} */ function decodeStat(json) { switch (json.Status) { case 'valid': { const { Pinning, Pinned, Queued, Failed } = json.PinCount; return { status: 'valid', pinCount: { queued: Queued, pinning: Pinning, pinned: Pinned, failed: Failed } }; } case 'invalid': { return { status: 'invalid' }; } default: { return { status: json.Status }; } } } exports.decodeStat = decodeStat; //# sourceMappingURL=utils.js.map