-
Notifications
You must be signed in to change notification settings - Fork 62
/
AppMetadataManager.ts
48 lines (40 loc) · 1.53 KB
/
AppMetadataManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Storage, StorageKey, AppMetadata } from '@airgap/beacon-types'
import { StorageManager } from './StorageManager'
/**
* @internalapi
*
* The AppMetadataManager provides CRUD functionality for app-metadata entities and persists them to the provided storage.
*/
export class AppMetadataManager {
private readonly storageManager: StorageManager<StorageKey.APP_METADATA_LIST>
constructor(storage: Storage) {
this.storageManager = new StorageManager(storage, StorageKey.APP_METADATA_LIST)
}
public async getAppMetadataList(): Promise<AppMetadata[]> {
return (await this.storageManager.getAll()) ?? []
}
public async getAppMetadata(senderId: string): Promise<AppMetadata | undefined> {
return this.storageManager.getOne(
(appMetadata: AppMetadata) => appMetadata.senderId === senderId
)
}
public async addAppMetadata(appMetadata: AppMetadata): Promise<void> {
return this.storageManager.addOne(
appMetadata,
(appMetadataElement: AppMetadata) => appMetadataElement.senderId === appMetadata.senderId
)
}
public async removeAppMetadata(senderId: string): Promise<void> {
return this.storageManager.remove(
(appMetadata: AppMetadata) => appMetadata.senderId === senderId
)
}
public async removeAppMetadatas(senderIds: string[]): Promise<void> {
return this.storageManager.remove((appMetadata: AppMetadata) =>
senderIds.includes(appMetadata.senderId)
)
}
public async removeAllAppMetadata(): Promise<void> {
return this.storageManager.removeAll()
}
}