import IUnresolvableTransactionStore from './interfaces/IUnresolvableTransactionStore'; import TransactionModel from '../common/models/TransactionModel'; import { Collection, Db } from 'mongodb'; interface IUnresolvableTransaction extends TransactionModel { firstFetchTime: number; retryAttempts: number; nextRetryTime: number; } /** * Implementation of `IIUnresolvableTransactionStore` that stores the transaction data in a MongoDB database. */ export default class MongoDbUnresolvableTransactionStore implements IUnresolvableTransactionStore { private serverUrl; /** Default database name used if not specified in constructor. */ static readonly defaultDatabaseName: string; /** Collection name for unresolvable transactions. */ static readonly unresolvableTransactionCollectionName: string; /** Database name used by this transaction store. */ readonly databaseName: string; private exponentialDelayFactorInMilliseconds; private maximumUnresolvableTransactionReturnCount; private db; private unresolvableTransactionCollection; /** * Constructs a `MongoDbUnresolvableTransactionStore`; * @param retryExponentialDelayFactor * The exponential delay factor in milliseconds for retries of unresolvable transactions. * e.g. if it is set to 1 seconds, then the delays for retries will be 1 second, 2 seconds, 4 seconds... until the transaction can be resolved. */ constructor(serverUrl: string, databaseName?: string, retryExponentialDelayFactor?: number); /** * Initialize the MongoDB unresolvable transaction store. */ initialize(): Promise; /** * * Clears the unresolvable transaction store. */ clearCollection(): Promise; recordUnresolvableTransactionFetchAttempt(transaction: TransactionModel): Promise; removeUnresolvableTransaction(transaction: TransactionModel): Promise; getUnresolvableTransactionsDueForRetry(maximumReturnCount?: number): Promise; removeUnresolvableTransactionsLaterThan(transactionNumber?: number): Promise; /** * Gets the list of unresolvable transactions. * Mainly used for test purposes. */ getUnresolvableTransactions(): Promise; /** * Creates the `unresolvable-transaction` collection with indexes if it does not exists. * @returns The existing collection if exists, else the newly created collection. */ static createUnresolvableTransactionCollectionIfNotExist(db: Db): Promise>; } export {};