Skip to content

Commit 30c8981

Browse files
authored
fix: use blockstore interface where possible (#417)
Instead of depending on the Helia `Blocks` interface, depend on `Blockstore` as none of the extra methods are used. This improves compatibility with other modules and allows reuse from non-Helia contexts.
1 parent 8a5bc6f commit 30c8981

31 files changed

Lines changed: 89 additions & 84 deletions

packages/car/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"@helia/interface": "^4.0.0",
143143
"@ipld/car": "^5.2.5",
144144
"@libp2p/interfaces": "^3.3.1",
145+
"interface-blockstore": "^5.2.9",
145146
"it-drain": "^3.0.5",
146147
"it-map": "^3.0.5",
147148
"multiformats": "^13.0.0",
@@ -154,7 +155,6 @@
154155
"@ipld/dag-pb": "^4.0.8",
155156
"aegir": "^42.1.0",
156157
"blockstore-core": "^4.3.10",
157-
"interface-blockstore": "^5.2.9",
158158
"ipfs-unixfs-importer": "^15.2.3",
159159
"it-to-buffer": "^4.0.2"
160160
}

packages/car/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ import map from 'it-map'
6363
import defer from 'p-defer'
6464
import PQueue from 'p-queue'
6565
import type { DAGWalker } from '@helia/interface'
66-
import type { Blocks, GetBlockProgressEvents, PutManyBlocksProgressEvents } from '@helia/interface/blocks'
66+
import type { GetBlockProgressEvents, PutManyBlocksProgressEvents } from '@helia/interface/blocks'
6767
import type { CarReader, CarWriter } from '@ipld/car'
6868
import type { AbortOptions } from '@libp2p/interfaces'
69+
import type { Blockstore } from 'interface-blockstore'
6970
import type { CID } from 'multiformats/cid'
7071
import type { ProgressOptions } from 'progress-events'
7172

7273
export interface CarComponents {
73-
blockstore: Blocks
74+
blockstore: Blockstore
7475
dagWalkers: Record<number, DAGWalker>
7576
}
7677

@@ -204,6 +205,6 @@ class DefaultCar implements Car {
204205
/**
205206
* Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia}
206207
*/
207-
export function car (helia: { blockstore: Blocks, dagWalkers: Record<number, DAGWalker> }, init: any = {}): Car {
208+
export function car (helia: { blockstore: Blockstore, dagWalkers: Record<number, DAGWalker> }, init: any = {}): Car {
208209
return new DefaultCar(helia, init)
209210
}

packages/dag-cbor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@
143143
"@helia/interface": "^4.0.0",
144144
"@ipld/dag-cbor": "^9.0.7",
145145
"@libp2p/interfaces": "^3.3.1",
146+
"interface-blockstore": "^5.2.9",
146147
"multiformats": "^13.0.0",
147148
"progress-events": "^1.0.0"
148149
},
149150
"devDependencies": {
150151
"aegir": "^42.1.0",
151-
"blockstore-core": "^4.3.10",
152-
"interface-blockstore": "^5.2.9"
152+
"blockstore-core": "^4.3.10"
153153
}
154154
}

packages/dag-cbor/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import * as codec from '@ipld/dag-cbor'
2727
import { CID } from 'multiformats/cid'
2828
import { sha256 } from 'multiformats/hashes/sha2'
29-
import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
29+
import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
3030
import type { AbortOptions } from '@libp2p/interfaces'
31+
import type { Blockstore } from 'interface-blockstore'
3132
import type { BlockCodec } from 'multiformats/codecs/interface'
3233
import type { MultihashHasher } from 'multiformats/hashes/interface'
3334
import type { ProgressOptions } from 'progress-events'
3435

3536
export interface DAGCBORComponents {
36-
blockstore: Blocks
37+
blockstore: Blockstore
3738
}
3839

3940
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
@@ -115,6 +116,6 @@ class DefaultDAGCBOR implements DAGCBOR {
115116
/**
116117
* Create a {@link DAGCBOR} instance for use with {@link https://github.com/ipfs/helia Helia}
117118
*/
118-
export function dagCbor (helia: { blockstore: Blocks }): DAGCBOR {
119+
export function dagCbor (helia: { blockstore: Blockstore }): DAGCBOR {
119120
return new DefaultDAGCBOR(helia)
120121
}

packages/dag-json/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@
142142
"@helia/interface": "^4.0.0",
143143
"@ipld/dag-json": "^10.1.5",
144144
"@libp2p/interfaces": "^3.3.1",
145+
"interface-blockstore": "^5.2.9",
145146
"multiformats": "^13.0.0",
146147
"progress-events": "^1.0.0"
147148
},
148149
"devDependencies": {
149150
"aegir": "^42.1.0",
150-
"blockstore-core": "^4.3.10",
151-
"interface-blockstore": "^5.2.9"
151+
"blockstore-core": "^4.3.10"
152152
}
153153
}

packages/dag-json/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import * as codec from '@ipld/dag-json'
2727
import { CID } from 'multiformats/cid'
2828
import { sha256 } from 'multiformats/hashes/sha2'
29-
import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
29+
import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
3030
import type { AbortOptions } from '@libp2p/interfaces'
31+
import type { Blockstore } from 'interface-blockstore'
3132
import type { BlockCodec } from 'multiformats/codecs/interface'
3233
import type { MultihashHasher } from 'multiformats/hashes/interface'
3334
import type { ProgressOptions } from 'progress-events'
3435

