npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@la.machine.a.idees/firestore-orm-rxjs

v1.0.1

Published

ORM library for Google Firestore for rxjs (Angular) users

Downloads

6

Readme

Firestore ORM RxJS

A powerful TypeScript ORM for Firebase Firestore with first-class RxJS support, designed for modern Angular applications. This library combines type safety, reactive programming, and Firestore's real-time capabilities to provide a seamless development experience.

What is an ORM?

An Object-Relational Mapping (ORM) is a programming concept where an application maps object-oriented programming concepts to database concepts. In this context, an ORM is a library or framework that provides a set of tools and abstractions for working with NoSQL databases, using object-oriented programming languages like JavaScript.

Features

  • Type-safe entities with Zod schema validation
  • RxJS integration for reactive queries and real-time updates
  • Rich relationships support (one-to-one, one-to-many)
  • Intuitive API for CRUD operations
  • TypeScript-first approach

Installation

npm install @la.machine.a.idees/firestore-orm-rxjs

Quick Start

  1. Initialize Firebase in your application:
import { initializeOrm } from '@la.machine.a.idees/firestore-orm-rxjs';

initializeOrm({
  // Your Firebase config
  apiKey: 'your-api-key',
  authDomain: 'your-project.firebaseapp.com',
  projectId: 'your-project',
  storageBucket: 'your-project.appspot.com',
  messagingSenderId: 'your-messaging-sender-id',
  appId: 'your-app-id'
});
  1. Define your entity:
import { Entity } from '@la.machine.a.idees/firestore-orm-rxjs';
import { z } from 'zod';

const userSchema = z.object({
  name: z.string(),
  email: z.string().email(),
  age: z.number().optional()
});

class UserEntity extends Entity<z.infer<typeof userSchema>> {
  constructor() {
    // Pass the Firestore collection name, schema and default data
    super('users', userSchema, { name: 'John Doe', email: '[email protected]' });
  }
}
  1. Register your collection:
import { registerCollection } from '@la.machine.a.idees/firestore-orm-rxjs';

// Register once the collection with the Firestore collection name and your entity
const usersCollection = registerCollection('users', UserEntity);
  1. Use the collection:
// Create and save a new user
const user = new UserEntity();
user.data = {
  name: 'John Doe',
  email: '[email protected]'
};
await user.save();

// Update a user
user.data.age = 30;
await user.save();

// Get a user
const user = await usersCollection.getById('user123');

// Query users
const users = await usersCollection.get(ref => 
  query(ref, where('age', '>', 18))
);

// Observe users in real-time
usersCollection.observe$(ref => 
  query(ref, where('age', '>', 18))
).subscribe(users => {
  console.log('Users updated:', users);
});

Relationships

The library supports various types of relationships:

One-to-One

The user Document has a property profileId that references the profile Document.

class UserEntity extends Entity<z.infer<typeof userSchema>> {
  profile = this.referencesToOne<ProfileEntity>('profiles').fromKey('profileId');
}

One-to-One (Inverse)

The car Document has a property userId that references the user Document.

class UserEntity extends Entity<z.infer<typeof userSchema>> {
  car = this.referencesToOne<CarEntity>('cars').fromForeignKey('userId');
}

One-to-Many

A post Document has a property userId that references the user Document.

class UserEntity extends Entity<z.infer<typeof userSchema>> {
  posts = this.referencesToMultiple<PostEntity>('posts').fromForeignKey('userId');
}

One-to-Many (Inverse)

A group Document has an array property userIds that references the user Documents.

class UserEntity extends Entity<z.infer<typeof userSchema>> {
  groups = this.referencesToMultiple<GroupEntity>('groups').fromForeignArrayKey('userIds');
}

Real-time Updates

Enable real-time updates on entities:

const user = await usersCollection.getById('user123');
user.setRealtimeUpdates(true);

In your template, user data will be updated in real-time from Firestore updates:

<div *ngIf="user">
  <p>{{ user.data.name }}</p>
  <p>{{ user.data.email }}</p>
</div>

Schema Validation

The library uses Zod for runtime type checking and validation:

import { oneReference } from '@la.machine.a.idees/firestore-orm-rxjs';

const postSchema = z.object({
  title: z.string().min(1),
  content: z.string(),
  published: z.boolean().default(false),
  authorId: oneReference // Helper for foreign key references
});

For multiple foreign key references in an array, use multipleReferences.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Test Coverage

The library is tested using Vitest and covers a wide range of use cases.

License

MIT License