kubo-rpc-client-esm-cjs
Version:
A client library for the Kubo RPC API
89 lines • 5.15 kB
JavaScript
;
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAddAll = void 0;
const cid_1 = require("multiformats/cid");
const configure_js_1 = require("../lib/configure.js");
const normalise_input_1 = require("ipfs-core-utils/pins/normalise-input");
const to_url_search_params_js_1 = require("../lib/to-url-search-params.js");
exports.createAddAll = (0, configure_js_1.configure)(api => {
/**
* @type {import('../types').PinAPI["addAll"]}
*/
function addAll(source, options = {}) {
return __asyncGenerator(this, arguments, function* addAll_1() {
var _a, e_1, _b, _c, _d, e_2, _e, _f;
try {
for (var _g = true, _h = __asyncValues((0, normalise_input_1.normaliseInput)(source)), _j; _j = yield __await(_h.next()), _a = _j.done, !_a;) {
_c = _j.value;
_g = false;
try {
const { path, recursive, metadata } = _c;
const res = yield __await(api.post('pin/add', {
signal: options.signal,
searchParams: (0, to_url_search_params_js_1.toUrlSearchParams)(Object.assign(Object.assign({}, options), { arg: path, recursive, metadata: metadata ? JSON.stringify(metadata) : undefined, stream: true })),
headers: options.headers
}));
try {
for (var _k = true, _l = (e_2 = void 0, __asyncValues(res.ndjson())), _m; _m = yield __await(_l.next()), _d = _m.done, !_d;) {
_f = _m.value;
_k = false;
try {
const pin = _f;
if (pin.Pins) { // non-streaming response
for (const cid of pin.Pins) {
yield yield __await(cid_1.CID.parse(cid));
}
// eslint-disable-next-line no-continue
continue;
}
yield yield __await(cid_1.CID.parse(pin));
}
finally {
_k = true;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (!_k && !_d && (_e = _l.return)) yield __await(_e.call(_l));
}
finally { if (e_2) throw e_2.error; }
}
}
finally {
_g = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_g && !_a && (_b = _h.return)) yield __await(_b.call(_h));
}
finally { if (e_1) throw e_1.error; }
}
});
}
return addAll;
});
//# sourceMappingURL=add-all.js.map