@@ -17,6 +17,7 @@ import first from 'it-first'
1717import last from 'it-last'
1818import toBuffer from 'it-to-buffer'
1919import { CID } from 'multiformats/cid'
20+ import * as json from 'multiformats/codecs/json'
2021import * as raw from 'multiformats/codecs/raw'
2122import { identity } from 'multiformats/hashes/identity'
2223import { sha256 } from 'multiformats/hashes/sha2'
@@ -978,7 +979,7 @@ describe('exporter', () => {
978979 expect ( data ) . to . deep . equal ( smallFile )
979980 } )
980981
981- it ( 'errors when exporting a non-existent key from a cbor node' , async ( ) => {
982+ it ( 'errors when exporting a non-existent key from a dag- cbor node' , async ( ) => {
982983 const node = {
983984 foo : 'bar'
984985 }
@@ -994,7 +995,7 @@ describe('exporter', () => {
994995 }
995996 } )
996997
997- it ( 'exports a cbor node' , async ( ) => {
998+ it ( 'exports a dag- cbor node' , async ( ) => {
998999 const node = {
9991000 foo : 'bar'
10001001 }
@@ -1011,7 +1012,7 @@ describe('exporter', () => {
10111012 return expect ( first ( exported . content ( ) ) ) . to . eventually . deep . equal ( node )
10121013 } )
10131014
1014- it ( 'errors when exporting a non-existent key from a json node' , async ( ) => {
1015+ it ( 'errors when exporting a non-existent key from a dag- json node' , async ( ) => {
10151016 const node = {
10161017 foo : 'bar'
10171018 }
@@ -1027,7 +1028,7 @@ describe('exporter', () => {
10271028 }
10281029 } )
10291030
1030- it ( 'exports a json node' , async ( ) => {
1031+ it ( 'exports a dag- json node' , async ( ) => {
10311032 const node = {
10321033 foo : 'bar'
10331034 }
@@ -1044,6 +1045,39 @@ describe('exporter', () => {
10441045 return expect ( first ( exported . content ( ) ) ) . to . eventually . deep . equal ( node )
10451046 } )
10461047
1048+ it ( 'errors when exporting a non-existent key from a json node' , async ( ) => {
1049+ const node = {
1050+ foo : 'bar'
1051+ }
1052+
1053+ const jsonBlock = json . encode ( node )
1054+ const cid = CID . createV1 ( json . code , await sha256 . digest ( jsonBlock ) )
1055+ await block . put ( cid , jsonBlock )
1056+
1057+ try {
1058+ await exporter ( `${ cid } /baz` , block )
1059+ } catch ( err : any ) {
1060+ expect ( err . code ) . to . equal ( 'ERR_NO_PROP' )
1061+ }
1062+ } )
1063+
1064+ it ( 'exports a json node' , async ( ) => {
1065+ const node = {
1066+ foo : 'bar'
1067+ }
1068+
1069+ const jsonBlock = json . encode ( node )
1070+ const cid = CID . createV1 ( json . code , await sha256 . digest ( jsonBlock ) )
1071+ await block . put ( cid , jsonBlock )
1072+ const exported = await exporter ( `${ cid } ` , block )
1073+
1074+ if ( exported . type !== 'object' ) {
1075+ throw new Error ( 'Unexpected type' )
1076+ }
1077+
1078+ return expect ( first ( exported . content ( ) ) ) . to . eventually . deep . equal ( node )
1079+ } )
1080+
10471081 it ( 'errors when exporting a node with no resolver' , async ( ) => {
10481082 const cid = CID . create ( 1 , 0x78 , CID . parse ( 'zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY' ) . multihash )
10491083
0 commit comments