$ show indexeddbshim/IndexedDBShim
This library provides a polyfill/shim for the IndexedDB API, implementing IndexedDB functionality using WebSQL as a backend storage mechanism. It works in both browser environments (leveraging native WebSQL where available) and Node.js (via websql-configurable/SQLite3). The library offers both invasive (automatically setting global indexedDB) and non-invasive (requiring explicit setup) versions. It implements the full IndexedDB specification including databases, object stores, indexes, transactions, and cursors, with proper handling of JavaScript value serialization through a structured cloning algorithm. The project features comprehensive test suites validating W3C compliance and active maintenance with regular updates to address compatibility issues and specification changes.
The LLM identified 4 files worth highlighting for reuse:
Implements IndexedDB-specific key validation, extraction, and comparison logic according to the W3C specification. Handles all key types (string, number, date, binary, array) with complex sorting rules required for proper index ordering. This self-contained module solves a non-trivial problem specific to IndexedDB implementations and could be extracted for use in other projects requiring ordered key handling with minimal dependencies.
Implements the structured cloning algorithm for serializing and deserializing JavaScript values for storage in IndexedDB. Handles complex types including Date, RegExp, Blob, File, ArrayBuffer, and typed arrays, with proper error handling for non-clonable types. Wraps the typeaon libraries in a clean interface and provides encode/decode/clone functions that could be reused in any project needing to transport or persist complex JavaScript values.
Provides a complete implementation of DOM event behavior including ShimEvent, ShimCustomEvent, and ShimEventTarget classes. Properly handles event propagation, bubbling, cancellation, and listener management. This self-contained module implements non-trivial DOM event semantics and depends only on the eventtargeter library, making it suitable for extraction to other projects needing a lightweight event system that matches browser behavior.
Implements the IDBKeyRange interface for representing key ranges in IndexedDB queries (bound, lowerBound, upperBound, etc.). Includes logic for range inclusion/exclusion, intersection testing, and proper handling of different key types. Builds on the Key.js module for validation and comparison, creating a well-defined, self-contained component that encapsulates a core IndexedDB concept useful for any project implementing range-based data access.