@requestnetwork/data-access
Advanced tools
Comparing version 0.23.1-next.711 to 0.23.1-next.743
@@ -9,6 +9,6 @@ import { DataAccessTypes } from '@requestnetwork/types'; | ||
getTransactionsByChannelId(channelId: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined): Promise<DataAccessTypes.IReturnGetTransactions>; | ||
getChannelsByTopic(topic: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByMultipleTopics(topics: string[], updatedBetween?: DataAccessTypes.ITimestampBoundaries): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByTopic(topic: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined, page?: number, pageSize?: number): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByMultipleTopics(topics: string[], updatedBetween?: DataAccessTypes.ITimestampBoundaries, page?: number | undefined, pageSize?: number | undefined): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
persistTransaction(transactionData: DataAccessTypes.ITransaction, channelId: string, topics?: string[] | undefined): Promise<DataAccessTypes.IReturnPersistTransaction>; | ||
} | ||
//# sourceMappingURL=combined-data-access.d.ts.map |
@@ -27,10 +27,10 @@ "use strict"; | ||
} | ||
getChannelsByTopic(topic, updatedBetween) { | ||
getChannelsByTopic(topic, updatedBetween, page, pageSize) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.reader.getChannelsByTopic(topic, updatedBetween); | ||
return yield this.reader.getChannelsByTopic(topic, updatedBetween, page, pageSize); | ||
}); | ||
} | ||
getChannelsByMultipleTopics(topics, updatedBetween) { | ||
getChannelsByMultipleTopics(topics, updatedBetween, page, pageSize) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.reader.getChannelsByMultipleTopics(topics, updatedBetween); | ||
return yield this.reader.getChannelsByMultipleTopics(topics, updatedBetween, page, pageSize); | ||
}); | ||
@@ -37,0 +37,0 @@ } |
@@ -11,4 +11,4 @@ import { DataAccessTypes, StorageTypes } from '@requestnetwork/types'; | ||
getTransactionsByChannelId(channelId: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries): Promise<DataAccessTypes.IReturnGetTransactions>; | ||
getChannelsByTopic(topic: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByMultipleTopics(topics: string[], updatedBetween?: DataAccessTypes.ITimestampBoundaries): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByTopic(topic: string, updatedBetween?: DataAccessTypes.ITimestampBoundaries | undefined, page?: number | undefined, pageSize?: number | undefined): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
getChannelsByMultipleTopics(topics: string[], updatedBetween?: DataAccessTypes.ITimestampBoundaries, page?: number, pageSize?: number): Promise<DataAccessTypes.IReturnGetChannelsByTopic>; | ||
private getPending; | ||
@@ -15,0 +15,0 @@ protected toStorageMeta(result: StorageTypes.IIndexedTransaction, lastBlockNumber: number, network: string): StorageTypes.IEntryMetadata; |
@@ -39,11 +39,17 @@ "use strict"; | ||
} | ||
getChannelsByTopic(topic, updatedBetween) { | ||
getChannelsByTopic(topic, updatedBetween, page, pageSize) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return this.getChannelsByMultipleTopics([topic], updatedBetween); | ||
return this.getChannelsByMultipleTopics([topic], updatedBetween, page, pageSize); | ||
}); | ||
} | ||
getChannelsByMultipleTopics(topics, updatedBetween) { | ||
getChannelsByMultipleTopics(topics, updatedBetween, page, pageSize) { | ||
var _a; | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const result = yield this.storage.getTransactionsByTopics(topics); | ||
// Validate pagination parameters | ||
if (page !== undefined && page < 1) { | ||
throw new Error(`Page number must be greater than or equal to 1, but it is ${page}`); | ||
} | ||
if (pageSize !== undefined && pageSize < 1) { | ||
throw new Error(`Page size must be greater than 0, but it is ${pageSize}`); | ||
} | ||
const pending = ((_a = this.pendingStore) === null || _a === void 0 ? void 0 : _a.findByTopics(topics)) || []; | ||
@@ -54,2 +60,23 @@ const pendingItems = pending.map((item) => { | ||
}); | ||
// Calculate adjusted pagination | ||
let adjustedPage = page; | ||
let adjustedPageSize = pageSize; | ||
let pendingItemsOnCurrentPage = 0; | ||
if (page !== undefined && pageSize !== undefined) { | ||
const totalPending = pendingItems.length; | ||
const itemsPerPage = (page - 1) * pageSize; | ||
if (totalPending > itemsPerPage) { | ||
pendingItemsOnCurrentPage = Math.min(totalPending - itemsPerPage, pageSize); | ||
adjustedPageSize = pageSize - pendingItemsOnCurrentPage; | ||
adjustedPage = 1; | ||
if (adjustedPageSize === 0) { | ||
adjustedPageSize = 1; | ||
pendingItemsOnCurrentPage--; | ||
} | ||
} | ||
else { | ||
adjustedPage = page - Math.floor(totalPending / pageSize); | ||
} | ||
} | ||
const result = yield this.storage.getTransactionsByTopics(topics, adjustedPage, adjustedPageSize); | ||
const transactions = result.transactions.concat(...pendingItems); | ||
@@ -75,2 +102,11 @@ // list of channels having at least one tx updated during the updatedBetween boundaries | ||
}, {}), | ||
pagination: page && pageSize | ||
? { | ||
total: result.transactions.length + pendingItems.length, | ||
page, | ||
pageSize, | ||
hasMore: (page - 1) * pageSize + filteredTxs.length - pendingItemsOnCurrentPage < | ||
result.transactions.length, | ||
} | ||
: undefined, | ||
}, | ||
@@ -77,0 +113,0 @@ result: { |
@@ -15,5 +15,5 @@ import { StorageTypes } from '@requestnetwork/types'; | ||
getTransactionsByChannelId(channelId: string): Promise<StorageTypes.IGetTransactionsResponse>; | ||
getTransactionsByTopics(topics: string[]): Promise<StorageTypes.IGetTransactionsResponse>; | ||
getTransactionsByTopics(topics: string[], page?: number, pageSize?: number): Promise<StorageTypes.IGetTransactionsResponse>; | ||
private parseDocuments; | ||
} | ||
//# sourceMappingURL=in-memory-indexer.d.ts.map |
@@ -59,5 +59,28 @@ "use strict"; | ||
} | ||
getTransactionsByTopics(topics) { | ||
getTransactionsByTopics(topics, page, pageSize) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const channelIds = topics.map((topic) => tslib_1.__classPrivateFieldGet(this, _InMemoryIndexer_topicToChannelsIndex, "f").get(topic)).flat(); | ||
if (page !== undefined && page < 1) { | ||
throw new Error('Page must be greater than or equal to 1'); | ||
} | ||
if (pageSize !== undefined && pageSize <= 0) { | ||
throw new Error('Page size must be greater than 0'); | ||
} | ||
// Efficiently get total count without creating intermediate array | ||
const channelIdsSet = new Set(topics.flatMap((topic) => tslib_1.__classPrivateFieldGet(this, _InMemoryIndexer_topicToChannelsIndex, "f").get(topic))); | ||
const total = channelIdsSet.size; | ||
let channelIds = Array.from(channelIdsSet); | ||
if (page && pageSize) { | ||
const start = (page - 1) * pageSize; | ||
// Return empty result if page exceeds available data | ||
if (start >= total) { | ||
return { | ||
blockNumber: 0, | ||
transactions: [], | ||
pagination: page && pageSize | ||
? { total, page, pageSize, hasMore: page * pageSize < total } | ||
: undefined, | ||
}; | ||
} | ||
channelIds = channelIds.slice(start, start + pageSize); | ||
} | ||
const locations = channelIds | ||
@@ -64,0 +87,0 @@ .map((channel) => tslib_1.__classPrivateFieldGet(this, _InMemoryIndexer_channelToLocationsIndex, "f").get(channel)) |
{ | ||
"name": "@requestnetwork/data-access", | ||
"version": "0.23.1-next.711+dc135379", | ||
"version": "0.23.1-next.743+d54df7f7", | ||
"publishConfig": { | ||
@@ -42,5 +42,5 @@ "access": "public" | ||
"dependencies": { | ||
"@requestnetwork/multi-format": "0.15.1-next.711+dc135379", | ||
"@requestnetwork/types": "0.29.1-next.711+dc135379", | ||
"@requestnetwork/utils": "0.28.1-next.711+dc135379", | ||
"@requestnetwork/multi-format": "0.15.1-next.743+d54df7f7", | ||
"@requestnetwork/types": "0.29.1-next.743+d54df7f7", | ||
"@requestnetwork/utils": "0.28.1-next.743+d54df7f7", | ||
"tslib": "2.5.0" | ||
@@ -58,3 +58,3 @@ }, | ||
}, | ||
"gitHead": "dc135379ba3fa9d2e998c7cdd42f1122d1fd8639" | ||
"gitHead": "d54df7f7923978c066c06dd2b0a9f7c596eb3b80" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
75315
884