Skip to content

Commit ca10d79

Browse files
authored
fix: align blockstore pick interface name (#301)
1 parent 18e5b94 commit ca10d79

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

packages/ipfs-unixfs-exporter/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import resolve from './resolvers/index.js'
44
import last from 'it-last'
55
import type { UnixFS } from 'ipfs-unixfs'
66
import type { PBNode } from '@ipld/dag-pb'
7-
import type { Blockstore as InterfaceBlockstore } from 'interface-blockstore'
7+
import type { Blockstore } from 'interface-blockstore'
88
import type { Bucket } from 'hamt-sharding'
99
import type { ProgressOptions } from 'progress-events'
1010

@@ -65,21 +65,21 @@ export interface ResolveResult {
6565
next?: NextResult
6666
}
6767

68-
export interface Resolve { (cid: CID, name: string, path: string, toResolve: string[], depth: number, blockstore: Blockstore, options: ExporterOptions): Promise<ResolveResult> }
69-
export interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): Promise<ResolveResult> }
68+
export interface Resolve { (cid: CID, name: string, path: string, toResolve: string[], depth: number, blockstore: ReadableStorage, options: ExporterOptions): Promise<ResolveResult> }
69+
export interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions): Promise<ResolveResult> }
7070

7171
export type UnixfsV1FileContent = AsyncIterable<Uint8Array> | Iterable<Uint8Array>
7272
export type UnixfsV1DirectoryContent = AsyncIterable<UnixFSEntry> | Iterable<UnixFSEntry>
7373
export type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent
74-
export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: Blockstore): (options: ExporterOptions) => UnixfsV1Content }
74+
export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage): (options: ExporterOptions) => UnixfsV1Content }
7575

7676
export interface ShardTraversalContext {
7777
hamtDepth: number
7878
rootBucket: Bucket<boolean>
7979
lastBucket: Bucket<boolean>
8080
}
8181

82-
export type Blockstore = Pick<InterfaceBlockstore, 'get'>
82+
export type ReadableStorage = Pick<Blockstore, 'get'>
8383

