@@ -59,7 +59,7 @@ class DBStore {
5959
6060 private async getCollection ( ) : Promise < Array < IResult < IObject > > > {
6161 /* istanbul ignore next */
62- return ( ( await this . read ( ) ) ?. [ this . collectionName ] ) as Array < IResult < IObject > >
62+ return ( ( await this . read ( ) ) ?. [ this . collectionName ] ?? [ ] ) as Array < IResult < IObject > >
6363 }
6464
6565 private async getCollectionKey ( id : string ) : Promise < 1 | null > {
@@ -68,7 +68,7 @@ class DBStore {
6868
6969 private async getCollectionKeyMap ( ) : Promise < ILowDataKeyMap > {
7070 /* istanbul ignore next */
71- return ( ( ( await this . read ( ) ) ?. [ this . collectionKey ] ) as ILowDataKeyMap )
71+ return ( ( ( await this . read ( ) ) ?. [ this . collectionKey ] ) ?? { } ) as ILowDataKeyMap
7272 }
7373
7474 private async setCollectionKey ( id : string ) : Promise < void > {
@@ -79,7 +79,7 @@ class DBStore {
7979 }
8080
8181 @metaInfoHelper ( IMetaInfoMode . create )
82- async insert < T > ( value : T , writable = true ) : Promise < IResult < T > > {
82+ async insert < T > ( value : T , writable = true ) : Promise < IResult < T > > {
8383 const id = ( value as IResult < T > ) . id
8484 const result = await this . getCollectionKey ( id )
8585 if ( result ) {
@@ -95,7 +95,7 @@ class DBStore {
9595 }
9696
9797 @metaInfoHelper ( IMetaInfoMode . createMany )
98- async insertMany < T > ( value : T [ ] ) : Promise < Array < IResult < T > > > {
98+ async insertMany < T > ( value : T [ ] ) : Promise < Array < IResult < T > > > {
9999 for ( const item of value ) {
100100 await this . insert ( item , false )
101101 }
@@ -140,7 +140,7 @@ class DBStore {
140140 }
141141 }
142142
143- async getById < T > ( id : string ) : Promise < IResult < T > | undefined > {
143+ async getById < T > ( id : string ) : Promise < IResult < T > | undefined > {
144144 return ( await this . getCollection ( ) ) . find ( item => item . id === id ) as IResult < T >
145145 }
146146
@@ -156,7 +156,7 @@ class DBStore {
156156 }
157157 }
158158
159- async overwrite < T > ( value : T [ ] ) : Promise < Array < IResult < T > > > {
159+ async overwrite < T > ( value : T [ ] ) : Promise < Array < IResult < T > > > {
160160 await this . read ( ) ;
161161 ( this . db . data as ILowData ) [ this . collectionName ] = [ ] ;
162162 ( this . db . data as ILowData ) [ this . collectionKey ] = { }
0 commit comments