Skip to content

Commit 5564ed3

Browse files
committed
🐛 Fix: slice bug
1 parent c14c92c commit 5564ed3

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"eslint.enable": true,
3-
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": "explicit"
5-
},
3+
// "editor.codeActionsOnSave": {
4+
// "source.fixAll.eslint": "explicit"
5+
// },
66
"eslint.alwaysShowStatus": true,
77
"eslint.validate": [
88
"javascript",

src/DBStore.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)