@ocap/indexdb-memory 1.18.92 → 1.18.93

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/base.js +51 -1
  2. package/package.json +5 -5
package/lib/db/base.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable newline-per-chained-call */
2
2
  const { BN } = require('@ocap/util');
3
3
  const { BaseIndexDB } = require('@ocap/indexdb');
4
- const { formatPagination, formatNextPagination } = require('@ocap/indexdb/lib/util');
4
+ const { formatPagination, formatNextPagination, formatDelegationAfterRead } = require('@ocap/indexdb/lib/util');
5
5
  const { parseDateTime } = require('@ocap/indexdb/lib/util');
6
6
  const { DEFAULT_TOKEN_DECIMAL } = require('@ocap/util/lib/constant');
7
7
  const { toChecksumAddress } = require('@arcblock/did/lib/type');
@@ -499,6 +499,56 @@ class LocalBaseIndexDB extends BaseIndexDB {
499
499
 
500
500
  return { validators, paging: nextPaging };
501
501
  }
502
+
503
+ listDelegations({ from, to, paging = {}, timeFilter = {} } = {}) {
504
+ if (!from && !to) {
505
+ return { delegations: [], paging: { cursor: 0, next: false, total: 0 } };
506
+ }
507
+
508
+ const query = this.delegation.collection.chain();
509
+
510
+ let { startDateTime, endDateTime, field } = timeFilter;
511
+ startDateTime = parseDateTime(startDateTime);
512
+ endDateTime = parseDateTime(endDateTime);
513
+ field = ['genesisTime', 'renaissanceTime'].includes(field) ? field : 'renaissanceTime';
514
+
515
+ const pagination = formatPagination({
516
+ paging,
517
+ defaultSortField: 'renaissanceTime',
518
+ supportedSortFields: ['genesisTime', 'renaissanceTime'],
519
+ });
520
+
521
+ if (from && to) {
522
+ query.where((x) => x.from === from && x.to === to);
523
+ } else if (from) {
524
+ query.where((x) => x.from === from);
525
+ } else if (to) {
526
+ query.where((x) => x.to === to);
527
+ }
528
+
529
+ if (startDateTime && endDateTime) {
530
+ query.where((x) => x[field] > startDateTime && x[field] <= endDateTime);
531
+ } else if (startDateTime) {
532
+ query.where((x) => x[field] > startDateTime);
533
+ } else if (endDateTime) {
534
+ query.where((x) => x[field] <= endDateTime);
535
+ }
536
+
537
+ const delegations = query
538
+ .simplesort(pagination.order.field, paging.order.type === 'desc')
539
+ .offset(pagination.cursor)
540
+ .limit(pagination.size)
541
+ .data();
542
+
543
+ const total = query.count();
544
+ const nextPaging = {
545
+ cursor: pagination.cursor + delegations.length,
546
+ next: delegations.length >= pagination.size,
547
+ total,
548
+ };
549
+
550
+ return { delegations: delegations.map(formatDelegationAfterRead), paging: nextPaging };
551
+ }
502
552
  }
503
553
 
504
554
  module.exports = LocalBaseIndexDB;
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.18.92",
4
+ "version": "1.18.93",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ArcBlock/asset-chain/issues",
@@ -37,11 +37,11 @@
37
37
  "test": "jest --forceExit --detectOpenHandles",
38
38
  "coverage": "npm run test -- --coverage"
39
39
  },
40
- "gitHead": "166a276e6865f140e5eed88aced8a4ad39186a74",
40
+ "gitHead": "de8cc73243a1d3d27c9ecc6af6a7892a3e0c683a",
41
41
  "dependencies": {
42
- "@arcblock/did": "1.18.92",
43
- "@ocap/indexdb": "1.18.92",
44
- "@ocap/util": "1.18.92",
42
+ "@arcblock/did": "1.18.93",
43
+ "@ocap/indexdb": "1.18.93",
44
+ "@ocap/util": "1.18.93",
45
45
  "debug": "^4.3.4",
46
46
  "empty-value": "^1.0.1",
47
47
  "lodash": "^4.17.21",