More simple, powerful, and TypeScript friendly Firestore wrapper.
Introduction
If you’re looking for a more intuitive and user-friendly way to interact with Firestore, then firestore-simple is an excellent choice. This TypeScript-friendly wrapper simplifies the API of Firestore, allowing developers to interact with the database without the hassle of complex types and redundant casting.
Features
- More Simple API: The original Firestore API can be a tad complicated, but
firestore-simplestreamlines it for ease of use. - TypeScript Friendly: With automatic typing for your documents, you won’t need to cast objects manually.
- Encoding and Decoding: Forget about repetitive conversion for every document! Define your conversion functions just once.
- Easy and Safe Transactions: Use the same CRUD API within a transaction, eliminating transaction context worries.
Installation
To get started with firestore-simple, install the appropriate package depending on whether you’re using the admin SDK or the web SDK:
bash
# For Admin SDK
npm i @firestore-simpleadmin
# For Web SDK
npm i @firestore-simpleweb
Usage Example
Let’s say you want to manage a collection of users. Here’s how simple the code can be:
typescript
import admin, { ServiceAccount } from 'firebase-admin';
import serviceAccount from 'path_to_your_firebase_secret.json';
import FirestoreSimple from '@firestore-simpleadmin';
// Initialize Firestore
admin.initializeApp({ credential: admin.credential.cert(serviceAccount as ServiceAccount) });
const firestore = admin.firestore();
// User Interface
interface User {
id: string;
name: string;
age: number;
}
// Main function
const main = async () => {
const firestoreSimple = new FirestoreSimple(firestore);
const dao = firestoreSimple.collectionUser({ path: 'user' });
// Add a user
const bobId = await dao.add({ name: 'bob', age: 20 });
// Fetch the user
const bob: User | undefined = await dao.fetch(bobId);
console.log(bob); // Outputs: { id: "someId", name: "bob", age: 20 }
};
main();
Understanding the Code: An Analogy
Imagine firestore-simple as a helpful librarian in a gigantic library (Firestore). Instead of you rummaging through rows and rows of books (documents), the librarian easily fetches the book you ask for, opens the correct pages, and even helps you take notes. Just as you would describe a book with its title, author, and publishing year, you define your users by their attributes (name, age) and let the librarian take care of the details. This makes reading (or working with your data) an enjoyable and efficient experience.
Troubleshooting
If you encounter issues while using firestore-simple, consider the following:
- Ensure you have the necessary Firebase credentials set up correctly.
- Verify that your installation of the appropriate SDK corresponds to your application needs.
- Consult the examples and API documentation for specific method usage.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Final Thoughts
By adopting firestore-simple, you can make your interaction with Firestore much smoother. Remember to keep your code updated, and if you would like to see more functionalities, look into the project’s directory or documentation.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

