@ocap/indexdb-elasticsearch 1.18.68 → 1.18.69

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.
Files changed (2) hide show
  1. package/lib/db.js +27 -1
  2. package/package.json +5 -5
package/lib/db.js CHANGED
@@ -28,6 +28,13 @@ const REQUEST_TIMEOUT = 8000;
28
28
  const MAX_REQUEST_FACTORY_ADDRESS_SIZE = 100;
29
29
  const TRACK_TOTAL_HITS = +process.env.TRACK_TOTAL_HITS || 10000;
30
30
 
31
+ const getMigratedFrom = (account) => {
32
+ if (account.migratedFrom) {
33
+ return Array.isArray(account.migratedFrom) ? account.migratedFrom[0] : account.migratedFrom;
34
+ }
35
+ return '';
36
+ };
37
+
31
38
  class ESIndexDB extends BaseIndexDB {
32
39
  /**
33
40
  * Creates an instance of ESIndexDB.
@@ -211,10 +218,29 @@ class ESIndexDB extends BaseIndexDB {
211
218
  return { transactions: items.map((item) => formatTxAfterRead(item)), paging: nextPaging };
212
219
  }
213
220
 
221
+ async getRelatedAddresses(address) {
222
+ let account = await this.account.get(address);
223
+ if (!account) {
224
+ return [];
225
+ }
226
+
227
+ const related = [address];
228
+ while (account && getMigratedFrom(account) && related.length <= 8) {
229
+ related.push(getMigratedFrom(account));
230
+ // eslint-disable-next-line no-await-in-loop
231
+ account = await this.account.get(getMigratedFrom(account));
232
+ }
233
+
234
+ return related;
235
+ }
236
+
214
237
  async listAssets({ ownerAddress, factoryAddress, paging, timeFilter = {} } = {}) {
215
238
  const conditions = [];
216
239
  if (ownerAddress) {
217
- conditions.push({ term: { owner: ownerAddress } });
240
+ const possibleOwners = await this.getRelatedAddresses(ownerAddress);
241
+ if (possibleOwners.length) {
242
+ conditions.push({ terms: { owner: possibleOwners } });
243
+ }
218
244
  }
219
245
  if (factoryAddress) {
220
246
  conditions.push({ term: { parent: factoryAddress } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocap/indexdb-elasticsearch",
3
3
  "description": "OCAP indexdb adapter that uses elasticsearch as backend",
4
- "version": "1.18.68",
4
+ "version": "1.18.69",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ArcBlock/asset-chain/issues",
@@ -38,12 +38,12 @@
38
38
  "test": "jest --forceExit --detectOpenHandles",
39
39
  "coverage": "npm run test -- --coverage"
40
40
  },
41
- "gitHead": "85b001bdb1e3711aae31009ae7c506ff984419ed",
41
+ "gitHead": "464d72d0a7107cb6f81afa78b74361018ecdc2e4",
42
42
  "dependencies": {
43
- "@arcblock/did": "1.18.68",
43
+ "@arcblock/did": "1.18.69",
44
44
  "@elastic/elasticsearch": "7.13.0",
45
- "@ocap/indexdb": "1.18.68",
46
- "@ocap/util": "1.18.68",
45
+ "@ocap/indexdb": "1.18.69",
46
+ "@ocap/util": "1.18.69",
47
47
  "axios": "^0.27.2",
48
48
  "bn.js": "^5.2.1",
49
49
  "debug": "^4.3.4",