8484
const toPathComponents = (path: string = ''): string[] => {
8585
// split on / unless escaped with \
@@ -121,7 +121,7 @@ const cidAndRest = (path: string | Uint8Array | CID): { cid: CID, toResolve: str
121121
throw errCode(new Error(`Unknown path type ${path}`), 'ERR_BAD_PATH')
122122
}
123123

124-
export async function * walkPath (path: string | CID, blockstore: Blockstore, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
124+
export async function * walkPath (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
125125
let {
126126
cid,
127127
toResolve
@@ -153,7 +153,7 @@ export async function * walkPath (path: string | CID, blockstore: Blockstore, op
153153
}
154154
}
155155

156-
export async function exporter (path: string | CID, blockstore: Blockstore, options: ExporterOptions = {}): Promise<UnixFSEntry> {
156+
export async function exporter (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): Promise<UnixFSEntry> {
157157
const result = await last(walkPath(path, blockstore, options))
158158

159159
if (result == null) {
@@ -163,7 +163,7 @@ export async function exporter (path: string | CID, blockstore: Blockstore, opti
163163
return result
164164
}
165165

166-
export async function * recursive (path: string | CID, blockstore: Blockstore, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
166+
export async function * recursive (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
167167
const node = await exporter(path, blockstore, options)
168168

169169
if (node == null) {

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import parallel from 'it-parallel'
99
import { pipe } from 'it-pipe'
1010
import map from 'it-map'
1111
import PQueue from 'p-queue'
12-
import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, Blockstore } from '../../../index.js'
12+
import type { ExporterOptions, UnixfsV1FileContent, UnixfsV1Resolver, ReadableStorage } from '../../../index.js'
1313

14-
async function walkDAG (blockstore: Blockstore, node: dagPb.PBNode | Uint8Array, queue: Pushable<Uint8Array>, streamPosition: bigint, start: bigint, end: bigint, options: ExporterOptions): Promise<void> {
14+
async function walkDAG (blockstore: ReadableStorage, node: dagPb.PBNode | Uint8Array, queue: Pushable<Uint8Array>, streamPosition: bigint, start: bigint, end: bigint, options: ExporterOptions): Promise<void> {
1515
// a `raw` node
1616
if (node instanceof Uint8Array) {
1717
queue.push(extractDataFromBlock(node, streamPosition, start, end))

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import parallel from 'it-parallel'
22
import { pipe } from 'it-pipe'
33
import map from 'it-map'
44
import { decode, PBNode } from '@ipld/dag-pb'
5-
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, Blockstore } from '../../../index.js'
5+
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage } from '../../../index.js'
66

77
const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => {
88
function yieldHamtDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent {
@@ -12,7 +12,7 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path,
1212
return yieldHamtDirectoryContent
1313
}
1414

15-
async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): UnixfsV1DirectoryContent {
15+
async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions): UnixfsV1DirectoryContent {
1616
const links = node.Links
1717

1818
const results = pipe(

packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Bucket, BucketPosition, createHAMT } from 'hamt-sharding'
33
import { decode, PBLink, PBNode } from '@ipld/dag-pb'
44
import { murmur3128 } from '@multiformats/murmur3'
5-
import type { ExporterOptions, ShardTraversalContext, Blockstore } from '../index.js'
5+
import type { ExporterOptions, ShardTraversalContext, ReadableStorage } from '../index.js'
66
import type { CID } from 'multiformats/cid'
77

88
// FIXME: this is copy/pasted from ipfs-unixfs-importer/src/options.js
@@ -61,7 +61,7 @@ const toBucketPath = (position: BucketPosition<boolean>): Array<Bucket<boolean>>
6161
return path.reverse()
6262
}
6363

64-
const findShardCid = async (node: PBNode, name: string, blockstore: Blockstore, context?: ShardTraversalContext, options?: ExporterOptions): Promise<CID | undefined> => {
64+
const findShardCid = async (node: PBNode, name: string, blockstore: ReadableStorage, context?: ShardTraversalContext, options?: ExporterOptions): Promise<CID | undefined> => {
6565
if (context == null) {
6666
const rootBucket = createHAMT<boolean>({
6767
hashFn

packages/ipfs-unixfs-importer/src/dag-builder/dir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UnixFS } from 'ipfs-unixfs'
22
import { persist } from '../utils/persist.js'
33
import { encode, prepare } from '@ipld/dag-pb'
4-
import type { Directory, InProgressImportResult, Blockstore } from '../index.js'
4+
import type { Directory, InProgressImportResult, WritableStorage } from '../index.js'
55
import type { Version } from 'multiformats/cid'
66
import type { ProgressOptions } from 'progress-events'
77

@@ -10,7 +10,7 @@ export interface DirBuilderOptions extends ProgressOptions {
1010
signal?: AbortSignal
1111
}
1212

13-
export const dirBuilder = async (dir: Directory, blockstore: Blockstore, options: DirBuilderOptions): Promise<InProgressImportResult> => {
13+
export const dirBuilder = async (dir: Directory, blockstore: WritableStorage, options: DirBuilderOptions): Promise<InProgressImportResult> => {
1414
const unixfs = new UnixFS({
1515
type: 'directory',
1616
mtime: dir.mtime,

packages/ipfs-unixfs-importer/src/dag-builder/file.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { persist } from '../utils/persist.js'
33
import { encode, PBLink, prepare } from '@ipld/dag-pb'
44
import parallelBatch from 'it-parallel-batch'
55
import * as rawCodec from 'multiformats/codecs/raw'
6-
import type { BufferImporter, File, InProgressImportResult, Blockstore, SingleBlockImportResult } from '../index.js'
6+
import type { BufferImporter, File, InProgressImportResult, WritableStorage, SingleBlockImportResult } from '../index.js'
77
import type { FileLayout, Reducer } from '../layout/index.js'
88
import type { Version } from 'multiformats/cid'
99
import type { ProgressOptions } from 'progress-events'
@@ -13,7 +13,7 @@ interface BuildFileBatchOptions {
1313
blockWriteConcurrency: number
1414
}
1515

16-
async function * buildFileBatch (file: File, blockstore: Blockstore, options: BuildFileBatchOptions): AsyncGenerator<InProgressImportResult> {
16+
async function * buildFileBatch (file: File, blockstore: WritableStorage, options: BuildFileBatchOptions): AsyncGenerator<InProgressImportResult> {
1717
let count = -1
1818
let previous: SingleBlockImportResult | undefined
1919

@@ -60,7 +60,7 @@ function isSingleBlockImport (result: any): result is SingleBlockImportResult {
6060
return result.single === true
6161
}
6262

63-
const reduce = (file: File, blockstore: Blockstore, options: ReduceOptions): Reducer => {
63+
const reduce = (file: File, blockstore: WritableStorage, options: ReduceOptions): Reducer => {
6464
const reducer: Reducer = async function (leaves) {
6565
if (leaves.length === 1 && isSingleBlockImport(leaves[0]) && options.reduceSingleLeafToSelf) {
6666
const leaf = leaves[0]
@@ -163,6 +163,6 @@ export interface FileBuilderOptions extends BuildFileBatchOptions, ReduceOptions
163163
layout: FileLayout
164164
}
165165

166-
export const fileBuilder = async (file: File, block: Blockstore, options: FileBuilderOptions): Promise<InProgressImportResult> => {
166+
export const fileBuilder = async (file: File, block: WritableStorage, options: FileBuilderOptions): Promise<InProgressImportResult> => {
167167
return await options.layout(buildFileBatch(file, block, options), reduce(file, block, options))
168168
}

packages/ipfs-unixfs-importer/src/dag-builder/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirBuilder, DirBuilderOptions } from './dir.js'
22
import { fileBuilder, FileBuilderOptions } from './file.js'
33
import errCode from 'err-code'
4-
import type { Directory, File, FileCandidate, ImportCandidate, InProgressImportResult, Blockstore } from '../index.js'
4+
import type { Directory, File, FileCandidate, ImportCandidate, InProgressImportResult, WritableStorage } from '../index.js'
55
import type { ChunkValidator } from './validate-chunks.js'
66
import type { Chunker } from '../chunker/index.js'
77

@@ -42,7 +42,7 @@ export interface DagBuilderOptions extends FileBuilderOptions, DirBuilderOptions
4242
export type ImporterSourceStream = AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>
4343

4444
export interface DAGBuilder {
45-
(source: ImporterSourceStream, blockstore: Blockstore): AsyncIterable<() => Promise<InProgressImportResult>>
45+
(source: ImporterSourceStream, blockstore: WritableStorage): AsyncIterable<() => Promise<InProgressImportResult>>
4646
}
4747

4848
export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder {

packages/ipfs-unixfs-importer/src/dir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Blockstore, ImportResult, InProgressImportResult } from './index.js'
1+
import type { WritableStorage, ImportResult, InProgressImportResult } from './index.js'
22
import type { Mtime, UnixFS } from 'ipfs-unixfs'
33
import { CID } from 'multiformats/cid'
44
import type { PersistOptions } from './utils/persist.js'
@@ -50,7 +50,7 @@ export abstract class Dir {
5050
abstract put (name: string, value: InProgressImportResult | Dir): Promise<void>
5151
abstract get (name: string): Promise<InProgressImportResult | Dir | undefined>
5252
abstract eachChildSeries (): AsyncIterable<{ key: string, child: InProgressImportResult | Dir }>
53-
abstract flush (blockstore: Blockstore): AsyncGenerator<ImportResult>
53+
abstract flush (blockstore: WritableStorage): AsyncGenerator<ImportResult>
5454
abstract estimateNodeSize (): number
5555
abstract childCount (): number
5656
}

packages/ipfs-unixfs-importer/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DAGBuilder, defaultDagBuilder } from './dag-builder/index.js'
33
import { defaultTreeBuilder } from './tree-builder.js'
44
import type { UnixFS, Mtime } from 'ipfs-unixfs'
55
import type { CID, Version as CIDVersion } from 'multiformats/cid'
6-
import type { Blockstore as InterfaceBlockstore } from 'interface-blockstore'
6+
import type { Blockstore } from 'interface-blockstore'
77
import { ChunkValidator, defaultChunkValidator } from './dag-builder/validate-chunks.js'
88
import { fixedSize } from './chunker/fixed-size.js'
99
import type { Chunker } from './chunker/index.js'
@@ -17,7 +17,7 @@ import type { ProgressOptions } from 'progress-events'
1717
export type ByteStream = AwaitIterable<Uint8Array>
1818
export type ImportContent = ByteStream | Uint8Array
1919

20-
export type Blockstore = Pick<InterfaceBlockstore, 'put'>
20+
export type WritableStorage = Pick<Blockstore, 'put'>
2121

2222
export interface FileCandidate {
2323
path?: string
@@ -73,8 +73,8 @@ export interface BufferImporterResult extends ImportResult {
7373
}
7474

7575
export interface HamtHashFn { (value: Uint8Array): Promise<Uint8Array> }
76-
export interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: Blockstore): AsyncIterable<ImportResult> }
77-
export interface BufferImporter { (file: File, blockstore: Blockstore): AsyncIterable<() => Promise<BufferImporterResult>> }
76+
export interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: WritableStorage): AsyncIterable<ImportResult> }
77+
export interface BufferImporter { (file: File, blockstore: WritableStorage): AsyncIterable<() => Promise<BufferImporterResult>> }
7878

7979
export type ImportProgressEvents =
8080
BufferImportProgressEvents
@@ -227,7 +227,7 @@ export type ImportCandidateStream = AsyncIterable<FileCandidate | DirectoryCandi
227227
* }
228228
* ```
229229
*/
230-
export async function * importer (source: ImportCandidateStream, blockstore: Blockstore, options: ImporterOptions = {}): AsyncGenerator<ImportResult, void, unknown> {
230+
export async function * importer (source: ImportCandidateStream, blockstore: WritableStorage, options: ImporterOptions = {}): AsyncGenerator<ImportResult, void, unknown> {
231231
let candidates: AsyncIterable<FileCandidate | DirectoryCandidate> | Iterable<FileCandidate | DirectoryCandidate>
232232

233233
if (Symbol.asyncIterator in source || Symbol.iterator in source) {
@@ -302,7 +302,7 @@ export async function * importer (source: ImportCandidateStream, blockstore: Blo
302302
* const entry = await importFile(input, blockstore)
303303
* ```
304304
*/
305-
export async function importFile (content: FileCandidate, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
305+
export async function importFile (content: FileCandidate, blockstore: WritableStorage, options: ImporterOptions = {}): Promise<ImportResult> {
306306
const result = await first(importer([content], blockstore, options))
307307

308308
if (result == null) {
@@ -333,7 +333,7 @@ export async function importFile (content: FileCandidate, blockstore: Blockstore
333333
* const entry = await importDirectory(input, blockstore)
334334
* ```
335335
*/
336-
export async function importDirectory (content: DirectoryCandidate, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
336+
export async function importDirectory (content: DirectoryCandidate, blockstore: WritableStorage, options: ImporterOptions = {}): Promise<ImportResult> {
337337
const result = await first(importer([content], blockstore, options))
338338

339339
if (result == null) {
@@ -361,7 +361,7 @@ export async function importDirectory (content: DirectoryCandidate, blockstore:
361361
* const entry = await importBytes(input, blockstore)
362362
* ```
363363
*/
364-
export async function importBytes (buf: ImportContent, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
364+
export async function importBytes (buf: ImportContent, blockstore: WritableStorage, options: ImporterOptions = {}): Promise<ImportResult> {
365365
return await importFile({
366366
content: buf
367367
}, blockstore, options)
@@ -388,7 +388,7 @@ export async function importBytes (buf: ImportContent, blockstore: Blockstore, o
388388
* const entry = await importByteStream(input, blockstore)
389389
* ```
390390
*/
391-
export async function importByteStream (bufs: ByteStream, blockstore: Blockstore, options: ImporterOptions = {}): Promise<ImportResult> {
391+
export async function importByteStream (bufs: ByteStream, blockstore: WritableStorage, options: ImporterOptions = {}): Promise<ImportResult> {
392392
return await importFile({
393393
content: bufs
394394
}, blockstore, options)

packages/ipfs-unixfs-importer/src/tree-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DirFlat } from './dir-flat.js'
22
import { flatToShard } from './flat-to-shard.js'
33
import { Dir } from './dir.js'
44
import { toPathComponents } from './utils/to-path-components.js'
5-
import type { ImportResult, InProgressImportResult, TreeBuilder, Blockstore } from './index.js'
5+
import type { ImportResult, InProgressImportResult, TreeBuilder, WritableStorage } from './index.js'
66
import type { PersistOptions } from './utils/persist.js'
77

88
export interface AddToTreeOptions extends PersistOptions {
@@ -54,7 +54,7 @@ async function addToTree (elem: InProgressImportResult, tree: Dir, options: AddT
5454
return tree
5555
}
5656

57-
async function * flushAndYield (tree: Dir | InProgressImportResult, blockstore: Blockstore): AsyncGenerator<ImportResult> {
57+
async function * flushAndYield (tree: Dir | InProgressImportResult, blockstore: WritableStorage): AsyncGenerator<ImportResult> {
5858
if (!(tree instanceof Dir)) {
5959
if (tree.unixfs?.isDirectory() === true) {
6060
yield tree

0 commit comments

Comments
 (0)