Skip to content

Commit

Permalink
Merge pull request #31 from dwhiffing/fix-collection
Browse files Browse the repository at this point in the history
Fixes collection issue
  • Loading branch information
dwhiffing authored Aug 29, 2024
2 parents 873e749 + 2747793 commit db0eef1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions utils/kvCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ export class KVCollection<T> {
const autoInc = await this.getAutoInc();
const members = await this.get();

const valueToSet = [...members, { key: autoInc, ...item }];
const valueToSet = [...members, { key: autoInc, ...item }].filter(
(m) => m.key > -1,
);

await kv.set(this.getStorageKey(), valueToSet);

await this.onAutoInc();
}

public async delete(key: string): Promise<void> {
public async delete(key: number): Promise<void> {
const members = await this.get();
await kv.set(
this.getStorageKey(),
// @ts-ignore
members.filter((m) => m.key !== key),
);
const valueToSet = members.filter((m) => m.key !== key && m.key > -1);
await kv.set(this.getStorageKey(), valueToSet);
}

public async get(): Promise<(T & { key: number })[]> {
Expand Down

0 comments on commit db0eef1

Please sign in to comment.