import { ITransferRequestStore } from "../interfaces/transfer-request-store.i"; import { NrtTransaction } from "../interfaces/network-listener.i"; import { Observable, of } from "rxjs"; const Keyv = require('keyv') const KeyvFile = require('keyv-file') // More options with default value: export class FileTransferRequestStorage implements ITransferRequestStore { private customKeyvFile = new KeyvFile({ filename: `./keyv-file/default-rnd-${Math.random().toString(36).slice(2)}.txt`, expiredCheckDelay: 24 * 3600 * 1000, // ms, check and remove expired data in each ms writeDelay: 100, // ms, batch write to disk in a specific duration, enhance write performance. }) private customKeyv = new Keyv({ store: this.customKeyvFile }) retrieve(): Observable { return of(Array.from(this.customKeyvFile.keys().map((key: string) => this.customKeyv.get(key)))); } remove(tx: string): void { this.customKeyv.delete(tx); } put(tx: NrtTransaction): void { this.customKeyv.set(tx.transactionID, tx); } }