@ocap/indexdb-memory 1.29.3 → 1.29.5
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/esm/db/base.mjs +24 -12
- package/lib/db/base.cjs +24 -12
- package/package.json +6 -6
package/esm/db/base.mjs
CHANGED
|
@@ -130,12 +130,6 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
130
130
|
paging,
|
|
131
131
|
defaultSortField: "renaissanceTime"
|
|
132
132
|
});
|
|
133
|
-
const { field = "renaissanceTime" } = timeFilter;
|
|
134
|
-
if ([
|
|
135
|
-
"genesisTime",
|
|
136
|
-
"renaissanceTime",
|
|
137
|
-
"consumedTime"
|
|
138
|
-
].includes(field) === false) throw new Error("invalid field specified in timeFilter");
|
|
139
133
|
const query = getCollection(this.asset).chain();
|
|
140
134
|
if (ownerAddress) {
|
|
141
135
|
const possibleOwners = await this.getRelatedAddresses(ownerAddress);
|
|
@@ -189,21 +183,32 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
189
183
|
paging,
|
|
190
184
|
pagination
|
|
191
185
|
});
|
|
192
|
-
query.where((x) => {
|
|
193
|
-
const
|
|
186
|
+
if (tokenAddress) query.where((x) => {
|
|
187
|
+
const tokens = x.tokens;
|
|
188
|
+
if (!tokens) return false;
|
|
189
|
+
const owned = tokens.find((t) => t.address === tokenAddress);
|
|
194
190
|
return owned ? owned.balance > "0" : false;
|
|
195
191
|
});
|
|
196
192
|
if (pagination.order.field === "balance") {
|
|
197
193
|
const descending = pagination.order.type === "desc";
|
|
198
|
-
query.sort((a, b) => {
|
|
199
|
-
const
|
|
200
|
-
const
|
|
194
|
+
if (tokenAddress) query.sort((a, b) => {
|
|
195
|
+
const tokensA = a.tokens;
|
|
196
|
+
const tokensB = b.tokens;
|
|
197
|
+
const tokenA = tokensA?.find((t) => t.address === tokenAddress);
|
|
198
|
+
const tokenB = tokensB?.find((t) => t.address === tokenAddress);
|
|
201
199
|
const balanceA = new BN(tokenA ? tokenA.balance : "0");
|
|
202
200
|
const balanceB = new BN(tokenB ? tokenB.balance : "0");
|
|
203
201
|
if (balanceB.gt(balanceA)) return descending ? 1 : -1;
|
|
204
202
|
if (balanceB.eq(balanceA)) return 0;
|
|
205
203
|
return descending ? -1 : 1;
|
|
206
204
|
});
|
|
205
|
+
else query.sort((a, b) => {
|
|
206
|
+
const balanceA = new BN(a.balance || "0");
|
|
207
|
+
const balanceB = new BN(b.balance || "0");
|
|
208
|
+
if (balanceB.gt(balanceA)) return descending ? 1 : -1;
|
|
209
|
+
if (balanceB.eq(balanceA)) return 0;
|
|
210
|
+
return descending ? -1 : 1;
|
|
211
|
+
});
|
|
207
212
|
} else query.simplesort(pagination.order.field, pagination.order.type === "desc");
|
|
208
213
|
const accounts = query.offset(pagination.cursor).limit(pagination.size).data();
|
|
209
214
|
const total = query.count();
|
|
@@ -343,7 +348,14 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
343
348
|
const query = getCollection(this.rollup).chain();
|
|
344
349
|
if (tokenAddress) query.where((x) => x.tokenAddress === tokenAddress);
|
|
345
350
|
const foreignTokenAddr = foreignTokenAddress || erc20TokenAddress;
|
|
346
|
-
if (
|
|
351
|
+
if (foreignTokenAddr) {
|
|
352
|
+
const checksumAddr = toChecksumAddress(foreignTokenAddr);
|
|
353
|
+
const lowerAddr = foreignTokenAddr.toLowerCase();
|
|
354
|
+
query.where((x) => {
|
|
355
|
+
const contractAddr = x.foreignToken?.contractAddress;
|
|
356
|
+
return contractAddr === checksumAddr || contractAddr?.toLowerCase() === lowerAddr;
|
|
357
|
+
});
|
|
358
|
+
}
|
|
347
359
|
debug("listRollups", {
|
|
348
360
|
paging,
|
|
349
361
|
pagination
|
package/lib/db/base.cjs
CHANGED
|
@@ -134,12 +134,6 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
134
134
|
paging,
|
|
135
135
|
defaultSortField: "renaissanceTime"
|
|
136
136
|
});
|
|
137
|
-
const { field = "renaissanceTime" } = timeFilter;
|
|
138
|
-
if ([
|
|
139
|
-
"genesisTime",
|
|
140
|
-
"renaissanceTime",
|
|
141
|
-
"consumedTime"
|
|
142
|
-
].includes(field) === false) throw new Error("invalid field specified in timeFilter");
|
|
143
137
|
const query = getCollection(this.asset).chain();
|
|
144
138
|
if (ownerAddress) {
|
|
145
139
|
const possibleOwners = await this.getRelatedAddresses(ownerAddress);
|
|
@@ -193,21 +187,32 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
193
187
|
paging,
|
|
194
188
|
pagination
|
|
195
189
|
});
|
|
196
|
-
query.where((x) => {
|
|
197
|
-
const
|
|
190
|
+
if (tokenAddress) query.where((x) => {
|
|
191
|
+
const tokens = x.tokens;
|
|
192
|
+
if (!tokens) return false;
|
|
193
|
+
const owned = tokens.find((t) => t.address === tokenAddress);
|
|
198
194
|
return owned ? owned.balance > "0" : false;
|
|
199
195
|
});
|
|
200
196
|
if (pagination.order.field === "balance") {
|
|
201
197
|
const descending = pagination.order.type === "desc";
|
|
202
|
-
query.sort((a, b) => {
|
|
203
|
-
const
|
|
204
|
-
const
|
|
198
|
+
if (tokenAddress) query.sort((a, b) => {
|
|
199
|
+
const tokensA = a.tokens;
|
|
200
|
+
const tokensB = b.tokens;
|
|
201
|
+
const tokenA = tokensA?.find((t) => t.address === tokenAddress);
|
|
202
|
+
const tokenB = tokensB?.find((t) => t.address === tokenAddress);
|
|
205
203
|
const balanceA = new _ocap_util.BN(tokenA ? tokenA.balance : "0");
|
|
206
204
|
const balanceB = new _ocap_util.BN(tokenB ? tokenB.balance : "0");
|
|
207
205
|
if (balanceB.gt(balanceA)) return descending ? 1 : -1;
|
|
208
206
|
if (balanceB.eq(balanceA)) return 0;
|
|
209
207
|
return descending ? -1 : 1;
|
|
210
208
|
});
|
|
209
|
+
else query.sort((a, b) => {
|
|
210
|
+
const balanceA = new _ocap_util.BN(a.balance || "0");
|
|
211
|
+
const balanceB = new _ocap_util.BN(b.balance || "0");
|
|
212
|
+
if (balanceB.gt(balanceA)) return descending ? 1 : -1;
|
|
213
|
+
if (balanceB.eq(balanceA)) return 0;
|
|
214
|
+
return descending ? -1 : 1;
|
|
215
|
+
});
|
|
211
216
|
} else query.simplesort(pagination.order.field, pagination.order.type === "desc");
|
|
212
217
|
const accounts = query.offset(pagination.cursor).limit(pagination.size).data();
|
|
213
218
|
const total = query.count();
|
|
@@ -347,7 +352,14 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
347
352
|
const query = getCollection(this.rollup).chain();
|
|
348
353
|
if (tokenAddress) query.where((x) => x.tokenAddress === tokenAddress);
|
|
349
354
|
const foreignTokenAddr = foreignTokenAddress || erc20TokenAddress;
|
|
350
|
-
if (
|
|
355
|
+
if (foreignTokenAddr) {
|
|
356
|
+
const checksumAddr = (0, _arcblock_did_lib_type.toChecksumAddress)(foreignTokenAddr);
|
|
357
|
+
const lowerAddr = foreignTokenAddr.toLowerCase();
|
|
358
|
+
query.where((x) => {
|
|
359
|
+
const contractAddr = x.foreignToken?.contractAddress;
|
|
360
|
+
return contractAddr === checksumAddr || contractAddr?.toLowerCase() === lowerAddr;
|
|
361
|
+
});
|
|
362
|
+
}
|
|
351
363
|
debug$1("listRollups", {
|
|
352
364
|
paging,
|
|
353
365
|
pagination
|
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.29.
|
|
4
|
+
"version": "1.29.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
7
7
|
"bugs": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@ocap/indexdb-test": "1.29.
|
|
18
|
+
"@ocap/indexdb-test": "1.29.5",
|
|
19
19
|
"@types/debug": "^4.1.12",
|
|
20
20
|
"@types/lodash": "^4.17.10",
|
|
21
21
|
"@types/lokijs": "^1.5.14",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
},
|
|
79
79
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@arcblock/did": "1.29.
|
|
82
|
-
"@ocap/indexdb": "1.29.
|
|
83
|
-
"@ocap/types": "1.29.
|
|
84
|
-
"@ocap/util": "1.29.
|
|
81
|
+
"@arcblock/did": "1.29.5",
|
|
82
|
+
"@ocap/indexdb": "1.29.5",
|
|
83
|
+
"@ocap/types": "1.29.5",
|
|
84
|
+
"@ocap/util": "1.29.5",
|
|
85
85
|
"debug": "^4.4.3",
|
|
86
86
|
"lodash": "^4.17.23",
|
|
87
87
|
"lokijs": "^1.5.12"
|