Skip to content

v2.0.8

Choose a tag to compare

@dharayush7 dharayush7 released this 09 Jul 12:22

fireclass-js v2.0.8

@dharayush7/fireclass-js — the first public release of the Fireclass suite's firebase-admin runtime, for Node.js and Express.

It wraps @dharayush7/fireclass-core with a firebase-admin adapter and re-exports the whole core, so you define type-safe Firestore models as classes and get typed CRUD, query building, and class-validator validation on the server. It replaces the deprecated @dharayush7/fireclass (v0.2.12).

Highlights

  • createFireclass(firestore) — bind Fireclass to a firebase-admin Firestore and get back { BaseModel, adapter }.
  • AdminAdapter — implements the core FirestoreAdapter over firebase-admin, including batchDelete (500-write batches) and aggregate count.
  • fireclassErrorHandler() — Express error middleware that turns ValidationFailedError into a 400 with field-level details (no express dependency).
  • getBaseModel(firestore) — a drop-in alias for the deprecated package's entry point.
  • Re-exports the full core — decorators, QueryOptions, errors, defineBaseModel — so you install one package.

Install

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

firebase-admin, class-validator, and class-transformer are peer dependencies. @dharayush7/fireclass-core is a regular dependency (^2.0.8) — installed automatically. Enable decorators in tsconfig.json:

{ "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true } }

Quick look

import "reflect-metadata";
import { getFirestore } from "firebase-admin/firestore";
import { createFireclass, Collection } from "@dharayush7/fireclass-js";
import { IsEmail, IsInt, Min } from "class-validator";

const { BaseModel } = createFireclass(getFirestore());

@Collection("users")
class User extends BaseModel<User> {
  @IsEmail() email!: string;
  @IsInt() @Min(0) age!: number;
  constructor(data?: Partial<User>) { super(data); Object.assign(this, data); }
}

const id = await new User({ email: "ada@example.com", age: 36 }).save();
const adults = await User.findMany({ where: { age: { gte: 18 } }, orderBy: { age: "desc" } });

A complete Express CRUD API is in examples/express-api.

Migration from @dharayush7/fireclass

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

getBaseModel(firestore) still works. Note the query operator is equals (the old docs incorrectly showed equal).

Quality

  • 19 tests, including an end-to-end suite that drives the full core model API through the real AdminAdapter against an in-memory firebase-admin mock (no emulator).
  • Verified live against a real Firestore project — full CRUD cycle passes.
  • Dual ESM + CJS build with type declarations. Core is kept external (a shared dependency), not bundled, so the suite uses a single copy.

The Fireclass suite

Package Runtime For
@dharayush7/fireclass-core none (pure TS) shared modeling core
@dharayush7/fireclass-js firebase-admin Node / Express — this package
@dharayush7/fireclass-ssr firebase-admin Next.js (App Router)
@dharayush7/fireclass-react firebase client SDK React (realtime hooks)

Docs: https://fireclass.ayushdhar.com


Full API and examples: see the README. Changelog: see CHANGELOG.md.