@ocap/indexdb-fs 1.6.5 → 1.6.10

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
@@ -1,4 +1,4 @@
1
- # [**@ocap/indexdb-fs**](https://github.com/arcblock/ocap-js)
1
+ # [**@ocap/indexdb-fs**](https://github.com/arcblock/asset-chain)
2
2
 
3
3
  [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
4
4
 
package/lib/db.js CHANGED
@@ -1,6 +1,5 @@
1
- const { BaseIndexDB } = require('@ocap/indexdb');
1
+ const BaseIndexDB = require('@ocap/indexdb-memory/lib/db/base');
2
2
  const md5 = require('@ocap/util/lib/md5');
3
- const formatPagination = require('@ocap/util/lib/format-pagination');
4
3
 
5
4
  const Table = require('./table/base');
6
5
  const Transaction = require('./table/transaction');
@@ -17,142 +16,16 @@ class FsIndexDB extends BaseIndexDB {
17
16
 
18
17
  this.account = new Table('account', dataDir, 'address');
19
18
  this.asset = new Table('asset', dataDir, 'address');
19
+ this.factory = new Table('factory', dataDir, 'address');
20
20
  this.delegation = new Table('delegation', dataDir, 'address');
21
21
  this.tx = new Transaction('tx', dataDir, 'hash');
22
+ this.token = new Table('token', dataDir, 'address');
23
+ this.stake = new Table('stake', dataDir, 'address');
24
+ this.rollup = new Table('rollup', dataDir, 'address');
25
+ this.rollupBlock = new Table('rollupBlock', dataDir, 'hash');
26
+ this.rollupValidator = new Table('rollupValidator', dataDir, 'address');
22
27
 
23
- this.account.onReady(() => this.markReady('account'));
24
- this.asset.onReady(() => this.markReady('asset'));
25
- this.delegation.onReady(() => this.markReady('delegation'));
26
- this.tx.onReady(() => this.markReady('tx'));
27
- }
28
-
29
- listTransactions({ addressFilter = {}, paging = {}, timeFilter = {}, typeFilter = {} } = {}) {
30
- const query = this.tx.collection.chain();
31
-
32
- const { sender, receiver, direction = 'UNION' } = addressFilter;
33
- const { types = [] } = typeFilter;
34
- const { startDateTime, endDateTime } = timeFilter;
35
- const params = formatPagination({ paging, defaultSortField: 'time' });
36
-
37
- if (sender && receiver) {
38
- if (direction === 'MUTUAL') {
39
- // 两人之间的所有往来
40
- query.where((x) => {
41
- if (x.sender === sender && x.receiver === receiver) {
42
- return true;
43
- }
44
- if (x.sender === receiver && x.receiver === sender) {
45
- return true;
46
- }
47
-
48
- return false;
49
- });
50
- } else if (direction === 'ONE_WAY') {
51
- // 两人之间的单向交易
52
- query.where((x) => x.sender === sender && x.receiver === receiver);
53
- } else if (direction === 'UNION') {
54
- // 查询某个人收发的交易
55
- query.where((x) => x.sender === sender || x.receiver === receiver);
56
- }
57
- } else if (sender) {
58
- // 某个人发的交易
59
- query.where((x) => x.sender === sender);
60
- } else if (receiver) {
61
- // 某个人收的交易
62
- query.where((x) => x.receiver === receiver);
63
- }
64
-
65
- if (types.length) {
66
- query.where((x) => typeFilter.types.includes(x.type));
67
- }
68
-
69
- if (startDateTime && endDateTime) {
70
- query.where((x) => x.time > startDateTime && x.time <= endDateTime);
71
- } else if (startDateTime) {
72
- query.where((x) => x.time > startDateTime);
73
- } else if (endDateTime) {
74
- query.where((x) => x.time <= endDateTime);
75
- }
76
-
77
- const result = query
78
- .simplesort(paging.order.field, paging.order.type === 'desc')
79
- .offset(params.cursor)
80
- .limit(params.size)
81
- .data();
82
- const total = query.count();
83
-
84
- result.paging = { cursor: params.cursor + result.length, next: result.length >= params.size, total };
85
- return result;
86
- }
87
-
88
- async listAssets({ ownerAddress, paging } = {}) {
89
- if (!ownerAddress) {
90
- return {};
91
- }
92
-
93
- const pagination = formatPagination({ paging, defaultSortField: 'renaissanceTime' });
94
-
95
- const condition = { owner: ownerAddress };
96
- const assets = await this.asset.collection
97
- .chain()
98
- .find(condition)
99
- .simplesort(pagination.order.field, pagination.order.type === 'desc')
100
- .offset(pagination.cursor)
101
- .limit(pagination.size)
102
- .data();
103
-
104
- const total = await this.asset.count(condition);
105
-
106
- const account = await this.account.get(ownerAddress);
107
- return {
108
- assets,
109
- account,
110
- paging: { cursor: pagination.cursor + assets.length, next: assets.length >= pagination.size, total },
111
- };
112
- }
113
-
114
- async listAssetTransactions({ address, paging } = {}) {
115
- if (!address) {
116
- return [];
117
- }
118
-
119
- const pagination = formatPagination({ paging, defaultSortField: 'time' });
120
-
121
- const queryCondition = { assets: { $contains: address } };
122
- const txs = await this.tx.collection
123
- .chain()
124
- .find(queryCondition)
125
- .simplesort(pagination.order.field, pagination.order.type === 'desc')
126
- .offset(pagination.cursor)
127
- .limit(pagination.size)
128
- .data();
129
-
130
- const total = await this.tx.collection.count(queryCondition);
131
-
132
- txs.paging = { cursor: pagination.cursor + txs.length, next: txs.length >= pagination.size, total };
133
-
134
- return txs;
135
- }
136
-
137
- listTopAccounts({ paging } = {}) {
138
- const params = formatPagination({ paging, defaultSortField: 'balance' });
139
-
140
- const accounts = this.account.collection
141
- .chain()
142
- .find()
143
- .simplesort(params.order.field, params.order.type === 'desc')
144
- .offset(params.cursor)
145
- .limit(params.size)
146
- .data();
147
-
148
- const total = this.account.count();
149
-
150
- accounts.paging = { cursor: params.cursor + accounts.length, next: accounts.length >= params.size, total };
151
- return accounts;
152
- }
153
-
154
- listBlocks() {
155
- return [];
28
+ this.attachReadyListeners();
156
29
  }
157
30
  }
