@mightylittle/transaction-log
v0.3.0
Published
In-memory, non-threadsafe replayable logs.
Readme
@mightylittle/transaction-log
The package defines two exported classes:
- MemorySimpleTransactionLog
- MemoryBatchedTransactionLog
Usage
MemorySimpleTransactionLog
JavaScript example:
import { MemorySimpleTransactionLog } from "@mightylittle/transaction-log";
async function start () {
const log = new MemorySimpleTransactionLog();
await log.open();
await log.append("foo");
await log.append("bar");
await log.countTransactions(); // => 2
await log.replay((data) => console.log("data", data));
await console.log("transactions", await log.getSeqRangeTransactions(1, 2)); // returns the first and second entries
await log.close();
await log.clear();
}MemoryBatchedTransactionLog
JavaScript example:
import { MemoryBatchedTransactionLog } from "@mightylittle/transaction-log";
async function start () {
const log = new MemoryBatchedTransactionLog();
await log.open();
log.append("foo");
log.append("bar");
await log.commit();
await log.countTransactions(); // => 2
await log.countCommits(); // => 1
await log.replay((data) => console.log("data", data), true);
await console.log("transactions", await log.getSeqRangeTransactions(1, 2)); // prints the first and second entries
await console.log("commits", await log.getSeqRangeCommits(1)); // prints the first and any later commits
await log.close();
await log.clear();
}Installation
npm installDevelopment
Build:
npm run buildRun tests:
npm run testGenerate documentation:
npm run typedocAuthor
- John Newton
Copyright
- John Newton
License
Apache-2.0
