@@ -4,10 +4,12 @@ import { base36 } from 'multiformats/bases/base36'
44import { CID , type Version } from 'multiformats/cid'
55import defer from 'p-defer'
66import PQueue from 'p-queue'
7+ import { CustomProgressEvent , type ProgressOptions } from 'progress-events'
78import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
89import { cborWalker , dagPbWalker , jsonWalker , rawWalker } from './utils/dag-walkers.js'
910import type { DAGWalker } from './index.js'
10- import type { AddOptions , IsPinnedOptions , LsOptions , Pin , Pins , RmOptions } from '@helia/interface/pins'
11+ import type { AddOptions , AddPinEvents , IsPinnedOptions , LsOptions , Pin , Pins , RmOptions } from '@helia/interface/pins'
12+ import type { GetBlockProgressEvents } from '@helia/interface/src/blocks.js'
1113import type { AbortOptions } from '@libp2p/interfaces'
1214import type { Blockstore } from 'interface-blockstore'
1315
@@ -41,7 +43,7 @@ const DATASTORE_ENCODING = base36
4143// const DAG_WALK_MAX_QUEUE_LENGTH = 10
4244const DAG_WALK_QUEUE_CONCURRENCY = 1
4345
44- interface WalkDagOptions extends AbortOptions {
46+ interface WalkDagOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | AddPinEvents > {
4547 depth : number
4648}
4749
@@ -142,7 +144,7 @@ export class PinsImpl implements Pins {
142144 throw new Error ( `No dag walker found for cid codec ${ cid . code } ` )
143145 }
144146
145- const block = await this . blockstore . get ( cid )
147+ const block = await this . blockstore . get ( cid , options )
146148
147149 await this . #updatePinnedBlock( cid , withPinnedBlock , options )
148150
@@ -160,7 +162,7 @@ export class PinsImpl implements Pins {
160162 /**
161163 * Update the pin count for the CID
162164 */
163- async #updatePinnedBlock ( cid : CID , withPinnedBlock : ( pinnedBlock : DatastorePinnedBlock ) => void , options : AbortOptions ) : Promise < void > {
165+ async #updatePinnedBlock ( cid : CID , withPinnedBlock : ( pinnedBlock : DatastorePinnedBlock ) => void , options : AddOptions ) : Promise < void > {
164166 const blockKey = new Key ( `${ DATASTORE_BLOCK_PREFIX } ${ DATASTORE_ENCODING . encode ( cid . multihash . bytes ) } ` )
165167
166168 let pinnedBlock : DatastorePinnedBlock = {
@@ -186,6 +188,7 @@ export class PinsImpl implements Pins {
186188 }
187189
188190 await this . datastore . put ( blockKey , cborg . encode ( pinnedBlock ) , options )
191+ options . onProgress ?.( new CustomProgressEvent < CID > ( 'helia:pin:add' , { detail : cid } ) )
189192 }
190193
191194 async rm ( cid : CID < unknown , number , number , Version > , options : RmOptions = { } ) : Promise < Pin > {
0 commit comments