@requestnetwork/data-access 0.23.0 → 0.23.1-next.709
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 +0 -4
- package/dist/block.d.ts +4 -4
- package/dist/block.d.ts.map +1 -1
- package/dist/block.js +9 -9
- package/dist/block.js.map +1 -1
- package/dist/combined-data-access.d.ts +13 -0
- package/dist/combined-data-access.d.ts.map +1 -0
- package/dist/combined-data-access.js +44 -0
- package/dist/combined-data-access.js.map +1 -0
- package/dist/data-read.d.ts +17 -0
- package/dist/data-read.d.ts.map +1 -0
- package/dist/data-read.js +158 -0
- package/dist/data-read.js.map +1 -0
- package/dist/data-write.d.ts +10 -0
- package/dist/data-write.d.ts.map +1 -0
- package/dist/data-write.js +48 -0
- package/dist/data-write.js.map +1 -0
- package/dist/in-memory-indexer.d.ts +18 -0
- package/dist/in-memory-indexer.d.ts.map +1 -0
- package/dist/in-memory-indexer.js +110 -0
- package/dist/in-memory-indexer.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/mock-data-access.d.ts +13 -0
- package/dist/mock-data-access.d.ts.map +1 -0
- package/dist/mock-data-access.js +29 -0
- package/dist/mock-data-access.js.map +1 -0
- package/dist/pending-store.d.ts +16 -0
- package/dist/pending-store.d.ts.map +1 -0
- package/dist/pending-store.js +33 -0
- package/dist/pending-store.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +18 -29
- package/CHANGELOG.md +0 -1466
- package/dist/data-access.d.ts +0 -140
- package/dist/data-access.d.ts.map +0 -1
- package/dist/data-access.js +0 -425
- package/dist/data-access.js.map +0 -1
- package/dist/ignored-location.d.ts +0 -58
- package/dist/ignored-location.d.ts.map +0 -1
- package/dist/ignored-location.js +0 -104
- package/dist/ignored-location.js.map +0 -1
- package/dist/interval-timer.d.ts +0 -36
- package/dist/interval-timer.d.ts.map +0 -1
- package/dist/interval-timer.js +0 -90
- package/dist/interval-timer.js.map +0 -1
- package/dist/transaction-index/index.d.ts +0 -5
- package/dist/transaction-index/index.d.ts.map +0 -1
- package/dist/transaction-index/index.js +0 -17
- package/dist/transaction-index/index.js.map +0 -1
- package/dist/transaction-index/location-by-topic.d.ts +0 -53
- package/dist/transaction-index/location-by-topic.d.ts.map +0 -1
- package/dist/transaction-index/location-by-topic.js +0 -111
- package/dist/transaction-index/location-by-topic.js.map +0 -1
- package/dist/transaction-index/timestamp-by-location.d.ts +0 -60
- package/dist/transaction-index/timestamp-by-location.d.ts.map +0 -1
- package/dist/transaction-index/timestamp-by-location.js +0 -116
- package/dist/transaction-index/timestamp-by-location.js.map +0 -1
- package/dist/transaction-index/transaction-index.d.ts +0 -74
- package/dist/transaction-index/transaction-index.d.ts.map +0 -1
- package/dist/transaction-index/transaction-index.js +0 -212
- package/dist/transaction-index/transaction-index.js.map +0 -1
package/dist/ignored-location.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const Keyv = require("keyv");
|
|
13
|
-
/**
|
|
14
|
-
* Class used to store the block's reason indexed by location of blocks
|
|
15
|
-
*/
|
|
16
|
-
class ReasonsByIgnoredLocationIndex {
|
|
17
|
-
/**
|
|
18
|
-
* reasonByLocationTransactionIndex constructor
|
|
19
|
-
* @param store a Keyv store to persist the index to
|
|
20
|
-
*/
|
|
21
|
-
constructor(store) {
|
|
22
|
-
this.reasonsByIgnoredLocation = new Keyv({
|
|
23
|
-
namespace: 'reasonsByIgnoredLocation',
|
|
24
|
-
store,
|
|
25
|
-
});
|
|
26
|
-
this.listIgnoredLocation = new Keyv({
|
|
27
|
-
namespace: 'listIgnoredLocation',
|
|
28
|
-
store,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Function to push reason indexed by location
|
|
33
|
-
*
|
|
34
|
-
* @param dataId dataId of the block
|
|
35
|
-
* @param reason reason to be ignored
|
|
36
|
-
*/
|
|
37
|
-
pushReasonByLocation(dataId, reason) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if (!(yield this.reasonsByIgnoredLocation.get(dataId))) {
|
|
40
|
-
yield this.reasonsByIgnoredLocation.set(dataId, reason);
|
|
41
|
-
yield this.updateDataId(dataId);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Function to update reason indexed by location
|
|
47
|
-
*
|
|
48
|
-
* @param dataId dataId of the block
|
|
49
|
-
* @param reason reason to be ignored
|
|
50
|
-
*/
|
|
51
|
-
removeReasonByLocation(dataId) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
yield this.reasonsByIgnoredLocation.delete(dataId);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Function to get reason from location
|
|
58
|
-
*
|
|
59
|
-
* @param dataId location to get the reason from
|
|
60
|
-
* @returns reason of the location, null if not found
|
|
61
|
-
*/
|
|
62
|
-
getReasonFromLocation(dataId) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const reason = yield this.reasonsByIgnoredLocation.get(dataId);
|
|
65
|
-
return reason ? reason : null;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get the list of data ids stored
|
|
70
|
-
*
|
|
71
|
-
* @returns the list of data ids stored
|
|
72
|
-
*/
|
|
73
|
-
getIgnoredLocations() {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
const listDataId = yield this.listIgnoredLocation.get('list');
|
|
76
|
-
if (!listDataId) {
|
|
77
|
-
return {};
|
|
78
|
-
}
|
|
79
|
-
const result = {};
|
|
80
|
-
for (const dataId of Array.from(listDataId)) {
|
|
81
|
-
result[dataId] = yield this.reasonsByIgnoredLocation.get(dataId);
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Update the list of data ids stored
|
|
88
|
-
*
|
|
89
|
-
* @param dataId data id to add to the list
|
|
90
|
-
* @returns
|
|
91
|
-
*/
|
|
92
|
-
updateDataId(dataId) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
let listDataIds = yield this.listIgnoredLocation.get('list');
|
|
95
|
-
if (!listDataIds) {
|
|
96
|
-
listDataIds = [];
|
|
97
|
-
}
|
|
98
|
-
listDataIds.push(dataId);
|
|
99
|
-
yield this.listIgnoredLocation.set('list', listDataIds);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.default = ReasonsByIgnoredLocationIndex;
|
|
104
|
-
//# sourceMappingURL=ignored-location.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ignored-location.js","sourceRoot":"","sources":["../src/ignored-location.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA6B;AAQ7B;;GAEG;AACH,MAAqB,6BAA6B;IAShD;;;OAGG;IACH,YAAmB,KAAuB;QACxC,IAAI,CAAC,wB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MAAM,CAAC,CAAC;aAClE;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAED;;;;;OAKG;IACW,YAAY,CAAC,MAAc;;YACvC,IAAI,WAAW,GAAyB,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACnF,IAAI,CAAC,WAAW,EAAE;gBAChB,WAAW,GAAG,EAAE,CAAC;aAClB;YACD,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,CAAC;KAAA;CACF;AA5FD,gDA4FC"}
|
package/dist/interval-timer.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { LogTypes } from '@requestnetwork/types';
|
|
2
|
-
/**
|
|
3
|
-
* Module to start and stop a periodical function
|
|
4
|
-
*/
|
|
5
|
-
export default class IntervalTimer {
|
|
6
|
-
intervalFunctionSuccessiveFailureCount: number;
|
|
7
|
-
private intervalFunction;
|
|
8
|
-
private intervalTime;
|
|
9
|
-
private timeoutObject;
|
|
10
|
-
private logger;
|
|
11
|
-
private successiveFailureThreshold;
|
|
12
|
-
/**
|
|
13
|
-
* Constructor IntervalTimer
|
|
14
|
-
*
|
|
15
|
-
* @param intervalFunction function to call periodically when timer is started
|
|
16
|
-
* @param intervalTime Interval time between interval function call
|
|
17
|
-
* @param logger Logger instance
|
|
18
|
-
* @param successiveFailureThreshold Required number of successive failure from interval function before logging an error
|
|
19
|
-
*/
|
|
20
|
-
constructor(intervalFunction: () => Promise<void>, intervalTime: number, logger: LogTypes.ILogger, successiveFailureThreshold?: number);
|
|
21
|
-
/**
|
|
22
|
-
* Start the interval timer
|
|
23
|
-
*/
|
|
24
|
-
start(): any;
|
|
25
|
-
/**
|
|
26
|
-
* Stop the interval timer
|
|
27
|
-
*/
|
|
28
|
-
stop(): any;
|
|
29
|
-
/**
|
|
30
|
-
* Gets current configuration
|
|
31
|
-
*
|
|
32
|
-
* @return the current configuration attributes
|
|
33
|
-
*/
|
|
34
|
-
getConfig(): any;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=interval-timer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interval-timer.d.ts","sourceRoot":"","sources":["../src/interval-timer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAGzB,sCAAsC,EAAE,MAAM,CAAK;IAE1D,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,0BAA0B,CAAS;IAE3C;;;;;;;OAOG;gBAED,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACrC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,QAAQ,CAAC,OAAO,EACxB,0BAA0B,GAAE,MAAU;IAQxC;;OAEG;IACI,KAAK,IAAI,GAAG;IAyCnB;;OAEG;IACI,IAAI,IAAI,GAAG;IASlB;;;;OAIG;IACI,SAAS,IAAI,GAAG;CAMxB"}
|
package/dist/interval-timer.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
/**
|
|
13
|
-
* Module to start and stop a periodical function
|
|
14
|
-
*/
|
|
15
|
-
class IntervalTimer {
|
|
16
|
-
/**
|
|
17
|
-
* Constructor IntervalTimer
|
|
18
|
-
*
|
|
19
|
-
* @param intervalFunction function to call periodically when timer is started
|
|
20
|
-
* @param intervalTime Interval time between interval function call
|
|
21
|
-
* @param logger Logger instance
|
|
22
|
-
* @param successiveFailureThreshold Required number of successive failure from interval function before logging an error
|
|
23
|
-
*/
|
|
24
|
-
constructor(intervalFunction, intervalTime, logger, successiveFailureThreshold = 1) {
|
|
25
|
-
// Count the successive number of failure from the interval function
|
|
26
|
-
// This value is used as we may not want to directly log an error if the interval function fails once
|
|
27
|
-
this.intervalFunctionSuccessiveFailureCount = 0;
|
|
28
|
-
this.timeoutObject = null;
|
|
29
|
-
this.intervalFunction = intervalFunction;
|
|
30
|
-
this.intervalTime = intervalTime;
|
|
31
|
-
this.logger = logger;
|
|
32
|
-
this.successiveFailureThreshold = successiveFailureThreshold;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Start the interval timer
|
|
36
|
-
*/
|
|
37
|
-
start() {
|
|
38
|
-
// Timer can't be restarted
|
|
39
|
-
if (this.timeoutObject) {
|
|
40
|
-
throw Error('IntervalTimer already started');
|
|
41
|
-
}
|
|
42
|
-
// Function to be called periodically
|
|
43
|
-
// This function calls and waits for the intervalFunction and sets a timeout
|
|
44
|
-
// to call itself recursively
|
|
45
|
-
const recursiveTimeoutFunction = () => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
try {
|
|
47
|
-
// We wait for the internal function to reset the timeout
|
|
48
|
-
yield this.intervalFunction();
|
|
49
|
-
// Reset intervalFunctionSuccessiveFailureCount
|
|
50
|
-
this.intervalFunctionSuccessiveFailureCount = 0;
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
// An error in the interval function should not stop the interval timer
|
|
54
|
-
// An isolated error from the interval function is considered as a warning
|
|
55
|
-
this.logger.warn(`${this.intervalFunction.name || 'intervalFunction'} error: ${e}`);
|
|
56
|
-
this.intervalFunctionSuccessiveFailureCount++;
|
|
57
|
-
// If the interval function failed several times in a row, it can be caused by a bigger problem therefore we display an error
|
|
58
|
-
if (this.intervalFunctionSuccessiveFailureCount >= this.successiveFailureThreshold) {
|
|
59
|
-
this.logger.error(`${this.intervalFunction.name || 'intervalFunction'} failed ${this.intervalFunctionSuccessiveFailureCount} times in a row, last error: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
this.timeoutObject = setTimeout(recursiveTimeoutFunction, this.intervalTime);
|
|
63
|
-
});
|
|
64
|
-
// First call to the recursive timeout function
|
|
65
|
-
this.timeoutObject = setTimeout(recursiveTimeoutFunction, this.intervalTime);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Stop the interval timer
|
|
69
|
-
*/
|
|
70
|
-
stop() {
|
|
71
|
-
if (!this.timeoutObject) {
|
|
72
|
-
throw Error(`Can't stop IntervalTimer if it has not been started`);
|
|
73
|
-
}
|
|
74
|
-
clearTimeout(this.timeoutObject);
|
|
75
|
-
this.timeoutObject = null;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets current configuration
|
|
79
|
-
*
|
|
80
|
-
* @return the current configuration attributes
|
|
81
|
-
*/
|
|
82
|
-
getConfig() {
|
|
83
|
-
return {
|
|
84
|
-
intervalTime: this.intervalTime,
|
|
85
|
-
successiveFailureThreshold: this.successiveFailureThreshold,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.default = IntervalTimer;
|
|
90
|
-
//# sourceMappingURL=interval-timer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interval-timer.js","sourceRoot":"","sources":["../src/interval-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AC,EAAE,CACpC,CAAC;iBACH;aACF;YAED,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,wBAAwB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/E,CAAC,CAAA,CAAC;QAEF,+CAA+C;QAC/C,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,wBAAwB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC/E,CAAC;IAED;;OAEG;IACI,IAAI;QACT,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,KAAK,CAAC,qDAAqD,CAAC,CAAC;SACpE;QAED,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO;YACL,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,0BAA0B,EAAE,IAAI,CAAC,0BAA0B;SAC5D,CAAC;IACJ,CAAC;CACF;AAlGD,gCAkGC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transaction-index/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AAEnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AAExC,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const transaction_index_1 = require("./transaction-index");
|
|
14
|
-
__exportStar(require("./location-by-topic"), exports);
|
|
15
|
-
__exportStar(require("./timestamp-by-location"), exports);
|
|
16
|
-
exports.default = transaction_index_1.default;
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transaction-index/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAmD;AAEnD,sDAAoC;AACpC,0DAAwC;AAExC,kBAAe,2BAAgB,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { DataAccessTypes } from '@requestnetwork/types';
|
|
2
|
-
import * as Keyv from 'keyv';
|
|
3
|
-
/**
|
|
4
|
-
* Helps store and retrieve channelIds by topic, and transaction location per channelId
|
|
5
|
-
*/
|
|
6
|
-
export default class LocationByTopicTransactionIndex {
|
|
7
|
-
/**
|
|
8
|
-
* Storage location by channel id
|
|
9
|
-
* maps channelId => [storageLocation]
|
|
10
|
-
* This attribute is public for mocking purpose
|
|
11
|
-
*/
|
|
12
|
-
storageLocationByChannelId: Keyv<Set<string>>;
|
|
13
|
-
/**
|
|
14
|
-
* Channel Ids by topic
|
|
15
|
-
* maps topic => [channelId]
|
|
16
|
-
* This attribute is public for mocking purpose
|
|
17
|
-
*/
|
|
18
|
-
channelIdByTopics: Keyv<Set<string>>;
|
|
19
|
-
/**
|
|
20
|
-
* Constructor for LocationByTopicIndex
|
|
21
|
-
* @param store a Keyv store to persist the index to.
|
|
22
|
-
*/
|
|
23
|
-
constructor(store?: Keyv.Store<any>);
|
|
24
|
-
/**
|
|
25
|
-
* Function to push location indexed with block topics
|
|
26
|
-
*
|
|
27
|
-
* @param storageLocation storage location to index
|
|
28
|
-
* @param blockHeader header of the block
|
|
29
|
-
*/
|
|
30
|
-
pushStorageLocationIndexedWithBlockTopics(storageLocation: string, blockHeader: DataAccessTypes.IBlockHeader): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Function to get the channel ids from a topic
|
|
33
|
-
*
|
|
34
|
-
* @param topic topic to retrieve the dataId
|
|
35
|
-
* @returns list of the channel ids connected to the topic
|
|
36
|
-
*/
|
|
37
|
-
getChannelIdsFromTopic(topic: string): Promise<string[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Function to get the channel ids from multiple topics
|
|
40
|
-
*
|
|
41
|
-
* @param topics topics to retrieve the dataIds
|
|
42
|
-
* @returns list of the channel ids linked to the topics
|
|
43
|
-
*/
|
|
44
|
-
getChannelIdsFromMultipleTopics(topics: string[]): Promise<string[]>;
|
|
45
|
-
/**
|
|
46
|
-
* Function to get storage locations from a channel id
|
|
47
|
-
*
|
|
48
|
-
* @param channelId channel id to retrieve the storage location
|
|
49
|
-
* @returns list of the location connected to the channel id
|
|
50
|
-
*/
|
|
51
|
-
getStorageLocationsFromChannelId(channelId: string): Promise<string[]>;
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=location-by-topic.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"location-by-topic.d.ts","sourceRoot":"","sources":["../../src/transaction-index/location-by-topic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAiB7B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,+BAA+B;IAClD;;;;OAIG;IACI,0BAA0B,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAErD;;;;OAIG;IACI,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5C;;;OAGG;gBACS,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAenC;;;;;OAKG;IACU,yCAAyC,CACpD,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,eAAe,CAAC,YAAY,GACxC,OAAO,CAAC,IAAI,CAAC;IAkBhB;;;;;OAKG;IACU,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIrE;;;;;OAKG;IACU,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IASjF;;;;;OAKG;IACU,gCAAgC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAGpF"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const utils_1 = require("@requestnetwork/utils");
|
|
13
|
-
const Keyv = require("keyv");
|
|
14
|
-
// Serialize function used for keyv to serialize a Set data structure into a string
|
|
15
|
-
// There is no way to directly stringify a Set, we need to convert it to an array before
|
|
16
|
-
// Typescript error from keyv: deserialized's type should be { value: Set<string>, expires: number }
|
|
17
|
-
// but it's inferred as a Set<string>
|
|
18
|
-
const serializeSet = (deserialized) => JSON.stringify(Array.from(deserialized.value));
|
|
19
|
-
// Deserialize function used for keyv to deserialize a string into a Set data structure
|
|
20
|
-
// Typescript error from keyv: function return's type should be { value: Set<string>, expires: number }
|
|
21
|
-
// but it's inferred as a Set<string>
|
|
22
|
-
const deserializeSet = (serialized) => {
|
|
23
|
-
// We use JSON.parse to convert the string into an array before converting it to a Set
|
|
24
|
-
const set = new Set(JSON.parse(serialized));
|
|
25
|
-
return { value: set };
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Helps store and retrieve channelIds by topic, and transaction location per channelId
|
|
29
|
-
*/
|
|
30
|
-
class LocationByTopicTransactionIndex {
|
|
31
|
-
/**
|
|
32
|
-
* Constructor for LocationByTopicIndex
|
|
33
|
-
* @param store a Keyv store to persist the index to.
|
|
34
|
-
*/
|
|
35
|
-
constructor(store) {
|
|
36
|
-
this.storageLocationByChannelId = new Keyv({
|
|
37
|
-
deserialize: deserializeSet,
|
|
38
|
-
namespace: 'storageLocationByChannelId',
|
|
39
|
-
serialize: serializeSet,
|
|
40
|
-
store,
|
|
41
|
-
});
|
|
42
|
-
this.channelIdByTopics = new Keyv({
|
|
43
|
-
deserialize: deserializeSet,
|
|
44
|
-
namespace: 'channelIdByTopics',
|
|
45
|
-
serialize: serializeSet,
|
|
46
|
-
store,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Function to push location indexed with block topics
|
|
51
|
-
*
|
|
52
|
-
* @param storageLocation storage location to index
|
|
53
|
-
* @param blockHeader header of the block
|
|
54
|
-
*/
|
|
55
|
-
pushStorageLocationIndexedWithBlockTopics(storageLocation, blockHeader) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
// index the new block with the channel ids
|
|
58
|
-
for (const id of Object.keys(blockHeader.channelIds)) {
|
|
59
|
-
const existingLocationIds = (yield this.storageLocationByChannelId.get(id)) || new Set([]);
|
|
60
|
-
yield this.storageLocationByChannelId.set(id, existingLocationIds.add(storageLocation));
|
|
61
|
-
}
|
|
62
|
-
// index channel ids by the topics
|
|
63
|
-
for (const id of Object.keys(blockHeader.topics)) {
|
|
64
|
-
for (const topic of blockHeader.topics[id]) {
|
|
65
|
-
const existingChannelIds = (yield this.channelIdByTopics.get(topic)) || new Set([]);
|
|
66
|
-
yield this.channelIdByTopics.set(topic, existingChannelIds.add(id));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Function to get the channel ids from a topic
|
|
73
|
-
*
|
|
74
|
-
* @param topic topic to retrieve the dataId
|
|
75
|
-
* @returns list of the channel ids connected to the topic
|
|
76
|
-
*/
|
|
77
|
-
getChannelIdsFromTopic(topic) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
return Array.from((yield this.channelIdByTopics.get(topic)) || []);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Function to get the channel ids from multiple topics
|
|
84
|
-
*
|
|
85
|
-
* @param topics topics to retrieve the dataIds
|
|
86
|
-
* @returns list of the channel ids linked to the topics
|
|
87
|
-
*/
|
|
88
|
-
getChannelIdsFromMultipleTopics(topics) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const channelIdsPromises = topics.map((topic) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
return Array.from((yield this.channelIdByTopics.get(topic)) || []);
|
|
92
|
-
}));
|
|
93
|
-
const channelIds = yield Promise.all(channelIdsPromises);
|
|
94
|
-
// flatten the array of array and remove the duplicates
|
|
95
|
-
return utils_1.default.unique(utils_1.default.flatten2DimensionsArray(channelIds)).uniqueItems;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Function to get storage locations from a channel id
|
|
100
|
-
*
|
|
101
|
-
* @param channelId channel id to retrieve the storage location
|
|
102
|
-
* @returns list of the location connected to the channel id
|
|
103
|
-
*/
|
|
104
|
-
getStorageLocationsFromChannelId(channelId) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
return Array.from((yield this.storageLocationByChannelId.get(channelId)) || []);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.default = LocationByTopicTransactionIndex;
|
|
111
|
-
//# sourceMappingURL=location-by-topic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"location-by-topic.js","sourceRoot":"","sources":["../../src/transaction-index/location-by-topic.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,iDAA0C;AAE1C,6BAA6B;AAE7B,mFAAmF;AACnF,wFAAwF;AACxF,oGAAoG;AACpG,qCAAqC;AACrC,MAAM,YAAY,GAAG,CAAC,YAAiB,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnG,uFAAuF;AACvF,uGAAuG;AACvG,qCAAqC;AACrC,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAO,EAAE;IACjD,sFAAsF;IACtF,MAAM,GAAG,GAAgB,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACzD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF;;GAEG;AACH,MAAqB,+BAA+B;IAelD;;;OAGG;IACH,YAAY,KAAuB;QACjC,IAAI,CAAC,0BAA0B,GAAG,IAAI,IAAI,CAAc;YACtD,WAAW,EAAE,cAAc;YAC3B,SAAS,EAAE,4BAA4B;YACvC,SAAS,EAAE,YAAY;YACvB,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,IAAI,IAAI,CAAc;YAC7C,WAAW,EAAE,cAAc;YAC3B,SAAS,EAAE,mBAAmB;YAC9B,SAAS,EAAE,YAAY;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACU,yCA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GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACrE,CAAC,CAAA,CAAC,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAEzD,uDAAuD;YACvD,OAAO,eAAK,CAAC,MAAM,CAAC,eAAK,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;QAC7E,CAAC;KAAA;IACD;;;;;OAKG;IACU,gCAAgC,CAAC,SAAiB;;YAC7D,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAClF,CAAC;KAAA;CACF;AA/FD,kDA+FC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { DataAccessTypes } from '@requestnetwork/types';
|
|
2
|
-
import * as Keyv from 'keyv';
|
|
3
|
-
/**
|
|
4
|
-
* Class used to store the block's timestamp indexed by location
|
|
5
|
-
*/
|
|
6
|
-
export default class TimestampByLocationTransactionIndex {
|
|
7
|
-
/**
|
|
8
|
-
* timestamp by location
|
|
9
|
-
* maps dataId => timestamp
|
|
10
|
-
*/
|
|
11
|
-
private timestampByLocation;
|
|
12
|
-
/**
|
|
13
|
-
* TimestampByLocationTransactionIndex constructor
|
|
14
|
-
* @param store a Keyv store to persist the index to
|
|
15
|
-
*/
|
|
16
|
-
constructor(store?: Keyv.Store<any>);
|
|
17
|
-
/**
|
|
18
|
-
* Function to push timestamp indexed by location
|
|
19
|
-
*
|
|
20
|
-
* @param dataId dataId of the block
|
|
21
|
-
* @param timestamp timestamp of the block
|
|
22
|
-
*/
|
|
23
|
-
pushTimestampByLocation(dataId: string, timestamp: number): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Removes timestamp indexed by location
|
|
26
|
-
*
|
|
27
|
-
* @param dataId dataId of the block
|
|
28
|
-
*/
|
|
29
|
-
removeIndexedDataId(dataId: string): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Function to update timestamp indexed by location
|
|
32
|
-
*
|
|
33
|
-
* @param dataId dataId of the block
|
|
34
|
-
* @param timestamp timestamp of the block
|
|
35
|
-
*/
|
|
36
|
-
updateTimestampByLocation(dataId: string, timestamp: number): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Function to get timestamp from location
|
|
39
|
-
*
|
|
40
|
-
* @param dataId location to get the timestamp from
|
|
41
|
-
* @returns timestamp of the location, null if not found
|
|
42
|
-
*/
|
|
43
|
-
getTimestampFromLocation(dataId: string): Promise<number | null>;
|
|
44
|
-
/**
|
|
45
|
-
* Function to get timestamp from location
|
|
46
|
-
*
|
|
47
|
-
* @param dataId location to get the timestamp from
|
|
48
|
-
* @returns timestamp of the location, null if not found
|
|
49
|
-
*/
|
|
50
|
-
isDataInBoundaries(dataId: string, boundaries?: DataAccessTypes.ITimestampBoundaries): Promise<boolean>;
|
|
51
|
-
/**
|
|
52
|
-
* the timestamp of the latest transaction
|
|
53
|
-
*/
|
|
54
|
-
getLastTransactionTimestamp(): Promise<number | null>;
|
|
55
|
-
/**
|
|
56
|
-
* the timestamp of the latest transaction
|
|
57
|
-
*/
|
|
58
|
-
private setLastTransactionTimestamp;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=timestamp-by-location.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp-by-location.d.ts","sourceRoot":"","sources":["../../src/transaction-index/timestamp-by-location.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mCAAmC;IACtD;;;OAGG;IACH,OAAO,CAAC,mBAAmB,CAAe;IAE1C;;;OAGG;gBACgB,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAO1C;;;;;OAKG;IACU,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtF;;;;OAIG;IACU,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D;;;;;OAKG;IACU,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxF;;;;;OAKG;IACU,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAK7E;;;;;OAKG;IACU,kBAAkB,CAC7B,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,eAAe,CAAC,oBAAoB,GAChD,OAAO,CAAC,OAAO,CAAC;IAanB;;OAEG;IACU,2BAA2B,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIlE;;OAEG;YACW,2BAA2B;CAG1C"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const Keyv = require("keyv");
|
|
13
|
-
/**
|
|
14
|
-
* Class used to store the block's timestamp indexed by location
|
|
15
|
-
*/
|
|
16
|
-
class TimestampByLocationTransactionIndex {
|
|
17
|
-
/**
|
|
18
|
-
* TimestampByLocationTransactionIndex constructor
|
|
19
|
-
* @param store a Keyv store to persist the index to
|
|
20
|
-
*/
|
|
21
|
-
constructor(store) {
|
|
22
|
-
this.timestampByLocation = new Keyv({
|
|
23
|
-
namespace: 'timestampByLocation',
|
|
24
|
-
store,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Function to push timestamp indexed by location
|
|
29
|
-
*
|
|
30
|
-
* @param dataId dataId of the block
|
|
31
|
-
* @param timestamp timestamp of the block
|
|
32
|
-
*/
|
|
33
|
-
pushTimestampByLocation(dataId, timestamp) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (!(yield this.timestampByLocation.get(dataId))) {
|
|
36
|
-
yield this.timestampByLocation.set(dataId, timestamp);
|
|
37
|
-
}
|
|
38
|
-
const lastTransactionTimestamp = yield this.getLastTransactionTimestamp();
|
|
39
|
-
if (!lastTransactionTimestamp || timestamp > lastTransactionTimestamp) {
|
|
40
|
-
yield this.setLastTransactionTimestamp(timestamp);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Removes timestamp indexed by location
|
|
46
|
-
*
|
|
47
|
-
* @param dataId dataId of the block
|
|
48
|
-
*/
|
|
49
|
-
removeIndexedDataId(dataId) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
yield this.timestampByLocation.delete(dataId);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Function to update timestamp indexed by location
|
|
56
|
-
*
|
|
57
|
-
* @param dataId dataId of the block
|
|
58
|
-
* @param timestamp timestamp of the block
|
|
59
|
-
*/
|
|
60
|
-
updateTimestampByLocation(dataId, timestamp) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
yield this.timestampByLocation.set(dataId, timestamp);
|
|
63
|
-
const lastTransactionTimestamp = yield this.getLastTransactionTimestamp();
|
|
64
|
-
if (!lastTransactionTimestamp || timestamp > lastTransactionTimestamp) {
|
|
65
|
-
yield this.setLastTransactionTimestamp(timestamp);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Function to get timestamp from location
|
|
71
|
-
*
|
|
72
|
-
* @param dataId location to get the timestamp from
|
|
73
|
-
* @returns timestamp of the location, null if not found
|
|
74
|
-
*/
|
|
75
|
-
getTimestampFromLocation(dataId) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const timestamp = yield this.timestampByLocation.get(dataId);
|
|
78
|
-
return timestamp !== undefined ? timestamp : null;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Function to get timestamp from location
|
|
83
|
-
*
|
|
84
|
-
* @param dataId location to get the timestamp from
|
|
85
|
-
* @returns timestamp of the location, null if not found
|
|
86
|
-
*/
|
|
87
|
-
isDataInBoundaries(dataId, boundaries) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const timestamp = yield this.timestampByLocation.get(dataId);
|
|
90
|
-
if (!timestamp) {
|
|
91
|
-
throw Error(`Unknown timestamp for the dataId ${dataId}`);
|
|
92
|
-
}
|
|
93
|
-
return (!boundaries ||
|
|
94
|
-
((boundaries.from === undefined || boundaries.from <= timestamp) &&
|
|
95
|
-
(boundaries.to === undefined || boundaries.to >= timestamp)));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* the timestamp of the latest transaction
|
|
100
|
-
*/
|
|
101
|
-
getLastTransactionTimestamp() {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
return (yield this.timestampByLocation.get('last_transaction_timestamp')) || null;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* the timestamp of the latest transaction
|
|
108
|
-
*/
|
|
109
|
-
setLastTransactionTimestamp(value) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
yield this.timestampByLocation.set('last_transaction_timestamp', value);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.default = TimestampByLocationTransactionIndex;
|
|
116
|
-
//# sourceMappingURL=timestamp-by-location.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp-by-location.js","sourceRoot":"","sources":["../../src/transaction-index/timestamp-by-location.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,6BAA6B;AAE7B;;GAEG;AACH,MAAqB,mCAAmC;IAOtD;;;OAGG;IACH,YAAmB,KAAuB;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,IAAI,CAAS;YAC1C,SAAS,EAAE,qBAAqB;YAChC,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACU,uBAAuB,CAAC,MAAc,EAAE,SAAiB;;YACpE,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE;gBACjD,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;aACvD;YACD,MAAM,wBAAwB,GAAG,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAC;YAC1E,IAAI,CAAC,wBAAwB,IAAI,SAAS,GAAG,wBAAwB,EAAE;gBACrE,MAAM,IAAI,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC;aACnD;QACH,CAAC;KAAA;IAED;;;;OAIG;IACU,mBAAmB,CAAC,MAAc;;YAC7C,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC;KAAA;IAED;;;;;OAKG;IACU,yBAAyB,CAAC,MAAc,EAAE,SAAi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