@@ -17,6 +17,7 @@ import first from 'it-first'
17
17
import last from 'it-last'
18
18
import toBuffer from 'it-to-buffer'
19
19
import { CID } from 'multiformats/cid'
20
+ import * as json from 'multiformats/codecs/json'
20
21
import * as raw from 'multiformats/codecs/raw'
21
22
import { identity } from 'multiformats/hashes/identity'
22
23
import { sha256 } from 'multiformats/hashes/sha2'
@@ -978,7 +979,7 @@ describe('exporter', () => {
978
979
expect ( data ) . to . deep . equal ( smallFile )
979
980
} )
980
981
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 ( ) => {
982
983
const node = {
983
984
foo : 'bar'
984
985
}
@@ -994,7 +995,7 @@ describe('exporter', () => {
994
995
}
995
996
} )
996
997
997
- it ( 'exports a cbor node' , async ( ) => {
998
+ it ( 'exports a dag- cbor node' , async ( ) => {
998
999
const node = {
999
1000
foo : 'bar'
1000
1001
}
@@ -1011,7 +1012,7 @@ describe('exporter', () => {
1011
1012
return expect ( first ( exported . content ( ) ) ) . to . eventually . deep . equal ( node )
1012
1013
} )
1013
1014
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 ( ) => {
1015
1016
const node = {
1016
1017
foo : 'bar'
1017
1018
}
@@ -1027,7 +1028,7 @@ describe('exporter', () => {
1027
1028
}
1028
1029
} )
1029
1030
1030
- it ( 'exports a json node' , async ( ) => {
1031
+ it ( 'exports a dag- json node' , async ( ) => {
1031
1032
const node = {
1032
1033
foo : 'bar'
1033
1034
}
@@ -1044,6 +1045,39 @@ describe('exporter', () => {
1044
1045
return expect ( first ( exported . content ( ) ) ) . to . eventually . deep . equal ( node )
1045
1046
} )
1046
1047
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
+
1047
1081
it ( 'errors when exporting a node with no resolver' , async ( ) => {
1048
1082
const cid = CID . create ( 1 , 0x78 , CID . parse ( 'zdj7WkRPAX9o9nb9zPbXzwG7JEs78uyhwbUs8JSUayB98DWWY' ) . multihash )
1049
1083
0 commit comments