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
10
10
* @typedef {import('ipld-dag-pb').DAGNode } DAGNode
11
- * @typedef {import('ipfs-core-types/src/ipld ').IPLD } IPLD
11
+ * @typedef {import('ipfs-core-types/src/block-service ').BlockService } BlockService
12
12
*
13
13
* @typedef {object } UnixFSFile
14
14
* @property {'file' } type
@@ -81,15 +81,19 @@ const toPathComponents = (path = '') => {
81
81
*/
82
82
const cidAndRest = ( path ) => {
83
83
if ( path instanceof Uint8Array ) {
84
+ console . log ( 'vmx: index: path:' , path )
84
85
return {
85
- cid : new CID ( path ) ,
86
+ // @ts -ignore
87
+ cid : CID . decode ( path ) ,
86
88
toResolve : [ ]
87
89
}
88
90
}
89
91
90
- if ( CID . isCID ( path ) ) {
92
+ // @ts -ignore
93
+ const cid = CID . asCID ( path )
94
+ if ( cid ) {
91
95
return {
92
- cid : path ,
96
+ cid,
93
97
toResolve : [ ]
94
98
}
95
99
}
@@ -102,7 +106,8 @@ const cidAndRest = (path) => {
102
106
const output = toPathComponents ( path )
103
107
104
108
return {
105
- cid : new CID ( output [ 0 ] ) ,
109
+ // @ts -ignore
110
+ cid : CID . parse ( output [ 0 ] ) ,
106
111
toResolve : output . slice ( 1 )
107
112
}
108
113
}
@@ -112,20 +117,20 @@ const cidAndRest = (path) => {
112
117
113
118
/**
114
119
* @param {string | CID } path
115
- * @param {IPLD } ipld
120
+ * @param {BlockService } blockService
116
121
* @param {ExporterOptions } [options]
117
122
*/
118
- const walkPath = async function * ( path , ipld , options = { } ) {
123
+ const walkPath = async function * ( path , blockService , options = { } ) {
119
124
let {
120
125
cid,
121
126
toResolve
122
127
} = cidAndRest ( path )
123
- let name = cid . toBaseEncodedString ( )
128
+ let name = cid . toString ( )
124
129
let entryPath = name
125
130
const startingDepth = toResolve . length
126
131
127
132
while ( true ) {
128
- const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , ipld , options )
133
+ const result = await resolve ( cid , name , entryPath , toResolve , startingDepth , blockService , options )
129
134
130
135
if ( ! result . entry && ! result . next ) {
131
136
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -149,11 +154,11 @@ const walkPath = async function * (path, ipld, options = {}) {
149
154
150
155
/**
151
156
* @param {string | CID } path
152
- * @param {IPLD } ipld
157
+ * @param {BlockService } blockService
153
158
* @param {ExporterOptions } [options]
154
159
*/
155
- const exporter = async ( path , ipld , options = { } ) => {
156
- const result = await last ( walkPath ( path , ipld , options ) )
160
+ const exporter = async ( path , blockService , options = { } ) => {
161
+ const result = await last ( walkPath ( path , blockService , options ) )
157
162
158
163
if ( ! result ) {
159
164
throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -164,11 +169,11 @@ const exporter = async (path, ipld, options = {}) => {
164
169
165
170
/**
166
171
* @param {string | CID } path
167
- * @param {IPLD } ipld
172
+ * @param {BlockService } blockService
168
173
* @param {ExporterOptions } [options]
169
174
*/
170
- const recursive = async function * ( path , ipld , options = { } ) {
171
- const node = await exporter ( path , ipld , options )
175
+ const recursive = async function * ( path , blockService , options = { } ) {
176
+ const node = await exporter ( path , blockService , options )
172
177
173
178
if ( ! node ) {
174
179
return
0 commit comments