This module provides a type-safe, domain-driven abstraction over Firestore persistence. It integrates tightly with the `Model`, `Entity`, `Criteria` and `UnitOfWork` constructs from the [Shared Kernel](https://www.npmjs.com/package/@schorts/shared-kernel)
npm install @schorts/firestore-daoThis module provides a type-safe, domain-driven abstraction over Firestore persistence. It integrates tightly with the Model, Entity, Criteria and UnitOfWork constructs from the Shared Kernel, enabling expressive, consistent, and testable data access across bounded contexts.
``bash`
npm install --save @schorts/firestore-dao
Firestore DAOs encapsulate all persistence logic for domain entities, including:
- ๐ Querying by ID, criteria, or full collection.
- ๐ง Translating domain filters into Firestore constraints.
- ๐งผ Formatting primitives for Firestore compatibility.
- ๐ Coordinating writes via FirestoreUnitOfWork for atomicity.
They are not responsible for business logic, validation, or orchestration โ only persistence.
Each DAO implements the following shared kernel interfaces:
- Model - defines the contract for persistence operations.Entity
- - domain object with identity and behavior.UnitOfWork
- - optional batching mechanism for transactional consistency.
`ts
import { initializeApp, getFirestore, EntityRegistry } from "@schorts/firestore-dao";
// You need to use the internal firebase/firestore packages and register you entity via EntityRegistry
EntityRegistry.register("users", User);
const user = new User({ id: "abc123", name: "Alice" });
await userDAO.create(user); // direct write
const uow = new FirestoreUnitOfWork(firestore);
await userDAO.create(user, uow); // batched write
await uow.commit();
`
`ts`
const found = await userDAO.findByID("abc123");
const results = await userDAO.search(Criteria.where("status", "EQUAL", "active"));
- Standard filters (EQUAL, IN, GREATER_THAN, etc.)distanceBetween
- Geo-radius queries with post-filtering via .startAfter
- Ordering, limits, and pagination ().
- Soft deletes via status: "deleted"`.
This layer reflects a commitment to:
- Domain-driven design.
- Type safety and semantic clarity.
- Separation of concerns.
- Scalable, testable architecture.