Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use blockstore interface where possible #417

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/car/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
7 changes: 4 additions & 3 deletions packages/car/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, DAGWalker>
}

Expand Down Expand Up @@ -204,6 +205,6 @@ class DefaultCar implements Car {
/**
* Create a {@link Car} instance for use with {@link https:/ipfs/helia Helia}
*/
export function car (helia: { blockstore: Blocks, dagWalkers: Record<number, DAGWalker> }, init: any = {}): Car {
export function car (helia: { blockstore: Blockstore, dagWalkers: Record<number, DAGWalker> }, init: any = {}): Car {
return new DefaultCar(helia, init)
}
4 changes: 2 additions & 2 deletions packages/dag-cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 4 additions & 3 deletions packages/dag-cbor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PutBlockProgressEvents> {
Expand Down Expand Up @@ -115,6 +116,6 @@ class DefaultDAGCBOR implements DAGCBOR {
/**
* Create a {@link DAGCBOR} instance for use with {@link https:/ipfs/helia Helia}
*/
export function dagCbor (helia: { blockstore: Blocks }): DAGCBOR {
export function dagCbor (helia: { blockstore: Blockstore }): DAGCBOR {
return new DefaultDAGCBOR(helia)
}
4 changes: 2 additions & 2 deletions packages/dag-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 4 additions & 3 deletions packages/dag-json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PutBlockProgressEvents> {
Expand Down Expand Up @@ -115,6 +116,6 @@ class DefaultDAGJSON implements DAGJSON {
/**
* Create a {@link DAGJSON} instance for use with {@link https:/ipfs/helia Helia}
*/
export function dagJson (helia: { blockstore: Blocks }): DAGJSON {
export function dagJson (helia: { blockstore: Blockstore }): DAGJSON {
return new DefaultDAGJSON(helia)
}
4 changes: 2 additions & 2 deletions packages/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 4 additions & 3 deletions packages/json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PutBlockProgressEvents> {
Expand Down Expand Up @@ -115,6 +116,6 @@ class DefaultJSON implements JSON {
/**
* Create a {@link JSON} instance for use with {@link https:/ipfs/helia Helia}
*/
export function json (helia: { blockstore: Blocks }): JSON {
export function json (helia: { blockstore: Blockstore }): JSON {
return new DefaultJSON(helia)
}
3 changes: 1 addition & 2 deletions packages/mfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/mfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ 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'

const log = logger('helia:mfs')

export interface MFSComponents {
blockstore: Blocks
blockstore: Blockstore
datastore: Datastore
}

Expand Down Expand Up @@ -590,6 +590,6 @@ class DefaultMFS implements MFS {
/**
* Create a {@link MFS} instance powered by {@link https:/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)
}
4 changes: 2 additions & 2 deletions packages/strings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 4 additions & 3 deletions packages/strings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PutBlockProgressEvents> {
Expand Down Expand Up @@ -117,6 +118,6 @@ class DefaultStrings implements Strings {
/**
* Create a {@link Strings} instance for use with {@link https:/ipfs/helia Helia}
*/
export function strings (helia: { blockstore: Blocks }): Strings {
export function strings (helia: { blockstore: Blockstore }): Strings {
return new DefaultStrings(helia)
}
2 changes: 1 addition & 1 deletion packages/unixfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions packages/unixfs/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand All @@ -18,14 +18,14 @@ const defaultImporterSettings: ImporterOptions = {
})
}

export async function * addAll (source: ImportCandidateStream, blockstore: Blocks, options: Partial<ImporterOptions> = {}): AsyncGenerator<ImportResult, void, unknown> {
export async function * addAll (source: ImportCandidateStream, blockstore: Blockstore, options: Partial<ImporterOptions> = {}): AsyncGenerator<ImportResult, void, unknown> {
yield * importer(source, blockstore, {
...defaultImporterSettings,
...options
})
}

export async function addBytes (bytes: Uint8Array, blockstore: Blocks, options: Partial<ImporterOptions> = {}): Promise<CID> {
export async function addBytes (bytes: Uint8Array, blockstore: Blockstore, options: Partial<ImporterOptions> = {}): Promise<CID> {
const { cid } = await importBytes(bytes, blockstore, {
...defaultImporterSettings,
...options
Expand All @@ -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<ImporterOptions> = {}): Promise<CID> {
export async function addByteStream (bytes: ByteStream, blockstore: Blockstore, options: Partial<ImporterOptions> = {}): Promise<CID> {
const { cid } = await importByteStream(bytes, blockstore, {
...defaultImporterSettings,
...options
Expand All @@ -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<ImporterOptions> = {}): Promise<CID> {
export async function addFile (file: FileCandidate, blockstore: Blockstore, options: Partial<ImporterOptions> = {}): Promise<CID> {
const { cid } = await importFile(file, blockstore, {
...defaultImporterSettings,
...options
Expand All @@ -52,7 +52,7 @@ export async function addFile (file: FileCandidate, blockstore: Blocks, options:
return cid
}

export async function addDirectory (dir: Partial<DirectoryCandidate>, blockstore: Blocks, options: Partial<ImporterOptions> = {}): Promise<CID> {
export async function addDirectory (dir: Partial<DirectoryCandidate>, blockstore: Blockstore, options: Partial<ImporterOptions> = {}): Promise<CID> {
const { cid } = await importDirectory({
...dir,
path: dir.path ?? '-'
Expand Down
4 changes: 2 additions & 2 deletions packages/unixfs/src/commands/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -12,7 +12,7 @@ const defaultOptions: CatOptions = {

}

export async function * cat (cid: CID, blockstore: Blocks, options: Partial<CatOptions> = {}): AsyncIterable<Uint8Array> {
export async function * cat (cid: CID, blockstore: Blockstore, options: Partial<CatOptions> = {}): AsyncIterable<Uint8Array> {
const opts: CatOptions = mergeOptions(defaultOptions, options)
const resolved = await resolve(cid, opts.path, blockstore, opts)
const result = await exporter(resolved.cid, blockstore, opts)
Expand Down
4 changes: 2 additions & 2 deletions packages/unixfs/src/commands/chmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -25,7 +25,7 @@ const defaultOptions: ChmodOptions = {
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
}

export async function chmod (cid: CID, mode: number, blockstore: Blocks, options: Partial<ChmodOptions> = {}): Promise<CID> {
export async function chmod (cid: CID, mode: number, blockstore: Blockstore, options: Partial<ChmodOptions> = {}): Promise<CID> {
const opts: ChmodOptions = mergeOptions(defaultOptions, options)
const resolved = await resolve(cid, opts.path, blockstore, options)

Expand Down
4 changes: 2 additions & 2 deletions packages/unixfs/src/commands/cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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<CpOptions> = {}): Promise<CID> {
export async function cp (source: CID, target: CID, name: string, blockstore: Blockstore, options: Partial<CpOptions> = {}): Promise<CID> {
const opts: CpOptions = mergeOptions(defaultOptions, options)

if (name.includes('/')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/unixfs/src/commands/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -12,7 +12,7 @@ const defaultOptions: LsOptions = {

}

export async function * ls (cid: CID, blockstore: Blocks, options: Partial<LsOptions> = {}): AsyncIterable<UnixFSEntry> {
export async function * ls (cid: CID, blockstore: Blockstore, options: Partial<LsOptions> = {}): AsyncIterable<UnixFSEntry> {
const opts: LsOptions = mergeOptions(defaultOptions, options)
const resolved = await resolve(cid, opts.path, blockstore, opts)
const result = await exporter(resolved.cid, blockstore)
Expand Down
Loading
Loading