3536
export interface DAGJSONComponents {
36-
blockstore: Blocks
37+
blockstore: Blockstore
3738
}
3839

3940
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
@@ -115,6 +116,6 @@ class DefaultDAGJSON implements DAGJSON {
115116
/**
116117
* Create a {@link DAGJSON} instance for use with {@link https://github.com/ipfs/helia Helia}
117118
*/
118-
export function dagJson (helia: { blockstore: Blocks }): DAGJSON {
119+
export function dagJson (helia: { blockstore: Blockstore }): DAGJSON {
119120
return new DefaultDAGJSON(helia)
120121
}

packages/json/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@
141141
"dependencies": {
142142
"@helia/interface": "^4.0.0",
143143
"@libp2p/interfaces": "^3.3.1",
144+
"interface-blockstore": "^5.2.9",
144145
"multiformats": "^13.0.0",
145146
"progress-events": "^1.0.0"
146147
},
147148
"devDependencies": {
148149
"aegir": "^42.1.0",
149-
"blockstore-core": "^4.3.10",
150-
"interface-blockstore": "^5.2.9"
150+
"blockstore-core": "^4.3.10"
151151
}
152152
}

packages/json/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import { CID } from 'multiformats/cid'
2727
import * as jsonCodec from 'multiformats/codecs/json'
2828
import { sha256 } from 'multiformats/hashes/sha2'
29-
import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
29+
import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
3030
import type { AbortOptions } from '@libp2p/interfaces'
31+
import type { Blockstore } from 'interface-blockstore'
3132
import type { BlockCodec } from 'multiformats/codecs/interface'
3233
import type { MultihashHasher } from 'multiformats/hashes/interface'
3334
import type { ProgressOptions } from 'progress-events'
3435

3536
export interface JSONComponents {
36-
blockstore: Blocks
37+
blockstore: Blockstore
3738
}
3839

3940
export interface AddOptions extends AbortOptions, ProgressOptions<PutBlockProgressEvents> {
@@ -115,6 +116,6 @@ class DefaultJSON implements JSON {
115116
/**
116117
* Create a {@link JSON} instance for use with {@link https://github.com/ipfs/helia Helia}
117118
*/
118-
export function json (helia: { blockstore: Blocks }): JSON {
119+
export function json (helia: { blockstore: Blockstore }): JSON {
119120
return new DefaultJSON(helia)
120121
}

packages/mfs/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
"release": "aegir release"
140140
},
141141
"dependencies": {
142-
"@helia/interface": "^4.0.0",
143142
"@helia/unixfs": "^3.0.0",
144143
"@libp2p/interfaces": "^3.3.1",
145144
"@libp2p/logger": "^4.0.4",
145+
"interface-blockstore": "^5.2.9",
146146
"interface-datastore": "^8.2.9",
147147
"ipfs-unixfs": "^11.0.0",
148148
"ipfs-unixfs-exporter": "^13.1.0",
@@ -155,7 +155,6 @@
155155
"blockstore-core": "^4.3.10",
156156
"datastore-core": "^9.2.7",
157157
"delay": "^6.0.0",
158-
"interface-blockstore": "^5.2.9",
159158
"it-all": "^3.0.4",
160159
"it-drain": "^3.0.5",
161160
"it-first": "^3.0.1",

packages/mfs/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ import { Key } from 'interface-datastore'
3636
import { UnixFS as IPFSUnixFS, type Mtime } from 'ipfs-unixfs'
3737
import { CID } from 'multiformats/cid'
3838
import { basename } from './utils/basename.js'
39-
import type { Blocks } from '@helia/interface/blocks'
4039
import type { AddOptions, CatOptions, ChmodOptions, CpOptions, LsOptions, MkdirOptions as UnixFsMkdirOptions, RmOptions as UnixFsRmOptions, StatOptions, TouchOptions, UnixFS, UnixFSStats } from '@helia/unixfs'
4140
import type { AbortOptions } from '@libp2p/interfaces'
41+
import type { Blockstore } from 'interface-blockstore'
4242
import type { Datastore } from 'interface-datastore'
4343
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
4444
import type { ByteStream } from 'ipfs-unixfs-importer'
4545

4646
const log = logger('helia:mfs')
4747

4848
export interface MFSComponents {
49-
blockstore: Blocks
49+
blockstore: Blockstore
5050
datastore: Datastore
5151
}
5252

@@ -590,6 +590,6 @@ class DefaultMFS implements MFS {
590590
/**
591591
* Create a {@link MFS} instance powered by {@link https://github.com/ipfs/helia Helia}
592592
*/
593-
export function mfs (helia: { blockstore: Blocks, datastore: Datastore }, init: MFSInit = {}): MFS {
593+
export function mfs (helia: { blockstore: Blockstore, datastore: Datastore }, init: MFSInit = {}): MFS {
594594
return new DefaultMFS(helia, init)
595595
}

0 commit comments

Comments
 (0)