File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed
Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @orbitdb/nested-db" ,
3- "version" : " 2.0.1 " ,
3+ "version" : " 2.0.2 " ,
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 @@ -18,6 +18,7 @@ import type {
1818} from "./types" ;
1919import {
2020 flatten ,
21+ isNestedKey ,
2122 isNestedValue ,
2223 isSubkey ,
2324 joinKey ,
@@ -138,14 +139,14 @@ export const NestedApi = ({ database }: { database: InternalDatabase }) => {
138139
139140 type InsertFunction = {
140141 ( object : NestedValueWithUndefined ) : Promise < string > ;
141- ( key : string , object : NestedValueWithUndefined ) : Promise < string > ;
142+ ( key : NestedKey , object : NestedValueWithUndefined ) : Promise < string > ;
142143 } ;
143144
144145 const insert : InsertFunction = async (
145146 keyOrObject ,
146147 object ?: NestedValueWithUndefined | undefined ,
147148 ) : Promise < string > => {
148- if ( typeof keyOrObject === "string" ) {
149+ if ( isNestedKey ( keyOrObject ) ) {
149150 const joinedRootKey =
150151 typeof keyOrObject === "string" ? keyOrObject : joinKey ( keyOrObject ) ;
151152 return await addOperation ( {
Original file line number Diff line number Diff line change @@ -242,6 +242,14 @@ describe("Nested Database", () => {
242242 expect ( actual ) . to . deep . equal ( { a : { b : 2 } } ) ;
243243 } ) ;
244244
245+ it ( "insert a nested value - list syntax" , async ( ) => {
246+ await db . insert ( [ "a" , "b" ] , { d : 1 } ) ;
247+ await db . insert ( [ "a" , "c" ] , { e : 2 } ) ;
248+
249+ const actual = await db . all ( ) ;
250+ expect ( actual ) . to . deep . equal ( { a : { b : { d : 1 } , c : { e : 2 } } } ) ;
251+ } ) ;
252+
245253 it . skip ( "add positioned nested value after put" , async ( ) => {
246254 await db . put ( "a" , { b : 2 , c : 3 } ) ;
247255 // await db.put("a/d", 1, 1);
You can’t perform that action at this time.
0 commit comments