File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @orbitdb/nested-db" ,
3- "version" : " 2.0.3 " ,
3+ "version" : " 2.0.4 " ,
44 "description" : " Nested key-value database type for orbit-db." ,
55 "author" : " Julien Jean Malard-Adam" ,
66 "keywords" : [
Original file line number Diff line number Diff line change @@ -122,11 +122,22 @@ export const NestedApi = ({ database }: { database: InternalDatabase }) => {
122122 const joinedKey = typeof key === "string" ? key : joinKey ( key ) ;
123123 const relevantKeyValues : { key : string ; value : DagCborEncodable } [ ] = [ ] ;
124124
125- for await ( const entry of iterator ( ) ) {
126- const { key : k , value } = entry ;
125+ const processEntry = ( k : string , value : DagCborEncodable ) => {
127126 if ( k === joinedKey || isSubkey ( k , joinedKey ) )
128127 relevantKeyValues . push ( { key : k , value } ) ;
128+ } ;
129+
130+ for await ( const entry of iterator ( ) ) {
131+ const { key : k , value } = entry ;
132+ if ( isNestedValue ( value ) ) {
133+ flatten ( value ) . forEach ( ( { key : subKey , value } ) =>
134+ processEntry ( `${ k } /${ subKey } ` , value ) ,
135+ ) ;
136+ } else {
137+ processEntry ( k , value ) ;
138+ }
129139 }
140+
130141 let nested : PossiblyNestedValue = toNested ( relevantKeyValues ) ;
131142 for ( const k of splitKey ( joinedKey ) ) {
132143 try {
Original file line number Diff line number Diff line change @@ -176,6 +176,20 @@ describe("Nested Database", () => {
176176 expect ( actualAB ) . to . equal ( 1 ) ;
177177 } ) ;
178178
179+ it ( "add a nested value - object type" , async ( ) => {
180+ await db . put ( "a/b" , { c : 1 } ) ;
181+
182+ const actual = await db . all ( ) ;
183+ expect ( actual ) . to . deep . equal ( { a : { b : { c : 1 } } } ) ;
184+ } ) ;
185+
186+ it ( "get a nested value - object type" , async ( ) => {
187+ await db . put ( "a/b" , { c : 1 } ) ;
188+
189+ const actual = await db . get ( "a/b/c" ) ;
190+ expect ( actual ) . to . deep . equal ( 1 ) ;
191+ } ) ;
192+
179193 it ( "get an inexisting nested key" , async ( ) => {
180194 const actual = await db . get ( "b/d" ) ;
181195 expect ( actual ) . to . be . undefined ( ) ;
You can’t perform that action at this time.
0 commit comments