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

hyperledger-identus / sdk-ts / 13919139621

18 Mar 2025 08:56AM UTC coverage: 74.693% (-0.2%) from 74.922%
13919139621

Pull #402

github

web-flow
Merge 48c601b65 into 3f9579c2f
Pull Request #402: fix: update signature encoding to follow JWS specification

1400 of 2080 branches covered (67.31%)

Branch coverage included in aggregate %.

19 of 38 new or added lines in 2 files covered. (50.0%)

20 existing lines in 2 files now uncovered.

3408 of 4357 relevant lines covered (78.22%)

50.75 hits per line

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

66.0
/src/pluto/rxdb/Store.ts
1
import { CollectionsOfDatabase, MangoQuery, RxDatabase, RxDatabaseCreator, RxDocument, addRxPlugin, createRxDatabase } from 'rxdb';
2
import { RxDBJsonDumpPlugin } from 'rxdb/plugins/json-dump';
3
import { RxDBQueryBuilderPlugin } from 'rxdb/plugins/query-builder';
4
import { CollectionList, makeCollections } from "./collections";
5
import type { Pluto } from "../Pluto";
6
import { Model } from '../models';
7
import { RxDBEncryptedMigrationPlugin } from '../migration';
8
import { Domain } from '../..';
9
import { RxDBUpdatePlugin } from 'rxdb/plugins/update';
10

11
export class RxdbStore implements Pluto.Store {
12
  private _db?: RxDatabase<CollectionsOfDatabase, any, any>;
13

14
  constructor(
15
    private readonly options: RxDatabaseCreator,
221✔
16
    private readonly collections?: CollectionList
221✔
17
  ) {
18
    console.warn("[DEPRECATION WARNING] RxdbStore is deprecated and future versions will no longer bundle it. Use @trust0/identus-store-rxdb in replacement for this class.");
221✔
19
    addRxPlugin(RxDBQueryBuilderPlugin);
221✔
20
    addRxPlugin(RxDBJsonDumpPlugin);
221✔
21
    addRxPlugin(RxDBEncryptedMigrationPlugin);
221✔
22
    addRxPlugin(RxDBUpdatePlugin);
221✔
23
  }
24

25

26
  get db() {
27
    if (!this._db) {
2,397!
UNCOV
28
      throw new Error('Start Pluto first.');
×
29
    }
30

31
    return this._db;
2,397✔
32
  }
33

34
  /**
35
   * Start the database and build collections
36
   */
37
  async start(): Promise<void> {
38
    if (!this._db) {
172!
39
      this._db = await createRxDatabase({
172✔
40
        ...this.options,
41
        multiInstance: true
42
      });
43
      const collections = makeCollections(this.collections ?? {});
172✔
44
      await this._db.addCollections(collections);
172✔
45
    }
46
  }
47

48
  async stop(): Promise<void> {
49
    await this.db.destroy();
48✔
50
    delete this._db;
48✔
51
  }
52

53
  async update<T extends Domain.Pluto.Storable>(name: string, model: T): Promise<void> {
54
    const table = this.getCollection(name);
×
UNCOV
55
    const row = await table.findOne({
×
56
      selector: {
57
        uuid: model.uuid
58
      }
59
    }).exec();
UNCOV
60
    if (row) {
×
61

62
      //Improve error handling when not found
UNCOV
63
      await row.patch(model);
×
64
    }
65
  }
66

67
  async delete(name: string, uuid: string): Promise<void> {
68
    const table = this.getCollection(name);
×
UNCOV
69
    const row = await table.findOne({
×
70
      selector: {
71
        uuid: uuid
72
      }
73
    });
74
    //TODO: Improve error handling, specially when not found
UNCOV
75
    await row?.remove();
×
76
  }
77

78

79
  getCollection(name: string) {
80
    const safeName = name.replace(/([A-Z])/g, "-$1").toLowerCase();
1,173✔
81
    if (!this.db.collections[safeName]) {
1,173!
UNCOV
82
      throw new Error("Collection does not exist");
×
83
    }
84

85
    return this.db.collections[safeName];
1,173✔
86
  }
87

88
  async query<T extends Model>(name: string, query?: MangoQuery<T>) {
89
    const collection = this.getCollection(name);
787✔
90
    const rxQuery = collection.find(query);
787✔
91
    const result: RxDocument[] = await rxQuery.exec();
787✔
92
    const models = result.map(x => x._data);
787✔
93
    return models as any;
787✔
94
  }
95

96
  async insert(name: string, data: any) {
97
    const table = this.getCollection(name);
386✔
98
    await table.insert(data);
386✔
99
  }
100

101
  /**
102
   * Use with caution, this will remove all entries from database
103
   */
104
  async cleanup() {
105
    const storages = Array.from(this.db.storageInstances.values());
3✔
106

107
    for (const storage of storages) {
3✔
108
      await storage.cleanup(Infinity);
24✔
109
    }
110
  }
111

112
  /**
113
   * Use with caution, this will remove all entries from database
114
   * and then destroy the database itself.
115
   */
116
  async clear() {
117
    await this.cleanup();
×
UNCOV
118
    await this.db.remove();
×
UNCOV
119
    delete this._db;
×
120
  }
121
}
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