@requestnetwork/data-access
Version:
Main package for the Request Network data access layer.
29 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockDataAccess = void 0;
const tslib_1 = require("tslib");
const data_write_1 = require("./data-write");
const data_read_1 = require("./data-read");
const pending_store_1 = require("./pending-store");
const in_memory_indexer_1 = require("./in-memory-indexer");
const combined_data_access_1 = require("./combined-data-access");
/**
* Mock Data access that bypasses the initialization.
* This class is meant to be used with HttpRequestNetwork and useMockStorage=true.
* Data-access initialization is asynchronous and this class is a hack to avoid having an asynchronous operation in the HttpRequestNetwork constructor.
*/
class MockDataAccess extends combined_data_access_1.CombinedDataAccess {
constructor(storage) {
const dataIndex = new in_memory_indexer_1.InMemoryIndexer(storage);
const pendingStore = new pending_store_1.PendingStore();
super(new data_read_1.DataAccessRead(dataIndex, { network: 'mock', pendingStore }), new data_write_1.DataAccessWrite(storage, pendingStore));
this.persistTransaction = (transactionData, channelId, topics) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const result = yield this.writer.persistTransaction(transactionData, channelId, topics);
this.dataIndex.addIndex(channelId, topics || [], result.meta.transactionStorageLocation);
return result;
});
this.dataIndex = dataIndex;
}
}
exports.MockDataAccess = MockDataAccess;
//# sourceMappingURL=mock-data-access.js.map