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());
    });
};
import { asyncIterableBatchProcessor } from '../../../../utils/async/iterable';
import { mapParticleToEntity } from '../../../../CozoDb/mapping';
import { serializeError } from 'serialize-error';
const fetchPins = (node) => __awaiter(void 0, void 0, void 0, function* () {
    const pins = [];
    yield asyncIterableBatchProcessor(node.ls(), (pinsBatch) => __awaiter(void 0, void 0, void 0, function* () {
        pins.push(...pinsBatch.filter((p) => p.type === 'direct' || p.type === 'recursive'));
    }), 10);
    return pins;
});
const importParicleContent = (particle, dbApi) => __awaiter(void 0, void 0, void 0, function* () {
    try {
        const entity = mapParticleToEntity(particle);
        const result = yield dbApi.putParticles(entity);
        return result;
    }
    catch (e) {
        const serializedError = serializeError(e);
        console.error('importParicleContent', JSON.stringify(serializedError, null, 2), !!dbApi);
        return false;
    }
});
export { fetchPins, importParicleContent };
//# sourceMappingURL=ipfsSource.js.map