-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split data-access read and write for TheGraph (#875)
- Loading branch information
1 parent
9c5ae2b
commit 8fdf34d
Showing
9 changed files
with
246 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { DataAccessTypes } from '@requestnetwork/types'; | ||
|
||
export abstract class CombinedDataAccess implements DataAccessTypes.IDataAccess { | ||
constructor( | ||
protected reader: DataAccessTypes.IDataRead, | ||
protected writer: DataAccessTypes.IDataWrite, | ||
) { | ||
this.getTransactionsByChannelId = this.reader.getTransactionsByChannelId.bind(this.reader); | ||
this.getChannelsByTopic = this.reader.getChannelsByTopic.bind(this.reader); | ||
this.getChannelsByMultipleTopics = this.reader.getChannelsByMultipleTopics.bind(this.reader); | ||
this.persistTransaction = this.writer.persistTransaction.bind(this.writer); | ||
} | ||
|
||
async initialize(): Promise<void> { | ||
await this.reader.initialize(); | ||
await this.writer.initialize(); | ||
} | ||
|
||
async close(): Promise<void> { | ||
await this.writer.close(); | ||
await this.reader.close(); | ||
} | ||
|
||
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>; | ||
persistTransaction: ( | ||
transactionData: DataAccessTypes.ITransaction, | ||
channelId: string, | ||
topics?: string[] | undefined, | ||
) => Promise<DataAccessTypes.IReturnPersistTransaction>; | ||
|
||
abstract _getStatus(): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { DataAccessTypes, StorageTypes } from '@requestnetwork/types'; | ||
|
||
type PendingItem = { | ||
transaction: DataAccessTypes.ITransaction; | ||
storageResult: StorageTypes.IAppendResult; | ||
}; | ||
/** | ||
* A simple in-memory store to share state between DataReader and DataWriter | ||
* Useful to retrieve a transaction that was just emitted but is not confirmed yet | ||
**/ | ||
export class PendingStore { | ||
private pending: Record<string, PendingItem> = {}; | ||
|
||
/** Gets a pending tx */ | ||
public get(channelId: string): PendingItem { | ||
return this.pending[channelId]; | ||
} | ||
|
||
public add( | ||
channelId: string, | ||
transaction: DataAccessTypes.ITransaction, | ||
storageResult: StorageTypes.IAppendResult, | ||
): void { | ||
this.pending[channelId] = { transaction, storageResult }; | ||
} | ||
|
||
public remove(channelId: string): void { | ||
delete this.pending[channelId]; | ||
} | ||
} |
Oops, something went wrong.