import { PinApi , PublishOpts , SyncOptions } from '@ceramicnetwork/common' ; import StreamID from '@ceramicnetwork/streamid' ; import { DiagnosticsLogger } from '@ceramicnetwork/common' ; import { Repository } from './state-management/repository' ; /**
 * PinApi for Ceramic core.
 */ export class LocalPinApi implements PinApi { constructor ( private readonly repository , private readonly logger ) { } async add ( streamId , force ? ) { const state$ = await this . repository . load ( streamId , { sync : SyncOptions . PREFER_CACHE } ) ; await this . repository . pin ( state$ , force ) ; this . logger . verbose ( `Pinned stream ${ streamId . toString ( ) }` ) ; } async rm ( streamId , opts ? ) { const state$ = await this . repository . get ( 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 } ) ; } , } ; } , } ; } }