npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@withcardinal/write-ahead-log

v1.0.3

Published

A write ahead log implementation for Cardinal

Downloads

3

Readme

write-ahead-log

A generalized write ahead log implementation.

Installation

npm install @withcardinal/write-ahead-log

Usage

A single class, WriteAheadLog is exposed.

const log = new WriteAheadLog(
  ".",
  "log",
  4194304,
  (valid, msg) => recover(msg)
);

Logs are appended to with append:

await log.append(msg: Buffer);

Appends are buffered until 32kib of log data are appended or flush is called. It's important to call flush any time a transaction is committed so that it's stored to disk.

await wal.flush();

Be sure to close the write-ahead-log during any graceful shutdown of your service:

await wal.close();

API Documentation

WriteAheadLog

init(logDir: string, name: string, logLimit: number, recoveryCallback: RecoveryCallback) : Promise<WriteAheadLog]>

Constructs a new write ahead log targeting logDir, which will generate log files with names like {name}-{logNum}.wal. Returns the new write ahead log and calls cb if there are any records to recover from prior logs. An interval is created in the background to flush outstanding log entries every 3 seconds.

Parameters
  • logDir - the directory to store logs in
  • name - the filename pattern to use when writing logs. Files will be written as {name}-{num}.wal within logDir
  • logLimit - the target number of bytes for each log file. This isn't a hard limit, but only one record will be written that exceeds log limit before rotating.
  • recoveryCallback - a callback of the form (valid: boolean, msg?: Buffer) => void that is called for each recovered statement from the log. The valid argument is true when no corruption was detected within the record, or false if it was determined to be corrupt. msg is passed only if the valid flag is true.

path

Returns the filename for the current log file with relative path.

append(msg: Buffer) : Promise<void>

Append msg to the log.

Parameters
  • msg - the message to add to the log

flush() : Promise<void>

Flush log to disk. Logs are flushed automatically every 32kib, but it's important to flush on transaction commits to ensure the transaction reaches disk.

close() : Promise<void>

Flushes any buffered data and closes the log.

crash() : Promise<void>

Simulates a crash by closing the log without flushing any pending writes. Useful for testing.

License

MIT. See LICENSE for details.