UNPKG

kubo-rpc-client

Version:
58 lines 1.64 kB
import { CID } from 'multiformats/cid'; import { toUrlSearchParams } from '../../lib/to-url-search-params.js'; export const decodePin = ({ Name: name, Status: status, Cid: cid }) => { return { cid: CID.parse(cid), name, status }; }; export const encodeService = (service) => { if (typeof service === 'string' && service !== '') { return service; } else { throw new TypeError('service name must be passed'); } }; export const encodeCID = (cid) => { if (CID.asCID(cid) != null) { return cid.toString(); } else { throw new TypeError(`CID instance expected instead of ${typeof cid}`); } }; export const encodeQuery = ({ service, cid, name, status, all }) => { const query = toUrlSearchParams({ service: encodeService(service), name, force: all === true ? true : undefined }); if (cid != null) { for (const value of cid) { query.append('cid', encodeCID(value)); } } if (status != null) { for (const value of status) { query.append('status', value); } } return query; }; export const encodeAddParams = (cid, { service, background, name, origins }) => { const params = toUrlSearchParams({ arg: encodeCID(cid), service: encodeService(service), name, background: background === true ? true : undefined }); if (origins != null) { for (const origin of origins) { params.append('origin', origin.toString()); } } return params; }; //# sourceMappingURL=utils.js.map