Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 273397d

Browse files
authored
feat!: update to latest blockstore interface (#70)
The latest blockstore interface has the datastore-specific methods removed and an extra method added for iterating over the contents of the blockstore. Also converts this module to typescript and updates all deps.x BREAKING CHANGE: `interface-blockstore@5` removes query/batch methods and adds getAll
1 parent f2ca76f commit 273397d

11 files changed

+147
-387
lines changed

.gitignore

+7-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
1-
package-lock.json
2-
yarn.lock
3-
**/node_modules/
4-
**/*.log
5-
test/repo-tests*
6-
7-
# Logs
8-
logs
9-
*.log
10-
11-
coverage
12-
13-
# Runtime data
14-
pids
15-
*.pid
16-
*.seed
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
24-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
25-
.grunt
26-
27-
# node-waf configuration
28-
.lock-wscript
29-
30-
build
31-
32-
# Dependency directory
33-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
341
node_modules
35-
36-
lib
2+
build
373
dist
38-
docs
39-
types
4+
.docs
5+
.coverage
6+
node_modules
7+
package-lock.json
8+
yarn.lock
9+
.vscode

package.json

+11-15
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@
4949
"exports": {
5050
".": {
5151
"types": "./dist/src/index.d.ts",
52-
"import": "./src/index.js"
52+
"import": "./dist/src/index.js"
5353
},
5454
"./base": {
55-
"types": "./src/base.d.ts",
56-
"import": "./src/base.js"
55+
"types": "./dist/src/base.d.ts",
56+
"import": "./dist/src/base.js"
5757
},
5858
"./errors": {
59-
"types": "./src/errors.d.ts",
60-
"import": "./src/errors.js"
59+
"types": "./dist/src/errors.d.ts",
60+
"import": "./dist/src/errors.js"
6161
},
6262
"./memory": {
63-
"types": "./src/memory.d.ts",
64-
"import": "./src/memory.js"
63+
"types": "./dist/src/memory.d.ts",
64+
"import": "./dist/src/memory.js"
6565
}
6666
},
6767
"eslintConfig": {
@@ -172,16 +172,12 @@
172172
},
173173
"dependencies": {
174174
"err-code": "^3.0.1",
175-
"interface-blockstore": "^4.0.0",
176-
"interface-store": "^3.0.0",
177-
"it-all": "^2.0.0",
178-
"it-drain": "^2.0.0",
179-
"it-filter": "^2.0.0",
180-
"it-take": "^2.0.0",
175+
"interface-blockstore": "^5.0.0",
176+
"interface-store": "^4.0.0",
181177
"multiformats": "^11.0.0"
182178
},
183179
"devDependencies": {
184-
"aegir": "^37.9.0",
185-
"interface-blockstore-tests": "^4.0.0"
180+
"aegir": "^38.1.7",
181+
"interface-blockstore-tests": "^5.0.0"
186182
}
187183
}

src/base.js

-241
This file was deleted.

src/base.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { Blockstore, Options, Pair } from 'interface-blockstore'
2+
import type { CID } from 'multiformats/cid'
3+
import type { AwaitIterable } from 'interface-store'
4+
5+
export class BaseBlockstore implements Blockstore {
6+
async has (key: CID, options?: Options): Promise<boolean> {
7+
return await Promise.reject(new Error('.has is not implemented'))
8+
}
9+
10+
async put (key: CID, val: Uint8Array, options?: Options): Promise<void> {
11+
await Promise.reject(new Error('.put is not implemented'))
12+
}
13+
14+
async * putMany (source: AwaitIterable<Pair>, options?: Options): AsyncIterable<Pair> {
15+
for await (const { cid, block } of source) {
16+
await this.put(cid, block, options)
17+
yield { cid, block }
18+
}
19+
}
20+
21+
async get (key: CID, options?: Options): Promise<Uint8Array> {
22+
return await Promise.reject(new Error('.get is not implemented'))
23+
}
24+
25+
async * getMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<Uint8Array> {
26+
for await (const key of source) {
27+
yield this.get(key, options)
28+
}
29+
}
30+
31+
async delete (key: CID, options?: Options): Promise<void> {
32+
await Promise.reject(new Error('.delete is not implemented'))
33+
}
34+
35+
async * deleteMany (source: AwaitIterable<CID>, options?: Options): AsyncIterable<CID> {
36+
for await (const key of source) {
37+
await this.delete(key, options)
38+
yield key
39+
}
40+
}
41+
42+
/**
43+
* Extending classes should override `query` or implement this method
44+
*/
45+
async * getAll (options?: Options): AwaitIterable<Pair> { // eslint-disable-line require-yield
46+
throw new Error('.getAll is not implemented')
47+
}
48+
}

0 commit comments

Comments
 (0)