@helia/unixfs 1.0.5 → 1.2.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 (84) 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 +1 -4
  9. package/dist/src/commands/cat.js.map +1 -1
  10. package/dist/src/commands/chmod.d.ts +2 -2
  11. package/dist/src/commands/chmod.d.ts.map +1 -1
  12. package/dist/src/commands/chmod.js +4 -2
  13. package/dist/src/commands/chmod.js.map +1 -1
  14. package/dist/src/commands/cp.d.ts +2 -2
  15. package/dist/src/commands/cp.d.ts.map +1 -1
  16. package/dist/src/commands/cp.js.map +1 -1
  17. package/dist/src/commands/ls.d.ts +2 -2
  18. package/dist/src/commands/ls.d.ts.map +1 -1
  19. package/dist/src/commands/ls.js.map +1 -1
  20. package/dist/src/commands/mkdir.d.ts +2 -2
  21. package/dist/src/commands/mkdir.d.ts.map +1 -1
  22. package/dist/src/commands/mkdir.js.map +1 -1
  23. package/dist/src/commands/rm.d.ts +2 -2
  24. package/dist/src/commands/rm.d.ts.map +1 -1
  25. package/dist/src/commands/rm.js.map +1 -1
  26. package/dist/src/commands/stat.d.ts +2 -2
  27. package/dist/src/commands/stat.d.ts.map +1 -1
  28. package/dist/src/commands/stat.js.map +1 -1
  29. package/dist/src/commands/touch.d.ts +2 -2
  30. package/dist/src/commands/touch.d.ts.map +1 -1
  31. package/dist/src/commands/touch.js +3 -1
  32. package/dist/src/commands/touch.js.map +1 -1
  33. package/dist/src/commands/utils/add-link.d.ts +2 -2
  34. package/dist/src/commands/utils/add-link.d.ts.map +1 -1
  35. package/dist/src/commands/utils/add-link.js.map +1 -1
  36. package/dist/src/commands/utils/cid-to-directory.d.ts +2 -2
  37. package/dist/src/commands/utils/cid-to-directory.d.ts.map +1 -1
  38. package/dist/src/commands/utils/cid-to-directory.js.map +1 -1
  39. package/dist/src/commands/utils/cid-to-pblink.d.ts +2 -2
  40. package/dist/src/commands/utils/cid-to-pblink.d.ts.map +1 -1
  41. package/dist/src/commands/utils/cid-to-pblink.js.map +1 -1
  42. package/dist/src/commands/utils/dir-sharded.d.ts +3 -3
  43. package/dist/src/commands/utils/dir-sharded.d.ts.map +1 -1
  44. package/dist/src/commands/utils/dir-sharded.js.map +1 -1
  45. package/dist/src/commands/utils/hamt-utils.d.ts +4 -4
  46. package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
  47. package/dist/src/commands/utils/hamt-utils.js.map +1 -1
  48. package/dist/src/commands/utils/is-over-shard-threshold.d.ts +2 -2
  49. package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -1
  50. package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
  51. package/dist/src/commands/utils/persist.d.ts +4 -2
  52. package/dist/src/commands/utils/persist.d.ts.map +1 -1
  53. package/dist/src/commands/utils/persist.js +1 -0
  54. package/dist/src/commands/utils/persist.js.map +1 -1
  55. package/dist/src/commands/utils/remove-link.d.ts +2 -2
  56. package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
  57. package/dist/src/commands/utils/remove-link.js.map +1 -1
  58. package/dist/src/commands/utils/resolve.d.ts +3 -3
  59. package/dist/src/commands/utils/resolve.d.ts.map +1 -1
  60. package/dist/src/commands/utils/resolve.js.map +1 -1
  61. package/dist/src/index.d.ts +23 -18
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/typedoc-urls.json +3 -0
  65. package/package.json +12 -7
  66. package/src/commands/add.ts +6 -6
  67. package/src/commands/cat.ts +3 -6
  68. package/src/commands/chmod.ts +4 -3
  69. package/src/commands/cp.ts +2 -2
  70. package/src/commands/ls.ts +2 -2
  71. package/src/commands/mkdir.ts +2 -2
  72. package/src/commands/rm.ts +2 -2
  73. package/src/commands/stat.ts +3 -3
  74. package/src/commands/touch.ts +3 -2
  75. package/src/commands/utils/add-link.ts +5 -5
  76. package/src/commands/utils/cid-to-directory.ts +2 -2
  77. package/src/commands/utils/cid-to-pblink.ts +2 -2
  78. package/src/commands/utils/dir-sharded.ts +4 -4
  79. package/src/commands/utils/hamt-utils.ts +4 -4
  80. package/src/commands/utils/is-over-shard-threshold.ts +3 -3
  81. package/src/commands/utils/persist.ts +5 -2
  82. package/src/commands/utils/remove-link.ts +5 -5
  83. package/src/commands/utils/resolve.ts +3 -3
  84. package/src/index.ts +34 -23
