@ocap/indexdb-fs 1.20.16 → 1.21.1
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.js +1 -0
- package/lib/table/base.js +13 -7
- package/package.json +5 -5
package/lib/db.js
CHANGED
@@ -25,6 +25,7 @@ class FsIndexDB extends BaseIndexDB {
|
|
25
25
|
this.rollupBlock = new Table('rollupBlock', dataDir, 'hash');
|
26
26
|
this.rollupValidator = new Table('rollupValidator', dataDir, 'address');
|
27
27
|
this.tokenDistribution = new Table('tokenDistribution', dataDir, 'tokenAddress');
|
28
|
+
this.balance = new Table('balance', dataDir, ['address', 'tokenAddress']);
|
28
29
|
|
29
30
|
this.attachReadyListeners();
|
30
31
|
}
|
package/lib/table/base.js
CHANGED
@@ -8,7 +8,7 @@ const debug = require('debug')(require('../../package.json').name);
|
|
8
8
|
|
9
9
|
class FsIndex extends BaseIndex {
|
10
10
|
constructor(name, dataDir, uniqIndex) {
|
11
|
-
super(name);
|
11
|
+
super(name, uniqIndex);
|
12
12
|
|
13
13
|
this.name = name;
|
14
14
|
this.uniqIndex = uniqIndex;
|
@@ -24,7 +24,7 @@ class FsIndex extends BaseIndex {
|
|
24
24
|
this.collection = db.getCollection(name);
|
25
25
|
|
26
26
|
if (this.collection === null) {
|
27
|
-
this.collection = db.addCollection(name, { unique: [
|
27
|
+
this.collection = db.addCollection(name, { unique: [this.primaryKey], clone: true });
|
28
28
|
}
|
29
29
|
|
30
30
|
this.markReady();
|
@@ -38,26 +38,32 @@ class FsIndex extends BaseIndex {
|
|
38
38
|
}
|
39
39
|
|
40
40
|
_insert(row) {
|
41
|
-
const
|
41
|
+
const id = this.generatePrimaryKey(row);
|
42
|
+
// Don't call this._get here cause _get may be overwritten
|
43
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
42
44
|
if (doc) {
|
43
45
|
return doc;
|
44
46
|
}
|
45
47
|
|
46
48
|
debug(`insert ${this.name}`, row);
|
47
|
-
return this.collection.insert({ ...row });
|
49
|
+
return this.collection.insert({ [this.primaryKey]: id, ...row });
|
48
50
|
}
|
49
51
|
|
50
52
|
_get(key) {
|
51
|
-
|
53
|
+
const id = this.generatePrimaryKey(key);
|
54
|
+
return key ? this.collection.by(this.primaryKey, id) : null;
|
52
55
|
}
|
53
56
|
|
54
57
|
_update(key, updates) {
|
55
|
-
const
|
58
|
+
const id = this.generatePrimaryKey(key);
|
59
|
+
// Don't call this._get here cause _get may be overwritten
|
60
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
56
61
|
if (!doc) {
|
57
62
|
return null;
|
58
63
|
}
|
59
64
|
|
60
|
-
debug(`update ${this.name}`, { key, updates });
|
65
|
+
debug(`update ${this.name}`, { id, key, updates });
|
66
|
+
|
61
67
|
Object.assign(doc, updates);
|
62
68
|
this.collection.update(doc);
|
63
69
|
return doc;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ocap/indexdb-fs",
|
3
3
|
"description": "OCAP indexdb adapter that uses file system as backend",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.21.1",
|
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.1"
|
19
19
|
},
|
20
20
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/fs",
|
21
21
|
"keywords": [
|
@@ -37,9 +37,9 @@
|
|
37
37
|
"debug": "^4.3.6",
|
38
38
|
"lodash": "^4.17.21",
|
39
39
|
"lokijs": "^1.5.12",
|
40
|
-
"@ocap/indexdb": "1.
|
41
|
-
"@ocap/
|
42
|
-
"@ocap/
|
40
|
+
"@ocap/indexdb": "1.21.1",
|
41
|
+
"@ocap/indexdb-memory": "1.21.1",
|
42
|
+
"@ocap/util": "1.21.1"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"lint": "eslint tests lib",
|