This file provides guidance to AI codign agents like Claude Code (claude.ai/code), Cursor AI, Codex, GitHub Copilot, and other AI coding assistants when working with code in this repository.
pnpm build- Full production build (TypeScript bundle + native C++ binding)pnpm build:binding- Incremental build C++ binding only (production)pnpm build:binding:debug- Incremental build C++ binding only (debug)pnpm build:bundle- TypeScript only (unminified)pnpm build:bundle:minify- TypeScript only (minified)pnpm rebuild- Configure and build C++ binding only (production)pnpm rebuild:debug- Native C++ binding only (with debug logging and coverage)
pnpm test- Run all tests with Vitest using Node.jspnpm coverage- Run all tests with Vitest and coverage reportnode --expose-gc ./node_modules/vitest/vitest.mjs test/specific.test.ts- Run single test filepnpm test:bun- Run all tests with Vitest using Bunpnpm test:deno- Run all tests with Vitest using Denopnpm test:stress- Run all stress tests with Vitest using Node.jspnpm bench- Run all benchmarks with Vitest using Node.js
pnpm check- Run type-check, lint, and format checkingpnpm fmt- Format code with oxfmtpnpm fmt:check- Check code formatting with oxfmtpnpm lint- Code linting with oxlintpnpm type-check- TypeScript type checking only
pnpm clean- Clean native build artifactspnpm build:bundle && pnpm rebuild:debug- Full debug build for development
This is a Node.js binding for RocksDB that provides both TypeScript and C++ layers:
database.ts- MainRocksDatabaseclass extendingDBIwith transaction supportstore.ts- CoreStoreclass wrapping native database with encoding/decodingtransaction.ts- Transaction implementation for atomic operationsdbi.ts&dbi-iterator.ts- Database interface and iteration logicencoding.ts- Key/value encoding with msgpack and ordered-binary supportload-binding.ts- Native module loading and configurationparse-transaction-log.ts- Utility for reading raw transaction log filestransaction-log.ts- Transaction log implementation for storing transaction related datatransaction.ts- Transaction-specific context for transactional operationsutil.ts- Various helpers
binding.cpp/h- Main N-API module entry pointdatabase.cpp/h- Native database operations and async work handlingdb_handle.cpp/h- Database handle managementtransaction.cpp/h&&transaction_handle.cpp/h- Native transaction implementations-
transaction_log*.cpp/h- Native transaction log store and file implementations
db_iterator*.cpp/h- Iterator implementations for range queriesutil.cpp/h- Utility functions and error handling
- Hybrid Sync/Async: Operations return promises for disk I/O or immediate values for cached data
- Encoding Strategy: Keys use ordered-binary encoding, values default to msgpack
- Store Pattern:
Storeclass encapsulates database instance and encoding logic, shared betweenRocksDatabaseandTransaction - Native Binding: Uses node-gyp with C++20, links against prebuilt RocksDB libraries
- Optimistic (default): Conflicts detected at commit time
- Pessimistic: Conflicts throw immediately on detection
- Both modes support async/sync APIs with automatic commit/rollback
Uses ExtendedIterable wrapper around native iterators for array-like methods (map, filter, etc.)
with lazy evaluation.
ROCKSDB_VERSION- Override RocksDB version (default from package.json, or 'latest')ROCKSDB_PATH- Build from local RocksDB source instead of prebuiltMINIFY=1- Enable minification of TypeScript bundleKEEP_FILES=1- Don't delete temporary test databases for debugging purposes
Tests are in test/ directory using Vitest:
- Individual feature tests (transactions, ranges, encoding, etc.)
test/lib/util.tscontains test utilities- Coverage reports generated to
coverage/directory
- Key Encoding Order: Always encode values before keys when using
sharedStructuresKeyto avoid overwriting shared key buffer - Buffer Management: Store uses reusable buffers for performance (
keyBuffer,encodeBuffer) - Memory Management: Native layer handles RocksDB memory, TypeScript layer manages encoding buffers
- Error Handling: C++ errors are translated to JavaScript exceptions via N-API