@@ -1,4 +1,4 @@
1
- import type { Blockstore } from 'interface-blockstore'
1
+ import type { Blocks } from '@helia/interface/blocks'
2
2
  import type { CID } from 'multiformats/cid'
3
3
  import type { RmOptions } from '../index.js'
4
4
  import mergeOpts from 'merge-options'
@@ -15,7 +15,7 @@ const defaultOptions: RmOptions = {
15
15
  shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
16
16
  }
17
17
 
18
- export async function rm (target: CID, name: string, blockstore: Blockstore, options: Partial<RmOptions> = {}): Promise<CID> {
18
+ export async function rm (target: CID, name: string, blockstore: Blocks, options: Partial<RmOptions> = {}): Promise<CID> {
19
19
  const opts: RmOptions = mergeOptions(defaultOptions, options)
20
20
 
21
21
  if (name.includes('/')) {
@@ -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 ?? {
@@ -67,6 +67,7 @@ export async function touch (cid: CID, blockstore: Blockstore, options: Partial<
67
67
  }
68
68
  }
69
69
  },
70
+ // @ts-expect-error blockstore types are incompatible
70
71
  (source) => importer(source, blockstore, {
71
72
  ...opts,
72
73
  dagBuilder: async function * (source, block) {
@@ -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'
@@ -43,18 +43,29 @@ import { rm } from './commands/rm.js'
43
43
  import { stat } from './commands/stat.js'
44
44
  import { touch } from './commands/touch.js'
45
45
  import { chmod } from './commands/chmod.js'
46
- import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
46
+ import type { ExporterProgressEvents, 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, ImporterProgressEvents, 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
52
53
  }
53
54
 
55
+ export type AddEvents = PutBlockProgressEvents
56
+ | ImporterProgressEvents
57
+
58
+ export interface AddOptions extends AbortOptions, Omit<ImporterOptions, 'onProgress'>, ProgressOptions<AddEvents> {
59
+
60
+ }
61
+
62
+ export type GetEvents = GetBlockProgressEvents
63
+ | ExporterProgressEvents
64
+
54
65
  /**
55
66
  * Options to pass to the cat command
56
67
  */
57
- export interface CatOptions extends AbortOptions {
68
+ export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents> {
58
69
  /**
59
70
  * Start reading the file at this offset
60
71
  */
@@ -74,7 +85,7 @@ export interface CatOptions extends AbortOptions {
74
85
  /**
75
86
  * Options to pass to the chmod command
76
87
  */
77
- export interface ChmodOptions extends AbortOptions {
88
+ export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
78
89
  /**
79
90
  * If the target of the operation is a directory and this is true,
80
91
  * apply the new mode to all directory contents
@@ -96,7 +107,7 @@ export interface ChmodOptions extends AbortOptions {
96
107
  /**
97
108
  * Options to pass to the cp command
98
109
  */
99
- export interface CpOptions extends AbortOptions {
110
+ export interface CpOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
100
111
  /**
101
112
  * If true, allow overwriting existing directory entries (default: false)
102
113
  */
@@ -112,7 +123,7 @@ export interface CpOptions extends AbortOptions {
112
123
  /**
113
124
  * Options to pass to the ls command
114
125
  */
115
- export interface LsOptions extends AbortOptions {
126
+ export interface LsOptions extends AbortOptions, ProgressOptions<GetEvents> {
116
127
  /**
117
128
  * Optional path to list subdirectory contents if the target CID resolves to
118
129
  * a directory
@@ -133,7 +144,7 @@ export interface LsOptions extends AbortOptions {
133
144
  /**
134
145
  * Options to pass to the mkdir command
135
146
  */
136
- export interface MkdirOptions extends AbortOptions {
147
+ export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
137
148
  /**
138
149
  * The CID version to create the new directory with - defaults to the same
139
150
  * version as the containing directory
@@ -165,7 +176,7 @@ export interface MkdirOptions extends AbortOptions {
165
176
  /**
166
177
  * Options to pass to the rm command
167
178
  */
168
- export interface RmOptions extends AbortOptions {
179
+ export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
169
180
  /**
170
181
  * DAGs with a root block larger than this value will be sharded. Blocks
171
182
  * smaller than this value will be regular UnixFS directories.
@@ -176,7 +187,7 @@ export interface RmOptions extends AbortOptions {
176
187
  /**
177
188
  * Options to pass to the stat command
178
189
  */
179
- export interface StatOptions extends AbortOptions {
190
+ export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents> {
180
191
  /**
181
192
  * An optional path to allow statting paths inside directories
182
193
  */
@@ -243,7 +254,7 @@ export interface UnixFSStats {
243
254
  /**
244
255
  * Options to pass to the touch command
245
256
  */
246
- export interface TouchOptions extends AbortOptions {
257
+ export interface TouchOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
247
258
  /**
248
259
  * Optional mtime to set on the DAG root, defaults to the current time
249
260
  */
@@ -292,7 +303,7 @@ export interface UnixFS {
292
303
  * }
293
304
  * ```
294
305
  */
295
- addAll: (source: ImportCandidateStream, options?: Partial<ImporterOptions>) => AsyncIterable<ImportResult>
306
+ addAll: (source: ImportCandidateStream, options?: Partial<AddOptions>) => AsyncIterable<ImportResult>
296
307
 
297
308
  /**
298
309
  * Add a single `Uint8Array` to your Helia node as a file.
@@ -305,7 +316,7 @@ export interface UnixFS {
305
316
  * console.info(cid)
306
317
  * ```
307
318
  */
308
- addBytes: (bytes: Uint8Array, options?: Partial<ImporterOptions>) => Promise<CID>
319
+ addBytes: (bytes: Uint8Array, options?: Partial<AddOptions>) => Promise<CID>
309
320
 
310
321
  /**
311
322
  * Add a stream of `Uint8Array` to your Helia node as a file.
@@ -321,7 +332,7 @@ export interface UnixFS {
321
332
  * console.info(cid)
322
333
  * ```
323
334
  */
324
- addByteStream: (bytes: ByteStream, options?: Partial<ImporterOptions>) => Promise<CID>
335
+ addByteStream: (bytes: ByteStream, options?: Partial<AddOptions>) => Promise<CID>
325
336
 
326
337
  /**
327
338
  * Add a file to your Helia node with optional metadata.
@@ -342,7 +353,7 @@ export interface UnixFS {
342
353
  * console.info(cid)
343
354
  * ```
344
355
  */
345
- addFile: (file: FileCandidate, options?: Partial<ImporterOptions>) => Promise<CID>
356
+ addFile: (file: FileCandidate, options?: Partial<AddOptions>) => Promise<CID>
346
357
 
347
358
  /**
348
359
  * Add a directory to your Helia node.
@@ -355,7 +366,7 @@ export interface UnixFS {
355
366
  * console.info(cid)
356
367
  * ```
357
368
  */
358
- addDirectory: (dir?: Partial<DirectoryCandidate>, options?: Partial<ImporterOptions>) => Promise<CID>
369
+ addDirectory: (dir?: Partial<DirectoryCandidate>, options?: Partial<AddOptions>) => Promise<CID>
359
370
 
360
371
  /**
361
372
  * Retrieve the contents of a file from your Helia node.
@@ -489,23 +500,23 @@ class DefaultUnixFS implements UnixFS {
489
500
  this.components = components
490
501
  }
491
502
 
492
- async * addAll (source: ImportCandidateStream, options: Partial<ImporterOptions> = {}): AsyncIterable<ImportResult> {
503
+ async * addAll (source: ImportCandidateStream, options: Partial<AddOptions> = {}): AsyncIterable<ImportResult> {
493
504
  yield * addAll(source, this.components.blockstore, options)
494
505
  }
495
506
 
496
- async addBytes (bytes: Uint8Array, options: Partial<ImporterOptions> = {}): Promise<CID> {
507
+ async addBytes (bytes: Uint8Array, options: Partial<AddOptions> = {}): Promise<CID> {
497
508
  return await addBytes(bytes, this.components.blockstore, options)
498
509
  }
499
510
 
500
- async addByteStream (bytes: ByteStream, options: Partial<ImporterOptions> = {}): Promise<CID> {
511
+ async addByteStream (bytes: ByteStream, options: Partial<AddOptions> = {}): Promise<CID> {
501
512
  return await addByteStream(bytes, this.components.blockstore, options)
502
513
  }
503
514
 
504
- async addFile (file: FileCandidate, options: Partial<ImporterOptions> = {}): Promise<CID> {
515
+ async addFile (file: FileCandidate, options: Partial<AddOptions> = {}): Promise<CID> {
505
516
  return await addFile(file, this.components.blockstore, options)
506
517
  }
507
518
 
508
- async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<ImporterOptions> = {}): Promise<CID> {
519
+ async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<AddOptions> = {}): Promise<CID> {
509
520
  return await addDirectory(dir, this.components.blockstore, options)
510
521
  }
511
522
 
@@ -545,6 +556,6 @@ class DefaultUnixFS implements UnixFS {
545
556
  /**
546
557
  * Create a {@link UnixFS} instance for use with {@link https://github.com/ipfs/helia Helia}
547
558
  */
548
- export function unixfs (helia: { blockstore: Blockstore }): UnixFS {
559
+ export function unixfs (helia: { blockstore: Blocks }): UnixFS {
549
560
  return new DefaultUnixFS(helia)
550
561
  }