@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 CHANGED
@@ -9,7 +9,7 @@
9
9
  ```sh
10
10
  npm install @ocap/indexdb-memory
11
11
  // or
12
- pnpm install @ocap/indexdb-memory
12
+ bun install @ocap/indexdb-memory
13
13
  ```
14
14
 
15
15
  ## Usage
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 && tx.tx.itxJson) {
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 && account.migratedFrom && related.length <= 8) {
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; // eslint-disable-line
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
- this.account = new Table('account', 'address');
19
- this.asset = new Table('asset', 'address');
20
- this.delegation = new Table('delegation', 'address');
21
- this.tx = new Transaction('tx', 'hash');
22
- this.factory = new Table('factory', 'address');
23
- this.token = new Table('token', 'address');
24
- this.stake = new Table('stake', 'address');
25
- this.rollup = new Table('rollup', 'address');
26
- this.rollupBlock = new Table('rollupBlock', 'hash');
27
- this.rollupValidator = new Table('rollupValidator', 'address');
28
- this.tokenDistribution = new Table('tokenDistribution', 'tokenAddress');
29
- this.balance = new Table('balance', ['address', 'tokenAddress']);
30
- this.tokenFactory = new Table('tokenFactory', 'address');
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
- constructor(name, uniqIndex) {
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
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-underscore-dangle */
2
1
  const { formatTxBeforeInsert } = require('@ocap/indexdb/lib/util');
3
2
  const Base = require('./base');
4
3
 
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.6",
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
- "jest": "^29.7.0",
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
+ }