@helia/unixfs 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +1 -1
  2. package/dist/index.min.js +1 -1
  3. package/dist/src/commands/add.d.ts +6 -6
  4. package/dist/src/commands/add.d.ts.map +1 -1
  5. package/dist/src/commands/add.js.map +1 -1
  6. package/dist/src/commands/cat.d.ts +2 -2
  7. package/dist/src/commands/cat.d.ts.map +1 -1
  8. package/dist/src/commands/cat.js.map +1 -1
  9. package/dist/src/commands/chmod.d.ts +2 -2
  10. package/dist/src/commands/chmod.d.ts.map +1 -1
  11. package/dist/src/commands/chmod.js +4 -2
  12. package/dist/src/commands/chmod.js.map +1 -1
  13. package/dist/src/commands/cp.d.ts +2 -2
  14. package/dist/src/commands/cp.d.ts.map +1 -1
  15. package/dist/src/commands/cp.js.map +1 -1
  16. package/dist/src/commands/ls.d.ts +2 -2
  17. package/dist/src/commands/ls.d.ts.map +1 -1
  18. package/dist/src/commands/ls.js.map +1 -1
  19. package/dist/src/commands/mkdir.d.ts +2 -2
  20. package/dist/src/commands/mkdir.d.ts.map +1 -1
  21. package/dist/src/commands/mkdir.js.map +1 -1
  22. package/dist/src/commands/rm.d.ts +2 -2
  23. package/dist/src/commands/rm.d.ts.map +1 -1
  24. package/dist/src/commands/rm.js.map +1 -1
  25. package/dist/src/commands/stat.d.ts +2 -2
  26. package/dist/src/commands/stat.d.ts.map +1 -1
  27. package/dist/src/commands/stat.js.map +1 -1
  28. package/dist/src/commands/touch.d.ts +2 -2
  29. package/dist/src/commands/touch.d.ts.map +1 -1
  30. package/dist/src/commands/touch.js.map +1 -1
  31. package/dist/src/commands/utils/add-link.d.ts +2 -2
  32. package/dist/src/commands/utils/add-link.d.ts.map +1 -1
  33. package/dist/src/commands/utils/add-link.js.map +1 -1
  34. package/dist/src/commands/utils/cid-to-directory.d.ts +2 -2
  35. package/dist/src/commands/utils/cid-to-directory.d.ts.map +1 -1
  36. package/dist/src/commands/utils/cid-to-directory.js.map +1 -1
  37. package/dist/src/commands/utils/cid-to-pblink.d.ts +2 -2
  38. package/dist/src/commands/utils/cid-to-pblink.d.ts.map +1 -1
  39. package/dist/src/commands/utils/cid-to-pblink.js.map +1 -1
  40. package/dist/src/commands/utils/dir-sharded.d.ts +3 -3
  41. package/dist/src/commands/utils/dir-sharded.d.ts.map +1 -1
  42. package/dist/src/commands/utils/dir-sharded.js.map +1 -1
  43. package/dist/src/commands/utils/hamt-utils.d.ts +4 -4
  44. package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
  45. package/dist/src/commands/utils/hamt-utils.js.map +1 -1
  46. package/dist/src/commands/utils/is-over-shard-threshold.d.ts +2 -2
  47. package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -1
  48. package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
  49. package/dist/src/commands/utils/persist.d.ts +4 -2
  50. package/dist/src/commands/utils/persist.d.ts.map +1 -1
  51. package/dist/src/commands/utils/persist.js +1 -0
  52. package/dist/src/commands/utils/persist.js.map +1 -1
  53. package/dist/src/commands/utils/remove-link.d.ts +2 -2
  54. package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
  55. package/dist/src/commands/utils/remove-link.js.map +1 -1
  56. package/dist/src/commands/utils/resolve.d.ts +3 -3
  57. package/dist/src/commands/utils/resolve.d.ts.map +1 -1
  58. package/dist/src/commands/utils/resolve.js.map +1 -1
  59. package/dist/src/index.d.ts +22 -18
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/index.js.map +1 -1
  62. package/dist/typedoc-urls.json +2 -0
  63. package/package.json +12 -7
  64. package/src/commands/add.ts +6 -6
  65. package/src/commands/cat.ts +2 -2
  66. package/src/commands/chmod.ts +4 -3
  67. package/src/commands/cp.ts +2 -2
  68. package/src/commands/ls.ts +2 -2
  69. package/src/commands/mkdir.ts +2 -2
  70. package/src/commands/rm.ts +2 -2
  71. package/src/commands/stat.ts +3 -3
  72. package/src/commands/touch.ts +2 -2
  73. package/src/commands/utils/add-link.ts +5 -5
  74. package/src/commands/utils/cid-to-directory.ts +2 -2
  75. package/src/commands/utils/cid-to-pblink.ts +2 -2
  76. package/src/commands/utils/dir-sharded.ts +4 -4
  77. package/src/commands/utils/hamt-utils.ts +4 -4
  78. package/src/commands/utils/is-over-shard-threshold.ts +3 -3
  79. package/src/commands/utils/persist.ts +5 -2
  80. package/src/commands/utils/remove-link.ts +5 -5
  81. package/src/commands/utils/resolve.ts +3 -3
  82. package/src/index.ts +31 -23