158
31
 
@@ -1,10 +1,10 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- const { formatRowBeforeInsert } = require('@ocap/util/lib/transaction');
2
+ const { formatTxBeforeInsert } = require('@ocap/indexdb/lib/util');
3
3
  const Base = require('./base');
4
4
 
5
5
  class Transaction extends Base {
6
6
  _insert(row) {
7
- return super._insert(formatRowBeforeInsert(row));
7
+ return super._insert(formatTxBeforeInsert(row));
8
8
  }
9
9
  }
10
10
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ocap/indexdb-fs",
3
3
  "description": "OCAP indexdb adapter that uses file system as backend",
4
- "version": "1.6.5",
4
+ "version": "1.6.10",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
- "url": "https://github.com/ArcBlock/ocap-js/issues",
7
+ "url": "https://github.com/ArcBlock/asset-chain/issues",
8
8
  "email": "shijun@arcblock.io"
9
9
  },
10
10
  "publishConfig": {
@@ -14,9 +14,9 @@
14
14
  "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
15
15
  ],
16
16
  "devDependencies": {
17
- "jest": "^26.6.3"
17
+ "jest": "^27.3.1"
18
18
  },
19
- "homepage": "https://github.com/ArcBlock/ocap-js/tree/master/indexdb/fs",
19
+ "homepage": "https://github.com/ArcBlock/asset-chain/tree/master/indexdb/fs",
20
20
  "keywords": [
21
21
  "ocap",
22
22
  "indexdb",
@@ -29,19 +29,20 @@
29
29
  ],
30
30
  "repository": {
31
31
  "type": "git",
32
- "url": "https://github.com/ArcBlock/ocap-js/tree/master/indexdb/fs"
32
+ "url": "https://github.com/ArcBlock/asset-chain/tree/master/indexdb/fs"
33
33
  },
34
34
  "scripts": {
35
35
  "lint": "eslint tests lib",
36
36
  "lint:fix": "eslint --fix tests lib",
37
- "test": "node tools/jest.js",
37
+ "test": "jest --forceExit --detectOpenHandles",
38
38
  "coverage": "npm run test -- --coverage"
39
39
  },
40
- "gitHead": "5779448f13824de38978df3c84c9da0c1e1ad989",
40
+ "gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1",
41
41
  "dependencies": {
42
- "@ocap/indexdb": "^1.6.5",
43
- "@ocap/util": "^1.6.5",
44
- "debug": "^4.3.1",
42
+ "@ocap/indexdb": "1.6.10",
43
+ "@ocap/indexdb-memory": "1.6.10",
44
+ "@ocap/util": "1.6.10",
45
+ "debug": "^4.3.3",
45
46
  "lodash": "^4.17.21",
46
47
  "lokijs": "^1.5.11"
47
48
  }