@ocap/indexdb-memory 1.28.6 → 1.28.7
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/README.md +1 -1
- package/lib/db/base.js +3 -7
- package/lib/db/index.js +20 -14
- package/lib/table/base.js +10 -5
- package/lib/table/transaction.js +0 -1
- package/package.json +13 -14
package/README.md
CHANGED
package/lib/db/base.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable require-await */
|
|
2
|
-
/* eslint-disable newline-per-chained-call */
|
|
3
1
|
const { BN } = require('@ocap/util');
|
|
4
2
|
const { BaseIndexDB } = require('@ocap/indexdb');
|
|
5
3
|
const { formatPagination, formatNextPagination, formatDelegationAfterRead } = require('@ocap/indexdb/lib/util');
|
|
@@ -156,7 +154,7 @@ class LocalBaseIndexDB extends BaseIndexDB {
|
|
|
156
154
|
// Filter out data field if includeItxData is false (default behavior for performance)
|
|
157
155
|
if (!includeItxData) {
|
|
158
156
|
transactions = transactions.map((tx) => {
|
|
159
|
-
if (tx.tx
|
|
157
|
+
if (tx.tx?.itxJson) {
|
|
160
158
|
return {
|
|
161
159
|
...tx,
|
|
162
160
|
tx: {
|
|
@@ -186,9 +184,8 @@ class LocalBaseIndexDB extends BaseIndexDB {
|
|
|
186
184
|
}
|
|
187
185
|
|
|
188
186
|
const related = [address];
|
|
189
|
-
while (account
|
|
187
|
+
while (account?.migratedFrom && related.length <= 8) {
|
|
190
188
|
related.push(account.migratedFrom);
|
|
191
|
-
// eslint-disable-next-line no-await-in-loop
|
|
192
189
|
account = await this.account.get(account.migratedFrom);
|
|
193
190
|
}
|
|
194
191
|
|
|
@@ -202,7 +199,6 @@ class LocalBaseIndexDB extends BaseIndexDB {
|
|
|
202
199
|
|
|
203
200
|
const pagination = formatPagination({ paging, defaultSortField: 'renaissanceTime' });
|
|
204
201
|
|
|
205
|
-
// eslint-disable-next-line prefer-const
|
|
206
202
|
let { startDateTime, endDateTime, field = 'renaissanceTime' } = timeFilter;
|
|
207
203
|
startDateTime = parseDateTime(startDateTime);
|
|
208
204
|
endDateTime = parseDateTime(endDateTime);
|
|
@@ -494,7 +490,7 @@ class LocalBaseIndexDB extends BaseIndexDB {
|
|
|
494
490
|
|
|
495
491
|
const { txs = [] } = txFilter;
|
|
496
492
|
const { validators = [] } = validatorFilter;
|
|
497
|
-
let { startDateTime, endDateTime, field = 'genesisTime' } = timeFilter;
|
|
493
|
+
let { startDateTime, endDateTime, field = 'genesisTime' } = timeFilter;
|
|
498
494
|
startDateTime = parseDateTime(startDateTime);
|
|
499
495
|
endDateTime = parseDateTime(endDateTime);
|
|
500
496
|
|
package/lib/db/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
/* eslint-disable newline-per-chained-call */
|
|
2
1
|
const { md5 } = require('@ocap/util/lib/md5');
|
|
2
|
+
const Lokijs = require('lokijs');
|
|
3
3
|
const BaseIndexDB = require('./base');
|
|
4
4
|
|
|
5
5
|
const Table = require('../table/base');
|
|
6
6
|
const Transaction = require('../table/transaction');
|
|
7
7
|
const { name, version } = require('../../package.json');
|
|
8
8
|
|
|
9
|
+
let instanceCounter = 0;
|
|
10
|
+
|
|
9
11
|
class MemoryIndexDB extends BaseIndexDB {
|
|
10
12
|
constructor() {
|
|
11
13
|
super();
|
|
@@ -15,19 +17,23 @@ class MemoryIndexDB extends BaseIndexDB {
|
|
|
15
17
|
|
|
16
18
|
this.md5 = md5;
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
20
|
+
// Each instance has its own LokiJS database to ensure test isolation
|
|
21
|
+
instanceCounter += 1;
|
|
22
|
+
this.db = new Lokijs(`ocap-memory-indexdb-${instanceCounter}.db`);
|
|
23
|
+
|
|
24
|
+
this.account = new Table('account', 'address', this.db);
|
|
25
|
+
this.asset = new Table('asset', 'address', this.db);
|
|
26
|
+
this.delegation = new Table('delegation', 'address', this.db);
|
|
27
|
+
this.tx = new Transaction('tx', 'hash', this.db);
|
|
28
|
+
this.factory = new Table('factory', 'address', this.db);
|
|
29
|
+
this.token = new Table('token', 'address', this.db);
|
|
30
|
+
this.stake = new Table('stake', 'address', this.db);
|
|
31
|
+
this.rollup = new Table('rollup', 'address', this.db);
|
|
32
|
+
this.rollupBlock = new Table('rollupBlock', 'hash', this.db);
|
|
33
|
+
this.rollupValidator = new Table('rollupValidator', 'address', this.db);
|
|
34
|
+
this.tokenDistribution = new Table('tokenDistribution', 'tokenAddress', this.db);
|
|
35
|
+
this.balance = new Table('balance', ['address', 'tokenAddress'], this.db);
|
|
36
|
+
this.tokenFactory = new Table('tokenFactory', 'address', this.db);
|
|
31
37
|
|
|
32
38
|
this.attachReadyListeners();
|
|
33
39
|
}
|
package/lib/table/base.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
1
|
const { BaseIndex } = require('@ocap/indexdb');
|
|
3
|
-
const Lokijs = require('lokijs');
|
|
4
2
|
|
|
5
3
|
const debug = require('debug')(require('../../package.json').name);
|
|
6
4
|
|
|
7
|
-
const db = new Lokijs('ocap-memory-indexdb.db');
|
|
8
|
-
|
|
9
5
|
class MemoryIndex extends BaseIndex {
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} name table name
|
|
8
|
+
* @param {string|string[]} uniqIndex primary key(s)
|
|
9
|
+
* @param {import('lokijs')} db LokiJS database instance
|
|
10
|
+
*/
|
|
11
|
+
constructor(name, uniqIndex, db) {
|
|
11
12
|
super(name, uniqIndex);
|
|
12
13
|
|
|
13
14
|
this.uniqIndex = uniqIndex;
|
|
14
15
|
|
|
16
|
+
if (!db) {
|
|
17
|
+
throw new Error('db is required for MemoryIndex');
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
this.collection = db.addCollection(name, { unique: [this.primaryKey], clone: true });
|
|
16
21
|
this.markReady();
|
|
17
22
|
}
|
package/lib/table/transaction.js
CHANGED
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.28.
|
|
4
|
+
"version": "1.28.7",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"@ocap/indexdb-test": "1.28.6"
|
|
17
|
+
"@ocap/indexdb-test": "1.28.7"
|
|
19
18
|
},
|
|
20
19
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/memory",
|
|
21
20
|
"keywords": [
|
|
@@ -32,20 +31,20 @@
|
|
|
32
31
|
"type": "git",
|
|
33
32
|
"url": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/memory"
|
|
34
33
|
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "biome check",
|
|
36
|
+
"lint:fix": "biome check --write",
|
|
37
|
+
"test": "bun test",
|
|
38
|
+
"coverage": "npm run test -- --coverage"
|
|
39
|
+
},
|
|
35
40
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
36
41
|
"dependencies": {
|
|
42
|
+
"@arcblock/did": "1.28.7",
|
|
43
|
+
"@ocap/indexdb": "1.28.7",
|
|
44
|
+
"@ocap/util": "1.28.7",
|
|
37
45
|
"debug": "^4.3.6",
|
|
38
46
|
"empty-value": "^1.0.1",
|
|
39
47
|
"lodash": "^4.17.21",
|
|
40
|
-
"lokijs": "^1.5.12"
|
|
41
|
-
"@ocap/indexdb": "1.28.6",
|
|
42
|
-
"@ocap/util": "1.28.6",
|
|
43
|
-
"@arcblock/did": "1.28.6"
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"lint": "eslint tests lib",
|
|
47
|
-
"lint:fix": "eslint --fix tests lib",
|
|
48
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
49
|
-
"coverage": "npm run test -- --coverage"
|
|
48
|
+
"lokijs": "^1.5.12"
|
|
50
49
|
}
|
|
51
|
-
}
|
|
50
|
+
}
|