@@ -10,7 +10,7 @@ import type { AbortOptions } from '@libp2p/interfaces'
10
10
  import type { Mtime } from 'ipfs-unixfs'
11
11
  import { resolve } from './utils/resolve.js'
12
12
  import * as raw from 'multiformats/codecs/raw'
13
- import type { Blockstore } from 'interface-blockstore'
13
+ import type { Blocks } from '@helia/interface/blocks'
14
14
 
15
15
  const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
16
16
  const log = logger('helia:unixfs:stat')
@@ -19,7 +19,7 @@ const defaultOptions: StatOptions = {
19
19
 
20
20
  }
21
21
 
22
- export async function stat (cid: CID, blockstore: Blockstore, options: Partial<StatOptions> = {}): Promise<UnixFSStats> {
22
+ export async function stat (cid: CID, blockstore: Blocks, options: Partial<StatOptions> = {}): Promise<UnixFSStats> {
23
23
  const opts: StatOptions = mergeOptions(defaultOptions, options)
24
24
  const resolved = await resolve(cid, options.path, blockstore, opts)
25
25
 
@@ -93,7 +93,7 @@ interface InspectDagResults {
93
93
  blocks: number
94
94
  }
95
95
 
96
- async function inspectDag (cid: CID, blockstore: Blockstore, options: AbortOptions): Promise<InspectDagResults> {
96
+ async function inspectDag (cid: CID, blockstore: Blocks, options: AbortOptions): Promise<InspectDagResults> {
97
97
  const results = {
98
98
  localFileSize: 0,
99
99
  localDagSize: 0,
@@ -10,7 +10,7 @@ import * as dagPB from '@ipld/dag-pb'
10
10
  import type { PBNode, PBLink } from '@ipld/dag-pb'
11
11
  import { importer } from 'ipfs-unixfs-importer'
12
12
  import { persist } from './utils/persist.js'
13
- import type { Blockstore } from 'interface-blockstore'
13
+ import type { Blocks } from '@helia/interface/blocks'
14
14
  import last from 'it-last'
15
15
  import { sha256 } from 'multiformats/hashes/sha2'
16
16
  import { resolve, updatePathCids } from './utils/resolve.js'
@@ -25,7 +25,7 @@ const defaultOptions: TouchOptions = {
25
25
  shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
26
26
  }
27
27
 
28
- export async function touch (cid: CID, blockstore: Blockstore, options: Partial<TouchOptions> = {}): Promise<CID> {
28
+ export async function touch (cid: CID, blockstore: Blocks, options: Partial<TouchOptions> = {}): Promise<CID> {
29
29
  const opts: TouchOptions = mergeOptions(defaultOptions, options)
30
30
  const resolved = await resolve(cid, opts.path, blockstore, opts)
31
31
  const mtime = opts.mtime ?? {
@@ -14,7 +14,7 @@ import { AlreadyExistsError, InvalidParametersError, InvalidPBNodeError } from '
14
14
  import type { ImportResult } from 'ipfs-unixfs-importer'
15
15
  import type { AbortOptions } from '@libp2p/interfaces'
16
16
  import type { Directory } from './cid-to-directory.js'
17
- import type { Blockstore } from 'interface-blockstore'
17
+ import type { Blocks } from '@helia/interface/blocks'
18
18
  import { isOverShardThreshold } from './is-over-shard-threshold.js'
19
19
  import { hamtBucketBits, hamtHashFn } from './hamt-constants.js'
20
20
  // @ts-expect-error no types
@@ -35,7 +35,7 @@ export interface AddLinkOptions extends AbortOptions {
35
35
  cidVersion: Version
36
36
  }
37
37
 
38
- export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> {
38
+ export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: Blocks, options: AddLinkOptions): Promise<AddLinkResult> {
39
39
  if (parent.node.Data == null) {
40
40
  throw new InvalidParametersError('Invalid parent passed to addLink')
41
41
  }
@@ -63,7 +63,7 @@ export async function addLink (parent: Directory, child: Required<PBLink>, block
63
63
  return result
64
64
  }
65
65
 
66
- const convertToShardedDirectory = async (parent: Directory, blockstore: Blockstore): Promise<ImportResult> => {
66
+ const convertToShardedDirectory = async (parent: Directory, blockstore: Blocks): Promise<ImportResult> => {
67
67
  if (parent.node.Data == null) {
68
68
  throw new InvalidParametersError('Invalid parent passed to convertToShardedDirectory')
69
69
  }
@@ -85,7 +85,7 @@ const convertToShardedDirectory = async (parent: Directory, blockstore: Blocksto
85
85
  return result
86
86
  }
87
87
 
88
- const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> => {
88
+ const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Blocks, options: AddLinkOptions): Promise<AddLinkResult> => {
89
89
  // Remove existing link if it exists
90
90
  const parentLinks = parent.node.Links.filter((link) => {
91
91
  const matches = link.Name === child.Name
@@ -137,7 +137,7 @@ const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Bloc
137
137
  }
138
138
  }
139
139
 
140
- const addToShardedDirectory = async (parent: Directory, child: Required<PBLink>, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> => {
140
+ const addToShardedDirectory = async (parent: Directory, child: Required<PBLink>, blockstore: Blocks, options: AddLinkOptions): Promise<AddLinkResult> => {
141
141
  const { path, hash } = await recreateShardedDirectory(parent.cid, child.Name, blockstore, options)
142
142
  const finalSegment = path[path.length - 1]
143
143
 
@@ -1,7 +1,7 @@
1
1
  import { exporter, ExporterOptions } from 'ipfs-unixfs-exporter'
2
2
  import type { CID } from 'multiformats/cid'
3
3
  import type { PBNode } from '@ipld/dag-pb'
4
- import type { Blockstore } from 'interface-blockstore'
4
+ import type { Blocks } from '@helia/interface/blocks'
5
5
  import { NotADirectoryError } from './errors.js'
6
6
 
7
7
  export interface Directory {
@@ -9,7 +9,7 @@ export interface Directory {
9
9
  node: PBNode
10
10
  }
11
11
 
12
- export async function cidToDirectory (cid: CID, blockstore: Blockstore, options: ExporterOptions = {}): Promise<Directory> {
12
+ export async function cidToDirectory (cid: CID, blockstore: Blocks, options: ExporterOptions = {}): Promise<Directory> {
13
13
  const entry = await exporter(cid, blockstore, options)
14
14
 
15
15
  if (entry.type !== 'directory') {
@@ -3,9 +3,9 @@ import type { CID } from 'multiformats/cid'
3
3
  import { NotUnixFSError } from './errors.js'
4
4
  import * as dagPb from '@ipld/dag-pb'
5
5
  import type { PBNode, PBLink } from '@ipld/dag-pb'
6
- import type { Blockstore } from 'interface-blockstore'
6
+ import type { Blocks } from '@helia/interface/blocks'
7
7
 
8
- export async function cidToPBLink (cid: CID, name: string, blockstore: Blockstore, options?: ExporterOptions): Promise<Required<PBLink>> {
8
+ export async function cidToPBLink (cid: CID, name: string, blockstore: Blocks, options?: ExporterOptions): Promise<Required<PBLink>> {
9
9
  const sourceEntry = await exporter(cid, blockstore, options)
10
10
 
11
11
  if (sourceEntry.type !== 'directory' && sourceEntry.type !== 'file' && sourceEntry.type !== 'raw') {
@@ -8,7 +8,7 @@ import {
8
8
  } from './hamt-constants.js'
9
9
  import { CID } from 'multiformats/cid'
10
10
  import type { Mtime } from 'ipfs-unixfs'
11
- import type { Blockstore } from 'interface-blockstore'
11
+ import type { Blocks } from '@helia/interface/blocks'
12
12
 
13
13
  interface InProgressImportResult extends ImportResult {
14
14
  single?: boolean
@@ -69,7 +69,7 @@ abstract class Dir {
69
69
  abstract put (name: string, value: InProgressImportResult | Dir): Promise<void>
70
70
  abstract get (name: string): Promise<InProgressImportResult | Dir | undefined>
71
71
  abstract eachChildSeries (): AsyncIterable<{ key: string, child: InProgressImportResult | Dir }>
72
- abstract flush (blockstore: Blockstore): AsyncGenerator<ImportResult>
72
+ abstract flush (blockstore: Blocks): AsyncGenerator<ImportResult>
73
73
  abstract estimateNodeSize (): number
74
74
  abstract childCount (): number
75
75
  }
@@ -129,7 +129,7 @@ export class DirSharded extends Dir {
129
129
  return this.nodeSize
130
130
  }
131
131
 
132
- async * flush (blockstore: Blockstore): AsyncGenerator<ImportResult> {
132
+ async * flush (blockstore: Blocks): AsyncGenerator<ImportResult> {
133
133
  for await (const entry of flush(this._bucket, blockstore, this, this.options)) {
134
134
  yield {
135
135
  ...entry,
@@ -139,7 +139,7 @@ export class DirSharded extends Dir {
139
139
  }
140
140
  }
141
141
 
142
- async function * flush (bucket: Bucket<Dir | InProgressImportResult>, blockstore: Blockstore, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
142
+ async function * flush (bucket: Bucket<Dir | InProgressImportResult>, blockstore: Blocks, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
143
143
  const children = bucket._children
144
144
  const links: PBLink[] = []
145
145
  let childrenSize = 0n
@@ -9,7 +9,7 @@ import {
9
9
  hamtHashFn,
10
10
  hamtBucketBits
11
11
  } from './hamt-constants.js'
12
- import type { Blockstore } from 'interface-blockstore'
12
+ import type { Blocks } from '@helia/interface/blocks'
13
13
  import type { Mtime } from 'ipfs-unixfs'
14
14
  import type { AbortOptions } from '@libp2p/interfaces'
15
15
  import type { ImportResult } from 'ipfs-unixfs-importer'
@@ -40,7 +40,7 @@ export interface CreateShardOptions {
40
40
  cidVersion: Version
41
41
  }
42
42
 
43
- export const createShard = async (blockstore: Blockstore, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
43
+ export const createShard = async (blockstore: Blocks, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
44
44
  const shard = new DirSharded({
45
45
  root: true,
46
46
  dir: true,
@@ -75,7 +75,7 @@ export interface HAMTPath {
75
75
  node: dagPB.PBNode
76
76
  }
77
77
 
78
- export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blockstore, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => {
78
+ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blocks, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => {
79
79
  // persist any metadata on the shard root
80
80
  const shardRoot = UnixFS.unmarshal(path[0].node.Data ?? new Uint8Array(0))
81
81
 
@@ -142,7 +142,7 @@ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Block
142
142
  return { cid, node }
143
143
  }
144
144
 
145
- export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blockstore, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => {
145
+ export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blocks, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => {
146
146
  const wrapped = wrapHash(hamtHashFn)
147
147
  const hash = wrapped(uint8ArrayFromString(fileName))
148
148
  const path: HAMTPath[] = []
@@ -1,5 +1,5 @@
1
1
  import type { PBNode } from '@ipld/dag-pb'
2
- import type { Blockstore } from 'interface-blockstore'
2
+ import type { Blocks } from '@helia/interface/blocks'
3
3
  import { UnixFS } from 'ipfs-unixfs'
4
4
  import * as dagPb from '@ipld/dag-pb'
5
5
  import { CID_V0, CID_V1 } from './dir-sharded.js'
@@ -10,7 +10,7 @@ import { CID_V0, CID_V1 } from './dir-sharded.js'
10
10
  *
11
11
  * If the node is a hamt sharded directory the calculation is based on if it was a regular directory.
12
12
  */
13
- export async function isOverShardThreshold (node: PBNode, blockstore: Blockstore, threshold: number): Promise<boolean> {
13
+ export async function isOverShardThreshold (node: PBNode, blockstore: Blocks, threshold: number): Promise<boolean> {
14
14
  if (node.Data == null) {
15
15
  throw new Error('DagPB node had no data')
16
16
  }
@@ -42,7 +42,7 @@ function estimateNodeSize (node: PBNode): number {
42
42
  return size
43
43
  }
44
44
 
45
- async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blockstore): Promise<number> {
45
+ async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blocks): Promise<number> {
46
46
  if (current > max) {
47
47
  return max
48
48
  }
@@ -1,7 +1,7 @@
1
1
  import { CID } from 'multiformats/cid'
2
2
  import * as dagPb from '@ipld/dag-pb'
3
3
  import { sha256 } from 'multiformats/hashes/sha2'
4
- import type { Blockstore } from 'ipfs-unixfs-importer'
4
+ import type { Blocks } from '@helia/interface/blocks'
5
5
  import type { BlockCodec } from 'multiformats/codecs/interface'
6
6
  import type { Version as CIDVersion } from 'multiformats/cid'
7
7
 
@@ -11,7 +11,9 @@ export interface PersistOptions {
11
11
  signal?: AbortSignal
12
12
  }
13
13
 
14
- export const persist = async (buffer: Uint8Array, blockstore: Blockstore, options: PersistOptions): Promise<CID> => {
14
+ type PutStore = Pick<Blocks, 'put'>
15
+
16
+ export const persist = async (buffer: Uint8Array, blockstore: PutStore, options: PersistOptions): Promise<CID> => {
15
17
  if (options.codec == null) {
16
18
  options.codec = dagPb
17
19
  }
@@ -20,6 +22,7 @@ export const persist = async (buffer: Uint8Array, blockstore: Blockstore, option
20
22
  const cid = CID.create(options.cidVersion, options.codec.code, multihash)
21
23
 
22
24
  await blockstore.put(cid, buffer, {
25
+ ...options,
23
26
  signal: options.signal
24
27
  })
25
28
 
@@ -9,7 +9,7 @@ import {
9
9
  updateShardedDirectory
10
10
  } from './hamt-utils.js'
11
11
  import type { PBNode } from '@ipld/dag-pb'
12
- import type { Blockstore } from 'interface-blockstore'
12
+ import type { Blocks } from '@helia/interface/blocks'
13
13
  import type { Directory } from './cid-to-directory.js'
14
14
  import type { AbortOptions } from '@libp2p/interfaces'
15
15
  import { InvalidParametersError, InvalidPBNodeError } from './errors.js'
@@ -29,7 +29,7 @@ export interface RemoveLinkResult {
29
29
  cid: CID
30
30
  }
31
31
 
32
- export async function removeLink (parent: Directory, name: string, blockstore: Blockstore, options: RmLinkOptions): Promise<RemoveLinkResult> {
32
+ export async function removeLink (parent: Directory, name: string, blockstore: Blocks, options: RmLinkOptions): Promise<RemoveLinkResult> {
33
33
  if (parent.node.Data == null) {
34
34
  throw new InvalidPBNodeError('Parent node had no data')
35
35
  }
@@ -55,7 +55,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: B
55
55
  return await removeFromDirectory(parent, name, blockstore, options)
56
56
  }
57
57
 
58
- const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: AbortOptions): Promise<RemoveLinkResult> => {
58
+ const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: AbortOptions): Promise<RemoveLinkResult> => {
59
59
  // Remove existing link if it exists
60
60
  parent.node.Links = parent.node.Links.filter((link) => {
61
61
  return link.Name !== name
@@ -75,7 +75,7 @@ const removeFromDirectory = async (parent: Directory, name: string, blockstore:
75
75
  }
76
76
  }
77
77
 
78
- const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => {
78
+ const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => {
79
79
  const { path } = await recreateShardedDirectory(parent.cid, name, blockstore, options)
80
80
  const finalSegment = path[path.length - 1]
81
81
 
@@ -132,7 +132,7 @@ const removeFromShardedDirectory = async (parent: Directory, name: string, block
132
132
  return await updateShardedDirectory(path, blockstore, options)
133
133
  }
134
134
 
135
- const convertToFlatDirectory = async (parent: Directory, blockstore: Blockstore, options: RmLinkOptions): Promise<RemoveLinkResult> => {
135
+ const convertToFlatDirectory = async (parent: Directory, blockstore: Blocks, options: RmLinkOptions): Promise<RemoveLinkResult> => {
136
136
  if (parent.node.Data == null) {
137
137
  throw new InvalidParametersError('Invalid parent passed to convertToFlatDirectory')
138
138
  }
@@ -6,7 +6,7 @@ import { DoesNotExistError, InvalidParametersError } from './errors.js'
6
6
  import { addLink } from './add-link.js'
7
7
  import { cidToDirectory } from './cid-to-directory.js'
8
8
  import { cidToPBLink } from './cid-to-pblink.js'
9
- import type { Blockstore } from 'interface-blockstore'
9
+ import type { Blocks } from '@helia/interface/blocks'
10
10
 
11
11
  const log = logger('helia:unixfs:components:utils:resolve')
12
12
 
@@ -32,7 +32,7 @@ export interface ResolveResult {
32
32
  segments?: Segment[]
33
33
  }
34
34
 
35
- export async function resolve (cid: CID, path: string | undefined, blockstore: Blockstore, options: AbortOptions): Promise<ResolveResult> {
35
+ export async function resolve (cid: CID, path: string | undefined, blockstore: Blocks, options: AbortOptions): Promise<ResolveResult> {
36
36
  if (path == null || path === '') {
37
37
  return { cid }
38
38
  }
@@ -101,7 +101,7 @@ export interface UpdatePathCidsOptions extends AbortOptions {
101
101
  * Where we have descended into a DAG to update a child node, ascend up the DAG creating
102
102
  * new hashes and blocks for the changed content
103
103
  */
104
- export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blockstore, options: UpdatePathCidsOptions): Promise<CID> {
104
+ export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blocks, options: UpdatePathCidsOptions): Promise<CID> {
105
105
  if (result.segments == null || result.segments.length === 0) {
106
106
  return cid
107
107
  }
package/src/index.ts CHANGED
@@ -32,7 +32,7 @@
32
32
  */
33
33
 
34
34
  import type { CID, Version } from 'multiformats/cid'
35
- import type { Blockstore } from 'interface-blockstore'
35
+ import type { Blocks, GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
36
36
  import type { AbortOptions } from '@libp2p/interfaces'
37
37
  import { addAll, addBytes, addByteStream, addDirectory, addFile } from './commands/add.js'
38
38
  import { cat } from './commands/cat.js'
@@ -45,16 +45,24 @@ import { touch } from './commands/touch.js'
45
45
  import { chmod } from './commands/chmod.js'
46
46
  import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
47
47
  import { ls } from './commands/ls.js'
48
- import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImportResult } from 'ipfs-unixfs-importer'
48
+ import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImportProgressEvents, ImportResult } from 'ipfs-unixfs-importer'
49
+ import type { ProgressOptions } from 'progress-events'
49
50
 
50
51
  export interface UnixFSComponents {
51
- blockstore: Blockstore
52
+ blockstore: Blocks
53
+ }
54
+
55
+ export type AddEvents = PutBlockProgressEvents
56
+ | ImportProgressEvents
57
+
58
+ export interface AddOptions extends AbortOptions, Omit<ImporterOptions, 'onProgress'>, ProgressOptions<AddEvents> {
59
+
52
60
  }
53
61
 
54
62
  /**
55
63
  * Options to pass to the cat command
56
64
  */
57
- export interface CatOptions extends AbortOptions {
65
+ export interface CatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
58
66
  /**
59
67
  * Start reading the file at this offset
60
68
  */
@@ -74,7 +82,7 @@ export interface CatOptions extends AbortOptions {
74
82
  /**
75
83
  * Options to pass to the chmod command
76
84
  */
77
- export interface ChmodOptions extends AbortOptions {
85
+ export interface ChmodOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
78
86
  /**
79
87
  * If the target of the operation is a directory and this is true,
80
88
  * apply the new mode to all directory contents
@@ -96,7 +104,7 @@ export interface ChmodOptions extends AbortOptions {
96
104
  /**
97
105
  * Options to pass to the cp command
98
106
  */
99
- export interface CpOptions extends AbortOptions {
107
+ export interface CpOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
100
108
  /**
101
109
  * If true, allow overwriting existing directory entries (default: false)
102
110
  */
@@ -112,7 +120,7 @@ export interface CpOptions extends AbortOptions {
112
120
  /**
113
121
  * Options to pass to the ls command
114
122
  */
115
- export interface LsOptions extends AbortOptions {
123
+ export interface LsOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
116
124
  /**
117
125
  * Optional path to list subdirectory contents if the target CID resolves to
118
126
  * a directory
@@ -133,7 +141,7 @@ export interface LsOptions extends AbortOptions {
133
141
  /**
134
142
  * Options to pass to the mkdir command
135
143
  */
136
- export interface MkdirOptions extends AbortOptions {
144
+ export interface MkdirOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
137
145
  /**
138
146
  * The CID version to create the new directory with - defaults to the same
139
147
  * version as the containing directory
@@ -165,7 +173,7 @@ export interface MkdirOptions extends AbortOptions {
165
173
  /**
166
174
  * Options to pass to the rm command
167
175
  */
168
- export interface RmOptions extends AbortOptions {
176
+ export interface RmOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
169
177
  /**
170
178
  * DAGs with a root block larger than this value will be sharded. Blocks
171
179
  * smaller than this value will be regular UnixFS directories.
@@ -176,7 +184,7 @@ export interface RmOptions extends AbortOptions {
176
184
  /**
177
185
  * Options to pass to the stat command
178
186
  */
179
- export interface StatOptions extends AbortOptions {
187
+ export interface StatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
180
188
  /**
181
189
  * An optional path to allow statting paths inside directories
182
190
  */
@@ -292,7 +300,7 @@ export interface UnixFS {
292
300
  * }
293
301
  * ```
294
302
  */
295
- addAll: (source: ImportCandidateStream, options?: Partial<ImporterOptions>) => AsyncIterable<ImportResult>
303
+ addAll: (source: ImportCandidateStream, options?: Partial<AddOptions>) => AsyncIterable<ImportResult>
296
304
 
297
305
  /**
298
306
  * Add a single `Uint8Array` to your Helia node as a file.
@@ -305,7 +313,7 @@ export interface UnixFS {
305
313
  * console.info(cid)
306
314
  * ```
307
315
  */
308
- addBytes: (bytes: Uint8Array, options?: Partial<ImporterOptions>) => Promise<CID>
316
+ addBytes: (bytes: Uint8Array, options?: Partial<AddOptions>) => Promise<CID>
309
317
 
310
318
  /**
311
319
  * Add a stream of `Uint8Array` to your Helia node as a file.
@@ -321,7 +329,7 @@ export interface UnixFS {
321
329
  * console.info(cid)
322
330
  * ```
323
331
  */
324
- addByteStream: (bytes: ByteStream, options?: Partial<ImporterOptions>) => Promise<CID>
332
+ addByteStream: (bytes: ByteStream, options?: Partial<AddOptions>) => Promise<CID>
325
333
 
326
334
  /**
327
335
  * Add a file to your Helia node with optional metadata.
@@ -342,7 +350,7 @@ export interface UnixFS {
342
350
  * console.info(cid)
343
351
  * ```
344
352
  */
345
- addFile: (file: FileCandidate, options?: Partial<ImporterOptions>) => Promise<CID>
353
+ addFile: (file: FileCandidate, options?: Partial<AddOptions>) => Promise<CID>
346
354
 
347
355
  /**
348
356
  * Add a directory to your Helia node.
@@ -355,7 +363,7 @@ export interface UnixFS {
355
363
  * console.info(cid)
356
364
  * ```
357
365
  */
358
- addDirectory: (dir?: Partial<DirectoryCandidate>, options?: Partial<ImporterOptions>) => Promise<CID>
366
+ addDirectory: (dir?: Partial<DirectoryCandidate>, options?: Partial<AddOptions>) => Promise<CID>
359
367
 
360
368
  /**
361
369
  * Retrieve the contents of a file from your Helia node.
@@ -368,7 +376,7 @@ export interface UnixFS {
368
376
  * }
369
377
  * ```
370
378
  */
371
- cat: (cid: CID, options?: Partial<CatOptions>) => AsyncIterable<Uint8Array>
379
+ cat: (cid: CID, options?: Partial<CatOptions> & ProgressOptions<GetBlockProgressEvents>) => AsyncIterable<Uint8Array>
372
380
 
373
381
  /**
374
382
  * Change the permissions on a file or directory in a DAG
@@ -415,7 +423,7 @@ export interface UnixFS {
415
423
  * }
416
424
  * ```
417
425
  */
418
- ls: (cid: CID, options?: Partial<LsOptions>) => AsyncIterable<UnixFSEntry>
426
+ ls: (cid: CID, options?: Partial<LsOptions> & ProgressOptions<GetBlockProgressEvents>) => AsyncIterable<UnixFSEntry>
419
427
 
420
428
  /**
421
429
  * Make a new directory under an existing directory.
@@ -489,23 +497,23 @@ class DefaultUnixFS implements UnixFS {
489
497
  this.components = components
490
498
  }
491
499
 
492
- async * addAll (source: ImportCandidateStream, options: Partial<ImporterOptions> = {}): AsyncIterable<ImportResult> {
500
+ async * addAll (source: ImportCandidateStream, options: Partial<AddOptions> = {}): AsyncIterable<ImportResult> {
493
501
  yield * addAll(source, this.components.blockstore, options)
494
502
  }
495
503
 
496
- async addBytes (bytes: Uint8Array, options: Partial<ImporterOptions> = {}): Promise<CID> {
504
+ async addBytes (bytes: Uint8Array, options: Partial<AddOptions> = {}): Promise<CID> {
497
505
  return await addBytes(bytes, this.components.blockstore, options)
498
506
  }
499
507
 
500
- async addByteStream (bytes: ByteStream, options: Partial<ImporterOptions> = {}): Promise<CID> {
508
+ async addByteStream (bytes: ByteStream, options: Partial<AddOptions> = {}): Promise<CID> {
501
509
  return await addByteStream(bytes, this.components.blockstore, options)
502
510
  }
503
511
 
504
- async addFile (file: FileCandidate, options: Partial<ImporterOptions> = {}): Promise<CID> {
512
+ async addFile (file: FileCandidate, options: Partial<AddOptions> = {}): Promise<CID> {
505
513
  return await addFile(file, this.components.blockstore, options)
506
514
  }
507
515
 
508
- async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<ImporterOptions> = {}): Promise<CID> {
516
+ async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<AddOptions> = {}): Promise<CID> {
509
517
  return await addDirectory(dir, this.components.blockstore, options)
510
518
  }
511
519
 
@@ -545,6 +553,6 @@ class DefaultUnixFS implements UnixFS {
545
553
  /**
546
554
  * Create a {@link UnixFS} instance for use with {@link https://github.com/ipfs/helia Helia}
547
555
  */
548
- export function unixfs (helia: { blockstore: Blockstore }): UnixFS {
556
+ export function unixfs (helia: { blockstore: Blocks }): UnixFS {
549
557
  return new DefaultUnixFS(helia)
550
558
  }