11'use strict'
22
33const errCode = require ( 'err-code' )
4- const CID = require ( 'cids ' )
4+ const CID = require ( 'multiformats/cid ' )
55const resolve = require ( './resolvers' )
66const last = require ( 'it-last' )
77
88/**
99 * @typedef {import('ipfs-unixfs') } UnixFS
1010 * @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
1212 *
1313 * @typedef {object } UnixFSFile
1414 * @property {'file' } type
@@ -81,15 +81,19 @@ const toPathComponents = (path = '') => {
8181 */
8282const cidAndRest = ( path ) => {
8383 if ( path instanceof Uint8Array ) {
84+ console . log ( 'vmx: index: path:' , path )
8485 return {
85- cid : new CID ( path ) ,
86+ // @ts -ignore
87+ cid : CID . decode ( path ) ,
8688 toResolve : [ ]
8789 }
8890 }
8991
90- if ( CID . isCID ( path ) ) {
92+ // @ts -ignore
93+ const cid = CID . asCID ( path )
94+ if ( cid ) {
9195 return {
92- cid : path ,
96+ cid,
9397 toResolve : [ ]
9498 }
9599 }
@@ -102,7 +106,8 @@ const cidAndRest = (path) => {
102106 const output = toPathComponents ( path )
103107
104108 return {
105- cid : new CID ( output [ 0 ] ) ,
109+ // @ts -ignore
110+ cid : CID . parse ( output [ 0 ] ) ,
106111 toResolve : output . slice ( 1 )
107112 }
108113 }
@@ -112,20 +117,20 @@ const cidAndRest = (path) => {
112117
113118/**
114119 * @param {string | CID } path
115- * @param {IPLD } ipld
120+ * @param {BlockService } blockService
116121 * @param {ExporterOptions } [options]
117122 */
118- const walkPath = async function * ( path , ipld , options = { } ) {
123+ const walkPath = async function * ( path , blockService , options = { } ) {
119124 let {
120125 cid,
121126 toResolve
122127 } = cidAndRest ( path )
123- let name = cid . toBaseEncodedString ( )
128+ let name = cid . toString ( )
124129 let entryPath = name
125130 const startingDepth = toResolve . length
126131
127132 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 )
129134
130135 if ( ! result . entry && ! result . next ) {
131136 throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -149,11 +154,11 @@ const walkPath = async function * (path, ipld, options = {}) {
149154
150155/**
151156 * @param {string | CID } path
152- * @param {IPLD } ipld
157+ * @param {BlockService } blockService
153158 * @param {ExporterOptions } [options]
154159 */
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 ) )
157162
158163 if ( ! result ) {
159164 throw errCode ( new Error ( `Could not resolve ${ path } ` ) , 'ERR_NOT_FOUND' )
@@ -164,11 +169,11 @@ const exporter = async (path, ipld, options = {}) => {
164169
165170/**
166171 * @param {string | CID } path
167- * @param {IPLD } ipld
172+ * @param {BlockService } blockService
168173 * @param {ExporterOptions } [options]
169174 */
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 )
172177
173178 if ( ! node ) {
174179 return
0 commit comments