Skip to content

dharayush7/fireclass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fireclass logo

@dharayush7/fireclass

Deprecated Firebase Admin model package. Migrate to the current Fireclass runtime for Node.js, Next.js, or React.

Migration guide | Current packages | GitHub | npm

Deprecated: Do not use this package for new applications. It is retained for existing Firebase Admin projects. The current Fireclass suite provides runtime-specific packages, typed errors, broader query support, testing utilities, Next.js boundaries, and React realtime hooks.

Choose the replacement

Application Current package
Node.js, Express, workers, Cloud Functions @dharayush7/fireclass-js
Next.js App Router @dharayush7/fireclass-ssr
React with Firebase client Firestore @dharayush7/fireclass-react
Custom adapters and in-memory tests @dharayush7/fireclass-core

For a Node or Express application:

npm remove @dharayush7/fireclass
npm install @dharayush7/fireclass-js firebase-admin class-validator class-transformer reflect-metadata

Then follow the complete migration guide.

Current initialization

Replace the legacy subpath factory:

- import { getBaseModel } from "@dharayush7/fireclass/core";
+ import { createFireclass } from "@dharayush7/fireclass-js";

- export const BaseModel = getBaseModel(firestore);
+ export const { BaseModel, adapter } = createFireclass(firestore);

The current Node runtime still exports getBaseModel(firestore) as an intermediate migration alias.

Current decorator imports

Remove legacy /decorators, /core, and /types imports:

- import { Collection } from "@dharayush7/fireclass/decorators";
- import type { QueryOptions } from "@dharayush7/fireclass/types";
+ import {
+   Collection,
+   type QueryOptions,
+ } from "@dharayush7/fireclass-js";

Import SDK decorators and standalone helpers directly where they are used. Keep the local initialized Fireclass file limited to BaseModel and the adapter.

Important migration differences

Area Legacy package Current suite
Validation errors Raw validation rejection ValidationFailedError with errors
Missing collection Generic error MissingCollectionError
Delete without id Generic error MissingIdError
Instance delete() Returns deleted id Returns void
findMany() Query required Query optional
Query operators Equality and ranges Adds in, not-in, array, cursor, find-one, and count
Testing Firebase Admin required In-memory FakeAdapter available
Next.js No server/client guard Dedicated server-only SSR package
React Not supported Dedicated client package and realtime hooks

The equality filter is equals, not equal.

Legacy installation

The following section is retained only for applications that cannot migrate immediately.

npm install @dharayush7/fireclass firebase-admin class-validator class-transformer reflect-metadata

Requirements:

  • Node.js 18 or newer.
  • Firebase Admin Firestore.
  • TypeScript decorators enabled.
  • A model constructor that calls super(data) and assigns data.
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Legacy Firebase Admin setup

import "reflect-metadata";
import { cert, getApps, initializeApp } from "firebase-admin/app";
import { getFirestore } from "firebase-admin/firestore";
import { getBaseModel } from "@dharayush7/fireclass/core";

if (getApps().length === 0) {
  initializeApp({
    credential: cert({
      projectId: process.env.FIREBASE_PROJECT_ID,
      clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
      privateKey: process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/g, "\n"),
    }),
  });
}

export const firestore = getFirestore();
export const BaseModel = getBaseModel(firestore);

Keep service-account values in gitignored environment files or a managed secret store.

Legacy model example

import { Collection } from "@dharayush7/fireclass/decorators";
import { IsEmail, IsOptional, IsString, Length } from "class-validator";
import { BaseModel } from "./fireclass";

@Collection("users")
export class User extends BaseModel<User> {
  @IsString()
  @Length(2, 80)
  name!: string;

  @IsEmail()
  email!: string;

  @IsOptional()
  @IsString()
  displayName?: string;

  constructor(data?: Partial<User>) {
    super(data);
    Object.assign(this, data);
  }
}

Legacy operations:

const id = await new User({
  name: "Ada Lovelace",
  email: "ada@example.com",
}).save();

const user = await User.findById(id);

const users = await User.findMany({
  where: { email: { equals: "ada@example.com" } },
  orderBy: { name: "asc" },
  limit: 20,
});

await user?.delete();

Complete migration workflow

  1. Choose the runtime package.
  2. Replace initialization and legacy subpath imports.
  3. Update validation error handling.
  4. Review instance delete return values.
  5. Review new query capabilities and Firestore indexes.
  6. For Next.js, move Admin models behind the SSR server-only boundary.
  7. Run the Fireclass CLI diagnostics and application tests.
npx fireclass init
npx fireclass doctor
npm run typecheck
npm test

Changing packages does not rewrite Firestore documents. Existing collection names remain controlled by @Collection, but application schema changes must be handled separately.

Documentation

See CHANGELOG.md for version history and RELEASE_NOTES.md for the current release summary.

Support

License

MIT. Copyright Ayush Dhar.

About

A minimal, type-safe Firestore model helper for Node.js with first-class integration for class-validator and class-transformer. Provides base models, typed CRUD, declarative collection mapping, and strong query builders.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors