@requestnetwork/data-access 0.28.1-next.1937 → 0.28.1-next.1939
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/dist/combined-data-access.d.ts +0 -1
- package/dist/combined-data-access.d.ts.map +1 -1
- package/dist/combined-data-access.js.map +1 -1
- 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 +107 -0
- package/dist/in-memory-indexer.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -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 +5 -9
- package/dist/data-access.d.ts +0 -148
- package/dist/data-access.d.ts.map +0 -1
- package/dist/data-access.js +0 -428
- 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 -96
- package/dist/ignored-location.js.map +0 -1
- package/dist/interval-timer.d.ts +0 -41
- package/dist/interval-timer.d.ts.map +0 -1
- package/dist/interval-timer.js +0 -94
- 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 -8
- 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 -103
- 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 -108
- 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 -204
- package/dist/transaction-index/transaction-index.js.map +0 -1
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const Keyv = require("keyv");
|
|
5
|
-
/**
|
|
6
|
-
* Class used to store the block's timestamp indexed by location
|
|
7
|
-
*/
|
|
8
|
-
class TimestampByLocationTransactionIndex {
|
|
9
|
-
/**
|
|
10
|
-
* TimestampByLocationTransactionIndex constructor
|
|
11
|
-
* @param store a Keyv store to persist the index to
|
|
12
|
-
*/
|
|
13
|
-
constructor(store) {
|
|
14
|
-
this.timestampByLocation = new Keyv({
|
|
15
|
-
namespace: 'timestampByLocation',
|
|
16
|
-
store,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Function to push timestamp indexed by location
|
|
21
|
-
*
|
|
22
|
-
* @param dataId dataId of the block
|
|
23
|
-
* @param timestamp timestamp of the block
|
|
24
|
-
*/
|
|
25
|
-
pushTimestampByLocation(dataId, timestamp) {
|
|
26
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
if (!(yield this.timestampByLocation.get(dataId))) {
|
|
28
|
-
yield this.timestampByLocation.set(dataId, timestamp);
|
|
29
|
-
}
|
|
30
|
-
const lastTransactionTimestamp = yield this.getLastTransactionTimestamp();
|
|
31
|
-
if (!lastTransactionTimestamp || timestamp > lastTransactionTimestamp) {
|
|
32
|
-
yield this.setLastTransactionTimestamp(timestamp);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Removes timestamp indexed by location
|
|
38
|
-
*
|
|
39
|
-
* @param dataId dataId of the block
|
|
40
|
-
*/
|
|
41
|
-
removeIndexedDataId(dataId) {
|
|
42
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
yield this.timestampByLocation.delete(dataId);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Function to update timestamp indexed by location
|
|
48
|
-
*
|
|
49
|
-
* @param dataId dataId of the block
|
|
50
|
-
* @param timestamp timestamp of the block
|
|
51
|
-
*/
|
|
52
|
-
updateTimestampByLocation(dataId, timestamp) {
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
yield this.timestampByLocation.set(dataId, timestamp);
|
|
55
|
-
const lastTransactionTimestamp = yield this.getLastTransactionTimestamp();
|
|
56
|
-
if (!lastTransactionTimestamp || timestamp > lastTransactionTimestamp) {
|
|
57
|
-
yield this.setLastTransactionTimestamp(timestamp);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Function to get timestamp from location
|
|
63
|
-
*
|
|
64
|
-
* @param dataId location to get the timestamp from
|
|
65
|
-
* @returns timestamp of the location, null if not found
|
|
66
|
-
*/
|
|
67
|
-
getTimestampFromLocation(dataId) {
|
|
68
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const timestamp = yield this.timestampByLocation.get(dataId);
|
|
70
|
-
return timestamp !== undefined ? timestamp : null;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Function to get timestamp from location
|
|
75
|
-
*
|
|
76
|
-
* @param dataId location to get the timestamp from
|
|
77
|
-
* @returns timestamp of the location, null if not found
|
|
78
|
-
*/
|
|
79
|
-
isDataInBoundaries(dataId, boundaries) {
|
|
80
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const timestamp = yield this.timestampByLocation.get(dataId);
|
|
82
|
-
if (!timestamp) {
|
|
83
|
-
throw Error(`Unknown timestamp for the dataId ${dataId}`);
|
|
84
|
-
}
|
|
85
|
-
return (!boundaries ||
|
|
86
|
-
((boundaries.from === undefined || boundaries.from <= timestamp) &&
|
|
87
|
-
(boundaries.to === undefined || boundaries.to >= timestamp)));
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* the timestamp of the latest transaction
|
|
92
|
-
*/
|
|
93
|
-
getLastTransactionTimestamp() {
|
|
94
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
return (yield this.timestampByLocation.get('last_transaction_timestamp')) || null;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* the timestamp of the latest transaction
|
|
100
|
-
*/
|
|
101
|
-
setLastTransactionTimestamp(value) {
|
|
102
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
yield this.timestampByLocation.set('last_transaction_timestamp', value);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.default = TimestampByLocationTransactionIndex;
|
|
108
|
-
//# 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,KAA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AC,IAAI,CAAC;QACpD,CAAC;KAAA;IAED;;;;;OAKG;IACU,kBAAkB,CAC7B,MAAc,EACd,UAAiD;;YAEjD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,KAAK,CAAC,oCAAoC,MAAM,EAAE,CAAC,CAAC;aAC3D;YAED,OAAO,CACL,CAAC,UAAU;gBACX,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,IAAI,SAAS,CAAC;oBAC9D,CAAC,UAAU,CAAC,EAAE,KAAK,SAAS,IAAI,UAAU,CAAC,EAAE,IAAI,SAAS,CAAC,CAAC,CAC/D,CAAC;QACJ,CAAC;KAAA;IAED;;OAEG;IACU,2BAA2B;;YACtC,OAAO,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,IAAI,IAAI,CAAC;QACpF,CAAC;KAAA;IAED;;OAEG;IACW,2BAA2B,CAAC,KAAa;;YACrD,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC;KAAA;CACF;AAxGD,sDAwGC"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { DataAccessTypes } from '@requestnetwork/types';
|
|
2
|
-
import * as Keyv from 'keyv';
|
|
3
|
-
/**
|
|
4
|
-
* An in-memory implementation of the transaction index.
|
|
5
|
-
*/
|
|
6
|
-
export default class TransactionIndex implements DataAccessTypes.ITransactionIndex {
|
|
7
|
-
private locationByTopic?;
|
|
8
|
-
private timestampByLocation;
|
|
9
|
-
private indexedLocation;
|
|
10
|
-
/**
|
|
11
|
-
* Constructor of TransactionIndex
|
|
12
|
-
* @param store a Keyv store to persist the index
|
|
13
|
-
*/
|
|
14
|
-
constructor(store?: Keyv.Store<string[]>);
|
|
15
|
-
initialize(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Get the last indexed timestamp
|
|
18
|
-
*/
|
|
19
|
-
getLastTransactionTimestamp(): Promise<number | null>;
|
|
20
|
-
/**
|
|
21
|
-
* Adds a transaction to the index, for indexing by channel, topic and timestamp
|
|
22
|
-
*
|
|
23
|
-
* @param dataId the dataId to index
|
|
24
|
-
* @param header the headers of the block (containing channels and topics)
|
|
25
|
-
* @param timestamp the timestamp of the transaction
|
|
26
|
-
*/
|
|
27
|
-
addTransaction(dataId: string, header: DataAccessTypes.IBlockHeader, timestamp: number): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Removes a transaction from the index
|
|
30
|
-
*
|
|
31
|
-
* @param dataId the dataId to remove
|
|
32
|
-
*/
|
|
33
|
-
removeTransaction(dataId: string): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Update timestamp for a dataId
|
|
36
|
-
*
|
|
37
|
-
* @param dataId the dataId to index
|
|
38
|
-
* @param timestamp the timestamp of the transaction
|
|
39
|
-
*/
|
|
40
|
-
updateTimestamp(dataId: string, timestamp: number): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Get a list of transactions indexed by channel id
|
|
43
|
-
* @param channelId channel id to retrieve the transaction from
|
|
44
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
45
|
-
* @returns list of location of a channel
|
|
46
|
-
*/
|
|
47
|
-
getStorageLocationList(channelId: string, timestampBoundaries?: DataAccessTypes.ITimestampBoundaries): Promise<string[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Get a list of channels indexed by topic
|
|
50
|
-
* @param topic topic to retrieve the channelIds from
|
|
51
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
52
|
-
* @returns list of location of the channels indexed by the topic
|
|
53
|
-
*/
|
|
54
|
-
getChannelIdsForTopic(topic: string, timestampBoundaries?: DataAccessTypes.ITimestampBoundaries | undefined): Promise<string[]>;
|
|
55
|
-
/**
|
|
56
|
-
* Get a list of channels indexed by topics
|
|
57
|
-
* @param topics topics to retrieve the channelIds from
|
|
58
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
59
|
-
* @returns list of location of the channels indexed by the topics
|
|
60
|
-
*/
|
|
61
|
-
getChannelIdsForMultipleTopics(topics: string[], timestampBoundaries?: DataAccessTypes.ITimestampBoundaries | undefined): Promise<string[]>;
|
|
62
|
-
/**
|
|
63
|
-
* the list of indexed locations
|
|
64
|
-
*/
|
|
65
|
-
getIndexedLocations(): Promise<string[]>;
|
|
66
|
-
/**
|
|
67
|
-
* Update the list of data ids stored
|
|
68
|
-
*
|
|
69
|
-
* @param dataId data id to add to the list
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
private updateIndexedLocation;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=transaction-index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-index.d.ts","sourceRoot":"","sources":["../../src/transaction-index/transaction-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,gBAAiB,YAAW,eAAe,CAAC,iBAAiB;IAGhF,OAAO,CAAC,eAAe,CAAC,CAAkB;IAI1C,OAAO,CAAC,mBAAmB,CAAsB;IAEjD,OAAO,CAAC,eAAe,CAAiB;IAExC;;;OAGG;gBACS,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAW3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAExC;;OAEG;IACI,2BAA2B,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5D;;;;;;OAMG;IACU,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,CAAC,YAAY,EACpC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;IAahB;;;;OAIG;IACU,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D;;;;;OAKG;IACU,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9E;;;;;OAKG;IACU,sBAAsB,CACjC,SAAS,EAAE,MAAM,EACjB,mBAAmB,CAAC,EAAE,eAAe,CAAC,oBAAoB,GACzD,OAAO,CAAC,MAAM,EAAE,CAAC;IAwBpB;;;;;OAKG;IACU,qBAAqB,CAChC,KAAK,EAAE,MAAM,EACb,mBAAmB,CAAC,EAAE,eAAe,CAAC,oBAAoB,GAAG,SAAS,GACrE,OAAO,CAAC,MAAM,EAAE,CAAC;IA+BpB;;;;;OAKG;IACU,8BAA8B,CACzC,MAAM,EAAE,MAAM,EAAE,EAChB,mBAAmB,CAAC,EAAE,eAAe,CAAC,oBAAoB,GAAG,SAAS,GACrE,OAAO,CAAC,MAAM,EAAE,CAAC;IA+BpB;;OAEG;IACU,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKrD;;;;;OAKG;YACW,qBAAqB;CAYpC"}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const Bluebird = require("bluebird");
|
|
5
|
-
const Keyv = require("keyv");
|
|
6
|
-
const location_by_topic_1 = require("./location-by-topic");
|
|
7
|
-
const timestamp_by_location_1 = require("./timestamp-by-location");
|
|
8
|
-
/**
|
|
9
|
-
* An in-memory implementation of the transaction index.
|
|
10
|
-
*/
|
|
11
|
-
class TransactionIndex {
|
|
12
|
-
/**
|
|
13
|
-
* Constructor of TransactionIndex
|
|
14
|
-
* @param store a Keyv store to persist the index
|
|
15
|
-
*/
|
|
16
|
-
constructor(store) {
|
|
17
|
-
this.timestampByLocation = new timestamp_by_location_1.default(store);
|
|
18
|
-
this.locationByTopic = new location_by_topic_1.default(store);
|
|
19
|
-
this.indexedLocation = new Keyv({
|
|
20
|
-
namespace: 'indexedLocation',
|
|
21
|
-
store,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
// eslint-disable-next-line no-empty, @typescript-eslint/no-empty-function
|
|
25
|
-
initialize() {
|
|
26
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () { });
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get the last indexed timestamp
|
|
30
|
-
*/
|
|
31
|
-
getLastTransactionTimestamp() {
|
|
32
|
-
return this.timestampByLocation.getLastTransactionTimestamp();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Adds a transaction to the index, for indexing by channel, topic and timestamp
|
|
36
|
-
*
|
|
37
|
-
* @param dataId the dataId to index
|
|
38
|
-
* @param header the headers of the block (containing channels and topics)
|
|
39
|
-
* @param timestamp the timestamp of the transaction
|
|
40
|
-
*/
|
|
41
|
-
addTransaction(dataId, header, timestamp) {
|
|
42
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
if (!this.locationByTopic) {
|
|
44
|
-
throw new Error('TransactionIndex must be initialized');
|
|
45
|
-
}
|
|
46
|
-
// topic the dataId with block topic
|
|
47
|
-
yield this.locationByTopic.pushStorageLocationIndexedWithBlockTopics(dataId, header);
|
|
48
|
-
// add the timestamp in the index
|
|
49
|
-
yield this.timestampByLocation.pushTimestampByLocation(dataId, timestamp);
|
|
50
|
-
yield this.updateIndexedLocation(dataId);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Removes a transaction from the index
|
|
55
|
-
*
|
|
56
|
-
* @param dataId the dataId to remove
|
|
57
|
-
*/
|
|
58
|
-
removeTransaction(dataId) {
|
|
59
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
if (!this.locationByTopic) {
|
|
61
|
-
throw new Error('TransactionIndex must be initialized');
|
|
62
|
-
}
|
|
63
|
-
// remove the timestamp in the index
|
|
64
|
-
yield this.timestampByLocation.removeIndexedDataId(dataId);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Update timestamp for a dataId
|
|
69
|
-
*
|
|
70
|
-
* @param dataId the dataId to index
|
|
71
|
-
* @param timestamp the timestamp of the transaction
|
|
72
|
-
*/
|
|
73
|
-
updateTimestamp(dataId, timestamp) {
|
|
74
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
if (!this.timestampByLocation) {
|
|
76
|
-
throw new Error('TransactionIndex must be initialized');
|
|
77
|
-
}
|
|
78
|
-
// update the timestamp in the index
|
|
79
|
-
yield this.timestampByLocation.updateTimestampByLocation(dataId, timestamp);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get a list of transactions indexed by channel id
|
|
84
|
-
* @param channelId channel id to retrieve the transaction from
|
|
85
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
86
|
-
* @returns list of location of a channel
|
|
87
|
-
*/
|
|
88
|
-
getStorageLocationList(channelId, timestampBoundaries) {
|
|
89
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
if (!this.locationByTopic) {
|
|
91
|
-
throw new Error('TransactionIndex must be initialized');
|
|
92
|
-
}
|
|
93
|
-
// get transaction locations for the given channel
|
|
94
|
-
let storageLocationList = yield this.locationByTopic.getStorageLocationsFromChannelId(channelId);
|
|
95
|
-
storageLocationList = yield Bluebird.filter(storageLocationList, (dataId) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
// if the dataId has not been suppressed
|
|
97
|
-
const exist = (yield this.timestampByLocation.getTimestampFromLocation(dataId)) !== null;
|
|
98
|
-
// if boundaries are passed, only return locations of transaction within these boundaries
|
|
99
|
-
const inTimeBoundaries = !timestampBoundaries ||
|
|
100
|
-
(yield this.timestampByLocation.isDataInBoundaries(dataId, timestampBoundaries));
|
|
101
|
-
return exist && inTimeBoundaries;
|
|
102
|
-
}));
|
|
103
|
-
return storageLocationList;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Get a list of channels indexed by topic
|
|
108
|
-
* @param topic topic to retrieve the channelIds from
|
|
109
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
110
|
-
* @returns list of location of the channels indexed by the topic
|
|
111
|
-
*/
|
|
112
|
-
getChannelIdsForTopic(topic, timestampBoundaries) {
|
|
113
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
if (!this.locationByTopic) {
|
|
115
|
-
throw new Error('TransactionIndex must be initialized');
|
|
116
|
-
}
|
|
117
|
-
// get channels for given topic
|
|
118
|
-
const channelIds = yield this.locationByTopic.getChannelIdsFromTopic(topic);
|
|
119
|
-
// if boundaries are passed, only return channelIds with transactions within these boundaries
|
|
120
|
-
if (timestampBoundaries) {
|
|
121
|
-
const result = [];
|
|
122
|
-
// check for each channel if one of its transactions occurred during the given boundaries
|
|
123
|
-
for (const channelId of channelIds) {
|
|
124
|
-
const txLocations = yield this.locationByTopic.getStorageLocationsFromChannelId(channelId);
|
|
125
|
-
for (const txLocation of txLocations) {
|
|
126
|
-
const isInBoundaries = yield this.timestampByLocation.isDataInBoundaries(txLocation, timestampBoundaries);
|
|
127
|
-
if (isInBoundaries) {
|
|
128
|
-
result.push(channelId);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
return channelIds;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Get a list of channels indexed by topics
|
|
142
|
-
* @param topics topics to retrieve the channelIds from
|
|
143
|
-
* @param timestampBoundaries timestamp boundaries of the transactions search
|
|
144
|
-
* @returns list of location of the channels indexed by the topics
|
|
145
|
-
*/
|
|
146
|
-
getChannelIdsForMultipleTopics(topics, timestampBoundaries) {
|
|
147
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
if (!this.locationByTopic) {
|
|
149
|
-
throw new Error('TransactionIndex must be initialized');
|
|
150
|
-
}
|
|
151
|
-
// get channels for given topics
|
|
152
|
-
const channelIds = yield this.locationByTopic.getChannelIdsFromMultipleTopics(topics);
|
|
153
|
-
// if boundaries are passed, only return channelIds with transactions within these boundaries
|
|
154
|
-
if (timestampBoundaries) {
|
|
155
|
-
const result = [];
|
|
156
|
-
// check for each channel if one of its transactions occurred inside the given boundaries
|
|
157
|
-
for (const channelId of channelIds) {
|
|
158
|
-
const txLocations = yield this.locationByTopic.getStorageLocationsFromChannelId(channelId);
|
|
159
|
-
for (const txLocation of txLocations) {
|
|
160
|
-
const isInBoundaries = yield this.timestampByLocation.isDataInBoundaries(txLocation, timestampBoundaries);
|
|
161
|
-
if (isInBoundaries) {
|
|
162
|
-
result.push(channelId);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
return channelIds;
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* the list of indexed locations
|
|
176
|
-
*/
|
|
177
|
-
getIndexedLocations() {
|
|
178
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const listDataIds = yield this.indexedLocation.get('list');
|
|
180
|
-
return listDataIds || [];
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Update the list of data ids stored
|
|
185
|
-
*
|
|
186
|
-
* @param dataId data id to add to the list
|
|
187
|
-
* @returns
|
|
188
|
-
*/
|
|
189
|
-
updateIndexedLocation(dataId) {
|
|
190
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
let listDataIds = yield this.indexedLocation.get('list');
|
|
192
|
-
if (!listDataIds) {
|
|
193
|
-
listDataIds = [];
|
|
194
|
-
}
|
|
195
|
-
// push it if not already done
|
|
196
|
-
if (!listDataIds.includes(dataId)) {
|
|
197
|
-
listDataIds.push(dataId);
|
|
198
|
-
yield this.indexedLocation.set('list', listDataIds);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
exports.default = TransactionIndex;
|
|
204
|
-
//# sourceMappingURL=transaction-index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-index.js","sourceRoot":"","sources":["../../src/transaction-index/transaction-index.ts"],"names":[],"mappings":";;;AAEA,qCAAqC;AACrC,6BAA6B;AAE7B,2DAAkD;AAClD,mEAA0D;AAE1D;;GAEG;AAEH,MAAqB,gBAAgB;IAWnC;;;OAGG;IACH,YAAY,KAA4B;QACtC,IAAI,CAAC,mBAAmB,GAAG,IAAI,+BAAmB,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,CAAC,eAAe,GAAG,IAAI,2BAAe,CAAC,KAAK,CAAC,CAAC;QAElD,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAW;YACxC,SAAS,EAAE,iBAAiB;YAC5B,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,0EAA0E;IAC7D,UAAU;sEAAmB,CAAC;KAAA;IAE3C;;OAEG;IACI,2BAA2B;QAChC,OAAO,IAAI,CAAC,mBAAmB,CAAC,2BAA2B,EAAE,CAAC;IAChE,CAAC;IAED;;;;;;OAMG;IACU,cAAc,CACzB,MAAc,EACd,MAAoC,EACpC,SAAiB;;YAEjB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;gBACzB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;aACzD;YACD,oCAAoC;YACpC,MAAM,IAAI,CAAC,eAA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