UNPKG

@ceramicnetwork/core

Version:

Typescript implementation of the Ceramic protocol

41 lines 1.54 kB
import { SyncOptions } from '@ceramicnetwork/common'; export class LocalPinApi { constructor(repository, logger) { this.repository = repository; this.logger = logger; } async add(streamId, force) { const state$ = await this.repository.load(streamId, { sync: SyncOptions.PREFER_CACHE, }); await this.repository.pin(state$, force); this.repository.markPinnedAndSynced(state$.id); this.logger.verbose(`Pinned stream ${streamId.toString()}`); } async rm(streamId, opts) { const state$ = await this.repository.fromMemoryOrStore(streamId); if (!state$) { this.logger.verbose(`Cannot unpin stream ${streamId.toString()} as it isn't pinned`); return; } await this.repository.unpin(state$, opts); this.logger.verbose(`Unpinned stream ${streamId.toString()}`); } async ls(streamId) { const streamIds = await this.repository.listPinned(streamId ? streamId.baseID : null); return { [Symbol.asyncIterator]() { let index = 0; return { next() { if (index === streamIds.length) { return Promise.resolve({ value: null, done: true }); } return Promise.resolve({ value: streamIds[index++], done: false }); }, }; }, }; } } //# sourceMappingURL=local-pin-api.js.map