diff --git a/packages/car/package.json b/packages/car/package.json index 55b34ee6..db8cadc9 100644 --- a/packages/car/package.json +++ b/packages/car/package.json @@ -142,6 +142,7 @@ "@helia/interface": "^4.0.0", "@ipld/car": "^5.2.5", "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.2.9", "it-drain": "^3.0.5", "it-map": "^3.0.5", "multiformats": "^13.0.0", @@ -154,7 +155,6 @@ "@ipld/dag-pb": "^4.0.8", "aegir": "^42.1.0", "blockstore-core": "^4.3.10", - "interface-blockstore": "^5.2.9", "ipfs-unixfs-importer": "^15.2.3", "it-to-buffer": "^4.0.2" } diff --git a/packages/car/src/index.ts b/packages/car/src/index.ts index 40dc2189..e2dd8b18 100644 --- a/packages/car/src/index.ts +++ b/packages/car/src/index.ts @@ -63,14 +63,15 @@ import map from 'it-map' import defer from 'p-defer' import PQueue from 'p-queue' import type { DAGWalker } from '@helia/interface' -import type { Blocks, GetBlockProgressEvents, PutManyBlocksProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutManyBlocksProgressEvents } from '@helia/interface/blocks' import type { CarReader, CarWriter } from '@ipld/car' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' import type { ProgressOptions } from 'progress-events' export interface CarComponents { - blockstore: Blocks + blockstore: Blockstore dagWalkers: Record } @@ -204,6 +205,6 @@ class DefaultCar implements Car { /** * Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function car (helia: { blockstore: Blocks, dagWalkers: Record }, init: any = {}): Car { +export function car (helia: { blockstore: Blockstore, dagWalkers: Record }, init: any = {}): Car { return new DefaultCar(helia, init) } diff --git a/packages/dag-cbor/package.json b/packages/dag-cbor/package.json index cde5fa92..d6e22e12 100644 --- a/packages/dag-cbor/package.json +++ b/packages/dag-cbor/package.json @@ -143,12 +143,12 @@ "@helia/interface": "^4.0.0", "@ipld/dag-cbor": "^9.0.7", "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.2.9", "multiformats": "^13.0.0", "progress-events": "^1.0.0" }, "devDependencies": { "aegir": "^42.1.0", - "blockstore-core": "^4.3.10", - "interface-blockstore": "^5.2.9" + "blockstore-core": "^4.3.10" } } diff --git a/packages/dag-cbor/src/index.ts b/packages/dag-cbor/src/index.ts index 7457c64d..12cf8c63 100644 --- a/packages/dag-cbor/src/index.ts +++ b/packages/dag-cbor/src/index.ts @@ -26,14 +26,15 @@ import * as codec from '@ipld/dag-cbor' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' import type { ProgressOptions } from 'progress-events' export interface DAGCBORComponents { - blockstore: Blocks + blockstore: Blockstore } export interface AddOptions extends AbortOptions, ProgressOptions { @@ -115,6 +116,6 @@ class DefaultDAGCBOR implements DAGCBOR { /** * Create a {@link DAGCBOR} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function dagCbor (helia: { blockstore: Blocks }): DAGCBOR { +export function dagCbor (helia: { blockstore: Blockstore }): DAGCBOR { return new DefaultDAGCBOR(helia) } diff --git a/packages/dag-json/package.json b/packages/dag-json/package.json index 9750227b..a79c10e3 100644 --- a/packages/dag-json/package.json +++ b/packages/dag-json/package.json @@ -142,12 +142,12 @@ "@helia/interface": "^4.0.0", "@ipld/dag-json": "^10.1.5", "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.2.9", "multiformats": "^13.0.0", "progress-events": "^1.0.0" }, "devDependencies": { "aegir": "^42.1.0", - "blockstore-core": "^4.3.10", - "interface-blockstore": "^5.2.9" + "blockstore-core": "^4.3.10" } } diff --git a/packages/dag-json/src/index.ts b/packages/dag-json/src/index.ts index 90be4cda..83fe4eea 100644 --- a/packages/dag-json/src/index.ts +++ b/packages/dag-json/src/index.ts @@ -26,14 +26,15 @@ import * as codec from '@ipld/dag-json' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' import type { ProgressOptions } from 'progress-events' export interface DAGJSONComponents { - blockstore: Blocks + blockstore: Blockstore } export interface AddOptions extends AbortOptions, ProgressOptions { @@ -115,6 +116,6 @@ class DefaultDAGJSON implements DAGJSON { /** * Create a {@link DAGJSON} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function dagJson (helia: { blockstore: Blocks }): DAGJSON { +export function dagJson (helia: { blockstore: Blockstore }): DAGJSON { return new DefaultDAGJSON(helia) } diff --git a/packages/json/package.json b/packages/json/package.json index fcfed4f7..775913a7 100644 --- a/packages/json/package.json +++ b/packages/json/package.json @@ -141,12 +141,12 @@ "dependencies": { "@helia/interface": "^4.0.0", "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.2.9", "multiformats": "^13.0.0", "progress-events": "^1.0.0" }, "devDependencies": { "aegir": "^42.1.0", - "blockstore-core": "^4.3.10", - "interface-blockstore": "^5.2.9" + "blockstore-core": "^4.3.10" } } diff --git a/packages/json/src/index.ts b/packages/json/src/index.ts index 053ebe09..09fcc235 100644 --- a/packages/json/src/index.ts +++ b/packages/json/src/index.ts @@ -26,14 +26,15 @@ import { CID } from 'multiformats/cid' import * as jsonCodec from 'multiformats/codecs/json' import { sha256 } from 'multiformats/hashes/sha2' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' import type { ProgressOptions } from 'progress-events' export interface JSONComponents { - blockstore: Blocks + blockstore: Blockstore } export interface AddOptions extends AbortOptions, ProgressOptions { @@ -115,6 +116,6 @@ class DefaultJSON implements JSON { /** * Create a {@link JSON} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function json (helia: { blockstore: Blocks }): JSON { +export function json (helia: { blockstore: Blockstore }): JSON { return new DefaultJSON(helia) } diff --git a/packages/mfs/package.json b/packages/mfs/package.json index c664d104..05f0b48b 100644 --- a/packages/mfs/package.json +++ b/packages/mfs/package.json @@ -139,10 +139,10 @@ "release": "aegir release" }, "dependencies": { - "@helia/interface": "^4.0.0", "@helia/unixfs": "^3.0.0", "@libp2p/interfaces": "^3.3.1", "@libp2p/logger": "^4.0.4", + "interface-blockstore": "^5.2.9", "interface-datastore": "^8.2.9", "ipfs-unixfs": "^11.0.0", "ipfs-unixfs-exporter": "^13.1.0", @@ -155,7 +155,6 @@ "blockstore-core": "^4.3.10", "datastore-core": "^9.2.7", "delay": "^6.0.0", - "interface-blockstore": "^5.2.9", "it-all": "^3.0.4", "it-drain": "^3.0.5", "it-first": "^3.0.1", diff --git a/packages/mfs/src/index.ts b/packages/mfs/src/index.ts index 7d1a3091..78b65d47 100644 --- a/packages/mfs/src/index.ts +++ b/packages/mfs/src/index.ts @@ -36,9 +36,9 @@ import { Key } from 'interface-datastore' import { UnixFS as IPFSUnixFS, type Mtime } from 'ipfs-unixfs' import { CID } from 'multiformats/cid' import { basename } from './utils/basename.js' -import type { Blocks } from '@helia/interface/blocks' import type { AddOptions, CatOptions, ChmodOptions, CpOptions, LsOptions, MkdirOptions as UnixFsMkdirOptions, RmOptions as UnixFsRmOptions, StatOptions, TouchOptions, UnixFS, UnixFSStats } from '@helia/unixfs' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { Datastore } from 'interface-datastore' import type { UnixFSEntry } from 'ipfs-unixfs-exporter' import type { ByteStream } from 'ipfs-unixfs-importer' @@ -46,7 +46,7 @@ import type { ByteStream } from 'ipfs-unixfs-importer' const log = logger('helia:mfs') export interface MFSComponents { - blockstore: Blocks + blockstore: Blockstore datastore: Datastore } @@ -590,6 +590,6 @@ class DefaultMFS implements MFS { /** * Create a {@link MFS} instance powered by {@link https://github.com/ipfs/helia Helia} */ -export function mfs (helia: { blockstore: Blocks, datastore: Datastore }, init: MFSInit = {}): MFS { +export function mfs (helia: { blockstore: Blockstore, datastore: Datastore }, init: MFSInit = {}): MFS { return new DefaultMFS(helia, init) } diff --git a/packages/strings/package.json b/packages/strings/package.json index c7febfb2..729b0891 100644 --- a/packages/strings/package.json +++ b/packages/strings/package.json @@ -143,13 +143,13 @@ "dependencies": { "@helia/interface": "^4.0.0", "@libp2p/interfaces": "^3.3.1", + "interface-blockstore": "^5.2.9", "multiformats": "^13.0.0", "progress-events": "^1.0.0", "uint8arrays": "^5.0.1" }, "devDependencies": { "aegir": "^42.1.0", - "blockstore-core": "^4.3.10", - "interface-blockstore": "^5.2.9" + "blockstore-core": "^4.3.10" } } diff --git a/packages/strings/src/index.ts b/packages/strings/src/index.ts index 7775a12f..228d04cb 100644 --- a/packages/strings/src/index.ts +++ b/packages/strings/src/index.ts @@ -26,14 +26,15 @@ import * as raw from 'multiformats/codecs/raw' import { sha256 } from 'multiformats/hashes/sha2' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interfaces' +import type { Blockstore } from 'interface-blockstore' import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' import type { ProgressOptions } from 'progress-events' export interface StringsComponents { - blockstore: Blocks + blockstore: Blockstore } export interface AddOptions extends AbortOptions, ProgressOptions { @@ -117,6 +118,6 @@ class DefaultStrings implements Strings { /** * Create a {@link Strings} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function strings (helia: { blockstore: Blocks }): Strings { +export function strings (helia: { blockstore: Blockstore }): Strings { return new DefaultStrings(helia) } diff --git a/packages/unixfs/package.json b/packages/unixfs/package.json index bdd6c8c7..044da534 100644 --- a/packages/unixfs/package.json +++ b/packages/unixfs/package.json @@ -168,6 +168,7 @@ "ipfs-unixfs": "^11.0.0", "ipfs-unixfs-exporter": "^13.1.0", "ipfs-unixfs-importer": "^15.2.3", + "interface-blockstore": "^5.2.9", "it-glob": "^2.0.4", "it-last": "^3.0.4", "it-pipe": "^3.0.1", @@ -181,7 +182,6 @@ "aegir": "^42.1.0", "blockstore-core": "^4.3.10", "delay": "^6.0.0", - "interface-blockstore": "^5.2.9", "iso-url": "^1.2.1", "it-all": "^3.0.4", "it-drain": "^3.0.5", diff --git a/packages/unixfs/src/commands/add.ts b/packages/unixfs/src/commands/add.ts index 5bc60cb6..8302bb8c 100644 --- a/packages/unixfs/src/commands/add.ts +++ b/packages/unixfs/src/commands/add.ts @@ -1,7 +1,7 @@ import { type ByteStream, type DirectoryCandidate, type FileCandidate, importBytes, importByteStream, type ImportCandidateStream, importDirectory, importer, type ImporterOptions, importFile, type ImportResult } from 'ipfs-unixfs-importer' import { fixedSize } from 'ipfs-unixfs-importer/chunker' import { balanced } from 'ipfs-unixfs-importer/layout' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' /** @@ -18,14 +18,14 @@ const defaultImporterSettings: ImporterOptions = { }) } -export async function * addAll (source: ImportCandidateStream, blockstore: Blocks, options: Partial = {}): AsyncGenerator { +export async function * addAll (source: ImportCandidateStream, blockstore: Blockstore, options: Partial = {}): AsyncGenerator { yield * importer(source, blockstore, { ...defaultImporterSettings, ...options }) } -export async function addBytes (bytes: Uint8Array, blockstore: Blocks, options: Partial = {}): Promise { +export async function addBytes (bytes: Uint8Array, blockstore: Blockstore, options: Partial = {}): Promise { const { cid } = await importBytes(bytes, blockstore, { ...defaultImporterSettings, ...options @@ -34,7 +34,7 @@ export async function addBytes (bytes: Uint8Array, blockstore: Blocks, options: return cid } -export async function addByteStream (bytes: ByteStream, blockstore: Blocks, options: Partial = {}): Promise { +export async function addByteStream (bytes: ByteStream, blockstore: Blockstore, options: Partial = {}): Promise { const { cid } = await importByteStream(bytes, blockstore, { ...defaultImporterSettings, ...options @@ -43,7 +43,7 @@ export async function addByteStream (bytes: ByteStream, blockstore: Blocks, opti return cid } -export async function addFile (file: FileCandidate, blockstore: Blocks, options: Partial = {}): Promise { +export async function addFile (file: FileCandidate, blockstore: Blockstore, options: Partial = {}): Promise { const { cid } = await importFile(file, blockstore, { ...defaultImporterSettings, ...options @@ -52,7 +52,7 @@ export async function addFile (file: FileCandidate, blockstore: Blocks, options: return cid } -export async function addDirectory (dir: Partial, blockstore: Blocks, options: Partial = {}): Promise { +export async function addDirectory (dir: Partial, blockstore: Blockstore, options: Partial = {}): Promise { const { cid } = await importDirectory({ ...dir, path: dir.path ?? '-' diff --git a/packages/unixfs/src/commands/cat.ts b/packages/unixfs/src/commands/cat.ts index 18269a80..f52acf9a 100644 --- a/packages/unixfs/src/commands/cat.ts +++ b/packages/unixfs/src/commands/cat.ts @@ -3,7 +3,7 @@ import mergeOpts from 'merge-options' import { NoContentError, NotAFileError } from '../errors.js' import { resolve } from './utils/resolve.js' import type { CatOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) @@ -12,7 +12,7 @@ const defaultOptions: CatOptions = { } -export async function * cat (cid: CID, blockstore: Blocks, options: Partial = {}): AsyncIterable { +export async function * cat (cid: CID, blockstore: Blockstore, options: Partial = {}): AsyncIterable { const opts: CatOptions = mergeOptions(defaultOptions, options) const resolved = await resolve(cid, opts.path, blockstore, opts) const result = await exporter(resolved.cid, blockstore, opts) diff --git a/packages/unixfs/src/commands/chmod.ts b/packages/unixfs/src/commands/chmod.ts index e9d04ec7..4f7d2b5e 100644 --- a/packages/unixfs/src/commands/chmod.ts +++ b/packages/unixfs/src/commands/chmod.ts @@ -14,8 +14,8 @@ import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js' import { persist } from './utils/persist.js' import { resolve, updatePathCids } from './utils/resolve.js' import type { ChmodOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode, PBLink } from '@ipld/dag-pb' +import type { Blockstore } from 'interface-blockstore' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) const log = logger('helia:unixfs:chmod') @@ -25,7 +25,7 @@ const defaultOptions: ChmodOptions = { shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES } -export async function chmod (cid: CID, mode: number, blockstore: Blocks, options: Partial = {}): Promise { +export async function chmod (cid: CID, mode: number, blockstore: Blockstore, options: Partial = {}): Promise { const opts: ChmodOptions = mergeOptions(defaultOptions, options) const resolved = await resolve(cid, opts.path, blockstore, options) diff --git a/packages/unixfs/src/commands/cp.ts b/packages/unixfs/src/commands/cp.ts index f8bbfdf1..3e5894ca 100644 --- a/packages/unixfs/src/commands/cp.ts +++ b/packages/unixfs/src/commands/cp.ts @@ -6,7 +6,7 @@ import { cidToDirectory } from './utils/cid-to-directory.js' import { cidToPBLink } from './utils/cid-to-pblink.js' import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js' import type { CpOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) @@ -17,7 +17,7 @@ const defaultOptions: CpOptions = { shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES } -export async function cp (source: CID, target: CID, name: string, blockstore: Blocks, options: Partial = {}): Promise { +export async function cp (source: CID, target: CID, name: string, blockstore: Blockstore, options: Partial = {}): Promise { const opts: CpOptions = mergeOptions(defaultOptions, options) if (name.includes('/')) { diff --git a/packages/unixfs/src/commands/ls.ts b/packages/unixfs/src/commands/ls.ts index c27566bd..e978a3b5 100644 --- a/packages/unixfs/src/commands/ls.ts +++ b/packages/unixfs/src/commands/ls.ts @@ -3,7 +3,7 @@ import mergeOpts from 'merge-options' import { NoContentError, NotADirectoryError } from '../errors.js' import { resolve } from './utils/resolve.js' import type { LsOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) @@ -12,7 +12,7 @@ const defaultOptions: LsOptions = { } -export async function * ls (cid: CID, blockstore: Blocks, options: Partial = {}): AsyncIterable { +export async function * ls (cid: CID, blockstore: Blockstore, options: Partial = {}): AsyncIterable { const opts: LsOptions = mergeOptions(defaultOptions, options) const resolved = await resolve(cid, opts.path, blockstore, opts) const result = await exporter(resolved.cid, blockstore) diff --git a/packages/unixfs/src/commands/mkdir.ts b/packages/unixfs/src/commands/mkdir.ts index 36c968c5..a30d8b51 100644 --- a/packages/unixfs/src/commands/mkdir.ts +++ b/packages/unixfs/src/commands/mkdir.ts @@ -11,7 +11,7 @@ import { cidToDirectory } from './utils/cid-to-directory.js' import { cidToPBLink } from './utils/cid-to-pblink.js' import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js' import type { MkdirOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) const log = logger('helia:unixfs:mkdir') @@ -22,7 +22,7 @@ const defaultOptions: MkdirOptions = { shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES } -export async function mkdir (parentCid: CID, dirname: string, blockstore: Blocks, options: Partial = {}): Promise { +export async function mkdir (parentCid: CID, dirname: string, blockstore: Blockstore, options: Partial = {}): Promise { const opts: MkdirOptions = mergeOptions(defaultOptions, options) if (dirname.includes('/')) { diff --git a/packages/unixfs/src/commands/rm.ts b/packages/unixfs/src/commands/rm.ts index e640ac4a..f5218f1b 100644 --- a/packages/unixfs/src/commands/rm.ts +++ b/packages/unixfs/src/commands/rm.ts @@ -5,7 +5,7 @@ import { cidToDirectory } from './utils/cid-to-directory.js' import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js' import { removeLink } from './utils/remove-link.js' import type { RmOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) @@ -15,7 +15,7 @@ const defaultOptions: RmOptions = { shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES } -export async function rm (target: CID, name: string, blockstore: Blocks, options: Partial = {}): Promise { +export async function rm (target: CID, name: string, blockstore: Blockstore, options: Partial = {}): Promise { const opts: RmOptions = mergeOptions(defaultOptions, options) if (name.includes('/')) { diff --git a/packages/unixfs/src/commands/stat.ts b/packages/unixfs/src/commands/stat.ts index 23cded33..8f2289de 100644 --- a/packages/unixfs/src/commands/stat.ts +++ b/packages/unixfs/src/commands/stat.ts @@ -7,8 +7,8 @@ import * as raw from 'multiformats/codecs/raw' import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.js' import { resolve } from './utils/resolve.js' import type { StatOptions, UnixFSStats } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { Mtime } from 'ipfs-unixfs' import type { CID } from 'multiformats/cid' @@ -19,7 +19,7 @@ const defaultOptions: StatOptions = { } -export async function stat (cid: CID, blockstore: Blocks, options: Partial = {}): Promise { +export async function stat (cid: CID, blockstore: Blockstore, options: Partial = {}): Promise { const opts: StatOptions = mergeOptions(defaultOptions, options) const resolved = await resolve(cid, options.path, blockstore, opts) @@ -93,7 +93,7 @@ interface InspectDagResults { blocks: number } -async function inspectDag (cid: CID, blockstore: Blocks, options: AbortOptions): Promise { +async function inspectDag (cid: CID, blockstore: Blockstore, options: AbortOptions): Promise { const results = { localFileSize: 0, localDagSize: 0, diff --git a/packages/unixfs/src/commands/touch.ts b/packages/unixfs/src/commands/touch.ts index 05b3aead..d07faed0 100644 --- a/packages/unixfs/src/commands/touch.ts +++ b/packages/unixfs/src/commands/touch.ts @@ -14,8 +14,8 @@ import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js' import { persist } from './utils/persist.js' import { resolve, updatePathCids } from './utils/resolve.js' import type { TouchOptions } from '../index.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode, PBLink } from '@ipld/dag-pb' +import type { Blockstore } from 'interface-blockstore' const mergeOptions = mergeOpts.bind({ ignoreUndefined: true }) const log = logger('helia:unixfs:touch') @@ -25,7 +25,7 @@ const defaultOptions: TouchOptions = { shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES } -export async function touch (cid: CID, blockstore: Blocks, options: Partial = {}): Promise { +export async function touch (cid: CID, blockstore: Blockstore, options: Partial = {}): Promise { const opts: TouchOptions = mergeOptions(defaultOptions, options) const resolved = await resolve(cid, opts.path, blockstore, opts) const mtime = opts.mtime ?? { diff --git a/packages/unixfs/src/commands/utils/add-link.ts b/packages/unixfs/src/commands/utils/add-link.ts index 2a43b55c..9a9608b5 100644 --- a/packages/unixfs/src/commands/utils/add-link.ts +++ b/packages/unixfs/src/commands/utils/add-link.ts @@ -17,9 +17,9 @@ import { } from './hamt-utils.js' import { isOverShardThreshold } from './is-over-shard-threshold.js' import type { Directory } from './cid-to-directory.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode, PBLink } from '@ipld/dag-pb/interface' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { ImportResult } from 'ipfs-unixfs-importer' const log = logger('helia:unixfs:components:utils:add-link') @@ -35,7 +35,7 @@ export interface AddLinkOptions extends AbortOptions { cidVersion: Version } -export async function addLink (parent: Directory, child: Required, blockstore: Blocks, options: AddLinkOptions): Promise { +export async function addLink (parent: Directory, child: Required, blockstore: Blockstore, options: AddLinkOptions): Promise { if (parent.node.Data == null) { throw new InvalidParametersError('Invalid parent passed to addLink') } @@ -63,7 +63,7 @@ export async function addLink (parent: Directory, child: Required, block return result } -const convertToShardedDirectory = async (parent: Directory, blockstore: Blocks): Promise => { +const convertToShardedDirectory = async (parent: Directory, blockstore: Blockstore): Promise => { if (parent.node.Data == null) { throw new InvalidParametersError('Invalid parent passed to convertToShardedDirectory') } @@ -85,7 +85,7 @@ const convertToShardedDirectory = async (parent: Directory, blockstore: Blocks): return result } -const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Blocks, options: AddLinkOptions): Promise => { +const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Blockstore, options: AddLinkOptions): Promise => { // Remove existing link if it exists const parentLinks = parent.node.Links.filter((link) => { const matches = link.Name === child.Name @@ -137,7 +137,7 @@ const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Bloc } } -const addToShardedDirectory = async (parent: Directory, child: Required, blockstore: Blocks, options: AddLinkOptions): Promise => { +const addToShardedDirectory = async (parent: Directory, child: Required, blockstore: Blockstore, options: AddLinkOptions): Promise => { const { path, hash } = await recreateShardedDirectory(parent.cid, child.Name, blockstore, options) const finalSegment = path[path.length - 1] diff --git a/packages/unixfs/src/commands/utils/cid-to-directory.ts b/packages/unixfs/src/commands/utils/cid-to-directory.ts index dc072c2c..4480b718 100644 --- a/packages/unixfs/src/commands/utils/cid-to-directory.ts +++ b/packages/unixfs/src/commands/utils/cid-to-directory.ts @@ -1,7 +1,7 @@ import { exporter, type ExporterOptions } from 'ipfs-unixfs-exporter' import { NotADirectoryError } from '../../errors.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode } from '@ipld/dag-pb' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' export interface Directory { @@ -9,7 +9,7 @@ export interface Directory { node: PBNode } -export async function cidToDirectory (cid: CID, blockstore: Blocks, options: ExporterOptions = {}): Promise { +export async function cidToDirectory (cid: CID, blockstore: Blockstore, options: ExporterOptions = {}): Promise { const entry = await exporter(cid, blockstore, options) if (entry.type !== 'directory') { diff --git a/packages/unixfs/src/commands/utils/cid-to-pblink.ts b/packages/unixfs/src/commands/utils/cid-to-pblink.ts index a1a460dd..578d34bd 100644 --- a/packages/unixfs/src/commands/utils/cid-to-pblink.ts +++ b/packages/unixfs/src/commands/utils/cid-to-pblink.ts @@ -1,11 +1,11 @@ import * as dagPb from '@ipld/dag-pb' import { exporter, type ExporterOptions } from 'ipfs-unixfs-exporter' import { NotUnixFSError } from '../../errors.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode, PBLink } from '@ipld/dag-pb' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' -export async function cidToPBLink (cid: CID, name: string, blockstore: Blocks, options?: ExporterOptions): Promise> { +export async function cidToPBLink (cid: CID, name: string, blockstore: Blockstore, options?: ExporterOptions): Promise> { const sourceEntry = await exporter(cid, blockstore, options) if (sourceEntry.type !== 'directory' && sourceEntry.type !== 'file' && sourceEntry.type !== 'raw') { diff --git a/packages/unixfs/src/commands/utils/dir-sharded.ts b/packages/unixfs/src/commands/utils/dir-sharded.ts index 4fba36cb..cede2a6d 100644 --- a/packages/unixfs/src/commands/utils/dir-sharded.ts +++ b/packages/unixfs/src/commands/utils/dir-sharded.ts @@ -7,7 +7,7 @@ import { hamtHashFn } from './hamt-constants.js' import { persist, type PersistOptions } from './persist.js' -import type { Blocks } from '@helia/interface/blocks' +import type { Blockstore } from 'interface-blockstore' import type { Mtime } from 'ipfs-unixfs' interface InProgressImportResult extends ImportResult { @@ -69,7 +69,7 @@ abstract class Dir { abstract put (name: string, value: InProgressImportResult | Dir): Promise abstract get (name: string): Promise abstract eachChildSeries (): AsyncIterable<{ key: string, child: InProgressImportResult | Dir }> - abstract flush (blockstore: Blocks): AsyncGenerator + abstract flush (blockstore: Blockstore): AsyncGenerator abstract estimateNodeSize (): number abstract childCount (): number } @@ -129,7 +129,7 @@ export class DirSharded extends Dir { return this.nodeSize } - async * flush (blockstore: Blocks): AsyncGenerator { + async * flush (blockstore: Blockstore): AsyncGenerator { for await (const entry of flush(this._bucket, blockstore, this, this.options)) { yield { ...entry, @@ -139,7 +139,7 @@ export class DirSharded extends Dir { } } -async function * flush (bucket: Bucket, blockstore: Blocks, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable { +async function * flush (bucket: Bucket, blockstore: Blockstore, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable { const children = bucket._children const links: PBLink[] = [] let childrenSize = 0n diff --git a/packages/unixfs/src/commands/utils/hamt-utils.ts b/packages/unixfs/src/commands/utils/hamt-utils.ts index 7dd4fb5a..4334c7c6 100644 --- a/packages/unixfs/src/commands/utils/hamt-utils.ts +++ b/packages/unixfs/src/commands/utils/hamt-utils.ts @@ -14,8 +14,8 @@ import { } from './hamt-constants.js' import { persist } from './persist.js' import type { PersistOptions } from './persist.js' -import type { Blocks } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { Mtime } from 'ipfs-unixfs' import type { ImportResult } from 'ipfs-unixfs-importer' import type { CID, Version } from 'multiformats/cid' @@ -40,7 +40,7 @@ export interface CreateShardOptions { cidVersion: Version } -export const createShard = async (blockstore: Blocks, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise => { +export const createShard = async (blockstore: Blockstore, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise => { const shard = new DirSharded({ root: true, dir: true, @@ -75,7 +75,7 @@ export interface HAMTPath { node: dagPB.PBNode } -export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blocks, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => { +export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blockstore, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => { // persist any metadata on the shard root const shardRoot = UnixFS.unmarshal(path[0].node.Data ?? new Uint8Array(0)) @@ -142,7 +142,7 @@ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Block return { cid, node } } -export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blocks, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => { +export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blockstore, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => { const wrapped = wrapHash(hamtHashFn) const hash = wrapped(uint8ArrayFromString(fileName)) const path: HAMTPath[] = [] diff --git a/packages/unixfs/src/commands/utils/is-over-shard-threshold.ts b/packages/unixfs/src/commands/utils/is-over-shard-threshold.ts index aa0edcbb..bcaf775e 100644 --- a/packages/unixfs/src/commands/utils/is-over-shard-threshold.ts +++ b/packages/unixfs/src/commands/utils/is-over-shard-threshold.ts @@ -1,9 +1,9 @@ import * as dagPb from '@ipld/dag-pb' import { UnixFS } from 'ipfs-unixfs' import { CID_V0, CID_V1 } from './dir-sharded.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode } from '@ipld/dag-pb' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' /** * Estimate node size only based on DAGLink name and CID byte lengths @@ -11,7 +11,7 @@ import type { AbortOptions } from '@libp2p/interface' * * If the node is a hamt sharded directory the calculation is based on if it was a regular directory. */ -export async function isOverShardThreshold (node: PBNode, blockstore: Blocks, threshold: number, options: AbortOptions): Promise { +export async function isOverShardThreshold (node: PBNode, blockstore: Blockstore, threshold: number, options: AbortOptions): Promise { if (node.Data == null) { throw new Error('DagPB node had no data') } @@ -43,7 +43,7 @@ function estimateNodeSize (node: PBNode): number { return size } -async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blocks, options: AbortOptions): Promise { +async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blockstore, options: AbortOptions): Promise { if (current > max) { return max } diff --git a/packages/unixfs/src/commands/utils/remove-link.ts b/packages/unixfs/src/commands/utils/remove-link.ts index 52ad517b..d3648714 100644 --- a/packages/unixfs/src/commands/utils/remove-link.ts +++ b/packages/unixfs/src/commands/utils/remove-link.ts @@ -11,9 +11,9 @@ import { import { isOverShardThreshold } from './is-over-shard-threshold.js' import { persist } from './persist.js' import type { Directory } from './cid-to-directory.js' -import type { Blocks } from '@helia/interface/blocks' import type { PBNode } from '@ipld/dag-pb' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { CID, Version } from 'multiformats/cid' const log = logger('helia:unixfs:utils:remove-link') @@ -28,7 +28,7 @@ export interface RemoveLinkResult { cid: CID } -export async function removeLink (parent: Directory, name: string, blockstore: Blocks, options: RmLinkOptions): Promise { +export async function removeLink (parent: Directory, name: string, blockstore: Blockstore, options: RmLinkOptions): Promise { if (parent.node.Data == null) { throw new InvalidPBNodeError('Parent node had no data') } @@ -54,7 +54,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: B return removeFromDirectory(parent, name, blockstore, options) } -const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: AbortOptions): Promise => { +const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: AbortOptions): Promise => { // Remove existing link if it exists parent.node.Links = parent.node.Links.filter((link) => { return link.Name !== name @@ -74,7 +74,7 @@ const removeFromDirectory = async (parent: Directory, name: string, blockstore: } } -const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => { +const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => { const { path } = await recreateShardedDirectory(parent.cid, name, blockstore, options) const finalSegment = path[path.length - 1] @@ -131,7 +131,7 @@ const removeFromShardedDirectory = async (parent: Directory, name: string, block return updateShardedDirectory(path, blockstore, options) } -const convertToFlatDirectory = async (parent: Directory, blockstore: Blocks, options: RmLinkOptions): Promise => { +const convertToFlatDirectory = async (parent: Directory, blockstore: Blockstore, options: RmLinkOptions): Promise => { if (parent.node.Data == null) { throw new InvalidParametersError('Invalid parent passed to convertToFlatDirectory') } diff --git a/packages/unixfs/src/commands/utils/resolve.ts b/packages/unixfs/src/commands/utils/resolve.ts index ed3ddd64..43c5defe 100644 --- a/packages/unixfs/src/commands/utils/resolve.ts +++ b/packages/unixfs/src/commands/utils/resolve.ts @@ -4,8 +4,8 @@ import { DoesNotExistError, InvalidParametersError } from '../../errors.js' import { addLink } from './add-link.js' import { cidToDirectory } from './cid-to-directory.js' import { cidToPBLink } from './cid-to-pblink.js' -import type { Blocks } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { CID } from 'multiformats/cid' const log = logger('helia:unixfs:components:utils:resolve') @@ -32,7 +32,7 @@ export interface ResolveResult { segments?: Segment[] } -export async function resolve (cid: CID, path: string | undefined, blockstore: Blocks, options: AbortOptions): Promise { +export async function resolve (cid: CID, path: string | undefined, blockstore: Blockstore, options: AbortOptions): Promise { if (path == null || path === '') { return { cid } } @@ -101,7 +101,7 @@ export interface UpdatePathCidsOptions extends AbortOptions { * Where we have descended into a DAG to update a child node, ascend up the DAG creating * new hashes and blocks for the changed content */ -export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blocks, options: UpdatePathCidsOptions): Promise { +export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blockstore, options: UpdatePathCidsOptions): Promise { if (result.segments == null || result.segments.length === 0) { return cid } diff --git a/packages/unixfs/src/index.ts b/packages/unixfs/src/index.ts index 4c066ad8..741ddc00 100644 --- a/packages/unixfs/src/index.ts +++ b/packages/unixfs/src/index.ts @@ -52,8 +52,9 @@ import { mkdir } from './commands/mkdir.js' import { rm } from './commands/rm.js' import { stat } from './commands/stat.js' import { touch } from './commands/touch.js' -import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' +import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks' import type { AbortOptions } from '@libp2p/interface' +import type { Blockstore } from 'interface-blockstore' import type { Mtime, UnixFS as IPFSUnixFS } from 'ipfs-unixfs' import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter' import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImporterProgressEvents, ImportResult } from 'ipfs-unixfs-importer' @@ -61,7 +62,7 @@ import type { CID, Version } from 'multiformats/cid' import type { ProgressOptions } from 'progress-events' export interface UnixFSComponents { - blockstore: Blocks + blockstore: Blockstore } export type AddEvents = PutBlockProgressEvents @@ -616,7 +617,7 @@ class DefaultUnixFS implements UnixFS { /** * Create a {@link UnixFS} instance for use with {@link https://github.com/ipfs/helia Helia} */ -export function unixfs (helia: { blockstore: Blocks }): UnixFS { +export function unixfs (helia: { blockstore: Blockstore }): UnixFS { return new DefaultUnixFS(helia) }