• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-wallet-sdk-ts / 9416468997

07 Jun 2024 11:46AM UTC coverage: 69.3% (+1.2%) from 68.144%
9416468997

Pull #215

github

web-flow
Merge ff72c3dfc into 78838eaef
Pull Request #215: feat: Backup and Restore

1087 of 1756 branches covered (61.9%)

Branch coverage included in aggregate %.

218 of 264 new or added lines in 29 files covered. (82.58%)

3 existing lines in 2 files now uncovered.

2290 of 3117 relevant lines covered (73.47%)

19.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/pluto/backup/BackupManager.ts
1
import * as Domain from "../../domain";
2
import * as Versions from "./versions";
3
import { Pluto } from "../Pluto";
4
import { PlutoRepositories } from "../repositories";
5
import { isEmpty } from "../../utils";
6
import { IBackupTask, IRestoreTask } from "./versions/interfaces";
7

8
/**
9
 * BackupManager
10
 * handle the different versions of backup and restore
11
 */
12
export class BackupManager {
13
  constructor(
14
    private readonly Pluto: Pluto,
15
    private readonly Repositories: PlutoRepositories
16
  ) {}
17

18
  /**
19
   * convert stored data to JSON
20
   * 
21
   * @param version - backup schema version
22
   * @returns {Promise<Domain.Backup.Schema>}
23
   */
24
  backup(version?: string) {
25
    const task = this.getBackupTask(version);
9✔
26
    return task.run();
9✔
27
  }
28

29
  /**
30
   * convert JSON to stored data
31
   * 
32
   * @param backup 
33
   */
34
  async restore(backup: Domain.Backup.Schema) {
35
    await this.assertStoreIsEmpty();
15✔
36
    const task = this.getRestoreTask(backup);
10✔
37
    await task.run();
10✔
38
  }
39

40
  private getBackupTask(version: string = Domain.Backup.defaultVersion): IBackupTask {
9✔
41
    switch (version) {
9✔
42
      case "0.0.1":
43
        return new Versions.v0_0_1.BackupTask(this.Pluto, this.Repositories);
9✔
44
    }
45

NEW
46
    throw new Domain.PlutoError.BackupNotFoundError();
×
47
  }
48

49
  private getRestoreTask(backup: Domain.Backup.Schema): IRestoreTask {
50
    const version = backup.version ?? Domain.Backup.defaultVersion;
10✔
51

52
    switch (version) {
10✔
53
      case "0.0.1":
54
        return new Versions.v0_0_1.RestoreTask(this.Pluto, backup);
10✔
55
    }
56

NEW
57
    throw new Domain.PlutoError.RestoreNotFoundError();
×
58
  }
59

60
  private async assertStoreIsEmpty() {
61
    const credentials = await this.Repositories.Credentials.getModels();
15✔
62
    const dids = await this.Repositories.DIDs.getModels();
15✔
63
    const keys = await this.Repositories.Keys.getModels();
15✔
64
    const link_secret = await this.Repositories.LinkSecrets.getModels();
15✔
65
    const messages = await this.Repositories.Messages.getModels();
15✔
66

67
    if (
15✔
68
      isEmpty(credentials) &&
64✔
69
      isEmpty(dids) &&
70
      isEmpty(keys) &&
71
      isEmpty(link_secret) &&
72
      isEmpty(messages)
73
    ) {
74
      return true;
10✔
75
    }
76

77
    throw new Domain.PlutoError.StoreNotEmptyError();
5✔
78
  }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc