memory-level

In-memory abstract-level database for Node.js and browsers, backed by a fully persistent red-black tree.

Library
npm
v3.1.0
36stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
37/100Needs Attention
Development Activity32
Maintenance20
Community28
Maturity56
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture88
Code Quality85
Innovation62
Learning Curve50

memory-level is an in-memory implementation of the abstract-level key-value store interface, built for Node.js and browsers alike. It replaces two older packages, memdown and level-mem, and stores its data in a fully persistent red-black tree supplied by functional-red-black-tree — a structure that supports the level ecosystem’s explicit and implicit snapshot semantics without extra copying overhead.

Because it implements the same AbstractLevel API used by disk-backed stores like classic-level, memory-level is most often reached for in tests, prototypes, and browser bundles where a real LevelDB binary isn’t available or desirable — swap it in for a persistent backend without touching application code that talks to the abstract-level interface.

What You Get

  • Full abstract-level API compliance (put/get/del/batch/iterator, sorted iteration, ranges)
  • Configurable internal storage encoding (buffer, view, or utf8) to control memory shape and browser bundle size
  • Explicit and implicit snapshot support for consistent reads during concurrent writes
  • Zero native dependencies — pure JavaScript, so it works identically in Node.js and in the browser

Common Use Cases

  • Unit and integration tests for code written against abstract-level/levelup without touching disk
  • Browser bundles that need a Level-compatible store without a WASM/native LevelDB backend
  • Fast prototyping of Level-based applications before wiring up a persistent backend
  • Ephemeral caches or scratch stores that should vanish when the process exits

Under The Hood

Architecture MemoryLevel extends AbstractLevel from abstract-level, delegating lifecycle and encoding concerns to the parent while implementing only the storage primitives (_put, _get, _getSync, _getMany, _has, _hasMany, _del, _batch, _clear, _iterator, _keys, _values, _snapshot). State lives in a private #tree field holding a functional-red-black-tree instance; because the tree is persistent and immutable, _snapshot() just captures a reference to the current tree into a MemorySnapshot rather than deep-copying data, and every read op resolves options.snapshot?.[kTree] ?? this.#tree to transparently support point-in-time reads. Iterators in lib/iterator.js share one factored init/test/advance state machine across four concrete iterator classes (Entry/Key/Value/Clear) using symbol-keyed private state and shared prototype methods, keeping range/reverse/seek logic in one place instead of four. Batch and clear both build a new tree by chaining functional insert/remove calls rather than mutating in place, and clear() branches between a fast path (replace the whole tree) and a slow iterator-driven path with periodic yields for very large limited deletes.

Tech Stack Pure JavaScript with a hand-written index.d.ts for TypeScript consumers, targeting Node.js 18+ with zero runtime native dependencies. Runtime deps are abstract-level (the shared interface this package implements), functional-red-black-tree (the persistent tree), and module-error for structured error codes. Dev tooling includes standard for linting, tape paired with the shared abstract-level/test compliance suite, nyc for coverage, hallmark for changelog/docs linting, and airtap plus airtap-playwright to run the same suite in real browsers via babelify/@babel/preset-env transpilation.

Code Quality Testing is thorough for the package’s scope: test.js runs the shared abstract-level/test suite three times (default buffer encoding, then explicitly view and utf8), exercising the full CRUD/iterator/range contract across all storeEncoding modes, plus implementation-specific tests for buffer identity preservation, invalid storeEncoding errors, and clear()‘s tick-yielding behavior. Coverage is tracked via nyc/codecov. Errors use module-error to attach stable code properties rather than bare Error objects, matching the rest of the Level ecosystem’s convention. No TypeScript at the implementation level, but standard linting, hallmark, and CI keep style and docs consistent.

API Design The public API is intentionally thin: one constructor option beyond what abstract-level already defines (storeEncoding), with createIfMissing and errorIfExists explicitly documented as no-ops for this backend. Getting started is a single import and a MemoryLevel construction — no configuration is required to start reading and writing. Because it shares abstract-level’s full documented API surface, anyone already familiar with a disk-backed Level store needs no additional learning to use this one.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search