Skip to content

Commit 7760066

Browse files
authored
fix: return type of deleteMany should be the cids you deleted (#311)
It should not leak datastore keys, instead return the cid you deleted. Lets us not depend on ipfs-repo or interface-datastore in the types of ipfs-blockstore, then ipld, then ipfs-http-client.
1 parent e8784a8 commit 7760066

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"ipfs-utils": "^6.0.0",
8282
"ipld-block": "^0.11.0",
8383
"it-filter": "^1.0.2",
84-
"it-map": "^1.0.2",
8584
"it-pushable": "^1.4.0",
8685
"just-safe-get": "^2.0.0",
8786
"just-safe-set": "^2.1.0",

src/blockstore.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { shard, ShardingDatastore } = require('datastore-core')
44
const Block = require('ipld-block')
55
const { cidToKey, keyToCid } = require('./blockstore-utils')
6-
const map = require('it-map')
76
const drain = require('it-drain')
87
const pushable = require('it-pushable')
98
/**
@@ -135,7 +134,21 @@ function createBaseStore (store) {
135134
},
136135

137136
deleteMany (cids, options) {
138-
return store.deleteMany(map(cids, cid => cidToKey(cid)), options)
137+
const out = pushable()
138+
139+
drain(store.deleteMany((async function * () {
140+
for await (const cid of cids) {
141+
yield cidToKey(cid)
142+
143+
out.push(cid)
144+
}
145+
146+
out.end()
147+
}()), options)).catch(err => {
148+
out.end(err)
149+
})
150+
151+
return out
139152
},
140153

141154
close () {

src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface Blockstore {
105105
/**
106106
* Delete a block from the store
107107
*/
108-
deleteMany: (cids: AwaitIterable<any>, options?: DatastoreOptions) => AsyncIterable<Key>
108+
deleteMany: (cids: AwaitIterable<any>, options?: DatastoreOptions) => AsyncIterable<CID>
109109

110110
/**
111111
* Close the store

test/blockstore-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,11 @@ module.exports = (repo) => {
440440

441441
describe('.deleteMany', () => {
442442
it('simple', async () => {
443-
await drain(repo.blocks.deleteMany([b.cid]))
443+
const deleted = await all(repo.blocks.deleteMany([b.cid]))
444444
const exists = await repo.blocks.has(b.cid)
445445
expect(exists).to.equal(false)
446+
expect(deleted).to.have.lengthOf(1)
447+
expect(deleted[0]).to.deep.equal(b.cid)
446448
})
447449

448450
it('including identity cid', async () => {

0 commit comments

Comments
 (0)