@ocap/indexdb-memory 1.20.15 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/db/index.js +1 -0
- package/lib/table/base.js +16 -6
- package/package.json +5 -5
package/lib/db/index.js
CHANGED
@@ -26,6 +26,7 @@ class MemoryIndexDB extends BaseIndexDB {
|
|
26
26
|
this.rollupBlock = new Table('rollupBlock', 'hash');
|
27
27
|
this.rollupValidator = new Table('rollupValidator', 'address');
|
28
28
|
this.tokenDistribution = new Table('tokenDistribution', 'tokenAddress');
|
29
|
+
this.balance = new Table('balance', ['address', 'tokenAddress']);
|
29
30
|
|
30
31
|
this.attachReadyListeners();
|
31
32
|
}
|
package/lib/table/base.js
CHANGED
@@ -8,9 +8,11 @@ const db = new Lokijs('ocap-memory-indexdb.db');
|
|
8
8
|
|
9
9
|
class MemoryIndex extends BaseIndex {
|
10
10
|
constructor(name, uniqIndex) {
|
11
|
-
super(name);
|
11
|
+
super(name, uniqIndex);
|
12
|
+
|
12
13
|
this.uniqIndex = uniqIndex;
|
13
|
-
|
14
|
+
|
15
|
+
this.collection = db.addCollection(name, { unique: [this.primaryKey], clone: true });
|
14
16
|
this.markReady();
|
15
17
|
}
|
16
18
|
|
@@ -20,16 +22,24 @@ class MemoryIndex extends BaseIndex {
|
|
20
22
|
|
21
23
|
_insert(row) {
|
22
24
|
debug(`insert ${this.name}`, row);
|
23
|
-
|
25
|
+
|
26
|
+
const id = this.generatePrimaryKey(row);
|
27
|
+
return this.collection.insert({ [this.primaryKey]: id, ...row });
|
24
28
|
}
|
25
29
|
|
26
30
|
_get(key) {
|
27
|
-
|
31
|
+
const id = this.generatePrimaryKey(key);
|
32
|
+
return key ? this.collection.by(this.primaryKey, id) : null;
|
28
33
|
}
|
29
34
|
|
30
35
|
_update(key, updates) {
|
31
|
-
|
32
|
-
|
36
|
+
const id = this.generatePrimaryKey(key);
|
37
|
+
// Don't call this._get here cause _get may be overwritten
|
38
|
+
const doc = MemoryIndex.prototype._get.call(this, id);
|
39
|
+
if (!doc) {
|
40
|
+
throw new Error(`${this.name} does not exists: ${key}`);
|
41
|
+
}
|
42
|
+
|
33
43
|
Object.assign(doc, updates);
|
34
44
|
this.collection.update(doc);
|
35
45
|
return doc;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ocap/indexdb-memory",
|
3
3
|
"description": "OCAP indexdb adapter that uses memory as backend, just for test purpose",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.21.0",
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
],
|
16
16
|
"devDependencies": {
|
17
17
|
"jest": "^29.7.0",
|
18
|
-
"@ocap/indexdb-test": "1.
|
18
|
+
"@ocap/indexdb-test": "1.21.0"
|
19
19
|
},
|
20
20
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/memory",
|
21
21
|
"keywords": [
|
@@ -38,9 +38,9 @@
|
|
38
38
|
"empty-value": "^1.0.1",
|
39
39
|
"lodash": "^4.17.21",
|
40
40
|
"lokijs": "^1.5.12",
|
41
|
-
"@arcblock/did": "1.
|
42
|
-
"@ocap/indexdb": "1.
|
43
|
-
"@ocap/util": "1.
|
41
|
+
"@arcblock/did": "1.21.0",
|
42
|
+
"@ocap/indexdb": "1.21.0",
|
43
|
+
"@ocap/util": "1.21.0"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"lint": "eslint tests lib",
|