How neeraj-ghodla/redis-om-node works
Main Components
• External Dependencies:
– Redis Server (Redis Stack with RedisJSON and RediSearch)
– Node Redis client (used for connecting, executing commands, etc.)
• Library Core Modules (located in the “lib” directory):
– Client Module: (lib/client)
• Manages Redis connection, low‑level commands execution.
– Schema Module: (lib/schema)
• Defines the mappings for Entities (fields, types, optional JSONPath/field aliases).
– Entity Module: (lib/entity)
• Represents user entities as JavaScript objects with additional metadata (like the generated unique ID).
– Repository Module: (lib/repository)
• Provides a high‑level interface for data operations (saving, fetching, deleting, expiring, indexing, etc.).
– Search Module: (lib/search)
• Implements the fluent API for building RediSearch queries (numeric comparisons, full‑text search, geo‑search, pagination, sorting).
– Indexer Module: (lib/indexer)
• Responsible for building and maintaining search indexes based on Schema definitions.
– Transformer Module: (lib/transformer)
• Converts between different Redis data formats (e.g. JSON documents versus hashes) and JavaScript objects.
– Error Module: (lib/error)
• Contains custom error classes (such as “InvalidInput”, “InvalidSchema”, “SearchError”, etc.) that encapsulate various exception conditions.
• Tests & Documentation:
– Spec folder (spec) shows a comprehensive suite of unit and functional tests.
– Docs folder contains markdown documentation for each of the key classes (which can be referenced for details on public APIs).
Interactions and Relationships
• The User (or developer’s application) makes calls to the Repository.
• The Repository interacts with:
– The Client (to perform Redis operations via Node Redis)
– The Schema (to map data structures and enforce validations)
– The Indexer (to create or update search indexes when saving/updating Entities)
– The Transformer (to convert between JavaScript objects and Redis JSON/Hashes)
– The Search Module (to enable fluent query building and execution).
• Meanwhile, errors raised by any module (Client, Schema, or Indexer) are standardized via the Error Module.
• The Repository also provides methods for “search”, “save”, “update”, “fetch”, “remove”, and “expire” that internally combine these components.
Architectural Patterns & Design Principles
• Modular Design: The library is separated into distinct concerns (client, entity, schema, repository, search, iterator, transformer) which makes it both maintainable and testable.
• Fluent Interface: The search queries use a fluent API that allows chaining methods to build complex queries (as seen in the README examples).
• Abstraction over Redis: By encapsulating Redis operations within higher‑level abstractions (repository, transformer, etc.), the library hides the low‑level details from the developer.
Technologies and Frameworks
• Written in TypeScript.
• Uses Node Redis as an underlying Redis client.
• Integrates with Redis Stack components (RedisJSON, RediSearch, Geo features).
• Testing is performed with Vitest (as indicated by “vitest.config.js”) and additional TypeScript configurations (tsconfig.json).