1
1
'use strict'
2
2
3
3
const errCode = require ( 'err-code' )
4
- const CID = require ( 'cids ' )
4
+ const CID = require ( 'multiformats/cid ' )
5
5
const resolve = require ( './resolvers' )
6
6
const last = require ( 'it-last' )
7
7
8
8
/**
9
9
* @typedef {import('ipfs-unixfs').UnixFS } UnixFS
10
- * @typedef {import('ipld-dag-pb').DAGNode } DAGNode
11
- * @typedef {import('ipld') } IPLD
10
+ * @typedef {import('ipfs-unixfs-importer/src/types').BlockAPI } BlockAPI
12
11
* @typedef {import('./types').ExporterOptions } ExporterOptions
13
12
* @typedef {import('./types').UnixFSFile } UnixFSFile
14
13
* @typedef {import('./types').UnixFSDirectory } UnixFSDirectory
@@ -31,15 +30,19 @@ const toPathComponents = (path = '') => {
31
30
*/
32
31
const cidAndRest = ( path ) => {
33
32
if ( path instanceof Uint8Array ) {
33
+ console . log ( 'vmx: index: path:' , path )
34
34
return {
35
- cid : new CID ( path ) ,
35
+ // @ts -ignore
36
+ cid : CID . decode ( path ) ,
36
37
toResolve : [ ]
37
38
}
38
39
}
39
40
40
- if ( CID . isCID ( path ) ) {
41
+ // @ts -ignore
42
+ const cid = CID . asCID ( path )
43
+ if ( cid ) {
41
44
return {
42
- cid : path ,
45
+ cid,
43
46
toResolve : [ ]
44
47
}
45
48
}
@@ -52,7 +55,8 @@ const cidAndRest = (path) => {
52
55
const output = toPathComponents ( path )
53
56
54
57
return {
55
- cid : new CID ( output [ 0 ] ) ,
58
+ // @ts -ignore
59
+ cid : CID . parse ( output [ 0 ] ) ,
56
60
toResolve : output . slice ( 1 )
57
61
}
58
62
}
@@ -62,10 +66,10 @@ const cidAndRest = (path) => {
62
66
63
67
/**
64
68
* @param {string | CID } path
65
- * @param {IPLD } ipld
69
+ * @param {BlockAPI } blockService
66
70
* @param {ExporterOptions } [options]
67
71
*/
68
- async function * walkPath ( path , ipld , options = { } ) {
72
+ async function * walkPath ( path , blockService , options = { } ) {
69
73
let {
70
74
cid,
71
75
toResolve
@@ -75,7 +79,7 @@ async function * walkPath (path, ipld, options = {}) {
75
79
const startingDepth = toResolve . length
76
80
77
81
while ( true ) {
78
- const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , ipld , options )
82
+ const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , blockService , options )
79
83
80
84
if ( ! result . entry && ! result . next ) {
81
85
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -99,11 +103,11 @@ async function * walkPath (path, ipld, options = {}) {
99
103
100
104
/**
101
105
* @param {string | CID } path
102
- * @param {IPLD } ipld
106
+ * @param {BlockAPI } blockService
103
107
* @param {ExporterOptions } [options]
104
108
*/
105
- async function exporter ( path , ipld , options = { } ) {
106
- const result = await last ( walkPath ( path , ipld , options ) )
109
+ async function exporter ( path , blockService , options = { } ) {
110
+ const result = await last ( walkPath ( path , blockService , options ) )
107
111
108
112
if ( ! result ) {
109
113
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -114,11 +118,11 @@ async function exporter (path, ipld, options = {}) {
114
118
115
119
/**
116
120
* @param {string | CID } path
117
- * @param {IPLD } ipld
121
+ * @param {BlockAPI } blockService
118
122
* @param {ExporterOptions } [options]
119
123
*/
120
- async function * recursive ( path , ipld , options = { } ) {
121
- const node = await exporter ( path , ipld , options )
124
+ async function * recursive ( path , blockService , options = { } ) {
125
+ const node = await exporter ( path , blockService , options )
122
126
123
127
if ( ! node ) {
124
128
return
0 commit comments